mig-schema-table 3.0.8 → 3.0.10

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.
@@ -0,0 +1,17 @@
1
+ import { IColumnConfig } from "../../types";
2
+ import { oas31 } from "openapi3-ts";
3
+ import "react-datepicker/dist/react-datepicker.css";
4
+ interface IColumnFilterRowProps {
5
+ columnNames: string[];
6
+ getWidth: (index: number) => number;
7
+ config?: {
8
+ [propName: string]: IColumnConfig<any>;
9
+ };
10
+ columnSearchHandler: (propName: string, value: string | number | boolean) => void;
11
+ value: {
12
+ [propName: string]: string | number | boolean;
13
+ };
14
+ schema: oas31.SchemaObject;
15
+ }
16
+ export default function ColumnFilterRow({ columnNames, getWidth, config, value, columnSearchHandler, schema, }: IColumnFilterRowProps): import("react/jsx-runtime").JSX.Element;
17
+ export {};
@@ -0,0 +1,62 @@
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 { localeFormat } from "../../inc/date";
8
+ import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, } from "../../inc/constant";
9
+ export default function ColumnFilterRow({ columnNames, getWidth, config, value, columnSearchHandler, schema, }) {
10
+ const { properties = {} } = schema;
11
+ const getSelectComponent = React.useCallback((propSchema, propName, value, inputChangeHandler) => {
12
+ const enumItems = propSchema.type === "boolean" ? ["true", "false"] : 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, propConfig) => {
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 = (propConfig === null || propConfig === void 0 ? void 0 : propConfig.dateFormat) ||
28
+ (format === "date"
29
+ ? DEFAULT_DATE_FORMAT
30
+ : DEFAULT_DATE_TIME_FORMAT);
31
+ const dateChangeHandler = (date) => {
32
+ columnSearchHandler(propName, date ? localeFormat(date, dateFormat) : "");
33
+ };
34
+ return (_jsx(DatePicker, { id: "filter-date", dateFormat: dateFormat, "data-prop-name": propName, showTimeSelect: format === "date-time", locale: nl, selected: propValue ? new Date(propValue) : null, onChange: dateChangeHandler, value: propValue || undefined, placeholderText: dateFormat, isClearable: true }));
35
+ }
36
+ return (_jsx("input", { value: strValue, "data-prop-name": propName, onChange: inputChangeHandler, placeholder: `Search ${propName}` }));
37
+ case "integer":
38
+ return (_jsx("input", { type: "number", value: strValue, "data-prop-name": propName, onChange: inputChangeHandler, placeholder: `Search ${propName}`, min: minimum, max: maximum }));
39
+ case "boolean":
40
+ return getSelectComponent(propSchema, propName, strValue, inputChangeHandler);
41
+ default:
42
+ return _jsx(_Fragment, {});
43
+ }
44
+ }, [columnSearchHandler, getSelectComponent]);
45
+ const SchemaColumnFilter = React.useCallback((index) => {
46
+ const propName = columnNames[index];
47
+ const propSchema = properties[propName];
48
+ const propConfig = config ? config[propName] : undefined;
49
+ const propValue = value === null || value === void 0 ? void 0 : value[propName];
50
+ if (propName === SELECT_ALL_COLUMN_NAME || !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.isFilterable)) {
51
+ return _jsx("div", { className: "schema-table__th" });
52
+ }
53
+ return (_jsx("div", Object.assign({ className: "schema-table__th" }, { children: field(propSchema, propName, propValue, propConfig) }), `filter-col-${propName}`));
54
+ }, [columnNames, config, field, properties, value]);
55
+ return (_jsx("div", Object.assign({ className: "schema-table__th-row", style: { display: "flex", flex: "row" } }, { children: columnNames.map((columnName, index) => {
56
+ return (_jsx("div", Object.assign({ className: "schema-table__column-filter", style: {
57
+ width: getWidth(index),
58
+ height: 25,
59
+ paddingBottom: 7,
60
+ } }, { children: SchemaColumnFilter(index) }), `filter-${index}`));
61
+ }) })));
62
+ }
@@ -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
- if (!sortedRenderData) {
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
  }
