@m4l/components 9.2.17 → 9.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/DataGrid/contexts/DataGridContext/index.js +18 -3
- package/components/DataGrid/subcomponents/Table/hooks/useSortColumnsRows.js +8 -5
- package/package.json +2 -2
- package/storybook/components/DataGrid/DataGrid.stories.d.ts +1 -0
- package/storybook/components/DataGrid/subcomponents/DataGridRender.d.ts +1 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useState, useMemo, useEffect, useCallback } from "react";
|
|
3
3
|
import { c as castMapColumnsWidthToRecord } from "../../helpers/castMapColumnsWidthToRecord.js";
|
|
4
|
+
import { useFirstRender } from "@m4l/graphics";
|
|
4
5
|
const DataGridContext = createContext(null);
|
|
5
6
|
const getColumnConfigByKey = (key, storeColumnsConfig) => {
|
|
6
7
|
let indexFind = -1;
|
|
@@ -114,6 +115,7 @@ function DataGridProvider(props) {
|
|
|
114
115
|
rowKeyGetter,
|
|
115
116
|
onChangeUserColumns
|
|
116
117
|
} = props;
|
|
118
|
+
const isFirstRender = useFirstRender();
|
|
117
119
|
const [columnsWidths, setColumnsWidths] = useState(
|
|
118
120
|
/* @__PURE__ */ new Map()
|
|
119
121
|
);
|
|
@@ -145,9 +147,22 @@ function DataGridProvider(props) {
|
|
|
145
147
|
const finalRowHeights = useMemo(() => rowHeights, [rowHeights]);
|
|
146
148
|
let timerSaveColumns;
|
|
147
149
|
useEffect(() => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
if (isFirstRender) {
|
|
151
|
+
setColumnsWidths(getColumnsWidth(id, columns, defaultUserColumns));
|
|
152
|
+
setColumnsConfigOptions(getColumnsConfig(id, columns, defaultUserColumns));
|
|
153
|
+
}
|
|
154
|
+
}, [defaultUserColumns]);
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
if (!isFirstRender) {
|
|
157
|
+
const newColumns = columns.filter((column, index) => column.key !== columnsConfig[index]?.key);
|
|
158
|
+
const newColConfig = getColumnsConfig(id, newColumns).map((column, index) => {
|
|
159
|
+
const indexNewCol = index + columnsConfig.length;
|
|
160
|
+
return { ...column, index: indexNewCol, orginalIndex: indexNewCol };
|
|
161
|
+
});
|
|
162
|
+
columnsConfig.push(...newColConfig);
|
|
163
|
+
setColumnsWidths((prevColumnsWidth) => new Map([...prevColumnsWidth, ...getColumnsWidth(id, newColumns, defaultUserColumns)]));
|
|
164
|
+
}
|
|
165
|
+
}, [columns, id]);
|
|
151
166
|
const onChangeColumnsConfig = useCallback(
|
|
152
167
|
(newColumnsConfig) => {
|
|
153
168
|
saveColumnsConfig(id, newColumnsConfig, onChangeUserColumns);
|
|
@@ -42,15 +42,18 @@ const getInOrderColumns = (columns, hasCheckedRows, columnsConfig, columnsWidths
|
|
|
42
42
|
const visible = columnConfigIndex > -1 ? columnsConfig[columnConfigIndex].visible : true;
|
|
43
43
|
return !column.hidden && visible;
|
|
44
44
|
}).sort(
|
|
45
|
-
(a, b) =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
(a, b) => {
|
|
46
|
+
let indexA = getColumIndex(a.key, columnsConfig);
|
|
47
|
+
indexA = indexA === -1 ? columnsConfig.length : indexA;
|
|
48
|
+
let indexB = getColumIndex(b.key, columnsConfig);
|
|
49
|
+
indexB = indexB === -1 ? columnsConfig.length : indexB;
|
|
50
|
+
return indexA - indexB;
|
|
51
|
+
}
|
|
49
52
|
).map((columnSorted) => {
|
|
50
53
|
const columnConfigIndex = getColumIndex(columnSorted.key, columnsConfig);
|
|
51
54
|
return {
|
|
52
55
|
...columnSorted,
|
|
53
|
-
frozen: columnConfigIndex > -1 ? columnsConfig[columnConfigIndex].frozen :
|
|
56
|
+
frozen: columnConfigIndex > -1 ? columnsConfig[columnConfigIndex].frozen : false,
|
|
54
57
|
width: typeof columnsWidths.get(columnSorted.key) === "number" ? columnsWidths.get(columnSorted.key) : columnSorted.width
|
|
55
58
|
};
|
|
56
59
|
}).sort((a, b) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m4l/components",
|
|
3
|
-
"version": "9.2.
|
|
3
|
+
"version": "9.2.18",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"lint-staged": {
|
|
6
6
|
"*.{js,ts,tsx}": "eslint --fix --max-warnings 0 --no-warn-ignored"
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"react-dom": "^18.0.0",
|
|
68
68
|
"storybook": "^8.3.4",
|
|
69
69
|
"attr-accept": "2.2.2",
|
|
70
|
-
"@vitejs/plugin-react": "
|
|
70
|
+
"@vitejs/plugin-react": "4.3.4"
|
|
71
71
|
},
|
|
72
72
|
"overrides": {
|
|
73
73
|
"glob": "^10.4.5",
|