@m4l/components 9.2.60-J18062025.beta.1 → 9.2.60-J24062025.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.styles.js +2 -3
- package/components/DataGrid/icons.d.ts +1 -0
- package/components/DataGrid/icons.js +1 -0
- package/components/DataGrid/subcomponents/Table/hooks/useHeaderMenuActions.js +5 -2
- package/components/DataGrid/subcomponents/Table/subcomponents/DraggableHeaderRenderer.js +44 -8
- package/components/DataGrid/subcomponents/Table/subcomponents/HeaderRenderClick/HeaderRenderClick.js +11 -1
- package/components/mui_extended/CheckBox/CheckBox.styles.js +2 -1
- package/hooks/useDynamicFilterAndSort/useDynamicFilterAndSort.d.ts +3 -7
- package/hooks/useDynamicFilterAndSort/useDynamicFilterAndSort.js +39 -5
- package/package.json +1 -1
- package/storybook/components/DataGrid/subcomponents/DataGridRender.d.ts +2 -0
- package/storybook/components/DataGrid/subcomponents/DataGridRenderWithExternalFiltersAndSorts.d.ts +0 -16
|
@@ -625,11 +625,10 @@ const dataGridStyles = {
|
|
|
625
625
|
/**
|
|
626
626
|
* Estilos para el contenedor del nombre de la columna y el icono de sort
|
|
627
627
|
*/
|
|
628
|
-
nameColumnIcon: () => ({
|
|
628
|
+
nameColumnIcon: ({ theme }) => ({
|
|
629
629
|
display: "flex",
|
|
630
630
|
alignItems: "center",
|
|
631
|
-
|
|
632
|
-
gap: "5px"
|
|
631
|
+
gap: theme.vars.size.baseSpacings.sp1
|
|
633
632
|
}),
|
|
634
633
|
/**
|
|
635
634
|
* Estilos para el popover del header actions
|
|
@@ -15,6 +15,7 @@ const pathIcons = {
|
|
|
15
15
|
search: "frontend/components/data_grid/assets/icons/search.svg",
|
|
16
16
|
sortAsc: "frontend/components/data_grid/assets/icons/sort_asc.svg",
|
|
17
17
|
sortDesc: "frontend/components/data_grid/assets/icons/sort_desc.svg",
|
|
18
|
+
filter2: "frontend/components/data_grid/assets/icons/filter.svg",
|
|
18
19
|
removeSort: "frontend/components/data_grid/assets/icons/eraser.svg",
|
|
19
20
|
freezeColumn: "frontend/components/data_grid/assets/icons/pin.svg",
|
|
20
21
|
unfreezeColumn: "frontend/components/data_grid/assets/icons/pin-off.svg",
|
|
@@ -21,7 +21,10 @@ function useHeaderMenuActions(columnKey, finalColumns, defaultSortable) {
|
|
|
21
21
|
if (!columnKey) {
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
if (typeof column?.sortable === "boolean") {
|
|
25
|
+
return column.sortable;
|
|
26
|
+
}
|
|
27
|
+
return defaultSortable;
|
|
25
28
|
}, [columnKey, column, defaultSortable]);
|
|
26
29
|
const canSortExternally = useMemo(() => {
|
|
27
30
|
if (!columnKey || !externalSortSettings) {
|
|
@@ -208,7 +211,7 @@ function useHeaderMenuActions(columnKey, finalColumns, defaultSortable) {
|
|
|
208
211
|
const filterAction = externalFilterSettings ? [
|
|
209
212
|
{
|
|
210
213
|
type: "menuItem",
|
|
211
|
-
startIcon: `${host_static_assets}/${environment_assets}/${pathIcons.
|
|
214
|
+
startIcon: `${host_static_assets}/${environment_assets}/${pathIcons.filter2}`,
|
|
212
215
|
label: getLabel(DICTIONARY.ADD_FILTER_COLUMN),
|
|
213
216
|
dataTestId: "filter-add",
|
|
214
217
|
onClick: () => {
|
|
@@ -20,14 +20,16 @@ function DraggableHeaderRenderer(props) {
|
|
|
20
20
|
} = props;
|
|
21
21
|
const { ref, tabIndex } = useFocusRef(isCellSelected);
|
|
22
22
|
const { getLabel } = useModuleDictionary();
|
|
23
|
-
const { size, classes } = useDataGrid();
|
|
23
|
+
const { size, classes, externalSortSettings, externalFilterSettings } = useDataGrid();
|
|
24
24
|
const { host_static_assets, environment_assets } = useEnvironment();
|
|
25
25
|
const { activeFilters, filters, onChangeFilter } = useFilters();
|
|
26
|
-
const { externalSortSettings } = useDataGrid();
|
|
27
26
|
const [filter, setFilter] = useState(filters?.get(column.key) || "");
|
|
28
27
|
const currentExternalSort = externalSortSettings?.sortsApplied?.find(
|
|
29
28
|
(s) => s.columnKey === column.key
|
|
30
29
|
);
|
|
30
|
+
const currentExternalFilter = externalFilterSettings?.filtersApplied?.find(
|
|
31
|
+
(f) => f.columnKey === column.key
|
|
32
|
+
);
|
|
31
33
|
const [{ isDragging }, drag] = useDrag({
|
|
32
34
|
type: "COLUMN_DRAG",
|
|
33
35
|
item: { key: column.key },
|
|
@@ -57,6 +59,38 @@ function DraggableHeaderRenderer(props) {
|
|
|
57
59
|
setFilter(e.target.value);
|
|
58
60
|
};
|
|
59
61
|
const getSortIcon = (direction) => direction === "asc" ? `${host_static_assets}/${environment_assets}/${pathIcons.sortAsc}` : `${host_static_assets}/${environment_assets}/${pathIcons.sortDesc}`;
|
|
62
|
+
const getColumnIcons = () => {
|
|
63
|
+
const icons = [];
|
|
64
|
+
if (currentExternalSort) {
|
|
65
|
+
const sortIconPath = getSortIcon(currentExternalSort.direction);
|
|
66
|
+
icons.push(
|
|
67
|
+
/* @__PURE__ */ jsx(
|
|
68
|
+
Icon,
|
|
69
|
+
{
|
|
70
|
+
src: sortIconPath,
|
|
71
|
+
size: "small",
|
|
72
|
+
color: "text.secondary"
|
|
73
|
+
},
|
|
74
|
+
"sort-icon"
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (currentExternalFilter?.isValid) {
|
|
79
|
+
const filterIconPath = `${host_static_assets}/${environment_assets}/${pathIcons.filter2}`;
|
|
80
|
+
icons.push(
|
|
81
|
+
/* @__PURE__ */ jsx(
|
|
82
|
+
Icon,
|
|
83
|
+
{
|
|
84
|
+
src: filterIconPath,
|
|
85
|
+
size: "small",
|
|
86
|
+
color: "text.secondary"
|
|
87
|
+
},
|
|
88
|
+
"filter-icon"
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return icons.length > 0 ? icons : null;
|
|
93
|
+
};
|
|
60
94
|
useEffect(() => {
|
|
61
95
|
if (!activeFilters) {
|
|
62
96
|
setFilter("");
|
|
@@ -66,12 +100,14 @@ function DraggableHeaderRenderer(props) {
|
|
|
66
100
|
if (newColumn.withinHeaderRenderer) {
|
|
67
101
|
newColumn.name = newColumn.withinHeaderRenderer(props);
|
|
68
102
|
}
|
|
69
|
-
if (
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
newColumn.name,
|
|
73
|
-
|
|
74
|
-
|
|
103
|
+
if (!newColumn.withinHeaderRenderer) {
|
|
104
|
+
const columnIcons = getColumnIcons();
|
|
105
|
+
if (columnIcons) {
|
|
106
|
+
newColumn.name = /* @__PURE__ */ jsxs(NameColumnIconStyled, { children: [
|
|
107
|
+
newColumn.name,
|
|
108
|
+
columnIcons
|
|
109
|
+
] });
|
|
110
|
+
}
|
|
75
111
|
}
|
|
76
112
|
return /* @__PURE__ */ jsxs(
|
|
77
113
|
DraggableHeaderRootStyled,
|
package/components/DataGrid/subcomponents/Table/subcomponents/HeaderRenderClick/HeaderRenderClick.js
CHANGED
|
@@ -7,6 +7,7 @@ import { M as MenuDivider } from "../../../../../mui_extended/MenuDivider/MenuDi
|
|
|
7
7
|
import { P as Popover } from "../../../../../mui_extended/Popover/Popover.js";
|
|
8
8
|
import { D as DICTIONARY } from "../../../../dictionary.js";
|
|
9
9
|
import { g as DATAGRID_HEADER_RENDER_CLICK_KEY } from "../../../../constants.js";
|
|
10
|
+
import { u as useFilters } from "../../../../hooks/useFilters.js";
|
|
10
11
|
function HeaderRenderClick(props) {
|
|
11
12
|
const {
|
|
12
13
|
menuActions,
|
|
@@ -22,6 +23,7 @@ function HeaderRenderClick(props) {
|
|
|
22
23
|
...other
|
|
23
24
|
} = props;
|
|
24
25
|
const { getLabel } = useModuleDictionary();
|
|
26
|
+
const { activeFilters } = useFilters();
|
|
25
27
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
26
28
|
const resolvedAnchorEl = externalOpen ?? anchorEl;
|
|
27
29
|
const open = typeof externalOpen !== "undefined" ? Boolean(externalOpen) : Boolean(anchorEl);
|
|
@@ -122,7 +124,15 @@ function HeaderRenderClick(props) {
|
|
|
122
124
|
arrowType,
|
|
123
125
|
...other,
|
|
124
126
|
slots: { ...slots },
|
|
125
|
-
slotProps: {
|
|
127
|
+
slotProps: {
|
|
128
|
+
paper: {
|
|
129
|
+
...paperProps,
|
|
130
|
+
sx: {
|
|
131
|
+
mt: !activeFilters ? 0 : 6.5,
|
|
132
|
+
...paperProps?.sx
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
126
136
|
disableAutoFocus: true,
|
|
127
137
|
disableEnforceFocus: true,
|
|
128
138
|
anchorOrigin: { vertical: "bottom", horizontal: "left" },
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { FilterFieldApplied } from '../../components/DynamicFilter/types';
|
|
2
|
-
import { SortFieldApplied } from '../../components/DynamicSort/types';
|
|
3
1
|
import { UseDynamicFilterAndSortProps } from './types';
|
|
4
|
-
import {
|
|
2
|
+
import { SortSettings, FilterSettings } from '../../components/DataGrid/types';
|
|
5
3
|
/**
|
|
6
4
|
* Hook para manejar los filtros y ordenamientos dinamicos
|
|
7
5
|
*/
|
|
@@ -10,8 +8,6 @@ export declare const useDynamicFilterAndSort: (props: UseDynamicFilterAndSortPro
|
|
|
10
8
|
rightActions: import("react/jsx-runtime").JSX.Element;
|
|
11
9
|
visibleCustomHeader: boolean;
|
|
12
10
|
customHeaderComponent: import("react/jsx-runtime").JSX.Element;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
handleChangeFilterExternal: (event: FilterChangeEvent) => void;
|
|
16
|
-
getCurrentFilters: () => FilterFieldApplied[];
|
|
11
|
+
externalSortSettings: SortSettings | undefined;
|
|
12
|
+
externalFilterSettings: FilterSettings | undefined;
|
|
17
13
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useEnvironment, useModuleDictionary } from "@m4l/core";
|
|
3
|
-
import { useState, useRef, useMemo, useCallback } from "react";
|
|
3
|
+
import { useState, useRef, useMemo, useCallback, useReducer } from "react";
|
|
4
4
|
import { D as DynamicFilter } from "../../components/DynamicFilter/DynamicFilter.js";
|
|
5
5
|
import { D as DynamicSort } from "../../components/DynamicSort/DynamicSort.js";
|
|
6
6
|
import { I as IconButton } from "../../components/mui_extended/IconButton/IconButton.js";
|
|
@@ -78,6 +78,10 @@ const useDynamicFilterAndSort = (props) => {
|
|
|
78
78
|
}
|
|
79
79
|
return true;
|
|
80
80
|
}, [eventRefs, fields]);
|
|
81
|
+
const [changeFlags, dispatchChangeFlag] = useReducer(
|
|
82
|
+
(state, action) => ({ ...state, [action]: !state[action] }),
|
|
83
|
+
{ filters: false, sorts: false }
|
|
84
|
+
);
|
|
81
85
|
const handleChangeFilters = useCallback(
|
|
82
86
|
(filters, rawFilters) => {
|
|
83
87
|
setInvisibleBadge((prev) => ({ ...prev, filter: filters.length === 0 }));
|
|
@@ -96,6 +100,7 @@ const useDynamicFilterAndSort = (props) => {
|
|
|
96
100
|
onChangeFilterSort(eventRefs.current);
|
|
97
101
|
}
|
|
98
102
|
refOnChangeFilterSort.current++;
|
|
103
|
+
dispatchChangeFlag("filters");
|
|
99
104
|
},
|
|
100
105
|
[onChangeFilterSort, prefixCookie, setCookie, setInvisibleBadge, sorts]
|
|
101
106
|
);
|
|
@@ -118,6 +123,7 @@ const useDynamicFilterAndSort = (props) => {
|
|
|
118
123
|
} else {
|
|
119
124
|
refOnChangeFilterSort.current++;
|
|
120
125
|
}
|
|
126
|
+
dispatchChangeFlag("sorts");
|
|
121
127
|
},
|
|
122
128
|
[
|
|
123
129
|
onChangeFilterSort,
|
|
@@ -360,15 +366,43 @@ const useDynamicFilterAndSort = (props) => {
|
|
|
360
366
|
),
|
|
361
367
|
[togglesLeftActions, dataTestId, dynamicsFiltersSorts]
|
|
362
368
|
);
|
|
369
|
+
const externalSortSettings = useMemo(() => {
|
|
370
|
+
if (!sorts || sorts.length === 0) {
|
|
371
|
+
return void 0;
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
sortsColumns: sorts.map((sort) => sort.name),
|
|
375
|
+
sortsApplied: getCurrentSorts().map((sort) => ({
|
|
376
|
+
columnKey: sort.field.name,
|
|
377
|
+
removable: !sort.fixed,
|
|
378
|
+
direction: sort.operator
|
|
379
|
+
})),
|
|
380
|
+
onChange: handleChangeSortExternal
|
|
381
|
+
};
|
|
382
|
+
}, [sorts, changeFlags.sorts, getCurrentSorts, handleChangeSortExternal]);
|
|
383
|
+
const externalFilterSettings = useMemo(() => {
|
|
384
|
+
if (!fields || fields.length === 0) {
|
|
385
|
+
return void 0;
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
filterColumns: fields.map((filter) => ({
|
|
389
|
+
name: filter.name,
|
|
390
|
+
multiple: filter.multiple || false
|
|
391
|
+
})),
|
|
392
|
+
filtersApplied: getCurrentFilters().map((filter) => ({
|
|
393
|
+
columnKey: filter.field.name,
|
|
394
|
+
isValid: filter.isSet
|
|
395
|
+
})),
|
|
396
|
+
onChange: handleChangeFilterExternal
|
|
397
|
+
};
|
|
398
|
+
}, [fields, changeFlags.filters, getCurrentFilters, handleChangeFilterExternal]);
|
|
363
399
|
return {
|
|
364
400
|
leftActions,
|
|
365
401
|
rightActions: finalRightActions,
|
|
366
402
|
visibleCustomHeader,
|
|
367
403
|
customHeaderComponent,
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
handleChangeFilterExternal,
|
|
371
|
-
getCurrentFilters
|
|
404
|
+
externalSortSettings,
|
|
405
|
+
externalFilterSettings
|
|
372
406
|
};
|
|
373
407
|
};
|
|
374
408
|
export {
|
package/package.json
CHANGED
|
@@ -8,6 +8,8 @@ interface DataGridRenderProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> {
|
|
|
8
8
|
dynamicColumns?: boolean;
|
|
9
9
|
filterSortAutomatic?: boolean;
|
|
10
10
|
visibleRefreshFilterSort?: boolean;
|
|
11
|
+
withExternalSortSettings?: boolean;
|
|
12
|
+
withExternalFilterSettings?: boolean;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* Componente que renderiza el DataGrid para el storybook
|
package/storybook/components/DataGrid/subcomponents/DataGridRenderWithExternalFiltersAndSorts.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { DataGridProps, RowKey } from '../../../../src/components/DataGrid/types';
|
|
2
|
-
import { RowType, SeedProps } from '../helpers/types';
|
|
3
|
-
interface DataGridRenderProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> {
|
|
4
|
-
dataGridProps: DataGridProps<TRow, TSummaryRow, TKey>;
|
|
5
|
-
seedProps: SeedProps;
|
|
6
|
-
rowsSelecteds?: boolean;
|
|
7
|
-
withCustomHeader?: boolean;
|
|
8
|
-
dynamicColumns?: boolean;
|
|
9
|
-
filterSortAutomatic?: boolean;
|
|
10
|
-
visibleRefreshFilterSort?: boolean;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Componente que renderiza el DataGrid para el storybook
|
|
14
|
-
*/
|
|
15
|
-
declare function DataGridRenderWithActions<TKey extends RowKey = RowKey>(props: DataGridRenderProps<RowType, unknown, TKey>): import("react/jsx-runtime").JSX.Element;
|
|
16
|
-
export default DataGridRenderWithActions;
|