@uxf/data-grid 11.0.0-beta.6 → 11.0.0-beta.7
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.d.ts +2 -2
- package/_store/reducer.js +31 -18
- package/hidden-columns/hidden-columns.js +2 -4
- package/package.json +1 -1
- package/selected-rows-toolbar/selected-rows-toolbar.stories.js +4 -1
- package/styles.css +2 -0
- package/table/hooks/use-react-data-grid-columns.d.ts +2 -1
- package/table/hooks/use-react-data-grid-columns.js +8 -1
- package/table/table.js +1 -1
- package/types/state.d.ts +5 -1
- package/use-data-grid-control/use-data-grid-control.d.ts +3 -1
- package/use-data-grid-control/use-data-grid-control.js +1 -1
package/_store/reducer.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Nullish } from "@uxf/core/types";
|
|
|
2
2
|
import { Reducer } from "react";
|
|
3
3
|
import { Request } from "../types/api";
|
|
4
4
|
import { Schema } from "../types/schema";
|
|
5
|
-
import { DataGridState } from "../types/state";
|
|
6
|
-
export declare const getInitialState: (schema: Schema<any>, init?: Request | string | Nullish) => DataGridState;
|
|
5
|
+
import { DataGridState, DataGridUserConfig } from "../types/state";
|
|
6
|
+
export declare const getInitialState: (schema: Schema<any>, init?: Request | string | Nullish, initialUserConfig?: DataGridUserConfig | Nullish) => DataGridState;
|
|
7
7
|
export declare const reducer: Reducer<DataGridState, any>;
|
|
8
8
|
export declare const debugReducer: Reducer<DataGridState, any>;
|
package/_store/reducer.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
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
|
-
const getInitialState = (schema, init) => {
|
|
7
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
6
|
+
const getInitialState = (schema, init, initialUserConfig) => {
|
|
7
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
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
9
|
return {
|
|
10
10
|
request: {
|
|
@@ -12,18 +12,21 @@ const getInitialState = (schema, init) => {
|
|
|
12
12
|
page: (_c = initialState.page) !== null && _c !== void 0 ? _c : 0,
|
|
13
13
|
dir: (_d = initialState.dir) !== null && _d !== void 0 ? _d : schema.dir,
|
|
14
14
|
sort: (_e = initialState.sort) !== null && _e !== void 0 ? _e : schema.sort,
|
|
15
|
-
perPage: (_f = initialState.perPage) !== null && _f !== void 0 ? _f : schema.perPage,
|
|
16
|
-
tab: (
|
|
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: (_k = (_j = (_h = schema.tabs) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.name) !== null && _k !== void 0 ? _k : null,
|
|
17
17
|
search: "",
|
|
18
18
|
},
|
|
19
|
-
|
|
19
|
+
userConfig: {
|
|
20
|
+
columns: (_l = initialUserConfig === null || initialUserConfig === void 0 ? void 0 : initialUserConfig.columns) !== null && _l !== void 0 ? _l : {},
|
|
21
|
+
perPage: (_m = initialUserConfig === null || initialUserConfig === void 0 ? void 0 : initialUserConfig.perPage) !== null && _m !== void 0 ? _m : schema.perPage,
|
|
22
|
+
},
|
|
20
23
|
tabRequests: {},
|
|
21
24
|
};
|
|
22
25
|
};
|
|
23
26
|
exports.getInitialState = getInitialState;
|
|
24
27
|
// eslint-disable-next-line complexity
|
|
25
28
|
const reducer = (state, action) => {
|
|
26
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
29
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
27
30
|
switch (action.type) {
|
|
28
31
|
case "CHANGE_PAGE":
|
|
29
32
|
return {
|
|
@@ -40,6 +43,10 @@ const reducer = (state, action) => {
|
|
|
40
43
|
...state.request,
|
|
41
44
|
perPage: action.perPage,
|
|
42
45
|
},
|
|
46
|
+
userConfig: {
|
|
47
|
+
...state.userConfig,
|
|
48
|
+
perPage: action.perPage,
|
|
49
|
+
},
|
|
43
50
|
};
|
|
44
51
|
case "FILTER":
|
|
45
52
|
// eslint-disable-next-line no-case-declarations
|
|
@@ -121,24 +128,30 @@ const reducer = (state, action) => {
|
|
|
121
128
|
case "HIDE_COLUMN":
|
|
122
129
|
return {
|
|
123
130
|
...state,
|
|
124
|
-
|
|
125
|
-
...state.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
userConfig: {
|
|
132
|
+
...state.userConfig,
|
|
133
|
+
columns: {
|
|
134
|
+
...state.userConfig.columns,
|
|
135
|
+
[action.name]: {
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
137
|
+
...((_k = (_j = state.userConfig.columns) === null || _j === void 0 ? void 0 : _j[action.name]) !== null && _k !== void 0 ? _k : {}),
|
|
138
|
+
isHidden: true,
|
|
139
|
+
},
|
|
130
140
|
},
|
|
131
141
|
},
|
|
132
142
|
};
|
|
133
143
|
case "SHOW_COLUMN":
|
|
134
144
|
return {
|
|
135
145
|
...state,
|
|
136
|
-
|
|
137
|
-
...state.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
146
|
+
userConfig: {
|
|
147
|
+
...state.userConfig,
|
|
148
|
+
columns: {
|
|
149
|
+
...state.userConfig.columns,
|
|
150
|
+
[action.name]: {
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
152
|
+
...((_m = (_l = state.userConfig.columns) === null || _l === void 0 ? void 0 : _l[action.name]) !== null && _m !== void 0 ? _m : {}),
|
|
153
|
+
isHidden: false,
|
|
154
|
+
},
|
|
142
155
|
},
|
|
143
156
|
},
|
|
144
157
|
};
|
|
@@ -8,10 +8,8 @@ const toggle_1 = require("@uxf/ui/toggle");
|
|
|
8
8
|
const react_1 = __importDefault(require("react"));
|
|
9
9
|
function HiddenColumns(props) {
|
|
10
10
|
return (react_1.default.createElement("div", { className: "uxf-data-grid__toolbar-control-columns" }, props.schema.columns.map((column) => {
|
|
11
|
-
var _a;
|
|
12
|
-
return (react_1.default.createElement(toggle_1.Toggle, { key: column.name, label: typeof column.label === "string" ? column.label : "",
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
14
|
-
value: !((_a = props.state.columnConfig[column.name]) === null || _a === void 0 ? void 0 : _a.isHidden), onChange: (value) => value ? props.actions.showColumn(column.name) : props.actions.hideColumn(column.name) }));
|
|
11
|
+
var _a, _b;
|
|
12
|
+
return (react_1.default.createElement(toggle_1.Toggle, { key: column.name, label: typeof column.label === "string" ? column.label : "", value: !((_b = (_a = props.state.userConfig.columns) === null || _a === void 0 ? void 0 : _a[column.name]) === null || _b === void 0 ? void 0 : _b.isHidden), onChange: (value) => value ? props.actions.showColumn(column.name) : props.actions.hideColumn(column.name) }));
|
|
15
13
|
})));
|
|
16
14
|
}
|
|
17
15
|
exports.HiddenColumns = HiddenColumns;
|
package/package.json
CHANGED
|
@@ -25,6 +25,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.Default = void 0;
|
|
27
27
|
const json_renderer_1 = require("@uxf/example/src/components/json-renderer");
|
|
28
|
+
const button_1 = require("@uxf/ui/button");
|
|
29
|
+
const icon_1 = require("@uxf/ui/icon");
|
|
28
30
|
const react_1 = __importStar(require("react"));
|
|
29
31
|
const schema_1 = require("../_story-utils/schema");
|
|
30
32
|
const use_data_grid_control_1 = require("../use-data-grid-control");
|
|
@@ -35,7 +37,8 @@ function Default() {
|
|
|
35
37
|
actions.setSelectedRows([{ id: 1 }, { id: 2 }]);
|
|
36
38
|
}, [actions]);
|
|
37
39
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
38
|
-
react_1.default.createElement(selected_rows_toolbar_1.SelectedRowsToolbar, { state: state, actions: actions
|
|
40
|
+
react_1.default.createElement(selected_rows_toolbar_1.SelectedRowsToolbar, { state: state, actions: actions, Actions: () => (react_1.default.createElement(button_1.Button, { isIconButton: true },
|
|
41
|
+
react_1.default.createElement(icon_1.Icon, { name: "camera" }))) }),
|
|
39
42
|
react_1.default.createElement(json_renderer_1.JsonRenderer, { value: state })));
|
|
40
43
|
}
|
|
41
44
|
exports.Default = Default;
|
package/styles.css
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Column } from "react-data-grid";
|
|
2
|
+
import { DataGridState } from "../../types";
|
|
2
3
|
import { TableProps } from "../types";
|
|
3
|
-
export declare function useReactDataGridColumns(props: TableProps<any
|
|
4
|
+
export declare function useReactDataGridColumns(props: TableProps<any>, state: DataGridState): Column<any>[];
|
|
@@ -29,16 +29,22 @@ const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
|
29
29
|
const react_1 = __importStar(require("react"));
|
|
30
30
|
const react_data_grid_1 = require("react-data-grid");
|
|
31
31
|
const action_cell_base_1 = require("../components/action-cell-base");
|
|
32
|
-
function useReactDataGridColumns(props) {
|
|
32
|
+
function useReactDataGridColumns(props, state) {
|
|
33
33
|
var _a;
|
|
34
34
|
const { onReload, actionCellWidth, schema, isRowSelectable, BodyCells, getOpenUrl, onOpen, getEditUrl, onEdit, onRemove, } = props;
|
|
35
35
|
const ActionCell = (_a = props.ActionCell) !== null && _a !== void 0 ? _a : action_cell_base_1.ActionCellBase;
|
|
36
|
+
const columnsConfig = state.userConfig.columns;
|
|
36
37
|
return (0, react_1.useMemo)(() => {
|
|
38
|
+
var _a;
|
|
37
39
|
const columns = [];
|
|
38
40
|
if (isRowSelectable) {
|
|
39
41
|
columns.push(react_data_grid_1.SelectColumn);
|
|
40
42
|
}
|
|
41
43
|
for (const schemaColumn of schema.columns) {
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
45
|
+
if ((_a = columnsConfig === null || columnsConfig === void 0 ? void 0 : columnsConfig[schemaColumn.name]) === null || _a === void 0 ? void 0 : _a.isHidden) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
42
48
|
columns.push({
|
|
43
49
|
key: schemaColumn.name,
|
|
44
50
|
name: schemaColumn.label,
|
|
@@ -76,6 +82,7 @@ function useReactDataGridColumns(props) {
|
|
|
76
82
|
});
|
|
77
83
|
return columns;
|
|
78
84
|
}, [
|
|
85
|
+
columnsConfig,
|
|
79
86
|
ActionCell,
|
|
80
87
|
actionCellWidth,
|
|
81
88
|
schema.columns,
|
package/table/table.js
CHANGED
|
@@ -56,7 +56,7 @@ function Table(props) {
|
|
|
56
56
|
renderCheckbox: (args) => react_1.default.createElement(select_row_checkbox_1.SelectRowCheckbox, { ...args }),
|
|
57
57
|
noRowsFallback: react_1.default.createElement(NoRowsFallback, { error: error, loading: isLoading }),
|
|
58
58
|
}), [NoRowsFallback, error, isLoading]);
|
|
59
|
-
const columns = (0, use_react_data_grid_columns_1.useReactDataGridColumns)(props);
|
|
59
|
+
const columns = (0, use_react_data_grid_columns_1.useReactDataGridColumns)(props, props.state);
|
|
60
60
|
const onSelectRows = (value) => {
|
|
61
61
|
const selectedRows = Array.from(value).map((id) => props.data.find((row) => keyExtractor(row) === id));
|
|
62
62
|
props.actions.setSelectedRows(selectedRows);
|
package/types/state.d.ts
CHANGED
|
@@ -13,11 +13,15 @@ interface ColumnConfig {
|
|
|
13
13
|
isHidden: boolean;
|
|
14
14
|
width?: number;
|
|
15
15
|
}
|
|
16
|
+
export interface DataGridUserConfig {
|
|
17
|
+
columns?: Record<string, ColumnConfig>;
|
|
18
|
+
perPage?: number;
|
|
19
|
+
}
|
|
16
20
|
export interface DataGridState {
|
|
17
21
|
response?: Response;
|
|
18
22
|
request: GridRequest;
|
|
19
23
|
selectedRows?: any[];
|
|
20
|
-
|
|
24
|
+
userConfig: DataGridUserConfig;
|
|
21
25
|
tabRequests: {
|
|
22
26
|
[tab: string]: GridRequest;
|
|
23
27
|
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Nullish } from "@uxf/core/types";
|
|
2
2
|
import { Request } from "../types/api";
|
|
3
3
|
import { Schema } from "../types/schema";
|
|
4
|
+
import { DataGridUserConfig } from "../types/state";
|
|
4
5
|
interface Config {
|
|
5
6
|
schema: Schema<any>;
|
|
6
7
|
initialState?: Request | string | Nullish;
|
|
7
8
|
isDebug?: boolean;
|
|
9
|
+
initialUserConfig?: DataGridUserConfig | Nullish;
|
|
8
10
|
}
|
|
9
11
|
export declare function useDataGridControl(config: Config): {
|
|
10
|
-
state: import("
|
|
12
|
+
state: import("../types/state").DataGridState;
|
|
11
13
|
actions: {
|
|
12
14
|
changePage: (page: number) => void;
|
|
13
15
|
changePerPage: (perPage: number) => void;
|
|
@@ -5,7 +5,7 @@ const react_1 = require("react");
|
|
|
5
5
|
const reducer_1 = require("../_store/reducer");
|
|
6
6
|
const actions_factory_1 = require("./actions-factory");
|
|
7
7
|
function useDataGridControl(config) {
|
|
8
|
-
const [state, dispatch] = (0, react_1.useReducer)(config.isDebug ? reducer_1.debugReducer : reducer_1.reducer, (0, reducer_1.getInitialState)(config.schema, config.initialState));
|
|
8
|
+
const [state, dispatch] = (0, react_1.useReducer)(config.isDebug ? reducer_1.debugReducer : reducer_1.reducer, (0, reducer_1.getInitialState)(config.schema, config.initialState, config.initialUserConfig));
|
|
9
9
|
const actions = (0, react_1.useMemo)(() => (0, actions_factory_1.createActions)(dispatch), [dispatch]);
|
|
10
10
|
return { state, actions };
|
|
11
11
|
}
|