@m4l/components 9.2.60 → 9.2.61
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 +17 -3
- package/components/DataGrid/Datagrid.styles.js +72 -20
- package/components/DataGrid/constants.d.ts +2 -0
- package/components/DataGrid/constants.js +7 -3
- package/components/DataGrid/contexts/DataGridContext/index.js +77 -30
- package/components/DataGrid/contexts/DataGridContext/types.d.ts +5 -2
- package/components/DataGrid/dictionary.d.ts +8 -0
- package/components/DataGrid/dictionary.js +26 -17
- package/components/DataGrid/icons.d.ts +7 -0
- package/components/DataGrid/icons.js +8 -1
- package/components/DataGrid/slots/DataGridEnum.d.ts +7 -1
- package/components/DataGrid/slots/DataGridEnum.js +6 -0
- package/components/DataGrid/slots/DataGridSlot.d.ts +6 -0
- package/components/DataGrid/slots/DataGridSlot.js +35 -5
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/Filter/index.js +9 -1
- package/components/DataGrid/subcomponents/Table/hooks/getDragHeaderRenderer.d.ts +3 -1
- package/components/DataGrid/subcomponents/Table/hooks/getDragHeaderRenderer.js +9 -2
- package/components/DataGrid/subcomponents/Table/hooks/useHeaderMenuActions.d.ts +6 -0
- package/components/DataGrid/subcomponents/Table/hooks/useHeaderMenuActions.js +262 -0
- package/components/DataGrid/subcomponents/Table/hooks/useSortColumnsRows.d.ts +6 -4
- package/components/DataGrid/subcomponents/Table/hooks/useSortColumnsRows.js +35 -20
- package/components/DataGrid/subcomponents/Table/index.js +97 -34
- package/components/DataGrid/subcomponents/Table/subcomponents/ActionsColumn.js +1 -1
- package/components/DataGrid/subcomponents/Table/subcomponents/DraggableHeaderRenderer.d.ts +1 -0
- package/components/DataGrid/subcomponents/Table/subcomponents/DraggableHeaderRenderer.js +79 -4
- package/components/DataGrid/subcomponents/Table/subcomponents/HeaderRenderClick/HeaderRenderClick.d.ts +5 -0
- package/components/DataGrid/subcomponents/Table/subcomponents/HeaderRenderClick/HeaderRenderClick.js +146 -0
- package/components/DataGrid/subcomponents/Table/subcomponents/HeaderRenderClick/index.d.ts +1 -0
- package/components/DataGrid/subcomponents/Table/subcomponents/HeaderRenderClick/index.js +1 -0
- package/components/DataGrid/subcomponents/Table/subcomponents/HeaderRenderClick/types.d.ts +131 -0
- package/components/DataGrid/subcomponents/Table/subcomponents/SelectColumn.js +1 -1
- package/components/DataGrid/subcomponents/editors/TextEditor/index.js +1 -1
- package/components/DataGrid/tests/HeaderRenderClick.test.d.ts +1 -0
- package/components/DataGrid/tests/useHeaderMenuActions.test.d.ts +1 -0
- package/components/DataGrid/types.d.ts +53 -0
- package/components/DynamicFilter/store/DynamicFilterContext.js +63 -23
- package/components/DynamicFilter/subcomponents/PopoverFilter/usePopoverFilter.d.ts +3 -3
- package/components/DynamicFilter/types.d.ts +3 -0
- package/components/DynamicSort/DynamicSort.js +10 -6
- package/components/DynamicSort/store/DynamicSortContext.js +96 -67
- package/components/DynamicSort/store/DynamicSortStore.js +53 -4
- package/components/DynamicSort/store/types.d.ts +11 -0
- package/components/DynamicSort/subcomponents/PopoverSort/usePopoverSort.d.ts +3 -3
- package/components/DynamicSort/types.d.ts +4 -0
- package/components/NumberInput/hooks/useNumberInput/useNumberInput.js +0 -2
- package/components/hook-form/RHFAutocompleteAsync/reducer/RHFAutocompleteReducer.js +0 -5
- package/components/hook-form/RHFormContext/index.d.ts +1 -1
- package/components/mui_extended/CheckBox/CheckBox.styles.js +2 -1
- package/hooks/useDynamicFilterAndSort/useDynamicFilterAndSort.d.ts +3 -0
- package/hooks/useDynamicFilterAndSort/useDynamicFilterAndSort.js +334 -88
- package/index.js +7 -7
- package/package.json +1 -1
- package/storybook/components/DataGrid/DataGrid.stories.d.ts +22 -0
- package/storybook/components/DataGrid/MswHandles.d.ts +1 -0
- package/storybook/components/DataGrid/helpers/filterFieldsSeedData.d.ts +5 -0
- package/storybook/components/DataGrid/helpers/getRows.d.ts +4 -0
- package/storybook/components/DataGrid/helpers/getRowsWithBackendSimulation.d.ts +9 -0
- package/storybook/components/DataGrid/helpers/sortsSeedData.d.ts +5 -0
- package/storybook/components/DataGrid/helpers/types.d.ts +1 -0
- package/storybook/components/DataGrid/helpers/useSeed.d.ts +3 -0
- package/storybook/components/DataGrid/subcomponents/DataGridRender.d.ts +2 -0
- package/storybook/components/ObjectLogs/ObjectLogs.stories.d.ts +2 -2
|
@@ -4,4 +4,6 @@ import { HeaderRendererProps } from 'react-data-grid';
|
|
|
4
4
|
* Función encargada de retornar el componente de renderizado de cabecera con la capacidad de arrastrar columnas
|
|
5
5
|
* @param handleColumnsReorder - Función que se ejecuta al reordenar columnas
|
|
6
6
|
*/
|
|
7
|
-
export declare const getDragHeaderRenderer: <TRow, TSummaryRow>(handleColumnsReorder: (sourceKey: string, targetKey: string) => void
|
|
7
|
+
export declare const getDragHeaderRenderer: <TRow, TSummaryRow>(handleColumnsReorder: (sourceKey: string, targetKey: string) => void, options?: {
|
|
8
|
+
openPopover?: (anchorEl: HTMLElement, columnKey: string) => void;
|
|
9
|
+
}) => FunctionComponent<HeaderRendererProps<TRow, TSummaryRow>>;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { D as DraggableHeaderRenderer } from "../subcomponents/DraggableHeaderRenderer.js";
|
|
3
|
-
const getDragHeaderRenderer = (handleColumnsReorder) => {
|
|
3
|
+
const getDragHeaderRenderer = (handleColumnsReorder, options) => {
|
|
4
4
|
function HeaderRenderer(props) {
|
|
5
|
-
return /* @__PURE__ */ jsx(
|
|
5
|
+
return /* @__PURE__ */ jsx(
|
|
6
|
+
DraggableHeaderRenderer,
|
|
7
|
+
{
|
|
8
|
+
...props,
|
|
9
|
+
onColumnsReorder: handleColumnsReorder,
|
|
10
|
+
openPopover: options?.openPopover
|
|
11
|
+
}
|
|
12
|
+
);
|
|
6
13
|
}
|
|
7
14
|
return HeaderRenderer;
|
|
8
15
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Column } from 'react-data-grid';
|
|
2
|
+
import { MenuAction } from '../subcomponents/HeaderRenderClick/types';
|
|
3
|
+
/**
|
|
4
|
+
* Función que retorna las acciones del menu del header de la columna
|
|
5
|
+
*/
|
|
6
|
+
export declare function useHeaderMenuActions<Trow, TSummaryRow>(columnKey: string | null, finalColumns: readonly Column<Trow, TSummaryRow>[], defaultSortable: boolean): MenuAction[];
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { useMemo, useCallback } from "react";
|
|
2
|
+
import { u as useDataGrid } from "../../../hooks/useDataGrid.js";
|
|
3
|
+
import { useEnvironment, useModuleDictionary } from "@m4l/core";
|
|
4
|
+
import { D as DICTIONARY } from "../../../dictionary.js";
|
|
5
|
+
import { p as pathIcons } from "../../../icons.js";
|
|
6
|
+
function useHeaderMenuActions(columnKey, finalColumns, defaultSortable) {
|
|
7
|
+
const {
|
|
8
|
+
columnsConfig,
|
|
9
|
+
onChangeColumnsConfig,
|
|
10
|
+
setSortColumns,
|
|
11
|
+
sortColumns,
|
|
12
|
+
externalSortSettings,
|
|
13
|
+
externalFilterSettings
|
|
14
|
+
} = useDataGrid();
|
|
15
|
+
const { host_static_assets, environment_assets } = useEnvironment();
|
|
16
|
+
const { getLabel } = useModuleDictionary();
|
|
17
|
+
const column = useMemo(() => {
|
|
18
|
+
return finalColumns.find((c) => c.key === columnKey);
|
|
19
|
+
}, [columnKey, finalColumns]);
|
|
20
|
+
const canSort = useMemo(() => {
|
|
21
|
+
if (!columnKey) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (typeof column?.sortable === "boolean") {
|
|
25
|
+
return column.sortable;
|
|
26
|
+
}
|
|
27
|
+
return defaultSortable;
|
|
28
|
+
}, [columnKey, column, defaultSortable]);
|
|
29
|
+
const canSortExternally = useMemo(() => {
|
|
30
|
+
if (!columnKey || !externalSortSettings) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return externalSortSettings.sortsColumns.includes(columnKey);
|
|
34
|
+
}, [columnKey, externalSortSettings]);
|
|
35
|
+
const currentSort = useMemo(() => {
|
|
36
|
+
if (!columnKey || !externalSortSettings?.sortsApplied) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
return externalSortSettings.sortsApplied.find(
|
|
40
|
+
(s) => s.columnKey === columnKey
|
|
41
|
+
);
|
|
42
|
+
}, [columnKey, externalSortSettings?.sortsApplied]);
|
|
43
|
+
const hasExternalSortAsc = useMemo(() => {
|
|
44
|
+
return currentSort?.direction === "asc";
|
|
45
|
+
}, [currentSort]);
|
|
46
|
+
const hasExternalSortDesc = useMemo(() => {
|
|
47
|
+
return currentSort?.direction === "desc";
|
|
48
|
+
}, [currentSort]);
|
|
49
|
+
const isAsc = useMemo(
|
|
50
|
+
() => Boolean(
|
|
51
|
+
columnKey && sortColumns.some(
|
|
52
|
+
(s) => s.columnKey === columnKey && s.direction === "ASC"
|
|
53
|
+
)
|
|
54
|
+
),
|
|
55
|
+
[columnKey, sortColumns]
|
|
56
|
+
);
|
|
57
|
+
const isDesc = useMemo(
|
|
58
|
+
() => Boolean(
|
|
59
|
+
columnKey && sortColumns.some(
|
|
60
|
+
(s) => s.columnKey === columnKey && s.direction === "DESC"
|
|
61
|
+
)
|
|
62
|
+
),
|
|
63
|
+
[columnKey, sortColumns]
|
|
64
|
+
);
|
|
65
|
+
const clearLocalSort = useCallback(() => {
|
|
66
|
+
if (!columnKey) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
setSortColumns((prev) => prev.filter((s) => s.columnKey !== columnKey));
|
|
70
|
+
}, [columnKey, setSortColumns]);
|
|
71
|
+
const hasAnySortApplied = useMemo(() => {
|
|
72
|
+
return Boolean(currentSort);
|
|
73
|
+
}, [currentSort]);
|
|
74
|
+
const toggleFrozen = useCallback(() => {
|
|
75
|
+
if (!columnKey) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const next = columnsConfig.map(
|
|
79
|
+
(c) => c.key === columnKey ? { ...c, frozen: !c.frozen } : c
|
|
80
|
+
);
|
|
81
|
+
onChangeColumnsConfig(next);
|
|
82
|
+
}, [columnKey, columnsConfig, onChangeColumnsConfig]);
|
|
83
|
+
const toggleVisible = useCallback(() => {
|
|
84
|
+
if (!columnKey) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const next = columnsConfig.map(
|
|
88
|
+
(c) => c.key === columnKey ? { ...c, visible: !c.visible } : c
|
|
89
|
+
);
|
|
90
|
+
onChangeColumnsConfig(next);
|
|
91
|
+
}, [columnKey, columnsConfig, onChangeColumnsConfig]);
|
|
92
|
+
const addExternalSort = useCallback(
|
|
93
|
+
(direction) => {
|
|
94
|
+
if (!columnKey || !column || column?.type === "custom") {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
externalSortSettings?.onChange({
|
|
98
|
+
action: "add",
|
|
99
|
+
columnKey,
|
|
100
|
+
direction
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
[columnKey, column, externalSortSettings]
|
|
104
|
+
);
|
|
105
|
+
const isRemovable = useMemo(() => {
|
|
106
|
+
return currentSort?.removable;
|
|
107
|
+
}, [currentSort]);
|
|
108
|
+
const addExternalFilter = useCallback(() => {
|
|
109
|
+
if (!columnKey || !column) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
externalFilterSettings?.onChange({
|
|
113
|
+
action: "add",
|
|
114
|
+
columnKey
|
|
115
|
+
});
|
|
116
|
+
}, [columnKey, column, externalFilterSettings]);
|
|
117
|
+
const isAddFilterDisabled = useMemo(() => {
|
|
118
|
+
if (!columnKey || !column) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
if (column.type === "custom") {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
const isInFilterColumns = externalFilterSettings?.filterColumns.some(
|
|
125
|
+
(filter) => filter.name === columnKey
|
|
126
|
+
);
|
|
127
|
+
if (!isInFilterColumns) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
const isFilterApplied = externalFilterSettings?.filtersApplied.some(
|
|
131
|
+
(filter) => filter.columnKey === columnKey && filter.isValid
|
|
132
|
+
);
|
|
133
|
+
const isFilterMultiple = externalFilterSettings?.filterColumns.find(
|
|
134
|
+
(filter) => filter.name === columnKey
|
|
135
|
+
)?.multiple;
|
|
136
|
+
return isFilterApplied && !isFilterMultiple;
|
|
137
|
+
}, [columnKey, column, externalFilterSettings]);
|
|
138
|
+
return useMemo(() => {
|
|
139
|
+
if (!columnKey) {
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
const sortActions = [
|
|
143
|
+
{
|
|
144
|
+
type: "menuItem",
|
|
145
|
+
startIcon: `${host_static_assets}/${environment_assets}/${pathIcons.sortAsc}`,
|
|
146
|
+
label: getLabel(DICTIONARY.ORDER_ASC_COLUMN),
|
|
147
|
+
dataTestId: "sort-ascending",
|
|
148
|
+
/**
|
|
149
|
+
* Función que agrega un sort externo en modo ascendente
|
|
150
|
+
*/
|
|
151
|
+
onClick: () => {
|
|
152
|
+
if (externalSortSettings) {
|
|
153
|
+
addExternalSort("asc");
|
|
154
|
+
} else {
|
|
155
|
+
setSortColumns([
|
|
156
|
+
{
|
|
157
|
+
columnKey,
|
|
158
|
+
direction: "ASC"
|
|
159
|
+
}
|
|
160
|
+
]);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
disabled: !canSort || (externalSortSettings ? !canSortExternally || hasExternalSortAsc : isAsc)
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
type: "menuItem",
|
|
167
|
+
startIcon: `${host_static_assets}/${environment_assets}/${pathIcons.sortDesc}`,
|
|
168
|
+
label: getLabel(DICTIONARY.ORDER_DESC_COLUMN),
|
|
169
|
+
dataTestId: "sort-descending",
|
|
170
|
+
/**
|
|
171
|
+
* Función que agrega un sort externo en modo descendente
|
|
172
|
+
*/
|
|
173
|
+
onClick: () => {
|
|
174
|
+
if (externalSortSettings) {
|
|
175
|
+
addExternalSort("desc");
|
|
176
|
+
} else {
|
|
177
|
+
setSortColumns([
|
|
178
|
+
{
|
|
179
|
+
columnKey,
|
|
180
|
+
direction: "DESC"
|
|
181
|
+
}
|
|
182
|
+
]);
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
disabled: !canSort || (externalSortSettings ? !canSortExternally || hasExternalSortDesc : isDesc)
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
type: "menuItem",
|
|
189
|
+
startIcon: `${host_static_assets}/${environment_assets}/${pathIcons.removeSort}`,
|
|
190
|
+
label: getLabel(DICTIONARY.REMOVE_ORDER_COLUMN),
|
|
191
|
+
dataTestId: "sort-remove",
|
|
192
|
+
/**
|
|
193
|
+
* Función que elimina el sort externo
|
|
194
|
+
*/
|
|
195
|
+
onClick: () => {
|
|
196
|
+
if (columnKey) {
|
|
197
|
+
if (externalSortSettings && isRemovable) {
|
|
198
|
+
externalSortSettings.onChange({
|
|
199
|
+
action: "remove",
|
|
200
|
+
columnKey
|
|
201
|
+
});
|
|
202
|
+
return;
|
|
203
|
+
} else {
|
|
204
|
+
clearLocalSort();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
disabled: externalSortSettings ? !hasAnySortApplied || !isRemovable : !(isAsc || isDesc)
|
|
209
|
+
}
|
|
210
|
+
];
|
|
211
|
+
const filterAction = externalFilterSettings ? [
|
|
212
|
+
{
|
|
213
|
+
type: "menuItem",
|
|
214
|
+
startIcon: `${host_static_assets}/${environment_assets}/${pathIcons.filter2}`,
|
|
215
|
+
label: getLabel(DICTIONARY.ADD_FILTER_COLUMN),
|
|
216
|
+
dataTestId: "filter-add",
|
|
217
|
+
onClick: () => {
|
|
218
|
+
addExternalFilter();
|
|
219
|
+
},
|
|
220
|
+
disabled: isAddFilterDisabled
|
|
221
|
+
}
|
|
222
|
+
] : [];
|
|
223
|
+
const baseActions = [
|
|
224
|
+
{
|
|
225
|
+
type: "menuItem",
|
|
226
|
+
startIcon: columnsConfig.find((c) => c.key === columnKey)?.frozen ? `${host_static_assets}/${environment_assets}/${pathIcons.unfreezeColumn}` : `${host_static_assets}/${environment_assets}/${pathIcons.freezeColumn}`,
|
|
227
|
+
label: columnsConfig.find((c) => c.key === columnKey)?.frozen ? getLabel(DICTIONARY.UNFREEZE_COLUMN) : getLabel(DICTIONARY.FREEZE_COLUMN),
|
|
228
|
+
onClick: toggleFrozen,
|
|
229
|
+
disabled: !columnsConfig.find((c) => c.key === columnKey)?.visible,
|
|
230
|
+
dataTestId: "toggle-freeze"
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
type: "menuItem",
|
|
234
|
+
startIcon: `${host_static_assets}/${environment_assets}/${pathIcons.hideColumn}`,
|
|
235
|
+
label: getLabel(DICTIONARY.HIDE_COLUMN),
|
|
236
|
+
onClick: toggleVisible,
|
|
237
|
+
dataTestId: "hide-column"
|
|
238
|
+
}
|
|
239
|
+
];
|
|
240
|
+
return [...sortActions, ...filterAction, ...baseActions];
|
|
241
|
+
}, [
|
|
242
|
+
columnKey,
|
|
243
|
+
canSort,
|
|
244
|
+
canSortExternally,
|
|
245
|
+
hasExternalSortAsc,
|
|
246
|
+
hasExternalSortDesc,
|
|
247
|
+
hasAnySortApplied,
|
|
248
|
+
addExternalSort,
|
|
249
|
+
toggleFrozen,
|
|
250
|
+
toggleVisible,
|
|
251
|
+
columnsConfig,
|
|
252
|
+
externalSortSettings,
|
|
253
|
+
externalFilterSettings,
|
|
254
|
+
host_static_assets,
|
|
255
|
+
environment_assets,
|
|
256
|
+
getLabel,
|
|
257
|
+
isAddFilterDisabled
|
|
258
|
+
]);
|
|
259
|
+
}
|
|
260
|
+
export {
|
|
261
|
+
useHeaderMenuActions as u
|
|
262
|
+
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { Column
|
|
1
|
+
import { Column } from 'react-data-grid';
|
|
2
2
|
/**
|
|
3
3
|
* Hook encargado de ordenar datos de las columnas y las filas.
|
|
4
4
|
* Se utiliza para ordenar las columnas y las filas de un DataGrid.
|
|
5
5
|
*/
|
|
6
|
-
export declare const useSortColumnsRows: <TRow, TSummaryRow>(sourceColumns: readonly Column<TRow, TSummaryRow>[], sourceRows: readonly TRow[]
|
|
6
|
+
export declare const useSortColumnsRows: <TRow, TSummaryRow>(sourceColumns: readonly Column<TRow, TSummaryRow>[], sourceRows: readonly TRow[], popoverHandlers?: {
|
|
7
|
+
openPopover?: (anchorEl: HTMLElement, columnKey: string) => void;
|
|
8
|
+
}) => {
|
|
7
9
|
finalColumns: readonly Column<TRow, TSummaryRow>[];
|
|
8
|
-
sortColumns:
|
|
9
|
-
setSortColumns: import('react').Dispatch<import('react').SetStateAction<
|
|
10
|
+
sortColumns: import('react-data-grid').SortColumn[];
|
|
11
|
+
setSortColumns: import('react').Dispatch<import('react').SetStateAction<import('react-data-grid').SortColumn[]>>;
|
|
10
12
|
finalRows: readonly TRow[];
|
|
11
13
|
};
|
|
@@ -6,7 +6,7 @@ import { useModuleSkeleton, getPropertyByString } from "@m4l/core";
|
|
|
6
6
|
import { u as useFilters } from "../../../hooks/useFilters.js";
|
|
7
7
|
import { u as useDataGrid } from "../../../hooks/useDataGrid.js";
|
|
8
8
|
import { S as SkeletonFormatter } from "../subcomponents/SkeletonFormatter/index.js";
|
|
9
|
-
import {
|
|
9
|
+
import { d as DATAGRID_SELECT_COLUMN_KEY } from "../../../constants.js";
|
|
10
10
|
function getComparator(columns, sortColumn) {
|
|
11
11
|
const column = columns.find((d) => d.key === sortColumn);
|
|
12
12
|
let typeOrder = "string";
|
|
@@ -17,7 +17,6 @@ function getComparator(columns, sortColumn) {
|
|
|
17
17
|
return column.customSort;
|
|
18
18
|
}
|
|
19
19
|
switch (typeOrder) {
|
|
20
|
-
//Si el tipo de dato de la columna es un numerico, retorna una función de ordenamiento numérica
|
|
21
20
|
case "number":
|
|
22
21
|
return (a, b) => {
|
|
23
22
|
try {
|
|
@@ -26,7 +25,6 @@ function getComparator(columns, sortColumn) {
|
|
|
26
25
|
return -1;
|
|
27
26
|
}
|
|
28
27
|
};
|
|
29
|
-
//Por defecto retorna una función de ordenamiento de string
|
|
30
28
|
default:
|
|
31
29
|
return (a, b) => {
|
|
32
30
|
try {
|
|
@@ -43,15 +41,13 @@ const getInOrderColumns = (columns, hasCheckedRows, columnsConfig, columnsWidths
|
|
|
43
41
|
const columnConfigIndex = getColumIndex(column.key, columnsConfig);
|
|
44
42
|
const visible = columnConfigIndex > -1 ? columnsConfig[columnConfigIndex].visible : true;
|
|
45
43
|
return !column.hidden && visible;
|
|
46
|
-
}).sort(
|
|
47
|
-
(a,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
).map((columnSorted) => {
|
|
44
|
+
}).sort((a, b) => {
|
|
45
|
+
let indexA = getColumIndex(a.key, columnsConfig);
|
|
46
|
+
indexA = indexA === -1 ? columnsConfig.length : indexA;
|
|
47
|
+
let indexB = getColumIndex(b.key, columnsConfig);
|
|
48
|
+
indexB = indexB === -1 ? columnsConfig.length : indexB;
|
|
49
|
+
return indexA - indexB;
|
|
50
|
+
}).map((columnSorted) => {
|
|
55
51
|
const columnConfigIndex = getColumIndex(columnSorted.key, columnsConfig);
|
|
56
52
|
return {
|
|
57
53
|
...columnSorted,
|
|
@@ -83,21 +79,26 @@ const getAligByType = (columnType) => {
|
|
|
83
79
|
}
|
|
84
80
|
return "left";
|
|
85
81
|
};
|
|
86
|
-
const useSortColumnsRows = (sourceColumns, sourceRows) => {
|
|
82
|
+
const useSortColumnsRows = (sourceColumns, sourceRows, popoverHandlers) => {
|
|
87
83
|
const {
|
|
88
84
|
columnsConfig,
|
|
89
85
|
columnsWidths,
|
|
90
86
|
onChangeColumnsOrder,
|
|
91
87
|
rowActionsGetter,
|
|
92
88
|
checkedRows,
|
|
93
|
-
onCheckedRowsChange
|
|
89
|
+
onCheckedRowsChange,
|
|
90
|
+
sortColumns,
|
|
91
|
+
setSortColumns
|
|
94
92
|
} = useDataGrid();
|
|
95
|
-
const [columns, setColumns] = useState(
|
|
96
|
-
|
|
93
|
+
const [columns, setColumns] = useState(
|
|
94
|
+
() => []
|
|
95
|
+
);
|
|
97
96
|
const isSkeleton = useModuleSkeleton();
|
|
98
97
|
const { activeFilters, filters } = useFilters();
|
|
99
98
|
const findKeyInColumns = (key, cols) => {
|
|
100
|
-
const index = cols.findIndex(
|
|
99
|
+
const index = cols.findIndex(
|
|
100
|
+
(column) => key === column.key && column.hidden === false
|
|
101
|
+
);
|
|
101
102
|
return index !== -1;
|
|
102
103
|
};
|
|
103
104
|
useEffect(() => {
|
|
@@ -119,7 +120,12 @@ const useSortColumnsRows = (sourceColumns, sourceRows) => {
|
|
|
119
120
|
}
|
|
120
121
|
}, [sourceColumns, columnsConfig, rowActionsGetter]);
|
|
121
122
|
const finalColumns = useMemo(() => {
|
|
122
|
-
const DragAndDropHeaderRenderer = getDragHeaderRenderer(
|
|
123
|
+
const DragAndDropHeaderRenderer = getDragHeaderRenderer(
|
|
124
|
+
onChangeColumnsOrder,
|
|
125
|
+
{
|
|
126
|
+
openPopover: popoverHandlers?.openPopover
|
|
127
|
+
}
|
|
128
|
+
);
|
|
123
129
|
return columns.map((c) => {
|
|
124
130
|
const cellClass = c.align !== void 0 ? `rdg-cell-align-${c.align}` : `rdg-cell-align-${getAligByType(c.type)}`;
|
|
125
131
|
const newColumn = {
|
|
@@ -143,7 +149,13 @@ const useSortColumnsRows = (sourceColumns, sourceRows) => {
|
|
|
143
149
|
newColumn.headerRenderer = DragAndDropHeaderRenderer;
|
|
144
150
|
return newColumn;
|
|
145
151
|
});
|
|
146
|
-
}, [
|
|
152
|
+
}, [
|
|
153
|
+
isSkeleton,
|
|
154
|
+
columns,
|
|
155
|
+
activeFilters,
|
|
156
|
+
onChangeColumnsOrder,
|
|
157
|
+
popoverHandlers
|
|
158
|
+
]);
|
|
147
159
|
const finalRows = useMemo(() => {
|
|
148
160
|
const nextRows = sourceRows.filter((r) => {
|
|
149
161
|
if (!filters || filters.size === 0) {
|
|
@@ -154,7 +166,10 @@ const useSortColumnsRows = (sourceColumns, sourceRows) => {
|
|
|
154
166
|
for (let i = 0; i < filters.size; i++) {
|
|
155
167
|
const entry = iterator.next().value;
|
|
156
168
|
const columnKey = entry?.[0] ?? "";
|
|
157
|
-
const columnFilter = entry?.[1] ?? {
|
|
169
|
+
const columnFilter = entry?.[1] ?? {
|
|
170
|
+
value: "",
|
|
171
|
+
customFilter: void 0
|
|
172
|
+
};
|
|
158
173
|
let valCell;
|
|
159
174
|
const valueMaybeString = getPropertyByString(r, columnKey);
|
|
160
175
|
let fixedValue;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useRef, useEffect } from "react";
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState, useRef, useEffect } from "react";
|
|
3
3
|
import DataGrid from "react-data-grid";
|
|
4
4
|
import { DndProvider } from "react-dnd";
|
|
5
5
|
import { HTML5Backend } from "react-dnd-html5-backend";
|
|
@@ -9,15 +9,52 @@ import { u as useSortColumnsRows } from "./hooks/useSortColumnsRows.js";
|
|
|
9
9
|
import { u as useFilters } from "../../hooks/useFilters.js";
|
|
10
10
|
import { u as useDataGrid } from "../../hooks/useDataGrid.js";
|
|
11
11
|
import { l as TableContainerStyled, T as TableWrapperDataGridStyled } from "../../slots/DataGridSlot.js";
|
|
12
|
+
import { u as useHeaderMenuActions } from "./hooks/useHeaderMenuActions.js";
|
|
13
|
+
import { H as HeaderRenderClick } from "./subcomponents/HeaderRenderClick/HeaderRenderClick.js";
|
|
12
14
|
function Table(props) {
|
|
13
|
-
const {
|
|
14
|
-
const { finalColumns, sortColumns, setSortColumns, finalRows } = useSortColumnsRows(
|
|
15
|
+
const {
|
|
15
16
|
columns,
|
|
16
|
-
rows
|
|
17
|
+
rows,
|
|
18
|
+
onRowsChange,
|
|
19
|
+
rowKeyGetter,
|
|
20
|
+
selectedRows,
|
|
21
|
+
onSelectedRowsChange
|
|
22
|
+
} = props;
|
|
23
|
+
const { finalColumns, finalRows } = useSortColumnsRows(
|
|
24
|
+
columns,
|
|
25
|
+
rows,
|
|
26
|
+
useMemo(
|
|
27
|
+
() => ({
|
|
28
|
+
/**
|
|
29
|
+
* Función que abre el menú de acciones para una columna
|
|
30
|
+
*/
|
|
31
|
+
openPopover: (anchorEl, columnKey) => {
|
|
32
|
+
if (anchorEl instanceof HTMLDivElement) {
|
|
33
|
+
setPopoverState({
|
|
34
|
+
anchorEl,
|
|
35
|
+
columnKey
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}),
|
|
40
|
+
[]
|
|
41
|
+
)
|
|
17
42
|
);
|
|
18
43
|
const { activeFilters } = useFilters();
|
|
19
|
-
const {
|
|
44
|
+
const {
|
|
45
|
+
onChangeColumnWidth,
|
|
46
|
+
setRowsCount,
|
|
47
|
+
currentRowHeight,
|
|
48
|
+
currentRowHeaderHeight,
|
|
49
|
+
size,
|
|
50
|
+
sortColumns,
|
|
51
|
+
setSortColumns
|
|
52
|
+
} = useDataGrid();
|
|
20
53
|
const ref_data_grid = useRef(null);
|
|
54
|
+
const [popoverState, setPopoverState] = useState({
|
|
55
|
+
anchorEl: null,
|
|
56
|
+
columnKey: null
|
|
57
|
+
});
|
|
21
58
|
const onRowClick = (row) => {
|
|
22
59
|
if (selectedRows && onSelectedRowsChange) {
|
|
23
60
|
if (selectedRows.entries().next().value) {
|
|
@@ -32,11 +69,17 @@ function Table(props) {
|
|
|
32
69
|
useEffect(() => {
|
|
33
70
|
let columnIndice = 0;
|
|
34
71
|
for (const column of finalColumns) {
|
|
35
|
-
const index = sortColumns.findIndex(
|
|
72
|
+
const index = sortColumns.findIndex(
|
|
73
|
+
(sortColumn) => column.key === sortColumn.columnKey
|
|
74
|
+
);
|
|
36
75
|
if (index !== -1) {
|
|
37
|
-
ref_data_grid.current?.element?.querySelector(
|
|
76
|
+
ref_data_grid.current?.element?.querySelector(
|
|
77
|
+
`[role="columnheader"][aria-colindex="${columnIndice + 1}"]`
|
|
78
|
+
)?.setAttribute("aria-columnsort", `${sortColumns[index].direction}`);
|
|
38
79
|
} else {
|
|
39
|
-
ref_data_grid.current?.element?.querySelector(
|
|
80
|
+
ref_data_grid.current?.element?.querySelector(
|
|
81
|
+
`[role="columnheader"][aria-colindex="${columnIndice + 1}"]`
|
|
82
|
+
)?.removeAttribute("aria-columnsort");
|
|
40
83
|
}
|
|
41
84
|
columnIndice++;
|
|
42
85
|
}
|
|
@@ -47,31 +90,51 @@ function Table(props) {
|
|
|
47
90
|
const onColumnResize = (idx, width) => {
|
|
48
91
|
onChangeColumnWidth(finalColumns[idx].key, width);
|
|
49
92
|
};
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
93
|
+
const defaultColumnOptions = { resizable: true, sortable: true };
|
|
94
|
+
const menuActions = useHeaderMenuActions(
|
|
95
|
+
popoverState.columnKey,
|
|
96
|
+
finalColumns,
|
|
97
|
+
defaultColumnOptions.sortable
|
|
98
|
+
);
|
|
99
|
+
return /* @__PURE__ */ jsx(TableContainerStyled, { id: "WrapperTable", children: /* @__PURE__ */ jsxs(TableWrapperDataGridStyled, { ownerState: { size }, children: [
|
|
100
|
+
/* @__PURE__ */ jsx(DndProvider, { backend: HTML5Backend, context: window, children: /* @__PURE__ */ jsx(
|
|
101
|
+
DataGrid,
|
|
102
|
+
{
|
|
103
|
+
className: "rdg-light",
|
|
104
|
+
ref: ref_data_grid,
|
|
105
|
+
headerRowHeight: activeFilters ? currentRowHeaderHeight + filterHeight : currentRowHeaderHeight,
|
|
106
|
+
columns: finalColumns,
|
|
107
|
+
sortColumns,
|
|
108
|
+
onSortColumnsChange: setSortColumns,
|
|
109
|
+
onColumnResize,
|
|
110
|
+
rows: finalRows,
|
|
111
|
+
onRowsChange,
|
|
112
|
+
selectedRows,
|
|
113
|
+
onSelectedRowsChange,
|
|
114
|
+
onRowClick,
|
|
115
|
+
rowHeight: currentRowHeight,
|
|
116
|
+
rowKeyGetter,
|
|
117
|
+
cellNavigationMode: "LOOP_OVER_ROW",
|
|
118
|
+
components: { checkboxFormatter: CheckboxFormatter },
|
|
119
|
+
defaultColumnOptions
|
|
120
|
+
}
|
|
121
|
+
) }),
|
|
122
|
+
popoverState.columnKey && popoverState.anchorEl instanceof HTMLDivElement && /* @__PURE__ */ jsx(
|
|
123
|
+
HeaderRenderClick,
|
|
124
|
+
{
|
|
125
|
+
externalOpen: popoverState.anchorEl,
|
|
126
|
+
onOpen: (open) => {
|
|
127
|
+
if (!open) {
|
|
128
|
+
setPopoverState({
|
|
129
|
+
anchorEl: null,
|
|
130
|
+
columnKey: null
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
menuActions
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
] }) });
|
|
75
138
|
}
|
|
76
139
|
export {
|
|
77
140
|
Table as T
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { u as useDataGrid } from "../../../hooks/useDataGrid.js";
|
|
3
3
|
import { useTheme } from "@mui/material";
|
|
4
|
-
import {
|
|
4
|
+
import { e as DATAGRID_SEMANTIC_WIDTHS, f as DATAGRID_ACTIONS_COLUMN_KEY } from "../../../constants.js";
|
|
5
5
|
import { M as MenuActions } from "../../../../MenuActions/MenuActions.js";
|
|
6
6
|
function ActionsFormatter(props) {
|
|
7
7
|
const { rowActionsGetter } = useDataGrid();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HeaderRendererProps } from 'react-data-grid';
|
|
2
2
|
interface DraggableHeaderRendererProps<TRow> extends HeaderRendererProps<TRow> {
|
|
3
3
|
onColumnsReorder: (sourceKey: string, targetKey: string) => void;
|
|
4
|
+
openPopover?: (anchorEl: HTMLElement, columnKey: string) => void;
|
|
4
5
|
}
|
|
5
6
|
/**
|
|
6
7
|
* TODO: Documentar
|