@m4l/components 0.1.79 → 0.1.81
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/@types/export.d.ts +35 -3
- package/components/AccountPopover/{index.d541e4e6.js → index.fea740a5.js} +10 -6
- package/components/AppBar/{index.f90014de.js → index.6bdee075.js} +5 -4
- package/components/CommonActions/components/ActionCancel/{index.92536832.js → index.6928b5ae.js} +1 -1
- package/components/CommonActions/components/ActionFormCancel/{index.7fb1ed8d.js → index.28d32483.js} +12 -11
- package/components/CommonActions/components/ActionFormIntro/{index.bebc0c94.js → index.f044e93c.js} +1 -1
- package/components/CommonActions/components/ActionIntro/{index.aa4e432e.js → index.8b1b3afc.js} +1 -1
- package/components/CommonActions/components/Actions/{index.5732847f.js → index.265d99c8.js} +10 -9
- package/components/DataGrid/classes/constants.d.ts +1 -0
- package/components/DataGrid/classes/index.d.ts +27 -0
- package/components/DataGrid/classes/types.d.ts +27 -0
- package/components/DataGrid/contexts/DataGridContext/types.d.ts +3 -1
- package/components/DataGrid/index.820e0043.js +1009 -0
- package/components/DataGrid/subcomponents/Actions/index.43325b59.js +618 -0
- package/components/DataGrid/subcomponents/Actions/subcomponents/Settings/subcomponents/ColumnsConfig/subcomponents/FormatterColumn/index.d.ts +2 -2
- package/components/DataGrid/subcomponents/Actions/subcomponents/Settings/subcomponents/ColumnsConfig/subcomponents/FormatterColumn/types.d.ts +3 -0
- package/components/DataGrid/subcomponents/Actions/subcomponents/Settings/subcomponents/ColumnsConfig/types.d.ts +2 -0
- package/components/DataGrid/subcomponents/editors/TextEditor/index.91380a55.js +64 -0
- package/components/DataGrid/types.d.ts +7 -0
- package/components/DynamicFilter/{index.0887320f.js → index.2b80238b.js} +23 -22
- package/components/GridLayout/GridLayout.d.ts +1 -0
- package/components/GridLayout/classes/index.d.ts +4 -0
- package/components/GridLayout/classes/types.d.ts +17 -0
- package/components/GridLayout/constants.d.ts +26 -0
- package/components/GridLayout/{index.da6fd387.js → index.76bccc4f.js} +323 -576
- package/components/GridLayout/index.d.ts +4 -3
- package/components/GridLayout/subcomponents/Griditem/index.01fc14c3.js +370 -0
- package/components/GridLayout/subcomponents/Griditem/index.d.ts +9 -0
- package/components/GridLayout/subcomponents/Griditem/types.d.ts +103 -0
- package/components/GridLayout/subcomponents/Responsive/helper.d.ts +10 -0
- package/components/GridLayout/subcomponents/Responsive/index.d.ts +15 -2
- package/components/GridLayout/{Responsive/index.0905a698.js → subcomponents/Responsive/index.e589d8bf.js} +95 -139
- package/components/GridLayout/subcomponents/Responsive/responsiveUtils.d.ts +3 -6
- package/components/GridLayout/subcomponents/Responsive/types.d.ts +114 -33
- package/components/GridLayout/{WidthProvider/index.9a26dfe4.js → subcomponents/WidthProvider/index.50dafd87.js} +5 -5
- package/components/GridLayout/subcomponents/WidthProvider/index.d.ts +4 -5
- package/components/GridLayout/types.d.ts +83 -18
- package/components/GridLayout/utils.d.ts +15 -12
- package/components/HelperText/{index.29d5ad65.js → index.2c408d8a.js} +5 -4
- package/components/LanguagePopover/{index.ce84f099.js → index.4596bf54.js} +5 -4
- package/components/ModalDialog/{index.ab432b77.js → index.62ffad3a.js} +3 -3
- package/components/NavLink/{index.3bf44e30.js → index.68392bd4.js} +5 -4
- package/components/ObjectLogs/{index.c947ded4.js → index.665e043d.js} +14 -13
- package/components/Period/{index.adc328ca.js → index.7d44c0e5.js} +16 -15
- package/components/PropertyValue/{index.6b583e7a.js → index.a66988e1.js} +1 -1
- package/components/areas/components/AreasAdmin/{index.31905078.js → index.5562f65f.js} +23 -22
- package/components/areas/components/AreasViewer/{index.fe18bdbc.js → index.1004b7a0.js} +35 -146
- package/components/areas/components/{index.7ae189ba.js → index.a441c8b1.js} +8 -7
- package/components/areas/contexts/AreasContext/helper.d.ts +2 -2
- package/components/areas/contexts/AreasContext/{index.1213c3ef.js → index.4bf1eabe.js} +12 -6
- package/components/areas/contexts/AreasContext/types.d.ts +4 -4
- package/components/areas/contexts/{index.84d35ffe.js → index.2938bc5a.js} +1 -1
- package/components/areas/hooks/useAreas/{index.cd799cf6.js → index.c77a2416.js} +1 -1
- package/components/areas/{index.6ee7a4eb.js → index.09851bae.js} +8 -7
- package/components/hook-form/RHFAutocomplete/classes/index.d.ts +4 -0
- package/components/hook-form/RHFAutocomplete/classes/types.d.ts +6 -0
- package/components/hook-form/RHFAutocomplete/{index.e52c1f6a.js → index.9a9d7c73.js} +34 -51
- package/components/hook-form/RHFAutocomplete/subcomponents/Skeleton/types.d.ts +2 -1
- package/components/hook-form/RHFAutocompleteAsync/{index.a226b8ac.js → index.172df421.js} +1 -1
- package/components/hook-form/RHFCheckbox/{index.9619debd.js → index.47f0157b.js} +42 -67
- package/components/hook-form/RHFCheckbox/types.d.ts +2 -1
- package/components/hook-form/RHFDateTime/{index.5da7b839.js → index.f46e987f.js} +9 -7
- package/components/hook-form/RHFPeriod/{index.7e42c292.js → index.2e07ba7b.js} +2 -2
- package/components/hook-form/RHFTextField/{index.13447584.js → index.253620eb.js} +4 -3
- package/components/hook-form/RHFUpload/{index.80071782.js → index.9f00121f.js} +6 -5
- package/components/modal/{WindowBase.90d3c1d5.js → WindowBase.37b59511.js} +8 -6
- package/components/modal/{WindowConfirm.835f8d13.js → WindowConfirm.1a8c8c21.js} +13 -12
- package/components/modal/{index.cd34ddb3.js → index.c8e23b8d.js} +10 -9
- package/components/mui_extended/Accordion/{index.e8ba0755.js → index.fa658639.js} +1 -1
- package/components/mui_extended/Badge/classes/constants.d.ts +1 -1
- package/components/mui_extended/Badge/{index.8c2b8b66.js → index.cad260fe.js} +1 -1
- package/components/mui_extended/CheckBox/CheckBox.d.ts +3 -0
- package/components/mui_extended/CheckBox/classes/constants.d.ts +1 -0
- package/components/mui_extended/CheckBox/classes/index.d.ts +8 -0
- package/components/mui_extended/CheckBox/classes/types.d.ts +10 -0
- package/components/mui_extended/CheckBox/index.d.ts +1 -0
- package/components/mui_extended/CheckBox/subcomponents/Skeleton/index.d.ts +3 -0
- package/components/mui_extended/CheckBox/subcomponents/Skeleton/types.d.ts +4 -0
- package/components/mui_extended/CheckBox/types.d.ts +5 -0
- package/components/mui_extended/CheckBox.5f6c78b0.js +86 -0
- package/components/mui_extended/Pager/classes/constants.d.ts +1 -0
- package/components/mui_extended/Pager/classes/index.d.ts +10 -0
- package/components/mui_extended/Pager/classes/types.d.ts +10 -0
- package/components/mui_extended/Pager/{index.2f6d6d7d.js → index.82e89328.js} +67 -31
- package/components/mui_extended/Tab/{index.3c005df1.js → index.f94d233e.js} +1 -1
- package/components/mui_extended/{index.ff59a512.js → index.07fcc38f.js} +5 -4
- package/components/mui_extended/index.d.ts +1 -0
- package/contexts/ModalContext/{index.feded672.js → index.66e060a3.js} +1 -1
- package/hooks/useModal/{index.6d238807.js → index.61968b84.js} +1 -1
- package/index.js +70 -65
- package/package.json +1 -2
- package/{vendor.9b969b18.js → vendor.fefd45a3.js} +42 -38
- package/components/DataGrid/index.302080d3.js +0 -1810
- package/components/GridLayout/subcomponents/GridItem/index.d.ts +0 -26
- package/components/GridLayout/subcomponents/GridItem/types.d.ts +0 -78
- package/components/hook-form/RHFCheckbox/subcomponents/Skeleton/index.d.ts +0 -3
- package/components/hook-form/RHFCheckbox/subcomponents/Skeleton/types.d.ts +0 -5
|
@@ -0,0 +1,1009 @@
|
|
|
1
|
+
import { g as getModalDialogComponentsDictionary } from "../ModalDialog/index.62ffad3a.js";
|
|
2
|
+
import { g as getPagerComponentsDictionary } from "../mui_extended/Pager/index.82e89328.js";
|
|
3
|
+
import { styled } from "@mui/material/styles";
|
|
4
|
+
import { forwardRef, createContext, useState, useMemo, useEffect, useCallback, useContext, useRef, useLayoutEffect } from "react";
|
|
5
|
+
import { S as SELECT_COLUMN_KEY, u as useRowSelection, a as SelectCellFormatter, H as HeaderRenderer, D as DataGrid$1 } from "../../react-data-grid.d46d625e.js";
|
|
6
|
+
import { useDrag, useDrop, DndProvider } from "react-dnd";
|
|
7
|
+
import { HTML5Backend } from "react-dnd-html5-backend";
|
|
8
|
+
import { SvgIcon, Checkbox, InputBase, Skeleton, generateUtilityClasses, generateUtilityClass } from "@mui/material";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { voidFunction, useModuleDictionary, useModuleSkeleton, getPropertyByString } from "@m4l/core";
|
|
11
|
+
import { A as ActionsColumn, a as Actions } from "./subcomponents/Actions/index.43325b59.js";
|
|
12
|
+
import { unstable_composeClasses } from "@mui/base";
|
|
13
|
+
import { B as BooleanFormatter } from "../formatters/BooleanFormatter/index.e8de8e4c.js";
|
|
14
|
+
import "@m4l/graphics";
|
|
15
|
+
import "../Icon/index.9fcd1476.js";
|
|
16
|
+
import "clsx";
|
|
17
|
+
import { D as DateFormatter } from "../formatters/DateFormatter/index.578a9f53.js";
|
|
18
|
+
import { C as ConcatenatedFormatter } from "../formatters/index.67aeb049.js";
|
|
19
|
+
const DataGridRoot = styled("div")(({
|
|
20
|
+
theme
|
|
21
|
+
}) => ({
|
|
22
|
+
display: "flex",
|
|
23
|
+
flexDirection: "column",
|
|
24
|
+
position: "absolute",
|
|
25
|
+
padding: "0px",
|
|
26
|
+
inset: "0px",
|
|
27
|
+
overflow: "hidden",
|
|
28
|
+
...theme.components?.M4LDataGrid?.styleOverrides
|
|
29
|
+
}));
|
|
30
|
+
function CheckboxIcon(props) {
|
|
31
|
+
return /* @__PURE__ */ jsx(SvgIcon, {
|
|
32
|
+
...props,
|
|
33
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
34
|
+
d: "M17 3a4 4 0 014 4v10a4 4 0 01-4 4H7a4 4 0 01-4-4V7a4 4 0 014-4h10zm0 2H7a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2z"
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function CheckboxCheckedIcon(props) {
|
|
39
|
+
return /* @__PURE__ */ jsx(SvgIcon, {
|
|
40
|
+
...props,
|
|
41
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
42
|
+
d: "M17 3a4 4 0 014 4v10a4 4 0 01-4 4H7a4 4 0 01-4-4V7a4 4 0 014-4h10zm-1.372 4.972a1.006 1.006 0 00-.928.388l-3.78 5-1.63-2.08a1.001 1.001 0 00-1.58 1.23l2.44 3.11a1 1 0 001.58-.01l4.57-6v-.03a1.006 1.006 0 00-.672-1.608z"
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function CheckboxIndeterminateIcon(props) {
|
|
47
|
+
return /* @__PURE__ */ jsx(SvgIcon, {
|
|
48
|
+
...props,
|
|
49
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
50
|
+
d: "M17 3a4 4 0 014 4v10a4 4 0 01-4 4H7a4 4 0 01-4-4V7a4 4 0 014-4h10zm-1.75 8h-6.5a.75.75 0 00-.75.75v.5c0 .414.336.75.75.75h6.5a.75.75 0 00.75-.75v-.5a.75.75 0 00-.75-.75z"
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const CheckboxFormatter = forwardRef(
|
|
55
|
+
function CheckboxFormatter2({
|
|
56
|
+
onChange,
|
|
57
|
+
checked,
|
|
58
|
+
...props
|
|
59
|
+
}, _ref) {
|
|
60
|
+
function handleChange(e) {
|
|
61
|
+
onChange(e.target.checked, e.nativeEvent.shiftKey);
|
|
62
|
+
}
|
|
63
|
+
return /* @__PURE__ */ jsx(Checkbox, {
|
|
64
|
+
checked,
|
|
65
|
+
size: "small",
|
|
66
|
+
icon: /* @__PURE__ */ jsx(CheckboxIcon, {}),
|
|
67
|
+
checkedIcon: /* @__PURE__ */ jsx(CheckboxCheckedIcon, {}),
|
|
68
|
+
indeterminateIcon: /* @__PURE__ */ jsx(CheckboxIndeterminateIcon, {}),
|
|
69
|
+
onChange: handleChange,
|
|
70
|
+
...props
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
const DataGridContext = createContext(null);
|
|
75
|
+
const getColumnConfigByKey = (key, storeColumnsConfig) => {
|
|
76
|
+
let indexFind = -1;
|
|
77
|
+
return [storeColumnsConfig.find((column, index) => {
|
|
78
|
+
if (column.key === key) {
|
|
79
|
+
indexFind = index;
|
|
80
|
+
}
|
|
81
|
+
return column.key === key;
|
|
82
|
+
}), indexFind];
|
|
83
|
+
};
|
|
84
|
+
function getColumnsConfig(id, columns, remoteConfig = void 0) {
|
|
85
|
+
let columnsConfig;
|
|
86
|
+
if (remoteConfig) {
|
|
87
|
+
columnsConfig = remoteConfig.columnsConfig;
|
|
88
|
+
} else {
|
|
89
|
+
try {
|
|
90
|
+
const item = window.localStorage.getItem(`${id}_columns_config`);
|
|
91
|
+
columnsConfig = item !== null ? JSON.parse(item) : [];
|
|
92
|
+
} catch (e) {
|
|
93
|
+
columnsConfig = [];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return columns.map((column, index) => {
|
|
97
|
+
const [columnConfig = {
|
|
98
|
+
...column
|
|
99
|
+
}, columnConfigIndex] = getColumnConfigByKey(column.key, columnsConfig);
|
|
100
|
+
return {
|
|
101
|
+
key: column.key,
|
|
102
|
+
name: column.name,
|
|
103
|
+
hidden: column.hidden === void 0 ? false : column.hidden,
|
|
104
|
+
index: columnConfigIndex > -1 ? columnConfigIndex : index,
|
|
105
|
+
visible: columnConfig.visible === void 0 ? true : columnConfig.visible,
|
|
106
|
+
frozen: columnConfig.frozen === void 0 ? false : columnConfig.frozen,
|
|
107
|
+
orginalIndex: index,
|
|
108
|
+
originalVisible: column.visible === void 0 ? true : column.visible,
|
|
109
|
+
originalFrozen: column.frozen === void 0 ? false : column.frozen
|
|
110
|
+
};
|
|
111
|
+
}).sort((a, b) => a.index - b.index);
|
|
112
|
+
}
|
|
113
|
+
function getColumnsWidth(id, columns, remoteConfig) {
|
|
114
|
+
const newMap = /* @__PURE__ */ new Map();
|
|
115
|
+
let storeColumnsWidth;
|
|
116
|
+
try {
|
|
117
|
+
const item = window.localStorage.getItem(`${id}_columns_width`);
|
|
118
|
+
storeColumnsWidth = item !== null ? new Map(JSON.parse(item)) : /* @__PURE__ */ new Map();
|
|
119
|
+
} catch (e) {
|
|
120
|
+
storeColumnsWidth = /* @__PURE__ */ new Map();
|
|
121
|
+
}
|
|
122
|
+
for (let i = 0; i < columns.length; i++) {
|
|
123
|
+
let width;
|
|
124
|
+
if (remoteConfig) {
|
|
125
|
+
try {
|
|
126
|
+
width = remoteConfig.columnsWidths.get(columns[i].key);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (width === void 0) {
|
|
131
|
+
const storeWidth = storeColumnsWidth.get(columns[i].key);
|
|
132
|
+
if (typeof storeWidth === "number") {
|
|
133
|
+
width = storeWidth;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (width !== void 0) {
|
|
137
|
+
newMap.set(columns[i].key, width);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return newMap;
|
|
141
|
+
}
|
|
142
|
+
function saveColumnsWidth(id, storeColumnsWidth) {
|
|
143
|
+
localStorage.setItem(`${id}_columns_width`, JSON.stringify([...storeColumnsWidth]));
|
|
144
|
+
}
|
|
145
|
+
function saveColumnsConfig(id, columnsConfig) {
|
|
146
|
+
localStorage.setItem(`${id}_columns_config`, JSON.stringify(columnsConfig));
|
|
147
|
+
}
|
|
148
|
+
function getIndexRowHeightVariant(variant) {
|
|
149
|
+
if (variant === "compact") {
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
if (variant === "standard") {
|
|
153
|
+
return 1;
|
|
154
|
+
}
|
|
155
|
+
return 2;
|
|
156
|
+
}
|
|
157
|
+
function DataGridProvider(props) {
|
|
158
|
+
const {
|
|
159
|
+
id,
|
|
160
|
+
children,
|
|
161
|
+
columns,
|
|
162
|
+
remoteConfig,
|
|
163
|
+
rows,
|
|
164
|
+
rowsCount,
|
|
165
|
+
rowActionsGetter,
|
|
166
|
+
rowHeights = [36, 52, 67],
|
|
167
|
+
rowHeaderHeights = [44, 63, 75],
|
|
168
|
+
initialRowHeightVariant = "compact",
|
|
169
|
+
checkedRows,
|
|
170
|
+
onCheckedRowsChange,
|
|
171
|
+
rowKeyGetter,
|
|
172
|
+
classes
|
|
173
|
+
} = props;
|
|
174
|
+
const [columnsWidths, setColumnsWidths] = useState(/* @__PURE__ */ new Map());
|
|
175
|
+
const [columnsConfig, setColumnsConfigOptions] = useState(() => []);
|
|
176
|
+
const [rowsFilterCount, setRowFilterCount] = useState(rowsCount);
|
|
177
|
+
const [currentRowHeightVariant, setCurrentRowHeightVariant] = useState(() => {
|
|
178
|
+
if (typeof rowHeights !== typeof rowHeaderHeights) {
|
|
179
|
+
throw new Error("Must be same type rowheights and rowHeaderTypes");
|
|
180
|
+
}
|
|
181
|
+
if (typeof rowHeights === "number" && typeof rowHeaderHeights === "number") {
|
|
182
|
+
return {
|
|
183
|
+
rowHVariant: "compact",
|
|
184
|
+
rowHeight: rowHeights,
|
|
185
|
+
rowHeaderHeight: rowHeaderHeights
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
if (typeof rowHeights !== "number" && rowHeights.length !== 3) {
|
|
189
|
+
throw new Error("Must be 3 heights");
|
|
190
|
+
}
|
|
191
|
+
if (typeof rowHeaderHeights !== "number" && rowHeaderHeights.length !== 3) {
|
|
192
|
+
throw new Error("Must be 3 HeaderHeights");
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
rowHVariant: initialRowHeightVariant,
|
|
196
|
+
rowHeight: typeof rowHeights !== "number" ? rowHeights[getIndexRowHeightVariant(initialRowHeightVariant)] : rowHeights,
|
|
197
|
+
rowHeaderHeight: typeof rowHeaderHeights !== "number" ? rowHeaderHeights[getIndexRowHeightVariant(initialRowHeightVariant)] : rowHeaderHeights
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
const finalRowHeights = useMemo(() => rowHeights, [rowHeights]);
|
|
201
|
+
let timerSaveColumns;
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
}, [columnsConfig]);
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
setColumnsWidths(getColumnsWidth(id, columns, remoteConfig));
|
|
206
|
+
setColumnsConfigOptions(getColumnsConfig(id, columns, remoteConfig));
|
|
207
|
+
}, [columns, id, remoteConfig]);
|
|
208
|
+
const onChangeColumnsConfig = useCallback((newColumnsConfig) => {
|
|
209
|
+
saveColumnsConfig(id, newColumnsConfig);
|
|
210
|
+
setColumnsConfigOptions(newColumnsConfig);
|
|
211
|
+
}, [setColumnsConfigOptions, id]);
|
|
212
|
+
const onChangeColumnsOrder = useCallback((sourceKey, targetKey) => {
|
|
213
|
+
if (sourceKey === targetKey)
|
|
214
|
+
return;
|
|
215
|
+
const sourceColumnIndex = columnsConfig.findIndex((c) => c.key === sourceKey);
|
|
216
|
+
const targetColumnIndex = columnsConfig.findIndex((c) => c.key === targetKey);
|
|
217
|
+
const reorderedColumnsConfig = [...columnsConfig];
|
|
218
|
+
reorderedColumnsConfig.splice(targetColumnIndex, 0, reorderedColumnsConfig.splice(sourceColumnIndex, 1)[0]);
|
|
219
|
+
onChangeColumnsConfig(reorderedColumnsConfig);
|
|
220
|
+
}, [columnsConfig, onChangeColumnsConfig]);
|
|
221
|
+
const onChangeColumnWidth = (columnKey, width) => {
|
|
222
|
+
columnsWidths.set(columnKey, Math.round(width));
|
|
223
|
+
if (timerSaveColumns) {
|
|
224
|
+
clearTimeout(timerSaveColumns);
|
|
225
|
+
}
|
|
226
|
+
timerSaveColumns = setTimeout(() => {
|
|
227
|
+
saveColumnsWidth(id, columnsWidths);
|
|
228
|
+
}, 500);
|
|
229
|
+
};
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
setColumnsConfigOptions(getColumnsConfig(id, columns));
|
|
232
|
+
}, [columns]);
|
|
233
|
+
const setRowFilterCountInternal = (newRowsCount) => {
|
|
234
|
+
setRowFilterCount(newRowsCount);
|
|
235
|
+
};
|
|
236
|
+
const setCurrentRowHeightInternal = useCallback((newVariant) => {
|
|
237
|
+
if (typeof rowHeights === "number" || typeof rowHeaderHeights === "number") {
|
|
238
|
+
throw new Error("Only use setCurrentRowHeight with vector rowHeights");
|
|
239
|
+
}
|
|
240
|
+
setCurrentRowHeightVariant({
|
|
241
|
+
rowHVariant: newVariant,
|
|
242
|
+
rowHeight: rowHeights[getIndexRowHeightVariant(newVariant)],
|
|
243
|
+
rowHeaderHeight: rowHeaderHeights[getIndexRowHeightVariant(newVariant)]
|
|
244
|
+
});
|
|
245
|
+
}, [setCurrentRowHeightVariant, rowHeights, rowHeaderHeights]);
|
|
246
|
+
return /* @__PURE__ */ jsx(DataGridContext.Provider, {
|
|
247
|
+
value: {
|
|
248
|
+
columnsConfig,
|
|
249
|
+
columnsWidths,
|
|
250
|
+
rowsCount: rowsFilterCount,
|
|
251
|
+
currentRowHeightVariant: currentRowHeightVariant.rowHVariant,
|
|
252
|
+
currentRowHeight: currentRowHeightVariant.rowHeight,
|
|
253
|
+
currentRowHeaderHeight: currentRowHeightVariant.rowHeaderHeight,
|
|
254
|
+
rows,
|
|
255
|
+
rowHeights: finalRowHeights,
|
|
256
|
+
checkedRows,
|
|
257
|
+
onChangeColumnsConfig,
|
|
258
|
+
onChangeColumnsOrder,
|
|
259
|
+
onChangeColumnWidth,
|
|
260
|
+
setRowsCount: setRowFilterCountInternal,
|
|
261
|
+
rowActionsGetter,
|
|
262
|
+
classes,
|
|
263
|
+
setRowHeightVariant: setCurrentRowHeightInternal,
|
|
264
|
+
onCheckedRowsChange,
|
|
265
|
+
rowKeyGetter
|
|
266
|
+
},
|
|
267
|
+
children
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
function useDataGrid() {
|
|
271
|
+
const context = useContext(DataGridContext);
|
|
272
|
+
if (!context)
|
|
273
|
+
throw new Error("useDataGrid context must be use inside DataGridContext");
|
|
274
|
+
return context;
|
|
275
|
+
}
|
|
276
|
+
const filterColumnClassName = "filter-cell";
|
|
277
|
+
const filterHeight = 35;
|
|
278
|
+
function SelectGroupFormatter(props) {
|
|
279
|
+
const [isRowSelected, onRowSelectionChange] = useRowSelection();
|
|
280
|
+
const onChange = (checked) => {
|
|
281
|
+
onRowSelectionChange({
|
|
282
|
+
row: props.row,
|
|
283
|
+
checked,
|
|
284
|
+
isShiftClick: false
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
const cellFormater = SelectCellFormatter({
|
|
288
|
+
value: isRowSelected,
|
|
289
|
+
isCellSelected: props.isCellSelected,
|
|
290
|
+
onChange,
|
|
291
|
+
"aria-label": "Select Group"
|
|
292
|
+
});
|
|
293
|
+
return cellFormater;
|
|
294
|
+
}
|
|
295
|
+
function SelectFormatter(props) {
|
|
296
|
+
const {
|
|
297
|
+
checkedRows,
|
|
298
|
+
onCheckedRowsChange,
|
|
299
|
+
rowKeyGetter
|
|
300
|
+
} = useDataGrid();
|
|
301
|
+
const onChange = (checked, _isShiftClick) => {
|
|
302
|
+
const newCheckedRows = new Set(checkedRows);
|
|
303
|
+
if (checked) {
|
|
304
|
+
newCheckedRows.add(rowKeyGetter(props.row));
|
|
305
|
+
} else {
|
|
306
|
+
newCheckedRows.delete(rowKeyGetter(props.row));
|
|
307
|
+
}
|
|
308
|
+
onCheckedRowsChange && onCheckedRowsChange(newCheckedRows);
|
|
309
|
+
};
|
|
310
|
+
return /* @__PURE__ */ jsx(SelectCellFormatter, {
|
|
311
|
+
value: checkedRows?.has(rowKeyGetter(props.row)) || false,
|
|
312
|
+
isCellSelected: props.isCellSelected,
|
|
313
|
+
onChange,
|
|
314
|
+
"aria-label": "Select"
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
const SelectColumnHeaderRenderer = (props) => {
|
|
318
|
+
const {
|
|
319
|
+
rows,
|
|
320
|
+
rowKeyGetter,
|
|
321
|
+
onCheckedRowsChange,
|
|
322
|
+
checkedRows
|
|
323
|
+
} = useDataGrid();
|
|
324
|
+
const onAllRowsCheckedChange = (checked) => {
|
|
325
|
+
if (!onCheckedRowsChange)
|
|
326
|
+
return;
|
|
327
|
+
if (checked) {
|
|
328
|
+
onCheckedRowsChange(new Set(rows.map((r) => rowKeyGetter(r))));
|
|
329
|
+
} else {
|
|
330
|
+
onCheckedRowsChange(/* @__PURE__ */ new Set());
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
const allRowsChecked = rows.length === checkedRows?.size;
|
|
334
|
+
return SelectCellFormatter({
|
|
335
|
+
"aria-label": "Select All",
|
|
336
|
+
isCellSelected: props.isCellSelected,
|
|
337
|
+
value: allRowsChecked,
|
|
338
|
+
onChange: onAllRowsCheckedChange
|
|
339
|
+
});
|
|
340
|
+
};
|
|
341
|
+
const SelectColumn = {
|
|
342
|
+
key: SELECT_COLUMN_KEY,
|
|
343
|
+
name: "",
|
|
344
|
+
width: 60,
|
|
345
|
+
maxWidth: 60,
|
|
346
|
+
resizable: false,
|
|
347
|
+
sortable: false,
|
|
348
|
+
frozen: true,
|
|
349
|
+
type: "boolean",
|
|
350
|
+
headerRenderer: SelectColumnHeaderRenderer,
|
|
351
|
+
formatter: SelectFormatter,
|
|
352
|
+
groupFormatter: SelectGroupFormatter
|
|
353
|
+
};
|
|
354
|
+
function useFocusRef(isSelected) {
|
|
355
|
+
const ref = useRef(null);
|
|
356
|
+
useLayoutEffect(() => {
|
|
357
|
+
if (!isSelected)
|
|
358
|
+
return;
|
|
359
|
+
ref.current?.focus({ preventScroll: true });
|
|
360
|
+
}, [isSelected]);
|
|
361
|
+
return {
|
|
362
|
+
ref,
|
|
363
|
+
tabIndex: isSelected ? 0 : -1
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
const initialState = {
|
|
367
|
+
activeFilters: false,
|
|
368
|
+
setActiveFilters: voidFunction
|
|
369
|
+
};
|
|
370
|
+
const FilterContext = createContext(initialState);
|
|
371
|
+
function FilterProvider({
|
|
372
|
+
children,
|
|
373
|
+
initialActiveFilters
|
|
374
|
+
}) {
|
|
375
|
+
const [filterOptions, setFilterOptions] = useState({
|
|
376
|
+
activeFilters: initialActiveFilters
|
|
377
|
+
});
|
|
378
|
+
const onChangeFilter = (column, value) => {
|
|
379
|
+
const newMap = filterOptions.filters ? new Map(filterOptions.filters) : /* @__PURE__ */ new Map();
|
|
380
|
+
if (value !== "") {
|
|
381
|
+
newMap.set(column.key, {
|
|
382
|
+
value,
|
|
383
|
+
customFilter: column.customFilter
|
|
384
|
+
});
|
|
385
|
+
} else {
|
|
386
|
+
newMap.delete(column.key);
|
|
387
|
+
}
|
|
388
|
+
setFilterOptions({
|
|
389
|
+
...filterOptions,
|
|
390
|
+
filters: newMap
|
|
391
|
+
});
|
|
392
|
+
};
|
|
393
|
+
const setActiveFilters = (active) => {
|
|
394
|
+
if (active) {
|
|
395
|
+
setFilterOptions({
|
|
396
|
+
activeFilters: true,
|
|
397
|
+
filters: /* @__PURE__ */ new Map()
|
|
398
|
+
});
|
|
399
|
+
} else {
|
|
400
|
+
setFilterOptions({
|
|
401
|
+
activeFilters: false
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
return /* @__PURE__ */ jsx(FilterContext.Provider, {
|
|
406
|
+
value: {
|
|
407
|
+
...filterOptions,
|
|
408
|
+
onChangeFilter,
|
|
409
|
+
setActiveFilters
|
|
410
|
+
},
|
|
411
|
+
children
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
const useFilters = () => useContext(FilterContext);
|
|
415
|
+
function DraggableHeaderRenderer(props) {
|
|
416
|
+
const {
|
|
417
|
+
onColumnsReorder,
|
|
418
|
+
column,
|
|
419
|
+
isCellSelected,
|
|
420
|
+
...others
|
|
421
|
+
} = props;
|
|
422
|
+
const {
|
|
423
|
+
ref,
|
|
424
|
+
tabIndex
|
|
425
|
+
} = useFocusRef(isCellSelected);
|
|
426
|
+
const {
|
|
427
|
+
getLabel
|
|
428
|
+
} = useModuleDictionary();
|
|
429
|
+
const {
|
|
430
|
+
activeFilters,
|
|
431
|
+
filters,
|
|
432
|
+
onChangeFilter
|
|
433
|
+
} = useFilters();
|
|
434
|
+
const [filter, setFilter] = useState(filters?.get(column.key) || "");
|
|
435
|
+
const [{
|
|
436
|
+
isDragging
|
|
437
|
+
}, drag] = useDrag({
|
|
438
|
+
type: "COLUMN_DRAG",
|
|
439
|
+
item: {
|
|
440
|
+
key: column.key
|
|
441
|
+
},
|
|
442
|
+
collect: (monitor) => ({
|
|
443
|
+
isDragging: monitor.isDragging()
|
|
444
|
+
})
|
|
445
|
+
});
|
|
446
|
+
const [{
|
|
447
|
+
isOver
|
|
448
|
+
}, drop] = useDrop({
|
|
449
|
+
accept: "COLUMN_DRAG",
|
|
450
|
+
drop({
|
|
451
|
+
key
|
|
452
|
+
}) {
|
|
453
|
+
onColumnsReorder(key, column.key);
|
|
454
|
+
},
|
|
455
|
+
collect: (monitor) => ({
|
|
456
|
+
isOver: monitor.isOver(),
|
|
457
|
+
canDrop: monitor.canDrop()
|
|
458
|
+
})
|
|
459
|
+
});
|
|
460
|
+
const handleChange = (e) => {
|
|
461
|
+
if (activeFilters) {
|
|
462
|
+
if (onChangeFilter)
|
|
463
|
+
onChangeFilter(column, e.target.value);
|
|
464
|
+
}
|
|
465
|
+
setFilter(e.target.value);
|
|
466
|
+
};
|
|
467
|
+
useEffect(() => {
|
|
468
|
+
if (!activeFilters)
|
|
469
|
+
setFilter("");
|
|
470
|
+
}, [activeFilters]);
|
|
471
|
+
const newColumn = {
|
|
472
|
+
...column
|
|
473
|
+
};
|
|
474
|
+
if (newColumn.withinHeaderRenderer) {
|
|
475
|
+
newColumn.name = newColumn.withinHeaderRenderer(props);
|
|
476
|
+
}
|
|
477
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
478
|
+
ref: (newRef) => {
|
|
479
|
+
drag(newRef);
|
|
480
|
+
drop(newRef);
|
|
481
|
+
},
|
|
482
|
+
style: {
|
|
483
|
+
opacity: isDragging ? 0.5 : 1,
|
|
484
|
+
backgroundColor: isOver ? "#ececec" : void 0,
|
|
485
|
+
cursor: "move",
|
|
486
|
+
display: "flex",
|
|
487
|
+
flexDirection: "column",
|
|
488
|
+
lineHeight: "1",
|
|
489
|
+
height: "100%",
|
|
490
|
+
justifyContent: "center",
|
|
491
|
+
textAlign: "center"
|
|
492
|
+
},
|
|
493
|
+
children: [/* @__PURE__ */ jsx(HeaderRenderer, {
|
|
494
|
+
column: newColumn,
|
|
495
|
+
isCellSelected,
|
|
496
|
+
...others
|
|
497
|
+
}), activeFilters && (column?.withFilter === void 0 || column.withFilter === true) && /* @__PURE__ */ jsx("div", {
|
|
498
|
+
className: "filter_cell_div",
|
|
499
|
+
style: {
|
|
500
|
+
borderTop: "1px solid var(--rdg-border-color)",
|
|
501
|
+
width: "100%",
|
|
502
|
+
display: "flex",
|
|
503
|
+
alignItems: "center",
|
|
504
|
+
height: `${filterHeight}px`
|
|
505
|
+
},
|
|
506
|
+
children: /* @__PURE__ */ jsx(InputBase, {
|
|
507
|
+
inputRef: ref,
|
|
508
|
+
placeholder: getLabel("data_grid.filter_holder"),
|
|
509
|
+
style: {
|
|
510
|
+
width: "100%",
|
|
511
|
+
paddingBottom: "2px",
|
|
512
|
+
border: "1px solid var(--rdg-border-color)"
|
|
513
|
+
},
|
|
514
|
+
tabIndex,
|
|
515
|
+
type: "text",
|
|
516
|
+
onChange: handleChange,
|
|
517
|
+
value: filter
|
|
518
|
+
})
|
|
519
|
+
})]
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
const getDragHeaderRenderer = (handleColumnsReorder) => {
|
|
523
|
+
function HeaderRenderer2(props) {
|
|
524
|
+
return /* @__PURE__ */ jsx(DraggableHeaderRenderer, {
|
|
525
|
+
...props,
|
|
526
|
+
onColumnsReorder: handleColumnsReorder
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
return HeaderRenderer2;
|
|
530
|
+
};
|
|
531
|
+
const WrapperSkeleton = styled("div")(() => ({
|
|
532
|
+
display: "flex",
|
|
533
|
+
width: "100%",
|
|
534
|
+
height: "100%",
|
|
535
|
+
alignItems: "center"
|
|
536
|
+
}));
|
|
537
|
+
function SkeletonFormatter() {
|
|
538
|
+
const {
|
|
539
|
+
classes
|
|
540
|
+
} = useDataGrid();
|
|
541
|
+
return /* @__PURE__ */ jsx(WrapperSkeleton, {
|
|
542
|
+
className: classes.skeletonFormatter,
|
|
543
|
+
children: /* @__PURE__ */ jsx(Skeleton, {
|
|
544
|
+
variant: "text",
|
|
545
|
+
width: "100%",
|
|
546
|
+
height: "12px"
|
|
547
|
+
})
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
function getComparator(columns, sortColumn) {
|
|
551
|
+
const column = columns.find((d) => d.key === sortColumn);
|
|
552
|
+
let typeOrder = "string";
|
|
553
|
+
if (column) {
|
|
554
|
+
typeOrder = column.type || "string";
|
|
555
|
+
}
|
|
556
|
+
switch (typeOrder) {
|
|
557
|
+
case "number":
|
|
558
|
+
return (a, b) => {
|
|
559
|
+
try {
|
|
560
|
+
return Number(a[sortColumn]) - Number(b[sortColumn]);
|
|
561
|
+
} catch (error) {
|
|
562
|
+
return -1;
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
default:
|
|
566
|
+
return (a, b) => {
|
|
567
|
+
try {
|
|
568
|
+
return a[sortColumn].toString().localeCompare(b[sortColumn].toString());
|
|
569
|
+
} catch (error) {
|
|
570
|
+
return -1;
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
const getColumIndex = (key, columnsConfig) => columnsConfig.findIndex((columnConfig) => columnConfig.key === key);
|
|
576
|
+
const getInOrderColumns = (columns, hasCheckedRows, columnsConfig, columnsWidths, rowActionsGetter) => {
|
|
577
|
+
let filteredSortedColumns = columns.filter((column) => {
|
|
578
|
+
const columnConfigIndex = getColumIndex(column.key, columnsConfig);
|
|
579
|
+
const visible = columnConfigIndex > -1 ? columnsConfig[columnConfigIndex].visible : true;
|
|
580
|
+
return !column.hidden && visible;
|
|
581
|
+
}).sort(
|
|
582
|
+
(a, b) => getColumIndex(a.key, columnsConfig) - getColumIndex(b.key, columnsConfig)
|
|
583
|
+
).map((columnSorted) => {
|
|
584
|
+
const columnConfigIndex = getColumIndex(columnSorted.key, columnsConfig);
|
|
585
|
+
return {
|
|
586
|
+
...columnSorted,
|
|
587
|
+
frozen: columnConfigIndex > -1 ? columnsConfig[columnConfigIndex].frozen : true,
|
|
588
|
+
width: typeof columnsWidths.get(columnSorted.key) === "number" ? columnsWidths.get(columnSorted.key) : columnSorted.width
|
|
589
|
+
};
|
|
590
|
+
}).sort((a, b) => {
|
|
591
|
+
const order = (a.frozen === void 0 || a.frozen === false) === (b.frozen === void 0 || b.frozen === false) ? 0 : a.frozen ? -1 : 1;
|
|
592
|
+
return order;
|
|
593
|
+
});
|
|
594
|
+
if (rowActionsGetter) {
|
|
595
|
+
filteredSortedColumns = [ActionsColumn, ...filteredSortedColumns];
|
|
596
|
+
}
|
|
597
|
+
if (hasCheckedRows) {
|
|
598
|
+
filteredSortedColumns = [SelectColumn, ...filteredSortedColumns];
|
|
599
|
+
}
|
|
600
|
+
return filteredSortedColumns;
|
|
601
|
+
};
|
|
602
|
+
const getAligByType = (columnType) => {
|
|
603
|
+
switch (columnType) {
|
|
604
|
+
case "string":
|
|
605
|
+
return "left";
|
|
606
|
+
case "date":
|
|
607
|
+
case "boolean":
|
|
608
|
+
case "custom":
|
|
609
|
+
return "center";
|
|
610
|
+
case "number":
|
|
611
|
+
return "right";
|
|
612
|
+
}
|
|
613
|
+
return "left";
|
|
614
|
+
};
|
|
615
|
+
const useSortColumnsRows = (sourceColumns, sourceRows) => {
|
|
616
|
+
const {
|
|
617
|
+
columnsConfig,
|
|
618
|
+
columnsWidths,
|
|
619
|
+
onChangeColumnsOrder,
|
|
620
|
+
rowActionsGetter,
|
|
621
|
+
checkedRows,
|
|
622
|
+
onCheckedRowsChange
|
|
623
|
+
} = useDataGrid();
|
|
624
|
+
const [columns, setColumns] = useState(() => []);
|
|
625
|
+
const [sortColumns, setSortColumns] = useState([]);
|
|
626
|
+
const isSkeleton = useModuleSkeleton();
|
|
627
|
+
const { activeFilters, filters } = useFilters();
|
|
628
|
+
const findKeyInColumns = (key, cols) => {
|
|
629
|
+
const index = cols.findIndex((column) => key === column.key && column.hidden === false);
|
|
630
|
+
return index !== -1;
|
|
631
|
+
};
|
|
632
|
+
useEffect(() => {
|
|
633
|
+
setColumns(
|
|
634
|
+
getInOrderColumns(
|
|
635
|
+
sourceColumns,
|
|
636
|
+
!!checkedRows && !!onCheckedRowsChange,
|
|
637
|
+
columnsConfig,
|
|
638
|
+
columnsWidths,
|
|
639
|
+
rowActionsGetter
|
|
640
|
+
)
|
|
641
|
+
);
|
|
642
|
+
const finalSortedColumns = sortColumns.filter(
|
|
643
|
+
(sortColumn) => findKeyInColumns(sortColumn.columnKey, sourceColumns)
|
|
644
|
+
);
|
|
645
|
+
if (JSON.stringify(finalSortedColumns) !== JSON.stringify(sortColumns)) {
|
|
646
|
+
setSortColumns(finalSortedColumns);
|
|
647
|
+
}
|
|
648
|
+
}, [sourceColumns, columnsConfig, rowActionsGetter]);
|
|
649
|
+
const finalColumns = useMemo(() => {
|
|
650
|
+
const DragAndDropHeaderRenderer = getDragHeaderRenderer(onChangeColumnsOrder);
|
|
651
|
+
return columns.map((c) => {
|
|
652
|
+
const newColumn = {
|
|
653
|
+
...c,
|
|
654
|
+
cellClass: c.align !== void 0 ? `rdg-cell-align-${c.align}` : `rdg-cell-align-${getAligByType(c.type)}`
|
|
655
|
+
};
|
|
656
|
+
if (newColumn.key === SELECT_COLUMN_KEY || newColumn.isDraggable !== void 0 && newColumn.isDraggable === false)
|
|
657
|
+
return newColumn;
|
|
658
|
+
if (isSkeleton) {
|
|
659
|
+
newColumn.headerRenderer = SkeletonFormatter;
|
|
660
|
+
newColumn.formatter = SkeletonFormatter;
|
|
661
|
+
}
|
|
662
|
+
if (newColumn.headerRenderer) {
|
|
663
|
+
newColumn.withinHeaderRenderer = newColumn.headerRenderer;
|
|
664
|
+
}
|
|
665
|
+
if ((newColumn?.withFilter === void 0 || newColumn.withFilter === true) && activeFilters) {
|
|
666
|
+
newColumn.headerCellClass = filterColumnClassName;
|
|
667
|
+
}
|
|
668
|
+
newColumn.headerRenderer = DragAndDropHeaderRenderer;
|
|
669
|
+
return newColumn;
|
|
670
|
+
});
|
|
671
|
+
}, [isSkeleton, columns, activeFilters, onChangeColumnsOrder]);
|
|
672
|
+
const finalRows = useMemo(() => {
|
|
673
|
+
const nextRows = sourceRows.filter((r) => {
|
|
674
|
+
if (!filters || filters.size === 0)
|
|
675
|
+
return true;
|
|
676
|
+
const iterator = filters.entries();
|
|
677
|
+
let valReturn = true;
|
|
678
|
+
for (let i = 0; i < filters.size; i++) {
|
|
679
|
+
const entry = iterator.next().value;
|
|
680
|
+
const columnKey = entry[0];
|
|
681
|
+
const columnFilter = entry[1];
|
|
682
|
+
let valCell;
|
|
683
|
+
try {
|
|
684
|
+
if (columnFilter.customFilter) {
|
|
685
|
+
valReturn = valReturn && columnFilter.customFilter(r, columnFilter.value);
|
|
686
|
+
} else {
|
|
687
|
+
valCell = getPropertyByString(r, columnKey) || "";
|
|
688
|
+
valReturn = valReturn && valCell.includes(columnFilter.value);
|
|
689
|
+
}
|
|
690
|
+
} catch (error) {
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
if (!valReturn)
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
return valReturn;
|
|
697
|
+
});
|
|
698
|
+
if (sortColumns.length === 0) {
|
|
699
|
+
return nextRows;
|
|
700
|
+
}
|
|
701
|
+
nextRows.sort((a, b) => {
|
|
702
|
+
for (const sort of sortColumns) {
|
|
703
|
+
const comparator = getComparator(columns, sort.columnKey);
|
|
704
|
+
const compResult = comparator(a, b);
|
|
705
|
+
if (compResult !== 0) {
|
|
706
|
+
return sort.direction === "ASC" ? compResult : -compResult;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return 0;
|
|
710
|
+
});
|
|
711
|
+
return nextRows;
|
|
712
|
+
}, [sourceRows, sortColumns, filters]);
|
|
713
|
+
return { finalColumns, sortColumns, setSortColumns, finalRows };
|
|
714
|
+
};
|
|
715
|
+
function Table(props) {
|
|
716
|
+
const {
|
|
717
|
+
columns,
|
|
718
|
+
rows,
|
|
719
|
+
onRowsChange,
|
|
720
|
+
rowKeyGetter,
|
|
721
|
+
selectedRows,
|
|
722
|
+
onSelectedRowsChange
|
|
723
|
+
} = props;
|
|
724
|
+
const {
|
|
725
|
+
finalColumns,
|
|
726
|
+
sortColumns,
|
|
727
|
+
setSortColumns,
|
|
728
|
+
finalRows
|
|
729
|
+
} = useSortColumnsRows(columns, rows);
|
|
730
|
+
const {
|
|
731
|
+
activeFilters
|
|
732
|
+
} = useFilters();
|
|
733
|
+
const {
|
|
734
|
+
onChangeColumnWidth,
|
|
735
|
+
setRowsCount,
|
|
736
|
+
currentRowHeight,
|
|
737
|
+
currentRowHeaderHeight,
|
|
738
|
+
classes
|
|
739
|
+
} = useDataGrid();
|
|
740
|
+
const ref_data_grid = useRef(null);
|
|
741
|
+
const onRowClick = (row) => {
|
|
742
|
+
if (selectedRows && onSelectedRowsChange) {
|
|
743
|
+
if (selectedRows.entries().next().value) {
|
|
744
|
+
if (selectedRows.entries().next().value[1] === rowKeyGetter(row)) {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
const mySet = /* @__PURE__ */ new Set([rowKeyGetter(row)]);
|
|
749
|
+
onSelectedRowsChange(mySet);
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
useEffect(() => {
|
|
753
|
+
let columnIndice = 0;
|
|
754
|
+
for (const column of finalColumns) {
|
|
755
|
+
const index = sortColumns.findIndex((sortColumn) => column.key === sortColumn.columnKey);
|
|
756
|
+
if (index !== -1) {
|
|
757
|
+
ref_data_grid.current?.element?.querySelector(`[role="columnheader"][aria-colindex="${columnIndice + 1}"]`)?.setAttribute("aria-columnsort", `${sortColumns[index].direction}`);
|
|
758
|
+
} else {
|
|
759
|
+
ref_data_grid.current?.element?.querySelector(`[role="columnheader"][aria-colindex="${columnIndice + 1}"]`)?.removeAttribute("aria-columnsort");
|
|
760
|
+
}
|
|
761
|
+
columnIndice++;
|
|
762
|
+
}
|
|
763
|
+
}, [sortColumns, finalColumns]);
|
|
764
|
+
useEffect(() => {
|
|
765
|
+
setRowsCount(finalRows.length);
|
|
766
|
+
}, [finalRows]);
|
|
767
|
+
const onColumnResize = (idx, width) => {
|
|
768
|
+
onChangeColumnWidth(finalColumns[idx].key, width);
|
|
769
|
+
};
|
|
770
|
+
const onChangeSort = (newSortColumns) => {
|
|
771
|
+
setSortColumns(newSortColumns);
|
|
772
|
+
};
|
|
773
|
+
return /* @__PURE__ */ jsx("div", {
|
|
774
|
+
className: classes.tableContaniner,
|
|
775
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
776
|
+
className: classes.wrapperDataGridCss,
|
|
777
|
+
children: /* @__PURE__ */ jsx(DndProvider, {
|
|
778
|
+
backend: HTML5Backend,
|
|
779
|
+
context: window,
|
|
780
|
+
children: /* @__PURE__ */ jsx(DataGrid$1, {
|
|
781
|
+
className: "fill-grid rdg-light",
|
|
782
|
+
ref: ref_data_grid,
|
|
783
|
+
headerRowHeight: activeFilters ? currentRowHeaderHeight + filterHeight : currentRowHeaderHeight,
|
|
784
|
+
columns: finalColumns,
|
|
785
|
+
sortColumns,
|
|
786
|
+
onSortColumnsChange: onChangeSort,
|
|
787
|
+
onColumnResize,
|
|
788
|
+
rows: finalRows,
|
|
789
|
+
onRowsChange,
|
|
790
|
+
selectedRows,
|
|
791
|
+
onSelectedRowsChange,
|
|
792
|
+
onRowClick,
|
|
793
|
+
rowHeight: currentRowHeight,
|
|
794
|
+
rowKeyGetter,
|
|
795
|
+
cellNavigationMode: "LOOP_OVER_ROW",
|
|
796
|
+
components: {
|
|
797
|
+
checkboxFormatter: CheckboxFormatter
|
|
798
|
+
},
|
|
799
|
+
defaultColumnOptions: {
|
|
800
|
+
resizable: true,
|
|
801
|
+
sortable: true
|
|
802
|
+
}
|
|
803
|
+
})
|
|
804
|
+
})
|
|
805
|
+
})
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
const componentName = "M4LDataGrid";
|
|
809
|
+
const dataGridClasses = generateUtilityClasses(componentName, [
|
|
810
|
+
"root",
|
|
811
|
+
"actions",
|
|
812
|
+
"withPager",
|
|
813
|
+
"withNoPager",
|
|
814
|
+
"rowsCount",
|
|
815
|
+
"rowsCountLabel",
|
|
816
|
+
"rowsCountValue",
|
|
817
|
+
"densitySkeleton",
|
|
818
|
+
"actionDensityPopover",
|
|
819
|
+
"actionFilter",
|
|
820
|
+
"actionSettings",
|
|
821
|
+
"tableContaniner",
|
|
822
|
+
"wrapperDataGridCss",
|
|
823
|
+
"columnsConfigContainer",
|
|
824
|
+
"columnsLabelSetColumns",
|
|
825
|
+
"columnsConfigContent",
|
|
826
|
+
"columnsConfigGrid",
|
|
827
|
+
"columnsConfigActions",
|
|
828
|
+
"formatterColumn",
|
|
829
|
+
"skeletonFormatter",
|
|
830
|
+
"actionsFormatter",
|
|
831
|
+
"withActions"
|
|
832
|
+
]);
|
|
833
|
+
function getDataGridUtilityClass(slot) {
|
|
834
|
+
return generateUtilityClass(componentName, slot);
|
|
835
|
+
}
|
|
836
|
+
const dataGridUtilityClasses = (ownerState) => {
|
|
837
|
+
const slots = {
|
|
838
|
+
root: ["root"],
|
|
839
|
+
actions: ["actions", ownerState.actionsProps.withPager ? "withPager" : "withNoPager"],
|
|
840
|
+
rowsCount: ["rowsCount"],
|
|
841
|
+
rowsCountLabel: ["rowsCountLabel"],
|
|
842
|
+
rowsCountValue: ["rowsCountValue"],
|
|
843
|
+
densitySkeleton: ["densitySkeleton"],
|
|
844
|
+
densityRoot: ["densityRoot"],
|
|
845
|
+
densityPopover: ["densityPopover"],
|
|
846
|
+
actionFilter: ["actionFilter"],
|
|
847
|
+
actionSettings: ["actionSettingsRoot"],
|
|
848
|
+
actionDensityPopover: ["actionDensityPopover"],
|
|
849
|
+
tableContaniner: ["tableContaniner", ownerState.withActions && "withActions"],
|
|
850
|
+
wrapperDataGridCss: ["wrapperDataGridCss"],
|
|
851
|
+
columnsConfigContainer: ["columnsConfigContainer"],
|
|
852
|
+
columnsLabelSetColumns: ["columnsLabelSetColumns"],
|
|
853
|
+
columnsConfigContent: ["columnsConfigContent"],
|
|
854
|
+
columnsConfigGrid: ["columnsConfigGrid"],
|
|
855
|
+
columnsConfigActions: ["columnsConfigActions"],
|
|
856
|
+
formatterColumn: ["formatterColumn"],
|
|
857
|
+
skeletonFormatter: ["skeletonFormatter"],
|
|
858
|
+
actionsFormatter: ["actionsFormatter"]
|
|
859
|
+
};
|
|
860
|
+
const composedClasses = unstable_composeClasses(slots, getDataGridUtilityClass, {});
|
|
861
|
+
return {
|
|
862
|
+
...composedClasses
|
|
863
|
+
};
|
|
864
|
+
};
|
|
865
|
+
function getDataGridComponentsDictionary() {
|
|
866
|
+
return ["data_grid"].concat(getPagerComponentsDictionary()).concat(getModalDialogComponentsDictionary());
|
|
867
|
+
}
|
|
868
|
+
const dictionary = {
|
|
869
|
+
LABEL_ACTIONS: "actions",
|
|
870
|
+
LABEL_ROWS_PER_PAGE: "pager.rows_per_page",
|
|
871
|
+
LABEL_OF: "pager.of"
|
|
872
|
+
};
|
|
873
|
+
const DATAGRID_TEST_ID = "m4ldatagrid";
|
|
874
|
+
const PREFIX_TEST_ATTRIBUTE = "data-testid";
|
|
875
|
+
const TEST_PROP_COLUMNS = `${PREFIX_TEST_ATTRIBUTE}-${DATAGRID_TEST_ID}-columns`;
|
|
876
|
+
function DataGrid(props) {
|
|
877
|
+
const {
|
|
878
|
+
id,
|
|
879
|
+
withActions = true,
|
|
880
|
+
rows,
|
|
881
|
+
columns,
|
|
882
|
+
actionsProps,
|
|
883
|
+
selectedRows,
|
|
884
|
+
onSelectedRowsChange,
|
|
885
|
+
rowKeyGetter,
|
|
886
|
+
rowActionsGetter,
|
|
887
|
+
onRowsChange,
|
|
888
|
+
rowHeaderHeights,
|
|
889
|
+
rowHeights,
|
|
890
|
+
initialRowHeightVariant,
|
|
891
|
+
checkedRows,
|
|
892
|
+
onCheckedRowsChange,
|
|
893
|
+
dataTestId
|
|
894
|
+
} = props;
|
|
895
|
+
const ownerState = {
|
|
896
|
+
actionsProps,
|
|
897
|
+
withActions
|
|
898
|
+
};
|
|
899
|
+
const classes = dataGridUtilityClasses(ownerState);
|
|
900
|
+
return /* @__PURE__ */ jsx(DataGridRoot, {
|
|
901
|
+
id: `WrapperGrid_${props.id}`,
|
|
902
|
+
className: classes.root,
|
|
903
|
+
...process.env.NODE_ENV !== "production" ? {
|
|
904
|
+
[TEST_PROP_COLUMNS]: JSON.stringify(columns),
|
|
905
|
+
[PREFIX_TEST_ATTRIBUTE]: `m4ldatagrid-${dataTestId}`
|
|
906
|
+
} : {},
|
|
907
|
+
children: /* @__PURE__ */ jsx(DataGridProvider, {
|
|
908
|
+
id: props.id,
|
|
909
|
+
columns: props.columns,
|
|
910
|
+
rowHeights,
|
|
911
|
+
rowHeaderHeights,
|
|
912
|
+
initialRowHeightVariant,
|
|
913
|
+
rowsCount: rows.length,
|
|
914
|
+
checkedRows,
|
|
915
|
+
rowActionsGetter,
|
|
916
|
+
onCheckedRowsChange,
|
|
917
|
+
rowKeyGetter,
|
|
918
|
+
rows,
|
|
919
|
+
classes,
|
|
920
|
+
children: /* @__PURE__ */ jsxs(FilterProvider, {
|
|
921
|
+
initialActiveFilters: false,
|
|
922
|
+
children: [withActions && actionsProps && /* @__PURE__ */ jsx(Actions, {
|
|
923
|
+
...actionsProps
|
|
924
|
+
}), /* @__PURE__ */ jsx(Table, {
|
|
925
|
+
id,
|
|
926
|
+
withActions,
|
|
927
|
+
columns,
|
|
928
|
+
rows,
|
|
929
|
+
selectedRows,
|
|
930
|
+
onSelectedRowsChange,
|
|
931
|
+
rowKeyGetter,
|
|
932
|
+
onRowsChange
|
|
933
|
+
})]
|
|
934
|
+
})
|
|
935
|
+
})
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
function columnBooleanFormatter(props) {
|
|
939
|
+
const {
|
|
940
|
+
fieldValue,
|
|
941
|
+
presentationType,
|
|
942
|
+
Component
|
|
943
|
+
} = props;
|
|
944
|
+
return (obProps) => {
|
|
945
|
+
return /* @__PURE__ */ jsx(BooleanFormatter, {
|
|
946
|
+
presentationType,
|
|
947
|
+
value: getPropertyByString(obProps, fieldValue),
|
|
948
|
+
Component
|
|
949
|
+
});
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
function columnDateFormatter(props) {
|
|
953
|
+
const {
|
|
954
|
+
fieldValue,
|
|
955
|
+
presentationType,
|
|
956
|
+
Component
|
|
957
|
+
} = props;
|
|
958
|
+
return (obProps) => {
|
|
959
|
+
return /* @__PURE__ */ jsx(DateFormatter, {
|
|
960
|
+
presentationType,
|
|
961
|
+
value: getPropertyByString(obProps, fieldValue),
|
|
962
|
+
Component
|
|
963
|
+
});
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
function columnConcatenatedValuesFormatter(props) {
|
|
967
|
+
const {
|
|
968
|
+
fieldValue,
|
|
969
|
+
fieldSeparator,
|
|
970
|
+
Component
|
|
971
|
+
} = props;
|
|
972
|
+
return (obProps) => {
|
|
973
|
+
const values = fieldValue.map((element) => getPropertyByString(obProps, element));
|
|
974
|
+
return /* @__PURE__ */ jsx(ConcatenatedFormatter, {
|
|
975
|
+
values,
|
|
976
|
+
separator: fieldSeparator,
|
|
977
|
+
Component
|
|
978
|
+
});
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
const getDataGridRowsFromSet = (set, rows, rowKeyGetter) => {
|
|
982
|
+
const rowsFinded = [];
|
|
983
|
+
if (set) {
|
|
984
|
+
if (set.size > 0) {
|
|
985
|
+
const iterator = set.entries();
|
|
986
|
+
for (let i = 0; i < set.size; i++) {
|
|
987
|
+
const entry = iterator.next().value;
|
|
988
|
+
const key = entry[1];
|
|
989
|
+
const row = rows.find((frow) => rowKeyGetter(frow) === key);
|
|
990
|
+
if (row) {
|
|
991
|
+
rowsFinded.push(row);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return rowsFinded;
|
|
997
|
+
};
|
|
998
|
+
export {
|
|
999
|
+
DataGrid as D,
|
|
1000
|
+
useFilters as a,
|
|
1001
|
+
dictionary as b,
|
|
1002
|
+
getDataGridRowsFromSet as c,
|
|
1003
|
+
dataGridClasses as d,
|
|
1004
|
+
columnBooleanFormatter as e,
|
|
1005
|
+
columnDateFormatter as f,
|
|
1006
|
+
getDataGridComponentsDictionary as g,
|
|
1007
|
+
columnConcatenatedValuesFormatter as h,
|
|
1008
|
+
useDataGrid as u
|
|
1009
|
+
};
|