@m4l/components 9.4.2 → 9.4.4
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 +41 -11
- package/components/DataGrid/hooks/useChangeColumnsOrder/useChangeColumnsOrder.js +5 -1
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/Settings/subcomponents/ColumnsConfig/index.js +4 -0
- package/components/DataGrid/types.d.ts +6 -2
- package/components/formatters/IconsFormatter/constants.d.ts +1 -0
- package/components/formatters/IconsFormatter/constants.js +8 -1
- package/components/formatters/IconsFormatter/helpers/renderIcon.js +2 -0
- package/components/formatters/IconsFormatter/slots/IconsFormatterSlots.js +1 -1
- package/hooks/useDataGridPersistence/useDataGridPersistence.d.ts +2 -2
- package/hooks/useDataGridPersistence/useDataGridPersistence.js +34 -21
- package/package.json +1 -1
|
@@ -49,13 +49,15 @@ function DataGridProvider(props) {
|
|
|
49
49
|
const resolvedDefaultConfig = defaultConfig ?? defaultUserColumns;
|
|
50
50
|
const resolvedOnChangeConfig = onChangeConfig ?? onChangeUserColumns;
|
|
51
51
|
const isFirstRender = useFirstRender([columns, id]);
|
|
52
|
-
const { viewModeState, setViewModeState, handleViewModeChange } = useViewMode(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
const { viewModeState, setViewModeState, handleViewModeChange } = useViewMode(
|
|
53
|
+
{
|
|
54
|
+
id,
|
|
55
|
+
viewMode,
|
|
56
|
+
defaultViewMode,
|
|
57
|
+
onViewModeChange,
|
|
58
|
+
onChangeConfig: resolvedOnChangeConfig
|
|
59
|
+
}
|
|
60
|
+
);
|
|
59
61
|
const { currentRowHeightVariant, setRowHeightVariant } = useRowHeight({
|
|
60
62
|
rowHeights,
|
|
61
63
|
rowHeaderHeights,
|
|
@@ -88,6 +90,29 @@ function DataGridProvider(props) {
|
|
|
88
90
|
const [sortColumns, setSortColumns] = useState([]);
|
|
89
91
|
useEffect(() => {
|
|
90
92
|
const keys = new Set(columns.map((c) => c.key));
|
|
93
|
+
if (defaultViewMode === "cards" && cardsViewConfig === void 0) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`DataGridProvider: Cuando defaultViewMode="cards", es obligatorio proporcionar cardsViewConfig.
|
|
96
|
+
|
|
97
|
+
Ejemplo válido con columnsConfig:
|
|
98
|
+
defaultViewMode="cards"
|
|
99
|
+
cardsViewConfig={{
|
|
100
|
+
columnsConfig: [
|
|
101
|
+
{ columnKey: 'name', showTitle: false },
|
|
102
|
+
{ columnKey: 'email', showTitle: true }
|
|
103
|
+
]
|
|
104
|
+
}}
|
|
105
|
+
|
|
106
|
+
Ejemplo válido con customRender:
|
|
107
|
+
defaultViewMode="cards"
|
|
108
|
+
cardsViewConfig={{
|
|
109
|
+
customRender: {
|
|
110
|
+
renderContent: (row) => <CustomCard row={row} />,
|
|
111
|
+
minHeight: 200
|
|
112
|
+
}
|
|
113
|
+
}}`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
91
116
|
if (sortSettings?.sortsColumns) {
|
|
92
117
|
for (const sort of sortSettings.sortsColumns) {
|
|
93
118
|
if (!keys.has(sort)) {
|
|
@@ -149,12 +174,14 @@ function DataGridProvider(props) {
|
|
|
149
174
|
}
|
|
150
175
|
}
|
|
151
176
|
}
|
|
152
|
-
}, [columns, sortSettings, filterSettings, cardsViewConfig]);
|
|
177
|
+
}, [columns, sortSettings, filterSettings, cardsViewConfig, defaultViewMode]);
|
|
153
178
|
const finalRowHeights = useMemo(() => rowHeights, [rowHeights]);
|
|
154
179
|
useEffect(() => {
|
|
155
180
|
if (isFirstRender) {
|
|
156
181
|
setColumnsWidths(getColumnsWidth(id, columns, resolvedDefaultConfig));
|
|
157
|
-
setViewModeState(
|
|
182
|
+
setViewModeState(
|
|
183
|
+
getViewMode(id, resolvedDefaultConfig, defaultViewMode) ?? "table"
|
|
184
|
+
);
|
|
158
185
|
updateConfigColumns(
|
|
159
186
|
"table",
|
|
160
187
|
getInitialColumnsConfig(
|
|
@@ -167,7 +194,7 @@ function DataGridProvider(props) {
|
|
|
167
194
|
)
|
|
168
195
|
);
|
|
169
196
|
const finalCardsConfig = (() => {
|
|
170
|
-
if (resolvedDefaultConfig?.columnsConfigCards) {
|
|
197
|
+
if (resolvedDefaultConfig?.columnsConfigCards && resolvedDefaultConfig.columnsConfigCards.length > 0) {
|
|
171
198
|
return resolvedDefaultConfig.columnsConfigCards;
|
|
172
199
|
}
|
|
173
200
|
if (cardsViewConfig?.columnsConfig) {
|
|
@@ -228,8 +255,11 @@ function DataGridProvider(props) {
|
|
|
228
255
|
});
|
|
229
256
|
getAllViewModes().forEach((viewModeParam) => {
|
|
230
257
|
const currentConfig = updatedConfigs[viewModeParam];
|
|
258
|
+
const currentConfigKeys = new Set(
|
|
259
|
+
getConfigColumns(viewModeParam).map((c) => c.key)
|
|
260
|
+
);
|
|
231
261
|
const newColumnsForView = columns.filter(
|
|
232
|
-
(column
|
|
262
|
+
(column) => !currentConfigKeys.has(column.key)
|
|
233
263
|
);
|
|
234
264
|
if (newColumnsForView.length > 0) {
|
|
235
265
|
const colLength = currentConfig.length;
|
|
@@ -21,7 +21,11 @@ const useChangeColumnsOrder = ({
|
|
|
21
21
|
0,
|
|
22
22
|
reorderedConfig.splice(sourceColumnIndex, 1)[0]
|
|
23
23
|
);
|
|
24
|
-
|
|
24
|
+
const configWithUpdatedIndexes = reorderedConfig.map((col, idx) => ({
|
|
25
|
+
...col,
|
|
26
|
+
index: idx
|
|
27
|
+
}));
|
|
28
|
+
onChangeColumnsConfig(viewModeParam, configWithUpdatedIndexes);
|
|
25
29
|
},
|
|
26
30
|
[getConfigColumns, onChangeColumnsConfig]
|
|
27
31
|
);
|
|
@@ -165,6 +165,10 @@ const ColumnsConfig = forwardRef((props, ref) => {
|
|
|
165
165
|
newColumnConfig.visible = columnConfigRow.visible;
|
|
166
166
|
newColumnConfig.frozen = columnConfigRow.frozen;
|
|
167
167
|
}
|
|
168
|
+
const rowIndex = rows.findIndex((row) => row.key === columnConfig.key);
|
|
169
|
+
if (rowIndex > -1) {
|
|
170
|
+
newColumnConfig.index = rowIndex;
|
|
171
|
+
}
|
|
168
172
|
}
|
|
169
173
|
return newColumnConfig;
|
|
170
174
|
}).sort((a, b) => getRowIndex(a) - getRowIndex(b));
|
|
@@ -184,12 +184,16 @@ export interface GridProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> exte
|
|
|
184
184
|
*/
|
|
185
185
|
size?: Extract<Sizes, 'small' | 'medium'>;
|
|
186
186
|
/**
|
|
187
|
-
* Modo por defecto de visualización
|
|
187
|
+
* Modo por defecto de visualización.
|
|
188
|
+
*
|
|
189
|
+
* IMPORTANTE: Si se especifica 'cards', es obligatorio proporcionar `cardsViewConfig`.
|
|
188
190
|
*/
|
|
189
191
|
defaultViewMode?: ViewMode;
|
|
190
192
|
/**
|
|
191
193
|
* Configuración de la vista de "cards"
|
|
192
|
-
* Incluye habilitación, configuración de columnas y renderizado personalizado
|
|
194
|
+
* Incluye habilitación, configuración de columnas y renderizado personalizado.
|
|
195
|
+
*
|
|
196
|
+
* IMPORTANTE: Es obligatorio si `defaultViewMode` es 'cards'.
|
|
193
197
|
*/
|
|
194
198
|
cardsViewConfig?: CardsViewConfig<TRow>;
|
|
195
199
|
/**
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { g as getComponentClasses } from "../../../utils/getComponentSlotRoot.js";
|
|
2
|
+
import { I as IconsFormatterSlots } from "./slots/IconsFormatterEnum.js";
|
|
1
3
|
const ICONS_FORMATTER_KEY_COMPONENT = "M4LIconsFormatter";
|
|
4
|
+
const ICONS_FORMATTER_CLASSES = getComponentClasses(
|
|
5
|
+
ICONS_FORMATTER_KEY_COMPONENT,
|
|
6
|
+
IconsFormatterSlots
|
|
7
|
+
);
|
|
2
8
|
export {
|
|
3
|
-
|
|
9
|
+
ICONS_FORMATTER_CLASSES as I,
|
|
10
|
+
ICONS_FORMATTER_KEY_COMPONENT as a
|
|
4
11
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { I as ICONS_FORMATTER_CLASSES } from "../constants.js";
|
|
2
3
|
import { I as IconClickeableStyled, a as IconStyled } from "../slots/IconsFormatterSlots.js";
|
|
3
4
|
function renderIcon(iconConfig, key) {
|
|
4
5
|
const { iconUrl, onClick, tooltip, dataTestId, color, visible, size } = iconConfig;
|
|
@@ -13,6 +14,7 @@ function renderIcon(iconConfig, key) {
|
|
|
13
14
|
onClick,
|
|
14
15
|
tooltipContent: tooltip,
|
|
15
16
|
instaceDataTestId: dataTestId,
|
|
17
|
+
className: onClick ? ICONS_FORMATTER_CLASSES.iconClickeable : ICONS_FORMATTER_CLASSES.icon,
|
|
16
18
|
color,
|
|
17
19
|
size
|
|
18
20
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { styled } from "@mui/material";
|
|
2
|
-
import {
|
|
2
|
+
import { a as ICONS_FORMATTER_KEY_COMPONENT } from "../constants.js";
|
|
3
3
|
import { I as IconsFormatterSlots } from "./IconsFormatterEnum.js";
|
|
4
4
|
import { i as iconsFormatterStyles } from "../IconsFormatter.styles.js";
|
|
5
5
|
import { I as Icon } from "../../../Icon/Icon.js";
|
|
@@ -6,8 +6,8 @@ import { ChangeConfig, IGridConfigExtended } from '../../components/DataGrid';
|
|
|
6
6
|
* Retorna:
|
|
7
7
|
* - `defaultConfig`: Configuración inicial cargada desde cookies
|
|
8
8
|
* - `onChangeConfig`: Callback para persistir cambios en cookies
|
|
9
|
-
* - `defaultUserColumns`:
|
|
10
|
-
* - `onChangeUserColumns`:
|
|
9
|
+
* - `defaultUserColumns`: (deprecated) Alias de defaultConfig
|
|
10
|
+
* - `onChangeUserColumns`: (deprecated) Alias de onChangeConfig
|
|
11
11
|
*/
|
|
12
12
|
export declare const useDataGridPersistence: (props: UseDataGridPersistenceProps) => {
|
|
13
13
|
defaultConfig: IGridConfigExtended;
|
|
@@ -2,34 +2,47 @@ import { useState, useCallback } from "react";
|
|
|
2
2
|
import { g as getColumnsConfigCardsCookie, a as getColumnsConfigCookie } from "./helpers.js";
|
|
3
3
|
import { C as COOKIE_VIEW_MODE, a as COOKIE_COLUMNS_CONFIG_CARDS, b as COOKIE_COLUMNS_CONFIG, c as COOKIE_COLUMNS_WIDTHS } from "./constants.js";
|
|
4
4
|
import { u as useWindowToolsMF } from "../../components/WindowBase/hooks/useWindowToolsMF/index.js";
|
|
5
|
+
const REASON_TO_COOKIE_MAP = {
|
|
6
|
+
columnsConfig: COOKIE_COLUMNS_CONFIG,
|
|
7
|
+
columnsConfigCards: COOKIE_COLUMNS_CONFIG_CARDS,
|
|
8
|
+
columnsWidths: COOKIE_COLUMNS_WIDTHS,
|
|
9
|
+
viewMode: COOKIE_VIEW_MODE
|
|
10
|
+
};
|
|
5
11
|
const useDataGridPersistence = (props) => {
|
|
6
12
|
const { prefixCookie } = props;
|
|
7
13
|
const { setCookie, getCookie } = useWindowToolsMF();
|
|
8
14
|
const [defaultConfig] = useState(() => {
|
|
9
15
|
return {
|
|
10
|
-
columnsWidths: getCookie(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
columnsWidths: getCookie(
|
|
17
|
+
prefixCookie ? `${prefixCookie}_${COOKIE_COLUMNS_WIDTHS}` : COOKIE_COLUMNS_WIDTHS
|
|
18
|
+
) || {},
|
|
19
|
+
columnsConfig: getColumnsConfigCookie(
|
|
20
|
+
getCookie(
|
|
21
|
+
prefixCookie ? `${prefixCookie}_${COOKIE_COLUMNS_CONFIG}` : COOKIE_COLUMNS_CONFIG
|
|
22
|
+
)
|
|
23
|
+
) || [],
|
|
24
|
+
columnsConfigCards: getColumnsConfigCardsCookie(
|
|
25
|
+
getCookie(
|
|
26
|
+
prefixCookie ? `${prefixCookie}_${COOKIE_COLUMNS_CONFIG_CARDS}` : COOKIE_COLUMNS_CONFIG_CARDS
|
|
27
|
+
)
|
|
28
|
+
) || [],
|
|
29
|
+
viewMode: getCookie(
|
|
30
|
+
prefixCookie ? `${prefixCookie}_${COOKIE_VIEW_MODE}` : COOKIE_VIEW_MODE
|
|
31
|
+
)
|
|
14
32
|
};
|
|
15
33
|
});
|
|
16
|
-
const onChangeConfig = useCallback(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
setCookie(
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
setCookie(prefixCookie ? `${prefixCookie}_${COOKIE_VIEW_MODE}` : COOKIE_VIEW_MODE, "window", userConfig);
|
|
29
|
-
} else {
|
|
30
|
-
setCookie(prefixCookie ? `${prefixCookie}_${reason}` : reason, "window", userConfig);
|
|
31
|
-
}
|
|
32
|
-
}, [setCookie, prefixCookie]);
|
|
34
|
+
const onChangeConfig = useCallback(
|
|
35
|
+
(newProps) => {
|
|
36
|
+
const { reason, userConfig } = newProps;
|
|
37
|
+
if (userConfig === void 0) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const cookieName = REASON_TO_COOKIE_MAP[reason] ?? reason;
|
|
41
|
+
const fullCookieName = prefixCookie ? `${prefixCookie}_${cookieName}` : cookieName;
|
|
42
|
+
setCookie(fullCookieName, "window", userConfig);
|
|
43
|
+
},
|
|
44
|
+
[setCookie, prefixCookie]
|
|
45
|
+
);
|
|
33
46
|
return {
|
|
34
47
|
// Nuevos nombres
|
|
35
48
|
defaultConfig,
|