@addev-be/ui 0.1.20 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/package.json +1 -1
  2. package/src/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.ts +100 -0
  3. package/src/components/data/AdvancedRequestDataGrid/helpers/columns.tsx +263 -0
  4. package/src/components/data/AdvancedRequestDataGrid/helpers/index.ts +2 -0
  5. package/src/components/data/{DataGrid/AdvancedRequestDataGrid.tsx → AdvancedRequestDataGrid/index.tsx} +112 -61
  6. package/src/components/data/AdvancedRequestDataGrid/types.ts +47 -0
  7. package/src/components/data/DataGrid/DataGridCell.tsx +3 -6
  8. package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +1 -1
  9. package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +2 -2
  10. package/src/components/data/DataGrid/DataGridFooter.tsx +4 -4
  11. package/src/components/data/DataGrid/DataGridHeader.tsx +14 -15
  12. package/src/components/data/DataGrid/VirtualScroller.tsx +2 -7
  13. package/src/components/data/DataGrid/helpers/columns.tsx +33 -94
  14. package/src/components/data/DataGrid/helpers/filters.ts +16 -28
  15. package/src/components/data/DataGrid/helpers/index.ts +1 -2
  16. package/src/components/data/DataGrid/hooks/index.ts +1 -1
  17. package/src/components/data/DataGrid/hooks/useDataGrid.tsx +40 -4
  18. package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +1 -1
  19. package/src/components/data/DataGrid/index.tsx +15 -27
  20. package/src/components/data/DataGrid/styles.ts +19 -4
  21. package/src/components/data/DataGrid/types.ts +69 -68
  22. package/src/components/data/index.ts +3 -2
  23. package/src/components/forms/IconButton.tsx +0 -1
  24. package/src/components/forms/IndeterminateCheckbox.tsx +1 -1
  25. package/src/services/advancedRequests.ts +1 -0
  26. package/src/components/data/DataGrid/helpers/advancedRequests.tsx +0 -61
@@ -0,0 +1,47 @@
1
+ import {
2
+ AdvancedRequestRow,
3
+ ConditionDTO,
4
+ FieldDTO,
5
+ OrderByDTO,
6
+ } from '../../../services/advancedRequests';
7
+ import {
8
+ DataGridColumn,
9
+ DataGridFilter,
10
+ DataGridFilterType,
11
+ DataGridProps,
12
+ } from '../DataGrid/types';
13
+
14
+ export type AdvancedRequestDataGridFilter<
15
+ T extends DataGridFilterType = DataGridFilterType
16
+ > = DataGridFilter<T> & {
17
+ field?: FieldDTO;
18
+ };
19
+
20
+ export type AdvancedRequestDataGridFilters = Record<
21
+ string,
22
+ AdvancedRequestDataGridFilter
23
+ >;
24
+
25
+ export type AdvancedRequestDataGridColumn<R> = DataGridColumn<R> & {
26
+ filter?: AdvancedRequestDataGridFilter;
27
+ field?: FieldDTO;
28
+ filterField?: FieldDTO;
29
+ sortField?: FieldDTO;
30
+ };
31
+
32
+ export type AdvancedRequestDataGridColumns<R> = Record<
33
+ string,
34
+ AdvancedRequestDataGridColumn<R>
35
+ >;
36
+
37
+ export type AdvancedRequestDataGridProps<R> = Omit<
38
+ DataGridProps<R>,
39
+ 'rows' | 'columns'
40
+ > & {
41
+ columns: AdvancedRequestDataGridColumns<R>;
42
+ type: string;
43
+ orderBy?: OrderByDTO[];
44
+ conditions?: ConditionDTO[];
45
+ idField?: FieldDTO | null;
46
+ parser?: (row: AdvancedRequestRow<R>) => R;
47
+ };
@@ -3,17 +3,14 @@
3
3
 
4
4
  import * as styles from './styles';
5
5
 
