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

teableio / teable / 8536869866

03 Apr 2024 10:05AM CUT coverage: 21.234% (-0.3%) from 21.535%
8536869866

Pull #514

github

web-flow
Merge 91a25d710 into 45ee7ebb3
Pull Request #514: refactor: user and link selector

1394 of 2532 branches covered (55.06%)

27 of 1620 new or added lines in 60 files covered. (1.67%)

4 existing lines in 2 files now uncovered.

14588 of 68702 relevant lines covered (21.23%)

2.02 hits per line

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

0.0
/packages/sdk/src/components/filter/condition/FieldValue.tsx
1
import type { IDateFilter, IFilterItem } from '@teable/core';
×
2
import { FieldType } from '@teable/core';
×
3

×
4
import { Input } from '@teable/ui-lib';
×
NEW
5
import { useContext, useMemo } from 'react';
×
6
import { useField } from '../../../hooks';
×
7

×
8
import type { DateField } from '../../../model';
×
9
import { NumberEditor, RatingEditor } from '../../editor';
×
10
import {
×
11
  FileTypeSelect,
×
12
  FilterCheckbox,
×
13
  FilterDatePicker,
×
14
  FilterInput,
×
NEW
15
  FilterLink,
×
16
  FilterMultipleSelect,
×
17
  FilterSingleSelect,
×
18
  FilterUserSelect,
×
19
} from '../component';
×
NEW
20
import { EMPTY_OPERATORS, MULTIPLE_OPERATORS } from '../constant';
×
NEW
21
import { FilterContext } from '../context';
×
22

×
23
interface IFieldValue {
×
24
  filter: IFilterItem;
×
25
  onSelect: (value: IFilterItem['value']) => void;
×
26
}
×
27

×
28
function FieldValue(props: IFieldValue) {
×
29
  const { filter, onSelect } = props;
×
30
  const field = useField(filter.fieldId);
×
NEW
31
  const { components } = useContext(FilterContext);
×
32

×
33
  const emptyComponent = <Input className="m-1 h-8 w-40 placeholder:text-[13px]" disabled />;
×
34
  const showEmptyComponent = useMemo(() => {
×
NEW
35
    const showEmpty = EMPTY_OPERATORS.includes(filter.operator);
×
36
    showEmpty && onSelect?.(null);
×
37
    return showEmpty;
×
38
  }, [filter.operator, onSelect]);
×
39

×
NEW
40
  if (showEmptyComponent) {
×
NEW
41
    return emptyComponent;
×
NEW
42
  }
×
43

×
NEW
44
  const InputComponent = (
×
NEW
45
    <FilterInput
×
NEW
46
      placeholder="Enter a value"
×
NEW
47
      value={filter.value as string}
×
NEW
48
      onChange={onSelect}
×
NEW
49
      className="w-40"
×
NEW
50
    />
×
NEW
51
  );
×
NEW
52

×
NEW
53
  switch (field?.type) {
×
NEW
54
    case FieldType.Number:
×
NEW
55
      return (
×
NEW
56
        <NumberEditor
×
NEW
57
          value={filter.value as number}
×
NEW
58
          options={field.options}
×
NEW
59
          onChange={onSelect as (value?: number | null) => void}
×
NEW
60
          className="m-1 w-40"
×
NEW
61
        />
×
NEW
62
      );
×
NEW
63
    case FieldType.SingleSelect:
×
NEW
64
      return MULTIPLE_OPERATORS.includes(filter.operator) ? (
×
NEW
65
        <FilterMultipleSelect
×
NEW
66
          field={field}
×
NEW
67
          value={filter.value as string[]}
×
NEW
68
          onSelect={(value) => onSelect(value as IFilterItem['value'])}
×
NEW
69
        />
×
NEW
70
      ) : (
×
NEW
71
        <FilterSingleSelect
×
NEW
72
          field={field}
×
NEW
73
          value={filter.value as string}
×
NEW
74
          onSelect={onSelect}
×
NEW
75
          operator={filter.operator}
×
NEW
76
        />
×
NEW
77
      );
×
NEW
78
    case FieldType.MultipleSelect:
×
NEW
79
      return (
×
NEW
80
        <FilterMultipleSelect
×
NEW
81
          field={field}
×
NEW
82
          value={filter.value as string[]}
×
NEW
83
          onSelect={(value) => onSelect(value as IFilterItem['value'])}
×
NEW
84
        />
×
NEW
85
      );
×
NEW
86
    case FieldType.Date:
×
NEW
87
    case FieldType.CreatedTime:
×
NEW
88
    case FieldType.LastModifiedTime:
×
NEW
89
      return (
×
NEW
90
        <FilterDatePicker
×
NEW
91
          field={field as DateField}
×
NEW
92
          value={filter.value as IDateFilter}
×
NEW
93
          onSelect={onSelect}
×
NEW
94
          operator={filter.operator}
×
NEW
95
        />
×
NEW
96
      );
×
NEW
97
    case FieldType.SingleLineText:
×
NEW
98
    case FieldType.AutoNumber:
×
NEW
99
      return InputComponent;
×
NEW
100
    case FieldType.Checkbox:
×
NEW
101
      return <FilterCheckbox value={filter.value as boolean} onChange={onSelect} />;
×
NEW
102
    case FieldType.Link: {
×
NEW
103
      const linkProps = {
×
NEW
104
        field,
×
NEW
105
        onSelect: (value: string[] | string | null) =>
×
NEW
106
          onSelect(value?.length ? (value as IFilterItem['value']) : null),
×
NEW
107
        value: filter.value as string[],
×
NEW
108
        operator: filter.operator,
×
NEW
109
      };
×
NEW
110
      if (components && FieldType.Link in components) {
×
NEW
111
        const LinkComponents = components[FieldType.Link];
×
NEW
112
        return <LinkComponents {...linkProps} />;
×
NEW
113
      }
×
NEW
114
      return <FilterLink {...linkProps} />;
×
NEW
115
    }
×
NEW
116
    case FieldType.Attachment:
×
NEW
117
      return <FileTypeSelect value={filter.value as string} onSelect={onSelect} />;
×
NEW
118
    case FieldType.Rating:
×
NEW
119
      return (
×
NEW
120
        <RatingEditor
×
NEW
121
          value={filter.value as number}
×
NEW
122
          options={field.options}
×
NEW
123
          onChange={onSelect as (value?: number) => void}
×
NEW
124
          className="h-8 rounded-md border border-input px-2 shadow-sm"
×
NEW
125
          iconClassName="w-4 h-4 mr-1"
×
NEW
126
        />
×
NEW
127
      );
×
NEW
128
    case FieldType.User: {
×
NEW
129
      const props = {
×
NEW
130
        field,
×
NEW
131
        onSelect: (value: string[] | string | null) =>
×
NEW
132
          onSelect(value?.length ? (value as IFilterItem['value']) : null),
×
NEW
133
        value: filter.value as string[],
×
NEW
134
        operator: filter.operator,
×
NEW
135
      };
×
NEW
136
      if (components && FieldType.User in components) {
×
NEW
137
        const UserComponents = components[FieldType.User];
×
NEW
138
        return <UserComponents {...props} />;
×
NEW
139
      }
×
NEW
140
      return <FilterUserSelect {...props} />;
×
141
    }
×
NEW
142
    default:
×
NEW
143
      return InputComponent;
×
NEW
144
  }
×
UNCOV
145
}
×
UNCOV
146

×
UNCOV
147
export { FieldValue };
×
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