@uxf/data-grid 11.12.1 → 11.15.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/README.md +12 -0
- package/_api/index.d.ts +8 -0
- package/_api/index.js +12 -0
- package/_generator/cli.js +3 -2
- package/_generator/index.js +38 -10
- package/_store/reducer.js +26 -6
- package/_story-utils/schema.js +13 -11
- package/components.d.ts +5 -0
- package/components.js +5 -0
- package/filter-handler/boolean-select.d.ts +4 -0
- package/filter-handler/boolean-select.js +23 -0
- package/filter-handler/checkbox.d.ts +4 -0
- package/filter-handler/checkbox.js +19 -0
- package/filter-handler/date.d.ts +6 -2
- package/filter-handler/date.js +25 -22
- package/filter-handler/datetime.d.ts +7 -0
- package/filter-handler/datetime.js +34 -0
- package/filter-handler/entity-multi-select.d.ts +5 -0
- package/filter-handler/entity-multi-select.js +22 -0
- package/filter-handler/entity-select.d.ts +5 -0
- package/filter-handler/entity-select.js +22 -0
- package/filter-handler/index.d.ts +1 -1
- package/filter-handler/index.js +20 -13
- package/filter-handler/interval.d.ts +7 -0
- package/filter-handler/interval.js +45 -0
- package/filter-handler/multi-select.d.ts +4 -2
- package/filter-handler/multi-select.js +13 -16
- package/filter-handler/select.d.ts +5 -0
- package/filter-handler/{select-filter.js → select.js} +6 -6
- package/filter-handler/string.d.ts +4 -0
- package/filter-handler/{text-filter.js → string.js} +9 -7
- package/filter-handler/types.d.ts +5 -6
- package/filter-list/filter-list.js +6 -9
- package/filters/filters.js +4 -7
- package/package.json +4 -2
- package/styles.css +3 -1
- package/table-v2/hooks/use-resizable-columns.d.ts +9 -0
- package/table-v2/hooks/use-resizable-columns.js +68 -0
- package/table-v2/index.d.ts +1 -0
- package/table-v2/index.js +17 -0
- package/table-v2/no-rows-fallback.d.ts +7 -0
- package/table-v2/no-rows-fallback.js +15 -0
- package/table-v2/styles.css +62 -0
- package/table-v2/table-v2.d.ts +3 -0
- package/table-v2/table-v2.js +46 -0
- package/table-v2/table-v2.stories.d.ts +2 -0
- package/table-v2/table-v2.stories.js +22 -0
- package/table-v2/types.d.ts +24 -0
- package/table-v2/types.js +2 -0
- package/table-v2/utils/get-grid-template-rows.d.ts +2 -0
- package/table-v2/utils/get-grid-template-rows.js +15 -0
- package/types/api.d.ts +0 -1
- package/types/components.d.ts +5 -5
- package/types/schema.d.ts +5 -7
- package/use-data-grid-control/actions-factory.d.ts +4 -2
- package/use-data-grid-control/actions-factory.js +3 -1
- package/use-data-grid-control/use-data-grid-control.d.ts +3 -1
- package/use-data-grid-fetching/loader.js +2 -4
- package/utils/create-filter-component-props.d.ts +4 -0
- package/utils/create-filter-component-props.js +16 -0
- package/_store/actions.d.ts +0 -45
- package/_store/actions.js +0 -47
- package/filter-handler/bool-filter.d.ts +0 -3
- package/filter-handler/bool-filter.js +0 -20
- package/filter-handler/boolean-filter.d.ts +0 -3
- package/filter-handler/boolean-filter.js +0 -16
- package/filter-handler/interval-filter.d.ts +0 -3
- package/filter-handler/interval-filter.js +0 -50
- package/filter-handler/select-filter.d.ts +0 -3
- package/filter-handler/text-filter.d.ts +0 -3
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { MultiSelectProps } from "@uxf/ui/multi-select";
|
|
1
2
|
import { FilterHandler } from "./types";
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
type StateValue = MultiSelectProps["value"];
|
|
4
|
+
declare const filterHandler: FilterHandler<StateValue>;
|
|
5
|
+
export default filterHandler;
|
|
@@ -3,27 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const is_empty_1 = require("@uxf/core/utils/is-empty");
|
|
7
7
|
const chip_1 = require("@uxf/ui/chip");
|
|
8
8
|
const multi_select_1 = require("@uxf/ui/multi-select");
|
|
9
9
|
const react_1 = __importDefault(require("react"));
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
var _a
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
}, name: props.filter.name }));
|
|
10
|
+
const filterHandler = {
|
|
11
|
+
Input(props) {
|
|
12
|
+
var _a;
|
|
13
|
+
const onChange = (value) => {
|
|
14
|
+
props.onChange(Array.isArray(value) && !(0, is_empty_1.isEmpty)(value) ? value : null);
|
|
15
|
+
};
|
|
16
|
+
return (react_1.default.createElement(multi_select_1.MultiSelect, { options: (_a = props.filter.options) !== null && _a !== void 0 ? _a : [], label: props.filter.label, value: props.value, onChange: onChange, name: props.filter.name }));
|
|
19
17
|
},
|
|
20
|
-
|
|
18
|
+
ListItem(props) {
|
|
19
|
+
var _a;
|
|
21
20
|
return (react_1.default.createElement(chip_1.Chip, { onClose: props.onClear },
|
|
22
21
|
props.filter.label,
|
|
23
|
-
":\u00A0",
|
|
24
|
-
|
|
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(", ")));
|
|
22
|
+
":\u00A0", (_a = props.value) === null || _a === void 0 ? void 0 :
|
|
23
|
+
_a.map((item) => item.label).join(", ")));
|
|
27
24
|
},
|
|
28
25
|
};
|
|
29
|
-
exports.default =
|
|
26
|
+
exports.default = filterHandler;
|
|
@@ -6,16 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const chip_1 = require("@uxf/ui/chip");
|
|
7
7
|
const select_1 = require("@uxf/ui/select");
|
|
8
8
|
const react_1 = __importDefault(require("react"));
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const filterHandler = {
|
|
10
|
+
Input(props) {
|
|
11
11
|
var _a;
|
|
12
|
-
return (react_1.default.createElement(select_1.Select, { options: (_a = props.filter.options) !== null && _a !== void 0 ? _a : [], label: props.filter.label, value: props.value
|
|
12
|
+
return (react_1.default.createElement(select_1.Select, { options: (_a = props.filter.options) !== null && _a !== void 0 ? _a : [], label: props.filter.label, value: props.value, onChange: (value) => props.onChange(value), isClearable: true, name: props.filter.name }));
|
|
13
13
|
},
|
|
14
|
-
|
|
14
|
+
ListItem(props) {
|
|
15
15
|
var _a, _b, _c;
|
|
16
16
|
return (react_1.default.createElement(chip_1.Chip, { onClose: props.onClear },
|
|
17
17
|
props.filter.label,
|
|
18
|
-
":\u00A0", (_c = (_b = (_a = props.filter.options) === null || _a === void 0 ? void 0 : _a.find((v) => v.id === props.value
|
|
18
|
+
":\u00A0", (_c = (_b = (_a = props.filter.options) === null || _a === void 0 ? void 0 : _a.find((v) => v.id === props.value)) === null || _b === void 0 ? void 0 : _b.label) !== null && _c !== void 0 ? _c : ""));
|
|
19
19
|
},
|
|
20
20
|
};
|
|
21
|
-
exports.default =
|
|
21
|
+
exports.default = filterHandler;
|
|
@@ -3,22 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const is_empty_1 = require("@uxf/core/utils/is-empty");
|
|
7
|
+
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
6
8
|
const chip_1 = require("@uxf/ui/chip");
|
|
7
9
|
const text_input_1 = require("@uxf/ui/text-input");
|
|
8
10
|
const react_1 = __importDefault(require("react"));
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
+
const filterHandler = {
|
|
12
|
+
Input(props) {
|
|
11
13
|
var _a;
|
|
12
|
-
return (react_1.default.createElement(text_input_1.TextInput, { label: props.filter.label, value: (_a = props.value
|
|
14
|
+
return (react_1.default.createElement(text_input_1.TextInput, { label: props.filter.label, value: (_a = props.value) !== null && _a !== void 0 ? _a : "", onChange: (value) => props.onChange(value), name: props.filter.name }));
|
|
13
15
|
},
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
+
ListItem(props) {
|
|
17
|
+
if ((0, is_nil_1.isNil)(props.value) || (0, is_empty_1.isEmpty)(props.value)) {
|
|
16
18
|
return null;
|
|
17
19
|
}
|
|
18
20
|
return (react_1.default.createElement(chip_1.Chip, { onClose: props.onClear },
|
|
19
21
|
props.filter.label,
|
|
20
22
|
": ",
|
|
21
|
-
props.value
|
|
23
|
+
props.value));
|
|
22
24
|
},
|
|
23
25
|
};
|
|
24
|
-
exports.default =
|
|
26
|
+
exports.default = filterHandler;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FunctionComponent } from "react";
|
|
2
2
|
import { FilterProps } from "../types/components";
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
listItem: FilterComponent<any>;
|
|
3
|
+
export type FilterComponent<StateValue> = FunctionComponent<FilterProps<StateValue>>;
|
|
4
|
+
export interface FilterHandler<StateValue> {
|
|
5
|
+
Input: FilterComponent<StateValue>;
|
|
6
|
+
ListItem: FilterComponent<StateValue>;
|
|
8
7
|
}
|
|
@@ -5,25 +5,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.FilterList = void 0;
|
|
7
7
|
const cx_1 = require("@uxf/core/utils/cx");
|
|
8
|
+
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
8
9
|
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const create_filter_component_props_1 = require("../utils/create-filter-component-props");
|
|
9
11
|
function FilterList(props) {
|
|
10
12
|
const renderedFilters = props.state.request.f
|
|
11
13
|
.map((filterRequest) => {
|
|
12
|
-
var _a;
|
|
13
|
-
if (typeof filterRequest.value !== "number" && !filterRequest.value) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
14
|
const filter = props.schema.filters.find((f) => f.name === filterRequest.name);
|
|
17
|
-
if (
|
|
15
|
+
if ((0, is_nil_1.isNil)(filter)) {
|
|
18
16
|
return null;
|
|
19
17
|
}
|
|
20
|
-
|
|
21
|
-
const FilterListItem =
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
18
|
+
const filterHandler = props.filterHandlers[filter.type];
|
|
19
|
+
const FilterListItem = filterHandler === null || filterHandler === void 0 ? void 0 : filterHandler.ListItem;
|
|
23
20
|
if (!FilterListItem) {
|
|
24
21
|
return null;
|
|
25
22
|
}
|
|
26
|
-
return (react_1.default.createElement(FilterListItem, { key: filterRequest.name,
|
|
23
|
+
return (react_1.default.createElement(FilterListItem, { key: filterRequest.name, ...(0, create_filter_component_props_1.createFilterComponentProps)(props.gridName, filter, props.state, props.actions) }));
|
|
27
24
|
})
|
|
28
25
|
.filter((item) => !!item);
|
|
29
26
|
if (renderedFilters.length === 0) {
|
package/filters/filters.js
CHANGED
|
@@ -5,21 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Filters = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const create_filter_component_props_1 = require("../utils/create-filter-component-props");
|
|
8
9
|
function Filters(props) {
|
|
9
10
|
return (react_1.default.createElement("div", { className: "uxf-data-grid__filters" }, props.schema.filters.map((filter) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const FilterInput = (_a = props.filterHandlers[filter.type]) === null || _a === void 0 ? void 0 : _a.input;
|
|
11
|
+
const filterHandler = props.filterHandlers[filter.type];
|
|
12
|
+
const FilterInput = filterHandler === null || filterHandler === void 0 ? void 0 : filterHandler.Input;
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
14
14
|
if (!FilterInput) {
|
|
15
15
|
// eslint-disable-next-line no-console
|
|
16
16
|
console.warn(`Unknown filter "${filter.type}".`);
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
|
-
return (react_1.default.createElement(FilterInput, { key: filter.name,
|
|
20
|
-
name: filter.name,
|
|
21
|
-
value: null,
|
|
22
|
-
}, onFilter: (requestFilter) => props.actions.filter(requestFilter), onClear: () => props.actions.filter({ name: filter.name, value: null }) }));
|
|
19
|
+
return (react_1.default.createElement(FilterInput, { key: filter.name, ...(0, create_filter_component_props_1.createFilterComponentProps)(props.gridName, filter, props.state, props.actions) }));
|
|
23
20
|
})));
|
|
24
21
|
}
|
|
25
22
|
exports.Filters = Filters;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/data-grid",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.15.0",
|
|
4
4
|
"description": "UXF DataGrid",
|
|
5
5
|
"homepage": "https://gitlab.com/uxf-npm/data-grid#readme",
|
|
6
6
|
"main": "index.js",
|
|
@@ -31,8 +31,10 @@
|
|
|
31
31
|
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@uxf/
|
|
34
|
+
"@uxf/core": "11.11.3",
|
|
35
|
+
"@uxf/ui": "11.15.0",
|
|
35
36
|
"dayjs": "1.11.10",
|
|
37
|
+
"deepmerge": "4.3.1",
|
|
36
38
|
"fast-glob": "3.3.2",
|
|
37
39
|
"qs": "6.11.2",
|
|
38
40
|
"react-data-grid": "7.0.0-beta.39",
|
package/styles.css
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
@import url("react-data-grid/lib/styles.css");
|
|
2
|
+
@import url("./table-v2/styles.css");
|
|
2
3
|
|
|
3
4
|
@layer rdg.Root {
|
|
4
5
|
.uxf-data-grid__table {
|
|
@@ -165,7 +166,8 @@
|
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
&__filter {
|
|
168
|
-
&--date
|
|
169
|
+
&--date,
|
|
170
|
+
&--datetime {
|
|
169
171
|
display: grid;
|
|
170
172
|
gap: theme("spacing.4");
|
|
171
173
|
grid-template-columns: repeat(2, 1fr);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Column } from "../../types";
|
|
3
|
+
import { DataGridControl } from "../../use-data-grid-control";
|
|
4
|
+
import { TableProps } from "../types";
|
|
5
|
+
export declare function useResizableColumns(columns: Column<any, any>[], actionCell: TableProps<any>["actionCell"], actions: DataGridControl["actions"]): {
|
|
6
|
+
tableRef: import("react").RefObject<HTMLDivElement>;
|
|
7
|
+
columnRefs: import("react").MutableRefObject<(HTMLDivElement | null)[]>;
|
|
8
|
+
onResizeStart(index: number): void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useResizableColumns = void 0;
|
|
4
|
+
const is_empty_1 = require("@uxf/core/utils/is-empty");
|
|
5
|
+
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
6
|
+
const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
7
|
+
const rem_1 = require("@uxf/styles/units/rem");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
function mapColumnSizesToGridTemplateColumns(columnSizes, actionCellWidth) {
|
|
10
|
+
const normalizedColumnSizes = columnSizes.map((size) => ((0, is_not_nil_1.isNotNil)(size) ? (0, rem_1.rem)(size) : "1fr"));
|
|
11
|
+
return (0, is_nil_1.isNil)(actionCellWidth)
|
|
12
|
+
? `${normalizedColumnSizes.join(" ")}`
|
|
13
|
+
: `${normalizedColumnSizes.join(" ")} ${(0, rem_1.rem)(actionCellWidth)}`;
|
|
14
|
+
}
|
|
15
|
+
function useResizableColumns(columns, actionCell, actions) {
|
|
16
|
+
const [activeIndex, setActiveIndex] = (0, react_1.useState)(null);
|
|
17
|
+
const tableRef = (0, react_1.useRef)(null);
|
|
18
|
+
const columnRefs = (0, react_1.useRef)([]);
|
|
19
|
+
const actionCellWidth = actionCell === null || actionCell === void 0 ? void 0 : actionCell.width;
|
|
20
|
+
(0, react_1.useEffect)(() => {
|
|
21
|
+
let tempColumnSizes = [];
|
|
22
|
+
const onMouseMove = (e) => {
|
|
23
|
+
const gridColumns = columns.map((_, i) => {
|
|
24
|
+
var _a, _b, _c, _d;
|
|
25
|
+
const columnRef = columnRefs.current[i];
|
|
26
|
+
if (i === activeIndex) {
|
|
27
|
+
const tableScrollLeft = (_b = (_a = tableRef.current) === null || _a === void 0 ? void 0 : _a.scrollLeft) !== null && _b !== void 0 ? _b : 0;
|
|
28
|
+
const columnOffsetLeft = (_c = columnRef === null || columnRef === void 0 ? void 0 : columnRef.offsetLeft) !== null && _c !== void 0 ? _c : 0;
|
|
29
|
+
const clickPositionX = e.clientX + tableScrollLeft;
|
|
30
|
+
const width = clickPositionX - columnOffsetLeft;
|
|
31
|
+
return width >= 50 ? width : 50;
|
|
32
|
+
}
|
|
33
|
+
return (_d = columnRef === null || columnRef === void 0 ? void 0 : columnRef.offsetWidth) !== null && _d !== void 0 ? _d : 50;
|
|
34
|
+
});
|
|
35
|
+
// TODO @vejvis - jak tohle udělat lépe??
|
|
36
|
+
tempColumnSizes = gridColumns;
|
|
37
|
+
if (tableRef.current) {
|
|
38
|
+
tableRef.current.style.gridTemplateColumns = mapColumnSizesToGridTemplateColumns(gridColumns, actionCellWidth);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const onMouseUp = () => {
|
|
42
|
+
setActiveIndex(null);
|
|
43
|
+
if (!(0, is_empty_1.isEmpty)(tempColumnSizes)) {
|
|
44
|
+
const userConfigColumns = {};
|
|
45
|
+
columns.forEach((column, index) => {
|
|
46
|
+
userConfigColumns[column.name] = { width: tempColumnSizes[index] };
|
|
47
|
+
});
|
|
48
|
+
actions.updateUserConfig({ columns: userConfigColumns });
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
if (activeIndex !== null) {
|
|
52
|
+
window.addEventListener("mousemove", onMouseMove);
|
|
53
|
+
window.addEventListener("mouseup", onMouseUp);
|
|
54
|
+
}
|
|
55
|
+
return () => {
|
|
56
|
+
window.removeEventListener("mousemove", onMouseMove);
|
|
57
|
+
window.removeEventListener("mouseup", onMouseUp);
|
|
58
|
+
};
|
|
59
|
+
}, [columns, actions, actionCellWidth, activeIndex]);
|
|
60
|
+
return {
|
|
61
|
+
tableRef,
|
|
62
|
+
columnRefs,
|
|
63
|
+
onResizeStart(index) {
|
|
64
|
+
setActiveIndex(index);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.useResizableColumns = useResizableColumns;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./table-v2";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./table-v2"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React, { FC } from "react";
|
|
2
|
+
export interface NoRowsFallbackProps {
|
|
3
|
+
error?: any;
|
|
4
|
+
loading: boolean;
|
|
5
|
+
}
|
|
6
|
+
export type NoRowsFallbackComponent = FC<NoRowsFallbackProps>;
|
|
7
|
+
export declare function NoRowsFallback(props: NoRowsFallbackProps): React.JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
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.NoRowsFallback = void 0;
|
|
7
|
+
const cx_1 = require("@uxf/core/utils/cx");
|
|
8
|
+
const icon_1 = require("@uxf/ui/icon");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
function NoRowsFallback(props) {
|
|
11
|
+
return (react_1.default.createElement("div", { className: (0, cx_1.cx)("uxf-data-grid__fallback", props.loading && "is-loading", props.error && "is-error") }, props.loading ? (react_1.default.createElement(react_1.default.Fragment, null, "Na\u010D\u00EDt\u00E1m...")) : props.error ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
12
|
+
react_1.default.createElement(icon_1.Icon, { name: "warning", size: 24 }),
|
|
13
|
+
react_1.default.createElement("p", null, "Vyskytla se chyba"))) : (react_1.default.createElement(react_1.default.Fragment, null, "\u017D\u00E1dn\u00E9 z\u00E1znamy"))));
|
|
14
|
+
}
|
|
15
|
+
exports.NoRowsFallback = NoRowsFallback;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
.uxf-data-grid__table-v2 {
|
|
2
|
+
display: grid;
|
|
3
|
+
font-size: theme("fontSize.sm");
|
|
4
|
+
overflow-x: auto;
|
|
5
|
+
width: 100%;
|
|
6
|
+
|
|
7
|
+
.uxf-data-grid__row {
|
|
8
|
+
display: contents;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.uxf-data-grid__cell {
|
|
12
|
+
align-items: center;
|
|
13
|
+
border-top: 1px solid theme("colors.lightBorder");
|
|
14
|
+
display: flex;
|
|
15
|
+
padding: 8px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.uxf-data-grid__cell-header {
|
|
19
|
+
background-color: theme("colors.neutral.50");
|
|
20
|
+
color: theme("colors.neutral.400");
|
|
21
|
+
position: relative;
|
|
22
|
+
user-select: none;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.uxf-data-grid__cell-action {
|
|
26
|
+
background-color: theme("colors.white");
|
|
27
|
+
border-left: 1px solid theme("colors.lightBorder");
|
|
28
|
+
position: sticky;
|
|
29
|
+
right: 0;
|
|
30
|
+
|
|
31
|
+
&.uxf-data-grid__cell-header {
|
|
32
|
+
background-color: theme("colors.neutral.50");
|
|
33
|
+
z-index: 2;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.uxf-data-grid__cell-resize-handle {
|
|
38
|
+
bottom: 0;
|
|
39
|
+
cursor: col-resize;
|
|
40
|
+
position: absolute;
|
|
41
|
+
right: -8px;
|
|
42
|
+
top: 0;
|
|
43
|
+
width: 16px;
|
|
44
|
+
z-index: 2;
|
|
45
|
+
|
|
46
|
+
&::before {
|
|
47
|
+
background-color: theme("colors.lightBorder");
|
|
48
|
+
bottom: 0;
|
|
49
|
+
content: "";
|
|
50
|
+
position: absolute;
|
|
51
|
+
right: 8px;
|
|
52
|
+
top: 0;
|
|
53
|
+
width: 1px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
&:hover {
|
|
57
|
+
&::before {
|
|
58
|
+
width: 2px;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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.TableV2 = void 0;
|
|
7
|
+
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
8
|
+
const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
9
|
+
const rem_1 = require("@uxf/styles/units/rem");
|
|
10
|
+
const react_1 = __importDefault(require("react"));
|
|
11
|
+
const use_resizable_columns_1 = require("./hooks/use-resizable-columns");
|
|
12
|
+
const get_grid_template_rows_1 = require("./utils/get-grid-template-rows");
|
|
13
|
+
const defaultKeyExtractor = (r) => r.id;
|
|
14
|
+
function TableV2(props) {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
16
|
+
const keyExtractor = (_a = props.keyExtractor) !== null && _a !== void 0 ? _a : defaultKeyExtractor;
|
|
17
|
+
const visibleColumns = props.schema.columns.filter((column) => { var _a, _b; return !((_b = (_a = props.state.userConfig.columns) === null || _a === void 0 ? void 0 : _a[column.name]) === null || _b === void 0 ? void 0 : _b.isHidden); });
|
|
18
|
+
const { tableRef, columnRefs, onResizeStart } = (0, use_resizable_columns_1.useResizableColumns)(visibleColumns, props.actionCell, props.actions);
|
|
19
|
+
const gridTemplateRows = (0, get_grid_template_rows_1.getGridTemplateRows)(props.data, (_b = props.headerRowHeight) !== null && _b !== void 0 ? _b : 36, (_c = props.rowHeight) !== null && _c !== void 0 ? _c : 44);
|
|
20
|
+
const gridTemplateColumnsWithoutAction = visibleColumns
|
|
21
|
+
.map((column) => { var _a, _b, _c, _d; return (_c = (_b = (_a = props.state.userConfig.columns) === null || _a === void 0 ? void 0 : _a[column.name]) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : (_d = column.config) === null || _d === void 0 ? void 0 : _d.width; })
|
|
22
|
+
.map((width) => ((0, is_nil_1.isNil)(width) ? "1fr" : (0, rem_1.rem)(width)))
|
|
23
|
+
.join(" ");
|
|
24
|
+
const gridTemplateColumns = (0, is_nil_1.isNil)((_d = props.actionCell) === null || _d === void 0 ? void 0 : _d.width)
|
|
25
|
+
? gridTemplateColumnsWithoutAction
|
|
26
|
+
: `${gridTemplateColumnsWithoutAction} ${(0, rem_1.rem)(props.actionCell.width)}`;
|
|
27
|
+
return (react_1.default.createElement("div", { className: "uxf-data-grid__table-v2", ref: tableRef, style: { gridTemplateColumns, gridTemplateRows } },
|
|
28
|
+
react_1.default.createElement("div", { className: "uxf-data-grid__row" },
|
|
29
|
+
visibleColumns.map((column, index) => (react_1.default.createElement("div", { key: column.name, className: "uxf-data-grid__cell uxf-data-grid__cell-header", ref: (el) => (columnRefs.current[index] = el) },
|
|
30
|
+
column.label,
|
|
31
|
+
react_1.default.createElement("div", { className: "uxf-data-grid__cell-resize-handle", onMouseDown: () => onResizeStart(index) })))),
|
|
32
|
+
(0, is_not_nil_1.isNotNil)(props.actionCell) && (react_1.default.createElement("div", { className: "uxf-data-grid__cell uxf-data-grid__cell-header uxf-data-grid__cell-action" }))),
|
|
33
|
+
props.data.map((row) => (react_1.default.createElement("div", { className: "uxf-data-grid__row", key: keyExtractor(row) },
|
|
34
|
+
visibleColumns.map((column) => {
|
|
35
|
+
var _a, _b, _c;
|
|
36
|
+
const BodyCell = (_b = (_a = props.bodyCells) === null || _a === void 0 ? void 0 : _a[column.type]) !== null && _b !== void 0 ? _b : (_c = props.bodyCells) === null || _c === void 0 ? void 0 : _c.default;
|
|
37
|
+
if (!BodyCell) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return (react_1.default.createElement("div", { className: "uxf-data-grid__cell", key: column.name },
|
|
41
|
+
react_1.default.createElement(BodyCell, { column: column, row: row, value: row[column.name], reload: () => { var _a; return (_a = props.onReload) === null || _a === void 0 ? void 0 : _a.call(props); } })));
|
|
42
|
+
}),
|
|
43
|
+
(0, is_not_nil_1.isNotNil)(props.actionCell) && (react_1.default.createElement("div", { className: "uxf-data-grid__cell uxf-data-grid__cell-action" },
|
|
44
|
+
react_1.default.createElement(props.actionCell.Component, { row: row, reload: () => { var _a; return (_a = props.onReload) === null || _a === void 0 ? void 0 : _a.call(props); } }))))))));
|
|
45
|
+
}
|
|
46
|
+
exports.TableV2 = TableV2;
|
|
@@ -0,0 +1,22 @@
|
|
|
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.Default = void 0;
|
|
7
|
+
const json_renderer_1 = require("@uxf/example/src/components/json-renderer");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const data_1 = require("../_story-utils/data");
|
|
10
|
+
const schema_1 = require("../_story-utils/schema");
|
|
11
|
+
const body_cell_1 = require("../body-cell");
|
|
12
|
+
const hidden_columns_button_1 = require("../hidden-columns-button");
|
|
13
|
+
const use_data_grid_control_1 = require("../use-data-grid-control");
|
|
14
|
+
const table_v2_1 = require("./table-v2");
|
|
15
|
+
function Default() {
|
|
16
|
+
const { state, actions } = (0, use_data_grid_control_1.useDataGridControl)({ schema: schema_1.schema });
|
|
17
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
18
|
+
react_1.default.createElement(hidden_columns_button_1.HiddenColumnsButton, { schema: schema_1.schema, state: state, actions: actions }),
|
|
19
|
+
react_1.default.createElement(table_v2_1.TableV2, { state: state, actions: actions, data: data_1.data, isLoading: true, error: undefined, schema: schema_1.schema, bodyCells: body_cell_1.BodyCells, isRowSelectable: true, actionCell: { width: 150, Component: () => react_1.default.createElement("div", null, "ActionCell") } }),
|
|
20
|
+
react_1.default.createElement(json_renderer_1.JsonRenderer, { value: state })));
|
|
21
|
+
}
|
|
22
|
+
exports.Default = Default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Nullish } from "@uxf/core/types";
|
|
2
|
+
import { ActionCellComponent, BodyCellComponents } from "../types/components";
|
|
3
|
+
import { KeyExtractor } from "../types/core";
|
|
4
|
+
import { Schema } from "../types/schema";
|
|
5
|
+
import { DataGridControl } from "../use-data-grid-control";
|
|
6
|
+
import { NoRowsFallbackComponent } from "./no-rows-fallback";
|
|
7
|
+
export interface TableProps<Row> extends DataGridControl {
|
|
8
|
+
schema: Schema<any>;
|
|
9
|
+
data: Row[];
|
|
10
|
+
isLoading?: boolean;
|
|
11
|
+
error?: any | Nullish;
|
|
12
|
+
onReload?: () => void;
|
|
13
|
+
rowHeight?: number | ((row: Row) => number) | "auto";
|
|
14
|
+
headerRowHeight?: number;
|
|
15
|
+
rowClass?: (row: Row) => "success" | "warning" | "error" | "primary" | "secondary" | string | null | undefined;
|
|
16
|
+
keyExtractor?: KeyExtractor;
|
|
17
|
+
bodyCells?: BodyCellComponents<any, any>;
|
|
18
|
+
actionCell?: {
|
|
19
|
+
width: number;
|
|
20
|
+
Component: ActionCellComponent<any>;
|
|
21
|
+
};
|
|
22
|
+
NoRowsFallback?: NoRowsFallbackComponent;
|
|
23
|
+
isRowSelectable?: boolean;
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGridTemplateRows = void 0;
|
|
4
|
+
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
5
|
+
const rem_1 = require("@uxf/styles/units/rem");
|
|
6
|
+
function getGridTemplateRows(rows, headerRowHeight, rowHeight) {
|
|
7
|
+
if (rowHeight === "auto" || (0, is_nil_1.isNil)(rowHeight)) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
if (typeof rowHeight === "number") {
|
|
11
|
+
return `${(0, rem_1.rem)(headerRowHeight)} repeat(${rows.length}, ${(0, rem_1.rem)(rowHeight)})`;
|
|
12
|
+
}
|
|
13
|
+
return `${headerRowHeight} ${rows.map(rowHeight).join(" ")}`;
|
|
14
|
+
}
|
|
15
|
+
exports.getGridTemplateRows = getGridTemplateRows;
|
package/types/api.d.ts
CHANGED
package/types/components.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ComponentType, FC } from "react";
|
|
2
|
-
import { RequestFilter } from "./api";
|
|
3
2
|
import { BaseGridType, Columns, Filter } from "./schema";
|
|
4
3
|
export interface ActionCellProps<R> {
|
|
5
4
|
row: R;
|
|
@@ -17,10 +16,11 @@ export type BodyCellComponents<C, R> = {
|
|
|
17
16
|
[key: string]: BodyCellComponent<C, R>;
|
|
18
17
|
default: BodyCellComponent<C, R>;
|
|
19
18
|
};
|
|
20
|
-
export interface FilterProps<
|
|
19
|
+
export interface FilterProps<StateValue> {
|
|
21
20
|
gridName?: string;
|
|
22
|
-
filter:
|
|
23
|
-
value:
|
|
24
|
-
|
|
21
|
+
filter: Filter;
|
|
22
|
+
value: StateValue;
|
|
23
|
+
op?: string;
|
|
24
|
+
onChange: (value: StateValue | undefined, op?: string) => void;
|
|
25
25
|
onClear: () => void;
|
|
26
26
|
}
|
package/types/schema.d.ts
CHANGED
|
@@ -37,19 +37,17 @@ export interface FilterOption {
|
|
|
37
37
|
id: string | number;
|
|
38
38
|
label: string;
|
|
39
39
|
}
|
|
40
|
-
export interface Filter
|
|
41
|
-
name:
|
|
40
|
+
export interface Filter {
|
|
41
|
+
name: string;
|
|
42
42
|
label: string;
|
|
43
|
-
type
|
|
43
|
+
type: string;
|
|
44
44
|
options?: FilterOption[];
|
|
45
|
+
autocomplete?: string | null;
|
|
45
46
|
}
|
|
46
|
-
export type Filters<F extends BaseGridType["filters"]> = {
|
|
47
|
-
[K in keyof F]: Filter<K, F[K]>;
|
|
48
|
-
}[keyof F];
|
|
49
47
|
export interface Schema<GritType extends BaseGridType> {
|
|
50
48
|
name?: string;
|
|
51
49
|
columns: Columns<GritType["columns"]>[];
|
|
52
|
-
filters:
|
|
50
|
+
filters: Filter[];
|
|
53
51
|
tabs?: Tab[];
|
|
54
52
|
s: DataGridSort;
|
|
55
53
|
perPage: number;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Dispatch } from "react";
|
|
2
|
-
import { RequestFilter } from "../types/api";
|
|
3
2
|
import { Tab } from "../types/schema";
|
|
3
|
+
import { DataGridUserConfig } from "../types/state";
|
|
4
4
|
export declare function createActions(dispatch: Dispatch<any>): {
|
|
5
5
|
changePage: (page: number) => void;
|
|
6
6
|
changePerPage: (perPage: number) => void;
|
|
7
|
-
filter: (
|
|
7
|
+
filter: (name: string, value: any, op?: string) => void;
|
|
8
|
+
filterClear: (name: string) => void;
|
|
8
9
|
sort: (columnName: string, direction: string) => void;
|
|
9
10
|
sortClear: () => void;
|
|
10
11
|
search: (search: string) => void;
|
|
@@ -12,4 +13,5 @@ export declare function createActions(dispatch: Dispatch<any>): {
|
|
|
12
13
|
setSelectedRows: (rows: any[]) => void;
|
|
13
14
|
hideColumn: (name: string) => void;
|
|
14
15
|
showColumn: (name: string) => void;
|
|
16
|
+
updateUserConfig: (userConfig: DataGridUserConfig<any>) => void;
|
|
15
17
|
};
|