mig-schema-table 3.0.42 → 3.0.44

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.
@@ -3,11 +3,12 @@ import { oas31 } from "openapi3-ts";
3
3
  import { TColumnFilterValue } from "../../index";
4
4
  import { IColumnConfig } from "../../../types";
5
5
  export interface IFilterFormComponentProps {
6
- onChange: (newValue?: TColumnFilterValue) => void;
7
- propSchema: oas31.SchemaObject;
8
- propName: string;
9
6
  columnFilterValue: TColumnFilterValue;
7
+ onChange: (newValue?: TColumnFilterValue) => void;
8
+ onInputKeyDown: (e: React.KeyboardEvent) => void;
10
9
  propConfig?: IColumnConfig<any>;
10
+ propName: string;
11
+ propSchema: oas31.SchemaObject;
11
12
  }
12
- declare const _default: React.MemoExoticComponent<({ onChange, propSchema, propName, propConfig, columnFilterValue, }: IFilterFormComponentProps) => import("react/jsx-runtime").JSX.Element>;
13
+ declare const _default: React.MemoExoticComponent<({ columnFilterValue, onChange, onInputKeyDown, propConfig, propName, propSchema, }: IFilterFormComponentProps) => import("react/jsx-runtime").JSX.Element>;
13
14
  export default _default;
@@ -4,22 +4,22 @@ import { t } from "../../../inc/string";
4
4
  import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, } from "../../../inc/constant";
5
5
  import DatePicker from "react-datepicker";
6
6
  import nl from "date-fns/locale/nl";
7
- const FilterFormComponent = ({ onChange, propSchema, propName, propConfig, columnFilterValue, }) => {
7
+ const FilterFormComponent = ({ columnFilterValue, onChange, onInputKeyDown, propConfig, propName, propSchema, }) => {
8
8
  const { type, format, minimum, maximum } = propSchema;
9
9
  const value = columnFilterValue;
10
10
  switch (type) {
11
11
  case "integer":
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) => {
12
+ return (_jsx("div", Object.assign({ className: "input-group" }, { children: _jsx("input", { autoFocus: true, 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));
16
- }, placeholder: `Search ${propName}`, min: minimum, max: maximum }) })));
16
+ }, onKeyDown: onInputKeyDown, placeholder: `Search ${propName}`, min: minimum, max: maximum }) })));
17
17
  case "boolean":
18
18
  let selectValue = value ? "✓" : "✕";
19
19
  if (value === undefined) {
20
20
  selectValue = "";
21
21
  }
