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

teableio / teable / 10845398142

13 Sep 2024 08:04AM UTC coverage: 85.107%. First build
10845398142

Pull #909

github

web-flow
Merge 5bdc07c75 into ca18e637c
Pull Request #909: fix: the flickering issue when rendering grouped in the grid view

5369 of 5622 branches covered (95.5%)

287 of 325 new or added lines in 5 files covered. (88.31%)

34699 of 40771 relevant lines covered (85.11%)

1216.39 hits per line

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

74.03
/apps/nestjs-backend/src/utils/filter.ts
1
/* eslint-disable @typescript-eslint/naming-convention */
4✔
2
import type { IUserCellValue, ILinkCellValue, IOperator } from '@teable/core';
4✔
3
import {
4✔
4
  FieldType,
4✔
5
  isNot,
4✔
6
  is,
4✔
7
  isNotEmpty,
4✔
8
  exactDate,
4✔
9
  hasNoneOf,
4✔
10
  CellValueType,
4✔
11
} from '@teable/core';
4✔
12
import { zonedTimeToUtc } from 'date-fns-tz';
4✔
13
import type { IFieldInstance } from '../features/field/model/factory';
4✔
14

4✔
15
const SPECIAL_OPERATOR_FIELD_TYPE_SET = new Set([
4✔
16
  FieldType.MultipleSelect,
4✔
17
  FieldType.User,
4✔
18
  FieldType.CreatedBy,
4✔
19
  FieldType.LastModifiedBy,
4✔
20
  FieldType.Link,
4✔
21
]);
4✔
22

4✔
23
export const shouldFilterByDefaultValue = (
4✔
24
  field: { type: FieldType; cellValueType: CellValueType } | undefined
2✔
25
) => {
2✔
26
  if (!field) return false;
2!
27

2✔
28
  const { type, cellValueType } = field;
2✔
29
  return (
2✔
30
    type === FieldType.Checkbox ||
2✔
31
    (type === FieldType.Formula && cellValueType === CellValueType.Boolean)
2!
32
  );
2✔
33
};
2✔
34

4✔
35
export const cellValue2FilterValue = (cellValue: unknown, field: IFieldInstance) => {
4✔
36
  const { type, isMultipleCellValue } = field;
2✔
37

2✔
38
  if (
2✔
39
    cellValue == null ||
2!
NEW
40
    ![FieldType.User, FieldType.CreatedBy, FieldType.LastModifiedBy, FieldType.Link].includes(type)
×
41
  )
2✔
42
    return cellValue;
2!
NEW
43

×
NEW
44
  if (isMultipleCellValue) {
×
NEW
45
    return (cellValue as (IUserCellValue | ILinkCellValue)[])?.map((v) => v.id);
×
NEW
46
  }
×
NEW
47
  return (cellValue as IUserCellValue | ILinkCellValue).id;
×
NEW
48
};
×
49

4✔
50
export const generateFilterItem = (field: IFieldInstance, value: unknown) => {
4✔
51
  let operator: IOperator = isNot.value;
2✔
52
  const { id: fieldId, type, isMultipleCellValue, options } = field;
2✔
53

2✔
54
  if (shouldFilterByDefaultValue(field)) {
2!
NEW
55
    operator = is.value;
×
NEW
56
    value = !value || null;
×
57
  } else if (value == null) {
2✔
58
    operator = isNotEmpty.value;
2✔
59
  } else if (type === FieldType.Date) {
2!
NEW
60
    const timeZone =
×
NEW
61
      options?.formatting?.timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
×
NEW
62
    const dateStr = zonedTimeToUtc(value as string, timeZone).toISOString();
×
NEW
63
    value = {
×
NEW
64
      exactDate: dateStr,
×
NEW
65
      mode: exactDate.value,
×
NEW
66
      timeZone,
×
NEW
67
    };
×
NEW
68
  } else if (SPECIAL_OPERATOR_FIELD_TYPE_SET.has(type) && isMultipleCellValue) {
×
NEW
69
    operator = hasNoneOf.value;
×
NEW
70
  }
×
71

2✔
72
  return {
2✔
73
    fieldId,
2✔
74
    value: cellValue2FilterValue(value, field) as never,
2✔
75
    operator,
2✔
76
  };
2✔
77
};
2✔
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