mig-schema-table 3.0.8 → 3.0.9
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.js +30 -16
- package/dist/SchemaTable/index.d.ts +2 -1
- package/dist/SchemaTable/index.js +52 -9
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
|
@@ -13,22 +13,38 @@ function Td({ checkedIndexes, columnIndex, data, getRowClassName, getRowSelected
|
|
|
13
13
|
const row = sortedRenderData[parseInt(rowIndex, 10)];
|
|
14
14
|
onRowClick(data[row._index], row._index, e);
|
|
15
15
|
}, [data, onRowClick, sortedRenderData]);
|
|
16
|
-
|
|
16
|
+
const row = sortedRenderData ? sortedRenderData[rowIndex] : undefined;
|
|
17
|
+
const tdDivProps = React.useMemo(() => {
|
|
18
|
+
if (!row) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
"data-row-index": rowIndex,
|
|
23
|
+
"data-column-index": columnIndex,
|
|
24
|
+
key: propName,
|
|
25
|
+
style: Object.assign(Object.assign({}, style), { lineHeight: `${rowHeight}px` }),
|
|
26
|
+
onClick: !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell) ? onTdClick : undefined,
|
|
27
|
+
className: `schema-table__td schema-table__td--${rowIndex % 2 ? "odd" : "even"}${getRowSelected && getRowSelected(data[row._index])
|
|
28
|
+
? " schema-table__td--selected"
|
|
29
|
+
: ""} ${getRowClassName ? getRowClassName(data[row._index], row._index) : ""}`,
|
|
30
|
+
title: row[propName],
|
|
31
|
+
};
|
|
32
|
+
}, [
|
|
33
|
+
columnIndex,
|
|
34
|
+
data,
|
|
35
|
+
getRowClassName,
|
|
36
|
+
getRowSelected,
|
|
37
|
+
onTdClick,
|
|
38
|
+
propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell,
|
|
39
|
+
propName,
|
|
40
|
+
row,
|
|
41
|
+
rowHeight,
|
|
42
|
+
rowIndex,
|
|
43
|
+
style,
|
|
44
|
+
]);
|
|
45
|
+
if (!row || !tdDivProps) {
|
|
17
46
|
return null;
|
|
18
47
|
}
|
|
19
|
-
const row = sortedRenderData[rowIndex];
|
|
20
|
-
const tdDivProps = {
|
|
21
|
-
"data-row-index": rowIndex,
|
|
22
|
-
"data-column-index": columnIndex,
|
|
23
|
-
key: propName,
|
|
24
|
-
style: Object.assign(Object.assign({}, style), { lineHeight: `${rowHeight}px` }),
|
|
25
|
-
onClick: !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell) ? onTdClick : undefined,
|
|
26
|
-
className: `schema-table__td schema-table__td--${rowIndex % 2 ? "odd" : "even"}${row && getRowSelected && getRowSelected(data[row._index])
|
|
27
|
-
? " schema-table__td--selected"
|
|
28
|
-
: ""} ${row && getRowClassName
|
|
29
|
-
? getRowClassName(data[row._index], row._index)
|
|
30
|
-
: ""}`,
|
|
31
|
-
};
|
|
32
48
|
if (propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell) {
|
|
33
49
|
return (_jsx("div", Object.assign({}, tdDivProps, { children: propConfig.renderCell(data[row._index], row._index, rowIndex) })));
|
|
34
50
|
}
|
|
@@ -53,8 +69,6 @@ function Td({ checkedIndexes, columnIndex, data, getRowClassName, getRowSelected
|
|
|
53
69
|
tdDivProps.className += ` text-${(propConfig === null || propConfig === void 0 ? void 0 : propConfig.align) || "end"}`;
|
|
54
70
|
break;
|
|
55
71
|
case "string":
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
tdDivProps.title = row[propName];
|
|
58
72
|
if (propSchema.format === "date" || propSchema.format === "date-time") {
|
|
59
73
|
tdDivProps.className += ` text-${(propConfig === null || propConfig === void 0 ? void 0 : propConfig.align) || "end"}`;
|
|
60
74
|
}
|
|
@@ -15,6 +15,7 @@ export interface ISchemaTableComponentProps<T> {
|
|
|
15
15
|
getRowSelected?: (rowData: T) => boolean;
|
|
16
16
|
maxHeight?: number;
|
|
17
17
|
isSearchable?: boolean;
|
|
18
|
+
isColumnSearchable?: boolean;
|
|
18
19
|
isSortable?: boolean;
|
|
19
20
|
onCheckedIndexesChange?: (dataIndex: number[]) => void;
|
|
20
21
|
onRowClick?: (rowData: T, dataIndex: number, event: React.MouseEvent) => void;
|
|
@@ -24,4 +25,4 @@ export interface ISchemaTableComponentProps<T> {
|
|
|
24
25
|
style?: React.CSSProperties;
|
|
25
26
|
width: number;
|
|
26
27
|
}
|
|
27
|
-
export default function SchemaTable<T>({ Heading, checkedIndexes, config, customElement, data, defaultSortAsc, defaultSortColumn, getRowClassName, getRowSelected, maxHeight, isSearchable, isSortable, onCheckedIndexesChange, onRowClick, rowHeight, schema, searchPlaceholder, style, width, }: ISchemaTableComponentProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
export default function SchemaTable<T>({ Heading, checkedIndexes, config, customElement, data, defaultSortAsc, defaultSortColumn, getRowClassName, getRowSelected, maxHeight, isSearchable, isColumnSearchable, isSortable, onCheckedIndexesChange, onRowClick, rowHeight, schema, searchPlaceholder, style, width, }: ISchemaTableComponentProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -6,11 +6,12 @@ import { uncamel } from "../inc/string";
|
|
|
6
6
|
import Th from "./Th";
|
|
7
7
|
import { SELECT_ALL_COLUMN_NAME, SELECT_ALL_COLUMN_WIDTH } from "./constants";
|
|
8
8
|
import Td from "./Td";
|
|
9
|
-
export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, customElement, data, defaultSortAsc = false, defaultSortColumn, getRowClassName, getRowSelected, maxHeight, isSearchable, isSortable, onCheckedIndexesChange, onRowClick, rowHeight = 36, schema, searchPlaceholder, style, width, }) {
|
|
9
|
+
export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, customElement, data, defaultSortAsc = false, defaultSortColumn, getRowClassName, getRowSelected, maxHeight, isSearchable, isColumnSearchable, isSortable, onCheckedIndexesChange, onRowClick, rowHeight = 36, schema, searchPlaceholder, style, width, }) {
|
|
10
10
|
const [sortColumn, setSortColumn] = React.useState(defaultSortColumn);
|
|
11
11
|
const [sortAsc, setSortAsc] = React.useState(defaultSortAsc);
|
|
12
12
|
const [searchQuery, setSearchQuery] = React.useState("");
|
|
13
13
|
const [columnFilters, setColumnFilters] = React.useState();
|
|
14
|
+
const [columnSearchObj, setColumnSearchObj] = React.useState({});
|
|
14
15
|
const { properties = {} } = schema;
|
|
15
16
|
const columnNames = React.useMemo(() => {
|
|
16
17
|
const columns = Object.keys(properties);
|
|
@@ -52,24 +53,25 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
|
|
|
52
53
|
}, [config, onCheckedIndexesChange, properties]);
|
|
53
54
|
const renderData = React.useMemo(() => data
|
|
54
55
|
? data.map((object, rowIndex) => columnNames.reduce((prev, propName) => {
|
|
56
|
+
var _a;
|
|
55
57
|
const schema = properties[propName];
|
|
56
58
|
const propConfig = config ? config[propName] : undefined;
|
|
57
59
|
if (propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderData) {
|
|
58
60
|
prev[propName] = propConfig.renderData(object, rowIndex);
|
|
59
61
|
return prev;
|
|
60
62
|
}
|
|
61
|
-
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
62
|
-
prev[propName] = "asd";
|
|
63
|
-
return prev;
|
|
64
|
-
}
|
|
65
|
-
if (!schema) {
|
|
63
|
+
if (!schema || propName === SELECT_ALL_COLUMN_NAME) {
|
|
66
64
|
prev[propName] = "?";
|
|
67
65
|
return prev;
|
|
68
66
|
}
|
|
69
67
|
const rawValue = object[propName];
|
|
70
68
|
switch (schema.type) {
|
|
71
69
|
case "array":
|
|
72
|
-
prev[propName] =
|
|
70
|
+
prev[propName] =
|
|
71
|
+
((_a = schema.items) === null || _a === void 0 ? void 0 : _a.type) === "string" &&
|
|
72
|
+
rawValue
|
|
73
|
+
? rawValue.map(uncamel).join(", ")
|
|
74
|
+
: JSON.stringify(rawValue);
|
|
73
75
|
return prev;
|
|
74
76
|
case "boolean":
|
|
75
77
|
prev[propName] = rawValue ? "✓" : "✕";
|
|
@@ -149,6 +151,18 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
|
|
|
149
151
|
// @ts-ignore
|
|
150
152
|
`${item[columnName]}`.toLowerCase().includes(lcQuery)));
|
|
151
153
|
}
|
|
154
|
+
if (isColumnSearchable) {
|
|
155
|
+
return result.filter((item) => {
|
|
156
|
+
const rowColumnValidation = Object.keys(columnSearchObj).reduce((previousValue, propName) => {
|
|
157
|
+
const columnSearchText = columnSearchObj[propName];
|
|
158
|
+
previousValue.push(`${item[propName]}`
|
|
159
|
+
.toLowerCase()
|
|
160
|
+
.includes(columnSearchText.toLowerCase()));
|
|
161
|
+
return previousValue;
|
|
162
|
+
}, []);
|
|
163
|
+
return rowColumnValidation.every((el) => el);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
152
166
|
if (!columnFilters) {
|
|
153
167
|
return result;
|
|
154
168
|
}
|
|
@@ -156,7 +170,15 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
|
|
|
156
170
|
return result.filter((item) => columnFilterEntries.find(([columnName, columnFilterValue]) =>
|
|
157
171
|
// @ts-ignore
|
|
158
172
|
data[item._index][columnName] === columnFilterValue));
|
|
159
|
-
}, [
|
|
173
|
+
}, [
|
|
174
|
+
columnFilters,
|
|
175
|
+
columnNames,
|
|
176
|
+
columnSearchObj,
|
|
177
|
+
data,
|
|
178
|
+
isColumnSearchable,
|
|
179
|
+
renderData,
|
|
180
|
+
searchQuery,
|
|
181
|
+
]);
|
|
160
182
|
// Sort the filtered data
|
|
161
183
|
const sortedRenderData = React.useMemo(() => {
|
|
162
184
|
if (!sortColumn || !filteredRenderData) {
|
|
@@ -242,6 +264,21 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
|
|
|
242
264
|
rowHeight,
|
|
243
265
|
sortedRenderData,
|
|
244
266
|
]);
|
|
267
|
+
const columnSearchHandler = React.useCallback((e) => {
|
|
268
|
+
setColumnSearchObj((columnSearch) => (Object.assign(Object.assign({}, columnSearch), { [e.target.dataset.propName]: e.target.value })));
|
|
269
|
+
}, []);
|
|
270
|
+
const SchemaColumnFilter = React.useCallback((index) => {
|
|
271
|
+
const propName = columnNames[index];
|
|
272
|
+
// const propSchema = properties[propName] as oas31.SchemaObject;
|
|
273
|
+
const propConfig = config ? config[propName] : undefined;
|
|
274
|
+
if (propName === SELECT_ALL_COLUMN_NAME || !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.isSearchable)) {
|
|
275
|
+
return _jsx("div", { className: "schema-table__th", style: style });
|
|
276
|
+
}
|
|
277
|
+
return (_jsx("div", Object.assign({ className: "schema-table__th" }, { children: _jsx("input", { value: columnSearchObj === null || columnSearchObj === void 0 ? void 0 : columnSearchObj[propName], "data-prop-name": propName, onChange: columnSearchHandler, style: {
|
|
278
|
+
marginRight: 2,
|
|
279
|
+
width: "90%",
|
|
280
|
+
} }) }), `filter-col-${propName}`));
|
|
281
|
+
}, [columnNames, columnSearchHandler, columnSearchObj, config, style]);
|
|
245
282
|
const onSearchChange = React.useCallback((e) => {
|
|
246
283
|
setSearchQuery(e.currentTarget.value);
|
|
247
284
|
}, []);
|
|
@@ -255,5 +292,11 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
|
|
|
255
292
|
? rowsMaxHeight
|
|
256
293
|
: rowsHeight;
|
|
257
294
|
}, [maxHeight, isSearchable, rowCount, rowHeight]);
|
|
258
|
-
return (_jsxs("div", Object.assign({ className: `schema-table${onRowClick ? " schema-table--clickable-rows" : ""}`, style: Object.assign(Object.assign({}, style), { width: rowWidth }) }, { 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}`), _jsx(
|
|
295
|
+
return (_jsxs("div", Object.assign({ className: `schema-table${onRowClick ? " schema-table--clickable-rows" : ""}`, style: Object.assign(Object.assign({}, style), { width: rowWidth }) }, { 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}`), _jsx("div", Object.assign({ className: "schema-table__th-row", style: { display: "flex", flex: "row" } }, { children: columnNames.map((columnName, index) => {
|
|
296
|
+
return (_jsx("div", Object.assign({ className: "schema-table__th", style: {
|
|
297
|
+
width: getColumnWidth(index),
|
|
298
|
+
height: 20,
|
|
299
|
+
paddingBottom: 8,
|
|
300
|
+
} }, { children: SchemaColumnFilter(index) }), `filter-${index}`));
|
|
301
|
+
}) })), _jsx(VariableSizeGrid, Object.assign({ className: "schema-table__tbody", height: tableBodyHeight, width: rowWidth, columnWidth: getColumnWidth, rowHeight: getRowHeight, columnCount: columnCount, rowCount: rowCount }, { children: SchemaTableTd }), `tbody_${rowWidth}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}`)] })));
|
|
259
302
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -13,8 +13,9 @@ export interface IColumnConfig<T> {
|
|
|
13
13
|
title?: string | React.ReactElement;
|
|
14
14
|
width?: number;
|
|
15
15
|
order?: number;
|
|
16
|
+
isSearchable?: boolean;
|
|
16
17
|
}
|
|
17
18
|
export interface IRenderData {
|
|
18
19
|
_index: number;
|
|
19
|
-
[key: string]: any;
|
|
20
|
+
[key: string]: string | any;
|
|
20
21
|
}
|