22
- return (_jsxs("select", Object.assign({ className: "form-select", value: selectValue, "data-prop-name": propName, onChange: (e) => {
22
+ return (_jsxs("select", Object.assign({ autoFocus: true, 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, propConfig, colum
34
34
  // @ts-ignore
35
35
  case "string":
36
36
  if (propSchema.enum) {
37
- return (_jsxs("select", Object.assign({ className: "form-select", value: value, "data-prop-name": propName, onChange: (e) => {
37
+ return (_jsxs("select", Object.assign({ autoFocus: true, 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) => {
40
40
  const rowName = !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.translation)
@@ -69,13 +69,13 @@ const FilterFormComponent = ({ onChange, propSchema, propName, propConfig, colum
69
69
  }
70
70
  onChange(Object.assign(Object.assign({}, columnFilterValue), { to: date || undefined }));
71
71
  };
72
- 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" })] }))] })));
72
+ 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, { autoFocus: true, 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" })] }))] })));
73
73
  }
74
74
  // falls through
75
75
  default:
76
- 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) => {
76
+ return (_jsx("div", Object.assign({ className: "input-group" }, { children: _jsx("input", { autoFocus: true, type: "text", className: "form-control", placeholder: `Search ${propName}`, "aria-label": `Search ${propName}`, value: (value || ""), "data-prop-name": propName, onChange: (e) => {
77
77
  onChange(e.currentTarget.value || undefined);
78
- } }) })));
78
+ }, onKeyDown: onInputKeyDown }) })));
79
79
  }
80
80
  };
81
81
  export default React.memo(FilterFormComponent);
@@ -9,9 +9,10 @@ export interface ISchemaColumnFilterPopoverConfig {
9
9
  }
10
10
  type TSchemaColumnFilterPopoverProps = ISchemaColumnFilterPopoverConfig & {
11
11
  onChange: (newValue?: TColumnFilterValue) => void;
12
+ onInputKeyDown: (e: React.KeyboardEvent) => void;
12
13
  propSchema: oas31.SchemaObject;
13
14
  value: TColumnFilterValue;
14
15
  onClose: () => void;
15
16
  };
16
- declare const _default: React.MemoExoticComponent<({ onChange, onClose, propName, propSchema, referenceElement, value, propConfig, }: TSchemaColumnFilterPopoverProps) => import("react/jsx-runtime").JSX.Element>;
17
+ declare const _default: React.MemoExoticComponent<({ onChange, onClose, onInputKeyDown, propName, propSchema, referenceElement, value, propConfig, }: TSchemaColumnFilterPopoverProps) => import("react/jsx-runtime").JSX.Element>;
17
18
  export default _default;
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
3
  import FilterFormComponent from "./FilterFormComponent";
4
4
  import { usePopper } from "react-popper";
5
- const SchemaColumnFilterPopover = ({ onChange, onClose, propName, propSchema, referenceElement, value, propConfig, }) => {
5
+ const SchemaColumnFilterPopover = ({ onChange, onClose, onInputKeyDown, propName, propSchema, referenceElement, value, propConfig, }) => {
6
6
  const [popperElement, setPopperElement] = React.useState(null);
7
7
  const [arrowElement, setArrowElement] = React.useState(null);
8
8
  const { styles, attributes } = usePopper(referenceElement, popperElement, {
@@ -33,6 +33,6 @@ const SchemaColumnFilterPopover = ({ onChange, onClose, propName, propSchema, re
33
33
  classNames.push(`bs-popover-${attributes.popper["data-popper-placement"]}`);
34
34
  }
35
35
  const FilterForm = (propConfig === null || propConfig === void 0 ? void 0 : propConfig.FilterForm) || FilterFormComponent;
36
- return (_jsxs("div", Object.assign({ className: classNames.join(" "), role: "tooltip", ref: setPopperElement, style: styles.popper }, attributes.popper, { children: [_jsx("div", { className: "popover-arrow", ref: setArrowElement, style: styles.arrow }), _jsx("div", Object.assign({ className: "popover-body" }, { children: _jsx(FilterForm, { onChange: onChange, propSchema: propSchema, propName: propName, columnFilterValue: value, propConfig: propConfig }) }))] })));
36
+ return (_jsxs("div", Object.assign({ className: classNames.join(" "), role: "tooltip", ref: setPopperElement, style: styles.popper }, attributes.popper, { children: [_jsx("div", { className: "popover-arrow", ref: setArrowElement, style: styles.arrow }), _jsx("div", Object.assign({ className: "popover-body" }, { children: _jsx(FilterForm, { onChange: onChange, onInputKeyDown: onInputKeyDown, propSchema: propSchema, propName: propName, columnFilterValue: value, propConfig: propConfig }) }))] })));
37
37
  };
38
38
  export default React.memo(SchemaColumnFilterPopover);
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { oas31 } from "openapi3-ts";
3
3
  import { IColumnConfig } from "../types";
4
- interface IGetDataProps {
4
+ export interface IGetDataProps {
5
5
  searchQuery: string;
6
6
  columnFilterMap: {
7
7
  [propName: string]: TColumnFilterValue;
@@ -312,8 +312,11 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
312
312
  const disableColumnFilter = React.useCallback((propName) => {
313
313
  const newColumnFilterMap = Object.assign({}, columnFilterMap);
314
314
  delete newColumnFilterMap[propName];
315
+ if (data instanceof Function) {
316
+ setIsDirty(true);
317
+ }
315
318
  setColumnFilterMap(newColumnFilterMap);
316
- }, [columnFilterMap]);
319
+ }, [columnFilterMap, data]);
317
320
  const onSetSortColumn = React.useCallback((x) => {
318
321
  if (data instanceof Function) {
319
322
  setIsDirty(true);
@@ -385,9 +388,12 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
385
388
  setIsDirty(false);
386
389
  setSourceData(undefined);
387
390
  }, []);
388
- const onSearchKeyDown = React.useCallback((e) => {
389
- if (e.key === "Enter" && isDirty) {
390
- refreshData();
391
+ const onInputKeyDown = React.useCallback((e) => {
392
+ if (e.key === "Enter") {
393
+ setPopoverConfig(undefined);
394
+ if (isDirty) {
395
+ refreshData();
396
+ }
391
397
  }
392
398
  }, [isDirty, refreshData]);
393
399
  const getRowHeight = React.useCallback(() => rowHeight, [rowHeight]);
@@ -416,7 +422,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
416
422
  }
417
423
  setColumnFilterMap((columnFilterMap) => (Object.assign(Object.assign({}, columnFilterMap), { [popoverConfig.propName]: newColumnFilterValue })));
418
424
  }, [data, disableColumnFilter, popoverConfig]);
419
- 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: onSearchKeyDown, autoFocus: true })) : null })), customElement] })), _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: SchemaTableTh }), `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: {
425
+ 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: true })) : null })), customElement] })), _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: SchemaTableTh }), `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: {
420
426
  width: rowWidth,
421
427
  height: Math.max(50, tableBodyHeight),
422
428
  border: "1px solid #BBB",
@@ -425,6 +431,6 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
425
431
  backgroundColor: "#CCC",
426
432
  alignItems: "center",
427
433
  justifyContent: "center",
428
- } }, { children: isDirty ? (_jsx("button", Object.assign({ onClick: refreshData, className: "btn border" }, { children: "Refresh data" }))) : (_jsx("div", { children: "\u231B Loading..." })) }))), popoverConfig ? (_jsx(SchemaColumnFilterPopover, { referenceElement: popoverConfig.referenceElement, onClose: onPopoverClose, onChange: onSchemaColumnFilterChange, propName: popoverConfig.propName, propSchema: schema.properties[popoverConfig.propName], value: columnFilterMap[popoverConfig.propName], propConfig: popoverConfig.propConfig })) : null] })));
434
+ } }, { children: isDirty ? (_jsx("button", Object.assign({ onClick: refreshData, className: "btn border" }, { children: "Refresh data" }))) : (_jsx("div", { children: "\u231B Loading..." })) }))), popoverConfig ? (_jsx(SchemaColumnFilterPopover, { referenceElement: popoverConfig.referenceElement, onClose: onPopoverClose, onChange: onSchemaColumnFilterChange, onInputKeyDown: onInputKeyDown, propName: popoverConfig.propName, propSchema: schema.properties[popoverConfig.propName], value: columnFilterMap[popoverConfig.propName], propConfig: popoverConfig.propConfig })) : null] })));
429
435
  }
430
436
  export default React.memo(SchemaTable);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mig-schema-table",
3
- "version": "3.0.42",
3
+ "version": "3.0.44",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/"