mig-schema-table 3.0.44 → 3.0.46
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.
|
@@ -7,7 +7,7 @@ interface ITdProps<T> {
|
|
|
7
7
|
columnIndex: number;
|
|
8
8
|
data: T[];
|
|
9
9
|
getRowClassName?: (rowData: T, dataIndex: number) => string;
|
|
10
|
-
getRowSelected?: (rowData: T) => boolean;
|
|
10
|
+
getRowSelected?: (rowData: T, dataIndex: number) => boolean;
|
|
11
11
|
rowHeight: number;
|
|
12
12
|
rowIndex: number;
|
|
13
13
|
onCheckedIndexesChange?: (dataIndex: number[]) => void;
|
|
@@ -39,7 +39,7 @@ function Td({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowC
|
|
|
39
39
|
key: propName,
|
|
40
40
|
style: Object.assign(Object.assign({}, style), { lineHeight: `${rowHeight}px` }),
|
|
41
41
|
onClick: !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell) ? onTdClick : undefined,
|
|
42
|
-
className: `schema-table__td schema-table__td--${rowIndex % 2 ? "odd" : "even"}${getRowSelected && getRowSelected(data[row._index])
|
|
42
|
+
className: `schema-table__td schema-table__td--${rowIndex % 2 ? "odd" : "even"}${getRowSelected && getRowSelected(data[row._index], row._index)
|
|
43
43
|
? " schema-table__td--selected"
|
|
44
44
|
: ""} ${getRowClassName ? getRowClassName(data[row._index], row._index) : ""}`,
|
|
45
45
|
title,
|
|
@@ -21,7 +21,7 @@ export interface ISchemaTableProps<T> {
|
|
|
21
21
|
defaultSortAsc?: boolean;
|
|
22
22
|
defaultSortColumn?: keyof T;
|
|
23
23
|
getRowClassName?: (rowData: T, dataIndex: number) => string;
|
|
24
|
-
getRowSelected?: (rowData: T) => boolean;
|
|
24
|
+
getRowSelected?: (rowData: T, dataIndex: number) => boolean;
|
|
25
25
|
maxHeight?: number;
|
|
26
26
|
isSearchable?: boolean;
|
|
27
27
|
isColumnFilterable?: boolean;
|
|
@@ -15,19 +15,32 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
|
|
|
15
15
|
const [searchQuery, setSearchQuery] = React.useState("");
|
|
16
16
|
const [columnFilterMap, setColumnFilterMap] = React.useState({});
|
|
17
17
|
const [popoverConfig, setPopoverConfig] = React.useState();
|
|
18
|
-
const
|
|
18
|
+
const isDataFunction = data instanceof Function;
|
|
19
|
+
const [sourceData, setSourceData] = React.useState(isDataFunction ? undefined : data);
|
|
19
20
|
const [isDirty, setIsDirty] = React.useState(false);
|
|
20
21
|
React.useEffect(() => {
|
|
21
|
-
if (sourceData !== undefined
|
|
22
|
+
if (sourceData !== undefined) {
|
|
22
23
|
return;
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
if (isDataFunction) {
|
|
26
|
+
data({
|
|
27
|
+
searchQuery,
|
|
28
|
+
columnFilterMap,
|
|
29
|
+
sortColumn,
|
|
30
|
+
sortAsc,
|
|
31
|
+
}).then(setSourceData);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
setSourceData(data);
|
|
35
|
+
}, [
|
|
36
|
+
columnFilterMap,
|
|
37
|
+
data,
|
|
38
|
+
isDataFunction,
|
|
39
|
+
searchQuery,
|
|
40
|
+
sortAsc,
|
|
41
|
+
sortColumn,
|
|
42
|
+
sourceData,
|
|
43
|
+
]);
|
|
31
44
|
const { properties = {} } = schema;
|
|
32
45
|
const columnNames = React.useMemo(() => {
|
|
33
46
|
const columns = Object.keys(properties);
|
|
@@ -171,7 +184,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
|
|
|
171
184
|
const filteredRenderData = React.useMemo(() => {
|
|
172
185
|
if (!renderData ||
|
|
173
186
|
(!isColumnFilterable && !isSearchable) ||
|
|
174
|
-
|
|
187
|
+
isDataFunction) {
|
|
175
188
|
return renderData;
|
|
176
189
|
}
|
|
177
190
|
return renderData.filter((item) => {
|
|
@@ -220,7 +233,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
|
|
|
220
233
|
renderData,
|
|
221
234
|
isColumnFilterable,
|
|
222
235
|
isSearchable,
|
|
223
|
-
|
|
236
|
+
isDataFunction,
|
|
224
237
|
searchQuery,
|
|
225
238
|
columnNames,
|
|
226
239
|
columnFilterMap,
|
|
@@ -229,10 +242,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
|
|
|
229
242
|
]);
|
|
230
243
|
// Sort the filtered data
|
|
231
244
|
const sortedRenderData = React.useMemo(() => {
|
|
232
|
-
if (!sortColumn ||
|
|
233
|
-
!filteredRenderData ||
|
|
234
|
-
!sourceData ||
|
|
235
|
-
data instanceof Function) {
|
|
245
|
+
if (!sortColumn || !filteredRenderData || !sourceData || isDataFunction) {
|
|
236
246
|
return filteredRenderData;
|
|
237
247
|
}
|
|
238
248
|
const sortSchema = properties[sortColumn];
|
|
@@ -288,7 +298,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
|
|
|
288
298
|
sortColumn,
|
|
289
299
|
filteredRenderData,
|
|
290
300
|
sourceData,
|
|
291
|
-
|
|
301
|
+
isDataFunction,
|
|
292
302
|
properties,
|
|
293
303
|
config,
|
|
294
304
|
sortAsc,
|
|
@@ -312,23 +322,23 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
|
|
|
312
322
|
const disableColumnFilter = React.useCallback((propName) => {
|
|
313
323
|
const newColumnFilterMap = Object.assign({}, columnFilterMap);
|
|
314
324
|
delete newColumnFilterMap[propName];
|
|
315
|
-
if (
|
|
325
|
+
if (isDataFunction) {
|
|
316
326
|
setIsDirty(true);
|
|
317
327
|
}
|
|
318
328
|
setColumnFilterMap(newColumnFilterMap);
|
|
319
|
-
}, [columnFilterMap,
|
|
329
|
+
}, [columnFilterMap, isDataFunction]);
|
|
320
330
|
const onSetSortColumn = React.useCallback((x) => {
|
|
321
|
-
if (
|
|
331
|
+
if (isDataFunction) {
|
|
322
332
|
setIsDirty(true);
|
|
323
333
|
}
|
|
324
334
|
setSortColumn(x);
|
|
325
|
-
}, [
|
|
335
|
+
}, [isDataFunction]);
|
|
326
336
|
const onSetSortAsc = React.useCallback((x) => {
|
|
327
|
-
if (
|
|
337
|
+
if (isDataFunction) {
|
|
328
338
|
setIsDirty(true);
|
|
329
339
|
}
|
|
330
340
|
setSortAsc(x);
|
|
331
|
-
}, [
|
|
341
|
+
}, [isDataFunction]);
|
|
332
342
|
const SchemaTableTh = React.useCallback(({ style, index }) => {
|
|
333
343
|
const propName = columnNames[index];
|
|
334
344
|
const propConfig = config ? config[propName] : undefined;
|
|
@@ -379,11 +389,11 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
|
|
|
379
389
|
sortedRenderData,
|
|
380
390
|
]);
|
|
381
391
|
const onSearchChange = React.useCallback((e) => {
|
|
382
|
-
if (
|
|
392
|
+
if (isDataFunction) {
|
|
383
393
|
setIsDirty(true);
|
|
384
394
|
}
|
|
385
395
|
setSearchQuery(e.currentTarget.value);
|
|
386
|
-
}, [
|
|
396
|
+
}, [isDataFunction]);
|
|
387
397
|
const refreshData = React.useCallback(() => {
|
|
388
398
|
setIsDirty(false);
|
|
389
399
|
setSourceData(undefined);
|
|
@@ -413,7 +423,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
|
|
|
413
423
|
if (!popoverConfig) {
|
|
414
424
|
return;
|
|
415
425
|
}
|
|
416
|
-
if (
|
|
426
|
+
if (isDataFunction) {
|
|
417
427
|
setIsDirty(true);
|
|
418
428
|
}
|
|
419
429
|
if (newColumnFilterValue === undefined) {
|
|
@@ -421,7 +431,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
|
|
|
421
431
|
return;
|
|
422
432
|
}
|
|
423
433
|
setColumnFilterMap((columnFilterMap) => (Object.assign(Object.assign({}, columnFilterMap), { [popoverConfig.propName]: newColumnFilterValue })));
|
|
424
|
-
}, [
|
|
434
|
+
}, [disableColumnFilter, isDataFunction, popoverConfig]);
|
|
425
435
|
return (_jsxs("div", Object.assign({ className: `schema-table${onRowClick ? " schema-table--clickable-rows" : ""}`, style: Object.assign(Object.assign({}, style), { width: rowWidth }), role: "table" }, { children: [_jsxs("div", Object.assign({ className: "schema-table__action-container" }, { children: [_jsx("div", Object.assign({ style: { flex: 1 } }, { children: isSearchable ? (_jsx("input", { type: "text", placeholder: searchPlaceholder || "Search...", value: searchQuery, onChange: onSearchChange, onKeyDown: onInputKeyDown, autoFocus: true })) : null })), customElement] })), _jsx(Heading, Object.assign({ height: 50, itemCount: columnCount, itemSize: getColumnWidth, layout: "horizontal", width: rowWidth, sortAsc: sortAsc, setSortAsc: onSetSortAsc, setSortColumn: onSetSortColumn, sortColumn: sortColumn, sortedRenderData: sortedRenderData, className: "schema-table__th-row" }, { children: SchemaTableTh }), `thead_${rowWidth}_${sortColumn}_${sortAsc}_${searchQuery}`), sourceData && !isDirty ? (_jsx(VariableSizeGrid, Object.assign({ className: "schema-table__tbody", height: tableBodyHeight, width: rowWidth, columnWidth: getColumnWidth, rowHeight: getRowHeight, columnCount: columnCount, rowCount: rowCount }, { children: SchemaTableTd }), `tbody_${tableBodyHeight}_${rowWidth}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}`)) : (_jsx("div", Object.assign({ style: {
|
|
426
436
|
width: rowWidth,
|
|
427
437
|
height: Math.max(50, tableBodyHeight),
|