mig-schema-table 3.0.80 → 3.0.82
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/dist/SchemaTable/Td/index.d.ts +2 -1
- package/dist/SchemaTable/Td/index.js +3 -3
- package/dist/SchemaTable/Th/index.d.ts +2 -1
- package/dist/SchemaTable/Th/index.js +10 -5
- package/dist/SchemaTable/ThMenu/FilterMenuComponent/index.d.ts +3 -4
- package/dist/SchemaTable/ThMenu/FilterMenuComponent/index.js +3 -7
- package/dist/SchemaTable/ThMenu/index.d.ts +3 -2
- package/dist/SchemaTable/ThMenu/index.js +2 -2
- package/dist/SchemaTable/index.d.ts +3 -1
- package/dist/SchemaTable/index.js +20 -19
- package/dist/inc/string.d.ts +1 -1
- package/dist/inc/string.js +1 -1
- package/dist/index.css +3 -7
- package/package.json +1 -1
|
@@ -18,7 +18,8 @@ interface ITdProps<T> {
|
|
|
18
18
|
propSchema?: oas31.SchemaObject;
|
|
19
19
|
sortedRenderData?: IRenderData[];
|
|
20
20
|
style: React.CSSProperties;
|
|
21
|
+
translate: (key: string, ...args: Array<string | number>) => string;
|
|
21
22
|
}
|
|
22
|
-
declare function Td<T>({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, onRowDoubleClick, propConfig, propName, propSchema, rowHeight, rowIndex, sortedRenderData, style, }: ITdProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
23
|
+
declare function Td<T>({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, onRowDoubleClick, propConfig, propName, propSchema, rowHeight, rowIndex, sortedRenderData, style, translate, }: ITdProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
23
24
|
declare const _default: typeof Td;
|
|
24
25
|
export default _default;
|
|
@@ -3,8 +3,7 @@ import React from "react";
|
|
|
3
3
|
import { SELECT_ALL_COLUMN_NAME } from "../constants";
|
|
4
4
|
import { localeFormatInTimeZone, timeZone } from "../../inc/date";
|
|
5
5
|
import { DEFAULT_DATE_TIME_FORMAT } from "../../inc/constant";
|
|
6
|
-
|
|
7
|
-
function Td({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, onRowDoubleClick, propConfig, propName, propSchema, rowHeight, rowIndex, sortedRenderData, style, }) {
|
|
6
|
+
function Td({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, onRowDoubleClick, propConfig, propName, propSchema, rowHeight, rowIndex, sortedRenderData, style, translate, }) {
|
|
8
7
|
const onTdClick = React.useCallback((e) => {
|
|
9
8
|
if (!sortedRenderData || !onRowClick) {
|
|
10
9
|
return;
|
|
@@ -43,7 +42,7 @@ function Td({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowC
|
|
|
43
42
|
? "Asia/Jakarta"
|
|
44
43
|
: "Europe/Amsterdam";
|
|
45
44
|
if (date) {
|
|
46
|
-
title = `${localeFormatInTimeZone(date, alternativeTimeZone, DEFAULT_DATE_TIME_FORMAT)} (${
|
|
45
|
+
title = `${localeFormatInTimeZone(date, alternativeTimeZone, DEFAULT_DATE_TIME_FORMAT)} (${translate(alternativeTimeZone)})`;
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
const classNames = [
|
|
@@ -82,6 +81,7 @@ function Td({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowC
|
|
|
82
81
|
rowIndex,
|
|
83
82
|
sortedRenderData,
|
|
84
83
|
style,
|
|
84
|
+
translate,
|
|
85
85
|
]);
|
|
86
86
|
if (!row || !tdDivProps) {
|
|
87
87
|
return null;
|
|
@@ -22,6 +22,7 @@ interface IThProps {
|
|
|
22
22
|
setSortColumn: Dispatch<SetStateAction<string>>;
|
|
23
23
|
sortAsc?: boolean;
|
|
24
24
|
style: CSSProperties;
|
|
25
|
+
translate: (key: string, ...args: Array<string | number>) => string;
|
|
25
26
|
}
|
|
26
|
-
declare const _default: ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows, onSelectAllIndexesHandler, propConfig, propIsRequired, propName, schema, setMenuConfig, setSortAsc, setSortColumn, sortAsc, style, }: IThProps) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
declare const _default: ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows, onSelectAllIndexesHandler, propConfig, propIsRequired, propName, schema, setMenuConfig, setSortAsc, setSortColumn, sortAsc, style, translate, }: IThProps) => import("react/jsx-runtime").JSX.Element;
|
|
27
28
|
export default _default;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import { t, uncamel } from "../../inc/string";
|
|
4
3
|
import { SELECT_ALL_COLUMN_NAME } from "../constants";
|
|
5
4
|
import { timeZone } from "../../inc/date";
|
|
6
5
|
export var EColumnFilterStatus;
|
|
@@ -9,7 +8,7 @@ export var EColumnFilterStatus;
|
|
|
9
8
|
EColumnFilterStatus["AVAILABLE"] = "AVAILABLE";
|
|
10
9
|
EColumnFilterStatus["ACTIVE"] = "ACTIVE";
|
|
11
10
|
})(EColumnFilterStatus || (EColumnFilterStatus = {}));
|
|
12
|
-
const Th = ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows, onSelectAllIndexesHandler, propConfig, propIsRequired, propName, schema, setMenuConfig, setSortAsc, setSortColumn, sortAsc, style, }) => {
|
|
11
|
+
const Th = ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows, onSelectAllIndexesHandler, propConfig, propIsRequired, propName, schema, setMenuConfig, setSortAsc, setSortColumn, sortAsc, style, translate, }) => {
|
|
13
12
|
const classNames = [
|
|
14
13
|
`schema-table__th`,
|
|
15
14
|
`schema-table__th--filter-${columnFilterStatus}`,
|
|
@@ -58,10 +57,16 @@ const Th = ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows
|
|
|
58
57
|
if ((schema === null || schema === void 0 ? void 0 : schema.format) &&
|
|
59
58
|
schema.format === "date-time" &&
|
|
60
59
|
(propConfig === null || propConfig === void 0 ? void 0 : propConfig.showTimezones) !== false) {
|
|
61
|
-
return `${
|
|
60
|
+
return `${translate(propName)} (${translate(timeZone)})`;
|
|
62
61
|
}
|
|
63
|
-
return
|
|
64
|
-
}, [
|
|
62
|
+
return translate(propName);
|
|
63
|
+
}, [
|
|
64
|
+
propConfig === null || propConfig === void 0 ? void 0 : propConfig.showTimezones,
|
|
65
|
+
propConfig === null || propConfig === void 0 ? void 0 : propConfig.title,
|
|
66
|
+
propName,
|
|
67
|
+
schema === null || schema === void 0 ? void 0 : schema.format,
|
|
68
|
+
translate,
|
|
69
|
+
]);
|
|
65
70
|
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
66
71
|
return (_jsx("div", Object.assign({ style: style, className: classNames.join(" ") }, { children: _jsx("div", Object.assign({ style: {
|
|
67
72
|
width: "100%",
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { oas31 } from "openapi3-ts";
|
|
3
3
|
import { TColumnFilterValue } from "../../index";
|
|
4
|
-
import { IColumnConfig } from "../../../types";
|
|
5
4
|
export interface IFilterMenuComponentProps {
|
|
6
5
|
columnFilterValue: TColumnFilterValue;
|
|
7
6
|
onChange: (newValue: TColumnFilterValue | undefined, persistState: boolean) => void;
|
|
8
|
-
onInputKeyDown: (e: React.KeyboardEvent) => void;
|
|
9
|
-
propConfig?: IColumnConfig<any>;
|
|
7
|
+
onInputKeyDown: (e: React.KeyboardEvent<HTMLElement>) => void;
|
|
10
8
|
propIsRequired: boolean;
|
|
11
9
|
propName: string;
|
|
12
10
|
propSchema?: oas31.SchemaObject;
|
|
11
|
+
translate: (key: string, ...args: Array<string | number>) => string;
|
|
13
12
|
}
|
|
14
|
-
declare const _default: React.MemoExoticComponent<({ columnFilterValue, onChange, onInputKeyDown,
|
|
13
|
+
declare const _default: React.MemoExoticComponent<({ columnFilterValue, onChange, onInputKeyDown, propIsRequired, propName, propSchema, translate, }: IFilterMenuComponentProps) => import("react/jsx-runtime").JSX.Element>;
|
|
15
14
|
export default _default;
|
|
@@ -11,12 +11,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import React from "react";
|
|
14
|
-
import { t } from "../../../inc/string";
|
|
15
14
|
import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, } from "../../../inc/constant";
|
|
16
15
|
import DatePicker from "react-datepicker";
|
|
17
16
|
import nl from "date-fns/locale/nl";
|
|
18
17
|
import { endOfDay } from "date-fns";
|
|
19
|
-
const FilterMenuComponent = ({ columnFilterValue, onChange, onInputKeyDown,
|
|
18
|
+
const FilterMenuComponent = ({ columnFilterValue, onChange, onInputKeyDown, propIsRequired, propName, propSchema, translate, }) => {
|
|
20
19
|
const { type, format, minimum, maximum } = propSchema || {};
|
|
21
20
|
const value = columnFilterValue;
|
|
22
21
|
const isDateTime = format === "date-time";
|
|
@@ -53,11 +52,8 @@ const FilterMenuComponent = ({ columnFilterValue, onChange, onInputKeyDown, prop
|
|
|
53
52
|
if (propSchema === null || propSchema === void 0 ? void 0 : propSchema.enum) {
|
|
54
53
|
return (_jsx("ol", Object.assign({ className: "schema-table-menu schema-table__th-menu__filter-menu-component" }, { children: _jsx("li", { children: _jsxs("select", Object.assign({ autoFocus: true, className: "form-select", value: value, "data-prop-name": propName, onChange: (e) => {
|
|
55
54
|
onChange(e.currentTarget.value || undefined, true);
|
|
56
|
-
} }, { children: [_jsx("option", Object.assign({ value: "" }, { children: "All" }), "all"), propSchema.enum.map((
|
|
57
|
-
|
|
58
|
-
? name
|
|
59
|
-
: t(name, propConfig.translation);
|
|
60
|
-
return (_jsx("option", Object.assign({ value: rowName }, { children: rowName }), `column-filter-select-${rowName}`));
|
|
55
|
+
} }, { children: [_jsx("option", Object.assign({ value: "" }, { children: "All" }), "all"), propSchema.enum.map((value) => {
|
|
56
|
+
return (_jsx("option", Object.assign({ value: value }, { children: translate(value) }), `column-filter-select-${value}`));
|
|
61
57
|
})] })) }) })));
|
|
62
58
|
}
|
|
63
59
|
if (isDateTime || format === "date") {
|
|
@@ -13,12 +13,13 @@ type TThMenuProps = IThMenuConfig & {
|
|
|
13
13
|
isFilterable: boolean;
|
|
14
14
|
onChange: (newValue: TColumnFilterValue | undefined, persistState: boolean) => void;
|
|
15
15
|
onClose: (e: MouseEvent | React.MouseEvent) => void;
|
|
16
|
-
onInputKeyDown: (e: React.KeyboardEvent) => void;
|
|
16
|
+
onInputKeyDown: (e: React.KeyboardEvent<HTMLElement>) => void;
|
|
17
17
|
propIsRequired: boolean;
|
|
18
18
|
propSchema: oas31.SchemaObject;
|
|
19
19
|
setSortAsc: Dispatch<SetStateAction<boolean>>;
|
|
20
20
|
setSortColumn: Dispatch<SetStateAction<string>>;
|
|
21
|
+
translate: (key: string, ...args: Array<string | number>) => string;
|
|
21
22
|
value: TColumnFilterValue;
|
|
22
23
|
};
|
|
23
|
-
declare const _default: React.MemoExoticComponent<({ isSortable, isFilterable, onChange, onClose, onInputKeyDown, propConfig, propIsRequired, propName, propSchema, referenceElement, setSortAsc, setSortColumn, value, }: TThMenuProps) => import("react/jsx-runtime").JSX.Element | null>;
|
|
24
|
+
declare const _default: React.MemoExoticComponent<({ isSortable, isFilterable, onChange, onClose, onInputKeyDown, propConfig, propIsRequired, propName, propSchema, referenceElement, setSortAsc, setSortColumn, translate, value, }: TThMenuProps) => import("react/jsx-runtime").JSX.Element | null>;
|
|
24
25
|
export default _default;
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import FilterMenuComponent from "./FilterMenuComponent";
|
|
4
4
|
import { usePopper } from "react-popper";
|
|
5
|
-
const ThMenu = ({ isSortable, isFilterable, onChange, onClose, onInputKeyDown, propConfig, propIsRequired, propName, propSchema, referenceElement, setSortAsc, setSortColumn, value, }) => {
|
|
5
|
+
const ThMenu = ({ isSortable, isFilterable, onChange, onClose, onInputKeyDown, propConfig, propIsRequired, propName, propSchema, referenceElement, setSortAsc, setSortColumn, translate, value, }) => {
|
|
6
6
|
const [menu, setMenu] = React.useState(null);
|
|
7
7
|
const [subMenu, setSubMenu] = React.useState(null);
|
|
8
8
|
const [subMenuReferenceElement, setSubMenuReferenceElement] = React.useState(null);
|
|
@@ -51,6 +51,6 @@ const ThMenu = ({ isSortable, isFilterable, onChange, onClose, onInputKeyDown, p
|
|
|
51
51
|
}
|
|
52
52
|
return (_jsxs(_Fragment, { children: [_jsx("div", Object.assign({ className: "schema-table__th-menu", ref: setMenu, style: menuPopper.styles.popper }, menuPopper.attributes.popper, { children: _jsxs("ol", Object.assign({ className: "schema-table-menu" }, { children: [isSortable ? (_jsxs("li", Object.assign({ onClick: onSortAscendingClick, style: { padding: 8 } }, { children: [_jsx("span", Object.assign({ className: "schema-table__th-menu__icon" }, { children: "\u2193" })), " Sort ascending"] }))) : null, isSortable ? (_jsxs("li", Object.assign({ onClick: onSortDescendingClick, style: { padding: 8 } }, { children: [_jsx("span", Object.assign({ className: "schema-table__th-menu__icon" }, { children: "\u2191" })), " Sort descending"] }))) : null, isFilterable ? (_jsxs("li", Object.assign({ style: { padding: 8 }, onMouseOver: (e) => {
|
|
53
53
|
setSubMenuReferenceElement(e.currentTarget);
|
|
54
|
-
} }, { children: [_jsx("span", Object.assign({ className: "schema-table__th-menu__icon" }, { children: _jsx("input", { type: "checkbox", id: "schema-table__th-menu__filters", checked: value !== undefined, disabled: value === undefined, onChange: onFilterCheckboxChange }) })), _jsx("label", Object.assign({ htmlFor: "schema-table__th-menu__filters" }, { children: "Filters" })), _jsx("div", Object.assign({ className: "schema-table__th-menu__sub-menu-indicator" }, { children: ">" }))] }))) : null] })) })), subMenuReferenceElement ? (_jsx("div", Object.assign({ className: "schema-table__th-menu__sub-menu", ref: setSubMenu, style: subMenuPopper.styles.popper }, subMenuPopper.attributes.popper, { children: _jsx(FilterMenu, { columnFilterValue: value, onChange: onChange, onInputKeyDown: onInputKeyDown,
|
|
54
|
+
} }, { children: [_jsx("span", Object.assign({ className: "schema-table__th-menu__icon" }, { children: _jsx("input", { type: "checkbox", id: "schema-table__th-menu__filters", checked: value !== undefined, disabled: value === undefined, onChange: onFilterCheckboxChange }) })), _jsx("label", Object.assign({ htmlFor: "schema-table__th-menu__filters" }, { children: "Filters" })), _jsx("div", Object.assign({ className: "schema-table__th-menu__sub-menu-indicator" }, { children: ">" }))] }))) : null] })) })), subMenuReferenceElement ? (_jsx("div", Object.assign({ className: "schema-table__th-menu__sub-menu", ref: setSubMenu, style: subMenuPopper.styles.popper }, subMenuPopper.attributes.popper, { children: _jsx(FilterMenu, { columnFilterValue: value, onChange: onChange, onInputKeyDown: onInputKeyDown, propIsRequired: propIsRequired, propName: propName, propSchema: propSchema, translate: translate }) }))) : null] }));
|
|
55
55
|
};
|
|
56
56
|
export default React.memo(ThMenu);
|
|
@@ -35,10 +35,12 @@ export interface ISchemaTableProps<T> {
|
|
|
35
35
|
onCheckedIndexesChange?: (dataIndex: number[]) => void;
|
|
36
36
|
onRowClick?: (rowData: T, dataIndex: number, event: React.MouseEvent) => void;
|
|
37
37
|
onRowDoubleClick?: (rowData: T, dataIndex: number, event: React.MouseEvent) => void;
|
|
38
|
+
onSearchEnter?: () => void;
|
|
38
39
|
rowHeight?: number;
|
|
39
40
|
schema: oas31.SchemaObject;
|
|
40
41
|
searchPlaceholder?: string;
|
|
41
42
|
style?: React.CSSProperties;
|
|
43
|
+
translate?: (key: string, ...args: Array<string | number>) => string;
|
|
42
44
|
useFilterStateHash?: boolean;
|
|
43
45
|
width: number;
|
|
44
46
|
}
|
|
@@ -48,6 +50,6 @@ export interface IDateColumnFilterValue {
|
|
|
48
50
|
filterEmpty?: true;
|
|
49
51
|
}
|
|
50
52
|
export type TColumnFilterValue = string | number | boolean | IDateColumnFilterValue;
|
|
51
|
-
declare function SchemaTable<T>({ Heading, checkedIndexes, config, customElement, data, defaultColumnFilters, defaultSortAsc, defaultSortColumn, disabledCheckedIndexes, enableAutoFocus, getRowClassName, getRowSelected, isColumnFilterable, isExportable, isSearchable, isSortable, maxHeight, onCheckedIndexesChange, onRowClick, onRowDoubleClick, rowHeight, schema, searchPlaceholder, style, useFilterStateHash, width, }: ISchemaTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
53
|
+
declare function SchemaTable<T>({ Heading, checkedIndexes, config, customElement, data, defaultColumnFilters, defaultSortAsc, defaultSortColumn, disabledCheckedIndexes, enableAutoFocus, getRowClassName, getRowSelected, isColumnFilterable, isExportable, isSearchable, isSortable, maxHeight, onCheckedIndexesChange, onRowClick, onRowDoubleClick, onSearchEnter, rowHeight, schema, searchPlaceholder, style, translate, useFilterStateHash, width, }: ISchemaTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
52
54
|
declare const _default: typeof SchemaTable;
|
|
53
55
|
export default _default;
|
|
@@ -13,7 +13,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
13
13
|
import React from "react";
|
|
14
14
|
import { VariableSizeGrid, VariableSizeList } from "react-window";
|
|
15
15
|
import { localeFormat } from "../inc/date";
|
|
16
|
-
import {
|
|
16
|
+
import { defaultTranslate } from "../inc/string";
|
|
17
17
|
import { SELECT_ALL_COLUMN_NAME, SELECT_ALL_COLUMN_WIDTH } from "./constants";
|
|
18
18
|
import Td from "./Td";
|
|
19
19
|
import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT } from "../inc/constant";
|
|
@@ -46,7 +46,7 @@ function getIsColumnSortable(isTableSortable, propSchema, propConfig) {
|
|
|
46
46
|
return !!(isTableSortable &&
|
|
47
47
|
(propSchema || (propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderData) || (propConfig === null || propConfig === void 0 ? void 0 : propConfig.sort)));
|
|
48
48
|
}
|
|
49
|
-
function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, customElement, data, defaultColumnFilters = {}, defaultSortAsc = false, defaultSortColumn, disabledCheckedIndexes, enableAutoFocus, getRowClassName, getRowSelected, isColumnFilterable = true, isExportable = true, isSearchable = true, isSortable = true, maxHeight, onCheckedIndexesChange, onRowClick, onRowDoubleClick, rowHeight = 36, schema, searchPlaceholder, style, useFilterStateHash, width, }) {
|
|
49
|
+
function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, customElement, data, defaultColumnFilters = {}, defaultSortAsc = false, defaultSortColumn, disabledCheckedIndexes, enableAutoFocus, getRowClassName, getRowSelected, isColumnFilterable = true, isExportable = true, isSearchable = true, isSortable = true, maxHeight, onCheckedIndexesChange, onRowClick, onRowDoubleClick, onSearchEnter, rowHeight = 36, schema, searchPlaceholder, style, translate = defaultTranslate, useFilterStateHash, width, }) {
|
|
50
50
|
const [sortColumn, setSortColumn] = React.useState(defaultSortColumn);
|
|
51
51
|
const [sortAsc, setSortAsc] = React.useState(defaultSortAsc);
|
|
52
52
|
const [thMenuConfig, setThMenuConfig] = React.useState();
|
|
@@ -138,16 +138,13 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
138
138
|
prev[propName] = "";
|
|
139
139
|
return prev;
|
|
140
140
|
}
|
|
141
|
-
const
|
|
142
|
-
const rawValue = !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.translation)
|
|
143
|
-
? val
|
|
144
|
-
: t(val, propConfig.translation);
|
|
141
|
+
const rawValue = object[propName];
|
|
145
142
|
switch (schema.type) {
|
|
146
143
|
case "array":
|
|
147
144
|
prev[propName] =
|
|
148
145
|
((_a = schema.items) === null || _a === void 0 ? void 0 : _a.type) === "string" &&
|
|
149
146
|
rawValue
|
|
150
|
-
? rawValue.map(
|
|
147
|
+
? rawValue.map(translate).join(", ")
|
|
151
148
|
: JSON.stringify(rawValue);
|
|
152
149
|
return prev;
|
|
153
150
|
case "boolean":
|
|
@@ -167,10 +164,9 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
167
164
|
// @ts-ignore
|
|
168
165
|
case "string":
|
|
169
166
|
if (schema.format === "date" && rawValue) {
|
|
170
|
-
prev[propName] =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
: localeFormat(new Date(rawValue), (propConfig === null || propConfig === void 0 ? void 0 : propConfig.dateFormat) || DEFAULT_DATE_FORMAT);
|
|
167
|
+
prev[propName] = ["2999-12-31", "1970-01-01"].includes(rawValue)
|
|
168
|
+
? "-"
|
|
169
|
+
: localeFormat(new Date(rawValue), (propConfig === null || propConfig === void 0 ? void 0 : propConfig.dateFormat) || DEFAULT_DATE_FORMAT);
|
|
174
170
|
return prev;
|
|
175
171
|
}
|
|
176
172
|
if (schema.format === "date-time" && rawValue) {
|
|
@@ -178,7 +174,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
178
174
|
return prev;
|
|
179
175
|
}
|
|
180
176
|
if (schema.enum) {
|
|
181
|
-
prev[propName] = rawValue ?
|
|
177
|
+
prev[propName] = rawValue ? translate(rawValue) : "";
|
|
182
178
|
return prev;
|
|
183
179
|
}
|
|
184
180
|
// fallthrough
|
|
@@ -187,7 +183,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
187
183
|
return prev;
|
|
188
184
|
}
|
|
189
185
|
}, { _index: rowIndex }))
|
|
190
|
-
: undefined, [columnNames,
|
|
186
|
+
: undefined, [sourceData, columnNames, properties, config, translate]);
|
|
191
187
|
const columnCount = columnNames.length;
|
|
192
188
|
const { dynamicWidthColumnCount, fixedWidthColumnsWidth } = React.useMemo(() => {
|
|
193
189
|
let fixedWidthColumnsWidth = 0;
|
|
@@ -417,13 +413,12 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
417
413
|
}
|
|
418
414
|
return (_jsx(Th, { columnFilterStatus: columnFilterStatus,
|
|
419
415
|
// disableColumnFilter={disableColumnFilter}
|
|
420
|
-
isAllChecked: isAllRowsChecked, isSortable: getIsColumnSortable(!!isSortable, propSchema, propConfig), numberOfSelectedRows: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length, onSelectAllIndexesHandler: onSelectAllIndexesHandler, propConfig: propConfig, propIsRequired: required.includes(propName), propName: propName, schema: propSchema, setMenuConfig: setThMenuConfig, setSortAsc: onSetSortAsc, setSortColumn: onSetSortColumn, sortAsc: sortColumn === propName ? sortAsc : undefined, style: style }));
|
|
416
|
+
isAllChecked: isAllRowsChecked, isSortable: getIsColumnSortable(!!isSortable, propSchema, propConfig), numberOfSelectedRows: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length, onSelectAllIndexesHandler: onSelectAllIndexesHandler, propConfig: propConfig, propIsRequired: required.includes(propName), propName: propName, schema: propSchema, setMenuConfig: setThMenuConfig, setSortAsc: onSetSortAsc, setSortColumn: onSetSortColumn, sortAsc: sortColumn === propName ? sortAsc : undefined, style: style, translate: translate }));
|
|
421
417
|
}, [
|
|
422
418
|
checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length,
|
|
423
419
|
columnFilterMap,
|
|
424
420
|
columnNames,
|
|
425
421
|
config,
|
|
426
|
-
// disableColumnFilter,
|
|
427
422
|
isAllRowsChecked,
|
|
428
423
|
isColumnFilterable,
|
|
429
424
|
isSortable,
|
|
@@ -434,13 +429,14 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
434
429
|
required,
|
|
435
430
|
sortAsc,
|
|
436
431
|
sortColumn,
|
|
432
|
+
translate,
|
|
437
433
|
]);
|
|
438
434
|
const SchemaTableTd = React.useCallback(({ columnIndex, rowIndex, style }) => {
|
|
439
435
|
const propName = columnNames[columnIndex];
|
|
440
436
|
const propSchema = (propName === SELECT_ALL_COLUMN_NAME
|
|
441
437
|
? { type: "boolean" }
|
|
442
438
|
: properties[propName]);
|
|
443
|
-
return sourceData ? (_jsx(Td, { checkedIndexes: checkedIndexes, disabledCheckedIndexes: disabledCheckedIndexes, columnIndex: columnIndex, data: sourceData, getRowClassName: getRowClassName, getRowSelected: getRowSelected, onCheckedIndexesChange: onCheckedIndexesChange, onRowClick: onRowClick, onRowDoubleClick: onRowDoubleClick, propConfig: config ? config[propName] : undefined, propName: propName, propSchema: propSchema, rowHeight: rowHeight, rowIndex: rowIndex, sortedRenderData: sortedRenderData, style: style })) : null;
|
|
439
|
+
return sourceData ? (_jsx(Td, { checkedIndexes: checkedIndexes, disabledCheckedIndexes: disabledCheckedIndexes, columnIndex: columnIndex, data: sourceData, getRowClassName: getRowClassName, getRowSelected: getRowSelected, onCheckedIndexesChange: onCheckedIndexesChange, onRowClick: onRowClick, onRowDoubleClick: onRowDoubleClick, propConfig: config ? config[propName] : undefined, propName: propName, propSchema: propSchema, rowHeight: rowHeight, rowIndex: rowIndex, sortedRenderData: sortedRenderData, style: style, translate: translate })) : null;
|
|
444
440
|
}, [
|
|
445
441
|
columnNames,
|
|
446
442
|
properties,
|
|
@@ -455,6 +451,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
455
451
|
config,
|
|
456
452
|
rowHeight,
|
|
457
453
|
sortedRenderData,
|
|
454
|
+
translate,
|
|
458
455
|
]);
|
|
459
456
|
const onSearchChange = React.useCallback((e) => {
|
|
460
457
|
if (isDataFunction) {
|
|
@@ -472,8 +469,12 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
472
469
|
if (isDirty) {
|
|
473
470
|
refreshData();
|
|
474
471
|
}
|
|
472
|
+
if (onSearchEnter &&
|
|
473
|
+
e.currentTarget.className === "schema-table__search") {
|
|
474
|
+
onSearchEnter();
|
|
475
|
+
}
|
|
475
476
|
}
|
|
476
|
-
}, [isDirty, refreshData]);
|
|
477
|
+
}, [isDirty, onSearchEnter, refreshData]);
|
|
477
478
|
const getRowHeight = React.useCallback(() => rowHeight, [rowHeight]);
|
|
478
479
|
const rowWidth = dynamicWidthColumnCount ? width : fixedWidthColumnsWidth;
|
|
479
480
|
const rowCount = React.useMemo(() => (sortedRenderData ? sortedRenderData.length : 0), [sortedRenderData]);
|
|
@@ -569,7 +570,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
569
570
|
type: "text/csv;charset=utf-8",
|
|
570
571
|
}), "export.csv");
|
|
571
572
|
}, [sortedRenderData]);
|
|
572
|
-
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: searchInputAutoFocus, onBlur: onSearchBlur })) : null })), customElement, isExportable ? (_jsx("button", Object.assign({ onClick: onExportDataClick, style: { marginLeft: 8 }, disabled: !(sortedRenderData === null || sortedRenderData === void 0 ? void 0 : sortedRenderData.length) }, { children: "Export data" }))) : null, isSearchable || isColumnFilterable ? (_jsx("button", Object.assign({ onClick: onClearFiltersButtonClick, style: { marginLeft: 8 }, disabled: Object.keys(columnFilterMap).length + searchQuery.length === 0 }, { children: "Clear filters" }))) : null] })), _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: ConfiguredTh }), `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: {
|
|
573
|
+
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", { className: "schema-table__search", type: "text", placeholder: searchPlaceholder || "Search...", value: searchQuery, onChange: onSearchChange, onKeyDown: onInputKeyDown, autoFocus: searchInputAutoFocus, onBlur: onSearchBlur })) : null })), customElement, isExportable ? (_jsx("button", Object.assign({ onClick: onExportDataClick, style: { marginLeft: 8 }, disabled: !(sortedRenderData === null || sortedRenderData === void 0 ? void 0 : sortedRenderData.length) }, { children: "Export data" }))) : null, isSearchable || isColumnFilterable ? (_jsx("button", Object.assign({ onClick: onClearFiltersButtonClick, style: { marginLeft: 8 }, disabled: Object.keys(columnFilterMap).length + searchQuery.length === 0 }, { children: "Clear filters" }))) : null] })), _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: ConfiguredTh }), `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: {
|
|
573
574
|
width: rowWidth,
|
|
574
575
|
height: Math.max(50, tableBodyHeight),
|
|
575
576
|
border: "1px solid #BBB",
|
|
@@ -578,6 +579,6 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
578
579
|
backgroundColor: "#CCC",
|
|
579
580
|
alignItems: "center",
|
|
580
581
|
justifyContent: "center",
|
|
581
|
-
} }, { children: isDirty ? (_jsx("button", Object.assign({ onClick: refreshData, className: "btn border" }, { children: "Refresh data" }))) : (_jsx("div", { children: "\u231B Loading..." })) }))), thMenuConfig ? (_jsx(ThMenu, { isFilterable: !!isColumnFilterable, isSortable: getIsColumnSortable(!!isSortable, schema.properties[thMenuConfig.propName], thMenuConfig.propConfig), onChange: onSchemaColumnFilterChange, onClose: onPopoverClose, onInputKeyDown: onInputKeyDown, propConfig: thMenuConfig.propConfig, propIsRequired: thMenuConfig.propIsRequired, propName: thMenuConfig.propName, propSchema: schema.properties[thMenuConfig.propName], referenceElement: thMenuConfig.referenceElement, setSortAsc: setSortAsc, setSortColumn: setSortColumn, value: columnFilterMap[thMenuConfig.propName] })) : null] })));
|
|
582
|
+
} }, { children: isDirty ? (_jsx("button", Object.assign({ onClick: refreshData, className: "btn border" }, { children: "Refresh data" }))) : (_jsx("div", { children: "\u231B Loading..." })) }))), thMenuConfig ? (_jsx(ThMenu, { isFilterable: !!isColumnFilterable, isSortable: getIsColumnSortable(!!isSortable, schema.properties[thMenuConfig.propName], thMenuConfig.propConfig), onChange: onSchemaColumnFilterChange, onClose: onPopoverClose, onInputKeyDown: onInputKeyDown, propConfig: thMenuConfig.propConfig, propIsRequired: thMenuConfig.propIsRequired, propName: thMenuConfig.propName, propSchema: schema.properties[thMenuConfig.propName], referenceElement: thMenuConfig.referenceElement, setSortAsc: setSortAsc, setSortColumn: setSortColumn, translate: translate, value: columnFilterMap[thMenuConfig.propName] })) : null] })));
|
|
582
583
|
}
|
|
583
584
|
export default React.memo(SchemaTable);
|
package/dist/inc/string.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare function uncamel(camel: string): string;
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function defaultTranslate(key: string, ...args: any[]): string;
|
package/dist/inc/string.js
CHANGED
|
@@ -21,7 +21,7 @@ const db = {
|
|
|
21
21
|
"Asia/Jakarta": "JKT",
|
|
22
22
|
"Asia/Bangkok": "JKT",
|
|
23
23
|
};
|
|
24
|
-
export function
|
|
24
|
+
export function defaultTranslate(key, ...args) {
|
|
25
25
|
let string = db[key] || uncamel(key);
|
|
26
26
|
args.forEach((arg, index) => {
|
|
27
27
|
string = string.replace(`{${index}}`, arg);
|
package/dist/index.css
CHANGED
|
@@ -49,13 +49,6 @@
|
|
|
49
49
|
.schema-table__td--selected {
|
|
50
50
|
background-color: var(--bs-gray-300, #dee2e6);
|
|
51
51
|
}
|
|
52
|
-
.schema-table__search {
|
|
53
|
-
margin: 1rem;
|
|
54
|
-
padding-right: 1rem;
|
|
55
|
-
}
|
|
56
|
-
.schema-table__search input {
|
|
57
|
-
width: 100%;
|
|
58
|
-
}
|
|
59
52
|
.schema-table--clickable-rows .schema-table__td {
|
|
60
53
|
cursor: pointer;
|
|
61
54
|
}
|
|
@@ -130,6 +123,9 @@
|
|
|
130
123
|
.schema-table__th:hover .schema-table__th__trigger-el {
|
|
131
124
|
display: block !important;
|
|
132
125
|
}
|
|
126
|
+
.schema-table__th svg {
|
|
127
|
+
vertical-align: baseline;
|
|
128
|
+
}
|
|
133
129
|
|
|
134
130
|
.schema-table__th-menu {
|
|
135
131
|
background-color: white;
|