mig-schema-table 3.0.40 → 3.0.42

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.
@@ -314,6 +314,18 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
314
314
  delete newColumnFilterMap[propName];
315
315
  setColumnFilterMap(newColumnFilterMap);
316
316
  }, [columnFilterMap]);
317
+ const onSetSortColumn = React.useCallback((x) => {
318
+ if (data instanceof Function) {
319
+ setIsDirty(true);
320
+ }
321
+ setSortColumn(x);
322
+ }, [data]);
323
+ const onSetSortAsc = React.useCallback((x) => {
324
+ if (data instanceof Function) {
325
+ setIsDirty(true);
326
+ }
327
+ setSortAsc(x);
328
+ }, [data]);
317
329
  const SchemaTableTh = React.useCallback(({ style, index }) => {
318
330
  const propName = columnNames[index];
319
331
  const propConfig = config ? config[propName] : undefined;
@@ -326,7 +338,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
326
338
  const schema = (propName === SELECT_ALL_COLUMN_NAME
327
339
  ? { type: "boolean" }
328
340
  : properties[propName]);
329
- return (_jsx(Th, { isAllChecked: isAllRowsChecked, columnFilterStatus: columnFilterStatus, disableColumnFilter: disableColumnFilter, isSortable: !!isSortable, numberOfSelectedRows: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length, onSelectAllIndexesHandler: onSelectAllIndexesHandler, propConfig: propConfig, propName: propName, schema: schema, setPopoverConfig: setPopoverConfig, setSortAsc: setSortAsc, setSortColumn: setSortColumn, sortAsc: sortColumn === propName ? sortAsc : undefined, style: style }));
341
+ return (_jsx(Th, { isAllChecked: isAllRowsChecked, columnFilterStatus: columnFilterStatus, disableColumnFilter: disableColumnFilter, isSortable: !!isSortable, numberOfSelectedRows: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length, onSelectAllIndexesHandler: onSelectAllIndexesHandler, propConfig: propConfig, propName: propName, schema: schema, setPopoverConfig: setPopoverConfig, setSortAsc: onSetSortAsc, setSortColumn: onSetSortColumn, sortAsc: sortColumn === propName ? sortAsc : undefined, style: style }));
330
342
  }, [
331
343
  checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length,
332
344
  columnFilterMap,
@@ -337,6 +349,8 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
337
349
  isColumnFilterable,
338
350
  isSortable,
339
351
  onSelectAllIndexesHandler,
352
+ onSetSortAsc,
353
+ onSetSortColumn,
340
354
  properties,
341
355
  sortAsc,
342
356
  sortColumn,
@@ -367,6 +381,15 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
367
381
  }
368
382
  setSearchQuery(e.currentTarget.value);
369
383
  }, [data]);
384
+ const refreshData = React.useCallback(() => {
385
+ setIsDirty(false);
386
+ setSourceData(undefined);
387
+ }, []);
388
+ const onSearchKeyDown = React.useCallback((e) => {
389
+ if (e.key === "Enter" && isDirty) {
390
+ refreshData();
391
+ }
392
+ }, [isDirty, refreshData]);
370
393
  const getRowHeight = React.useCallback(() => rowHeight, [rowHeight]);
371
394
  const rowWidth = dynamicWidthColumnCount ? width : fixedWidthColumnsWidth;
372
395
  const rowCount = React.useMemo(() => (sortedRenderData ? sortedRenderData.length : 0), [sortedRenderData]);
@@ -384,17 +407,16 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
384
407
  if (!popoverConfig) {
385
408
  return;
386
409
  }
410
+ if (data instanceof Function) {
411
+ setIsDirty(true);
412
+ }
387
413
  if (newColumnFilterValue === undefined) {
388
414
  disableColumnFilter(popoverConfig.propName);
389
415
  return;
390
416
  }
391
417
  setColumnFilterMap((columnFilterMap) => (Object.assign(Object.assign({}, columnFilterMap), { [popoverConfig.propName]: newColumnFilterValue })));
392
- }, [disableColumnFilter, popoverConfig]);
393
- const onRefreshDataClick = React.useCallback(() => {
394
- setIsDirty(false);
395
- setSourceData(undefined);
396
- }, []);
397
- 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, autoFocus: true })) : null })), customElement] })), _jsx(Heading, Object.assign({ height: 50, itemCount: columnCount, itemSize: getColumnWidth, layout: "horizontal", width: rowWidth, sortAsc: sortAsc, setSortAsc: setSortAsc, setSortColumn: setSortColumn, 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: {
418
+ }, [data, disableColumnFilter, popoverConfig]);
419
+ 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: onSearchKeyDown, 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: {
398
420
  width: rowWidth,
399
421
  height: Math.max(50, tableBodyHeight),
400
422
  border: "1px solid #BBB",
@@ -403,6 +425,6 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
403
425
  backgroundColor: "#CCC",
404
426
  alignItems: "center",
405
427
  justifyContent: "center",
406
- } }, { children: isDirty ? (_jsx("button", Object.assign({ onClick: onRefreshDataClick, className: "btn border" }, { children: "Refresh data" }))) : (_jsx("div", { children: "\u231B Loading..." })) }))), popoverConfig ? (_jsx(SchemaColumnFilterPopover, { referenceElement: popoverConfig.referenceElement, onClose: onPopoverClose, onChange: onSchemaColumnFilterChange, propName: popoverConfig.propName, propSchema: schema.properties[popoverConfig.propName], value: columnFilterMap[popoverConfig.propName], propConfig: popoverConfig.propConfig })) : null] })));
428
+ } }, { children: isDirty ? (_jsx("button", Object.assign({ onClick: refreshData, className: "btn border" }, { children: "Refresh data" }))) : (_jsx("div", { children: "\u231B Loading..." })) }))), popoverConfig ? (_jsx(SchemaColumnFilterPopover, { referenceElement: popoverConfig.referenceElement, onClose: onPopoverClose, onChange: onSchemaColumnFilterChange, propName: popoverConfig.propName, propSchema: schema.properties[popoverConfig.propName], value: columnFilterMap[popoverConfig.propName], propConfig: popoverConfig.propConfig })) : null] })));
407
429
  }
408
430
  export default React.memo(SchemaTable);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mig-schema-table",
3
- "version": "3.0.40",
3
+ "version": "3.0.42",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/"