mig-schema-table 3.0.28 → 3.0.30
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/README.md +1 -0
- package/dist/SchemaTable/SchemaColumnFilterPopover/FilterFormComponent/index.js +6 -6
- package/dist/SchemaTable/SchemaColumnFilterPopover/index.js +1 -1
- package/dist/SchemaTable/Td/index.d.ts +2 -1
- package/dist/SchemaTable/Td/index.js +2 -2
- package/dist/SchemaTable/index.d.ts +2 -1
- package/dist/SchemaTable/index.js +29 -10
- package/dist/index.css +16 -12
- package/package.json +2 -2
- package/dist/SchemaTable/ColumnFilterRow/index.d.ts +0 -21
- package/dist/SchemaTable/ColumnFilterRow/index.js +0 -111
- package/dist/SchemaTable/index.test.d.ts +0 -1
- package/dist/SchemaTable/index.test.js +0 -18
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ import { SchemaTable, IColumnConfig } from "mig-schema-table";
|
|
|
42
42
|
import "mig-schema-table/dist/index.css";
|
|
43
43
|
// Add this for default datepicker styling
|
|
44
44
|
import "react-datepicker/dist/react-datepicker.css";
|
|
45
|
+
// Optionally add bootstrap5 styles
|
|
45
46
|
|
|
46
47
|
const config: { [keyName: string]: IColumnConfig } = {
|
|
47
48
|
id: {
|
|
@@ -9,7 +9,7 @@ const FilterFormComponent = ({ onChange, propSchema, propName, columnFilterValue
|
|
|
9
9
|
const value = columnFilterValue;
|
|
10
10
|
switch (type) {
|
|
11
11
|
case "integer":
|
|
12
|
-
return (_jsx("div", Object.assign({ className: "
|
|
12
|
+
return (_jsx("div", Object.assign({ className: "input-group" }, { children: _jsx("input", { className: "form-control", type: "number", value: (value || ""), "data-prop-name": propName, onChange: (e) => {
|
|
13
13
|
onChange(e.currentTarget.value === ""
|
|
14
14
|
? undefined
|
|
15
15
|
: parseInt(e.currentTarget.value));
|
|
@@ -19,7 +19,7 @@ const FilterFormComponent = ({ onChange, propSchema, propName, columnFilterValue
|
|
|
19
19
|
if (value === undefined) {
|
|
20
20
|
selectValue = "";
|
|
21
21
|
}
|
|
22
|
-
return (_jsxs("select", Object.assign({ value: selectValue, "data-prop-name": propName, onChange: (e) => {
|
|
22
|
+
return (_jsxs("select", Object.assign({ className: "form-select", value: selectValue, "data-prop-name": propName, onChange: (e) => {
|
|
23
23
|
switch (e.currentTarget.value) {
|
|
24
24
|
case "✓":
|
|
25
25
|
onChange(true);
|
|
@@ -34,7 +34,7 @@ const FilterFormComponent = ({ onChange, propSchema, propName, columnFilterValue
|
|
|
34
34
|
// @ts-ignore
|
|
35
35
|
case "string":
|
|
36
36
|
if (propSchema.enum) {
|
|
37
|
-
return (_jsxs("select", Object.assign({ value: value, "data-prop-name": propName, onChange: (e) => {
|
|
37
|
+
return (_jsxs("select", Object.assign({ className: "form-select", value: value, "data-prop-name": propName, onChange: (e) => {
|
|
38
38
|
onChange(e.currentTarget.value || undefined);
|
|
39
39
|
} }, { children: [_jsx("option", Object.assign({ value: "" }, { children: "All" }), "all"), propSchema.enum.map((name) => (_jsx("option", Object.assign({ value: name }, { children: uncamel(name) }), `column-filter-select-${name}`)))] })));
|
|
40
40
|
}
|
|
@@ -64,13 +64,13 @@ const FilterFormComponent = ({ onChange, propSchema, propName, columnFilterValue
|
|
|
64
64
|
}
|
|
65
65
|
onChange(Object.assign(Object.assign({}, columnFilterValue), { to: date || undefined }));
|
|
66
66
|
};
|
|
67
|
-
return (
|
|
67
|
+
return (_jsxs("div", Object.assign({ className: "input-group d-flex" }, { children: [_jsxs("div", Object.assign({ className: "d-flex flex-column m-1" }, { children: [_jsx("label", { children: "Start date-time" }), _jsx(DatePicker, { dateFormat: dateFormat, "data-prop-name": propName, locale: nl, selected: dateRangeValue.from, onChange: startDateChangeHandler, placeholderText: dateFormat, isClearable: true, selectsStart: true, showTimeSelect: format === "date-time", timeIntervals: 15, shouldCloseOnSelect: format === "date" })] })), _jsxs("div", Object.assign({ className: "d-flex flex-column m-1" }, { children: [_jsx("label", { children: "End date-time" }), _jsx(DatePicker, { id: "filter-date", dateFormat: dateFormat, "data-prop-name": propName, locale: nl, selectsEnd: true, selected: dateRangeValue.to, onChange: endDateChangeHandler, placeholderText: dateFormat, isClearable: true, startDate: dateRangeValue.from, endDate: dateRangeValue.to, showTimeSelect: format === "date-time", timeIntervals: 15, shouldCloseOnSelect: format === "date" })] }))] })));
|
|
68
68
|
}
|
|
69
69
|
// falls through
|
|
70
70
|
default:
|
|
71
|
-
return (_jsx("div", Object.assign({ className: "
|
|
71
|
+
return (_jsx("div", Object.assign({ className: "input-group" }, { children: _jsx("input", { type: "text", className: "form-control", placeholder: `Search ${propName}`, "aria-label": `Search ${propName}`, autoFocus: true, value: (value || ""), "data-prop-name": propName, onChange: (e) => {
|
|
72
72
|
onChange(e.currentTarget.value || undefined);
|
|
73
|
-
}
|
|
73
|
+
} }) })));
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
export default React.memo(FilterFormComponent);
|
|
@@ -28,7 +28,7 @@ const SchemaColumnFilterPopover = ({ onChange, onClose, propName, propSchema, re
|
|
|
28
28
|
window.removeEventListener("click", onWindowClick, { capture: true });
|
|
29
29
|
};
|
|
30
30
|
}, [onClose, popperElement]);
|
|
31
|
-
const classNames = ["popover"];
|
|
31
|
+
const classNames = ["popover", "schema-column-filter-popover"];
|
|
32
32
|
if (attributes.popper) {
|
|
33
33
|
classNames.push(`bs-popover-${attributes.popper["data-popper-placement"]}`);
|
|
34
34
|
}
|
|
@@ -3,6 +3,7 @@ import { oas31 } from "openapi3-ts";
|
|
|
3
3
|
import { IColumnConfig, IRenderData } from "../../types";
|
|
4
4
|
interface ITdProps<T> {
|
|
5
5
|
checkedIndexes?: number[];
|
|
6
|
+
disabledCheckedIndexes?: number[];
|
|
6
7
|
columnIndex: number;
|
|
7
8
|
data: T[];
|
|
8
9
|
getRowClassName?: (rowData: T, dataIndex: number) => string;
|
|
@@ -17,6 +18,6 @@ interface ITdProps<T> {
|
|
|
17
18
|
sortedRenderData?: IRenderData[];
|
|
18
19
|
style: React.CSSProperties;
|
|
19
20
|
}
|
|
20
|
-
declare function Td<T>({ checkedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, propConfig, propName, propSchema, rowHeight, rowIndex, sortedRenderData, style, }: ITdProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
21
|
+
declare function Td<T>({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, propConfig, propName, propSchema, rowHeight, rowIndex, sortedRenderData, style, }: ITdProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
21
22
|
declare const _default: typeof Td;
|
|
22
23
|
export default _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
function Td({ checkedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, propConfig, propName, propSchema, rowHeight, rowIndex, sortedRenderData, style, }) {
|
|
4
|
+
function Td({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, propConfig, propName, propSchema, rowHeight, rowIndex, sortedRenderData, style, }) {
|
|
5
5
|
const onTdClick = React.useCallback((e) => {
|
|
6
6
|
if (!sortedRenderData || !onRowClick) {
|
|
7
7
|
return;
|
|
@@ -55,7 +55,7 @@ function Td({ checkedIndexes, columnIndex, data, getRowClassName, getRowSelected
|
|
|
55
55
|
}
|
|
56
56
|
onCheckedIndexesChange([row._index]);
|
|
57
57
|
};
|
|
58
|
-
return (_jsx("div", Object.assign({}, tdDivProps, { children: _jsx("div", Object.assign({ style: { textAlign: "center" } }, { children: _jsx("input", { "data-key": "row-checkbox", type: "checkbox", onChange: onChecked, checked: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.includes(row._index) }) })) })));
|
|
58
|
+
return (_jsx("div", Object.assign({}, tdDivProps, { children: _jsx("div", Object.assign({ style: { textAlign: "center" } }, { children: _jsx("input", { "data-key": "row-checkbox", type: "checkbox", onChange: onChecked, checked: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.includes(row._index), disabled: disabledCheckedIndexes === null || disabledCheckedIndexes === void 0 ? void 0 : disabledCheckedIndexes.includes(row._index) }) })) })));
|
|
59
59
|
}
|
|
60
60
|
if (!propSchema) {
|
|
61
61
|
return null;
|
|
@@ -4,6 +4,7 @@ import { IColumnConfig } from "../types";
|
|
|
4
4
|
export interface ISchemaTableProps<T> {
|
|
5
5
|
Heading?: any;
|
|
6
6
|
checkedIndexes?: number[];
|
|
7
|
+
disabledCheckedIndexes?: number[];
|
|
7
8
|
config?: {
|
|
8
9
|
[propName: string]: IColumnConfig<T>;
|
|
9
10
|
};
|
|
@@ -29,6 +30,6 @@ export type TColumnFilterValue = string | number | boolean | {
|
|
|
29
30
|
from?: Date;
|
|
30
31
|
to?: Date;
|
|
31
32
|
};
|
|
32
|
-
declare function SchemaTable<T>({ Heading, checkedIndexes, config, customElement, data, defaultSortAsc, defaultSortColumn, getRowClassName, getRowSelected, maxHeight, isSearchable, isColumnFilterable, isSortable, onCheckedIndexesChange, onRowClick, rowHeight, schema, searchPlaceholder, style, width, }: ISchemaTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
33
|
+
declare function SchemaTable<T>({ Heading, checkedIndexes, disabledCheckedIndexes, config, customElement, data, defaultSortAsc, defaultSortColumn, getRowClassName, getRowSelected, maxHeight, isSearchable, isColumnFilterable, isSortable, onCheckedIndexesChange, onRowClick, rowHeight, schema, searchPlaceholder, style, width, }: ISchemaTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
33
34
|
declare const _default: typeof SchemaTable;
|
|
34
35
|
export default _default;
|
|
@@ -8,7 +8,8 @@ import { SELECT_ALL_COLUMN_NAME, SELECT_ALL_COLUMN_WIDTH } from "./constants";
|
|
|
8
8
|
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
|
+
import { sum } from "lodash";
|
|
12
|
+
function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheckedIndexes, config, customElement, data, defaultSortAsc = false, defaultSortColumn, getRowClassName, getRowSelected, maxHeight, isSearchable, isColumnFilterable, isSortable, onCheckedIndexesChange, onRowClick, rowHeight = 36, schema, searchPlaceholder, style, width, }) {
|
|
12
13
|
const [sortColumn, setSortColumn] = React.useState(defaultSortColumn);
|
|
13
14
|
const [sortAsc, setSortAsc] = React.useState(defaultSortAsc);
|
|
14
15
|
const [searchQuery, setSearchQuery] = React.useState("");
|
|
@@ -113,11 +114,12 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
113
114
|
let dynamicWidthColumnCount = 0;
|
|
114
115
|
columnNames.forEach((propName) => {
|
|
115
116
|
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
116
|
-
|
|
117
|
+
fixedWidthColumnsWidth += SELECT_ALL_COLUMN_WIDTH;
|
|
118
|
+
return;
|
|
117
119
|
}
|
|
118
120
|
const propConfig = config ? config[propName] : undefined;
|
|
119
121
|
if (propConfig === null || propConfig === void 0 ? void 0 : propConfig.width) {
|
|
120
|
-
fixedWidthColumnsWidth += propConfig.width
|
|
122
|
+
fixedWidthColumnsWidth += propConfig.width;
|
|
121
123
|
}
|
|
122
124
|
else {
|
|
123
125
|
dynamicWidthColumnCount += 1;
|
|
@@ -127,13 +129,25 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
127
129
|
}, [columnNames, config]);
|
|
128
130
|
const columnWidths = React.useMemo(() => {
|
|
129
131
|
const dynamicColumnWidth = Math.floor((width - fixedWidthColumnsWidth) / dynamicWidthColumnCount);
|
|
130
|
-
|
|
132
|
+
const result = columnNames.map((propName) => {
|
|
131
133
|
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
132
134
|
return SELECT_ALL_COLUMN_WIDTH;
|
|
133
135
|
}
|
|
134
136
|
const propConfig = config ? config[propName] : undefined;
|
|
135
137
|
return (propConfig === null || propConfig === void 0 ? void 0 : propConfig.width) || dynamicColumnWidth;
|
|
136
138
|
});
|
|
139
|
+
const totalWidth = sum(result);
|
|
140
|
+
if (totalWidth < width && dynamicWidthColumnCount) {
|
|
141
|
+
// find the last dynamic width column and adjust to overcome rounding differences
|
|
142
|
+
const lastDynamicColumnName = [...columnNames]
|
|
143
|
+
.reverse()
|
|
144
|
+
.find((propName) => !config || !config[propName].width);
|
|
145
|
+
if (lastDynamicColumnName) {
|
|
146
|
+
const lastDynamicColumnIndex = columnNames.indexOf(lastDynamicColumnName);
|
|
147
|
+
result[lastDynamicColumnIndex] += width - totalWidth;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
137
151
|
}, [
|
|
138
152
|
columnNames,
|
|
139
153
|
config,
|
|
@@ -246,13 +260,18 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
246
260
|
if (!onCheckedIndexesChange || !filteredRenderData) {
|
|
247
261
|
return;
|
|
248
262
|
}
|
|
249
|
-
onCheckedIndexesChange(filteredRenderData
|
|
250
|
-
|
|
263
|
+
onCheckedIndexesChange(filteredRenderData
|
|
264
|
+
.map((el) => el._index)
|
|
265
|
+
.filter((index) => !(disabledCheckedIndexes === null || disabledCheckedIndexes === void 0 ? void 0 : disabledCheckedIndexes.includes(index))));
|
|
266
|
+
}, [onCheckedIndexesChange, filteredRenderData, disabledCheckedIndexes]);
|
|
251
267
|
const isAllRowsChecked = React.useMemo(() => {
|
|
268
|
+
const tableData = [...(filteredRenderData || [])].filter((el) => (checkedIndexes ? checkedIndexes.includes(el._index) : true) ||
|
|
269
|
+
(disabledCheckedIndexes
|
|
270
|
+
? !disabledCheckedIndexes.includes(el._index)
|
|
271
|
+
: true));
|
|
252
272
|
return ((checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length) !== 0 &&
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}, [checkedIndexes, filteredRenderData]);
|
|
273
|
+
tableData.length === (checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length));
|
|
274
|
+
}, [checkedIndexes, disabledCheckedIndexes, filteredRenderData]);
|
|
256
275
|
const disableColumnFilter = React.useCallback((propName) => {
|
|
257
276
|
const newColumnFilterMap = Object.assign({}, columnFilterMap);
|
|
258
277
|
delete newColumnFilterMap[propName];
|
|
@@ -284,7 +303,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
284
303
|
]);
|
|
285
304
|
const SchemaTableTd = React.useCallback(({ columnIndex, rowIndex, style }) => {
|
|
286
305
|
const propName = columnNames[columnIndex];
|
|
287
|
-
return (_jsx(Td, { checkedIndexes: checkedIndexes, 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 }));
|
|
306
|
+
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 }));
|
|
288
307
|
}, [
|
|
289
308
|
checkedIndexes,
|
|
290
309
|
columnNames,
|
package/dist/index.css
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
.
|
|
2
|
-
|
|
1
|
+
.schema-table .popover {
|
|
2
|
+
--bs-popover-max-width: 1024px;
|
|
3
3
|
}
|
|
4
|
-
|
|
5
4
|
.schema-table__tbody {
|
|
6
5
|
overflow-x: hidden !important;
|
|
7
6
|
border-collapse: collapse;
|
|
@@ -10,22 +9,27 @@
|
|
|
10
9
|
.schema-table__th-row {
|
|
11
10
|
overflow: hidden !important;
|
|
12
11
|
}
|
|
13
|
-
.schema-
|
|
12
|
+
.schema-table .schema-column-filter-popover {
|
|
14
13
|
background-color: #eee;
|
|
15
14
|
}
|
|
16
|
-
.schema-
|
|
17
|
-
.schema-
|
|
15
|
+
.schema-table .schema-column-filter-popover input,
|
|
16
|
+
.schema-table .schema-column-filter-popover select {
|
|
18
17
|
width: 100%;
|
|
19
18
|
padding: 3px;
|
|
20
19
|
margin-top: 3px;
|
|
21
20
|
border-radius: 5px;
|
|
22
21
|
}
|
|
23
|
-
.schema-
|
|
22
|
+
.schema-table .schema-column-filter-popover input[type=checkbox] {
|
|
24
23
|
width: fit-content;
|
|
25
24
|
margin-top: 10px;
|
|
26
25
|
margin-left: 30px;
|
|
27
26
|
}
|
|
28
|
-
.schema-
|
|
27
|
+
.schema-table .schema-column-filter-popover input[type=number],
|
|
28
|
+
.schema-table .schema-column-filter-popover input[type=text],
|
|
29
|
+
.schema-table .schema-column-filter-popover select {
|
|
30
|
+
min-width: 150px;
|
|
31
|
+
}
|
|
32
|
+
.schema-table .schema-column-filter-popover .react-datepicker {
|
|
29
33
|
display: flex;
|
|
30
34
|
}
|
|
31
35
|
.schema-table__th {
|
|
@@ -47,7 +51,7 @@
|
|
|
47
51
|
font-style: italic;
|
|
48
52
|
}
|
|
49
53
|
.schema-table__th--column-filter-status-ACTIVE svg {
|
|
50
|
-
color: red;
|
|
54
|
+
color: var(--bs-red, red);
|
|
51
55
|
}
|
|
52
56
|
.schema-table__td {
|
|
53
57
|
overflow: hidden;
|
|
@@ -57,13 +61,13 @@
|
|
|
57
61
|
align-items: center;
|
|
58
62
|
}
|
|
59
63
|
.schema-table__td--odd {
|
|
60
|
-
background-color: #
|
|
64
|
+
background-color: var(--bs-gray-100, #f8f9fa);
|
|
61
65
|
}
|
|
62
66
|
.schema-table__td--even {
|
|
63
|
-
background-color: #fff;
|
|
67
|
+
background-color: var(--bs-white, #fff);
|
|
64
68
|
}
|
|
65
69
|
.schema-table__td--selected {
|
|
66
|
-
background-color: #
|
|
70
|
+
background-color: var(--bs-gray-300, #dee2e6);
|
|
67
71
|
}
|
|
68
72
|
.schema-table__search {
|
|
69
73
|
margin: 1rem;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mig-schema-table",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.30",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"react-window": "^1.8.9"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "tsc -p tsconfig.json; sass --no-source-map src/component/index.scss dist/index.css",
|
|
27
|
+
"build": "rm -rf dist; tsc -p tsconfig.json; sass --no-source-map src/component/index.scss dist/index.css",
|
|
28
28
|
"prepublishOnly": "npm run build",
|
|
29
29
|
"start": "react-scripts start",
|
|
30
30
|
"test": "react-scripts test"
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from "react";
|
|
2
|
-
import { IColumnConfig } from "../../types";
|
|
3
|
-
import { oas31 } from "openapi3-ts";
|
|
4
|
-
import "react-datepicker/dist/react-datepicker.css";
|
|
5
|
-
import { tColumnSearchValue } from "../index";
|
|
6
|
-
interface IColumnFilterRowProps {
|
|
7
|
-
columnNames: string[];
|
|
8
|
-
getWidth: (index: number) => number;
|
|
9
|
-
config?: {
|
|
10
|
-
[propName: string]: IColumnConfig<any>;
|
|
11
|
-
};
|
|
12
|
-
columnSearchHandler: (propName: string, value: tColumnSearchValue) => void;
|
|
13
|
-
value: {
|
|
14
|
-
[propName: string]: tColumnSearchValue;
|
|
15
|
-
};
|
|
16
|
-
schema: oas31.SchemaObject;
|
|
17
|
-
columnFilterDropdown?: string;
|
|
18
|
-
setColumnFilterDropdown?: Dispatch<SetStateAction<string | undefined>>;
|
|
19
|
-
}
|
|
20
|
-
export default function ColumnFilterRow({ columnNames, getWidth, config, value, columnSearchHandler, schema, columnFilterDropdown, setColumnFilterDropdown, }: IColumnFilterRowProps): import("react/jsx-runtime").JSX.Element;
|
|
21
|
-
export {};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { SELECT_ALL_COLUMN_NAME } from "../constants";
|
|
4
|
-
import DatePicker from "react-datepicker";
|
|
5
|
-
import nl from "date-fns/locale/nl";
|
|
6
|
-
import "react-datepicker/dist/react-datepicker.css";
|
|
7
|
-
import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, } from "../../inc/constant";
|
|
8
|
-
import { getUnixTimeStamp } from "../../inc/date";
|
|
9
|
-
export default function ColumnFilterRow({ columnNames, getWidth, config, value, columnSearchHandler, schema, columnFilterDropdown, setColumnFilterDropdown, }) {
|
|
10
|
-
const { properties = {} } = schema;
|
|
11
|
-
const getSelectComponent = React.useCallback((propSchema, propName, value, inputChangeHandler) => {
|
|
12
|
-
const enumItems = propSchema.type === "boolean" ? ["✓", "✕"] : propSchema.enum;
|
|
13
|
-
return (_jsxs("select", Object.assign({ value: value, "data-prop-name": propName, onChange: inputChangeHandler }, { children: [_jsx("option", Object.assign({ value: "" }, { children: "All" }), "all"), enumItems.map((name) => (_jsx("option", Object.assign({ value: name }, { children: name }), `column-filter-select-${name}`)))] })));
|
|
14
|
-
}, []);
|
|
15
|
-
const field = React.useCallback((propSchema, propName, propValue) => {
|
|
16
|
-
const { type, format, minimum, maximum } = propSchema;
|
|
17
|
-
const inputChangeHandler = (event) => {
|
|
18
|
-
columnSearchHandler(propName, event.target.value);
|
|
19
|
-
};
|
|
20
|
-
const strValue = (propValue || "");
|
|
21
|
-
switch (type) {
|
|
22
|
-
case "string":
|
|
23
|
-
if (propSchema.enum) {
|
|
24
|
-
return getSelectComponent(propSchema, propName, strValue, inputChangeHandler);
|
|
25
|
-
}
|
|
26
|
-
if (format === "date-time" || format === "date") {
|
|
27
|
-
const dateFormat = format === "date"
|
|
28
|
-
? DEFAULT_DATE_FORMAT
|
|
29
|
-
: DEFAULT_DATE_TIME_FORMAT;
|
|
30
|
-
const dateRangeValue = propValue;
|
|
31
|
-
const startDate = (dateRangeValue === null || dateRangeValue === void 0 ? void 0 : dateRangeValue.from)
|
|
32
|
-
? new Date(dateRangeValue.from)
|
|
33
|
-
: null;
|
|
34
|
-
const endDate = (dateRangeValue === null || dateRangeValue === void 0 ? void 0 : dateRangeValue.to)
|
|
35
|
-
? new Date(dateRangeValue.to)
|
|
36
|
-
: null;
|
|
37
|
-
const startDateChangeHandler = (date) => {
|
|
38
|
-
if (endDate && date && date > endDate) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
columnSearchHandler(propName, Object.assign(Object.assign({}, dateRangeValue), { from: `${date || ""}`, to: `${date && endDate ? dateRangeValue.to : ""}` }));
|
|
42
|
-
};
|
|
43
|
-
const endDateChangeHandler = (date) => {
|
|
44
|
-
if (startDate &&
|
|
45
|
-
date &&
|
|
46
|
-
getUnixTimeStamp(`${date}`) < getUnixTimeStamp(`${startDate}`)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
columnSearchHandler(propName, Object.assign(Object.assign({}, dateRangeValue), { to: `${date || ""}` }));
|
|
50
|
-
};
|
|
51
|
-
return (_jsx("div", Object.assign({ "data-bs-toggle": "dropdown-menu-item" }, { children: _jsxs("div", Object.assign({ className: "d-flex p-2" }, { children: [_jsxs("div", Object.assign({ className: "d-flex flex-column m-1" }, { children: [_jsx("label", { children: "Start date-time" }), _jsx(DatePicker, { id: "filter-date", dateFormat: dateFormat, "data-prop-name": propName, locale: nl, selected: startDate, onChange: startDateChangeHandler, placeholderText: dateFormat, isClearable: true, selectsStart: true, startDate: startDate, endDate: endDate, showTimeSelect: format === "date-time", timeIntervals: 15, shouldCloseOnSelect: format === "date" })] })), _jsxs("div", Object.assign({ className: "d-flex flex-column m-1" }, { children: [_jsx("label", { children: "End date-time" }), _jsx(DatePicker, { id: "filter-date", dateFormat: dateFormat, "data-prop-name": propName, locale: nl, selectsEnd: true, selected: endDate, onChange: endDateChangeHandler, placeholderText: dateFormat, isClearable: true, startDate: startDate, endDate: endDate, showTimeSelect: format === "date-time", timeIntervals: 15, shouldCloseOnSelect: format === "date" })] }))] })) })));
|
|
52
|
-
}
|
|
53
|
-
return (_jsx("div", Object.assign({ className: "p-1" }, { children: _jsx("input", { value: strValue, "data-prop-name": propName, onChange: inputChangeHandler, placeholder: `Search ${propName}` }) })));
|
|
54
|
-
case "integer":
|
|
55
|
-
return (_jsx("div", Object.assign({ className: "d-flex p-1" }, { children: _jsx("input", { type: "number", value: strValue, "data-prop-name": propName, onChange: inputChangeHandler, placeholder: `Search ${propName}`, min: minimum, max: maximum }) })));
|
|
56
|
-
case "boolean":
|
|
57
|
-
return getSelectComponent(propSchema, propName, strValue, inputChangeHandler);
|
|
58
|
-
default:
|
|
59
|
-
return _jsx(_Fragment, {});
|
|
60
|
-
}
|
|
61
|
-
}, [columnSearchHandler, getSelectComponent]);
|
|
62
|
-
const removeDropdown = React.useCallback((e) => {
|
|
63
|
-
if (!columnFilterDropdown) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
let columnFilterEl = null;
|
|
67
|
-
let parentNode = e.target;
|
|
68
|
-
while (parentNode && parentNode.nodeName !== "HTML") {
|
|
69
|
-
if (typeof parentNode.className === "string" &&
|
|
70
|
-
parentNode.className.includes("schema-table__column-filter")) {
|
|
71
|
-
columnFilterEl = parentNode;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
parentNode = parentNode.parentNode;
|
|
75
|
-
}
|
|
76
|
-
if (!columnFilterEl) {
|
|
77
|
-
setColumnFilterDropdown && setColumnFilterDropdown(undefined);
|
|
78
|
-
}
|
|
79
|
-
}, [columnFilterDropdown, setColumnFilterDropdown]);
|
|
80
|
-
React.useEffect(() => {
|
|
81
|
-
if (!columnFilterDropdown) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
window.addEventListener("click", removeDropdown, { capture: true });
|
|
85
|
-
return () => {
|
|
86
|
-
window.removeEventListener("click", removeDropdown, { capture: true });
|
|
87
|
-
};
|
|
88
|
-
}, [columnFilterDropdown, removeDropdown]);
|
|
89
|
-
const SchemaColumnFilter = React.useCallback((index) => {
|
|
90
|
-
const propName = columnNames[index];
|
|
91
|
-
const propSchema = properties[propName];
|
|
92
|
-
const propConfig = config ? config[propName] : undefined;
|
|
93
|
-
const propValue = value === null || value === void 0 ? void 0 : value[propName];
|
|
94
|
-
if (propName === SELECT_ALL_COLUMN_NAME || !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.isFilterable)) {
|
|
95
|
-
return _jsx("div", { className: "schema-table__th" });
|
|
96
|
-
}
|
|
97
|
-
return (_jsx("ul", Object.assign({ id: "test", className: `dropdown-menu dropdown-menu-lg-end ${columnFilterDropdown && columnFilterDropdown === propName
|
|
98
|
-
? "show"
|
|
99
|
-
: ""}`, style: {
|
|
100
|
-
position: "fixed",
|
|
101
|
-
marginTop: -10,
|
|
102
|
-
minHeight: 100,
|
|
103
|
-
} }, { children: _jsx("div", Object.assign({ id: "filter-dropdown-item", style: { margin: 10 } }, { children: field(propSchema, propName, propValue) })) })));
|
|
104
|
-
}, [columnFilterDropdown, columnNames, config, field, properties, value]);
|
|
105
|
-
return (_jsx("div", Object.assign({ className: "schema-table__th-row", style: { display: "flex", flex: "row" } }, { children: columnNames.map((columnName, index) => {
|
|
106
|
-
return (_jsx("div", Object.assign({ className: "schema-table__column-filter", style: {
|
|
107
|
-
width: getWidth(index),
|
|
108
|
-
paddingBottom: 7,
|
|
109
|
-
} }, { children: SchemaColumnFilter(index) }), `filter-${index}`));
|
|
110
|
-
}) })));
|
|
111
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "@testing-library/jest-dom";
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
import "@testing-library/jest-dom";
|
|
12
|
-
import { render, screen } from "@testing-library/react";
|
|
13
|
-
import SchemaTable from "./index";
|
|
14
|
-
it("renders an empty table", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
-
render(_jsx(SchemaTable, { data: [], schema: {}, width: 1 }));
|
|
16
|
-
const table = yield screen.findByRole("table");
|
|
17
|
-
expect(table).toBeInTheDocument();
|
|
18
|
-
}));
|