@uxf/data-grid 11.56.0 → 11.57.0

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 CHANGED
@@ -44,17 +44,23 @@ yarn upgrade @uxf/core@latest @uxf/ui@latest @uxf/data-grid@latest
44
44
 
45
45
  ```tsx
46
46
  import { useDataGridControl } from "@uxf/data-grid/use-data-grid-control";
47
+ import { useUserConfigLocalStorageAdapter } from "@uxf/data-grid/user-config-storage-adapters/local-storage";
48
+
49
+ const { middleware, useUserConfig } = useUserConfigLocalStorageAdapter(schema);
47
50
 
48
51
  const { state, actions } = useDataGridControl({
49
- schema ,
52
+ schema,
50
53
  initialState: "Request or string (base64 encoded request)",
51
54
  userConfig: {
52
55
  columns: {
53
56
  id: { isHidden: true },
54
57
  }
55
58
  },
59
+ middleware,
56
60
  isDebug: true,
57
61
  });
62
+
63
+ useUserConfig(actions);
58
64
  ```
59
65
 
60
66
  ## Supported FilterHandlers
@@ -77,9 +83,14 @@ const { state, actions } = useDataGridControl({
77
83
  ```tsx
78
84
  import { useDataGridControl } from "@uxf/data-grid/use-data-grid-control";
79
85
  import { useDataGridFetching } from "@uxf/data-grid/use-data-grid-fetching";
86
+ import { useUserConfigLocalStorageAdapter } from "@uxf/data-grid/user-config-storage-adapters/local-storage";
80
87
 
81
88
  function BasicExample() {
82
- const { state, actions } = useDataGridControl({ schema });
89
+ const { middleware, useUserConfig } = useUserConfigLocalStorageAdapter(schema);
90
+ const { state, actions } = useDataGridControl({ schema, middleware });
91
+
92
+ useUserConfig(actions);
93
+
83
94
  const { isLoading, error, data, reload } = useDataGridFetching(loader, schema, "grid-name", state);
84
95
 
85
96
  return (
package/_store/reducer.js CHANGED
@@ -30,7 +30,7 @@ function getInitialState(schema, init, initialUserConfig) {
30
30
  }
31
31
  // eslint-disable-next-line complexity
32
32
  const reducer = (state, action) => {
33
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
33
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
34
34
  switch (action.type) {
35
35
  case "CHANGE_PAGE":
36
36
  return {
@@ -194,6 +194,10 @@ const reducer = (state, action) => {
194
194
  case "REINITIALIZE_USER_CONFIG":
195
195
  return {
196
196
  ...state,
197
+ request: {
198
+ ...state.request,
199
+ perPage: (_r = action.userConfig.perPage) !== null && _r !== void 0 ? _r : state.request.perPage,
200
+ },
197
201
  userConfig: action.userConfig,
198
202
  };
199
203
  default:
@@ -34,6 +34,7 @@ const data_grid_v2_1 = require("./data-grid-v2");
34
34
  const action_cell_1 = require("./table-v2/components/action-cell");
35
35
  const use_data_grid_control_1 = require("./use-data-grid-control");
36
36
  const use_data_grid_fetching_1 = require("./use-data-grid-fetching");
37
+ const local_storage_1 = require("./user-config-storage-adapters/local-storage");
37
38
  const merge_schema_with_config_1 = require("./utils/merge-schema-with-config");
38
39
  const actionCell = {
39
40
  width: 92,
@@ -79,10 +80,12 @@ const FILTER_BEHAVIOR_OPTIONS = [
79
80
  ];
80
81
  function Default() {
81
82
  const [filterBehavior, setFilterBehavior] = (0, react_1.useState)("filtersPerTab");
83
+ const { middleware, useUserConfig } = (0, local_storage_1.useUserConfigLocalStorageAdapter)(schema_1.schema);
82
84
  const { state, actions } = (0, use_data_grid_control_1.useDataGridControl)({
83
85
  schema: schema_1.schema,
84
- middleware: (newState, action) => console.log("middlerware", { newState, action }),
86
+ middleware,
85
87
  });
88
+ useUserConfig(actions);
86
89
  const { isLoading, error, data, reload } = (0, use_data_grid_fetching_1.useDataGridFetching)({
87
90
  loader: loader_1.loader,
88
91
  schema: schema_1.schema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/data-grid",
3
- "version": "11.56.0",
3
+ "version": "11.57.0",
4
4
  "description": "UXF DataGrid",
5
5
  "homepage": "https://gitlab.com/uxf-npm/data-grid#readme",
6
6
  "main": "index.js",
@@ -28,7 +28,7 @@ const cx_1 = require("@uxf/core/utils/cx");
28
28
  const icon_1 = require("@uxf/ui/icon");
29
29
  const react_1 = __importStar(require("react"));
30
30
  function HeaderCellComponent(props, ref) {
31
- var _a, _b;
31
+ var _a, _b, _c, _d;
32
32
  const iconName = !props.column.sort
33
33
  ? null
34
34
  : ((_a = props.sort) === null || _a === void 0 ? void 0 : _a.dir) === "asc"
@@ -38,7 +38,7 @@ function HeaderCellComponent(props, ref) {
38
38
  : "sort";
39
39
  return (
40
40
  // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
41
- react_1.default.createElement("div", { className: (0, cx_1.cx)(`uxf-dg-table__cell uxf-dg-table__cell--header uxf-dg-table__cell--type-${props.column.type}`, props.column.sort && "is-sortable"), onClick: props.onClick, ref: ref },
41
+ react_1.default.createElement("div", { className: (0, cx_1.cx)(`uxf-dg-table__cell uxf-dg-table__cell--header uxf-dg-table__cell--type-${props.column.type}`, props.column.sort && "is-sortable", ((_c = props.sort) === null || _c === void 0 ? void 0 : _c.dir) === "asc" && "is-sorted-asc", ((_d = props.sort) === null || _d === void 0 ? void 0 : _d.dir) === "desc" && "is-sorted-desc"), onClick: props.onClick, ref: ref },
42
42
  props.column.label,
43
43
  iconName && react_1.default.createElement(icon_1.Icon, { className: "ml-auto", name: iconName }),
44
44
  react_1.default.createElement("button", { className: "uxf-dg-table__column-resize-handle", onClick: (event) => event.stopPropagation(), onMouseDown: props.onResizeStart })));
@@ -0,0 +1,8 @@
1
+ import { DataGridControl } from "../use-data-grid-control";
2
+ import { Action } from "../use-data-grid-control/action";
3
+ import { Middleware } from "../use-data-grid-control/use-middleware-reducer";
4
+ import { DataGridState } from "./state";
5
+ export type UserConfigStorageAdapter = {
6
+ middleware: Middleware<DataGridState<any>, Action>;
7
+ useUserConfig: (actions: DataGridControl["actions"]) => void;
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -44,3 +44,4 @@ export type Action = {
44
44
  type: "REINITIALIZE_USER_CONFIG";
45
45
  userConfig: any;
46
46
  };
47
+ export declare const ACTIONS_CHANGING_USER_CONFIG: Array<Action["type"]>;
@@ -1,2 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ACTIONS_CHANGING_USER_CONFIG = void 0;
4
+ exports.ACTIONS_CHANGING_USER_CONFIG = [
5
+ "CHANGE_PER_PAGE",
6
+ "HIDE_COLUMN",
7
+ "SHOW_COLUMN",
8
+ "UPDATE_USER_CONFIG",
9
+ ];
@@ -0,0 +1,3 @@
1
+ import { Schema } from "../types";
2
+ import { UserConfigStorageAdapter } from "../types/user-config-storage-adapter";
3
+ export declare function useUserConfigLocalStorageAdapter(schema: Schema<any>): UserConfigStorageAdapter;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useUserConfigLocalStorageAdapter = useUserConfigLocalStorageAdapter;
4
+ const react_1 = require("react");
5
+ const action_1 = require("../use-data-grid-control/action");
6
+ const get_config_key_1 = require("../utils/get-config-key");
7
+ const isObject = (value) => typeof value === "function" || (typeof value === "object" && Boolean(value));
8
+ function useUserConfigLocalStorageAdapter(schema) {
9
+ const configKey = (0, get_config_key_1.getConfigKey)(schema);
10
+ return (0, react_1.useMemo)(() => ({
11
+ middleware: (newState, action) => {
12
+ if (action_1.ACTIONS_CHANGING_USER_CONFIG.includes(action.type)) {
13
+ window.localStorage.setItem(configKey, JSON.stringify(newState.userConfig));
14
+ }
15
+ },
16
+ useUserConfig: (actions) => {
17
+ (0, react_1.useEffect)(() => {
18
+ var _a;
19
+ let config = null;
20
+ try {
21
+ config = JSON.parse((_a = window.localStorage.getItem(configKey)) !== null && _a !== void 0 ? _a : "{}");
22
+ }
23
+ catch {
24
+ // ignore
25
+ }
26
+ if (isObject(config) && config !== null) {
27
+ actions.reinitializeUserConfig(config);
28
+ }
29
+ }, [actions]);
30
+ },
31
+ }), [configKey]);
32
+ }
@@ -0,0 +1,2 @@
1
+ import { Schema } from "../types";
2
+ export declare function getConfigKey(schema: Schema<any>): string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConfigKey = getConfigKey;
4
+ function getConfigKey(schema) {
5
+ return `data-grid-config__v2__${schema.name}`;
6
+ }