@uxf/data-grid 11.0.0-beta.16 → 11.0.0-beta.18
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 +28 -0
- package/_generator/index.js +24 -0
- package/bin/uxf-data-grid-generator.js +8 -0
- package/data-grid.js +7 -8
- package/data-grid.stories.js +25 -1
- package/package.json +8 -3
- 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 +10 -5
- package/table/table.stories.js +1 -1
- package/table/types.d.ts +10 -12
- 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/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,28 @@
|
|
|
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: "source" })
|
|
12
|
+
.option("h", { alias: "help", group: "Options" })
|
|
13
|
+
.strict(false)
|
|
14
|
+
.exitProcess(false);
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const { help, source } = cli.parse(argv.slice(2));
|
|
18
|
+
|
|
19
|
+
if (Boolean(help)) {
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
await require("./index")(source);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
console.error(e);
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const { globSync } = require("fast-glob");
|
|
2
|
+
const { readFileSync, writeFileSync } = require("fs");
|
|
3
|
+
const { dirname } = require("path");
|
|
4
|
+
|
|
5
|
+
function generateSchemaFile(jsonSchema, directory) {
|
|
6
|
+
const schemaTs = `import { Schema } from "@uxf/data-grid";
|
|
7
|
+
import json from "./schema.json";
|
|
8
|
+
|
|
9
|
+
export const schema: Schema<any> = json as any;`;
|
|
10
|
+
|
|
11
|
+
writeFileSync(`${directory}/schema.ts`, schemaTs);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function generate(jsonSchema, filename) {
|
|
15
|
+
const directory = dirname(filename);
|
|
16
|
+
|
|
17
|
+
generateSchemaFile(jsonSchema, directory);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = (source) => {
|
|
21
|
+
globSync(source)
|
|
22
|
+
.map((path) => process.cwd() + "/" + path)
|
|
23
|
+
.forEach((filename) => generate(readFileSync(filename), filename));
|
|
24
|
+
};
|
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, count: (
|
|
39
|
-
react_1.default.createElement(pagination_1.Pagination, { state: props.state, actions: props.actions, count: (
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/data-grid",
|
|
3
|
-
"version": "11.0.0-beta.
|
|
3
|
+
"version": "11.0.0-beta.18",
|
|
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": "11.0.0-beta.
|
|
33
|
+
"@uxf/ui": "11.0.0-beta.17",
|
|
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",
|
|
@@ -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,
|
|
@@ -75,9 +77,12 @@ function Table(props) {
|
|
|
75
77
|
const sortColumns = props.state.request.sort && props.state.request.dir
|
|
76
78
|
? [{ columnKey: props.state.request.sort, direction: props.state.request.dir.toUpperCase() }]
|
|
77
79
|
: [];
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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 })));
|
|
82
87
|
}
|
|
83
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
|
}
|
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
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