@uxf/data-grid 11.92.3 → 11.93.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/_store/reducer.js +8 -0
- package/data-grid-v2.js +1 -1
- package/data-grid-v2.stories.js +8 -1
- package/data-grid.js +1 -1
- package/hidden-columns/column-item.d.ts +10 -0
- package/hidden-columns/column-item.js +26 -0
- package/hidden-columns/drop-placeholder.d.ts +7 -0
- package/hidden-columns/drop-placeholder.js +21 -0
- package/hidden-columns/hidden-columns-sortable.d.ts +3 -0
- package/hidden-columns/hidden-columns-sortable.js +166 -0
- package/hidden-columns/hidden-columns.d.ts +2 -7
- package/hidden-columns/hidden-columns.stories.d.ts +1 -0
- package/hidden-columns/hidden-columns.stories.js +8 -0
- package/hidden-columns/index.d.ts +1 -0
- package/hidden-columns/index.js +1 -0
- package/hidden-columns/types.d.ts +14 -0
- package/hidden-columns/types.js +5 -0
- package/hidden-columns-button/hidden-columns-button.d.ts +2 -0
- package/hidden-columns-button/hidden-columns-button.js +5 -4
- package/hidden-columns-button/hidden-columns-button.stories.js +5 -1
- package/icons-config.js +5 -0
- package/icons.d.ts +1 -0
- package/package.json +9 -4
- package/styles.css +32 -3
- package/table-v2/components/header-cell.d.ts +1 -0
- package/table-v2/components/header-cell.js +5 -1
- package/table-v2/hooks/use-resizable-columns.d.ts +1 -0
- package/table-v2/hooks/use-resizable-columns.js +40 -0
- package/table-v2/table-v2.js +7 -3
- package/toolbar-control/toolbar-control.d.ts +4 -2
- package/toolbar-control/toolbar-control.js +1 -1
- package/translations/cs.json +3 -1
- package/translations/de.json +3 -1
- package/translations/en.json +3 -1
- package/translations/sk.json +3 -1
- package/translations/translations.d.ts +12 -0
- package/translations/translations.js +12 -0
- package/types/data-grid-props.d.ts +3 -0
- package/types/state.d.ts +1 -0
- package/use-data-grid-control/action.d.ts +3 -0
- package/use-data-grid-control/action.js +1 -0
- package/use-data-grid-control/actions-factory.d.ts +1 -0
- package/use-data-grid-control/actions-factory.js +1 -0
- package/use-data-grid-control/use-data-grid-control.d.ts +1 -0
- package/user-config-storage-adapters/local-storage.d.ts +1 -0
- package/user-config-storage-adapters/local-storage.js +8 -0
package/_store/reducer.js
CHANGED
|
@@ -186,6 +186,14 @@ const reducer = (state, action) => {
|
|
|
186
186
|
},
|
|
187
187
|
},
|
|
188
188
|
};
|
|
189
|
+
case "SET_COLUMNS_ORDER":
|
|
190
|
+
return {
|
|
191
|
+
...state,
|
|
192
|
+
userConfig: {
|
|
193
|
+
...state.userConfig,
|
|
194
|
+
columnsOrder: action.columns,
|
|
195
|
+
},
|
|
196
|
+
};
|
|
189
197
|
case "UPDATE_USER_CONFIG":
|
|
190
198
|
return {
|
|
191
199
|
...state,
|
package/data-grid-v2.js
CHANGED
|
@@ -29,7 +29,7 @@ function DataGridV2(props) {
|
|
|
29
29
|
react_1.default.createElement(root_1.DataGridRoot, { className: props.className },
|
|
30
30
|
react_1.default.createElement(toolbar_1.DataGridToolbar, null,
|
|
31
31
|
react_1.default.createElement(toolbar_tabs_1.DataGridToolbarTabs, { actions: props.actions, changeTabFilterBehavior: props.changeTabFilterBehavior, schema: props.schema, state: props.state, variant: props.tabsVariant }),
|
|
32
|
-
react_1.default.createElement(toolbar_control_1.DataGridToolbarControl, { actions: props.actions, filterHandlers: (_a = props.filterHandlers) !== null && _a !== void 0 ? _a : filter_handler_1.defaultFilterHandlers, getCsvDownloadUrl: props.getCsvDownloadUrl, schema: props.schema, state: props.state }),
|
|
32
|
+
react_1.default.createElement(toolbar_control_1.DataGridToolbarControl, { HiddenColumnsComponent: props.HiddenColumnsComponent, actions: props.actions, filterHandlers: (_a = props.filterHandlers) !== null && _a !== void 0 ? _a : filter_handler_1.defaultFilterHandlers, getCsvDownloadUrl: props.getCsvDownloadUrl, schema: props.schema, state: props.state }),
|
|
33
33
|
react_1.default.createElement(toolbar_customs_1.DataGridToolbarCustoms, { buttons: props.customActions })),
|
|
34
34
|
react_1.default.createElement(linear_progress_1.DataGridLinearProgress, { isLoading: props.isLoading }),
|
|
35
35
|
react_1.default.createElement(filter_list_1.DataGridFilterList, { actions: props.actions, filterHandlers: (_b = props.filterHandlers) !== null && _b !== void 0 ? _b : filter_handler_1.defaultFilterHandlers, schema: props.schema, state: props.state }),
|
package/data-grid-v2.stories.js
CHANGED
|
@@ -89,8 +89,13 @@ const FILTER_BEHAVIOR_OPTIONS = [
|
|
|
89
89
|
{ id: "sharedFiltersAndSearch", label: "sharedFiltersAndSearch" },
|
|
90
90
|
{ id: "sharedFiltersAndSearchAndSort", label: "sharedFiltersAndSearchAndSort" },
|
|
91
91
|
];
|
|
92
|
+
const HIDDEN_COLUMNS_SORTABLE_OPTIONS = [
|
|
93
|
+
{ id: "default", label: "Vypnuto" },
|
|
94
|
+
{ id: "sortable", label: "Zapnuto" },
|
|
95
|
+
];
|
|
92
96
|
function Default() {
|
|
93
97
|
const [filterBehavior, setFilterBehavior] = (0, react_1.useState)("filtersPerTab");
|
|
98
|
+
const [hiddenColumnsBehavior, setHiddenColumnsBehavior] = (0, react_1.useState)("default");
|
|
94
99
|
const { middleware, useUserConfig } = (0, local_storage_1.useUserConfigLocalStorageAdapter)(schema_1.schema);
|
|
95
100
|
const { state, actions } = (0, use_data_grid_control_1.useDataGridControl)({
|
|
96
101
|
schema: schema_1.schema,
|
|
@@ -102,8 +107,10 @@ function Default() {
|
|
|
102
107
|
schema: schema_1.schema,
|
|
103
108
|
state,
|
|
104
109
|
});
|
|
110
|
+
const clearLocalStorageUserConfig = (0, local_storage_1.useClearLocalStorageUserConfig)(schema_1.schema);
|
|
105
111
|
return (react_1.default.createElement("div", { className: "p-10" },
|
|
106
112
|
react_1.default.createElement(radio_group_1.RadioGroup, { label: "Chov\u00E1n\u00ED p\u0159ep\u00EDn\u00E1n\u00ED tab\u016F", name: "filterBehavior", onChange: (value) => setFilterBehavior(value), options: FILTER_BEHAVIOR_OPTIONS, value: filterBehavior, variant: "row" }),
|
|
107
|
-
react_1.default.createElement(
|
|
113
|
+
react_1.default.createElement(radio_group_1.RadioGroup, { className: "mb-2 mt-4", label: "\u0158azen\u00ED sloupc\u016F (Drag&Drop)", name: "hiddenColumnsSortable", onChange: (value) => setHiddenColumnsBehavior(value), options: HIDDEN_COLUMNS_SORTABLE_OPTIONS, value: hiddenColumnsBehavior, variant: "row" }),
|
|
114
|
+
react_1.default.createElement(data_grid_v2_1.DataGridV2, { actionCell: actionCell, actions: actions, changeTabFilterBehavior: filterBehavior !== null && filterBehavior !== void 0 ? filterBehavior : "filtersPerTab", customActions: [{ onClick: clearLocalStorageUserConfig, label: "Smazat user config" }], data: data, error: error, getCsvDownloadUrl: () => ``, isHiddenColumnsSortable: hiddenColumnsBehavior === "sortable", isLoading: isLoading, isRowSelectDisabled: (row) => row.id === 6, isRowsSelectable: true, reload: reload, rowAccent: (row) => (row.id === 2 ? "success" : undefined), rowClassName: (row) => (row.id === 3 ? "some-custom-classname" : undefined), rowHeight: "auto", schema: schemaWithFrontendConfig, state: state, tabsVariant: "segmented" }),
|
|
108
115
|
react_1.default.createElement(json_renderer_1.JsonRenderer, { value: state })));
|
|
109
116
|
}
|
package/data-grid.js
CHANGED
|
@@ -28,7 +28,7 @@ function DataGrid(props) {
|
|
|
28
28
|
react_1.default.createElement(root_1.DataGridRoot, { className: props.className },
|
|
29
29
|
react_1.default.createElement(toolbar_1.DataGridToolbar, null,
|
|
30
30
|
react_1.default.createElement(toolbar_tabs_1.DataGridToolbarTabs, { actions: props.actions, changeTabFilterBehavior: props.changeTabFilterBehavior, schema: props.schema, state: props.state, variant: props.tabsVariant }),
|
|
31
|
-
react_1.default.createElement(toolbar_control_1.DataGridToolbarControl, { actions: props.actions, filterHandlers: (_a = props.filterHandlers) !== null && _a !== void 0 ? _a : filter_handler_1.defaultFilterHandlers, getCsvDownloadUrl: props.getCsvDownloadUrl, schema: props.schema, state: props.state }),
|
|
31
|
+
react_1.default.createElement(toolbar_control_1.DataGridToolbarControl, { HiddenColumnsComponent: props.HiddenColumnsComponent, actions: props.actions, filterHandlers: (_a = props.filterHandlers) !== null && _a !== void 0 ? _a : filter_handler_1.defaultFilterHandlers, getCsvDownloadUrl: props.getCsvDownloadUrl, schema: props.schema, state: props.state }),
|
|
32
32
|
react_1.default.createElement(toolbar_customs_1.DataGridToolbarCustoms, { buttons: props.customActions })),
|
|
33
33
|
react_1.default.createElement(linear_progress_1.DataGridLinearProgress, { isLoading: props.isLoading }),
|
|
34
34
|
react_1.default.createElement(filter_list_1.DataGridFilterList, { actions: props.actions, filterHandlers: (_b = props.filterHandlers) !== null && _b !== void 0 ? _b : filter_handler_1.defaultFilterHandlers, schema: props.schema, state: props.state }),
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ColumnWithId } from "./types";
|
|
3
|
+
interface DataGridColumnsItemProps {
|
|
4
|
+
column: ColumnWithId;
|
|
5
|
+
isChecked: boolean;
|
|
6
|
+
id: string;
|
|
7
|
+
onToggle: (id: string, value: boolean) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function ColumnItem(props: DataGridColumnsItemProps): React.JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
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.ColumnItem = ColumnItem;
|
|
7
|
+
const sortable_1 = require("@dnd-kit/sortable");
|
|
8
|
+
const utilities_1 = require("@dnd-kit/utilities");
|
|
9
|
+
const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
10
|
+
const icon_1 = require("@uxf/ui/icon");
|
|
11
|
+
const toggle_1 = require("@uxf/ui/toggle");
|
|
12
|
+
const react_1 = __importDefault(require("react"));
|
|
13
|
+
function ColumnItem(props) {
|
|
14
|
+
const { attributes, listeners, isDragging, transform, transition, setNodeRef } = (0, sortable_1.useSortable)({
|
|
15
|
+
id: props.id,
|
|
16
|
+
});
|
|
17
|
+
const style = {
|
|
18
|
+
opacity: isDragging ? 0.4 : undefined,
|
|
19
|
+
transform: utilities_1.CSS.Translate.toString(transform),
|
|
20
|
+
transition,
|
|
21
|
+
};
|
|
22
|
+
return (react_1.default.createElement("div", { className: "uxf-data-grid__hidden-columns-column-item", id: props.id, ref: setNodeRef, style: style },
|
|
23
|
+
react_1.default.createElement("button", { type: "button", ...attributes, ...listeners },
|
|
24
|
+
react_1.default.createElement(icon_1.Icon, { name: "grip-dots-vertical", size: 20 })),
|
|
25
|
+
react_1.default.createElement(toggle_1.Toggle, { key: props.column.name, label: typeof props.column.label === "string" ? props.column.label : "", name: props.column.name, onChange: (value) => ((0, is_not_nil_1.isNotNil)(value) ? props.onToggle(props.column.name, value) : void null), size: "sm", value: props.isChecked, variant: "reversed" })));
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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.DropPlaceholder = DropPlaceholder;
|
|
7
|
+
const sortable_1 = require("@dnd-kit/sortable");
|
|
8
|
+
const utilities_1 = require("@dnd-kit/utilities");
|
|
9
|
+
const translations_1 = require("@uxf/core-react/translations");
|
|
10
|
+
const cx_1 = require("@uxf/core/utils/cx");
|
|
11
|
+
const react_1 = __importDefault(require("react"));
|
|
12
|
+
function DropPlaceholder(props) {
|
|
13
|
+
const t = (0, translations_1.useUxfTranslation)();
|
|
14
|
+
const { setNodeRef, transform, transition, isOver } = (0, sortable_1.useSortable)({ id: props.id });
|
|
15
|
+
return (react_1.default.createElement("div", { className: (0, cx_1.cx)("uxf-data-grid__hidden-columns-drop-placeholder", isOver && "uxf-data-grid__hidden-columns-drop-placeholder--over"), ref: setNodeRef, style: {
|
|
16
|
+
transform: utilities_1.CSS.Translate.toString(transform),
|
|
17
|
+
transition,
|
|
18
|
+
} }, props.type === "hidden"
|
|
19
|
+
? t("uxf-data-grid-hidden-columns:drag-columns-hide")
|
|
20
|
+
: t("uxf-data-grid-hidden-columns:drag-columns-show")));
|
|
21
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.DataGridHiddenColumnsSortable = DataGridHiddenColumnsSortable;
|
|
38
|
+
const core_1 = require("@dnd-kit/core");
|
|
39
|
+
const sortable_1 = require("@dnd-kit/sortable");
|
|
40
|
+
const show_1 = require("@uxf/core-react/components/show");
|
|
41
|
+
const use_sortable_multi_1 = require("@uxf/core-react/dnd/hooks/use-sortable-multi");
|
|
42
|
+
const translations_1 = require("@uxf/core-react/translations");
|
|
43
|
+
const is_empty_1 = require("@uxf/core/utils/is-empty");
|
|
44
|
+
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
45
|
+
const is_not_empty_1 = require("@uxf/core/utils/is-not-empty");
|
|
46
|
+
const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
47
|
+
const icon_1 = require("@uxf/ui/icon");
|
|
48
|
+
const text_link_1 = require("@uxf/ui/text-link");
|
|
49
|
+
const react_1 = __importStar(require("react"));
|
|
50
|
+
const column_item_1 = require("./column-item");
|
|
51
|
+
const drop_placeholder_1 = require("./drop-placeholder");
|
|
52
|
+
const types_1 = require("./types");
|
|
53
|
+
function DataGridHiddenColumnsSortable(props) {
|
|
54
|
+
const t = (0, translations_1.useUxfTranslation)();
|
|
55
|
+
const columnsWithId = (0, react_1.useMemo)(() => props.schema.columns.filter((c) => !c.hidden).map((c) => ({ ...c, id: c.name })), [props.schema.columns]);
|
|
56
|
+
// Sort columns according to columnsOrder if it exists
|
|
57
|
+
const sortedColumnsWithId = (0, react_1.useMemo)(() => {
|
|
58
|
+
if (!props.state.userConfig.columnsOrder) {
|
|
59
|
+
return columnsWithId;
|
|
60
|
+
}
|
|
61
|
+
return [...columnsWithId].sort((a, b) => {
|
|
62
|
+
const aIndex = props.state.userConfig.columnsOrder.indexOf(a.name);
|
|
63
|
+
const bIndex = props.state.userConfig.columnsOrder.indexOf(b.name);
|
|
64
|
+
// If both columns are in the order array, sort by their position
|
|
65
|
+
if (aIndex !== -1 && bIndex !== -1) {
|
|
66
|
+
return aIndex - bIndex;
|
|
67
|
+
}
|
|
68
|
+
// If only one column is in the order array, prioritize it
|
|
69
|
+
if (aIndex !== -1) {
|
|
70
|
+
return -1;
|
|
71
|
+
}
|
|
72
|
+
if (bIndex !== -1) {
|
|
73
|
+
return 1;
|
|
74
|
+
}
|
|
75
|
+
// If neither is in the order array, maintain original order
|
|
76
|
+
return 0;
|
|
77
|
+
});
|
|
78
|
+
}, [columnsWithId, props.state.userConfig.columnsOrder]);
|
|
79
|
+
const visibleColumns = (0, react_1.useMemo)(() => sortedColumnsWithId.filter((c) => { var _a, _b, _c, _d; return !((_c = (_b = (_a = props.state.userConfig.columns) === null || _a === void 0 ? void 0 : _a[c.name]) === null || _b === void 0 ? void 0 : _b.isHidden) !== null && _c !== void 0 ? _c : (_d = c.config) === null || _d === void 0 ? void 0 : _d.isHidden); }), [sortedColumnsWithId, props.state.userConfig.columns]);
|
|
80
|
+
const hiddenColumns = (0, react_1.useMemo)(() => sortedColumnsWithId.filter((c) => { var _a, _b, _c, _d; return (_c = (_b = (_a = props.state.userConfig.columns) === null || _a === void 0 ? void 0 : _a[c.name]) === null || _b === void 0 ? void 0 : _b.isHidden) !== null && _c !== void 0 ? _c : (_d = c.config) === null || _d === void 0 ? void 0 : _d.isHidden; }), [sortedColumnsWithId, props.state.userConfig.columns]);
|
|
81
|
+
const [sections, setSections] = (0, react_1.useState)({
|
|
82
|
+
visible: visibleColumns,
|
|
83
|
+
hidden: hiddenColumns,
|
|
84
|
+
});
|
|
85
|
+
// Sync sections when visible/hidden columns change (e.g., after refresh when userConfig loads)
|
|
86
|
+
(0, react_1.useEffect)(() => {
|
|
87
|
+
setSections({
|
|
88
|
+
visible: visibleColumns,
|
|
89
|
+
hidden: hiddenColumns,
|
|
90
|
+
});
|
|
91
|
+
}, [visibleColumns, hiddenColumns]);
|
|
92
|
+
const onChangeAll = (value) => () => {
|
|
93
|
+
const allColumns = [...sections.visible, ...sections.hidden];
|
|
94
|
+
setSections({
|
|
95
|
+
visible: value ? allColumns : [],
|
|
96
|
+
hidden: !value ? allColumns : [],
|
|
97
|
+
});
|
|
98
|
+
// update all columns visibility in a single action to avoid multiple action calls
|
|
99
|
+
const newUserConfigColumns = {}; // TODO finalize typing after merging https://gitlab.uxf.cz/uxf/npm-packages/fe-monorepo/-/merge_requests/720
|
|
100
|
+
allColumns.forEach((column) => {
|
|
101
|
+
newUserConfigColumns[column.name] = { isHidden: !value };
|
|
102
|
+
});
|
|
103
|
+
props.actions.updateUserConfig({ columns: newUserConfigColumns });
|
|
104
|
+
};
|
|
105
|
+
const { getSectionItemsIds, activeItem, onDragStart, onDragEnd, onDragCancel, sensors, dropAnimationConfig } = (0, use_sortable_multi_1.useSortableMulti)(sections, setSections, (fromSection, toSection, fromIndex, toIndex, nextState) => {
|
|
106
|
+
const movedItem = nextState[toSection][toIndex];
|
|
107
|
+
const isNowVisible = toSection === "visible";
|
|
108
|
+
props.actions[isNowVisible ? "showColumn" : "hideColumn"](movedItem.name);
|
|
109
|
+
props.actions.setColumnsOrder(nextState.visible.map((c) => c.name));
|
|
110
|
+
});
|
|
111
|
+
const handleToggle = (0, react_1.useCallback)((id, isVisible) => {
|
|
112
|
+
const fromKey = isVisible ? "hidden" : "visible";
|
|
113
|
+
const toKey = isVisible ? "visible" : "hidden";
|
|
114
|
+
let newVisibleOrder = [];
|
|
115
|
+
setSections((prev) => {
|
|
116
|
+
const column = [...prev[fromKey]].find((c) => c.id === id);
|
|
117
|
+
if (!column) {
|
|
118
|
+
return prev;
|
|
119
|
+
}
|
|
120
|
+
const from = prev[fromKey].filter((c) => c.id !== id);
|
|
121
|
+
// When making visible, insert at proper position based on original order
|
|
122
|
+
let to;
|
|
123
|
+
if (isVisible) {
|
|
124
|
+
// Find the correct position based on sortedColumnsWithId order
|
|
125
|
+
const allColumnsInOrder = sortedColumnsWithId;
|
|
126
|
+
const targetIndex = allColumnsInOrder.findIndex((c) => c.id === id);
|
|
127
|
+
// Find insertion position in the 'to' array
|
|
128
|
+
let insertIndex = 0;
|
|
129
|
+
for (let i = 0; i < prev[toKey].length; i++) {
|
|
130
|
+
const currentColIndex = allColumnsInOrder.findIndex((c) => c.id === prev[toKey][i].id);
|
|
131
|
+
if (currentColIndex < targetIndex) {
|
|
132
|
+
insertIndex = i + 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
to = [...prev[toKey]];
|
|
136
|
+
to.splice(insertIndex, 0, column);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
// When hiding, just append to the end of hidden columns
|
|
140
|
+
to = [...prev[toKey], column];
|
|
141
|
+
}
|
|
142
|
+
const result = { ...prev, [fromKey]: from, [toKey]: to };
|
|
143
|
+
// Store the new visible order to update after setState
|
|
144
|
+
newVisibleOrder = result.visible.map((c) => c.name);
|
|
145
|
+
return result;
|
|
146
|
+
});
|
|
147
|
+
props.actions.setColumnsOrder(newVisibleOrder);
|
|
148
|
+
props.actions[isVisible ? "showColumn" : "hideColumn"](id);
|
|
149
|
+
}, [props.actions, sortedColumnsWithId]);
|
|
150
|
+
return (react_1.default.createElement("div", { className: "uxf-data-grid__toolbar-control-columns" },
|
|
151
|
+
react_1.default.createElement(core_1.DndContext, { collisionDetection: core_1.rectIntersection, onDragCancel: onDragCancel, onDragEnd: onDragEnd, onDragStart: onDragStart, sensors: sensors },
|
|
152
|
+
react_1.default.createElement("div", { className: "uxf-data-grid__hidden-columns-title" },
|
|
153
|
+
react_1.default.createElement("div", { className: "uxf-data-grid__hidden-columns-title-text" }, t("uxf-data-grid-hidden-columns:visible-columns")),
|
|
154
|
+
react_1.default.createElement(text_link_1.TextLink, { isDisabled: (0, is_empty_1.isEmpty)(sections.visible), onClick: onChangeAll(false), variant: "text" }, t("uxf-data-grid-hidden-columns:hide-all"))),
|
|
155
|
+
react_1.default.createElement(show_1.Show, { when: (0, is_empty_1.isEmpty)(sections.visible) },
|
|
156
|
+
react_1.default.createElement("div", { className: "uxf-data-grid__hidden-columns-empty-box" },
|
|
157
|
+
react_1.default.createElement(icon_1.Icon, { name: "triangle-exclamation-solid", size: 20 }),
|
|
158
|
+
t("uxf-data-grid-hidden-columns:empty-message"))),
|
|
159
|
+
react_1.default.createElement(sortable_1.SortableContext, { items: getSectionItemsIds("visible"), strategy: sortable_1.verticalListSortingStrategy }, (0, is_empty_1.isEmpty)(sections.visible) ? (react_1.default.createElement(drop_placeholder_1.DropPlaceholder, { id: types_1.EMPTY_VISIBLE_COLUMNS_PLACEHOLDER_ID, type: "visible" })) : (sections.visible.map((column) => (react_1.default.createElement(column_item_1.ColumnItem, { column: column, id: column.id, isChecked: true, key: `visible-${column.id}`, onToggle: handleToggle }))))),
|
|
160
|
+
react_1.default.createElement(show_1.Show, { when: (0, is_not_empty_1.isNotEmpty)(sections.hidden) || (0, is_not_nil_1.isNotNil)(activeItem) },
|
|
161
|
+
react_1.default.createElement("div", { className: "uxf-data-grid__hidden-columns-title" },
|
|
162
|
+
react_1.default.createElement("div", { className: "uxf-data-grid__hidden-columns-title-text" }, t("uxf-data-grid-hidden-columns:hidden-columns")),
|
|
163
|
+
((0, is_nil_1.isNil)(activeItem) || (0, is_not_empty_1.isNotEmpty)(sections.hidden)) && (react_1.default.createElement(text_link_1.TextLink, { onClick: onChangeAll(true), variant: "text" }, t("uxf-data-grid-hidden-columns:show-all")))),
|
|
164
|
+
(0, is_empty_1.isEmpty)(sections.hidden) ? (react_1.default.createElement(drop_placeholder_1.DropPlaceholder, { id: types_1.EMPTY_HIDDEN_COLUMNS_PLACEHOLDER_ID, type: "hidden" })) : (sections.hidden.map((column) => (react_1.default.createElement(column_item_1.ColumnItem, { column: column, id: column.id, isChecked: false, key: `hidden-${column.id}`, onToggle: handleToggle }))))),
|
|
165
|
+
react_1.default.createElement(core_1.DragOverlay, { dropAnimation: dropAnimationConfig }, (0, is_not_nil_1.isNotNil)(activeItem) ? (react_1.default.createElement(column_item_1.ColumnItem, { column: activeItem, id: activeItem.id, isChecked: Boolean(sections.visible.find((c) => c.name === activeItem.name)), onToggle: () => void null })) : null))));
|
|
166
|
+
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
3
|
-
import { DataGridControl } from "../use-data-grid-control";
|
|
4
|
-
export interface DataGridHiddenColumnsProps extends DataGridControl {
|
|
5
|
-
schema: Schema<any>;
|
|
6
|
-
title?: ReactNode;
|
|
7
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { DataGridHiddenColumnsProps } from "./types";
|
|
8
3
|
export declare function DataGridHiddenColumns(props: DataGridHiddenColumnsProps): React.JSX.Element;
|
|
@@ -4,14 +4,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Default = Default;
|
|
7
|
+
exports.Sortable = Sortable;
|
|
7
8
|
const react_1 = __importDefault(require("react"));
|
|
8
9
|
const json_renderer_1 = require("../_story-utils/json-renderer");
|
|
9
10
|
const schema_1 = require("../_story-utils/schema");
|
|
10
11
|
const use_data_grid_control_1 = require("../use-data-grid-control");
|
|
11
12
|
const hidden_columns_1 = require("./hidden-columns");
|
|
13
|
+
const hidden_columns_sortable_1 = require("./hidden-columns-sortable");
|
|
12
14
|
function Default() {
|
|
13
15
|
const { state, actions } = (0, use_data_grid_control_1.useDataGridControl)({ schema: schema_1.schema });
|
|
14
16
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
15
17
|
react_1.default.createElement(hidden_columns_1.DataGridHiddenColumns, { actions: actions, schema: schema_1.schema, state: state }),
|
|
16
18
|
react_1.default.createElement(json_renderer_1.JsonRenderer, { value: state })));
|
|
17
19
|
}
|
|
20
|
+
function Sortable() {
|
|
21
|
+
const { state, actions } = (0, use_data_grid_control_1.useDataGridControl)({ schema: schema_1.schema });
|
|
22
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
23
|
+
react_1.default.createElement(hidden_columns_sortable_1.DataGridHiddenColumnsSortable, { actions: actions, schema: schema_1.schema, state: state }),
|
|
24
|
+
react_1.default.createElement(json_renderer_1.JsonRenderer, { value: state })));
|
|
25
|
+
}
|
package/hidden-columns/index.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FunctionComponent } from "react";
|
|
2
|
+
import { Column, Schema } from "../types";
|
|
3
|
+
import { DataGridControl } from "../use-data-grid-control";
|
|
4
|
+
export type ColumnWithId = Column<any, any> & {
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
export type SectionKey = "visible" | "hidden";
|
|
8
|
+
export type Sections = Record<SectionKey, ColumnWithId[]>;
|
|
9
|
+
export declare const EMPTY_VISIBLE_COLUMNS_PLACEHOLDER_ID = "__empty-visible-placeholder__";
|
|
10
|
+
export declare const EMPTY_HIDDEN_COLUMNS_PLACEHOLDER_ID = "__empty-hidden-placeholder__";
|
|
11
|
+
export interface DataGridHiddenColumnsProps extends DataGridControl {
|
|
12
|
+
schema: Schema<any>;
|
|
13
|
+
}
|
|
14
|
+
export type HiddenColumnsComponentComponent = FunctionComponent<DataGridHiddenColumnsProps>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EMPTY_HIDDEN_COLUMNS_PLACEHOLDER_ID = exports.EMPTY_VISIBLE_COLUMNS_PLACEHOLDER_ID = void 0;
|
|
4
|
+
exports.EMPTY_VISIBLE_COLUMNS_PLACEHOLDER_ID = "__empty-visible-placeholder__";
|
|
5
|
+
exports.EMPTY_HIDDEN_COLUMNS_PLACEHOLDER_ID = "__empty-hidden-placeholder__";
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React, { ReactNode } from "react";
|
|
2
|
+
import { HiddenColumnsComponentComponent } from "../hidden-columns/types";
|
|
2
3
|
import { Schema } from "../types";
|
|
3
4
|
import { DataGridControl } from "../use-data-grid-control";
|
|
4
5
|
export interface DataGridHiddenColumnsButtonProps extends DataGridControl {
|
|
5
6
|
drawerTitle?: ReactNode;
|
|
7
|
+
HiddenColumnsComponent?: HiddenColumnsComponentComponent;
|
|
6
8
|
schema: Schema<any>;
|
|
7
9
|
}
|
|
8
10
|
export declare function DataGridHiddenColumnsButton(props: DataGridHiddenColumnsButtonProps): React.JSX.Element;
|
|
@@ -42,13 +42,14 @@ const react_1 = __importStar(require("react"));
|
|
|
42
42
|
const drawer_1 = require("../_components/drawer");
|
|
43
43
|
const hidden_columns_1 = require("../hidden-columns");
|
|
44
44
|
function DataGridHiddenColumnsButton(props) {
|
|
45
|
-
var _a;
|
|
45
|
+
var _a, _b;
|
|
46
46
|
const t = (0, translations_1.useUxfTranslation)();
|
|
47
47
|
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
48
48
|
const closeHandler = () => setIsOpen(false);
|
|
49
|
+
const HiddenColumnsComponent = (_a = props.HiddenColumnsComponent) !== null && _a !== void 0 ? _a : hidden_columns_1.DataGridHiddenColumns;
|
|
49
50
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
50
|
-
react_1.default.createElement(icon_button_1.IconButton, { className: "uxf-data-grid__plugin-button", iconName: "table-columns", label: t("uxf-data-grid-hidden-columns-button:column-settings-label"), onClick: () => setIsOpen(true), size: "sm", variant: "secondary" }),
|
|
51
|
+
react_1.default.createElement(icon_button_1.IconButton, { className: "uxf-data-grid__plugin-button", iconName: "table-columns", label: t("uxf-data-grid-hidden-columns-button:column-settings-label"), onClick: () => setIsOpen(true), size: "sm", title: t("uxf-data-grid-hidden-columns-button:column-settings-label"), variant: "secondary" }),
|
|
51
52
|
react_1.default.createElement(modal_1.Modal, { className: "uxf-dg-modal", isOpen: isOpen, onClose: closeHandler, variant: "drawer-right" },
|
|
52
|
-
react_1.default.createElement(drawer_1.Drawer, { onClose: closeHandler, title: (
|
|
53
|
-
react_1.default.createElement(
|
|
53
|
+
react_1.default.createElement(drawer_1.Drawer, { onClose: closeHandler, title: (_b = props.drawerTitle) !== null && _b !== void 0 ? _b : t("uxf-data-grid-hidden-columns-button:columns-title") },
|
|
54
|
+
react_1.default.createElement(HiddenColumnsComponent, { actions: props.actions, schema: props.schema, state: props.state })))));
|
|
54
55
|
}
|
|
@@ -7,11 +7,15 @@ exports.Default = Default;
|
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const json_renderer_1 = require("../_story-utils/json-renderer");
|
|
9
9
|
const schema_1 = require("../_story-utils/schema");
|
|
10
|
+
const hidden_columns_1 = require("../hidden-columns");
|
|
10
11
|
const use_data_grid_control_1 = require("../use-data-grid-control");
|
|
11
12
|
const hidden_columns_button_1 = require("./hidden-columns-button");
|
|
12
13
|
function Default() {
|
|
13
14
|
const { state, actions } = (0, use_data_grid_control_1.useDataGridControl)({ schema: schema_1.schema });
|
|
14
15
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
15
|
-
react_1.default.createElement(
|
|
16
|
+
react_1.default.createElement("div", { className: "mt-10" },
|
|
17
|
+
react_1.default.createElement(hidden_columns_button_1.DataGridHiddenColumnsButton, { actions: actions, schema: schema_1.schema, state: state })),
|
|
18
|
+
react_1.default.createElement("div", null,
|
|
19
|
+
react_1.default.createElement(hidden_columns_button_1.DataGridHiddenColumnsButton, { HiddenColumnsComponent: hidden_columns_1.DataGridHiddenColumnsSortable, actions: actions, schema: schema_1.schema, state: state })),
|
|
16
20
|
react_1.default.createElement(json_renderer_1.JsonRenderer, { value: state })));
|
|
17
21
|
}
|
package/icons-config.js
CHANGED
|
@@ -11,6 +11,11 @@ module.exports = {
|
|
|
11
11
|
height: 512,
|
|
12
12
|
data: `<path d="M3.9 54.9C10.5 40.9 24.5 32 40 32H472c15.5 0 29.5 8.9 36.1 22.9s4.6 30.5-5.2 42.5L320 320.9V448c0 12.1-6.8 23.2-17.7 28.6s-23.8 4.3-33.5-3l-64-48c-8.1-6-12.8-15.5-12.8-25.6V320.9L9 97.3C-.7 85.4-2.8 68.8 3.9 54.9z" fill="currentColor"/>`,
|
|
13
13
|
},
|
|
14
|
+
"grip-dots-vertical": {
|
|
15
|
+
width: 256,
|
|
16
|
+
height: 512,
|
|
17
|
+
data: `<path fill="currentColor" d="M64 128a32 32 0 1 0 0-64 32 32 0 1 0 0 64zm0 160a32 32 0 1 0 0-64 32 32 0 1 0 0 64zM96 416a32 32 0 1 0 -64 0 32 32 0 1 0 64 0zm96-288a32 32 0 1 0 0-64 32 32 0 1 0 0 64zm32 128a32 32 0 1 0 -64 0 32 32 0 1 0 64 0zM192 448a32 32 0 1 0 0-64 32 32 0 1 0 0 64z"/>`,
|
|
18
|
+
},
|
|
14
19
|
pen: {
|
|
15
20
|
width: 512,
|
|
16
21
|
height: 512,
|
package/icons.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/data-grid",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.93.0",
|
|
4
4
|
"description": "UXF DataGrid",
|
|
5
5
|
"homepage": "https://gitlab.com/uxf-npm/data-grid#readme",
|
|
6
6
|
"main": "index.js",
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
"data-grid",
|
|
22
22
|
"uxf"
|
|
23
23
|
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=24"
|
|
26
|
+
},
|
|
24
27
|
"scripts": {
|
|
25
28
|
"dev": "next dev",
|
|
26
29
|
"build": "tsc -P tsconfig.json",
|
|
@@ -31,9 +34,11 @@
|
|
|
31
34
|
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
32
35
|
},
|
|
33
36
|
"dependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"@uxf/
|
|
37
|
+
"@dnd-kit/core": "6.3.1",
|
|
38
|
+
"@dnd-kit/sortable": "10.0.0",
|
|
39
|
+
"@uxf/core": "11.93.0",
|
|
40
|
+
"@uxf/core-react": "11.93.0",
|
|
41
|
+
"@uxf/ui": "11.93.0",
|
|
37
42
|
"dayjs": "1.11.19",
|
|
38
43
|
"deepmerge": "4.3.1",
|
|
39
44
|
"fast-glob": "3.3.3",
|
package/styles.css
CHANGED
|
@@ -437,13 +437,26 @@ o
|
|
|
437
437
|
font-weight: theme("fontWeight.medium");
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
+
&__hidden-columns-column-item {
|
|
441
|
+
align-items: center;
|
|
442
|
+
display: flex;
|
|
443
|
+
gap: 12px;
|
|
444
|
+
width: 100%;
|
|
445
|
+
|
|
446
|
+
& > .uxf-toggle__wrapper {
|
|
447
|
+
flex-grow: 1;
|
|
448
|
+
padding-left: 0;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
440
452
|
&__hidden-columns-title {
|
|
441
453
|
display: flex;
|
|
442
454
|
gap: 8px;
|
|
443
455
|
justify-content: space-between;
|
|
444
456
|
padding: 24px 0 12px;
|
|
445
457
|
|
|
446
|
-
|
|
458
|
+
&-text {
|
|
459
|
+
color: theme("colors.lightMedium");
|
|
447
460
|
text-transform: uppercase;
|
|
448
461
|
}
|
|
449
462
|
|
|
@@ -464,11 +477,27 @@ o
|
|
|
464
477
|
display: flex;
|
|
465
478
|
gap: 12px;
|
|
466
479
|
margin: 8px 0;
|
|
467
|
-
padding:
|
|
480
|
+
padding: 12px 16px;
|
|
468
481
|
|
|
469
482
|
.uxf-icon {
|
|
470
483
|
color: theme("colors.warning_icon_on_muted");
|
|
471
|
-
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
&__hidden-columns-drop-placeholder {
|
|
488
|
+
align-items: center;
|
|
489
|
+
background-color: var(--gray-50);
|
|
490
|
+
border: 1px dashed var(--gray-300);
|
|
491
|
+
border-radius: 4px;
|
|
492
|
+
color: var(--gray-500);
|
|
493
|
+
display: grid;
|
|
494
|
+
justify-content: center;
|
|
495
|
+
min-height: 64px;
|
|
496
|
+
min-width: 100%;
|
|
497
|
+
padding: 16px;
|
|
498
|
+
|
|
499
|
+
&--over {
|
|
500
|
+
background-color: var(--gray-100);
|
|
472
501
|
}
|
|
473
502
|
}
|
|
474
503
|
|
|
@@ -51,7 +51,11 @@ function HeaderCellComponent(props, ref) {
|
|
|
51
51
|
react_1.default.createElement("div", { className: (0, cx_1.cx)(`uxf-dg-table__cell uxf-dg-table__cell--header uxf-dg-table__cell--type-${props.column.type}`, props.column.sort && "is-sortable", ((_c = props.sort) === null || _c === void 0 ? void 0 : _c.dir) === "asc" && "is-sorted-asc", ((_d = props.sort) === null || _d === void 0 ? void 0 : _d.dir) === "desc" && "is-sorted-desc"), onClick: props.onClick, ref: ref },
|
|
52
52
|
props.column.label,
|
|
53
53
|
iconName && react_1.default.createElement(icon_1.Icon, { className: "ml-auto", name: iconName }),
|
|
54
|
-
react_1.default.createElement("button", { className: "uxf-dg-table__column-resize-handle", onClick: (event) => event.stopPropagation(),
|
|
54
|
+
react_1.default.createElement("button", { className: "uxf-dg-table__column-resize-handle", onClick: (event) => event.stopPropagation(), onDoubleClick: (event) => {
|
|
55
|
+
var _a;
|
|
56
|
+
event.stopPropagation();
|
|
57
|
+
(_a = props.onAutoSize) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
58
|
+
}, onMouseDown: props.onResizeStart })));
|
|
55
59
|
}
|
|
56
60
|
exports.HeaderCell = (0, react_1.forwardRef)(HeaderCellComponent);
|
|
57
61
|
exports.HeaderCell.displayName = "HeaderCell";
|
|
@@ -6,4 +6,5 @@ export declare function useResizableColumns(columns: Column<any, any>[], actionC
|
|
|
6
6
|
tableRef: import("react").RefObject<HTMLDivElement>;
|
|
7
7
|
columnRefs: import("react").MutableRefObject<(HTMLDivElement | null)[]>;
|
|
8
8
|
onResizeStart(index: number): void;
|
|
9
|
+
onAutoSize: (index: number) => void;
|
|
9
10
|
};
|
|
@@ -6,6 +6,7 @@ const rem_1 = require("@uxf/styles/units/rem");
|
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const get_grid_template_columns_1 = require("../utils/get-grid-template-columns");
|
|
8
8
|
const COLUMN_ABSOLUTE_MIN_WIDTH = 50;
|
|
9
|
+
const COLUMN_PADDING = 24;
|
|
9
10
|
function useResizableColumns(columns, actionCell, actions, selectRowsCellWidth) {
|
|
10
11
|
const [activeIndex, setActiveIndex] = (0, react_1.useState)(null);
|
|
11
12
|
const tableRef = (0, react_1.useRef)(null);
|
|
@@ -59,11 +60,50 @@ function useResizableColumns(columns, actionCell, actions, selectRowsCellWidth)
|
|
|
59
60
|
window.removeEventListener("mouseup", onMouseUp);
|
|
60
61
|
};
|
|
61
62
|
}, [columns, actions, actionCellWidth, activeIndex, selectRowsCellWidth]);
|
|
63
|
+
const onAutoSize = (index) => {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
const table = tableRef.current;
|
|
66
|
+
if (!table) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const column = columns[index];
|
|
70
|
+
const columnRef = columnRefs.current[index];
|
|
71
|
+
if (!columnRef) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// Get all cells in this column (including header)
|
|
75
|
+
const cells = table.querySelectorAll(`.uxf-dg-table__cell--type-${column.type}:nth-child(${index + 1 + (selectRowsCellWidth ? 1 : 0)})`);
|
|
76
|
+
let maxWidth = COLUMN_ABSOLUTE_MIN_WIDTH;
|
|
77
|
+
// Measure content width of each cell
|
|
78
|
+
cells.forEach((cell) => {
|
|
79
|
+
const cellElement = cell;
|
|
80
|
+
// Create a temporary element to measure content width
|
|
81
|
+
const tempElement = document.createElement("span");
|
|
82
|
+
tempElement.style.visibility = "hidden";
|
|
83
|
+
tempElement.style.position = "absolute";
|
|
84
|
+
tempElement.style.whiteSpace = "nowrap";
|
|
85
|
+
tempElement.innerHTML = cellElement.innerHTML;
|
|
86
|
+
document.body.appendChild(tempElement);
|
|
87
|
+
const contentWidth = tempElement.offsetWidth + COLUMN_PADDING;
|
|
88
|
+
maxWidth = Math.max(maxWidth, contentWidth);
|
|
89
|
+
document.body.removeChild(tempElement);
|
|
90
|
+
});
|
|
91
|
+
// Apply min width constraint
|
|
92
|
+
const columnMinWidth = (_b = (_a = column.config) === null || _a === void 0 ? void 0 : _a.minWidth) !== null && _b !== void 0 ? _b : COLUMN_ABSOLUTE_MIN_WIDTH;
|
|
93
|
+
const finalWidth = Math.max(maxWidth, columnMinWidth);
|
|
94
|
+
// Update the user config with the auto-sized width
|
|
95
|
+
actions.updateUserConfig({
|
|
96
|
+
columns: {
|
|
97
|
+
[column.name]: { width: finalWidth },
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
};
|
|
62
101
|
return {
|
|
63
102
|
tableRef,
|
|
64
103
|
columnRefs,
|
|
65
104
|
onResizeStart(index) {
|
|
66
105
|
setActiveIndex(index);
|
|
67
106
|
},
|
|
107
|
+
onAutoSize,
|
|
68
108
|
};
|
|
69
109
|
}
|
package/table-v2/table-v2.js
CHANGED
|
@@ -27,9 +27,13 @@ function DataGridTableV2(props) {
|
|
|
27
27
|
const keyExtractor = (_a = props.keyExtractor) !== null && _a !== void 0 ? _a : defaultKeyExtractor;
|
|
28
28
|
const visibleColumns = props.schema.columns
|
|
29
29
|
.filter((column) => !column.hidden)
|
|
30
|
-
.filter((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.isHidden) !== null && _c !== void 0 ? _c : (_d = column.config) === null || _d === void 0 ? void 0 : _d.isHidden); })
|
|
30
|
+
.filter((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.isHidden) !== null && _c !== void 0 ? _c : (_d = column.config) === null || _d === void 0 ? void 0 : _d.isHidden); })
|
|
31
|
+
.sort((a, b) => props.state.userConfig.columnsOrder
|
|
32
|
+
? props.state.userConfig.columnsOrder.indexOf(a.name) -
|
|
33
|
+
props.state.userConfig.columnsOrder.indexOf(b.name)
|
|
34
|
+
: 0);
|
|
31
35
|
const selectedRowColumnWidth = props.isRowsSelectable ? SELECT_ROWS_CELL_WIDTH : null;
|
|
32
|
-
const { tableRef, columnRefs, onResizeStart } = (0, use_resizable_columns_1.useResizableColumns)(visibleColumns, props.actionCell, props.actions, selectedRowColumnWidth);
|
|
36
|
+
const { tableRef, columnRefs, onResizeStart, onAutoSize } = (0, use_resizable_columns_1.useResizableColumns)(visibleColumns, props.actionCell, props.actions, selectedRowColumnWidth);
|
|
33
37
|
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);
|
|
34
38
|
const gridTemplateBasicColumns = visibleColumns
|
|
35
39
|
.map((column) => {
|
|
@@ -66,7 +70,7 @@ function DataGridTableV2(props) {
|
|
|
66
70
|
react_1.default.createElement(header_select_all_rows_checkbox_1.HeaderSelectAllRowsCheckbox, { actions: props.actions, data: props.data, isRowSelectDisabled: props.isRowSelectDisabled, keyExtractor: keyExtractor, state: props.state })),
|
|
67
71
|
visibleColumns.map((column, index) => {
|
|
68
72
|
var _a;
|
|
69
|
-
return (react_1.default.createElement(components_1.Table.HeaderCell, { column: column, key: column.name, onClick: column.sort ? () => props.actions.sort(column.name) : undefined, onResizeStart: () => onResizeStart(index), ref: (el) => {
|
|
73
|
+
return (react_1.default.createElement(components_1.Table.HeaderCell, { column: column, key: column.name, onAutoSize: () => onAutoSize(index), onClick: column.sort ? () => props.actions.sort(column.name) : undefined, onResizeStart: () => onResizeStart(index), ref: (el) => {
|
|
70
74
|
columnRefs.current[index] = el;
|
|
71
75
|
}, sort: ((_a = props.state.request.s) === null || _a === void 0 ? void 0 : _a.name) === column.name ? props.state.request.s : null }));
|
|
72
76
|
}),
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Nullish } from "@uxf/core/types";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { FilterHandlers } from "../filter-handler";
|
|
4
|
+
import { HiddenColumnsComponentComponent } from "../hidden-columns/types";
|
|
4
5
|
import { CsvDownloadGetUrl, Schema } from "../types";
|
|
5
6
|
import { DataGridControl } from "../use-data-grid-control";
|
|
6
7
|
export interface DataGridToolbarControlProps extends DataGridControl {
|
|
7
|
-
|
|
8
|
+
HiddenColumnsComponent?: HiddenColumnsComponentComponent;
|
|
8
9
|
filterHandlers: FilterHandlers;
|
|
10
|
+
fulltextInputPlaceholder?: string;
|
|
9
11
|
getCsvDownloadUrl?: CsvDownloadGetUrl;
|
|
10
12
|
isBorderHidden?: boolean | Nullish;
|
|
11
|
-
|
|
13
|
+
schema: Schema<any>;
|
|
12
14
|
}
|
|
13
15
|
export declare function DataGridToolbarControl(props: DataGridToolbarControlProps): React.JSX.Element;
|
|
@@ -17,6 +17,6 @@ function DataGridToolbarControl(props) {
|
|
|
17
17
|
react_1.default.createElement(hide_1.Hide, { when: !props.schema.fullText },
|
|
18
18
|
react_1.default.createElement(fulltext_input_1.DataGridFulltextInput, { actions: props.actions, placeholder: props.fulltextInputPlaceholder, state: props.state })),
|
|
19
19
|
(0, is_not_nil_1.isNotNil)(props.getCsvDownloadUrl) && (react_1.default.createElement(export_button_1.DataGridExportButton, { actions: props.actions, getCsvDownloadUrl: props.getCsvDownloadUrl, schema: props.schema, state: props.state })),
|
|
20
|
-
react_1.default.createElement(hidden_columns_button_1.DataGridHiddenColumnsButton, { actions: props.actions, schema: props.schema, state: props.state }),
|
|
20
|
+
react_1.default.createElement(hidden_columns_button_1.DataGridHiddenColumnsButton, { HiddenColumnsComponent: props.HiddenColumnsComponent, actions: props.actions, schema: props.schema, state: props.state }),
|
|
21
21
|
react_1.default.createElement(filters_button_1.DataGridFiltersButton, { actions: props.actions, filterHandlers: props.filterHandlers, schema: props.schema, state: props.state })));
|
|
22
22
|
}
|
package/translations/cs.json
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
"hide-all": "skrýt vše",
|
|
5
5
|
"empty-message": "Tabulka má všechny sloupce skryté. Pro zobrazení vyberte sloupec níže.",
|
|
6
6
|
"hidden-columns": "Skryté sloupce",
|
|
7
|
-
"show-all": "zobrazit vše"
|
|
7
|
+
"show-all": "zobrazit vše",
|
|
8
|
+
"drag-columns-hide": "Přetáhněte sem sloupce pro skrytí sloupců",
|
|
9
|
+
"drag-columns-show": "Přetáhněte sem sloupce pro zobrazení sloupců"
|
|
8
10
|
},
|
|
9
11
|
"uxf-data-grid-fulltext-input": {
|
|
10
12
|
"search-label": "Vyhledávání",
|
package/translations/de.json
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
"hide-all": "alle ausblenden",
|
|
5
5
|
"empty-message": "Die Tabelle hat alle Spalten ausgeblendet. Um sie anzuzeigen, wählen Sie eine Spalte unten aus.",
|
|
6
6
|
"hidden-columns": "Ausgeblendete Spalten",
|
|
7
|
-
"show-all": "alle anzeigen"
|
|
7
|
+
"show-all": "alle anzeigen",
|
|
8
|
+
"drag-columns-hide": "Ziehen Sie hier Spalten hin, um Spalten zu verbergen",
|
|
9
|
+
"drag-columns-show": "Ziehen Sie hier Spalten hin, um Spalten anzuzeigen"
|
|
8
10
|
},
|
|
9
11
|
"uxf-data-grid-fulltext-input": {
|
|
10
12
|
"search-label": "Suche",
|
package/translations/en.json
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
"hide-all": "hide all",
|
|
5
5
|
"empty-message": "The table has all columns hidden. To display them, select a column below.",
|
|
6
6
|
"hidden-columns": "Hidden columns",
|
|
7
|
-
"show-all": "show all"
|
|
7
|
+
"show-all": "show all",
|
|
8
|
+
"drag-columns-hide": "Drag columns here to hide columns",
|
|
9
|
+
"drag-columns-show": "Drag columns here to show columns"
|
|
8
10
|
},
|
|
9
11
|
"uxf-data-grid-fulltext-input": {
|
|
10
12
|
"search-label": "Search",
|
package/translations/sk.json
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
"hide-all": "skryť všetko",
|
|
5
5
|
"empty-message": "Tabuľka má všetky stĺpce skryté. Pre zobrazenie vyberte stĺpec nižšie.",
|
|
6
6
|
"hidden-columns": "Skryté stĺpce",
|
|
7
|
-
"show-all": "zobraziť všetko"
|
|
7
|
+
"show-all": "zobraziť všetko",
|
|
8
|
+
"drag-columns-hide": "Potiahnite sem stĺpce na skrytie stĺpcov",
|
|
9
|
+
"drag-columns-show": "Potiahnite sem stĺpce na zobrazenie stĺpcov"
|
|
8
10
|
},
|
|
9
11
|
"uxf-data-grid-fulltext-input": {
|
|
10
12
|
"search-label": "Vyhľadávanie",
|
|
@@ -30,6 +30,18 @@ declare const _default: {
|
|
|
30
30
|
sk: string;
|
|
31
31
|
de: string;
|
|
32
32
|
};
|
|
33
|
+
"drag-columns-hide": {
|
|
34
|
+
cs: string;
|
|
35
|
+
en: string;
|
|
36
|
+
sk: string;
|
|
37
|
+
de: string;
|
|
38
|
+
};
|
|
39
|
+
"drag-columns-show": {
|
|
40
|
+
cs: string;
|
|
41
|
+
en: string;
|
|
42
|
+
sk: string;
|
|
43
|
+
de: string;
|
|
44
|
+
};
|
|
33
45
|
};
|
|
34
46
|
"uxf-data-grid-fulltext-input": {
|
|
35
47
|
"search-label": {
|
|
@@ -32,6 +32,18 @@ exports.default = {
|
|
|
32
32
|
sk: "zobraziť všetko",
|
|
33
33
|
de: "alle anzeigen",
|
|
34
34
|
},
|
|
35
|
+
"drag-columns-hide": {
|
|
36
|
+
cs: "Přetáhněte sem sloupce pro skrytí sloupců",
|
|
37
|
+
en: "Drag columns here to hide columns",
|
|
38
|
+
sk: "Potiahnite sem stĺpce na skrytie stĺpcov",
|
|
39
|
+
de: "Ziehen Sie hier Spalten hin, um Spalten zu verbergen",
|
|
40
|
+
},
|
|
41
|
+
"drag-columns-show": {
|
|
42
|
+
cs: "Přetáhněte sem sloupce pro zobrazení sloupců",
|
|
43
|
+
en: "Drag columns here to show columns",
|
|
44
|
+
sk: "Potiahnite sem stĺpce na zobrazenie stĺpcov",
|
|
45
|
+
de: "Ziehen Sie hier Spalten hin, um Spalten anzuzeigen",
|
|
46
|
+
},
|
|
35
47
|
},
|
|
36
48
|
"uxf-data-grid-fulltext-input": {
|
|
37
49
|
"search-label": {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Nullish } from "@uxf/core/types";
|
|
2
2
|
import { FilterHandlers } from "../filter-handler";
|
|
3
|
+
import { HiddenColumnsComponentComponent } from "../hidden-columns/types";
|
|
3
4
|
import { SelectedRowsToolbarActionsComponent } from "../selected-rows-toolbar";
|
|
4
5
|
import { NoRowsFallbackComponent } from "../table-v2/no-rows-fallback";
|
|
5
6
|
import { DataGridTableProps } from "../table-v2/types";
|
|
@@ -12,6 +13,7 @@ import { BaseGridType, Schema } from "./schema";
|
|
|
12
13
|
export type DataGridControlProps = DataGridControl;
|
|
13
14
|
export type DataGridDataProps<Row> = DataGridFetchingResult<Row>;
|
|
14
15
|
export type DataGridBaseProps<GridType extends BaseGridType, Row> = {
|
|
16
|
+
HiddenColumnsComponent?: HiddenColumnsComponentComponent;
|
|
15
17
|
NoRowsFallback?: NoRowsFallbackComponent;
|
|
16
18
|
SelectedRowsToolbarActions?: SelectedRowsToolbarActionsComponent;
|
|
17
19
|
actionCell?: DataGridTableProps<Row>["actionCell"];
|
|
@@ -24,6 +26,7 @@ export type DataGridBaseProps<GridType extends BaseGridType, Row> = {
|
|
|
24
26
|
gridName?: string;
|
|
25
27
|
headerRowHeight?: number;
|
|
26
28
|
isDebug?: boolean;
|
|
29
|
+
isHiddenColumnsSortable?: boolean;
|
|
27
30
|
isRowSelectDisabled?: (row: Row) => boolean;
|
|
28
31
|
isRowsSelectable?: boolean;
|
|
29
32
|
keyExtractor?: KeyExtractor;
|
package/types/state.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type GridRequest = {
|
|
|
10
10
|
};
|
|
11
11
|
export interface DataGridUserConfig<GridType extends BaseGridType> {
|
|
12
12
|
columns?: Partial<Record<keyof GridType["columns"], ColumnConfig>>;
|
|
13
|
+
columnsOrder?: (keyof GridType["columns"])[];
|
|
13
14
|
perPage?: number;
|
|
14
15
|
}
|
|
15
16
|
export interface DataGridFrontendConfig<GridType extends BaseGridType> extends DataGridUserConfig<GridType> {
|
|
@@ -14,6 +14,7 @@ export declare function createActions(dispatch: Dispatch<Action>): {
|
|
|
14
14
|
search: (search: string) => void;
|
|
15
15
|
changeTab: (tab: Tab, filterBehavior: ChangeTabFilterBehavior) => void;
|
|
16
16
|
setSelectedRows: (rows: any[]) => void;
|
|
17
|
+
setColumnsOrder: (columns: string[]) => void;
|
|
17
18
|
hideColumn: (name: string) => void;
|
|
18
19
|
showColumn: (name: string) => void;
|
|
19
20
|
updateUserConfig: (userConfig: DataGridUserConfig<any>) => void;
|
|
@@ -13,6 +13,7 @@ function createActions(dispatch) {
|
|
|
13
13
|
search: (search) => dispatch({ type: "FULLTEXT", search }),
|
|
14
14
|
changeTab: (tab, filterBehavior) => dispatch({ type: "CHANGE_TAB", tab, filterBehavior }),
|
|
15
15
|
setSelectedRows: (rows) => dispatch({ type: "SET_SELECTED_ROWS", rows }),
|
|
16
|
+
setColumnsOrder: (columns) => dispatch({ type: "SET_COLUMNS_ORDER", columns }),
|
|
16
17
|
hideColumn: (name) => dispatch({ type: "HIDE_COLUMN", name }),
|
|
17
18
|
showColumn: (name) => dispatch({ type: "SHOW_COLUMN", name }),
|
|
18
19
|
updateUserConfig: (userConfig) => dispatch({ type: "UPDATE_USER_CONFIG", userConfig }),
|
|
@@ -23,6 +23,7 @@ export declare function useDataGridControl<T extends BaseGridType>(config: UseDa
|
|
|
23
23
|
search: (search: string) => void;
|
|
24
24
|
changeTab: (tab: import("../types/schema").Tab, filterBehavior: import("..").ChangeTabFilterBehavior) => void;
|
|
25
25
|
setSelectedRows: (rows: any[]) => void;
|
|
26
|
+
setColumnsOrder: (columns: string[]) => void;
|
|
26
27
|
hideColumn: (name: string) => void;
|
|
27
28
|
showColumn: (name: string) => void;
|
|
28
29
|
updateUserConfig: (userConfig: DataGridUserConfig<any>) => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Schema } from "../types";
|
|
2
2
|
import { UserConfigStorageAdapter } from "../types/user-config-storage-adapter";
|
|
3
3
|
export declare function useUserConfigLocalStorageAdapter(schema: Schema<any>): UserConfigStorageAdapter;
|
|
4
|
+
export declare function useClearLocalStorageUserConfig(schema: Schema<any>): () => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useUserConfigLocalStorageAdapter = useUserConfigLocalStorageAdapter;
|
|
4
|
+
exports.useClearLocalStorageUserConfig = useClearLocalStorageUserConfig;
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const action_1 = require("../use-data-grid-control/action");
|
|
6
7
|
const get_config_key_1 = require("../utils/get-config-key");
|
|
@@ -30,3 +31,10 @@ function useUserConfigLocalStorageAdapter(schema) {
|
|
|
30
31
|
},
|
|
31
32
|
}), [configKey]);
|
|
32
33
|
}
|
|
34
|
+
function useClearLocalStorageUserConfig(schema) {
|
|
35
|
+
const configKey = (0, get_config_key_1.getConfigKey)(schema);
|
|
36
|
+
return () => {
|
|
37
|
+
window.localStorage.setItem(configKey, "");
|
|
38
|
+
window.location.reload();
|
|
39
|
+
};
|
|
40
|
+
}
|