@uxf/data-grid 11.4.0 → 11.6.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/_store/reducer.js CHANGED
@@ -4,23 +4,20 @@ exports.debugReducer = exports.reducer = exports.getInitialState = void 0;
4
4
  const is_nil_1 = require("@uxf/core/utils/is-nil");
5
5
  const utils_1 = require("../utils");
6
6
  function getInitialState(schema, init, initialUserConfig) {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
7
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
8
8
  const initialState = (0, is_nil_1.isNil)(init) ? {} : typeof init === "string" ? (_a = (0, utils_1.decodeFilter)(init)) !== null && _a !== void 0 ? _a : {} : init;
9
- const tabName = (_e = (_b = initialState.tab) !== null && _b !== void 0 ? _b : (_d = (_c = schema.tabs) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : null;
10
- const tabSort = tabName !== null ? (_g = (_f = schema.tabs) === null || _f === void 0 ? void 0 : _f.find((t) => t.name === tabName)) === null || _g === void 0 ? void 0 : _g.s : null;
9
+ const initialTabName = (_e = (_b = initialState.tab) !== null && _b !== void 0 ? _b : (_d = (_c = schema.tabs) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : null;
10
+ const initialTabSort = initialTabName !== null ? (_g = (_f = schema.tabs) === null || _f === void 0 ? void 0 : _f.find((t) => t.name === initialTabName)) === null || _g === void 0 ? void 0 : _g.s : null;
11
11
  return {
12
12
  request: {
13
13
  f: (_h = initialState.f) !== null && _h !== void 0 ? _h : [],
14
- s: (_k = (_j = initialState.s) !== null && _j !== void 0 ? _j : tabSort) !== null && _k !== void 0 ? _k : schema.s,
14
+ s: (_k = (_j = initialState.s) !== null && _j !== void 0 ? _j : initialTabSort) !== null && _k !== void 0 ? _k : schema.s,
15
15
  page: (_l = initialState.page) !== null && _l !== void 0 ? _l : 0,
16
16
  perPage: (_o = (_m = initialState.perPage) !== null && _m !== void 0 ? _m : initialUserConfig === null || initialUserConfig === void 0 ? void 0 : initialUserConfig.perPage) !== null && _o !== void 0 ? _o : schema.perPage,
17
- tab: tabName,
17
+ tab: initialTabName,
18
18
  search: (_p = initialState.search) !== null && _p !== void 0 ? _p : "",
19
19
  },
20
- userConfig: {
21
- columns: (_q = initialUserConfig === null || initialUserConfig === void 0 ? void 0 : initialUserConfig.columns) !== null && _q !== void 0 ? _q : {},
22
- perPage: (_r = initialUserConfig === null || initialUserConfig === void 0 ? void 0 : initialUserConfig.perPage) !== null && _r !== void 0 ? _r : schema.perPage,
23
- },
20
+ userConfig: initialUserConfig !== null && initialUserConfig !== void 0 ? initialUserConfig : {},
24
21
  tabRequests: {},
25
22
  };
26
23
  }
@@ -13,12 +13,8 @@ const loader = async (_, request) => {
13
13
  if (!s) {
14
14
  return 1;
15
15
  }
16
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
17
- // @ts-ignore
18
- const first = a[sort];
19
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
20
- // @ts-ignore
21
- const second = b[sort];
16
+ const first = a[s.name];
17
+ const second = b[s.name];
22
18
  if (typeof first === "number") {
23
19
  return s.dir === "asc" ? first - second : second - first;
24
20
  }
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.schema = void 0;
4
- const types_1 = require("../types");
5
4
  exports.schema = {
6
5
  columns: [
7
- { name: "id", type: "number", label: "Id", sort: true },
6
+ { name: "id", type: "number", label: "Id", sort: true, config: { width: 50 } },
8
7
  { name: "text", type: "string", label: "Text", sort: true },
9
8
  { name: "bool", type: "boolean", label: "Boolean" },
10
9
  { name: "mail", type: "email", label: "E-mail" },
@@ -58,17 +57,10 @@ exports.schema = {
58
57
  {
59
58
  name: "only-odd-ids",
60
59
  label: "Only odd ids blablabla",
61
- s: {
62
- name: "id",
63
- dir: types_1.DataGridSortDir.Desc,
64
- },
60
+ s: { name: "id", dir: "desc" },
65
61
  },
66
- // { name: "only-odd-ids", label: "Only odd ids" },
67
62
  ],
68
- s: {
69
- name: "id",
70
- dir: types_1.DataGridSortDir.Asc,
71
- },
63
+ s: { name: "id", dir: "asc" },
72
64
  perPage: 10,
73
65
  fullText: true,
74
66
  };
@@ -40,7 +40,7 @@ function Default() {
40
40
  schema: schema_1.schema,
41
41
  initialUserConfig: {
42
42
  columns: {
43
- id: { minWidth: 50 },
43
+ id: { width: 100 },
44
44
  text: { minWidth: 300 },
45
45
  mail: { minWidth: 300 },
46
46
  tel: { minWidth: 300 },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/data-grid",
3
- "version": "11.4.0",
3
+ "version": "11.6.0",
4
4
  "description": "UXF DataGrid",
5
5
  "homepage": "https://gitlab.com/uxf-npm/data-grid#readme",
6
6
  "main": "index.js",
@@ -31,7 +31,7 @@
31
31
  "typecheck": "tsc --noEmit --skipLibCheck"
32
32
  },
33
33
  "dependencies": {
34
- "@uxf/ui": "11.4.0",
34
+ "@uxf/ui": "11.6.0",
35
35
  "dayjs": "1.11.10",
36
36
  "fast-glob": "^3.3.2",
37
37
  "qs": "6.11.2",
@@ -29,16 +29,17 @@ const react_1 = __importStar(require("react"));
29
29
  const react_data_grid_1 = require("react-data-grid");
30
30
  function useReactDataGridColumns(props, state) {
31
31
  const { onReload, schema, isRowSelectable, bodyCells, actionCell } = props;
32
- const columnsConfig = state.userConfig.columns;
32
+ const userConfigColumns = state.userConfig.columns;
33
33
  return (0, react_1.useMemo)(() => {
34
- var _a, _b, _c, _d, _e, _f, _g;
34
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
35
35
  const columns = [];
36
36
  if (isRowSelectable) {
37
37
  columns.push(react_data_grid_1.SelectColumn);
38
38
  }
39
39
  for (const schemaColumn of schema.columns) {
40
+ const isHidden = (_b = (_a = userConfigColumns === null || userConfigColumns === void 0 ? void 0 : userConfigColumns[schemaColumn.name]) === null || _a === void 0 ? void 0 : _a.isHidden) !== null && _b !== void 0 ? _b : (_c = schemaColumn.config) === null || _c === void 0 ? void 0 : _c.isHidden;
40
41
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
41
- if ((_a = columnsConfig === null || columnsConfig === void 0 ? void 0 : columnsConfig[schemaColumn.name]) === null || _a === void 0 ? void 0 : _a.isHidden) {
42
+ if (isHidden) {
42
43
  continue;
43
44
  }
44
45
  columns.push({
@@ -47,9 +48,8 @@ function useReactDataGridColumns(props, state) {
47
48
  headerCellClass: (0, cx_1.cx)("uxf-data-grid__cell", "uxf-data-grid__cell--header", `uxf-data-grid__cell--type-${schemaColumn.type}`, `uxf-data-grid__cell--name-${schemaColumn.name}`),
48
49
  resizable: true,
49
50
  sortable: schemaColumn.sort,
50
- width: (_d = (_c = (_b = state.userConfig.columns) === null || _b === void 0 ? void 0 : _b[schemaColumn.name]) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : schemaColumn.width,
51
- minWidth: (_g = (_f = (_e = state.userConfig.columns) === null || _e === void 0 ? void 0 : _e[schemaColumn.name]) === null || _f === void 0 ? void 0 : _f.minWidth) !== null && _g !== void 0 ? _g : schemaColumn.minWidth,
52
- maxWidth: schemaColumn.maxWidth,
51
+ width: (_f = (_e = (_d = state.userConfig.columns) === null || _d === void 0 ? void 0 : _d[schemaColumn.name]) === null || _e === void 0 ? void 0 : _e.width) !== null && _f !== void 0 ? _f : (_g = schemaColumn.config) === null || _g === void 0 ? void 0 : _g.width,
52
+ minWidth: (_k = (_j = (_h = state.userConfig.columns) === null || _h === void 0 ? void 0 : _h[schemaColumn.name]) === null || _j === void 0 ? void 0 : _j.minWidth) !== null && _k !== void 0 ? _k : (_l = schemaColumn.config) === null || _l === void 0 ? void 0 : _l.minWidth,
53
53
  cellClass: (0, cx_1.cx)("uxf-data-grid__cell", `uxf-data-grid__cell--type-${schemaColumn.type}`, `uxf-data-grid__cell--name-${schemaColumn.name}`),
54
54
  renderCell: (p) => {
55
55
  var _a;
@@ -79,6 +79,6 @@ function useReactDataGridColumns(props, state) {
79
79
  });
80
80
  }
81
81
  return columns;
82
- }, [columnsConfig, actionCell, schema.columns, bodyCells, isRowSelectable, onReload, state.userConfig.columns]);
82
+ }, [userConfigColumns, actionCell, schema.columns, bodyCells, isRowSelectable, onReload, state.userConfig.columns]);
83
83
  }
84
84
  exports.useReactDataGridColumns = useReactDataGridColumns;
package/types/core.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Request, Response, ResultItem } from "./api";
2
2
  import { BaseGridType } from "./schema";
3
3
  export type KeyExtractor = (row: ResultItem) => number;
4
- export type ChangeHiddenColumnsHandler = (hiddenColumns: string[]) => void;
5
4
  export type CsvDownloadHandler = (request: Request) => void;
6
5
  export type Loader = (gridName: string | undefined, request: Request, encodedRequest: string) => Promise<Response>;
7
6
  export type CallbackRef = {
package/types/schema.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { ReactElement } from "react";
2
+ /** @deprecated use 'asc' or 'desc' */
2
3
  export declare enum DataGridSortDir {
3
4
  Asc = "asc",
4
5
  Desc = "desc"
5
6
  }
6
7
  export interface DataGridSort {
7
8
  name: string;
8
- dir: DataGridSortDir;
9
+ dir: "asc" | "desc";
9
10
  }
10
11
  export interface Tab {
11
12
  name: string;
@@ -22,12 +23,12 @@ export type Column<Name, Type> = {
22
23
  label: string | ReactElement;
23
24
  type: Type;
24
25
  sort?: boolean;
25
- hint?: string;
26
- print?: boolean;
27
- width?: number | string;
26
+ config?: ColumnConfig;
27
+ };
28
+ export type ColumnConfig = {
29
+ isHidden?: boolean;
30
+ width?: number;
28
31
  minWidth?: number;
29
- maxWidth?: number;
30
- frozen?: boolean;
31
32
  };
32
33
  export type Columns<C extends BaseGridType["columns"]> = {
33
34
  [K in keyof C]: Column<K, C[K]>;
@@ -46,6 +47,7 @@ export type Filters<F extends BaseGridType["filters"]> = {
46
47
  [K in keyof F]: Filter<K, F[K]>;
47
48
  }[keyof F];
48
49
  export interface Schema<GritType extends BaseGridType> {
50
+ name?: string;
49
51
  columns: Columns<GritType["columns"]>[];
50
52
  filters: Filters<GritType["filters"]>[];
51
53
  tabs?: Tab[];
package/types/schema.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataGridSortDir = void 0;
4
+ /** @deprecated use 'asc' or 'desc' */
4
5
  var DataGridSortDir;
5
6
  (function (DataGridSortDir) {
6
7
  DataGridSortDir["Asc"] = "asc";