@controleonline/ui-default 1.0.265 → 1.0.267
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.
- package/package.json +1 -1
- package/src/react/components/inputs/DefaultInput.js +71 -33
- package/src/react/components/inputs/DefaultInput.styles.js +36 -4
- package/src/react/components/inputs/DefaultSelect.js +83 -35
- package/src/react/components/inputs/defaultInputUtils.js +173 -26
- package/src/react/components/table/DefaultDebug.js +234 -233
- package/src/react/components/table/DefaultTable.js +431 -396
- package/src/react/components/table/DefaultTable.styles.js +69 -54
- package/src/react/components/table/DefaultTableCards.js +18 -9
- package/src/react/components/table/DefaultTableControls.js +205 -208
- package/src/react/components/table/DefaultTableFooter.js +10 -1
- package/src/react/components/table/DefaultTableRows.js +360 -333
- package/src/react/components/table/DefaultTableToolbar.js +8 -2
- package/src/react/components/table/useDefaultTableTheme.js +90 -47
- package/src/tests/react/components/table/DefaultTable.test.js +376 -241
- package/src/tests/react/inputs/defaultInputUtils.test.js +80 -9
|
@@ -1,396 +1,431 @@
|
|
|
1
|
-
import React, { useEffect, useMemo, useRef } from 'react';
|
|
2
|
-
import { View, useWindowDimensions } from 'react-native';
|
|
3
|
-
import { useIsFocused, useRoute } from '@react-navigation/native';
|
|
4
|
-
import { useStore } from '@store';
|
|
5
|
-
import { useMessage } from '@controleonline/ui-common/src/react/components/MessageService';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
[
|
|
116
|
-
);
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
} =
|
|
147
|
-
autoMode,
|
|
148
|
-
columnsForTable,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
);
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
1
|
+
import React, { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { TouchableOpacity, View, useWindowDimensions } from 'react-native';
|
|
3
|
+
import { useIsFocused, useRoute } from '@react-navigation/native';
|
|
4
|
+
import { useStore } from '@store';
|
|
5
|
+
import { useMessage } from '@controleonline/ui-common/src/react/components/MessageService';
|
|
6
|
+
import Icon from 'react-native-vector-icons/Feather';
|
|
7
|
+
import { normalizeText } from '../inputs/defaultInputUtils';
|
|
8
|
+
import { DEFAULT_COMPACT_BREAKPOINT, isObject, stableSerialize } from './DefaultTable.utils';
|
|
9
|
+
import {
|
|
10
|
+
resolveDefaultTablePreferenceScope,
|
|
11
|
+
resolveStoredTableFiltersPreference,
|
|
12
|
+
resolveStoredTableViewModePreference,
|
|
13
|
+
resolveStoredVisibleColumnsPreference,
|
|
14
|
+
sanitizeTableFiltersPreference,
|
|
15
|
+
sanitizeVisibleColumnsPreference,
|
|
16
|
+
} from '../../utils/tableVisibleColumnsPreferences';
|
|
17
|
+
import DefaultTableBody from './DefaultTableBody';
|
|
18
|
+
import DefaultTableFooter from './DefaultTableFooter';
|
|
19
|
+
import DefaultTableToolbar from './DefaultTableToolbar';
|
|
20
|
+
import styles from './DefaultTable.styles';
|
|
21
|
+
import { useDefaultTablePagination } from './useDefaultTablePagination';
|
|
22
|
+
import {
|
|
23
|
+
useDefaultTableSortedData,
|
|
24
|
+
useDefaultTableSortState,
|
|
25
|
+
} from './useDefaultTableSorting';
|
|
26
|
+
import useDefaultTableTheme from './useDefaultTableTheme';
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
mergeSortedDataWithLiveItems,
|
|
30
|
+
resolveColumnListLoadParams,
|
|
31
|
+
shouldTriggerEndReachedFromScroll,
|
|
32
|
+
} from './DefaultTable.utils';
|
|
33
|
+
|
|
34
|
+
const publishStoreValue = (store, actionName, value, getterName) => {
|
|
35
|
+
if (typeof store?.actions?.[actionName] === 'function') {
|
|
36
|
+
store.actions[actionName](value);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (store?.getters) {
|
|
41
|
+
store.getters[getterName] = value;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const assignGetterValue = (store, getterName, value) => {
|
|
46
|
+
if (store?.getters) {
|
|
47
|
+
store.getters[getterName] = value;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const DefaultTable = ({
|
|
52
|
+
accentColor = null,
|
|
53
|
+
actions = {},
|
|
54
|
+
add = null,
|
|
55
|
+
compactBreakpoint = DEFAULT_COMPACT_BREAKPOINT,
|
|
56
|
+
columns = [],
|
|
57
|
+
data = undefined,
|
|
58
|
+
filters = {},
|
|
59
|
+
footerComponent = null,
|
|
60
|
+
forceCardsOnCompact = true,
|
|
61
|
+
getOptionsForColumn = null,
|
|
62
|
+
hasMore = null,
|
|
63
|
+
initialViewMode = 'table',
|
|
64
|
+
isLoading = false,
|
|
65
|
+
onAdd = null,
|
|
66
|
+
onDataLoaded = null,
|
|
67
|
+
onEditRow = null,
|
|
68
|
+
onEndReached = null,
|
|
69
|
+
onFilterChange = null,
|
|
70
|
+
onMomentumScrollBegin = null,
|
|
71
|
+
onRowPress = null,
|
|
72
|
+
onSaved = null,
|
|
73
|
+
onScrollBeginDrag = null,
|
|
74
|
+
onSortChange = null,
|
|
75
|
+
pageSize = null,
|
|
76
|
+
pinRowActions = true,
|
|
77
|
+
renderCard = null,
|
|
78
|
+
requestParams = {},
|
|
79
|
+
rowActionsComponent = null,
|
|
80
|
+
rowStyle = null,
|
|
81
|
+
showColumnFiltersButton = true,
|
|
82
|
+
showRowActions = true,
|
|
83
|
+
showToolbar = true,
|
|
84
|
+
showTotalItemsInCompactToolbar = false,
|
|
85
|
+
showTotalItemsInFooter = true,
|
|
86
|
+
sort = null,
|
|
87
|
+
storeName = '',
|
|
88
|
+
summary = undefined,
|
|
89
|
+
summaryLabels = {},
|
|
90
|
+
toolbarActions = [],
|
|
91
|
+
visibleColumnsPreferenceKey = '',
|
|
92
|
+
}) => {
|
|
93
|
+
const { width } = useWindowDimensions();
|
|
94
|
+
const route = useRoute?.();
|
|
95
|
+
const store = useStore(storeName);
|
|
96
|
+
const isFocused = useIsFocused();
|
|
97
|
+
const configsSignatureRef = useRef('');
|
|
98
|
+
const { showError } = useMessage() || {};
|
|
99
|
+
const { tableBorderColors, themeColors } = useDefaultTableTheme(accentColor);
|
|
100
|
+
const tablePanelBorderColor = tableBorderColors.containerBorderColor;
|
|
101
|
+
const floatingAddBackgroundColor =
|
|
102
|
+
themeColors.buttonBackground || themeColors.primary || accentColor;
|
|
103
|
+
const floatingAddIconColor = themeColors.buttonText;
|
|
104
|
+
const tablePreferenceScope = useMemo(
|
|
105
|
+
() =>
|
|
106
|
+
resolveDefaultTablePreferenceScope({
|
|
107
|
+
preferenceKey: visibleColumnsPreferenceKey,
|
|
108
|
+
route,
|
|
109
|
+
storeName,
|
|
110
|
+
}),
|
|
111
|
+
[route?.key, route?.name, storeName, visibleColumnsPreferenceKey],
|
|
112
|
+
);
|
|
113
|
+
const storedViewMode = useMemo(
|
|
114
|
+
() => resolveStoredTableViewModePreference(tablePreferenceScope, null),
|
|
115
|
+
[initialViewMode, tablePreferenceScope],
|
|
116
|
+
);
|
|
117
|
+
const resolvedActions = useMemo(
|
|
118
|
+
() => ({
|
|
119
|
+
...(store?.actions || {}),
|
|
120
|
+
...(actions || {}),
|
|
121
|
+
}),
|
|
122
|
+
[actions, store?.actions],
|
|
123
|
+
);
|
|
124
|
+
const autoMode = data === undefined && normalizeText(storeName) !== '';
|
|
125
|
+
const storeColumns = Array.isArray(store?.getters?.columns) ? store.getters.columns : [];
|
|
126
|
+
const columnsForTable = storeColumns.length > 0 ? storeColumns : columns;
|
|
127
|
+
const storeFilters = isObject(store?.getters?.filters) ? store.getters.filters : {};
|
|
128
|
+
const requestParamsSeed = isObject(requestParams) ? requestParams : {};
|
|
129
|
+
const resolvedTotalItems = store?.getters?.totalItems;
|
|
130
|
+
const currentConfigs = store?.getters?.configs || {};
|
|
131
|
+
const isCompactView = width > 0 && width <= compactBreakpoint;
|
|
132
|
+
const addConfig = store?.getters?.add;
|
|
133
|
+
const shouldRenderFloatingAddButton =
|
|
134
|
+
showToolbar === false &&
|
|
135
|
+
(addConfig === true || add === true) &&
|
|
136
|
+
(typeof onAdd === 'function' || typeof store?.actions?.save === 'function');
|
|
137
|
+
|
|
138
|
+
if (storeColumns.length === 0 && Array.isArray(columns) && columns.length > 0) {
|
|
139
|
+
assignGetterValue(store, 'columns', columns);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (data !== undefined && Array.isArray(data)) {
|
|
143
|
+
assignGetterValue(store, 'items', data);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const { requestSort, resolvedSort } = useDefaultTableSortState({
|
|
147
|
+
autoMode,
|
|
148
|
+
columnsForTable,
|
|
149
|
+
onSortChange,
|
|
150
|
+
sort,
|
|
151
|
+
tablePreferenceScope,
|
|
152
|
+
});
|
|
153
|
+
const {
|
|
154
|
+
buildRequestQuery,
|
|
155
|
+
currentPage,
|
|
156
|
+
handleEndReached,
|
|
157
|
+
resolvedData,
|
|
158
|
+
} = useDefaultTablePagination({
|
|
159
|
+
autoMode,
|
|
160
|
+
columnsForTable,
|
|
161
|
+
data,
|
|
162
|
+
filters: storeFilters,
|
|
163
|
+
hasMore,
|
|
164
|
+
isFocused,
|
|
165
|
+
isLoading,
|
|
166
|
+
onEndReached,
|
|
167
|
+
pageSize,
|
|
168
|
+
requestParams: requestParamsSeed,
|
|
169
|
+
resolvedActions,
|
|
170
|
+
resolvedSort,
|
|
171
|
+
resolvedTotalItems,
|
|
172
|
+
showError,
|
|
173
|
+
store,
|
|
174
|
+
storeName,
|
|
175
|
+
});
|
|
176
|
+
const sortedData = useDefaultTableSortedData({
|
|
177
|
+
resolvedData,
|
|
178
|
+
resolvedSort,
|
|
179
|
+
storeName,
|
|
180
|
+
tableColumns: columnsForTable,
|
|
181
|
+
});
|
|
182
|
+
const debugFallbackParameters = useMemo(() => {
|
|
183
|
+
if (autoMode) {
|
|
184
|
+
return buildRequestQuery(currentPage || 1, false);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
filters: storeFilters,
|
|
189
|
+
requestParams: requestParamsSeed,
|
|
190
|
+
sort: resolvedSort || null,
|
|
191
|
+
};
|
|
192
|
+
}, [autoMode, buildRequestQuery, currentPage, requestParamsSeed, resolvedSort, storeFilters]);
|
|
193
|
+
const effectiveViewMode =
|
|
194
|
+
currentConfigs.viewMode ||
|
|
195
|
+
storedViewMode ||
|
|
196
|
+
(isCompactView && forceCardsOnCompact !== false ? 'cards' : initialViewMode);
|
|
197
|
+
const tableFiltersVisible = Boolean(currentConfigs.tableFiltersVisible);
|
|
198
|
+
const defaultTableConfigs = useMemo(
|
|
199
|
+
() => ({
|
|
200
|
+
add,
|
|
201
|
+
compactBreakpoint,
|
|
202
|
+
debugFallbackParameters,
|
|
203
|
+
effectiveViewMode,
|
|
204
|
+
filters,
|
|
205
|
+
footerComponent,
|
|
206
|
+
forceCardsOnCompact,
|
|
207
|
+
getOptionsForColumn,
|
|
208
|
+
initialViewMode,
|
|
209
|
+
onAdd,
|
|
210
|
+
onDataLoaded,
|
|
211
|
+
onEditRow,
|
|
212
|
+
onEndReached: handleEndReached,
|
|
213
|
+
onFilterChange,
|
|
214
|
+
onMomentumScrollBegin,
|
|
215
|
+
onRowPress,
|
|
216
|
+
onSaved,
|
|
217
|
+
onScrollBeginDrag,
|
|
218
|
+
pinRowActions,
|
|
219
|
+
renderCard,
|
|
220
|
+
requestParams: requestParamsSeed,
|
|
221
|
+
requestSort,
|
|
222
|
+
resolvedSort,
|
|
223
|
+
rowActionsComponent,
|
|
224
|
+
rowStyle,
|
|
225
|
+
showColumnFiltersButton,
|
|
226
|
+
showRowActions,
|
|
227
|
+
showToolbar,
|
|
228
|
+
showTotalItemsInCompactToolbar,
|
|
229
|
+
showTotalItemsInFooter,
|
|
230
|
+
sortedData,
|
|
231
|
+
summary,
|
|
232
|
+
summaryLabels,
|
|
233
|
+
tableFiltersVisible,
|
|
234
|
+
tablePreferenceScope,
|
|
235
|
+
toolbarActions,
|
|
236
|
+
viewMode: effectiveViewMode,
|
|
237
|
+
}),
|
|
238
|
+
[
|
|
239
|
+
add,
|
|
240
|
+
compactBreakpoint,
|
|
241
|
+
debugFallbackParameters,
|
|
242
|
+
effectiveViewMode,
|
|
243
|
+
filters,
|
|
244
|
+
footerComponent,
|
|
245
|
+
forceCardsOnCompact,
|
|
246
|
+
getOptionsForColumn,
|
|
247
|
+
handleEndReached,
|
|
248
|
+
initialViewMode,
|
|
249
|
+
onAdd,
|
|
250
|
+
onDataLoaded,
|
|
251
|
+
onEditRow,
|
|
252
|
+
onFilterChange,
|
|
253
|
+
onMomentumScrollBegin,
|
|
254
|
+
onRowPress,
|
|
255
|
+
onSaved,
|
|
256
|
+
onScrollBeginDrag,
|
|
257
|
+
pinRowActions,
|
|
258
|
+
renderCard,
|
|
259
|
+
requestParamsSeed,
|
|
260
|
+
requestSort,
|
|
261
|
+
resolvedSort,
|
|
262
|
+
rowActionsComponent,
|
|
263
|
+
rowStyle,
|
|
264
|
+
showColumnFiltersButton,
|
|
265
|
+
showRowActions,
|
|
266
|
+
showToolbar,
|
|
267
|
+
showTotalItemsInCompactToolbar,
|
|
268
|
+
showTotalItemsInFooter,
|
|
269
|
+
sortedData,
|
|
270
|
+
summary,
|
|
271
|
+
summaryLabels,
|
|
272
|
+
tableFiltersVisible,
|
|
273
|
+
tablePreferenceScope,
|
|
274
|
+
toolbarActions,
|
|
275
|
+
],
|
|
276
|
+
);
|
|
277
|
+
const defaultTableConfigsSignature = useMemo(
|
|
278
|
+
() =>
|
|
279
|
+
stableSerialize({
|
|
280
|
+
add,
|
|
281
|
+
compactBreakpoint,
|
|
282
|
+
debugFallbackParameters,
|
|
283
|
+
effectiveViewMode,
|
|
284
|
+
filters,
|
|
285
|
+
forceCardsOnCompact,
|
|
286
|
+
initialViewMode,
|
|
287
|
+
pinRowActions,
|
|
288
|
+
resolvedSort,
|
|
289
|
+
showColumnFiltersButton,
|
|
290
|
+
showRowActions,
|
|
291
|
+
showToolbar,
|
|
292
|
+
showTotalItemsInCompactToolbar,
|
|
293
|
+
showTotalItemsInFooter,
|
|
294
|
+
storedViewMode,
|
|
295
|
+
tableFiltersVisible,
|
|
296
|
+
sortedDataLength: sortedData.length,
|
|
297
|
+
toolbarActionsLength: Array.isArray(toolbarActions) ? toolbarActions.length : 0,
|
|
298
|
+
}),
|
|
299
|
+
[
|
|
300
|
+
add,
|
|
301
|
+
compactBreakpoint,
|
|
302
|
+
debugFallbackParameters,
|
|
303
|
+
effectiveViewMode,
|
|
304
|
+
filters,
|
|
305
|
+
forceCardsOnCompact,
|
|
306
|
+
initialViewMode,
|
|
307
|
+
pinRowActions,
|
|
308
|
+
resolvedSort,
|
|
309
|
+
showColumnFiltersButton,
|
|
310
|
+
showRowActions,
|
|
311
|
+
showToolbar,
|
|
312
|
+
showTotalItemsInCompactToolbar,
|
|
313
|
+
showTotalItemsInFooter,
|
|
314
|
+
storedViewMode,
|
|
315
|
+
tableFiltersVisible,
|
|
316
|
+
sortedData.length,
|
|
317
|
+
toolbarActions,
|
|
318
|
+
],
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
if (store?.getters) {
|
|
322
|
+
assignGetterValue(store, 'configs', defaultTableConfigs);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
useEffect(() => {
|
|
326
|
+
if (storeColumns.length > 0 || !Array.isArray(columns) || columns.length === 0) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
publishStoreValue(store, 'setColumns', columns, 'columns');
|
|
331
|
+
}, [columns, store, storeColumns.length]);
|
|
332
|
+
|
|
333
|
+
useEffect(() => {
|
|
334
|
+
if (data === undefined || !Array.isArray(data)) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
publishStoreValue(store, 'setItems', data, 'items');
|
|
339
|
+
}, [data, store]);
|
|
340
|
+
|
|
341
|
+
useEffect(() => {
|
|
342
|
+
if (!columnsForTable.length) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const storedVisibleColumns = resolveStoredVisibleColumnsPreference(tablePreferenceScope);
|
|
347
|
+
if (!storedVisibleColumns) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const nextVisibleColumns = sanitizeVisibleColumnsPreference({
|
|
352
|
+
columns: columnsForTable,
|
|
353
|
+
visibleColumns: storedVisibleColumns,
|
|
354
|
+
});
|
|
355
|
+
const currentVisibleColumns = store?.getters?.visibleColumns || {};
|
|
356
|
+
|
|
357
|
+
if (stableSerialize(currentVisibleColumns) === stableSerialize(nextVisibleColumns)) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
publishStoreValue(store, 'setVisibleColumns', nextVisibleColumns, 'visibleColumns');
|
|
362
|
+
}, [columnsForTable, store, tablePreferenceScope]);
|
|
363
|
+
|
|
364
|
+
useEffect(() => {
|
|
365
|
+
if (!columnsForTable.length || Object.keys(storeFilters).length > 0) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const storedFilters = resolveStoredTableFiltersPreference(tablePreferenceScope);
|
|
370
|
+
if (!storedFilters) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const nextFilters = sanitizeTableFiltersPreference({
|
|
375
|
+
columns: columnsForTable,
|
|
376
|
+
filters: storedFilters,
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
if (Object.keys(nextFilters).length === 0) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
publishStoreValue(store, 'setFilters', nextFilters, 'filters');
|
|
384
|
+
}, [columnsForTable, store, storeFilters, tablePreferenceScope]);
|
|
385
|
+
|
|
386
|
+
useEffect(() => {
|
|
387
|
+
if (configsSignatureRef.current === defaultTableConfigsSignature) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
configsSignatureRef.current = defaultTableConfigsSignature;
|
|
392
|
+
publishStoreValue(store, 'setConfigs', defaultTableConfigs, 'configs');
|
|
393
|
+
}, [defaultTableConfigs, defaultTableConfigsSignature, store]);
|
|
394
|
+
|
|
395
|
+
useEffect(() => {
|
|
396
|
+
onDataLoaded?.(sortedData);
|
|
397
|
+
}, [onDataLoaded, sortedData]);
|
|
398
|
+
|
|
399
|
+
return (
|
|
400
|
+
<View
|
|
401
|
+
style={[
|
|
402
|
+
styles.wrap,
|
|
403
|
+
{
|
|
404
|
+
borderWidth: tablePanelBorderColor ? 1 : 0,
|
|
405
|
+
borderColor: tablePanelBorderColor,
|
|
406
|
+
backgroundColor: themeColors.panelBackground,
|
|
407
|
+
},
|
|
408
|
+
]}
|
|
409
|
+
>
|
|
410
|
+
{showToolbar !== false ? <DefaultTableToolbar storeName={storeName} /> : null}
|
|
411
|
+
<DefaultTableBody storeName={storeName} />
|
|
412
|
+
<DefaultTableFooter storeName={storeName} />
|
|
413
|
+
{shouldRenderFloatingAddButton ? (
|
|
414
|
+
<TouchableOpacity
|
|
415
|
+
accessibilityRole="button"
|
|
416
|
+
accessibilityLabel={global.t?.t(storeName, 'button', 'add') || 'Adicionar'}
|
|
417
|
+
activeOpacity={0.84}
|
|
418
|
+
style={[
|
|
419
|
+
styles.floatingAddButton,
|
|
420
|
+
{ backgroundColor: floatingAddBackgroundColor },
|
|
421
|
+
]}
|
|
422
|
+
onPress={() => onAdd?.()}
|
|
423
|
+
>
|
|
424
|
+
<Icon name="plus" size={24} color={floatingAddIconColor} />
|
|
425
|
+
</TouchableOpacity>
|
|
426
|
+
) : null}
|
|
427
|
+
</View>
|
|
428
|
+
);
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
export default DefaultTable;
|