mig-schema-table 3.0.33 → 3.0.34

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.
@@ -1,11 +1,13 @@
1
1
  import React from "react";
2
2
  import { oas31 } from "openapi3-ts";
3
3
  import { TColumnFilterValue } from "../../index";
4
+ import { IColumnConfig } from "../../../types";
4
5
  interface IFilterFormComponentProps {
5
6
  onChange: (newValue?: TColumnFilterValue) => void;
6
7
  propSchema: oas31.SchemaObject;
7
8
  propName: string;
8
9
  columnFilterValue: TColumnFilterValue;
10
+ propConfig?: IColumnConfig<any>;
9
11
  }
10
- declare const _default: React.MemoExoticComponent<({ onChange, propSchema, propName, columnFilterValue, }: IFilterFormComponentProps) => import("react/jsx-runtime").JSX.Element>;
12
+ declare const _default: React.MemoExoticComponent<({ onChange, propSchema, propName, propConfig, columnFilterValue, }: IFilterFormComponentProps) => import("react/jsx-runtime").JSX.Element>;
11
13
  export default _default;
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
- import { uncamel } from "../../../inc/string";
3
+ 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, columnFilterValue, }) => {
7
+ const FilterFormComponent = ({ onChange, propSchema, propName, propConfig, columnFilterValue, }) => {
8
8
  const { type, format, minimum, maximum } = propSchema;
9
9
  const value = columnFilterValue;
10
10
  switch (type) {
@@ -36,7 +36,12 @@ const FilterFormComponent = ({ onChange, propSchema, propName, columnFilterValue
36
36
  if (propSchema.enum) {
37
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
- } }, { 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}`)))] })));
39
+ } }, { children: [_jsx("option", Object.assign({ value: "" }, { children: "All" }), "all"), propSchema.enum.map((name) => {
40
+ const rowName = !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.translation)
41
+ ? name
42
+ : t(name, propConfig.translation);
43
+ return (_jsx("option", Object.assign({ value: rowName }, { children: rowName }), `column-filter-select-${rowName}`));
44
+ })] })));
40
45
  }
41
46
  if (format === "date-time" || format === "date") {
42
47
  const dateFormat = format === "date" ? DEFAULT_DATE_FORMAT : DEFAULT_DATE_TIME_FORMAT;
@@ -1,9 +1,11 @@
1
1
  import React from "react";
2
2
  import { oas31 } from "openapi3-ts";
3
3
  import { TColumnFilterValue } from "../index";
4
+ import { IColumnConfig } from "../../types";
4
5
  export interface ISchemaColumnFilterPopoverConfig {
5
6
  referenceElement: HTMLElement;
6
7
  propName: string;
8
+ propConfig?: IColumnConfig<any>;
7
9
  }
8
10
  type TSchemaColumnFilterPopoverProps = ISchemaColumnFilterPopoverConfig & {
9
11
  onChange: (newValue?: TColumnFilterValue) => void;
@@ -11,5 +13,5 @@ type TSchemaColumnFilterPopoverProps = ISchemaColumnFilterPopoverConfig & {
11
13
  value: TColumnFilterValue;
12
14
  onClose: () => void;
13
15
  };
14
- declare const _default: React.MemoExoticComponent<({ onChange, onClose, propName, propSchema, referenceElement, value, }: TSchemaColumnFilterPopoverProps) => import("react/jsx-runtime").JSX.Element>;
16
+ declare const _default: React.MemoExoticComponent<({ onChange, onClose, propName, propSchema, referenceElement, value, propConfig, }: TSchemaColumnFilterPopoverProps) => import("react/jsx-runtime").JSX.Element>;
15
17
  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, }) => {
5
+ const SchemaColumnFilterPopover = ({ onChange, onClose, 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, {
@@ -32,6 +32,6 @@ const SchemaColumnFilterPopover = ({ onChange, onClose, propName, propSchema, re
32
32
  if (attributes.popper) {
33
33
  classNames.push(`bs-popover-${attributes.popper["data-popper-placement"]}`);
34
34
  }
35
- 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(FilterFormComponent, { onChange: onChange, propSchema: propSchema, propName: propName, columnFilterValue: value }) }))] })));
35
+ 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(FilterFormComponent, { onChange: onChange, propSchema: propSchema, propName: propName, columnFilterValue: value, propConfig: propConfig }) }))] })));
36
36
  };
37
37
  export default React.memo(SchemaColumnFilterPopover);
@@ -44,9 +44,16 @@ const Th = ({ isAllChecked, columnFilterStatus, disableColumnFilter, isSortable,
44
44
  return {
45
45
  referenceElement,
46
46
  propName,
47
+ propConfig,
47
48
  };
48
49
  });
49
- }, [columnFilterStatus, disableColumnFilter, propName, setPopoverConfig]);
50
+ }, [
51
+ columnFilterStatus,
52
+ disableColumnFilter,
53
+ propConfig,
54
+ propName,
55
+ setPopoverConfig,
56
+ ]);
50
57
  if (propName === SELECT_ALL_COLUMN_NAME) {
51
58
  return (_jsx("div", Object.assign({}, thDivProps, { children: _jsx("div", Object.assign({ style: {
52
59
  width: "100%",
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
3
  import { VariableSizeGrid, VariableSizeList } from "react-window";
4
4
  import { localeFormat } from "../inc/date";
5
- import { uncamel } from "../inc/string";
5
+ import { t, uncamel } from "../inc/string";
6
6
  import Th, { EColumnFilterStatus } from "./Th";
7
7
  import { SELECT_ALL_COLUMN_NAME, SELECT_ALL_COLUMN_WIDTH } from "./constants";
8
8
  import Td from "./Td";
@@ -66,7 +66,10 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
66
66
  prev[propName] = "?";
67
67
  return prev;
68
68
  }
69
- const rawValue = object[propName];
69
+ const val = object[propName];
70
+ const rawValue = !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.translation)
71
+ ? val
72
+ : t(val, propConfig.translation);
70
73
  switch (schema.type) {
71
74
  case "array":
72
75
  prev[propName] =
@@ -339,6 +342,6 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, disabledCheck
339
342
  }
340
343
  setColumnFilterMap((columnFilterMap) => (Object.assign(Object.assign({}, columnFilterMap), { [popoverConfig.propName]: newColumnFilterValue })));
341
344
  }, [disableColumnFilter, popoverConfig]);
342
- 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, 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_${tableBodyHeight}_${rowWidth}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}`), popoverConfig ? (_jsx(SchemaColumnFilterPopover, { referenceElement: popoverConfig.referenceElement, onClose: onPopoverClose, onChange: onSchemaColumnFilterChange, propName: popoverConfig.propName, propSchema: schema.properties[popoverConfig.propName], value: columnFilterMap[popoverConfig.propName] })) : null] })));
345
+ 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, 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_${tableBodyHeight}_${rowWidth}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}`), 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] })));
343
346
  }
344
347
  export default React.memo(SchemaTable);
@@ -1 +1,4 @@
1
1
  export declare function uncamel(camel: string): string;
2
+ export declare function t(key: string, db: {
3
+ [keyName: string]: string;
4
+ }): string;
@@ -15,3 +15,6 @@ export function uncamel(camel) {
15
15
  return ` ${nextIsUppercase ? letter : letter.toLowerCase()}`;
16
16
  }));
17
17
  }
18
+ export function t(key, db) {
19
+ return db[key] || uncamel(key);
20
+ }
package/dist/types.d.ts CHANGED
@@ -14,6 +14,9 @@ export interface IColumnConfig<T> {
14
14
  order?: number;
15
15
  isFilterable?: boolean;
16
16
  dateFormat?: string;
17
+ translation?: {
18
+ [keyName: string]: string;
19
+ };
17
20
  }
18
21
  export interface IRenderData {
19
22
  _index: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mig-schema-table",
3
- "version": "3.0.33",
3
+ "version": "3.0.34",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/"