6
- import { DataGridCellProps, DataGridColumn, DataGridFilterType } from './types';
6
+ import { DataGridCellProps, DataGridColumn } from './types';
7
7
  import { MouseEvent, useCallback } from 'react';
8
8
 
9
9
  import { DataGridEditableCell } from './DataGridEditableCell';
10
10
  import { join } from 'lodash';
11
11
  import { useDataGridContext } from './hooks';
12
12
 
13
- const defaultRender = <R,>(
14
- col: DataGridColumn<R, DataGridFilterType | undefined>,
15
- row: R
16
- ) => {
13
+ const defaultRender = <R,>(row: R, col: DataGridColumn<R>) => {
17
14
  const value = col.propertyName ? row[col.propertyName] : '';
18
15
  return !value ? '' : String(value);
19
16
  };
@@ -72,7 +69,7 @@ export const DataGridCell = <R,>({
72
69
  onDoubleClick={onDoubleClick}
73
70
  style={style}
74
71
  >
75
- {(column.render ?? defaultRender)(column, row)}
72
+ {(column.render ?? defaultRender)(row, column)}
76
73
  </styles.DataGridCell>
77
74
  );
78
75
  };
@@ -17,7 +17,7 @@ export const useFilterModal = <R,>({
17
17
  const [isVisible, setIsVisible] = useState(false);
18
18
  const { filters = {}, columns, setFilters } = useDataGridContext<R>(context);
19
19
  const column = columns[columnKey];
20
- const [currentFilter, setCurrentFilter] = useState<DataGridFilter<R>>(
20
+ const [currentFilter, setCurrentFilter] = useState<DataGridFilter>(
21
21
  filters[columnKey] ?? column?.filter
22
22
  );
23
23
 
@@ -3,6 +3,7 @@
3
3
 
4
4
  import * as styles from './styles';
5
5
 
6
+ import { DataGridContext, MysqlJsonObject } from '../types';
6
7
  import { FilterIcon, FilterSlashIcon, MagnifierIcon } from '../../../../Icons';
7
8
  import { applyFilters, getDateGroups } from '../helpers';
8
9
  import { intersection, uniq, without } from 'lodash';
@@ -15,7 +16,6 @@ import {
15
16
  useState,
16
17
  } from 'react';
17
18
 
18
- import { DataGridContext } from '../types';
19
19
  import { FilterValuesScroller } from '../FilterValuesScroller';
20
20
  import { Input } from '../../../forms';
21
21
  import { useFilterModal } from './hooks';
@@ -45,7 +45,7 @@ export const DataGridFilterMenu = <R,>({
45
45
  const [textFilter, setTextFilter] = useState('');
46
46
 
47
47
  const [availableValues, setAvailableValues] = useState<
48
- (string | number | null)[]
48
+ (string | number | null | MysqlJsonObject)[]
49
49
  >([]);
50
50
 
51
51
  useEffect(() => {
@@ -36,13 +36,13 @@ export const DataGridFooter = <R,>({
36
36
  }}
37
37
  >
38
38
  {!!selectable && (
39
- <th
39
+ <div
40
40
  // className="inline-block w-12 select-none"
41
41
  key="__select_checkbox__"
42
- ></th>
42
+ ></div>
43
43
  )}
44
44
  {visibleColumns.map(([key, col]) => (
45
- <th
45
+ <div
46
46
  key={key}
47
47
  className={join(
48
48
  [
@@ -56,7 +56,7 @@ export const DataGridFooter = <R,>({
56
56
  style={{ width: (col.width ?? 150) + 'px' }}
57
57
  >
58
58
  {col.footer?.(rows, sortedRows, selectedRows)}
59
- </th>
59
+ </div>
60
60
  ))}
61
61
  </tr>
62
62
  </tfoot>
@@ -9,7 +9,7 @@ import {
9
9
  FilterSlashIcon,
10
10
  TableColumnsIcon,
11
11
  } from '../../../Icons';
12
- import { useCallback, useMemo, useState } from 'react';
12
+ import { useCallback, useState } from 'react';
13
13
 
14
14
  import { Button } from '../../forms';
15
15
  import { DataGridContext } from './types';
@@ -29,39 +29,38 @@ export const DataGridHeader = <R,>({
29
29
  visibleColumns,
30
30
  selectable,
31
31
  rows,
32
- selectedRows,
33
- setSelectedRows,
32
+ selectedKeys,
33
+ setSelectedKeys,
34
34
  copyTable,
35
35
  setFilters,
36
36
  refresh,
37
37
  headerColor,
38
+ rowKeyGetter,
39
+ gridTemplateColumns,
40
+ getAllIds,
38
41
  } = useDataGridContext(context);
39
42
  const [visibleFilter, setVisibleFilter] = useState<string | undefined>();
40
43
 
41
44
  const { openModal, modal } = useDataGridColumnsModal<R>(context);
42
45
 
43
46
  const checkboxStatus =
44
- selectedRows.length === 0
47
+ selectedKeys.length === 0
45
48
  ? false
46
- : selectedRows.length === rows.length
49
+ : selectedKeys.length === rows.length
47
50
  ? true
48
51
  : undefined;
49
52
  const toggleAll = useCallback(
50
- (newStatus: boolean) => {
51
- setSelectedRows(newStatus ? rows : []);
53
+ async (newStatus: boolean) => {
54
+ const allIds = getAllIds ? await getAllIds() : rows.map(rowKeyGetter);
55
+ setSelectedKeys(newStatus ? allIds : []);
52
56
  },
53
- [rows, setSelectedRows]
57
+ [getAllIds, rowKeyGetter, rows, setSelectedKeys]
54
58
  );
55
59
 
56
60
  const onFilterButtonClicked = useCallback((columnKey: string) => {
57
61
  setVisibleFilter((prev) => (prev === columnKey ? undefined : columnKey));
58
62
  }, []);
59
63
 
60
- const gridTemplateColumns = useMemo(
61
- () => visibleColumns.map(([, col]) => `${col.width ?? 150}px`).join(' '),
62
- [visibleColumns]
63
- );
64
-
65
64
  const [isLoadingVisible, setIsLoadingVisible] = useState(false);
66
65
  const runCopyTable = useCallback(() => {
67
66
  setIsLoadingVisible(true);
@@ -103,14 +102,14 @@ export const DataGridHeader = <R,>({
103
102
  $headerColor={headerColor}
104
103
  >
105
104
  {!!selectable && (
106
- <th
105
+ <styles.SelectionCell
107
106
  // className="inline-flex items-center justify-center w-12 select-none"
108
107
  >
109
108
  <IndeterminateCheckbox
110
109
  checked={checkboxStatus}
111
110
  onChange={() => toggleAll(!checkboxStatus)}
112
111
  />
113
- </th>
112
+ </styles.SelectionCell>
114
113
  )}
115
114
  {visibleColumns.map(([key, col], index) => (
116
115
  <DataGridHeaderCell
@@ -1,6 +1,6 @@
1
1
  import * as styles from './styles';
2
2
 
3
- import { ReactNode, useContext, useMemo } from 'react';
3
+ import { ReactNode, useContext } from 'react';
4
4
 
5
5
  import { DataGridContext } from './types';
6
6
 
@@ -17,9 +17,9 @@ export const VirtualScroller = <R,>(props: VirtualScrollerProps<R>) => {
17
17
  rowHeight = styles.DEFAULT_ROW_HEIGHT,
18
18
  // headerRowHeight = styles.DEFAULT_HEADER_ROW_HEIGHT,
19
19
  sortedRows,
20
- visibleColumns,
21
20
  index,
22
21
  visibleRows,
22
+ gridTemplateColumns,
23
23
  } = useContext(props.context);
24
24
  const {
25
25
  rowTemplate,
@@ -32,11 +32,6 @@ export const VirtualScroller = <R,>(props: VirtualScrollerProps<R>) => {
32
32
  // const headerAndFooterHeight =
33
33
  // 2 * headerRowHeight + (hasFooter ? rowHeight : 0) + 2;
34
34
 
35
- const gridTemplateColumns = useMemo(
36
- () => visibleColumns.map(([, col]) => `${col.width ?? 150}px`).join(' '),
37
- [visibleColumns]
38
- );
39
-
40
35
  return (
41
36
  <styles.VirtualScrollerContainer $height={totalHeight}>
42
37
  <styles.VirtualScrollerRowsContainer
@@ -1,22 +1,17 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
 
3
- import {
4
- DataGridColumn,
5
- DataGridColumns,
6
- DataGridFilterType,
7
- DataGridSettings,
8
- } from '../types';
3
+ import { DataGridColumn, DataGridColumns, DataGridSettings } from '../types';
9
4
  import {
10
5
  formatMoney,
11
6
  formatNumber,
12
7
  formatPercentage,
13
8
  } from '../../../../helpers/numbers';
9
+ import { numberFilter, textFilter } from './filters';
14
10
 
15
- import _ from 'lodash';
16
11
  import moment from 'moment';
17
12
 
18
13
  export const isColumnVisible = <R,>(
19
- obj: DataGridColumn<R, any> | DataGridSettings
14
+ obj: DataGridColumn<R> | DataGridSettings
20
15
  ): boolean => {
21
16
  return obj?.order !== -1;
22
17
  };
@@ -24,19 +19,14 @@ export const isColumnVisible = <R,>(
24
19
  export const textColumn = <R extends Record<string, any>>(
25
20
  key: string,
26
21
  title: string,
27
- options?: Partial<DataGridColumn<R, DataGridFilterType>>
22
+ options?: Partial<DataGridColumn<R>>
28
23
  ): DataGridColumns<R> => ({
29
24
  [key]: {
30
25
  name: title,
31
- render: (col, row) => row[key] ?? '',
26
+ render: (row) => row[key] ?? '',
32
27
  getter: (row) => row[key] ?? '',
33
28
  sortGetter: (row) => row[key] ?? '',
34
- filter: {
35
- type: 'text',
36
- operator: 'contains',
37
- values: [''],
38
- getter: (row) => row[key] ?? '',
39
- },
29
+ filter: textFilter(key),
40
30
  ...options,
41
31
  },
42
32
  });
@@ -44,11 +34,11 @@ export const textColumn = <R extends Record<string, any>>(
44
34
  export const mailColumn = <R extends Record<string, any>>(
45
35
  key: string,
46
36
  title: string,
47
- options?: Partial<DataGridColumn<R, DataGridFilterType>>
37
+ options?: Partial<DataGridColumn<R>>
48
38
  ): DataGridColumns<R> => ({
49
39
  [key]: {
50
40
  name: title,
51
- render: (col, row) => (
41
+ render: (row) => (
52
42
  <a
53
43
  // className="text-blue-500 hover:text-blue-700"
54
44
  href={`mailto:${row[key]}`}
@@ -58,12 +48,7 @@ export const mailColumn = <R extends Record<string, any>>(
58
48
  ),
59
49
  getter: (row) => row[key] ?? '',
60
50
  sortGetter: (row) => row[key] ?? '',
61
- filter: {
62
- type: 'text',
63
- operator: 'contains',
64
- values: [''],
65
- getter: (row) => row[key] ?? '',
66
- },
51
+ filter: textFilter(key),
67
52
  ...options,
68
53
  },
69
54
  });
@@ -71,11 +56,11 @@ export const mailColumn = <R extends Record<string, any>>(
71
56
  export const phoneColumn = <R extends Record<string, any>>(
72
57
  key: string,
73
58
  title: string,
74
- options?: Partial<DataGridColumn<R, DataGridFilterType>>
59
+ options?: Partial<DataGridColumn<R>>
75
60
  ): DataGridColumns<R> => ({
76
61
  [key]: {
77
62
  name: title,
78
- render: (col, row) => (
63
+ render: (row) => (
79
64
  <a
80
65
  // className="text-blue-500 hover:text-blue-700"
81
66
  href={`tel:${row[key]}`}
@@ -85,12 +70,7 @@ export const phoneColumn = <R extends Record<string, any>>(
85
70
  ),
86
71
  getter: (row) => row[key] ?? '',
87
72
  sortGetter: (row) => row[key] ?? '',
88
- filter: {
89
- type: 'text',
90
- operator: 'contains',
91
- values: [''],
92
- getter: (row) => row[key] ?? '',
93
- },
73
+ filter: textFilter(key),
94
74
  ...options,
95
75
  },
96
76
  });
@@ -98,19 +78,14 @@ export const phoneColumn = <R extends Record<string, any>>(
98
78
  export const dateColumn = <R extends Record<string, any>>(
99
79
  key: string,
100
80
  title: string,
101
- options?: Partial<DataGridColumn<R, DataGridFilterType>>
81
+ options?: Partial<DataGridColumn<R>>
102
82
  ): DataGridColumns<R> => ({
103
83
  [key]: {
104
84
  name: title,
105
- render: (col, row) => moment(row[key]).format('DD/MM/YYYY') ?? '',
85
+ render: (row) => moment(row[key]).format('DD/MM/YYYY') ?? '',
106
86
  getter: (row) => row[key] ?? '',
107
87
  sortGetter: (row) => row[key] ?? '',
108
- filter: {
109
- type: 'text',
110
- operator: 'contains',
111
- values: [''],
112
- getter: (row) => row[key] ?? '',
113
- },
88
+ filter: textFilter(key),
114
89
  ...options,
115
90
  },
116
91
  });
@@ -118,19 +93,14 @@ export const dateColumn = <R extends Record<string, any>>(
118
93
  export const monthColumn = <R extends Record<string, any>>(
119
94
  key: string,
120
95
  title: string,
121
- options?: Partial<DataGridColumn<R, DataGridFilterType>>
96
+ options?: Partial<DataGridColumn<R>>
122
97
  ): DataGridColumns<R> => ({
123
98
  [key]: {
124
99
  name: title,
125
- render: (col, row) => (row[key] ? `${row[key]} mois ` : ''),
100
+ render: (row) => (row[key] ? `${row[key]} mois ` : ''),
126
101
  getter: (row) => row[key] ?? '',
127
102
  sortGetter: (row) => row[key] ?? '',
128
- filter: {
129
- type: 'text',
130
- operator: 'contains',
131
- values: [''],
132
- getter: (row) => row[key] ?? '',
133
- },
103
+ filter: textFilter(key),
134
104
  ...options,
135
105
  },
136
106
  });
@@ -139,11 +109,11 @@ export const numberColumn = <R extends Record<string, any>>(
139
109
  key: string,
140
110
  title: string,
141
111
  decimals = 2,
142
- options?: Partial<DataGridColumn<R, DataGridFilterType>>
112
+ options?: Partial<DataGridColumn<R>>
143
113
  ): DataGridColumns<R> => ({
144
114
  [key]: {
145
115
  name: title,
146
- render: (col, row) => formatNumber(row[key], decimals) ?? '',
116
+ render: (row) => formatNumber(row[key], decimals) ?? '',
147
117
  excelFormatter: () => '#',
148
118
  getter: (row) => row[key] ?? '',
149
119
  sortGetter: (row) => row[key] ?? '',
@@ -151,7 +121,7 @@ export const numberColumn = <R extends Record<string, any>>(
151
121
  type: 'number',
152
122
  operator: 'equals',
153
123
  values: [0],
154
- getter: (row) => row[key] ?? 0,
124
+ getter: (value) => value ?? 0,
155
125
  },
156
126
  ...options,
157
127
  },
@@ -161,20 +131,15 @@ export const moneyColumn = <R extends Record<string, any>>(
161
131
  key: string,
162
132
  title: string,
163
133
  decimals = 2,
164
- options?: Partial<DataGridColumn<R, DataGridFilterType>>
134
+ options?: Partial<DataGridColumn<R>>
165
135
  ): DataGridColumns<R> => ({
166
136
  [key]: {
167
137
  name: title,
168
- render: (col, row) => formatMoney(row[key], decimals) ?? '',
138
+ render: (row) => formatMoney(row[key], decimals) ?? '',
169
139
  excelFormatter: () => '#0.00',
170
140
  getter: (row) => row[key] ?? '',
171
141
  sortGetter: (row) => row[key] ?? '',
172
- filter: {
173
- type: 'number',
174
- operator: 'equals',
175
- values: [0],
176
- getter: (row) => row[key] ?? 0,
177
- },
142
+ filter: numberFilter(key),
178
143
  ...options,
179
144
  },
180
145
  });
@@ -182,20 +147,15 @@ export const moneyColumn = <R extends Record<string, any>>(
182
147
  export const percentageColumn = <R extends Record<string, any>>(
183
148
  key: string,
184
149
  title: string,
185
- options?: Partial<DataGridColumn<R, DataGridFilterType>>
150
+ options?: Partial<DataGridColumn<R>>
186
151
  ): DataGridColumns<R> => ({
187
152
  [key]: {
188
153
  name: title,
189
- render: (col, row) => formatPercentage(row[key]) ?? '',
154
+ render: (row) => formatPercentage(row[key]) ?? '',
190
155
  excelFormatter: () => '#0.00',
191
156
  getter: (row) => row[key] ?? '',
192
157
  sortGetter: (row) => row[key] ?? '',
193
- filter: {
194
- type: 'number',
195
- operator: 'equals',
196
- values: [0],
197
- getter: (row) => row[key] ?? 0,
198
- },
158
+ filter: numberFilter(key),
199
159
  ...options,
200
160
  },
201
161
  });
@@ -203,11 +163,11 @@ export const percentageColumn = <R extends Record<string, any>>(
203
163
  export const checkboxColumn = <R extends Record<string, any>>(
204
164
  key: string,
205
165
  title: string,
206
- options?: Partial<DataGridColumn<R, DataGridFilterType>>
166
+ options?: Partial<DataGridColumn<R>>
207
167
  ): DataGridColumns<R> => ({
208
168
  [key]: {
209
169
  name: title,
210
- render: (col, row) => (
170
+ render: (row) => (
211
171
  <>
212
172
  <input type="checkbox" checked={row[key]} />
213
173
  <span>{row[key] ? ' Oui' : ' Non'}</span>
@@ -215,12 +175,7 @@ export const checkboxColumn = <R extends Record<string, any>>(
215
175
  ),
216
176
  getter: (row) => row[key] ?? '',
217
177
  sortGetter: (row) => row[key] ?? '',
218
- filter: {
219
- type: 'number',
220
- operator: 'equals',
221
- values: [0],
222
- getter: (row) => row[key] ?? 0,
223
- },
178
+ filter: numberFilter(key),
224
179
  ...options,
225
180
  },
226
181
  });
@@ -228,32 +183,16 @@ export const checkboxColumn = <R extends Record<string, any>>(
228
183
  export const colorColumn = <R extends Record<string, any>>(
229
184
  key: string,
230
185
  title: string,
231
- options?: Partial<DataGridColumn<R, DataGridFilterType>>
186
+ options?: Partial<DataGridColumn<R>>
232
187
  ): DataGridColumns<R> => ({
233
188
  [key]: {
234
189
  name: title,
235
- render: (col, row) => (
190
+ render: (row) => (
236
191
  <div style={{ backgroundColor: row[key] }}>{row[key] ?? ''}</div>
237
192
  ),
238
193
  getter: (row) => row[key] ?? '',
239
194
  sortGetter: (row) => row[key] ?? '',
240
- filter: {
241
- type: 'text',
242
- operator: 'contains',
243
- values: [''],
244
- getter: (row) => row[key] ?? '',
245
- },
195
+ filter: textFilter(key),
246
196
  ...options,
247
197
  },
248
198
  });
249
-
250
- export const withGroupBy = <R extends Record<string, any>>(
251
- columns: DataGridColumns<R>
252
- ): DataGridColumns<R> =>
253
- _.mapValues(columns, (column, key) => ({
254
- ...column,
255
- field: {
256
- ...(column.field ?? { fieldName: key }),
257
- groupBy: true,
258
- },
259
- }));
@@ -9,11 +9,8 @@ import {
9
9
  DataGridFilterPredicateBuilder,
10
10
  DataGridFilterPredicates,
11
11
  DataGridFilterType,
12
- DataGridFilters,
13
12
  } from '../types';
14
13
 
15
- import { ConditionDTO } from '../../../../services/advancedRequests';
16
- import _ from 'lodash';
17
14
  import moment from 'moment';
18
15
 
19
16
  const escapeRegExp = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
@@ -118,20 +115,14 @@ export const filtersPredicates: DataGridFilterPredicates = {
118
115
  },
119
116
  };
120
117
 
121
- export const applyFilters = <R>(
122
- rows: R[],
123
- filters: DataGridFilter<R, DataGridFilterType>[]
124
- ): R[] => {
118
+ export const applyFilters = <R>(rows: R[], filters: DataGridFilter[]): R[] => {
125
119
  return filters.reduce(
126
120
  (tempRows, filter) => applyFilter(tempRows, filter),
127
121
  rows
128
122
  );
129
123
  };
130
124
 
131
- export const applyFilter = <R, T extends DataGridFilterType>(
132
- rows: R[],
133
- filter: DataGridFilter<R, T>
134
- ): R[] => {
125
+ export const applyFilter = <R>(rows: R[], filter: DataGridFilter): R[] => {
135
126
  const predicateBuilder = filtersPredicates[filter.type][filter.operator];
136
127
  if (typeof predicateBuilder !== 'function') return rows;
137
128
  const predicate = predicateBuilder(...filter.values);
@@ -183,23 +174,6 @@ export const getDateGroups = <R extends string | number | null>(
183
174
  }));
184
175
  };
185
176
 
186
- export const convertFiltersToConditions = <R>(
187
- filters: DataGridFilters<R>
188
- ): ConditionDTO[] => {
189
- return Object.entries(filters).map(([columnKey, filter]) => {
190
- const condition: ConditionDTO = {
191
- field: {
192
- fieldName: columnKey,
193
- },
194
- operator: filter.operator,
195
- value: ['inArray', 'inRange'].includes(filter.operator)
196
- ? filter.values
197
- : _.castArray(filter.values)[0],
198
- };
199
- return condition;
200
- });
201
- };
202
-
203
177
  export const getCheckboxes = <R extends string | number | null>(
204
178
  values: R[],
205
179
  formatter: DataGridFilterFormatter,
@@ -217,3 +191,17 @@ export const getCheckboxes = <R extends string | number | null>(
217
191
  level,
218
192
  })),
219
193
  ];
194
+
195
+ export const textFilter = (key: string): DataGridFilter<'text'> => ({
196
+ type: 'text',
197
+ operator: 'contains',
198
+ values: [''],
199
+ getter: (row) => row[key] ?? '',
200
+ });
201
+
202
+ export const numberFilter = (key: string): DataGridFilter<'number'> => ({
203
+ type: 'number',
204
+ operator: 'equals',
205
+ values: [0],
206
+ getter: (row) => row[key] ?? '',
207
+ });
@@ -1,3 +1,2 @@
1
- export * from './columns';
2
1
  export * from './filters';
3
- export * from './advancedRequests';
2
+ export * from './columns';
@@ -1,7 +1,7 @@
1
1
  import { DataGridColumns, DataGridContext } from '../types';
2
2
  import { useContext, useMemo } from 'react';
3
3
 
4
- import { isColumnVisible } from '../helpers';
4
+ import { isColumnVisible } from '../helpers/columns';
5
5
  import { pickBy } from 'lodash';
6
6
 
7
7
  export { useDataGridCopy } from './useDataGridCopy';