@m4l/components 9.3.21 → 9.3.22-JT22102025.beta.1
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/DataGrid.js +9 -4
- package/components/DataGrid/Datagrid.styles.js +270 -0
- package/components/DataGrid/constants.js +2 -2
- package/components/DataGrid/contexts/DataGridContext/index.js +322 -112
- package/components/DataGrid/contexts/DataGridContext/types.d.ts +63 -4
- package/components/DataGrid/dictionary.d.ts +5 -0
- package/components/DataGrid/dictionary.js +6 -1
- package/components/DataGrid/formatters/ColumnSetCheckFormatter/formatter.js +2 -2
- package/components/DataGrid/hooks/useModalCardDetail.d.ts +6 -0
- package/components/DataGrid/hooks/useModalCardDetail.js +74 -0
- package/components/DataGrid/hooks/useProcessedColumns.d.ts +50 -0
- package/components/DataGrid/hooks/useProcessedColumns.js +44 -0
- package/components/DataGrid/icons.d.ts +7 -0
- package/components/DataGrid/icons.js +5 -1
- package/components/DataGrid/index.d.ts +1 -1
- package/components/DataGrid/slots/DataGridEnum.d.ts +22 -1
- package/components/DataGrid/slots/DataGridEnum.js +21 -0
- package/components/DataGrid/slots/DataGridSlot.d.ts +24 -0
- package/components/DataGrid/slots/DataGridSlot.js +123 -21
- package/components/DataGrid/subcomponents/Cards/hooks/useCardContent.d.ts +9 -0
- package/components/DataGrid/subcomponents/Cards/hooks/useCardContent.js +91 -0
- package/components/DataGrid/subcomponents/Cards/index.d.ts +5 -0
- package/components/DataGrid/subcomponents/Cards/index.js +40 -0
- package/components/DataGrid/subcomponents/Cards/subcomponents/CardDetails/index.d.ts +8 -0
- package/components/DataGrid/subcomponents/Cards/subcomponents/CardDetails/index.js +79 -0
- package/components/DataGrid/subcomponents/Cards/subcomponents/CardHeader/index.d.ts +7 -0
- package/components/DataGrid/subcomponents/Cards/subcomponents/CardHeader/index.js +98 -0
- package/components/DataGrid/subcomponents/Cards/subcomponents/CardRow/index.d.ts +6 -0
- package/components/DataGrid/subcomponents/Cards/subcomponents/CardRow/index.js +71 -0
- package/components/DataGrid/subcomponents/Cards/subcomponents/IntersectCard/index.d.ts +20 -0
- package/components/DataGrid/subcomponents/Cards/subcomponents/IntersectCard/index.js +46 -0
- package/components/DataGrid/subcomponents/Cards/subcomponents/LazyLoadCard/index.d.ts +17 -0
- package/components/DataGrid/subcomponents/Cards/subcomponents/LazyLoadCard/index.js +34 -0
- package/components/DataGrid/subcomponents/Cards/types.d.ts +118 -0
- package/components/DataGrid/subcomponents/CheckboxCellAdapter/index.d.ts +7 -0
- package/components/DataGrid/subcomponents/CheckboxCellAdapter/index.js +43 -0
- package/components/DataGrid/subcomponents/CheckboxCellAdapter/types.d.ts +7 -0
- package/components/DataGrid/subcomponents/ControlNavigate/ControlNavigate.js +1 -1
- package/components/DataGrid/subcomponents/HeaderActions/index.js +5 -3
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/RowsCount/index.js +1 -1
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/Settings/index.js +11 -2
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/Settings/subcomponents/ColumnsConfig/index.js +1 -1
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/Settings/subcomponents/ColumnsConfigCards/index.d.ts +2 -0
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/Settings/subcomponents/ColumnsConfigCards/index.js +304 -0
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/Settings/subcomponents/ColumnsConfigCards/types.d.ts +31 -0
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/ViewMode/index.d.ts +4 -0
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/ViewMode/index.js +125 -0
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/hooks/useModalSettings/index.js +2 -2
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/hooks/useModalSettingsCards/index.d.ts +7 -0
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/hooks/useModalSettingsCards/index.js +74 -0
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/hooks/useModalSettingsCards/types.d.ts +4 -0
- package/components/DataGrid/subcomponents/RenderContent/index.d.ts +5 -0
- package/components/DataGrid/subcomponents/RenderContent/index.js +11 -0
- package/components/DataGrid/subcomponents/Table/hooks/useHeaderMenuActions.js +2 -2
- package/components/DataGrid/subcomponents/Table/hooks/useSortColumnsRows.js +1 -1
- package/components/DataGrid/subcomponents/Table/index.js +1 -1
- package/components/DataGrid/subcomponents/Table/subcomponents/ActionsColumn.js +1 -1
- package/components/DataGrid/subcomponents/Table/subcomponents/DraggableHeaderRenderer.js +1 -1
- package/components/DataGrid/subcomponents/Table/subcomponents/HeaderRenderClick/HeaderRenderClick.js +1 -1
- package/components/DataGrid/subcomponents/editors/TextEditor/index.js +1 -1
- package/components/DataGrid/tests/components/CardDetails.test.d.ts +1 -0
- package/components/DataGrid/tests/components/CardHeader.test.d.ts +1 -0
- package/components/DataGrid/tests/components/CardRow.test.d.ts +1 -0
- package/components/DataGrid/tests/components/Cards.test.d.ts +1 -0
- package/components/DataGrid/tests/components/CheckboxCellAdapter.test.d.ts +1 -0
- package/components/DataGrid/tests/components/ColumnsConfigCards.test.d.ts +1 -0
- package/components/DataGrid/tests/components/IntersectCard.test.d.ts +1 -0
- package/components/DataGrid/tests/components/ViewMode.test.d.ts +1 -0
- package/components/DataGrid/tests/helpers/types.d.ts +1 -0
- package/components/DataGrid/tests/helpers/useCardsViewConfig.d.ts +24 -0
- package/components/DataGrid/tests/helpers/useCustomCardExample.d.ts +7 -0
- package/components/DataGrid/tests/hooks/useCardContent.test.d.ts +1 -0
- package/components/DataGrid/tests/hooks/useModalDetail.test.d.ts +1 -0
- package/components/DataGrid/tests/hooks/useModalSettingsCards.test.d.ts +1 -0
- package/components/DataGrid/tests/hooks/useProcessedColumns.test.d.ts +1 -0
- package/components/DataGrid/types.d.ts +87 -5
- package/components/MFIsolationAppStorybook/MFIsolationAppStorybook.d.ts +5 -0
- package/components/MFIsolationAppStorybook/constants.d.ts +1 -0
- package/components/MFIsolationAppStorybook/icons.d.ts +3 -0
- package/components/MFIsolationAppStorybook/index.d.ts +1 -0
- package/components/MFIsolationAppStorybook/subcomponents/AppBarSettings/AppBarSettings.d.ts +4 -0
- package/components/MFIsolationAppStorybook/subcomponents/AppBarSettings/index.d.ts +1 -0
- package/components/MFIsolationAppStorybook/subcomponents/MFAuthAppStorybook/MFAuthAppStorybook.d.ts +5 -0
- package/components/MFIsolationAppStorybook/subcomponents/MFAuthAppStorybook/index.d.ts +1 -0
- package/components/MFIsolationAppStorybook/subcomponents/MFAuthAppStorybook/types.d.ts +4 -0
- package/components/MFIsolationAppStorybook/types.d.ts +31 -0
- package/components/MenuActions/MenuActions.js +105 -55
- package/components/areas/contexts/AreasContext/store.js +2 -2
- package/components/hook-form/RHFormContext/index.d.ts +1 -1
- package/hooks/useDataGridPersistence/helpers.d.ts +2 -2
- package/hooks/useDataGridPersistence/useDataGridPersistence.d.ts +2 -2
- package/hooks/useDataGridPersistence/useDataGridPersistence.js +5 -0
- package/index.js +8 -8
- package/package.json +1 -1
|
@@ -1,51 +1,12 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useEffect, useMemo,
|
|
2
|
+
import { useState, useCallback, useEffect, useMemo, createContext } from "react";
|
|
3
3
|
import { c as castMapColumnsWidthToRecord } from "../../helpers/castMapColumnsWidthToRecord.js";
|
|
4
|
-
import { useFirstRender } from "@m4l/graphics";
|
|
4
|
+
import { useFirstRender, useIsMobile } from "@m4l/graphics";
|
|
5
5
|
import { g as getComponentClasses } from "../../../../utils/getComponentSlotRoot.js";
|
|
6
6
|
import { a as DATAGRID_ROW_HEIGHTS, b as DATAGRID_ROW_HEADER_HEIGHTS, D as DATAGRID_PREFIX_NAME } from "../../constants.js";
|
|
7
7
|
import { C as ControlNavigateSlots, a as ColumnsConfigSlots, T as TextEditorSlots, b as TableSlots, R as RowsCountSlots, A as ActionsSlots, D as DataGridSlots } from "../../slots/DataGridEnum.js";
|
|
8
8
|
import { deepEqual } from "fast-equals";
|
|
9
9
|
const DataGridContext = createContext(null);
|
|
10
|
-
const getColumnConfigByKey = (key, storeColumnsConfig) => {
|
|
11
|
-
let indexFind = -1;
|
|
12
|
-
return [
|
|
13
|
-
storeColumnsConfig.find((column, index) => {
|
|
14
|
-
if (column.key === key) {
|
|
15
|
-
indexFind = index;
|
|
16
|
-
}
|
|
17
|
-
return column.key === key;
|
|
18
|
-
}),
|
|
19
|
-
indexFind
|
|
20
|
-
];
|
|
21
|
-
};
|
|
22
|
-
function getColumnsConfig(id, columns, defaultUserColumns = void 0) {
|
|
23
|
-
let columnsConfig;
|
|
24
|
-
if (defaultUserColumns) {
|
|
25
|
-
columnsConfig = defaultUserColumns.columnsConfig;
|
|
26
|
-
} else {
|
|
27
|
-
try {
|
|
28
|
-
const item = window.localStorage.getItem(`${id}_columns_config`);
|
|
29
|
-
columnsConfig = item !== null ? JSON.parse(item) : [];
|
|
30
|
-
} catch (_e) {
|
|
31
|
-
columnsConfig = [];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return columns.map((column, index) => {
|
|
35
|
-
const [columnConfig = { ...column }, columnConfigIndex] = getColumnConfigByKey(column.key, columnsConfig);
|
|
36
|
-
return {
|
|
37
|
-
key: column.key,
|
|
38
|
-
name: typeof column.name === "string" ? column.name : String(column.name),
|
|
39
|
-
hidden: column.hidden === void 0 ? false : column.hidden,
|
|
40
|
-
index: columnConfigIndex > -1 ? columnConfigIndex : index,
|
|
41
|
-
visible: columnConfig.visible === void 0 ? true : columnConfig.visible,
|
|
42
|
-
frozen: columnConfig.frozen ?? false,
|
|
43
|
-
originalIndex: index,
|
|
44
|
-
originalVisible: column.visible === void 0 ? true : column.visible,
|
|
45
|
-
originalFrozen: column.frozen ?? false
|
|
46
|
-
};
|
|
47
|
-
}).sort((a, b) => a.index - b.index);
|
|
48
|
-
}
|
|
49
10
|
function getColumnsWidth(id, columns, defaultUserColumns) {
|
|
50
11
|
const newMap = /* @__PURE__ */ new Map();
|
|
51
12
|
let storeColumnsWidth;
|
|
@@ -89,12 +50,87 @@ function saveColumnsWidth(id, storeColumnsWidth, onChangeUserColumns) {
|
|
|
89
50
|
JSON.stringify([...storeColumnsWidth])
|
|
90
51
|
);
|
|
91
52
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
53
|
+
const getAllViewModes = () => {
|
|
54
|
+
return ["table", "cards"];
|
|
55
|
+
};
|
|
56
|
+
const getViewSpecificConfig = (viewMode) => {
|
|
57
|
+
const configs = {
|
|
58
|
+
table: {
|
|
59
|
+
defaults: { frozen: false },
|
|
60
|
+
originalDefaults: { originalFrozen: false },
|
|
61
|
+
dynamicOriginalProperty: (item) => ({
|
|
62
|
+
originalFrozen: item?.frozen ?? false
|
|
63
|
+
})
|
|
64
|
+
},
|
|
65
|
+
cards: {
|
|
66
|
+
defaults: { showTitle: true },
|
|
67
|
+
originalDefaults: { originalShowTitle: true },
|
|
68
|
+
dynamicOriginalProperty: (item) => ({
|
|
69
|
+
originalShowTitle: item?.showTitle ?? true
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
return configs[viewMode] || configs.table;
|
|
74
|
+
};
|
|
75
|
+
const getViewSuffix = (viewMode) => {
|
|
76
|
+
if (viewMode === "table") {
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
return `_${viewMode}`;
|
|
80
|
+
};
|
|
81
|
+
function getInitialColumnsConfig(id, columns, viewMode, defaultUserConfig, viewSpecificDefaults, originalViewSpecificDefaults) {
|
|
82
|
+
let columnsConfig;
|
|
83
|
+
if (defaultUserConfig) {
|
|
84
|
+
columnsConfig = defaultUserConfig;
|
|
85
|
+
} else {
|
|
86
|
+
columnsConfig = loadViewConfig(
|
|
87
|
+
id,
|
|
88
|
+
getViewSuffix(viewMode)
|
|
89
|
+
) || [];
|
|
90
|
+
}
|
|
91
|
+
return columns.map((column, index) => {
|
|
92
|
+
const existingConfig = columnsConfig.find((c) => c.key === column.key);
|
|
93
|
+
const columnConfigIndex = existingConfig ? columnsConfig.indexOf(existingConfig) : -1;
|
|
94
|
+
const baseConfig = {
|
|
95
|
+
key: column.key,
|
|
96
|
+
name: typeof column.name === "string" ? column.name : String(column.name),
|
|
97
|
+
hidden: column.hidden === void 0 ? false : column.hidden,
|
|
98
|
+
index: columnConfigIndex > -1 ? columnConfigIndex : index,
|
|
99
|
+
visible: existingConfig?.visible !== void 0 ? existingConfig.visible : column.visible === void 0 ? true : column.visible,
|
|
100
|
+
originalIndex: index,
|
|
101
|
+
originalVisible: column.visible === void 0 ? true : column.visible
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
...baseConfig,
|
|
105
|
+
...viewSpecificDefaults,
|
|
106
|
+
...originalViewSpecificDefaults,
|
|
107
|
+
...existingConfig || {}
|
|
108
|
+
};
|
|
109
|
+
}).sort((a, b) => a.index - b.index);
|
|
110
|
+
}
|
|
111
|
+
function saveViewConfig(id, viewSuffix, config, onChangeCallback) {
|
|
112
|
+
if (onChangeCallback) {
|
|
113
|
+
const reason = viewSuffix === "" ? "columnsConfig" : `columnsConfig${viewSuffix.replace("_", "")}`;
|
|
114
|
+
onChangeCallback({
|
|
115
|
+
reason,
|
|
116
|
+
userConfig: config
|
|
117
|
+
});
|
|
95
118
|
return;
|
|
96
119
|
}
|
|
97
|
-
|
|
120
|
+
const storageKey = viewSuffix === "" ? `${id}_columns_config` : `${id}_columns_config${viewSuffix}`;
|
|
121
|
+
localStorage.setItem(storageKey, JSON.stringify(config));
|
|
122
|
+
}
|
|
123
|
+
function loadViewConfig(id, viewSuffix) {
|
|
124
|
+
try {
|
|
125
|
+
const storageKey = viewSuffix === "" ? `${id}_columns_config` : `${id}_columns_config${viewSuffix}`;
|
|
126
|
+
const stored = localStorage.getItem(storageKey);
|
|
127
|
+
return stored ? JSON.parse(stored) : null;
|
|
128
|
+
} catch (_e) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function saveViewMode(id, viewMode) {
|
|
133
|
+
localStorage.setItem(`${id}_view_mode`, viewMode);
|
|
98
134
|
}
|
|
99
135
|
function getIndexRowHeightVariant(variant) {
|
|
100
136
|
if (variant === "compact") {
|
|
@@ -123,9 +159,14 @@ function DataGridProvider(props) {
|
|
|
123
159
|
onChangeUserColumns,
|
|
124
160
|
externalSortSettings: sortSettings,
|
|
125
161
|
externalFilterSettings: filterSettings,
|
|
126
|
-
size
|
|
162
|
+
size,
|
|
163
|
+
viewMode,
|
|
164
|
+
onViewModeChange,
|
|
165
|
+
defaultViewMode,
|
|
166
|
+
cardsViewConfig
|
|
127
167
|
} = props;
|
|
128
168
|
const isFirstRender = useFirstRender([columns, id]);
|
|
169
|
+
const isMobile = useIsMobile();
|
|
129
170
|
const classes = getComponentClasses(DATAGRID_PREFIX_NAME, {
|
|
130
171
|
...DataGridSlots,
|
|
131
172
|
...ActionsSlots,
|
|
@@ -136,11 +177,56 @@ function DataGridProvider(props) {
|
|
|
136
177
|
...ControlNavigateSlots
|
|
137
178
|
});
|
|
138
179
|
const [columnsWidths, setColumnsWidths] = useState(/* @__PURE__ */ new Map());
|
|
139
|
-
const [
|
|
140
|
-
|
|
180
|
+
const [viewConfig, setViewConfig] = useState(() => ({
|
|
181
|
+
table: [],
|
|
182
|
+
cards: []
|
|
183
|
+
}));
|
|
184
|
+
const getConfigColumns = useCallback(
|
|
185
|
+
(viewModeParam) => {
|
|
186
|
+
return viewConfig[viewModeParam];
|
|
187
|
+
},
|
|
188
|
+
[viewConfig]
|
|
189
|
+
);
|
|
190
|
+
const updateConfigColumns = useCallback(
|
|
191
|
+
(viewModeParam, config) => {
|
|
192
|
+
setViewConfig((prev) => ({
|
|
193
|
+
...prev,
|
|
194
|
+
[viewModeParam]: config
|
|
195
|
+
}));
|
|
196
|
+
},
|
|
197
|
+
[]
|
|
141
198
|
);
|
|
142
199
|
const [rowsFilterCount, setRowFilterCount] = useState(rowsCount);
|
|
143
200
|
const [sortColumns, setSortColumns] = useState([]);
|
|
201
|
+
const [viewModeState, setViewModeState] = useState(() => {
|
|
202
|
+
if (viewMode) {
|
|
203
|
+
return viewMode;
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
const savedViewMode = localStorage.getItem(`${id}_view_mode`);
|
|
207
|
+
if (savedViewMode === "cards" || savedViewMode === "table") {
|
|
208
|
+
return savedViewMode;
|
|
209
|
+
}
|
|
210
|
+
} catch (_e) {
|
|
211
|
+
}
|
|
212
|
+
if (defaultViewMode) {
|
|
213
|
+
return defaultViewMode;
|
|
214
|
+
}
|
|
215
|
+
return isMobile ? "cards" : "table";
|
|
216
|
+
});
|
|
217
|
+
const handleViewModeChange = useCallback(
|
|
218
|
+
(newViewMode) => {
|
|
219
|
+
setViewModeState(newViewMode);
|
|
220
|
+
saveViewMode(id, newViewMode);
|
|
221
|
+
onViewModeChange?.(newViewMode);
|
|
222
|
+
},
|
|
223
|
+
[onViewModeChange, id]
|
|
224
|
+
);
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
if (viewMode !== void 0) {
|
|
227
|
+
setViewModeState(viewMode);
|
|
228
|
+
}
|
|
229
|
+
}, [viewMode]);
|
|
144
230
|
const [currentRowHeightVariant, setCurrentRowHeightVariant] = useState(() => {
|
|
145
231
|
if (typeof rowHeights !== typeof rowHeaderHeights) {
|
|
146
232
|
throw new Error("Must be same type rowheights and rowHeaderTypes");
|
|
@@ -184,99 +270,219 @@ function DataGridProvider(props) {
|
|
|
184
270
|
}
|
|
185
271
|
}
|
|
186
272
|
}
|
|
187
|
-
|
|
273
|
+
if (cardsViewConfig !== void 0) {
|
|
274
|
+
const hasCustomRender = cardsViewConfig.customRender !== void 0;
|
|
275
|
+
const hasColumnsConfig = cardsViewConfig.columnsConfig !== void 0 && cardsViewConfig.columnsConfig.length > 0;
|
|
276
|
+
if (!hasCustomRender && !hasColumnsConfig) {
|
|
277
|
+
throw new Error(
|
|
278
|
+
`DataGridProvider: cardsViewConfig.enabled=true requiere configurar al menos una de estas opciones:
|
|
279
|
+
- cardsViewConfig.customRender (renderizado personalizado)
|
|
280
|
+
- cardsViewConfig.columnsConfig (configuración de columnas con al menos 1 elemento)
|
|
281
|
+
|
|
282
|
+
Configuración actual:
|
|
283
|
+
- customRender: ${hasCustomRender ? "definido" : "undefined"}
|
|
284
|
+
- columnsConfig: ${cardsViewConfig.columnsConfig?.length || 0} columnas
|
|
285
|
+
|
|
286
|
+
Ejemplo válido con columnsConfig:
|
|
287
|
+
cardsViewConfig={{
|
|
288
|
+
enabled: true,
|
|
289
|
+
columnsConfig: [
|
|
290
|
+
{ columnKey: 'name', showTitle: false },
|
|
291
|
+
{ columnKey: 'email', showTitle: true }
|
|
292
|
+
]
|
|
293
|
+
}}
|
|
294
|
+
|
|
295
|
+
Ejemplo válido con customRender:
|
|
296
|
+
cardsViewConfig={{
|
|
297
|
+
enabled: true,
|
|
298
|
+
customRender: {
|
|
299
|
+
renderContent: (row) => <CustomCard row={row} />,
|
|
300
|
+
minHeight: 200
|
|
301
|
+
}
|
|
302
|
+
}}
|
|
303
|
+
`
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
if (hasColumnsConfig && cardsViewConfig.columnsConfig) {
|
|
307
|
+
for (const cardCol of cardsViewConfig.columnsConfig) {
|
|
308
|
+
if (!keys.has(cardCol.columnKey)) {
|
|
309
|
+
throw new Error(
|
|
310
|
+
`DataGridProvider: cardsViewConfig.columnsConfig incluye columnKey="${cardCol.columnKey}", pero no existe ninguna columna con key="${cardCol.columnKey}".`
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}, [columns, sortSettings, filterSettings, cardsViewConfig]);
|
|
188
317
|
const finalRowHeights = useMemo(() => rowHeights, [rowHeights]);
|
|
189
318
|
let timerSaveColumns;
|
|
190
319
|
useEffect(() => {
|
|
191
320
|
if (isFirstRender) {
|
|
192
321
|
setColumnsWidths(getColumnsWidth(id, columns, defaultUserColumns));
|
|
193
|
-
|
|
194
|
-
|
|
322
|
+
updateConfigColumns(
|
|
323
|
+
"table",
|
|
324
|
+
getInitialColumnsConfig(
|
|
325
|
+
id,
|
|
326
|
+
columns,
|
|
327
|
+
"table",
|
|
328
|
+
defaultUserColumns?.columnsConfig,
|
|
329
|
+
{ frozen: false },
|
|
330
|
+
{ originalFrozen: false }
|
|
331
|
+
)
|
|
332
|
+
);
|
|
333
|
+
const finalCardsConfig = (() => {
|
|
334
|
+
if (defaultUserColumns?.columnsConfigCards) {
|
|
335
|
+
return defaultUserColumns.columnsConfigCards;
|
|
336
|
+
}
|
|
337
|
+
if (cardsViewConfig?.columnsConfig) {
|
|
338
|
+
return cardsViewConfig.columnsConfig.map((colConfig, index) => {
|
|
339
|
+
const originalColumn = columns.find(
|
|
340
|
+
(col) => col.key === colConfig.columnKey
|
|
341
|
+
);
|
|
342
|
+
return {
|
|
343
|
+
key: colConfig.columnKey,
|
|
344
|
+
visible: originalColumn?.visible === void 0 ? true : originalColumn?.visible,
|
|
345
|
+
index,
|
|
346
|
+
showTitle: colConfig.showTitle
|
|
347
|
+
};
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
return void 0;
|
|
351
|
+
})();
|
|
352
|
+
updateConfigColumns(
|
|
353
|
+
"cards",
|
|
354
|
+
getInitialColumnsConfig(
|
|
355
|
+
id,
|
|
356
|
+
columns,
|
|
357
|
+
"cards",
|
|
358
|
+
finalCardsConfig,
|
|
359
|
+
{ showTitle: false },
|
|
360
|
+
{ originalShowTitle: false }
|
|
361
|
+
)
|
|
195
362
|
);
|
|
196
363
|
}
|
|
197
364
|
}, [defaultUserColumns]);
|
|
198
365
|
useEffect(() => {
|
|
199
366
|
if (!isFirstRender) {
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
...columnsConfig[i],
|
|
209
|
-
// name: column.name as string,
|
|
210
|
-
originalIndex: columnIndex,
|
|
211
|
-
originalFrozen: column.frozen ?? false,
|
|
212
|
-
originalVisible: column.visible ?? true
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
const newColumns = columns.filter(
|
|
217
|
-
(column, index) => column.key !== columnsConfig[index]?.key
|
|
218
|
-
);
|
|
219
|
-
if (newColumns.length > 0) {
|
|
220
|
-
const colLength = finalColumnsConfig.length;
|
|
221
|
-
const newColConfig = getColumnsConfig(
|
|
222
|
-
id,
|
|
223
|
-
newColumns
|
|
224
|
-
).map((columnConfig, index) => {
|
|
367
|
+
const updatedConfigs = {
|
|
368
|
+
table: [],
|
|
369
|
+
cards: []
|
|
370
|
+
};
|
|
371
|
+
getAllViewModes().forEach((viewModeParam) => {
|
|
372
|
+
const currentConfig = getConfigColumns(viewModeParam);
|
|
373
|
+
const finalConfig = [];
|
|
374
|
+
for (let i = 0; i < currentConfig.length; i++) {
|
|
225
375
|
const columnIndex = columns.findIndex(
|
|
226
|
-
(c) => c.key ===
|
|
376
|
+
(c) => c.key === currentConfig[i]?.key
|
|
227
377
|
);
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
378
|
+
if (columnIndex !== -1) {
|
|
379
|
+
const column = columns[columnIndex];
|
|
380
|
+
finalConfig.push({
|
|
381
|
+
...currentConfig[i],
|
|
382
|
+
originalIndex: columnIndex,
|
|
383
|
+
// Propiedades específicas por vista dinámicamente
|
|
384
|
+
...getViewSpecificConfig(viewModeParam).dynamicOriginalProperty(
|
|
385
|
+
currentConfig[i] || column
|
|
386
|
+
),
|
|
387
|
+
originalVisible: column.visible ?? true
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
updatedConfigs[viewModeParam] = finalConfig;
|
|
392
|
+
});
|
|
393
|
+
getAllViewModes().forEach((viewModeParam) => {
|
|
394
|
+
const currentConfig = updatedConfigs[viewModeParam];
|
|
395
|
+
const newColumnsForView = columns.filter(
|
|
396
|
+
(column, index) => column.key !== getConfigColumns(viewModeParam)[index]?.key
|
|
397
|
+
);
|
|
398
|
+
if (newColumnsForView.length > 0) {
|
|
399
|
+
const colLength = currentConfig.length;
|
|
400
|
+
const viewSpecificDefaults = viewModeParam === "cards" ? { showTitle: false } : {
|
|
401
|
+
frozen: false
|
|
237
402
|
};
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
403
|
+
const originalViewSpecificDefaults = viewModeParam === "cards" ? {
|
|
404
|
+
originalShowTitle: false
|
|
405
|
+
} : {
|
|
406
|
+
originalFrozen: false
|
|
407
|
+
};
|
|
408
|
+
const newColConfig = getInitialColumnsConfig(
|
|
409
|
+
id,
|
|
410
|
+
newColumnsForView,
|
|
411
|
+
viewModeParam,
|
|
412
|
+
void 0,
|
|
413
|
+
viewSpecificDefaults,
|
|
414
|
+
originalViewSpecificDefaults
|
|
415
|
+
).map((columnConfig, index) => {
|
|
416
|
+
const columnIndex = columns.findIndex(
|
|
417
|
+
(c) => c.key === newColumnsForView[index].key
|
|
418
|
+
);
|
|
419
|
+
const column = newColumnsForView[index];
|
|
420
|
+
return {
|
|
421
|
+
...columnConfig,
|
|
422
|
+
index: index + colLength,
|
|
423
|
+
name: column.name,
|
|
424
|
+
originalIndex: columnIndex,
|
|
425
|
+
originalVisible: column.visible ?? true,
|
|
426
|
+
// Propiedades específicas por vista dinámicamente
|
|
427
|
+
...getViewSpecificConfig(viewModeParam).dynamicOriginalProperty(
|
|
428
|
+
column
|
|
429
|
+
)
|
|
430
|
+
};
|
|
431
|
+
});
|
|
432
|
+
updatedConfigs[viewModeParam].push(...newColConfig);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
let hasChanges = false;
|
|
436
|
+
getAllViewModes().forEach((viewModeParam) => {
|
|
437
|
+
if (!deepEqual(
|
|
438
|
+
getConfigColumns(viewModeParam),
|
|
439
|
+
updatedConfigs[viewModeParam]
|
|
440
|
+
)) {
|
|
441
|
+
hasChanges = true;
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
if (!hasChanges) {
|
|
242
445
|
return;
|
|
243
446
|
}
|
|
244
|
-
console.log(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
);
|
|
249
|
-
setColumnsConfigOptions(finalColumnsConfig);
|
|
447
|
+
console.log("useEffect viewConfigs changed", updatedConfigs);
|
|
448
|
+
getAllViewModes().forEach((viewModeParam) => {
|
|
449
|
+
updateConfigColumns(viewModeParam, updatedConfigs[viewModeParam]);
|
|
450
|
+
});
|
|
250
451
|
}
|
|
251
452
|
}, [columns, id]);
|
|
252
453
|
const onChangeColumnsConfig = useCallback(
|
|
253
|
-
(
|
|
254
|
-
|
|
255
|
-
|
|
454
|
+
(viewModeParam, newConfig) => {
|
|
455
|
+
saveViewConfig(
|
|
456
|
+
id,
|
|
457
|
+
getViewSuffix(viewModeParam),
|
|
458
|
+
newConfig,
|
|
459
|
+
onChangeUserColumns
|
|
460
|
+
);
|
|
461
|
+
updateConfigColumns(viewModeParam, newConfig);
|
|
256
462
|
},
|
|
257
|
-
|
|
258
|
-
[setColumnsConfigOptions, id]
|
|
463
|
+
[id, onChangeUserColumns, updateConfigColumns]
|
|
259
464
|
);
|
|
260
465
|
const onChangeColumnsOrder = useCallback(
|
|
261
|
-
(sourceKey, targetKey) => {
|
|
466
|
+
(viewModeParam, sourceKey, targetKey) => {
|
|
262
467
|
if (sourceKey === targetKey) {
|
|
263
468
|
return;
|
|
264
469
|
}
|
|
265
|
-
const
|
|
470
|
+
const currentConfig = getConfigColumns(viewModeParam);
|
|
471
|
+
const sourceColumnIndex = currentConfig.findIndex(
|
|
266
472
|
(c) => c.key === sourceKey
|
|
267
473
|
);
|
|
268
|
-
const targetColumnIndex =
|
|
474
|
+
const targetColumnIndex = currentConfig.findIndex(
|
|
269
475
|
(c) => c.key === targetKey
|
|
270
476
|
);
|
|
271
|
-
const
|
|
272
|
-
|
|
477
|
+
const reorderedConfig = [...currentConfig];
|
|
478
|
+
reorderedConfig.splice(
|
|
273
479
|
targetColumnIndex,
|
|
274
480
|
0,
|
|
275
|
-
|
|
481
|
+
reorderedConfig.splice(sourceColumnIndex, 1)[0]
|
|
276
482
|
);
|
|
277
|
-
onChangeColumnsConfig(
|
|
483
|
+
onChangeColumnsConfig(viewModeParam, reorderedConfig);
|
|
278
484
|
},
|
|
279
|
-
[
|
|
485
|
+
[getConfigColumns, onChangeColumnsConfig]
|
|
280
486
|
);
|
|
281
487
|
const onChangeColumnWidth = (columnKey, width) => {
|
|
282
488
|
columnsWidths.set(columnKey, Math.round(width));
|
|
@@ -307,7 +513,9 @@ function DataGridProvider(props) {
|
|
|
307
513
|
DataGridContext.Provider,
|
|
308
514
|
{
|
|
309
515
|
value: {
|
|
310
|
-
|
|
516
|
+
getConfigColumns,
|
|
517
|
+
onChangeColumnsConfig,
|
|
518
|
+
columnsConfig: getConfigColumns("table"),
|
|
311
519
|
columnsWidths,
|
|
312
520
|
rowsCount: rowsFilterCount,
|
|
313
521
|
currentRowHeightVariant: currentRowHeightVariant.rowHVariant,
|
|
@@ -316,7 +524,6 @@ function DataGridProvider(props) {
|
|
|
316
524
|
rows,
|
|
317
525
|
rowHeights: finalRowHeights,
|
|
318
526
|
checkedRows,
|
|
319
|
-
onChangeColumnsConfig,
|
|
320
527
|
onChangeColumnsOrder,
|
|
321
528
|
onChangeColumnWidth,
|
|
322
529
|
setRowsCount: setRowFilterCountInternal,
|
|
@@ -330,7 +537,10 @@ function DataGridProvider(props) {
|
|
|
330
537
|
externalSortSettings: sortSettings,
|
|
331
538
|
externalFilterSettings: filterSettings,
|
|
332
539
|
classes,
|
|
333
|
-
size
|
|
540
|
+
size,
|
|
541
|
+
viewMode: viewModeState,
|
|
542
|
+
onViewModeChange: handleViewModeChange,
|
|
543
|
+
cardsViewConfig
|
|
334
544
|
},
|
|
335
545
|
children
|
|
336
546
|
}
|
|
@@ -3,6 +3,29 @@ import { RowKey, RowHeightVariants, GridProps } from '../../types';
|
|
|
3
3
|
import { Maybe } from '@m4l/core';
|
|
4
4
|
import { ActionsSlots, ColumnsConfigSlots, ControlNavigateSlots, DataGridSlots, RowsCountSlots, TableSlots, TextEditorSlots } from '../../slots/DataGridEnum';
|
|
5
5
|
import { SortColumn } from 'react-data-grid';
|
|
6
|
+
/**
|
|
7
|
+
* Configuración base genérica que puede extenderse con propiedades específicas de cualquier vista
|
|
8
|
+
* USO INTERNO: El sistema usa esto para manejar genéricamente las configuraciones
|
|
9
|
+
*/
|
|
10
|
+
export type BaseViewConfig<TViewSpecific = {}> = TViewSpecific & {
|
|
11
|
+
key: string;
|
|
12
|
+
visible: boolean;
|
|
13
|
+
index: number;
|
|
14
|
+
name?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Configuración extendida genérica con propiedades originales
|
|
18
|
+
* USO INTERNO: El contexto usa esto para el estado interno con propiedades de tracking
|
|
19
|
+
*/
|
|
20
|
+
export type IViewConfig<TViewSpecific = {}, TOriginalViewSpecific = {}> = BaseViewConfig<TViewSpecific> & {
|
|
21
|
+
hidden: boolean;
|
|
22
|
+
originalIndex: number;
|
|
23
|
+
originalVisible: boolean;
|
|
24
|
+
} & TOriginalViewSpecific;
|
|
25
|
+
/**
|
|
26
|
+
* Configuración base para columnas de tabla
|
|
27
|
+
* USO: Los desarrolladores pasan esto en defaultUserColumns.columnsConfig
|
|
28
|
+
*/
|
|
6
29
|
export interface BaseConfigColumn {
|
|
7
30
|
key: string;
|
|
8
31
|
visible: boolean;
|
|
@@ -13,28 +36,66 @@ export interface BaseConfigColumn {
|
|
|
13
36
|
*/
|
|
14
37
|
name?: string;
|
|
15
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Configuración base para vista cards - omite frozen y agrega showTitle
|
|
41
|
+
* USO: Los desarrolladores pasan esto en defaultUserColumns.columnsConfigCards
|
|
42
|
+
*/
|
|
43
|
+
export interface BaseConfigColumnCards extends Omit<BaseConfigColumn, 'frozen'> {
|
|
44
|
+
showTitle: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Configuración extendida para columnas de tabla (estado interno)
|
|
48
|
+
* USO INTERNO: El contexto agrega estas propiedades para tracking y gestión de estado
|
|
49
|
+
*/
|
|
16
50
|
export interface IConfigColumn extends BaseConfigColumn {
|
|
17
51
|
hidden: boolean;
|
|
18
52
|
originalIndex: number;
|
|
19
53
|
originalVisible: boolean;
|
|
20
54
|
originalFrozen: boolean;
|
|
21
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Configuración extendida para cards (estado interno)
|
|
58
|
+
* USO INTERNO: El contexto agrega estas propiedades para tracking y gestión de estado
|
|
59
|
+
*/
|
|
60
|
+
export interface IConfigColumnCards extends Omit<IConfigColumn, 'frozen' | 'originalFrozen'> {
|
|
61
|
+
showTitle: boolean;
|
|
62
|
+
originalShowTitle: boolean;
|
|
63
|
+
}
|
|
64
|
+
export type ViewMode = 'table' | 'cards';
|
|
65
|
+
/**
|
|
66
|
+
* Configuración base del Grid (API pública original)
|
|
67
|
+
* USO: Tipo base para defaultUserColumns - mantiene retrocompatibilidad
|
|
68
|
+
* IMPORTANTE: No modificar para mantener retrocompatibilidad con código existente
|
|
69
|
+
*/
|
|
22
70
|
export interface IGridConfig {
|
|
23
71
|
columnsConfig: BaseConfigColumn[];
|
|
24
72
|
columnsWidths: Record<RowKey, number>;
|
|
25
73
|
}
|
|
26
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Configuración extendida del Grid para soportar múltiples vistas
|
|
76
|
+
* USO: Para nuevas implementaciones que soporten cards y futuras vistas
|
|
77
|
+
* EXTENSIBILIDAD: Agregar aquí nuevas propiedades para nuevas vistas (ej: columnsConfigList)
|
|
78
|
+
*/
|
|
79
|
+
export interface IGridConfigExtended extends IGridConfig {
|
|
80
|
+
columnsConfigCards?: BaseConfigColumnCards[];
|
|
81
|
+
}
|
|
82
|
+
export interface DataGridProviderProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> extends Pick<GridProps<TRow, TSummaryRow, TKey>, 'rows' | 'columns' | 'rowActionsGetter' | 'rowHeaderHeights' | 'rowHeights' | 'initialRowHeightVariant' | 'checkedRows' | 'onCheckedRowsChange' | 'rowKeyGetter' | 'onChangeUserColumns' | 'defaultUserColumns' | 'externalSortSettings' | 'externalFilterSettings' | 'defaultViewMode' | 'cardsViewConfig'> {
|
|
27
83
|
id: number | string;
|
|
28
84
|
children: ReactNode;
|
|
29
85
|
rowsCount: number;
|
|
30
86
|
size: GridProps<any, any, any>['size'];
|
|
87
|
+
viewMode?: ViewMode;
|
|
88
|
+
onViewModeChange?: (viewMode: ViewMode) => void;
|
|
31
89
|
}
|
|
32
90
|
export type RowHeightState = {
|
|
33
91
|
rowHVariant: RowHeightVariants;
|
|
34
92
|
rowHeight: number;
|
|
35
93
|
rowHeaderHeight: number;
|
|
36
94
|
};
|
|
37
|
-
export interface DataGridContextProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> extends Pick<DataGridProviderProps<TRow, TSummaryRow, TKey>, 'rows' | 'checkedRows' | 'onCheckedRowsChange' | 'rowHeights' | 'rowsCount' | 'rowActionsGetter' | 'rowKeyGetter' | 'onChangeUserColumns' | 'externalSortSettings' | 'externalFilterSettings'> {
|
|
95
|
+
export interface DataGridContextProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> extends Pick<DataGridProviderProps<TRow, TSummaryRow, TKey>, 'rows' | 'checkedRows' | 'onCheckedRowsChange' | 'rowHeights' | 'rowsCount' | 'rowActionsGetter' | 'rowKeyGetter' | 'onChangeUserColumns' | 'externalSortSettings' | 'externalFilterSettings' | 'viewMode' | 'onViewModeChange' | 'defaultViewMode' | 'cardsViewConfig'> {
|
|
96
|
+
getConfigColumns: (viewMode: ViewMode) => IViewConfig[];
|
|
97
|
+
onChangeColumnsConfig: (viewMode: ViewMode, config: IViewConfig[]) => void;
|
|
98
|
+
onChangeColumnsOrder: (viewMode: ViewMode, sourceKey: string, targetKey: string) => void;
|
|
38
99
|
columnsConfig: IConfigColumn[];
|
|
39
100
|
columnsWidths: Map<string, Maybe<string | number>>;
|
|
40
101
|
setRowsCount: (newRowsCount: number) => void;
|
|
@@ -42,8 +103,6 @@ export interface DataGridContextProps<TRow, TSummaryRow, TKey extends RowKey = R
|
|
|
42
103
|
currentRowHeight: number;
|
|
43
104
|
currentRowHeightVariant: RowHeightVariants;
|
|
44
105
|
setRowHeightVariant: (neVariant: RowHeightVariants) => void;
|
|
45
|
-
onChangeColumnsConfig: (newColumnsConfig: IConfigColumn[]) => void;
|
|
46
|
-
onChangeColumnsOrder: (sourceKey: string, targetKey: string) => void;
|
|
47
106
|
onChangeColumnWidth: (columnKey: string, width: number) => void;
|
|
48
107
|
classes?: Record<DataGridSlots | ActionsSlots | RowsCountSlots | TableSlots | TextEditorSlots | ColumnsConfigSlots | ControlNavigateSlots, string>;
|
|
49
108
|
size: GridProps<any, any, any>['size'];
|
|
@@ -16,6 +16,7 @@ export declare const DICTIONARY: {
|
|
|
16
16
|
SETTINGS_COLUMN_NAME: string;
|
|
17
17
|
SETTINGS_COLUMN_POSITION: string;
|
|
18
18
|
SETTINGS_COLUMN_VISIBLE: string;
|
|
19
|
+
SETTINGS_COLUMN_SHOW_TITLE: string;
|
|
19
20
|
SETTINGS_COLUMNS_FROZEN: string;
|
|
20
21
|
SETTINGS_SEL_COLUMNS: string;
|
|
21
22
|
SETTINGS_MOVE_FIRST: string;
|
|
@@ -33,4 +34,8 @@ export declare const DICTIONARY: {
|
|
|
33
34
|
UNFREEZE_COLUMN: string;
|
|
34
35
|
HIDE_COLUMN: string;
|
|
35
36
|
ADD_FILTER_COLUMN: string;
|
|
37
|
+
VIEW_MODE_TABLE: string;
|
|
38
|
+
VIEW_MODE_CARDS: string;
|
|
39
|
+
TOOLTIP_VIEW_MODE: string;
|
|
40
|
+
DETAILS: string;
|
|
36
41
|
};
|
|
@@ -16,6 +16,7 @@ const DICTIONARY = {
|
|
|
16
16
|
SETTINGS_COLUMN_NAME: `${DATAGRID_ID_DICTIONARY}.settings_column_name`,
|
|
17
17
|
SETTINGS_COLUMN_POSITION: `${DATAGRID_ID_DICTIONARY}.settings_column_position`,
|
|
18
18
|
SETTINGS_COLUMN_VISIBLE: `${DATAGRID_ID_DICTIONARY}.settings_column_visible`,
|
|
19
|
+
SETTINGS_COLUMN_SHOW_TITLE: `${DATAGRID_ID_DICTIONARY}.settings_column_show_title`,
|
|
19
20
|
SETTINGS_COLUMNS_FROZEN: `${DATAGRID_ID_DICTIONARY}.settings_column_frozen`,
|
|
20
21
|
SETTINGS_SEL_COLUMNS: `${DATAGRID_ID_DICTIONARY}.settings_sel_columns`,
|
|
21
22
|
SETTINGS_MOVE_FIRST: `${DATAGRID_ID_DICTIONARY}.settings_move_first`,
|
|
@@ -32,7 +33,11 @@ const DICTIONARY = {
|
|
|
32
33
|
FREEZE_COLUMN: `${DATAGRID_ID_DICTIONARY}.freeze_column`,
|
|
33
34
|
UNFREEZE_COLUMN: `${DATAGRID_ID_DICTIONARY}.unfreeze_column`,
|
|
34
35
|
HIDE_COLUMN: `${DATAGRID_ID_DICTIONARY}.hide_column`,
|
|
35
|
-
ADD_FILTER_COLUMN: `${DATAGRID_ID_DICTIONARY}.add_filter
|
|
36
|
+
ADD_FILTER_COLUMN: `${DATAGRID_ID_DICTIONARY}.add_filter`,
|
|
37
|
+
VIEW_MODE_TABLE: `${DATAGRID_ID_DICTIONARY}.view_mode_table`,
|
|
38
|
+
VIEW_MODE_CARDS: `${DATAGRID_ID_DICTIONARY}.view_mode_cards`,
|
|
39
|
+
TOOLTIP_VIEW_MODE: `${DATAGRID_ID_DICTIONARY}.tooltip_view_mode`,
|
|
40
|
+
DETAILS: `${DATAGRID_ID_DICTIONARY}.details`
|
|
36
41
|
};
|
|
37
42
|
export {
|
|
38
43
|
DICTIONARY as D,
|