@@ -2,16 +2,10 @@ import { oas31 } from "openapi3-ts";
2
2
  import React, { CSSProperties, Dispatch, SetStateAction } from "react";
3
3
  import { IColumnConfig } from "../../types";
4
4
  interface IThProps {
5
- columnFilters?: {
6
- [prop: string]: any;
7
- };
8
5
  config?: IColumnConfig<any>;
9
6
  isSortable: boolean;
10
7
  name: string;
11
8
  schema: oas31.SchemaObject;
12
- setColumnFilters?: Dispatch<SetStateAction<{
13
- [prop: string]: any;
14
- } | undefined>>;
15
9
  setSortAsc: Dispatch<SetStateAction<boolean>>;
16
10
  setSortColumn: Dispatch<SetStateAction<string>>;
17
11
  sortAsc?: boolean;
@@ -20,5 +14,5 @@ interface IThProps {
20
14
  isAllChecked?: boolean;
21
15
  numberOfSelectedRows?: number;
22
16
  }
23
- declare const _default: ({ columnFilters, config, isSortable, name, schema, setColumnFilters, setSortAsc, setSortColumn, sortAsc, style, onSelectAllIndexesHandler, isAllChecked, numberOfSelectedRows, }: IThProps) => import("react/jsx-runtime").JSX.Element;
17
+ declare const _default: ({ config, isSortable, name, schema, setSortAsc, setSortColumn, sortAsc, style, onSelectAllIndexesHandler, isAllChecked, numberOfSelectedRows, }: IThProps) => import("react/jsx-runtime").JSX.Element;
24
18
  export default _default;
@@ -2,20 +2,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
3
  import { uncamel } from "../../inc/string";
4
4
  import { SELECT_ALL_COLUMN_NAME } from "../constants";
5
- const Th = ({ columnFilters, config, isSortable, name, schema, setColumnFilters, setSortAsc, setSortColumn, sortAsc, style, onSelectAllIndexesHandler, isAllChecked, numberOfSelectedRows, }) => {
5
+ const Th = ({ config, isSortable, name, schema, setSortAsc, setSortColumn, sortAsc, style, onSelectAllIndexesHandler, isAllChecked, numberOfSelectedRows, }) => {
6
6
  const thDivProps = {
7
7
  style,
8
8
  className: `schema-table__th ${isSortable ? "schema-table__th--sortable" : "schema-table__th--unsortable"}`,
9
9
  };
10
- const onFilterButtonClick = React.useCallback(() => {
11
- if (!setColumnFilters) {
12
- return;
13
- }
14
- if (columnFilters) {
15
- setColumnFilters(undefined);
16
- return;
17
- }
18
- }, [columnFilters, setColumnFilters]);
19
10
  const onSortButtonClick = React.useCallback(() => {
20
11
  if (sortAsc === undefined) {
21
12
  setSortColumn(name);
@@ -46,6 +37,6 @@ const Th = ({ columnFilters, config, isSortable, name, schema, setColumnFilters,
46
37
  thDivProps.className += ` text-${(config === null || config === void 0 ? void 0 : config.align) || "end"}`;
47
38
  }
48
39
  }
49
- return (_jsxs("div", Object.assign({}, thDivProps, { children: [isSortable ? (_jsxs("button", Object.assign({ className: "px-0", disabled: (config === null || config === void 0 ? void 0 : config.sortable) === false, onClick: onSortButtonClick }, { children: [(config === null || config === void 0 ? void 0 : config.title) === undefined ? uncamel(name) : config === null || config === void 0 ? void 0 : config.title, sortAsc === undefined ? null : sortAsc ? "▲" : "▼"] }))) : (_jsx("div", Object.assign({ style: { lineHeight: "44px" } }, { children: (config === null || config === void 0 ? void 0 : config.title) === undefined ? uncamel(name) : config === null || config === void 0 ? void 0 : config.title }))), (config === null || config === void 0 ? void 0 : config.isFilterable) ? (_jsx("button", Object.assign({ onClick: onFilterButtonClick }, { children: _jsx("svg", Object.assign({ viewBox: "0 0 36 36", xmlns: "http://www.w3.org/2000/svg", height: 16, width: 16, style: { display: "block" } }, { children: _jsx("polygon", { fill: "#231F20", points: "14,30 22,25 22,17 35.999,0 17.988,0 0,0 14,17 " }) })) }))) : null] })));
40
+ return (_jsx("div", Object.assign({}, thDivProps, { children: isSortable ? (_jsxs("button", Object.assign({ className: "px-0", disabled: (config === null || config === void 0 ? void 0 : config.sortable) === false, onClick: onSortButtonClick }, { children: [(config === null || config === void 0 ? void 0 : config.title) === undefined ? uncamel(name) : config === null || config === void 0 ? void 0 : config.title, sortAsc === undefined ? null : sortAsc ? "▲" : "▼"] }))) : (_jsx("div", Object.assign({ style: { lineHeight: "44px" } }, { children: (config === null || config === void 0 ? void 0 : config.title) === undefined ? uncamel(name) : config === null || config === void 0 ? void 0 : config.title }))) })));
50
41
  };
51
42
  export default React.memo(Th);
@@ -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,13 @@ 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
+ import ColumnFilterRow from "./ColumnFilterRow";
10
+ import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT } from "../inc/constant";
11
+ 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
12
  const [sortColumn, setSortColumn] = React.useState(defaultSortColumn);
11
13
  const [sortAsc, setSortAsc] = React.useState(defaultSortAsc);
12
14
  const [searchQuery, setSearchQuery] = React.useState("");
13
- const [columnFilters, setColumnFilters] = React.useState();
15
+ const [columnSearchObj, setColumnSearchObj] = React.useState({});
14
16
  const { properties = {} } = schema;
15
17
  const columnNames = React.useMemo(() => {
16
18
  const columns = Object.keys(properties);
@@ -52,24 +54,25 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
52
54
  }, [config, onCheckedIndexesChange, properties]);
53
55
  const renderData = React.useMemo(() => data
54
56
  ? data.map((object, rowIndex) => columnNames.reduce((prev, propName) => {
57
+ var _a;
55
58
  const schema = properties[propName];
56
59
  const propConfig = config ? config[propName] : undefined;
57
60
  if (propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderData) {
58
61
  prev[propName] = propConfig.renderData(object, rowIndex);
59
62
  return prev;
60
63
  }
61
- if (propName === SELECT_ALL_COLUMN_NAME) {
62
- prev[propName] = "asd";
63
- return prev;
64
- }
65
- if (!schema) {
64
+ if (!schema || propName === SELECT_ALL_COLUMN_NAME) {
66
65
  prev[propName] = "?";
67
66
  return prev;
68
67
  }
69
68
  const rawValue = object[propName];
70
69
  switch (schema.type) {
71
70
  case "array":
72
- prev[propName] = JSON.stringify(rawValue);
71
+ prev[propName] =
72
+ ((_a = schema.items) === null || _a === void 0 ? void 0 : _a.type) === "string" &&
73
+ rawValue
74
+ ? rawValue.map(uncamel).join(", ")
75
+ : JSON.stringify(rawValue);
73
76
  return prev;
74
77
  case "boolean":
75
78
  prev[propName] = rawValue ? "✓" : "✕";
@@ -85,11 +88,11 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
85
88
  prev[propName] =
86
89
  rawValue === "2999-12-31"
87
90
  ? "-"
88
- : localeFormat(new Date(rawValue), "dd MMM yyyy");
91
+ : localeFormat(new Date(rawValue), (propConfig === null || propConfig === void 0 ? void 0 : propConfig.dateFormat) || DEFAULT_DATE_FORMAT);
89
92
  return prev;
90
93
  }
91
94
  if (schema.format === "date-time" && rawValue) {
92
- prev[propName] = localeFormat(new Date(rawValue), "dd MMM yyyy hh:mm");
95
+ prev[propName] = localeFormat(new Date(rawValue), (propConfig === null || propConfig === void 0 ? void 0 : propConfig.dateFormat) || DEFAULT_DATE_TIME_FORMAT);
93
96
  return prev;
94
97
  }
95
98
  if (schema.enum) {
@@ -143,20 +146,38 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
143
146
  if (!result) {
144
147
  return result;
145
148
  }
146
- if (searchQuery) {
147
- const lcQuery = searchQuery.toLowerCase();
148
- result = result.filter((item) => !!columnNames.find((columnName) =>
149
- // @ts-ignore
150
- `${item[columnName]}`.toLowerCase().includes(lcQuery)));
151
- }
152
- if (!columnFilters) {
153
- return result;
149
+ if (isColumnSearchable || searchQuery) {
150
+ return result.filter((item) => {
151
+ const globalSearchFilterResult = searchQuery
152
+ ? !!columnNames.find((columnName) =>
153
+ // @ts-ignore
154
+ `${item[columnName]}`
155
+ .toLowerCase()
156
+ .includes(searchQuery.toLowerCase()))
157
+ : true;
158
+ const rowColumnValidation = isColumnSearchable
159
+ ? Object.keys(columnSearchObj).reduce((previousValue, propName) => {
160
+ const columnSearchText = columnSearchObj[propName];
161
+ const isBooleanValue = item[propName] === "✓" || item[propName] === "✕";
162
+ const rawValue = isBooleanValue
163
+ ? `${item[propName] === "✓"}`
164
+ : `${item[propName]}`;
165
+ previousValue.push(rawValue
166
+ .toLowerCase()
167
+ .includes(`${columnSearchText}`.toLowerCase()));
168
+ return previousValue;
169
+ }, [])
170
+ : [true];
171
+ return (globalSearchFilterResult && rowColumnValidation.every((el) => el));
172
+ });
154
173
  }
155
- const columnFilterEntries = Object.entries(columnFilters);
156
- return result.filter((item) => columnFilterEntries.find(([columnName, columnFilterValue]) =>
157
- // @ts-ignore
158
- data[item._index][columnName] === columnFilterValue));
159
- }, [columnFilters, columnNames, data, renderData, searchQuery]);
174
+ }, [
175
+ columnNames,
176
+ columnSearchObj,
177
+ isColumnSearchable,
178
+ renderData,
179
+ searchQuery,
180
+ ]);
160
181
  // Sort the filtered data
161
182
  const sortedRenderData = React.useMemo(() => {
162
183
  if (!sortColumn || !filteredRenderData) {
@@ -214,10 +235,9 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
214
235
  }, [checkedIndexes, filteredRenderData]);
215
236
  const SchemaTableTh = React.useCallback(({ style, index }) => {
216
237
  const propName = columnNames[index];
217
- return (_jsx(Th, { columnFilters: columnFilters, config: config ? config[propName] : undefined, isSortable: !!isSortable, name: propName, schema: properties[propName], setColumnFilters: setColumnFilters, setSortColumn: setSortColumn, setSortAsc: setSortAsc, sortAsc: sortColumn === propName ? sortAsc : undefined, style: style, onSelectAllIndexesHandler: onSelectAllIndexesHandler, isAllChecked: isAllRowsChecked, numberOfSelectedRows: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length }));
238
+ return (_jsx(Th, { config: config ? config[propName] : undefined, isSortable: !!isSortable, name: propName, schema: properties[propName], setSortColumn: setSortColumn, setSortAsc: setSortAsc, sortAsc: sortColumn === propName ? sortAsc : undefined, style: style, onSelectAllIndexesHandler: onSelectAllIndexesHandler, isAllChecked: isAllRowsChecked, numberOfSelectedRows: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length }));
218
239
  }, [
219
240
  columnNames,
220
- columnFilters,
221
241
  config,
222
242
  isSortable,
223
243
  properties,
@@ -242,6 +262,9 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
242
262
  rowHeight,
243
263
  sortedRenderData,
244
264
  ]);
265
+ const columnSearchHandler = React.useCallback((propName, value) => {
266
+ setColumnSearchObj((columnSearch) => (Object.assign(Object.assign({}, columnSearch), { [propName]: value })));
267
+ }, []);
245
268
  const onSearchChange = React.useCallback((e) => {
246
269
  setSearchQuery(e.currentTarget.value);
247
270
  }, []);
@@ -255,5 +278,5 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
255
278
  ? rowsMaxHeight
256
279
  : rowsHeight;
257
280
  }, [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(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}`)] })));
281
+ 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(ColumnFilterRow, { schema: schema, columnNames: columnNames, config: config, value: columnSearchObj, columnSearchHandler: columnSearchHandler, getWidth: getColumnWidth }), _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
282
  }
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_DATE_FORMAT = "dd-MM-yyyy";
2
+ export declare const DEFAULT_DATE_TIME_FORMAT = "dd MMM yyyy HH:mm";
@@ -0,0 +1,2 @@
1
+ export const DEFAULT_DATE_FORMAT = "dd-MM-yyyy";
2
+ export const DEFAULT_DATE_TIME_FORMAT = "dd MMM yyyy HH:mm";
package/dist/index.css CHANGED
@@ -9,6 +9,23 @@
9
9
  .schema-table__th-row {
10
10
  overflow: hidden !important;
11
11
  }
12
+ .schema-table__column-filter {
13
+ background-color: #eee;
14
+ }
15
+ .schema-table__column-filter input, .schema-table__column-filter select {
16
+ width: 90%;
17
+ padding: 3px;
18
+ margin-top: 3px;
19
+ border-radius: 5px;
20
+ }
21
+ .schema-table__column-filter input[type=checkbox] {
22
+ width: fit-content;
23
+ margin-top: 10px;
24
+ margin-left: 30px;
25
+ }
26
+ .schema-table__column-filter .react-datepicker {
27
+ display: flex;
28
+ }
12
29
  .schema-table__th {
13
30
  background-color: #eee;
14
31
  align-items: center;
package/dist/types.d.ts CHANGED
@@ -4,7 +4,6 @@ export interface IColumnConfig<T> {
4
4
  defaultSortDesc?: boolean;
5
5
  hidden?: boolean;
6
6
  hoverTitle?: string;
7
- isFilterable?: boolean;
8
7
  renderCell?: (rowData: T, dataIndex: number, rowIndex: number) => React.ReactElement | null;
9
8
  renderData?: (rowData: T, dataIndex: number) => string;
10
9
  sort?: (a: T, b: T, sortAsc: boolean) => number;
@@ -13,8 +12,10 @@ export interface IColumnConfig<T> {
13
12
  title?: string | React.ReactElement;
14
13
  width?: number;
15
14
  order?: number;
15
+ isFilterable?: boolean;
16
+ dateFormat?: string;
16
17
  }
17
18
  export interface IRenderData {
18
19
  _index: number;
19
- [key: string]: any;
20
+ [key: string]: string | any;
20
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mig-schema-table",
3
- "version": "3.0.8",
3
+ "version": "3.0.10",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/"
@@ -11,11 +11,13 @@
11
11
  "@types/jest": "^27.5.2",
12
12
  "@types/node": "^16.18.31",
13
13
  "@types/react": "^18.2.6",
14
+ "@types/react-datepicker": "^4.11.2",
14
15
  "@types/react-dom": "^18.2.4",
15
16
  "date-fns": "^2.30.0",
16
17
  "lodash": "^4.17.21",
17
18
  "openapi3-ts": "^4.1.2",
18
19
  "react": "^18.2.0",
20
+ "react-datepicker": "^4.14.0",
19
21
  "react-dom": "^18.2.0",
20
22
  "react-scripts": "5.0.1",
21
23
  "react-window": "^1.8.9"