• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

teableio / teable / 8538004962

03 Apr 2024 11:36AM CUT coverage: 18.233% (-3.3%) from 21.535%
8538004962

Pull #528

github

web-flow
Merge c1a248a6f into 45ee7ebb3
Pull Request #528: feat: Kanban view

575 of 1136 branches covered (50.62%)

29 of 2908 new or added lines in 83 files covered. (1.0%)

5 existing lines in 5 files now uncovered.

6439 of 35315 relevant lines covered (18.23%)

3.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/sdk/src/components/cell-value/cell-select/CellSelect.tsx
NEW
1
import type { ISelectFieldOptions } from '@teable/core';
×
NEW
2
import { ColorUtils } from '@teable/core';
×
NEW
3
import { cn } from '@teable/ui-lib';
×
NEW
4
import { keyBy } from 'lodash';
×
NEW
5
import { useMemo } from 'react';
×
NEW
6
import type { ICellValue } from '../type';
×
NEW
7
import { SelectTag } from './SelectTag';
×
NEW
8

×
NEW
9
export const transformSelectOptions = (options: ISelectFieldOptions) => {
×
NEW
10
  return options.choices.map(({ name, color }) => ({
×
NEW
11
    label: name,
×
NEW
12
    value: name,
×
NEW
13
    color: ColorUtils.shouldUseLightTextOnColor(color) ? '#ffffff' : '#000000',
×
NEW
14
    backgroundColor: ColorUtils.getHexForColor(color),
×
NEW
15
  }));
×
NEW
16
};
×
NEW
17

×
NEW
18
export interface ISelectOption {
×
NEW
19
  label: string;
×
NEW
20
  value: string;
×
NEW
21
  color?: string;
×
NEW
22
  backgroundColor?: string;
×
NEW
23
}
×
NEW
24

×
NEW
25
interface ICellSelect extends ICellValue<string | string[]> {
×
NEW
26
  options?: ISelectOption[] | null;
×
NEW
27
  itemClassName?: string;
×
NEW
28
}
×
NEW
29

×
NEW
30
export const CellSelect = (props: ICellSelect) => {
×
NEW
31
  const { value, options, className, style, itemClassName } = props;
×
NEW
32

×
NEW
33
  const innerValue = useMemo(() => {
×
NEW
34
    if (value == null || Array.isArray(value)) return value;
×
NEW
35
    return [value];
×
NEW
36
  }, [value]);
×
NEW
37

×
NEW
38
  const optionMap = useMemo(() => {
×
NEW
39
    return keyBy(options, 'value');
×
NEW
40
  }, [options]);
×
NEW
41

×
NEW
42
  return (
×
NEW
43
    <div className={cn('flex space-x-1', className)} style={style}>
×
NEW
44
      {innerValue?.map((itemVal) => {
×
NEW
45
        const option = optionMap[itemVal];
×
NEW
46
        if (option == null) return null;
×
NEW
47
        const { label, value, color, backgroundColor } = option;
×
NEW
48
        return (
×
NEW
49
          <SelectTag
×
NEW
50
            key={value}
×
NEW
51
            label={label || 'Untitled'}
×
NEW
52
            color={color}
×
NEW
53
            backgroundColor={backgroundColor}
×
NEW
54
            className={itemClassName}
×
NEW
55
          />
×
NEW
56
        );
×
NEW
57
      })}
×
NEW
58
    </div>
×
NEW
59
  );
×
NEW
60
};
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc