@uxf/data-grid 11.2.6 → 11.3.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.
@@ -1,4 +1,4 @@
1
- import { DataGridSortDir, RequestFilter, Response } from "../types";
1
+ import { DataGridSortDir, RequestFilter, Response, Tab } from "../types";
2
2
  export declare const dataGridActions: {
3
3
  filter: (filterValue: RequestFilter) => {
4
4
  type: string;
@@ -15,9 +15,9 @@ export declare const dataGridActions: {
15
15
  type: string;
16
16
  perPage: number;
17
17
  };
18
- changeTab: (tabName: string) => {
18
+ changeTab: (tab: Tab) => {
19
19
  type: string;
20
- name: string;
20
+ tab: Tab;
21
21
  };
22
22
  reload: () => {
23
23
  type: string;
package/_store/actions.js CHANGED
@@ -17,9 +17,9 @@ exports.dataGridActions = {
17
17
  type: "CHANGE_PER_PAGE",
18
18
  perPage,
19
19
  }),
20
- changeTab: (tabName) => ({
20
+ changeTab: (tab) => ({
21
21
  type: "CHANGE_TAB",
22
- name: tabName,
22
+ tab,
23
23
  }),
24
24
  reload: () => ({
25
25
  type: "RELOAD",
package/_store/reducer.js CHANGED
@@ -4,21 +4,22 @@ 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
  const getInitialState = (schema, init, initialUserConfig) => {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
7
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
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
11
  return {
10
12
  request: {
11
- f: (_b = initialState.f) !== null && _b !== void 0 ? _b : [],
12
- page: (_c = initialState.page) !== null && _c !== void 0 ? _c : 0,
13
- dir: (_d = initialState.dir) !== null && _d !== void 0 ? _d : schema.dir,
14
- sort: (_e = initialState.sort) !== null && _e !== void 0 ? _e : schema.sort,
15
- perPage: (_g = (_f = initialState.perPage) !== null && _f !== void 0 ? _f : initialUserConfig === null || initialUserConfig === void 0 ? void 0 : initialUserConfig.perPage) !== null && _g !== void 0 ? _g : schema.perPage,
16
- tab: (_l = (_h = initialState.tab) !== null && _h !== void 0 ? _h : (_k = (_j = schema.tabs) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.name) !== null && _l !== void 0 ? _l : null,
17
- search: (_m = initialState.search) !== null && _m !== void 0 ? _m : "",
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,
15
+ page: (_l = initialState.page) !== null && _l !== void 0 ? _l : 0,
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,
18
+ search: (_p = initialState.search) !== null && _p !== void 0 ? _p : "",
18
19
  },
19
20
  userConfig: {
20
- columns: (_o = initialUserConfig === null || initialUserConfig === void 0 ? void 0 : initialUserConfig.columns) !== null && _o !== void 0 ? _o : {},
21
- perPage: (_p = initialUserConfig === null || initialUserConfig === void 0 ? void 0 : initialUserConfig.perPage) !== null && _p !== void 0 ? _p : schema.perPage,
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,
22
23
  },
23
24
  tabRequests: {},
24
25
  };
@@ -75,8 +76,10 @@ const reducer = (state, action) => {
75
76
  ...state,
76
77
  request: {
77
78
  ...state.request,
78
- sort: action.columnName,
79
- dir: action.direction,
79
+ s: {
80
+ name: action.columnName,
81
+ dir: action.direction,
82
+ },
80
83
  },
81
84
  };
82
85
  case "SORT_CLEAR":
@@ -84,8 +87,7 @@ const reducer = (state, action) => {
84
87
  ...state,
85
88
  request: {
86
89
  ...state.request,
87
- sort: null,
88
- dir: null,
90
+ s: null,
89
91
  },
90
92
  };
91
93
  case "FULLTEXT":
@@ -99,21 +101,20 @@ const reducer = (state, action) => {
99
101
  };
100
102
  case "CHANGE_TAB":
101
103
  // eslint-disable-next-line no-case-declarations,@typescript-eslint/no-unnecessary-condition
102
- const tabHistory = (_a = state.tabRequests[action.name]) !== null && _a !== void 0 ? _a : {};
104
+ const tabHistory = (_a = state.tabRequests[action.tab.name]) !== null && _a !== void 0 ? _a : {};
103
105
  return {
104
106
  ...state,
105
107
  request: {
106
108
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
107
109
  f: (_b = tabHistory.f) !== null && _b !== void 0 ? _b : [],
110
+ s: (_d = (_c = tabHistory.s) !== null && _c !== void 0 ? _c : action.tab.s) !== null && _d !== void 0 ? _d : state.request.s,
108
111
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
109
- search: (_c = tabHistory.search) !== null && _c !== void 0 ? _c : "",
112
+ search: (_e = tabHistory.search) !== null && _e !== void 0 ? _e : "",
110
113
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
111
- page: (_d = tabHistory.page) !== null && _d !== void 0 ? _d : 0,
114
+ page: (_f = tabHistory.page) !== null && _f !== void 0 ? _f : 0,
112
115
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
113
- perPage: (_e = tabHistory.perPage) !== null && _e !== void 0 ? _e : state.request.perPage,
114
- dir: (_f = tabHistory.dir) !== null && _f !== void 0 ? _f : state.request.dir,
115
- sort: (_g = tabHistory.sort) !== null && _g !== void 0 ? _g : state.request.sort,
116
- tab: action.name,
116
+ perPage: (_g = tabHistory.perPage) !== null && _g !== void 0 ? _g : state.request.perPage,
117
+ tab: action.tab.name,
117
118
  },
118
119
  tabRequests: {
119
120
  ...state.tabRequests,
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loader = void 0;
4
4
  const data_1 = require("./data");
5
5
  const loader = async (_, request) => {
6
- const { page = 1, perPage = 10, tab, sort, dir, f } = request;
6
+ const { page = 1, perPage = 10, tab, s, f } = request;
7
7
  // eslint-disable-next-line no-console
8
8
  console.log("filter", f === null || f === void 0 ? void 0 : f.length);
9
9
  const filteredData = data_1.data
10
10
  .filter((item) => tab !== "only-odd-ids" || item.id % 2 === 0)
11
11
  .filter((item) => { var _a; return (request.search ? (_a = item.text) === null || _a === void 0 ? void 0 : _a.match(new RegExp(request.search, "i")) : true); })
12
12
  .sort((a, b) => {
13
- if (!sort || !dir) {
13
+ if (!s) {
14
14
  return 1;
15
15
  }
16
16
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -20,9 +20,9 @@ const loader = async (_, request) => {
20
20
  // @ts-ignore
21
21
  const second = b[sort];
22
22
  if (typeof first === "number") {
23
- return dir === "asc" ? first - second : second - first;
23
+ return s.dir === "asc" ? first - second : second - first;
24
24
  }
25
- return dir === "asc" ? first.localeCompare(second) : second.localeCompare(first);
25
+ return s.dir === "asc" ? first.localeCompare(second) : second.localeCompare(first);
26
26
  });
27
27
  // eslint-disable-next-line no-console
28
28
  console.log("loader", request);
@@ -55,11 +55,20 @@ exports.schema = {
55
55
  ],
56
56
  tabs: [
57
57
  { name: "all", label: "All" },
58
- { name: "only-odd-ids", label: "Only odd ids blablabla" },
58
+ {
59
+ name: "only-odd-ids",
60
+ label: "Only odd ids blablabla",
61
+ s: {
62
+ name: "id",
63
+ dir: types_1.DataGridSortDir.Desc,
64
+ },
65
+ },
59
66
  // { name: "only-odd-ids", label: "Only odd ids" },
60
67
  ],
61
- dir: types_1.DataGridSortDir.Asc,
62
- sort: "id",
68
+ s: {
69
+ name: "id",
70
+ dir: types_1.DataGridSortDir.Asc,
71
+ },
63
72
  perPage: 10,
64
73
  fullText: true,
65
74
  };
@@ -9,7 +9,7 @@ const icon_1 = require("@uxf/ui/icon");
9
9
  const react_1 = __importDefault(require("react"));
10
10
  const utils_1 = require("../utils");
11
11
  function ExportButton(props) {
12
- return (react_1.default.createElement(button_1.Button, { isIconButton: true, variant: "white", onClick: () => props.onCsvDownload((0, utils_1.createRequest)(props.state.request, props.schema.sort, props.schema.dir)), title: "St\u00E1hnout CSV", className: "uxf-data-grid__plugin-button" },
12
+ return (react_1.default.createElement(button_1.Button, { isIconButton: true, variant: "white", onClick: () => props.onCsvDownload((0, utils_1.createRequest)(props.state.request)), title: "St\u00E1hnout CSV", className: "uxf-data-grid__plugin-button" },
13
13
  react_1.default.createElement(icon_1.Icon, { name: "file-arrow-down" })));
14
14
  }
15
15
  exports.ExportButton = ExportButton;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/data-grid",
3
- "version": "11.2.6",
3
+ "version": "11.3.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.1.0",
34
+ "@uxf/ui": "11.3.0",
35
35
  "dayjs": "1.11.10",
36
36
  "fast-glob": "^3.3.2",
37
37
  "qs": "6.11.2",
package/table/table.js CHANGED
@@ -74,8 +74,8 @@ function Table(props) {
74
74
  props.actions.sortClear();
75
75
  }
76
76
  };
77
- const sortColumns = props.state.request.sort && props.state.request.dir
78
- ? [{ columnKey: props.state.request.sort, direction: props.state.request.dir.toUpperCase() }]
77
+ const sortColumns = props.state.request.s
78
+ ? [{ columnKey: props.state.request.s.name, direction: props.state.request.s.dir.toUpperCase() }]
79
79
  : [];
80
80
  const rdgVisuals = (0, use_rdg_visuals_1.useRdgVisuals)({
81
81
  headerRowHeight: props.headerRowHeight,
@@ -17,13 +17,13 @@ function ToolbarTabs(props) {
17
17
  var _a, _b, _c, _d;
18
18
  return (react_1.default.createElement(show_1.Show, { when: !!((_a = props.schema.tabs) === null || _a === void 0 ? void 0 : _a.length) },
19
19
  react_1.default.createElement("div", { className: "uxf-data-grid__toolbar-tabs" },
20
- react_1.default.createElement("nav", { className: "uxf-data-grid__toolbar-tabs-nav uxf-data-grid__toolbar-tabs-nav--desktop", "aria-label": "Tabs" }, (_b = props.schema.tabs) === null || _b === void 0 ? void 0 : _b.map((t) => (react_1.default.createElement(Tab, { key: t.name, title: t.label, isActive: props.state.request.tab === t.name, onClick: () => props.actions.changeTab(t.name) })))),
20
+ react_1.default.createElement("nav", { className: "uxf-data-grid__toolbar-tabs-nav uxf-data-grid__toolbar-tabs-nav--desktop", "aria-label": "Tabs" }, (_b = props.schema.tabs) === null || _b === void 0 ? void 0 : _b.map((t) => (react_1.default.createElement(Tab, { key: t.name, title: t.label, isActive: props.state.request.tab === t.name, onClick: () => props.actions.changeTab(t) })))),
21
21
  react_1.default.createElement("nav", { className: "uxf-data-grid__toolbar-tabs-nav uxf-data-grid__toolbar-tabs-nav--mobile" },
22
22
  react_1.default.createElement(button_1.Button, { variant: "text", className: "uxf-data-grid__toolbar-tabs-button", size: "sm", onClick: () => {
23
23
  var _a;
24
24
  return (0, modal_service_1.openModal)({
25
25
  children: (react_1.default.createElement("div", { className: "uxf-data-grid__toolbar-tabs-modal-content" }, (_a = props.schema.tabs) === null || _a === void 0 ? void 0 : _a.map((item) => (react_1.default.createElement(button_1.Button, { className: "uxf-data-grid__toolbar-tabs-modal-button", key: item.name, variant: "text", size: "xl", onClick: () => {
26
- props.actions.changeTab(item.name);
26
+ props.actions.changeTab(item);
27
27
  (0, modal_service_1.closeModal)();
28
28
  } },
29
29
  item.name === props.state.request.tab && (react_1.default.createElement(icon_1.Icon, { className: "uxf-data-grid__toolbar-tabs-modal-active-tab-icon", name: "check", size: 20 })),
package/types/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DataGridSortDir } from "./schema";
1
+ import { DataGridSort } from "./schema";
2
2
  export type ResultItem = any;
3
3
  export interface RequestFilter<T = any> {
4
4
  name: string;
@@ -8,8 +8,7 @@ export interface RequestFilter<T = any> {
8
8
  }
9
9
  export interface Request {
10
10
  f?: RequestFilter[];
11
- sort?: string;
12
- dir?: DataGridSortDir;
11
+ s?: DataGridSort;
13
12
  page?: number;
14
13
  perPage?: number;
15
14
  search?: string;
package/types/schema.d.ts CHANGED
@@ -3,10 +3,15 @@ export declare enum DataGridSortDir {
3
3
  Asc = "asc",
4
4
  Desc = "desc"
5
5
  }
6
+ export interface DataGridSort {
7
+ name: string;
8
+ dir: DataGridSortDir;
9
+ }
6
10
  export interface Tab {
7
11
  name: string;
8
12
  label: string;
9
13
  icon?: string;
14
+ s?: DataGridSort;
10
15
  }
11
16
  export type BaseGridType = {
12
17
  columns: any;
@@ -44,8 +49,7 @@ export interface Schema<GritType extends BaseGridType> {
44
49
  columns: Columns<GritType["columns"]>[];
45
50
  filters: Filters<GritType["filters"]>[];
46
51
  tabs?: Tab[];
47
- sort: string;
48
- dir: DataGridSortDir;
52
+ s: DataGridSort;
49
53
  perPage: number;
50
54
  fullText?: boolean;
51
55
  }
package/types/state.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { RequestFilter } from "./api";
2
- import { DataGridSortDir } from "./schema";
2
+ import { DataGridSort } from "./schema";
3
3
  export type GridRequest = {
4
4
  f: RequestFilter[];
5
- sort: string | null;
6
- dir: DataGridSortDir | null;
5
+ s: DataGridSort | null;
7
6
  page: number;
8
7
  perPage: number;
9
8
  search: string;
@@ -1,5 +1,6 @@
1
1
  import { Dispatch } from "react";
2
2
  import { RequestFilter } from "../types/api";
3
+ import { Tab } from "../types/schema";
3
4
  export declare function createActions(dispatch: Dispatch<any>): {
4
5
  changePage: (page: number) => void;
5
6
  changePerPage: (perPage: number) => void;
@@ -7,7 +8,7 @@ export declare function createActions(dispatch: Dispatch<any>): {
7
8
  sort: (columnName: string, direction: string) => void;
8
9
  sortClear: () => void;
9
10
  search: (search: string) => void;
10
- changeTab: (tabName: string) => void;
11
+ changeTab: (tab: Tab) => void;
11
12
  setSelectedRows: (rows: any[]) => void;
12
13
  hideColumn: (name: string) => void;
13
14
  showColumn: (name: string) => void;
@@ -9,7 +9,7 @@ function createActions(dispatch) {
9
9
  sort: (columnName, direction) => dispatch({ type: "SORT", columnName, direction }),
10
10
  sortClear: () => dispatch({ type: "SORT_CLEAR" }),
11
11
  search: (search) => dispatch({ type: "FULLTEXT", search }),
12
- changeTab: (tabName) => dispatch({ type: "CHANGE_TAB", name: tabName }),
12
+ changeTab: (tab) => dispatch({ type: "CHANGE_TAB", tab }),
13
13
  setSelectedRows: (rows) => dispatch({ type: "SET_SELECTED_ROWS", rows }),
14
14
  hideColumn: (name) => dispatch({ type: "HIDE_COLUMN", name }),
15
15
  showColumn: (name) => dispatch({ type: "SHOW_COLUMN", name }),
@@ -17,7 +17,7 @@ export declare function useDataGridControl(config: UseDataGridControlConfig): {
17
17
  sort: (columnName: string, direction: string) => void;
18
18
  sortClear: () => void;
19
19
  search: (search: string) => void;
20
- changeTab: (tabName: string) => void;
20
+ changeTab: (tab: import("../types/schema").Tab) => void;
21
21
  setSelectedRows: (rows: any[]) => void;
22
22
  hideColumn: (name: string) => void;
23
23
  showColumn: (name: string) => void;
@@ -5,14 +5,14 @@ const react_1 = require("react");
5
5
  const utils_1 = require("../utils");
6
6
  const loader_1 = require("./loader");
7
7
  function useDataGridFetching(config) {
8
- const { state, schema, loader = loader_1.dataGridLoader, gridName } = config;
8
+ const { state, loader = loader_1.dataGridLoader, gridName } = config;
9
9
  const [isLoading, setIsLoading] = (0, react_1.useState)(false);
10
10
  const [error, setError] = (0, react_1.useState)(null);
11
11
  const [data, setData] = (0, react_1.useState)(null);
12
12
  const stringStateRequest = JSON.stringify(state.request);
13
13
  const reload = (0, react_1.useCallback)(() => {
14
14
  const stateRequest = JSON.parse(stringStateRequest);
15
- const request = (0, utils_1.createRequest)(stateRequest, schema.sort, schema.dir);
15
+ const request = (0, utils_1.createRequest)(stateRequest);
16
16
  setIsLoading(true);
17
17
  loader(gridName, request, (0, utils_1.encodeFilter)(request))
18
18
  .then((response) => {
@@ -27,7 +27,7 @@ function useDataGridFetching(config) {
27
27
  setError(e);
28
28
  });
29
29
  // eslint-disable-next-line react-hooks/exhaustive-deps
30
- }, [stringStateRequest, schema.sort, schema.dir, gridName]);
30
+ }, [stringStateRequest, gridName]);
31
31
  (0, react_1.useEffect)(() => {
32
32
  reload();
33
33
  }, [reload]);
package/utils.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Request } from "./types/api";
2
- import { DataGridSortDir } from "./types/schema";
3
2
  import { GridRequest } from "./types/state";
4
3
  export declare function decodeFilter(filterString: string): null | Request;
5
4
  export declare function encodeFilter(request: Request): string;
6
- export declare function createRequest(request: GridRequest, defaultSort: string, defaultDir: DataGridSortDir): Request;
5
+ export declare function createRequest(request: GridRequest): Request;
package/utils.js CHANGED
@@ -9,8 +9,7 @@ function decodeFilter(filterString) {
9
9
  f: filter.f || [],
10
10
  perPage: filter.perPage || 10,
11
11
  page: filter.page || 0,
12
- dir: filter.dir || "asc",
13
- sort: filter.sort || "id",
12
+ s: filter.s,
14
13
  tab: (_a = filter.tab) !== null && _a !== void 0 ? _a : null,
15
14
  search: (_b = filter.search) !== null && _b !== void 0 ? _b : "",
16
15
  };
@@ -24,14 +23,12 @@ function encodeFilter(request) {
24
23
  return btoa(unescape(encodeURIComponent(JSON.stringify(request))));
25
24
  }
26
25
  exports.encodeFilter = encodeFilter;
27
- function createRequest(request, defaultSort, defaultDir) {
28
- var _a, _b;
26
+ function createRequest(request) {
29
27
  return {
30
- sort: (_a = request.sort) !== null && _a !== void 0 ? _a : defaultSort,
31
- dir: (_b = request.dir) !== null && _b !== void 0 ? _b : defaultDir,
32
28
  perPage: request.perPage,
33
29
  page: request.page,
34
30
  f: request.f.filter((f) => f.value !== undefined && f.value !== null && f.value !== ""),
31
+ s: request.s || undefined,
35
32
  search: request.search,
36
33
  tab: request.tab,
37
34
  };