@uxf/data-grid 11.0.0-beta.8 → 11.0.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/_generator/cli.js +29 -0
- package/_generator/index.js +40 -0
- package/_store/reducer.js +5 -5
- package/_story-utils/grid-type.d.ts +2 -0
- package/_story-utils/loader.js +1 -1
- package/_story-utils/schema.js +12 -0
- package/bin/uxf-data-grid-generator.js +8 -0
- package/data-grid.js +7 -8
- package/data-grid.stories.js +25 -1
- package/filter-handler/date.d.ts +3 -0
- package/filter-handler/date.js +43 -0
- package/filter-handler/index.js +4 -0
- package/filter-handler/multi-select.d.ts +3 -0
- package/filter-handler/multi-select.js +29 -0
- package/package.json +8 -3
- package/pagination/pagination.d.ts +1 -1
- package/pagination/pagination.js +2 -2
- package/pagination/pagination.stories.js +1 -1
- package/row-counts/row-counts.d.ts +1 -0
- package/row-counts/row-counts.js +7 -1
- package/row-counts/row-counts.stories.js +1 -1
- package/selected-rows-toolbar/selected-rows-toolbar.js +1 -1
- package/styles.css +9 -0
- package/table/components/action-cell-wrapper.d.ts +2 -0
- package/table/components/{action-cell-base.js → action-cell-wrapper.js} +3 -29
- package/table/components/action-cell.d.ts +7 -0
- package/table/components/action-cell.js +14 -0
- package/{hooks → table/hooks}/use-rdg-visuals.d.ts +2 -2
- package/{hooks → table/hooks}/use-rdg-visuals.js +2 -2
- package/table/hooks/use-react-data-grid-columns.js +14 -29
- package/table/index.d.ts +2 -0
- package/table/index.js +2 -0
- package/table/table.d.ts +1 -1
- package/table/table.js +14 -6
- package/table/table.stories.js +1 -1
- package/table/types.d.ts +10 -12
- package/toolbar-control/toolbar-control.js +2 -2
- package/types/components.d.ts +0 -5
- package/types/data-grid-props.d.ts +13 -12
- package/types/index.d.ts +0 -1
- package/types/index.js +0 -1
- package/use-data-grid-fetching/use-data-grid-fetching.js +1 -0
- package/table/components/action-cell-base.d.ts +0 -4
- package/types/ui-components.d.ts +0 -18
- package/types/ui-components.js +0 -2
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const { argv, env } = require("process");
|
|
2
|
+
|
|
3
|
+
module.exports = async () => {
|
|
4
|
+
const cli = require("yargs")
|
|
5
|
+
.command("$0", "UXF DataGrid generator", (yargs) => {
|
|
6
|
+
yargs.demandCommand(0, 0).usage(`
|
|
7
|
+
Usage:
|
|
8
|
+
uxf-data-grid-generator [options]
|
|
9
|
+
`);
|
|
10
|
+
})
|
|
11
|
+
.option("s", { alias: "schemaDirectory" })
|
|
12
|
+
.option("o", { alias: "outputDirectory" })
|
|
13
|
+
.option("h", { alias: "help", group: "Options" })
|
|
14
|
+
.strict(false)
|
|
15
|
+
.exitProcess(false);
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const { help, schemaDirectory, outputDirectory } = cli.parse(argv.slice(2));
|
|
19
|
+
|
|
20
|
+
if (Boolean(help)) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
await require("./index")(schemaDirectory, outputDirectory);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.error(e);
|
|
27
|
+
return 1;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const { globSync } = require("fast-glob");
|
|
2
|
+
const { readFileSync, writeFileSync, mkdirSync } = require("fs");
|
|
3
|
+
const { dirname, relative, parse, join } = require("path");
|
|
4
|
+
|
|
5
|
+
function camelize(value) {
|
|
6
|
+
return value
|
|
7
|
+
.split("-")
|
|
8
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
9
|
+
.join("");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function writeFile(filename, value) {
|
|
13
|
+
mkdirSync(dirname(filename), { recursive: true });
|
|
14
|
+
writeFileSync(filename, value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function generateSchemaFile(gridName, schemaRelativeImport) {
|
|
18
|
+
return `import { Schema } from "@uxf/data-grid";
|
|
19
|
+
import json from "${schemaRelativeImport}";
|
|
20
|
+
|
|
21
|
+
export const dataGridSchema_${camelize(gridName)}: Schema<any> = json as any;`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function generate(jsonSchema, filename, outputDirectory) {
|
|
25
|
+
const gridName = parse(filename).name;
|
|
26
|
+
const generatedPath = join(process.cwd(), outputDirectory, gridName);
|
|
27
|
+
|
|
28
|
+
const generatedSchemaFilename = `${generatedPath}/schema.ts`;
|
|
29
|
+
|
|
30
|
+
writeFile(
|
|
31
|
+
generatedSchemaFilename,
|
|
32
|
+
generateSchemaFile(gridName, relative(dirname(generatedSchemaFilename), filename)),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = (schemaDirectory, outputDirectory) => {
|
|
37
|
+
globSync(schemaDirectory + "/*.json")
|
|
38
|
+
.map((path) => process.cwd() + "/" + path)
|
|
39
|
+
.forEach((filename) => generate(readFileSync(filename), filename, outputDirectory));
|
|
40
|
+
};
|
package/_store/reducer.js
CHANGED
|
@@ -4,7 +4,7 @@ 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;
|
|
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
9
|
return {
|
|
10
10
|
request: {
|
|
@@ -13,12 +13,12 @@ const getInitialState = (schema, init, initialUserConfig) => {
|
|
|
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
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: (
|
|
17
|
-
search: "",
|
|
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 : "",
|
|
18
18
|
},
|
|
19
19
|
userConfig: {
|
|
20
|
-
columns: (
|
|
21
|
-
perPage: (
|
|
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,
|
|
22
22
|
},
|
|
23
23
|
tabRequests: {},
|
|
24
24
|
};
|
|
@@ -12,11 +12,13 @@ export type GridType = {
|
|
|
12
12
|
filters: {
|
|
13
13
|
text: "text";
|
|
14
14
|
bool: "boolean";
|
|
15
|
+
date: "date";
|
|
15
16
|
ival: "interval";
|
|
16
17
|
tel: "string";
|
|
17
18
|
mail: "string";
|
|
18
19
|
link: "string";
|
|
19
20
|
sele: "select";
|
|
20
21
|
seleBool: "select";
|
|
22
|
+
multiSelect: "multiSelect";
|
|
21
23
|
};
|
|
22
24
|
};
|
package/_story-utils/loader.js
CHANGED
|
@@ -29,7 +29,7 @@ const loader = async (_, request) => {
|
|
|
29
29
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
30
30
|
return {
|
|
31
31
|
count: filteredData.length,
|
|
32
|
-
totalCount:
|
|
32
|
+
totalCount: data_1.data.length,
|
|
33
33
|
result: filteredData.slice(page * perPage, page * perPage + perPage),
|
|
34
34
|
};
|
|
35
35
|
};
|
package/_story-utils/schema.js
CHANGED
|
@@ -18,6 +18,7 @@ exports.schema = {
|
|
|
18
18
|
{ name: "bool", type: "boolean", label: "Boolean" },
|
|
19
19
|
{ name: "ival", type: "interval", label: "Super interval" },
|
|
20
20
|
{ name: "mail", type: "string", label: "E-mail" },
|
|
21
|
+
{ name: "date", type: "date", label: "Date" },
|
|
21
22
|
{ name: "tel", type: "string", label: "Phone" },
|
|
22
23
|
{ name: "link", type: "string", label: "Link" },
|
|
23
24
|
{
|
|
@@ -30,6 +31,17 @@ exports.schema = {
|
|
|
30
31
|
{ id: 2, label: "B" },
|
|
31
32
|
],
|
|
32
33
|
},
|
|
34
|
+
{
|
|
35
|
+
name: "multiSelect",
|
|
36
|
+
label: "Multi select",
|
|
37
|
+
type: "multiSelect",
|
|
38
|
+
options: [
|
|
39
|
+
{ label: "Option 1", id: "option-1" },
|
|
40
|
+
{ label: "Option 2", id: "option-2" },
|
|
41
|
+
{ label: "Option 3", id: "option-3" },
|
|
42
|
+
{ label: "Option 4", id: "option-4" },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
33
45
|
{
|
|
34
46
|
name: "seleBool",
|
|
35
47
|
type: "select",
|
package/data-grid.js
CHANGED
|
@@ -15,7 +15,6 @@ const row_counts_1 = require("./row-counts");
|
|
|
15
15
|
const rows_per_page_select_1 = require("./rows-per-page-select");
|
|
16
16
|
const selected_rows_toolbar_1 = require("./selected-rows-toolbar");
|
|
17
17
|
const table_1 = require("./table");
|
|
18
|
-
const action_cell_base_1 = require("./table/components/action-cell-base");
|
|
19
18
|
const no_rows_fallback_1 = require("./table/no-rows-fallback");
|
|
20
19
|
const toolbar_control_1 = require("./toolbar-control");
|
|
21
20
|
const toolbar_customs_1 = require("./toolbar-customs");
|
|
@@ -23,20 +22,20 @@ const toolbar_tabs_1 = require("./toolbar-tabs");
|
|
|
23
22
|
const classes_1 = require("./utils/classes");
|
|
24
23
|
const DefaultSelectedRowsToolbarActions = () => null;
|
|
25
24
|
function DataGrid(props) {
|
|
26
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o
|
|
25
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
27
26
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
28
27
|
react_1.default.createElement("div", { className: (0, cx_1.cx)("uxf-data-grid", props.noBorder && classes_1.NO_BORDER_CLASS, props.className) },
|
|
29
28
|
react_1.default.createElement("div", { className: (0, cx_1.cx)("uxf-data-grid__toolbar", props.noBorder && classes_1.NO_BORDER_CLASS) },
|
|
30
29
|
react_1.default.createElement(toolbar_tabs_1.ToolbarTabs, { state: props.state, actions: props.actions, schema: props.schema }),
|
|
31
|
-
react_1.default.createElement(toolbar_control_1.ToolbarControl, { state: props.state, actions: props.actions, gridName: props.gridName, filterHandlers: (
|
|
30
|
+
react_1.default.createElement(toolbar_control_1.ToolbarControl, { state: props.state, actions: props.actions, gridName: props.gridName, filterHandlers: (_a = props.filterHandlers) !== null && _a !== void 0 ? _a : filter_handler_1.defaultFilterHandlers, schema: props.schema, onCsvDownload: props.onCsvDownload }),
|
|
32
31
|
react_1.default.createElement(toolbar_customs_1.ToolbarCustoms, { buttons: props.customActions })),
|
|
33
32
|
react_1.default.createElement(linear_progress_1.LinearProgress, { isLoading: props.isLoading }),
|
|
34
|
-
react_1.default.createElement(filter_list_1.FilterList, { state: props.state, actions: props.actions, schema: props.schema, gridName: props.gridName, filterHandlers: (
|
|
35
|
-
react_1.default.createElement(table_1.Table, { state: props.state, actions: props.actions, schema: props.schema, data: (
|
|
33
|
+
react_1.default.createElement(filter_list_1.FilterList, { state: props.state, actions: props.actions, schema: props.schema, gridName: props.gridName, filterHandlers: (_b = props.filterHandlers) !== null && _b !== void 0 ? _b : filter_handler_1.defaultFilterHandlers, className: props.noBorder ? classes_1.NO_BORDER_CLASS : undefined }),
|
|
34
|
+
react_1.default.createElement(table_1.Table, { state: props.state, actions: props.actions, schema: props.schema, data: (_d = (_c = props.data) === null || _c === void 0 ? void 0 : _c.result) !== null && _d !== void 0 ? _d : [], isLoading: props.isLoading, error: props.error, rowClass: props.rowClass, keyExtractor: props.keyExtractor, rowHeight: props.rowHeight, headerRowHeight: props.headerRowHeight, bodyCells: (_e = props.bodyCells) !== null && _e !== void 0 ? _e : body_cell_1.BodyCells, NoRowsFallback: (_f = props.NoRowsFallback) !== null && _f !== void 0 ? _f : no_rows_fallback_1.NoRowsFallback, actionCell: props.actionCell, onReload: props.onReload, isRowSelectable: props.isRowSelectable }),
|
|
36
35
|
react_1.default.createElement("div", { className: (0, cx_1.cx)("uxf-data-grid__footer", props.noBorder && classes_1.NO_BORDER_CLASS) },
|
|
37
36
|
react_1.default.createElement(rows_per_page_select_1.RowsPerPageSelect, { state: props.state, actions: props.actions }),
|
|
38
|
-
react_1.default.createElement(row_counts_1.RowCounts, { state: props.state, totalCount: (
|
|
39
|
-
react_1.default.createElement(pagination_1.Pagination, { state: props.state, actions: props.actions,
|
|
40
|
-
react_1.default.createElement(selected_rows_toolbar_1.SelectedRowsToolbar, { state: props.state, actions: props.actions, Actions: (
|
|
37
|
+
react_1.default.createElement(row_counts_1.RowCounts, { state: props.state, count: (_h = (_g = props.data) === null || _g === void 0 ? void 0 : _g.count) !== null && _h !== void 0 ? _h : 0, totalCount: (_k = (_j = props.data) === null || _j === void 0 ? void 0 : _j.totalCount) !== null && _k !== void 0 ? _k : 0 }),
|
|
38
|
+
react_1.default.createElement(pagination_1.Pagination, { state: props.state, actions: props.actions, count: (_m = (_l = props.data) === null || _l === void 0 ? void 0 : _l.count) !== null && _m !== void 0 ? _m : 0 }))),
|
|
39
|
+
react_1.default.createElement(selected_rows_toolbar_1.SelectedRowsToolbar, { state: props.state, actions: props.actions, Actions: (_o = props.SelectedRowsToolbarActions) !== null && _o !== void 0 ? _o : DefaultSelectedRowsToolbarActions })));
|
|
41
40
|
}
|
|
42
41
|
exports.DataGrid = DataGrid;
|
package/data-grid.stories.js
CHANGED
|
@@ -24,12 +24,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.Default = void 0;
|
|
27
|
+
const buildArray_1 = require("@uxf/core/utils/buildArray");
|
|
27
28
|
const json_renderer_1 = require("@uxf/example/src/components/json-renderer");
|
|
28
29
|
const toggle_1 = require("@uxf/ui/toggle");
|
|
29
30
|
const react_1 = __importStar(require("react"));
|
|
30
31
|
const loader_1 = require("./_story-utils/loader");
|
|
31
32
|
const schema_1 = require("./_story-utils/schema");
|
|
32
33
|
const data_grid_1 = require("./data-grid");
|
|
34
|
+
const table_1 = require("./table");
|
|
33
35
|
const use_data_grid_control_1 = require("./use-data-grid-control");
|
|
34
36
|
const use_data_grid_fetching_1 = require("./use-data-grid-fetching");
|
|
35
37
|
function Default() {
|
|
@@ -45,7 +47,29 @@ function Default() {
|
|
|
45
47
|
});
|
|
46
48
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
47
49
|
react_1.default.createElement(toggle_1.Toggle, { label: "No border", value: noBorder, onChange: (value) => setNoBorder(!!value) }),
|
|
48
|
-
react_1.default.createElement(data_grid_1.DataGrid, { onReload: onReload, state: state, actions: actions, data: data, isLoading: isLoading, error: error, schema: schema_1.schema, onCsvDownload: console.log, noBorder: noBorder,
|
|
50
|
+
react_1.default.createElement(data_grid_1.DataGrid, { onReload: onReload, state: state, actions: actions, data: data, isLoading: isLoading, error: error, schema: schema_1.schema, onCsvDownload: console.log, noBorder: noBorder, isRowSelectable: true, actionCell: {
|
|
51
|
+
width: 100,
|
|
52
|
+
Component: () => {
|
|
53
|
+
const actionCellActions = (0, buildArray_1.buildArray)()
|
|
54
|
+
.add({
|
|
55
|
+
icon: "arrow-right",
|
|
56
|
+
isIconButton: true,
|
|
57
|
+
href: "https://www.uxf.cz",
|
|
58
|
+
target: "_blank",
|
|
59
|
+
})
|
|
60
|
+
.add({
|
|
61
|
+
icon: "file",
|
|
62
|
+
label: "Download",
|
|
63
|
+
onClick: console.log,
|
|
64
|
+
})
|
|
65
|
+
.add({
|
|
66
|
+
icon: "cloud",
|
|
67
|
+
label: "Reload",
|
|
68
|
+
onClick: console.log,
|
|
69
|
+
});
|
|
70
|
+
return react_1.default.createElement(table_1.ActionCell, { buttons: actionCellActions, visibleButtonsCount: 1 });
|
|
71
|
+
},
|
|
72
|
+
} }),
|
|
49
73
|
react_1.default.createElement(json_renderer_1.JsonRenderer, { value: state })));
|
|
50
74
|
}
|
|
51
75
|
exports.Default = Default;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const filter_nullish_1 = require("@uxf/core/utils/filter-nullish");
|
|
7
|
+
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
8
|
+
const chip_1 = require("@uxf/ui/chip");
|
|
9
|
+
const date_picker_input_1 = require("@uxf/ui/date-picker-input");
|
|
10
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
11
|
+
const react_1 = __importDefault(require("react"));
|
|
12
|
+
const date = {
|
|
13
|
+
input: function (props) {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
const initializedValue = typeof ((_a = props.value.value) === null || _a === void 0 ? void 0 : _a.from) !== "undefined" && typeof ((_b = props.value.value) === null || _b === void 0 ? void 0 : _b.to) !== "undefined"
|
|
16
|
+
? props.value
|
|
17
|
+
: { name: props.filter.name, value: { from: null, to: null } };
|
|
18
|
+
return (react_1.default.createElement("div", { className: "uxf-data-grid__filter uxf-data-grid__filter--date" },
|
|
19
|
+
react_1.default.createElement(date_picker_input_1.DatePickerInput, { value: initializedValue.value.from, onChange: (changedValue) => props.onFilter({
|
|
20
|
+
...initializedValue,
|
|
21
|
+
value: { ...initializedValue.value, from: changedValue },
|
|
22
|
+
}), label: `${props.filter.label} (od)` }),
|
|
23
|
+
react_1.default.createElement(date_picker_input_1.DatePickerInput, { value: initializedValue.value.to, onChange: (changedValue) => props.onFilter({ ...initializedValue, value: { ...initializedValue.value, to: changedValue } }), label: `${props.filter.label} (do)` })));
|
|
24
|
+
},
|
|
25
|
+
listItem: function (props) {
|
|
26
|
+
if ((0, is_nil_1.isNil)(props.value.value)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const value = props.value.value;
|
|
30
|
+
if ((0, is_nil_1.isNil)(value.from) && (0, is_nil_1.isNil)(value.to)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const formatDate = [
|
|
34
|
+
value.from ? "od " + (0, dayjs_1.default)(value.from).format("l") : "",
|
|
35
|
+
value.to ? "do " + (0, dayjs_1.default)(value.to).format("l") : "",
|
|
36
|
+
];
|
|
37
|
+
return (react_1.default.createElement(chip_1.Chip, { onClose: () => props.onFilter({ ...props.value, value: undefined }) },
|
|
38
|
+
props.filter.label,
|
|
39
|
+
" ",
|
|
40
|
+
(0, filter_nullish_1.filterNullish)(formatDate).join(" ")));
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
exports.default = date;
|
package/filter-handler/index.js
CHANGED
|
@@ -20,16 +20,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
exports.defaultFilterHandlers = void 0;
|
|
21
21
|
const bool_filter_1 = __importDefault(require("./bool-filter"));
|
|
22
22
|
const boolean_filter_1 = __importDefault(require("./boolean-filter"));
|
|
23
|
+
const date_1 = __importDefault(require("./date"));
|
|
23
24
|
const interval_filter_1 = __importDefault(require("./interval-filter"));
|
|
25
|
+
const multi_select_1 = __importDefault(require("./multi-select"));
|
|
24
26
|
const select_filter_1 = __importDefault(require("./select-filter"));
|
|
25
27
|
const text_filter_1 = __importDefault(require("./text-filter"));
|
|
26
28
|
__exportStar(require("./types"), exports);
|
|
27
29
|
exports.defaultFilterHandlers = {
|
|
28
30
|
text: text_filter_1.default,
|
|
29
31
|
string: text_filter_1.default,
|
|
32
|
+
date: date_1.default,
|
|
30
33
|
bool: bool_filter_1.default,
|
|
31
34
|
boolean: boolean_filter_1.default,
|
|
32
35
|
checkbox: boolean_filter_1.default,
|
|
33
36
|
interval: interval_filter_1.default,
|
|
37
|
+
multiSelect: multi_select_1.default,
|
|
34
38
|
select: select_filter_1.default,
|
|
35
39
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
7
|
+
const chip_1 = require("@uxf/ui/chip");
|
|
8
|
+
const multi_select_1 = require("@uxf/ui/multi-select");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const multiSelect = {
|
|
11
|
+
input: (props) => {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
return (react_1.default.createElement(multi_select_1.MultiSelect, { options: (_a = props.filter.options) !== null && _a !== void 0 ? _a : [], label: props.filter.label, value: (_b = props.value.value) === null || _b === void 0 ? void 0 : _b.map((id) => { var _a; return (_a = props.filter.options) === null || _a === void 0 ? void 0 : _a.find((option) => option.id === id); }), onChange: (value) => {
|
|
14
|
+
props.onFilter({
|
|
15
|
+
...props.value,
|
|
16
|
+
value: (0, is_nil_1.isNil)(value) || value.length === 0 ? null : value.map((item) => item.id),
|
|
17
|
+
});
|
|
18
|
+
} }));
|
|
19
|
+
},
|
|
20
|
+
listItem: (props) => {
|
|
21
|
+
return (react_1.default.createElement(chip_1.Chip, { onClose: props.onClear },
|
|
22
|
+
props.filter.label,
|
|
23
|
+
":\u00A0",
|
|
24
|
+
props.value.value
|
|
25
|
+
.map((id) => { var _a, _b; return (_b = (_a = props.filter.options) === null || _a === void 0 ? void 0 : _a.find((option) => option.id === id)) === null || _b === void 0 ? void 0 : _b.label; })
|
|
26
|
+
.join(", ")));
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
exports.default = multiSelect;
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/data-grid",
|
|
3
|
-
"version": "11.0.0
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "UXF DataGrid",
|
|
5
5
|
"homepage": "https://gitlab.com/uxf-npm/data-grid#readme",
|
|
6
6
|
"main": "index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"uxf-data-grid-generator": "bin/uxf-data-grid-generator.js"
|
|
9
|
+
},
|
|
7
10
|
"typings": "index.d.ts",
|
|
8
11
|
"publishConfig": {
|
|
9
12
|
"access": "public"
|
|
@@ -27,9 +30,11 @@
|
|
|
27
30
|
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
28
31
|
},
|
|
29
32
|
"dependencies": {
|
|
30
|
-
"@uxf/ui": "
|
|
33
|
+
"@uxf/ui": "11.0.0",
|
|
31
34
|
"dayjs": "1.11.10",
|
|
32
|
-
"
|
|
35
|
+
"fast-glob": "^3.3.2",
|
|
36
|
+
"react-data-grid": "7.0.0-beta.39",
|
|
37
|
+
"yargs": "^17.7.2"
|
|
33
38
|
},
|
|
34
39
|
"peerDependencies": {
|
|
35
40
|
"react": ">=18.2.0",
|
|
@@ -2,7 +2,7 @@ import { Nullish } from "@uxf/core/types";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { DataGridControl } from "../use-data-grid-control";
|
|
4
4
|
interface PaginationProps extends DataGridControl {
|
|
5
|
-
|
|
5
|
+
count: number | Nullish;
|
|
6
6
|
}
|
|
7
7
|
export declare function Pagination(props: PaginationProps): React.JSX.Element;
|
|
8
8
|
export {};
|
package/pagination/pagination.js
CHANGED
|
@@ -8,8 +8,8 @@ const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
|
8
8
|
const pagination_1 = require("@uxf/ui/pagination");
|
|
9
9
|
const react_1 = __importDefault(require("react"));
|
|
10
10
|
function Pagination(props) {
|
|
11
|
-
const pageCount = (0, is_not_nil_1.isNotNil)(props.
|
|
12
|
-
? Math.max(Math.ceil(props.
|
|
11
|
+
const pageCount = (0, is_not_nil_1.isNotNil)(props.count) && props.count > 0
|
|
12
|
+
? Math.max(Math.ceil(props.count / props.state.request.perPage), 1)
|
|
13
13
|
: 1;
|
|
14
14
|
return (react_1.default.createElement(pagination_1.Pagination, { count: pageCount, page: props.state.request.page + 1, onPageChange: (value) => props.actions.changePage(value - 1) }));
|
|
15
15
|
}
|
|
@@ -12,7 +12,7 @@ const pagination_1 = require("./pagination");
|
|
|
12
12
|
function Default() {
|
|
13
13
|
const { state, actions } = (0, use_data_grid_control_1.useDataGridControl)({ schema: schema_1.schema });
|
|
14
14
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
15
|
-
react_1.default.createElement(pagination_1.Pagination, { state: state, actions: actions,
|
|
15
|
+
react_1.default.createElement(pagination_1.Pagination, { state: state, actions: actions, count: 100 }),
|
|
16
16
|
react_1.default.createElement(json_renderer_1.JsonRenderer, { value: state })));
|
|
17
17
|
}
|
|
18
18
|
exports.Default = Default;
|
package/row-counts/row-counts.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.RowCounts = void 0;
|
|
7
|
+
const show_1 = require("@uxf/core/components/show");
|
|
7
8
|
const react_1 = __importDefault(require("react"));
|
|
8
9
|
function RowCounts(props) {
|
|
9
10
|
const fromNumber = props.state.request.page * props.state.request.perPage + 1;
|
|
@@ -13,6 +14,11 @@ function RowCounts(props) {
|
|
|
13
14
|
"-",
|
|
14
15
|
toNumber,
|
|
15
16
|
" z ",
|
|
16
|
-
props.
|
|
17
|
+
props.count,
|
|
18
|
+
" ",
|
|
19
|
+
react_1.default.createElement(show_1.Show, { when: props.count !== props.totalCount },
|
|
20
|
+
"(celkem ",
|
|
21
|
+
props.totalCount,
|
|
22
|
+
")")));
|
|
17
23
|
}
|
|
18
24
|
exports.RowCounts = RowCounts;
|
|
@@ -10,6 +10,6 @@ const use_data_grid_control_1 = require("../use-data-grid-control");
|
|
|
10
10
|
const row_counts_1 = require("./row-counts");
|
|
11
11
|
function Default() {
|
|
12
12
|
const { state } = (0, use_data_grid_control_1.useDataGridControl)({ schema: schema_1.schema });
|
|
13
|
-
return react_1.default.createElement(row_counts_1.RowCounts, { state: state, totalCount: 150 });
|
|
13
|
+
return react_1.default.createElement(row_counts_1.RowCounts, { state: state, totalCount: 150, count: 100 });
|
|
14
14
|
}
|
|
15
15
|
exports.Default = Default;
|
|
@@ -27,6 +27,6 @@ function SelectedRowsToolbar(props) {
|
|
|
27
27
|
react_1.default.createElement("p", null, getText(props.state.selectedRows.length)),
|
|
28
28
|
react_1.default.createElement("div", { className: "uxf-data-grid__selected-rows-toolbar-actions" },
|
|
29
29
|
props.Actions && (react_1.default.createElement(props.Actions, { state: props.state, actions: props.actions, reload: () => { var _a; return (_a = props.onReload) === null || _a === void 0 ? void 0 : _a.call(props); } })),
|
|
30
|
-
react_1.default.createElement(button_1.Button, { onClick: () => props.actions.setSelectedRows([]) }, "
|
|
30
|
+
react_1.default.createElement(button_1.Button, { onClick: () => props.actions.setSelectedRows([]) }, "Zru\u0161it v\u00FDb\u011Br")))));
|
|
31
31
|
}
|
|
32
32
|
exports.SelectedRowsToolbar = SelectedRowsToolbar;
|
package/styles.css
CHANGED
|
@@ -165,6 +165,12 @@
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
&__filter {
|
|
168
|
+
&--date {
|
|
169
|
+
display: grid;
|
|
170
|
+
gap: theme("spacing.4");
|
|
171
|
+
grid-template-columns: repeat(2, 1fr);
|
|
172
|
+
}
|
|
173
|
+
|
|
168
174
|
&--interval {
|
|
169
175
|
display: grid;
|
|
170
176
|
gap: theme("spacing.4");
|
|
@@ -292,8 +298,10 @@
|
|
|
292
298
|
display: flex;
|
|
293
299
|
justify-content: center;
|
|
294
300
|
left: 0;
|
|
301
|
+
pointer-events: none;
|
|
295
302
|
position: fixed;
|
|
296
303
|
right: 0;
|
|
304
|
+
z-index: theme("zIndex.fixed");
|
|
297
305
|
}
|
|
298
306
|
|
|
299
307
|
&__selected-rows-toolbar {
|
|
@@ -307,6 +315,7 @@
|
|
|
307
315
|
display: flex;
|
|
308
316
|
justify-content: center;
|
|
309
317
|
padding: theme("spacing.2") theme("spacing.6");
|
|
318
|
+
pointer-events: auto;
|
|
310
319
|
|
|
311
320
|
:root .dark & {
|
|
312
321
|
border-color: theme("colors.darkBorder");
|
|
@@ -23,11 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
const button_1 = require("@uxf/ui/button");
|
|
28
|
-
const icon_1 = require("@uxf/ui/icon");
|
|
26
|
+
exports.ActionCellWrapper = void 0;
|
|
29
27
|
const react_1 = __importStar(require("react"));
|
|
30
|
-
|
|
28
|
+
function ActionCellWrapper(props) {
|
|
31
29
|
const innerRef = (0, react_1.useRef)(null);
|
|
32
30
|
(0, react_1.useEffect)(() => {
|
|
33
31
|
var _a;
|
|
@@ -56,29 +54,5 @@ const ActionCellWrapper = (props) => {
|
|
|
56
54
|
};
|
|
57
55
|
}, []);
|
|
58
56
|
return (react_1.default.createElement("div", { className: "uxf-data-grid__action-cell-wrapper", ref: innerRef }, props.children));
|
|
59
|
-
}
|
|
57
|
+
}
|
|
60
58
|
exports.ActionCellWrapper = ActionCellWrapper;
|
|
61
|
-
const Button = (props) => {
|
|
62
|
-
if (props.getUrl) {
|
|
63
|
-
const href = props.getUrl(props.row);
|
|
64
|
-
if (!href) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
return (react_1.default.createElement(button_1.Button, { href: href, title: props.title, variant: "white", size: "sm", isIconButton: true },
|
|
68
|
-
react_1.default.createElement(icon_1.Icon, { name: props.icon })));
|
|
69
|
-
}
|
|
70
|
-
if (props.onClick) {
|
|
71
|
-
return (react_1.default.createElement(button_1.Button, { variant: "white", size: "sm", onClick: () => { var _a; return (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, props.row); }, isIconButton: true },
|
|
72
|
-
react_1.default.createElement(icon_1.Icon, { name: props.icon })));
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
};
|
|
76
|
-
const ActionCellBase = (props) => {
|
|
77
|
-
const onRemove = props.onRemove;
|
|
78
|
-
const handleRemove = onRemove ? () => onRemove(props.row, props.reload) : undefined;
|
|
79
|
-
return (react_1.default.createElement(exports.ActionCellWrapper, null,
|
|
80
|
-
react_1.default.createElement(Button, { row: props.row, onClick: props.onOpen, getUrl: props.getOpenUrl, icon: "circle-info", title: "Detail" }),
|
|
81
|
-
react_1.default.createElement(Button, { row: props.row, onClick: props.onEdit, getUrl: props.getEditUrl, icon: "pen", title: "Upravit" }),
|
|
82
|
-
react_1.default.createElement(Button, { row: props.row, onClick: handleRemove, getUrl: undefined, icon: "trash", title: "Smazat" })));
|
|
83
|
-
};
|
|
84
|
-
exports.ActionCellBase = ActionCellBase;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ButtonListProps } from "@uxf/ui/button-list";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export interface ActionCellProps {
|
|
4
|
+
buttons: ButtonListProps["buttons"];
|
|
5
|
+
visibleButtonsCount: ButtonListProps["visibleButtonsCount"];
|
|
6
|
+
}
|
|
7
|
+
export declare function ActionCell(props: ActionCellProps): React.JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ActionCell = void 0;
|
|
7
|
+
const button_list_1 = require("@uxf/ui/button-list");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const action_cell_wrapper_1 = require("./action-cell-wrapper");
|
|
10
|
+
function ActionCell(props) {
|
|
11
|
+
return (react_1.default.createElement(action_cell_wrapper_1.ActionCellWrapper, null,
|
|
12
|
+
react_1.default.createElement(button_list_1.ButtonList, { buttons: props.buttons, visibleButtonsCount: props.visibleButtonsCount, variant: "white", size: "xs" })));
|
|
13
|
+
}
|
|
14
|
+
exports.ActionCell = ActionCell;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { DataGridHandle } from "react-data-grid";
|
|
3
|
-
import {
|
|
3
|
+
import { DataGridBaseProps } from "../../types/data-grid-props";
|
|
4
|
+
import { BaseGridType } from "../../types/schema";
|
|
4
5
|
export declare function useRdgVisuals(props: {
|
|
5
6
|
headerRowHeight?: DataGridBaseProps<BaseGridType, any>["headerRowHeight"];
|
|
6
|
-
mode?: DataGridBaseProps<BaseGridType, any>["mode"];
|
|
7
7
|
rowHeight?: DataGridBaseProps<BaseGridType, any>["rowHeight"];
|
|
8
8
|
rows: any[];
|
|
9
9
|
}): {
|
|
@@ -9,7 +9,7 @@ function useRdgVisuals(props) {
|
|
|
9
9
|
const rowHeight = (_a = props.rowHeight) !== null && _a !== void 0 ? _a : 44;
|
|
10
10
|
const headerRowHeight = (_b = props.headerRowHeight) !== null && _b !== void 0 ? _b : 36;
|
|
11
11
|
const contentHeight = typeof rowHeight === "function"
|
|
12
|
-
? props.rows.reduce((prev, curr) => prev + rowHeight(
|
|
12
|
+
? props.rows.reduce((prev, curr) => prev + rowHeight(curr))
|
|
13
13
|
: rowHeight * props.rows.length;
|
|
14
14
|
const ref = (0, react_1.useRef)(null);
|
|
15
15
|
const size = {
|
|
@@ -36,7 +36,7 @@ function useRdgVisuals(props) {
|
|
|
36
36
|
return () => observer.disconnect();
|
|
37
37
|
}, [mounted, storedSize]);
|
|
38
38
|
return {
|
|
39
|
-
className:
|
|
39
|
+
className: "uxf-data-grid__table rdg-light",
|
|
40
40
|
headerRowHeight,
|
|
41
41
|
ready: mounted,
|
|
42
42
|
ref,
|
|
@@ -25,14 +25,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.useReactDataGridColumns = void 0;
|
|
27
27
|
const cx_1 = require("@uxf/core/utils/cx");
|
|
28
|
-
const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
29
28
|
const react_1 = __importStar(require("react"));
|
|
30
29
|
const react_data_grid_1 = require("react-data-grid");
|
|
31
|
-
const action_cell_base_1 = require("../components/action-cell-base");
|
|
32
30
|
function useReactDataGridColumns(props, state) {
|
|
33
|
-
|
|
34
|
-
const { onReload, actionCellWidth, schema, isRowSelectable, BodyCells, getOpenUrl, onOpen, getEditUrl, onEdit, onRemove, } = props;
|
|
35
|
-
const ActionCell = (_a = props.ActionCell) !== null && _a !== void 0 ? _a : action_cell_base_1.ActionCellBase;
|
|
31
|
+
const { onReload, schema, isRowSelectable, bodyCells, actionCell } = props;
|
|
36
32
|
const columnsConfig = state.userConfig.columns;
|
|
37
33
|
return (0, react_1.useMemo)(() => {
|
|
38
34
|
var _a;
|
|
@@ -58,7 +54,7 @@ function useReactDataGridColumns(props, state) {
|
|
|
58
54
|
renderCell: (p) => {
|
|
59
55
|
var _a;
|
|
60
56
|
const columnType = schemaColumn.type;
|
|
61
|
-
const BodyCell = (_a =
|
|
57
|
+
const BodyCell = (_a = bodyCells === null || bodyCells === void 0 ? void 0 : bodyCells[columnType]) !== null && _a !== void 0 ? _a : bodyCells === null || bodyCells === void 0 ? void 0 : bodyCells.default;
|
|
62
58
|
if (!BodyCell) {
|
|
63
59
|
return null;
|
|
64
60
|
}
|
|
@@ -71,29 +67,18 @@ function useReactDataGridColumns(props, state) {
|
|
|
71
67
|
},
|
|
72
68
|
});
|
|
73
69
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
70
|
+
if (actionCell) {
|
|
71
|
+
columns.push({
|
|
72
|
+
key: "__action_column",
|
|
73
|
+
name: "",
|
|
74
|
+
resizable: false,
|
|
75
|
+
headerCellClass: "uxf-data-grid__action-cell",
|
|
76
|
+
cellClass: "uxf-data-grid__action-cell",
|
|
77
|
+
width: actionCell.width,
|
|
78
|
+
renderCell: (p) => react_1.default.createElement(actionCell.Component, { reload: async () => onReload === null || onReload === void 0 ? void 0 : onReload(), row: p.row }),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
83
81
|
return columns;
|
|
84
|
-
}, [
|
|
85
|
-
columnsConfig,
|
|
86
|
-
ActionCell,
|
|
87
|
-
actionCellWidth,
|
|
88
|
-
schema.columns,
|
|
89
|
-
BodyCells,
|
|
90
|
-
isRowSelectable,
|
|
91
|
-
onOpen,
|
|
92
|
-
getOpenUrl,
|
|
93
|
-
onEdit,
|
|
94
|
-
getEditUrl,
|
|
95
|
-
onRemove,
|
|
96
|
-
onReload,
|
|
97
|
-
]);
|
|
82
|
+
}, [columnsConfig, actionCell, schema.columns, bodyCells, isRowSelectable, onReload]);
|
|
98
83
|
}
|
|
99
84
|
exports.useReactDataGridColumns = useReactDataGridColumns;
|
package/table/index.d.ts
CHANGED
package/table/index.js
CHANGED
|
@@ -14,4 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./components/action-cell"), exports);
|
|
18
|
+
__exportStar(require("./components/action-cell-wrapper"), exports);
|
|
17
19
|
__exportStar(require("./table"), exports);
|
package/table/table.d.ts
CHANGED
package/table/table.js
CHANGED
|
@@ -27,10 +27,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.Table = void 0;
|
|
30
|
+
const show_1 = require("@uxf/core/components/show");
|
|
30
31
|
const useIsMounted_1 = require("@uxf/core/hooks/useIsMounted");
|
|
31
32
|
const react_1 = __importStar(require("react"));
|
|
32
33
|
const react_data_grid_1 = __importDefault(require("react-data-grid"));
|
|
33
34
|
const select_row_checkbox_1 = require("./components/select-row-checkbox");
|
|
35
|
+
const use_rdg_visuals_1 = require("./hooks/use-rdg-visuals");
|
|
34
36
|
const use_react_data_grid_columns_1 = require("./hooks/use-react-data-grid-columns");
|
|
35
37
|
const defaultKeyExtractor = (r) => r.id;
|
|
36
38
|
const DefaultNoRowsFallback = () => react_1.default.createElement("div", null, "no rows");
|
|
@@ -41,7 +43,7 @@ function Table(props) {
|
|
|
41
43
|
const headerRowHeight = (_b = props.headerRowHeight) !== null && _b !== void 0 ? _b : 36;
|
|
42
44
|
const keyExtractor = (_c = props.keyExtractor) !== null && _c !== void 0 ? _c : defaultKeyExtractor;
|
|
43
45
|
const contentHeight = typeof rowHeight === "function"
|
|
44
|
-
? props.data.reduce((prev, curr) => prev + rowHeight(
|
|
46
|
+
? props.data.reduce((prev, curr) => prev + rowHeight(curr))
|
|
45
47
|
: (rowHeight + 1) * props.data.length;
|
|
46
48
|
const reactDataGridStyles = {
|
|
47
49
|
border: 0,
|
|
@@ -58,7 +60,10 @@ function Table(props) {
|
|
|
58
60
|
}), [NoRowsFallback, error, isLoading]);
|
|
59
61
|
const columns = (0, use_react_data_grid_columns_1.useReactDataGridColumns)(props, props.state);
|
|
60
62
|
const onSelectRows = (value) => {
|
|
61
|
-
const selectedRows = Array.from(value).map((id) =>
|
|
63
|
+
const selectedRows = Array.from(value).map((id) => {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
return (_b = (_a = props.state.selectedRows) === null || _a === void 0 ? void 0 : _a.find((row) => keyExtractor(row) === id)) !== null && _b !== void 0 ? _b : props.data.find((row) => keyExtractor(row) === id);
|
|
66
|
+
});
|
|
62
67
|
props.actions.setSelectedRows(selectedRows);
|
|
63
68
|
};
|
|
64
69
|
const onSortColumnChange = (sortColumns) => {
|
|
@@ -72,9 +77,12 @@ function Table(props) {
|
|
|
72
77
|
const sortColumns = props.state.request.sort && props.state.request.dir
|
|
73
78
|
? [{ columnKey: props.state.request.sort, direction: props.state.request.dir.toUpperCase() }]
|
|
74
79
|
: [];
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
const rdgVisuals = (0, use_rdg_visuals_1.useRdgVisuals)({
|
|
81
|
+
headerRowHeight: props.headerRowHeight,
|
|
82
|
+
rowHeight: props.rowHeight,
|
|
83
|
+
rows: props.data,
|
|
84
|
+
});
|
|
85
|
+
return (react_1.default.createElement(show_1.Show, { when: isMounted },
|
|
86
|
+
react_1.default.createElement(react_data_grid_1.default, { ref: rdgVisuals.ref, style: reactDataGridStyles, className: rdgVisuals.className, columns: columns, rows: props.data, enableVirtualization: false, onSortColumnsChange: onSortColumnChange, sortColumns: sortColumns, rowHeight: rdgVisuals.rowHeight, headerRowHeight: rdgVisuals.headerRowHeight, rowClass: props.rowClass, rowKeyGetter: (_e = props.keyExtractor) !== null && _e !== void 0 ? _e : defaultKeyExtractor, selectedRows: new Set((_g = (_f = props.state.selectedRows) === null || _f === void 0 ? void 0 : _f.map(keyExtractor)) !== null && _g !== void 0 ? _g : []), onSelectedRowsChange: onSelectRows, renderers: components })));
|
|
79
87
|
}
|
|
80
88
|
exports.Table = Table;
|
package/table/table.stories.js
CHANGED
|
@@ -14,7 +14,7 @@ const table_1 = require("./table");
|
|
|
14
14
|
function Default() {
|
|
15
15
|
const { state, actions } = (0, use_data_grid_control_1.useDataGridControl)({ schema: schema_1.schema });
|
|
16
16
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
17
|
-
react_1.default.createElement(table_1.Table, { state: state, actions: actions, data: data_1.data, isLoading: true, error: undefined, schema: schema_1.schema,
|
|
17
|
+
react_1.default.createElement(table_1.Table, { state: state, actions: actions, data: data_1.data, isLoading: true, error: undefined, schema: schema_1.schema, bodyCells: body_cell_1.BodyCells, isRowSelectable: true }),
|
|
18
18
|
react_1.default.createElement(json_renderer_1.JsonRenderer, { value: state })));
|
|
19
19
|
}
|
|
20
20
|
exports.Default = Default;
|
package/table/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Nullish } from "@uxf/core/types";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ActionCellComponent, BodyCellComponents } from "../types/components";
|
|
3
|
+
import { KeyExtractor } from "../types/core";
|
|
4
|
+
import { Schema } from "../types/schema";
|
|
4
5
|
import { DataGridControl } from "../use-data-grid-control";
|
|
5
6
|
import { NoRowsFallbackComponent } from "./no-rows-fallback";
|
|
6
7
|
export interface TableProps<Row> extends DataGridControl {
|
|
@@ -9,18 +10,15 @@ export interface TableProps<Row> extends DataGridControl {
|
|
|
9
10
|
isLoading?: boolean;
|
|
10
11
|
error?: any | Nullish;
|
|
11
12
|
onReload?: () => void;
|
|
12
|
-
rowHeight?:
|
|
13
|
-
headerRowHeight?:
|
|
13
|
+
rowHeight?: number | ((row: Row) => number);
|
|
14
|
+
headerRowHeight?: number;
|
|
14
15
|
rowClass?: (row: Row) => "success" | "warning" | "error" | "primary" | "secondary" | string | null | undefined;
|
|
15
16
|
keyExtractor?: KeyExtractor;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
bodyCells?: BodyCellComponents<any, any>;
|
|
18
|
+
actionCell?: {
|
|
19
|
+
width: number;
|
|
20
|
+
Component: ActionCellComponent<any>;
|
|
21
|
+
};
|
|
19
22
|
NoRowsFallback?: NoRowsFallbackComponent;
|
|
20
23
|
isRowSelectable?: boolean;
|
|
21
|
-
onOpen?: (row: Row) => void;
|
|
22
|
-
getOpenUrl?: (row: Row) => string | null | undefined;
|
|
23
|
-
onEdit?: (row: Row) => void;
|
|
24
|
-
getEditUrl?: (row: Row) => string | null | undefined;
|
|
25
|
-
onRemove?: (row: Row, reload: () => void) => void;
|
|
26
24
|
}
|
|
@@ -15,8 +15,8 @@ function ToolbarControl(props) {
|
|
|
15
15
|
return (react_1.default.createElement("div", { className: "uxf-data-grid__toolbar-control" },
|
|
16
16
|
react_1.default.createElement(hide_1.Hide, { when: !props.schema.fullText },
|
|
17
17
|
react_1.default.createElement(fulltext_input_1.FulltextInput, { state: props.state, actions: props.actions })),
|
|
18
|
-
react_1.default.createElement(
|
|
18
|
+
(0, is_not_nil_1.isNotNil)(props.onCsvDownload) && (react_1.default.createElement(export_button_1.ExportButton, { state: props.state, actions: props.actions, schema: props.schema, onCsvDownload: props.onCsvDownload })),
|
|
19
19
|
react_1.default.createElement(hidden_columns_button_1.HiddenColumnsButton, { state: props.state, actions: props.actions, schema: props.schema }),
|
|
20
|
-
|
|
20
|
+
react_1.default.createElement(filters_button_1.FiltersButton, { state: props.state, actions: props.actions, gridName: props.gridName, schema: props.schema, filterHandlers: props.filterHandlers })));
|
|
21
21
|
}
|
|
22
22
|
exports.ToolbarControl = ToolbarControl;
|
package/types/components.d.ts
CHANGED
|
@@ -3,11 +3,6 @@ import { RequestFilter } from "./api";
|
|
|
3
3
|
import { BaseGridType, Columns, Filter } from "./schema";
|
|
4
4
|
export interface ActionCellProps<R> {
|
|
5
5
|
row: R;
|
|
6
|
-
onOpen?: (row: R) => void;
|
|
7
|
-
getOpenUrl?: (row: R) => string | null | undefined;
|
|
8
|
-
onEdit?: (row: R) => void;
|
|
9
|
-
getEditUrl?: (row: R) => string | null | undefined;
|
|
10
|
-
onRemove?: (row: R, reload: () => void) => void;
|
|
11
6
|
reload: () => void;
|
|
12
7
|
}
|
|
13
8
|
export type ActionCellComponent<R> = FC<ActionCellProps<R>>;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FilterHandlers } from "../filter-handler";
|
|
2
|
+
import { SelectedRowsToolbarActionsComponent } from "../selected-rows-toolbar";
|
|
3
|
+
import { NoRowsFallbackComponent } from "../table/no-rows-fallback";
|
|
4
|
+
import { TableProps } from "../table/types";
|
|
2
5
|
import { ToolbarCustomsProps } from "../toolbar-customs";
|
|
3
6
|
import { DataGridControl } from "../use-data-grid-control";
|
|
4
7
|
import { DataGridFetchingResult } from "../use-data-grid-fetching";
|
|
8
|
+
import { BodyCellComponents } from "./components";
|
|
5
9
|
import { CsvDownloadHandler, KeyExtractor } from "./core";
|
|
6
10
|
import { BaseGridType, Schema } from "./schema";
|
|
7
|
-
import { UIComponents } from "./ui-components";
|
|
8
11
|
export type DataGridControlProps = DataGridControl;
|
|
9
12
|
export type DataGridDataProps<Row> = DataGridFetchingResult<Row>;
|
|
10
13
|
export type DataGridBaseProps<GridType extends BaseGridType, Row> = {
|
|
@@ -12,20 +15,18 @@ export type DataGridBaseProps<GridType extends BaseGridType, Row> = {
|
|
|
12
15
|
gridName?: string;
|
|
13
16
|
keyExtractor?: KeyExtractor;
|
|
14
17
|
onCsvDownload?: CsvDownloadHandler;
|
|
15
|
-
onOpen?: (row: Row) => void;
|
|
16
|
-
getOpenUrl?: (row: Row) => string | null | undefined;
|
|
17
|
-
onEdit?: (row: Row) => void;
|
|
18
|
-
getEditUrl?: (row: Row) => string | null | undefined;
|
|
19
|
-
onRemove?: (row: Row, reload: () => void) => void;
|
|
20
18
|
noBorder?: boolean;
|
|
21
|
-
rowHeight?:
|
|
22
|
-
headerRowHeight?:
|
|
19
|
+
rowHeight?: number | ((row: Row) => number);
|
|
20
|
+
headerRowHeight?: number;
|
|
23
21
|
rowClass?: (row: Row) => "success" | "warning" | "error" | "primary" | "secondary" | string | null | undefined;
|
|
24
|
-
debug?: boolean;
|
|
25
22
|
className?: string;
|
|
26
23
|
customActions?: ToolbarCustomsProps["buttons"];
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
actionCell?: TableProps<Row>["actionCell"];
|
|
25
|
+
bodyCells?: BodyCellComponents<GridType["columns"], Row>;
|
|
26
|
+
filterHandlers?: FilterHandlers;
|
|
27
|
+
NoRowsFallback?: NoRowsFallbackComponent;
|
|
28
|
+
SelectedRowsToolbarActions?: SelectedRowsToolbarActionsComponent;
|
|
29
29
|
isRowSelectable?: boolean;
|
|
30
|
+
isDebug?: boolean;
|
|
30
31
|
};
|
|
31
32
|
export type DataGridProps<GridType extends BaseGridType, Row> = DataGridBaseProps<GridType, Row> & DataGridDataProps<Row> & DataGridControlProps;
|
package/types/index.d.ts
CHANGED
package/types/index.js
CHANGED
|
@@ -12,6 +12,7 @@ function useDataGridFetching(config) {
|
|
|
12
12
|
const reload = (0, react_1.useCallback)(() => {
|
|
13
13
|
const stateRequest = JSON.parse(stringStateRequest);
|
|
14
14
|
const request = (0, utils_1.createRequest)(stateRequest, schema.sort, schema.dir);
|
|
15
|
+
setIsLoading(true);
|
|
15
16
|
loader(gridName, request, (0, utils_1.encodeFilter)(request))
|
|
16
17
|
.then((response) => {
|
|
17
18
|
setData(response);
|
package/types/ui-components.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { FilterHandlers } from "../filter-handler";
|
|
2
|
-
import { SelectedRowsToolbarActionsComponent } from "../selected-rows-toolbar";
|
|
3
|
-
import { NoRowsFallbackComponent } from "../table/no-rows-fallback";
|
|
4
|
-
import { ActionCellComponent, BodyCellComponents } from "./components";
|
|
5
|
-
import { BaseGridType } from "./schema";
|
|
6
|
-
export type ActionCellWithRequiredWidth<R> = {
|
|
7
|
-
ActionCell?: ActionCellComponent<R>;
|
|
8
|
-
actionCellWidth: number;
|
|
9
|
-
} | {
|
|
10
|
-
ActionCell?: never;
|
|
11
|
-
actionCellWidth?: never;
|
|
12
|
-
};
|
|
13
|
-
export type UIComponents<GridType extends BaseGridType, R> = {
|
|
14
|
-
BodyCells?: BodyCellComponents<GridType["columns"], R>;
|
|
15
|
-
FilterHandlers?: FilterHandlers;
|
|
16
|
-
NoRowsFallback?: NoRowsFallbackComponent;
|
|
17
|
-
SelectedRowsToolbarActions?: SelectedRowsToolbarActionsComponent;
|
|
18
|
-
} & ActionCellWithRequiredWidth<R>;
|
package/types/ui-components.js
DELETED