mig-schema-table 3.0.57 → 3.0.59

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.
@@ -9,6 +9,20 @@ import Td from "./Td";
9
9
  import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT } from "../inc/constant";
10
10
  import SchemaColumnFilterPopover from "./SchemaColumnFilterPopover";
11
11
  const startOfTheWorldDate = new Date("1000-01-01 00:00:00Z");
12
+ function getSortByValue(propSchema, propConfig) {
13
+ var _a;
14
+ if ((propConfig === null || propConfig === void 0 ? void 0 : propConfig.sortByValue) !== undefined) {
15
+ return propConfig === null || propConfig === void 0 ? void 0 : propConfig.sortByValue;
16
+ }
17
+ if (!propSchema) {
18
+ return false;
19
+ }
20
+ const isDate = propSchema && ((_a = propSchema.format) === null || _a === void 0 ? void 0 : _a.startsWith("date"));
21
+ return (isDate ||
22
+ propSchema.type === "boolean" ||
23
+ propSchema.type === "integer" ||
24
+ !!(propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell));
25
+ }
12
26
  function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheckedIndexes, config, customElement, data, defaultColumnFilters = {}, defaultSortAsc = false, defaultSortColumn, getRowClassName, getRowSelected, maxHeight, isSearchable, isColumnFilterable, isSortable, onCheckedIndexesChange, onRowClick, rowHeight = 36, schema, searchPlaceholder, style, width, onRowDoubleClick, enableAutoFocus, }) {
13
27
  const [sortColumn, setSortColumn] = React.useState(defaultSortColumn);
14
28
  const [sortAsc, setSortAsc] = React.useState(defaultSortAsc);
@@ -254,6 +268,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
254
268
  ]);
255
269
  // Sort the filtered data
256
270
  const sortedRenderData = React.useMemo(() => {
271
+ var _a;
257
272
  if (!sortColumn || !filteredRenderData || !sourceData || isDataFunction) {
258
273
  return filteredRenderData;
259
274
  }
@@ -273,16 +288,9 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
273
288
  return columnSort(aData, bData, sortAsc);
274
289
  });
275
290
  }
291
+ const isDate = sortSchema && ((_a = sortSchema.format) === null || _a === void 0 ? void 0 : _a.startsWith("date"));
292
+ const sortByValue = getSortByValue(sortSchema, propConfig);
276
293
  return filteredRenderData.sort((a, b) => {
277
- var _a;
278
- const isDate = sortSchema && ((_a = sortSchema.format) === null || _a === void 0 ? void 0 : _a.startsWith("date"));
279
- const sortByValue = (propConfig === null || propConfig === void 0 ? void 0 : propConfig.sortByValue) === undefined
280
- ? !sortSchema ||
281
- isDate ||
282
- sortSchema.type === "boolean" ||
283
- sortSchema.type === "integer" ||
284
- (propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell)
285
- : propConfig.sortByValue;
286
294
  let x = sortByValue && sourceData[a._index]
287
295
  ? // @ts-ignore
288
296
  sourceData[a._index][sortColumn]
@@ -353,17 +361,17 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
353
361
  }, [isDataFunction]);
354
362
  const SchemaTableTh = React.useCallback(({ style, index }) => {
355
363
  const propName = columnNames[index];
364
+ const propSchema = (propName === SELECT_ALL_COLUMN_NAME
365
+ ? { type: "boolean" }
366
+ : properties[propName]);
356
367
  const propConfig = config ? config[propName] : undefined;
357
- let columnFilterStatus = isColumnFilterable && propConfig && propConfig.isFilterable !== false
368
+ let columnFilterStatus = isColumnFilterable && propSchema && (propConfig === null || propConfig === void 0 ? void 0 : propConfig.isFilterable) !== false
358
369
  ? EColumnFilterStatus.AVAILABLE
359
370
  : EColumnFilterStatus.UNAVAILABLE;
360
371
  if (columnFilterMap[propName] !== undefined) {
361
372
  columnFilterStatus = EColumnFilterStatus.ACTIVE;
362
373
  }
363
- const schema = (propName === SELECT_ALL_COLUMN_NAME
364
- ? { type: "boolean" }
365
- : properties[propName]);
366
- 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, propIsRequired: required.includes(propName), propName: propName, schema: schema, setPopoverConfig: setPopoverConfig, setSortAsc: onSetSortAsc, setSortColumn: onSetSortColumn, sortAsc: sortColumn === propName ? sortAsc : undefined, style: style }));
374
+ 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, propIsRequired: required.includes(propName), propName: propName, schema: propSchema, setPopoverConfig: setPopoverConfig, setSortAsc: onSetSortAsc, setSortColumn: onSetSortColumn, sortAsc: sortColumn === propName ? sortAsc : undefined, style: style }));
367
375
  }, [
368
376
  checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length,
369
377
  columnFilterMap,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mig-schema-table",
3
- "version": "3.0.57",
3
+ "version": "3.0.59",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/"