mig-schema-table 3.0.36 → 3.0.37

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.
@@ -1,6 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import React from "react";
3
3
  import { SELECT_ALL_COLUMN_NAME } from "../constants";
4
+ import { localeFormatInTimeZone, timeZone } from "../../inc/date";
5
+ import { DEFAULT_DATE_TIME_FORMAT } from "../../inc/constant";
6
+ import { t } from "../../inc/string";
4
7
  function Td({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, propConfig, propName, propSchema, rowHeight, rowIndex, sortedRenderData, style, }) {
5
8
  const onTdClick = React.useCallback((e) => {
6
9
  if (!sortedRenderData || !onRowClick) {
@@ -18,6 +21,18 @@ function Td({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowC
18
21
  if (!row) {
19
22
  return undefined;
20
23
  }
24
+ let title = propName === SELECT_ALL_COLUMN_NAME ? null : row[propName];
25
+ if (propSchema.format &&
26
+ propSchema.format.startsWith("date") &&
27
+ (propConfig === null || propConfig === void 0 ? void 0 : propConfig.showTimezones) !== false) {
28
+ // @ts-ignore
29
+ const dateString = data[row._index][propName];
30
+ const date = dateString ? new Date(dateString) : undefined;
31
+ const alternativeTimeZone = timeZone === "Europe/Amsterdam" ? "Asia/Jakarta" : "Europe/Amsterdam";
32
+ if (date) {
33
+ title = `${localeFormatInTimeZone(date, alternativeTimeZone, DEFAULT_DATE_TIME_FORMAT)} (${t(alternativeTimeZone)})`;
34
+ }
35
+ }
21
36
  return {
22
37
  "data-row-index": rowIndex,
23
38
  "data-column-index": columnIndex,
@@ -27,7 +42,7 @@ function Td({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowC
27
42
  className: `schema-table__td schema-table__td--${rowIndex % 2 ? "odd" : "even"}${getRowSelected && getRowSelected(data[row._index])
28
43
  ? " schema-table__td--selected"
29
44
  : ""} ${getRowClassName ? getRowClassName(data[row._index], row._index) : ""}`,
30
- title: propName === SELECT_ALL_COLUMN_NAME ? null : row[propName],
45
+ title,
31
46
  };
32
47
  }, [
33
48
  columnIndex,
@@ -35,8 +50,9 @@ function Td({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowC
35
50
  getRowClassName,
36
51
  getRowSelected,
37
52
  onTdClick,
38
- propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell,
53
+ propConfig,
39
54
  propName,
55
+ propSchema,
40
56
  row,
41
57
  rowHeight,
42
58
  rowIndex,
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
- import { uncamel } from "../../inc/string";
3
+ import { t, uncamel } from "../../inc/string";
4
4
  import { SELECT_ALL_COLUMN_NAME } from "../constants";
5
+ import { timeZone } from "../../inc/date";
5
6
  export var EColumnFilterStatus;
6
7
  (function (EColumnFilterStatus) {
7
8
  EColumnFilterStatus["UNAVAILABLE"] = "UNAVAILABLE";
@@ -54,6 +55,17 @@ const Th = ({ isAllChecked, columnFilterStatus, disableColumnFilter, isSortable,
54
55
  propName,
55
56
  setPopoverConfig,
56
57
  ]);
58
+ const labelBody = React.useMemo(() => {
59
+ if ((propConfig === null || propConfig === void 0 ? void 0 : propConfig.title) !== undefined) {
60
+ return propConfig.title;
61
+ }
62
+ if (schema.format &&
63
+ schema.format.startsWith("date") &&
64
+ (propConfig === null || propConfig === void 0 ? void 0 : propConfig.showTimezones) !== false) {
65
+ return `${uncamel(propName)} (${t(timeZone)})`;
66
+ }
67
+ return uncamel(propName);
68
+ }, [propConfig, propName, schema.format]);
57
69
  if (propName === SELECT_ALL_COLUMN_NAME) {
58
70
  return (_jsx("div", Object.assign({}, thDivProps, { children: _jsx("div", Object.assign({ style: {
59
71
  width: "100%",
@@ -76,10 +88,6 @@ const Th = ({ isAllChecked, columnFilterStatus, disableColumnFilter, isSortable,
76
88
  thDivProps.className += ` text-${propConfig.align}`;
77
89
  }
78
90
  }
79
- return (_jsxs("div", Object.assign({}, thDivProps, { children: [isSortable ? (_jsxs("button", Object.assign({ className: "px-0", disabled: (propConfig === null || propConfig === void 0 ? void 0 : propConfig.sortable) === false, onClick: onSortButtonClick }, { children: [(propConfig === null || propConfig === void 0 ? void 0 : propConfig.title) === undefined
80
- ? uncamel(propName)
81
- : propConfig === null || propConfig === void 0 ? void 0 : propConfig.title, sortAsc === undefined ? null : sortAsc ? "▲" : "▼"] }))) : (_jsx("div", Object.assign({ style: { lineHeight: "44px" } }, { children: (propConfig === null || propConfig === void 0 ? void 0 : propConfig.title) === undefined
82
- ? uncamel(propName)
83
- : propConfig === null || propConfig === void 0 ? void 0 : propConfig.title }))), columnFilterStatus !== EColumnFilterStatus.UNAVAILABLE ? (_jsx("button", Object.assign({ onClick: onFilterButtonClick, "data-bs-toggle": "dropdown" }, { children: _jsx("svg", Object.assign({ viewBox: "0 0 36 36", xmlns: "http://www.w3.org/2000/svg", height: 16, width: 16, style: { display: "block" }, fill: "currentColor" }, { children: _jsx("polygon", { points: "14,30 22,25 22,17 35.999,0 17.988,0 0,0 14,17 " }) })) }))) : null] })));
91
+ return (_jsxs("div", Object.assign({}, thDivProps, { children: [isSortable ? (_jsxs("button", Object.assign({ className: "px-0", disabled: (propConfig === null || propConfig === void 0 ? void 0 : propConfig.sortable) === false, onClick: onSortButtonClick }, { children: [labelBody, sortAsc === undefined ? null : sortAsc ? "▲" : "▼"] }))) : (_jsx("div", Object.assign({ style: { lineHeight: "44px" } }, { children: labelBody }))), columnFilterStatus !== EColumnFilterStatus.UNAVAILABLE ? (_jsx("button", Object.assign({ onClick: onFilterButtonClick, "data-bs-toggle": "dropdown" }, { children: _jsx("svg", Object.assign({ viewBox: "0 0 36 36", xmlns: "http://www.w3.org/2000/svg", height: 16, width: 16, style: { display: "block" }, fill: "currentColor" }, { children: _jsx("polygon", { points: "14,30 22,25 22,17 35.999,0 17.988,0 0,0 14,17 " }) })) }))) : null] })));
84
92
  };
85
93
  export default React.memo(Th);
@@ -296,7 +296,10 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
296
296
  if (columnFilterMap[propName] !== undefined) {
297
297
  columnFilterStatus = EColumnFilterStatus.ACTIVE;
298
298
  }
299
- 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: properties[propName], setPopoverConfig: setPopoverConfig, setSortAsc: setSortAsc, setSortColumn: setSortColumn, sortAsc: sortColumn === propName ? sortAsc : undefined, style: style }));
299
+ const schema = (propName === SELECT_ALL_COLUMN_NAME
300
+ ? { type: "boolean" }
301
+ : properties[propName]);
302
+ 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 }));
300
303
  }, [
301
304
  checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length,
302
305
  columnFilterMap,
@@ -313,7 +316,10 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
313
316
  ]);
314
317
  const SchemaTableTd = React.useCallback(({ columnIndex, rowIndex, style }) => {
315
318
  const propName = columnNames[columnIndex];
316
- return (_jsx(Td, { checkedIndexes: checkedIndexes, disabledCheckedIndexes: disabledCheckedIndexes, columnIndex: columnIndex, data: data, getRowClassName: getRowClassName, getRowSelected: getRowSelected, onCheckedIndexesChange: onCheckedIndexesChange, onRowClick: onRowClick, propConfig: config ? config[propName] : undefined, propName: propName, propSchema: properties[propName], rowHeight: rowHeight, rowIndex: rowIndex, sortedRenderData: sortedRenderData, style: style }));
319
+ const propSchema = (propName === SELECT_ALL_COLUMN_NAME
320
+ ? { type: "boolean" }
321
+ : properties[propName]);
322
+ return (_jsx(Td, { checkedIndexes: checkedIndexes, disabledCheckedIndexes: disabledCheckedIndexes, columnIndex: columnIndex, data: data, getRowClassName: getRowClassName, getRowSelected: getRowSelected, onCheckedIndexesChange: onCheckedIndexesChange, onRowClick: onRowClick, propConfig: config ? config[propName] : undefined, propName: propName, propSchema: propSchema, rowHeight: rowHeight, rowIndex: rowIndex, sortedRenderData: sortedRenderData, style: style }));
317
323
  }, [
318
324
  checkedIndexes,
319
325
  columnNames,
@@ -1 +1,3 @@
1
1
  export declare const localeFormat: (date: Date | number, dateFormat: string) => string;
2
+ export declare const localeFormatInTimeZone: (date: Date | number, timezone: string, dateFormat: string) => string;
3
+ export declare const timeZone: string;
package/dist/inc/date.js CHANGED
@@ -1,3 +1,7 @@
1
1
  import { format } from "date-fns";
2
+ import { formatInTimeZone } from "date-fns-tz";
2
3
  import nl from "date-fns/locale/nl";
3
4
  export const localeFormat = (date, dateFormat) => format(date, dateFormat, { locale: nl });
5
+ export const localeFormatInTimeZone = (date, timezone, dateFormat) => formatInTimeZone(date, timezone, dateFormat, { locale: nl });
6
+ // E.g. Europe/Amsterdam or Asia/Jakarta
7
+ export const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -1,4 +1,4 @@
1
1
  export declare function uncamel(camel: string): string;
2
- export declare function t(key: string, db: {
3
- [keyName: string]: string;
2
+ export declare function t(key: string, db?: {
3
+ [key: string]: string;
4
4
  }): string;
@@ -15,6 +15,9 @@ export function uncamel(camel) {
15
15
  return ` ${nextIsUppercase ? letter : letter.toLowerCase()}`;
16
16
  }));
17
17
  }
18
- export function t(key, db) {
18
+ export function t(key, db = {
19
+ "Europe/Amsterdam": "AMS",
20
+ "Asia/Jakarta": "JKT",
21
+ }) {
19
22
  return db[key] || uncamel(key);
20
23
  }
package/dist/types.d.ts CHANGED
@@ -1,22 +1,23 @@
1
1
  import React from "react";
2
2
  export interface IColumnConfig<T> {
3
3
  align?: "start" | "center" | "end";
4
+ dateFormat?: string;
4
5
  defaultSortDesc?: boolean;
5
6
  hidden?: boolean;
6
7
  hoverTitle?: string;
8
+ isFilterable?: boolean;
9
+ order?: number;
7
10
  renderCell?: (rowData: T, dataIndex: number, rowIndex: number) => React.ReactElement | null;
8
11
  renderData?: (rowData: T, dataIndex: number) => string;
12
+ showTimezones?: false;
9
13
  sort?: (a: T, b: T, sortAsc: boolean) => number;
10
14
  sortByValue?: boolean;
11
15
  sortable?: boolean;
12
16
  title?: string | React.ReactElement;
13
- width?: number;
14
- order?: number;
15
- isFilterable?: boolean;
16
- dateFormat?: string;
17
17
  translation?: {
18
18
  [keyName: string]: string;
19
19
  };
20
+ width?: number;
20
21
  }
21
22
  export interface IRenderData {
22
23
  _index: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mig-schema-table",
3
- "version": "3.0.36",
3
+ "version": "3.0.37",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/"
@@ -14,6 +14,7 @@
14
14
  "@types/react-datepicker": "^4.11.2",
15
15
  "@types/react-dom": "^18.2.4",
16
16
  "date-fns": "^2.30.0",
17
+ "date-fns-tz": "^2.0.0",
17
18
  "lodash": "^4.17.21",
18
19
  "openapi3-ts": "^4.1.2",
19
20
  "react": "^18.2.0",