@m4l/components 9.2.17 → 9.2.19

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.
Files changed (104) hide show
  1. package/components/DataGrid/contexts/DataGridContext/index.js +18 -3
  2. package/components/DataGrid/subcomponents/Table/hooks/useSortColumnsRows.js +8 -5
  3. package/components/DynamicFilter/DynamicFilter.d.ts +7 -3
  4. package/components/DynamicFilter/DynamicFilter.js +4 -3
  5. package/components/DynamicFilter/{DynamicFIlter.styles.d.ts → DynamicFilter.styles.d.ts} +1 -1
  6. package/components/DynamicFilter/{DynamicFIlter.styles.js → DynamicFilter.styles.js} +20 -2
  7. package/components/DynamicFilter/dictionary.d.ts +6 -1
  8. package/components/DynamicFilter/helpers/frontEndHelpers.js +2 -2
  9. package/components/DynamicFilter/index.d.ts +3 -3
  10. package/components/DynamicFilter/slots/dynamicFilterSlots.js +2 -2
  11. package/components/DynamicFilter/store/DynamicFilterContext.d.ts +4 -4
  12. package/components/DynamicFilter/store/DynamicFilterContext.js +25 -10
  13. package/components/DynamicFilter/store/DynamicFilterStore.js +32 -17
  14. package/components/DynamicFilter/store/types.d.ts +10 -33
  15. package/components/DynamicFilter/subcomponents/AppliedFilterChip/useAppliedFilterChip.js +1 -1
  16. package/components/DynamicFilter/subcomponents/AppliedFilters/AppliedFilters.d.ts +1 -1
  17. package/components/DynamicFilter/subcomponents/AppliedFilters/useAppliedFilters.d.ts +1 -1
  18. package/components/DynamicFilter/subcomponents/DynamicFilterBase/DynamicFilterBase.d.ts +1 -1
  19. package/components/DynamicFilter/subcomponents/DynamicFilterBase/DynamicFilterBase.js +3 -3
  20. package/components/DynamicFilter/subcomponents/DynamicFilterBase/useDynamicFilterBase.d.ts +4 -3
  21. package/components/DynamicFilter/subcomponents/DynamicFilterBase/useDynamicFilterBase.js +2 -1
  22. package/components/DynamicFilter/subcomponents/FieldTypes/BooleanFilter/helpers.d.ts +9 -8
  23. package/components/DynamicFilter/subcomponents/FieldTypes/BooleanFilter/helpers.js +7 -7
  24. package/components/DynamicFilter/subcomponents/FieldTypes/BooleanFilter/index.d.ts +1 -1
  25. package/components/DynamicFilter/subcomponents/FieldTypes/BooleanFilter/index.js +1 -1
  26. package/components/DynamicFilter/subcomponents/FieldTypes/DataTypeComponent.d.ts +2 -2
  27. package/components/DynamicFilter/subcomponents/FieldTypes/DateTimeFilter/helpers.d.ts +8 -8
  28. package/components/DynamicFilter/subcomponents/FieldTypes/DateTimeFilter/helpers.js +7 -7
  29. package/components/DynamicFilter/subcomponents/FieldTypes/DateTimeFilter/index.js +1 -1
  30. package/components/DynamicFilter/subcomponents/FieldTypes/FieldTypeInterface.d.ts +2 -2
  31. package/components/DynamicFilter/subcomponents/FieldTypes/NumberFilter/helpers.d.ts +8 -8
  32. package/components/DynamicFilter/subcomponents/FieldTypes/NumberFilter/helpers.js +7 -7
  33. package/components/DynamicFilter/subcomponents/FieldTypes/NumberFilter/index.js +2 -2
  34. package/components/DynamicFilter/subcomponents/FieldTypes/SelectAsyncFilter/helpers.d.ts +8 -8
  35. package/components/DynamicFilter/subcomponents/FieldTypes/SelectAsyncFilter/helpers.js +7 -7
  36. package/components/DynamicFilter/subcomponents/FieldTypes/SelectAsyncFilter/index.js +1 -1
  37. package/components/DynamicFilter/subcomponents/FieldTypes/SelectFilter/helpers.d.ts +6 -6
  38. package/components/DynamicFilter/subcomponents/FieldTypes/SelectFilter/helpers.js +5 -5
  39. package/components/DynamicFilter/subcomponents/FieldTypes/SelectFilter/index.js +1 -1
  40. package/components/DynamicFilter/subcomponents/FieldTypes/StringFilter/helpers.d.ts +8 -8
  41. package/components/DynamicFilter/subcomponents/FieldTypes/StringFilter/helpers.js +7 -7
  42. package/components/DynamicFilter/subcomponents/FieldTypes/StringFilter/index.js +1 -1
  43. package/components/DynamicFilter/subcomponents/FieldTypes/fieldFactory.d.ts +3 -3
  44. package/components/DynamicFilter/subcomponents/FieldTypes/fieldFactory.js +1 -1
  45. package/components/DynamicFilter/subcomponents/FilterActions/FilterActions.js +5 -5
  46. package/components/DynamicFilter/subcomponents/FilterActions/useFilterActions.d.ts +1 -1
  47. package/components/DynamicFilter/subcomponents/FilterActions/useFilterActions.js +1 -1
  48. package/components/DynamicFilter/subcomponents/InputFilter/useInputFilter.d.ts +1 -1
  49. package/components/DynamicFilter/subcomponents/InputFilter/useInputFilter.js +2 -2
  50. package/components/DynamicFilter/subcomponents/PopoverFilter/PopoverFilter.d.ts +1 -1
  51. package/components/DynamicFilter/subcomponents/PopoverFilter/PopoverFilter.js +3 -3
  52. package/components/DynamicFilter/subcomponents/PopoverFilter/usePopoverFilter.d.ts +3 -3
  53. package/components/DynamicFilter/subcomponents/PopoverFilter/usePopoverFilter.js +2 -2
  54. package/components/DynamicFilter/subcomponents/PopoverMenuFields/PopoverMenuFields.d.ts +1 -1
  55. package/components/DynamicFilter/subcomponents/PopoverMenuFields/PopoverMenuFields.js +1 -1
  56. package/components/DynamicFilter/subcomponents/PopoverMenuFields/usePopoverMenuFields.d.ts +1 -1
  57. package/components/DynamicFilter/subcomponents/PopoverMenuFields/usePopoverMenuFields.js +1 -1
  58. package/components/DynamicFilter/types.d.ts +23 -8
  59. package/components/DynamicSort/DynamicSort.d.ts +2 -2
  60. package/components/DynamicSort/DynamicSort.js +4 -3
  61. package/components/DynamicSort/DynamicSort.styles.js +20 -2
  62. package/components/DynamicSort/dictionary.d.ts +6 -1
  63. package/components/DynamicSort/dictionary.js +2 -3
  64. package/components/DynamicSort/helpers/getPurgedInitialSortApplyed.d.ts +1 -1
  65. package/components/DynamicSort/index.d.ts +2 -2
  66. package/components/DynamicSort/store/DynamicSortContext.d.ts +3 -3
  67. package/components/DynamicSort/store/DynamicSortContext.js +24 -9
  68. package/components/DynamicSort/store/DynamicSortStore.d.ts +2 -2
  69. package/components/DynamicSort/store/DynamicSortStore.js +31 -16
  70. package/components/DynamicSort/store/types.d.ts +9 -15
  71. package/components/DynamicSort/subcomponents/AppliedSortChip/useAppliedSortChip.js +1 -1
  72. package/components/DynamicSort/subcomponents/AppliedSorts/AppliedSorts.js +1 -1
  73. package/components/DynamicSort/subcomponents/DynamicSortBase/DynamicSortBase.js +2 -3
  74. package/components/DynamicSort/subcomponents/DynamicSortBase/useDynamicSortBase.d.ts +2 -1
  75. package/components/DynamicSort/subcomponents/DynamicSortBase/useDynamicSortBase.js +2 -1
  76. package/components/DynamicSort/subcomponents/FieldTypes/DataTypeComponent.d.ts +1 -1
  77. package/components/DynamicSort/subcomponents/FieldTypes/FieldTypeInterface.d.ts +2 -2
  78. package/components/DynamicSort/subcomponents/FieldTypes/StringSort/helpers.d.ts +1 -1
  79. package/components/DynamicSort/subcomponents/FieldTypes/StringSort/helpers.js +1 -1
  80. package/components/DynamicSort/subcomponents/FieldTypes/StringSort/index.js +2 -2
  81. package/components/DynamicSort/subcomponents/InputSort/useInputSort.d.ts +1 -1
  82. package/components/DynamicSort/subcomponents/InputSort/useInputSort.js +3 -3
  83. package/components/DynamicSort/subcomponents/PopoverMenuFields/PopoverMenuFields.d.ts +1 -1
  84. package/components/DynamicSort/subcomponents/PopoverMenuFields/PopoverMenuFields.js +1 -1
  85. package/components/DynamicSort/subcomponents/PopoverMenuFields/usePopoverMenuFields.d.ts +1 -1
  86. package/components/DynamicSort/subcomponents/PopoverMenuFields/usePopoverMenuFields.js +1 -1
  87. package/components/DynamicSort/subcomponents/PopoverSort/PopoverSort.d.ts +1 -1
  88. package/components/DynamicSort/subcomponents/PopoverSort/usePopoverSort.d.ts +2 -2
  89. package/components/DynamicSort/subcomponents/PopoverSort/usePopoverSort.js +2 -2
  90. package/components/DynamicSort/subcomponents/SortActions/SortActions.d.ts +3 -1
  91. package/components/DynamicSort/subcomponents/SortActions/SortActions.js +7 -7
  92. package/components/DynamicSort/subcomponents/SortActions/useSortActions.d.ts +1 -1
  93. package/components/DynamicSort/subcomponents/SortActions/useSortActions.js +2 -2
  94. package/components/DynamicSort/types.d.ts +25 -8
  95. package/hooks/useDynamicFilterAndSort/styles.js +4 -2
  96. package/hooks/useDynamicFilterAndSort/types.d.ts +2 -1
  97. package/hooks/useDynamicFilterAndSort/useDynamicFilterAndSort.js +31 -9
  98. package/index.js +29 -29
  99. package/package.json +2 -2
  100. package/storybook/components/DataGrid/DataGrid.stories.d.ts +9 -2
  101. package/storybook/components/DataGrid/subcomponents/DataGridRender.d.ts +3 -0
  102. package/storybook/components/DynamicFilter/DynamicFilter.stories.d.ts +4 -0
  103. package/storybook/components/DynamicSort/DynamicSort.stories.d.ts +5 -1
  104. /package/components/DynamicSort/{slots → store}/tests/DynamicSort.test.d.ts +0 -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
- setColumnsWidths(getColumnsWidth(id, columns, defaultUserColumns));
149
- setColumnsConfigOptions(getColumnsConfig(id, columns, defaultUserColumns));
150
- }, [columns, id, defaultUserColumns]);
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
- // Sort for index
47
- getColumIndex(a.key, columnsConfig) - getColumIndex(b.key, columnsConfig)
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 : true,
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) => {
@@ -1,5 +1,9 @@
1
- import { DynamicFilterProps } from './types';
1
+ import { DynamicFilterProps, DynamicFilterRef } from './types';
2
2
  /**
3
- * TODO: Documentar
3
+ * DynamicFilter: Componente que renderiza filtros dinámicos para una lista de elementos.
4
+ *
5
+ * ### Dependecias:
6
+ *- **`useFlagsPresent:`** Hook que permite verificar si una lista de flags se encuentran presentes.
7
+ *
4
8
  */
5
- export declare function DynamicFilter(props: DynamicFilterProps): import("react/jsx-runtime").JSX.Element | null;
9
+ export declare const DynamicFilter: import('react').ForwardRefExoticComponent<DynamicFilterProps & import('react').RefAttributes<DynamicFilterRef>>;
@@ -1,14 +1,15 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { useFlagsPresent, CommonFlags } from "@m4l/core";
3
+ import { forwardRef } from "react";
3
4
  import { D as DynamicFilterProvider } from "./store/DynamicFilterContext.js";
4
5
  import { D as DynamicFilterBase } from "./subcomponents/DynamicFilterBase/DynamicFilterBase.js";
5
- function DynamicFilter(props) {
6
+ const DynamicFilter = forwardRef((props, ref) => {
6
7
  const hasPresentFlags = useFlagsPresent([CommonFlags.FLAG_DICTIONARY_LOADED]);
7
8
  if (!hasPresentFlags) {
8
9
  return null;
9
10
  }
10
- return /* @__PURE__ */ jsx(DynamicFilterProvider, { ...props, children: /* @__PURE__ */ jsx(DynamicFilterBase, {}) });
11
- }
11
+ return /* @__PURE__ */ jsx(DynamicFilterProvider, { ...props, ref, children: /* @__PURE__ */ jsx(DynamicFilterBase, {}) });
12
+ });
12
13
  export {
13
14
  DynamicFilter as D
14
15
  };
@@ -1,2 +1,2 @@
1
- import { DynamicFilterStyles } from '../DynamicFilter/types';
1
+ import { DynamicFilterStyles } from './types';
2
2
  export declare const dynamicFilterStyles: DynamicFilterStyles;
@@ -128,7 +128,7 @@ const dynamicFilterStyles = {
128
128
  /**
129
129
  * actions: Estilos del contenedor de los botones de acción.
130
130
  */
131
- actions: ({ theme }) => ({
131
+ actions: ({ theme, ownerState }) => ({
132
132
  gridArea: "actions-filter",
133
133
  overflow: "hidden",
134
134
  display: "flex",
@@ -139,7 +139,7 @@ const dynamicFilterStyles = {
139
139
  alignItems: "center",
140
140
  borderTopRightRadius: theme.vars.size.borderRadius.r1,
141
141
  borderBottomRightRadius: theme.vars.size.borderRadius.r1,
142
- borderLeft: theme.vars.size.borderStroke.container,
142
+ borderLeft: !ownerState.visibleRefresh && !ownerState.isDirty ? "none" : theme.vars.size.borderStroke.container,
143
143
  borderColor: theme.vars.palette.border?.default
144
144
  }),
145
145
  actionsClearButton: {
@@ -151,6 +151,24 @@ const dynamicFilterStyles = {
151
151
  actionsSubmitButton: ({ theme, ownerState }) => ({
152
152
  ...ownerState.isValid === false ? { border: `1px dashed ${theme.vars.palette.error.enabled}` } : {
153
153
  visibility: "visible"
154
+ },
155
+ ...ownerState.isDirty ? {
156
+ animation: "changeBgColor 0.9s ease infinite",
157
+ "& .M4LIcon-icon": {
158
+ background: `${theme.vars.palette.primary.main} !important`
159
+ }
160
+ } : null,
161
+ //Create and apply animation with change background color red and green
162
+ "@keyframes changeBgColor": {
163
+ "0%": {
164
+ background: theme.vars.palette.primary.hoverOpacity
165
+ },
166
+ "50%": {
167
+ background: theme.vars.palette.primary.activeOpacity
168
+ },
169
+ "100%": {
170
+ background: theme.vars.palette.primary.hoverOpacity
171
+ }
154
172
  }
155
173
  }),
156
174
  /**
@@ -1,6 +1,7 @@
1
1
  export declare const DYNAMIC_FILTER_DICTIONARY_ID = "dynamic_filter";
2
2
  /**
3
- * TODO: Documentar
3
+ * getDynamicFilterComponentsDictionary: Devuelve un array con los ids de los componentes que
4
+ * componente DynamicFilter.
4
5
  */
5
6
  export declare function getDynamicFilterComponentsDictionary(): string[];
6
7
  export declare const DICCTIONARY: {
@@ -39,4 +40,8 @@ export declare const DICCTIONARY: {
39
40
  readonly error_operand_required: "error_operand_required";
40
41
  };
41
42
  export type TypeDictionary = typeof DICCTIONARY;
43
+ /**
44
+ * getDynamicFilterDictionary: Devuelve el id del diccionario de un componente DynamicFilter.
45
+ * @param key - Clave del diccionario.
46
+ */
42
47
  export declare const getDynamicFilterDictionary: (key: keyof TypeDictionary) => string;
@@ -208,6 +208,6 @@ function getFilterGroupFieldsByName(fields) {
208
208
  }, {});
209
209
  }
210
210
  export {
211
- getFilterGroupFieldsByName as a,
212
- getIsIfInDynamicFilter as g
211
+ getIsIfInDynamicFilter as a,
212
+ getFilterGroupFieldsByName as g
213
213
  };
@@ -1,4 +1,4 @@
1
- export * from './DynamicFilter';
2
1
  export { getDynamicFilterComponentsDictionary } from './dictionary';
3
- export type { FilterFieldApplied as FilterFieldApply, RawFilterFieldApply, InitialFilterApplied, FilterField, } from './types';
4
- export { getIsIfInDynamicFilter, getFilterGroupFieldsByName } from './helpers/frontEndHelpers';
2
+ export * from './DynamicFilter';
3
+ export type { FilterField, FilterFieldApplied as FilterFieldApply, InitialFilterApplied, RawFilterFieldApply, } from './types';
4
+ export { getFilterGroupFieldsByName, getIsIfInDynamicFilter } from './helpers/frontEndHelpers';
@@ -1,8 +1,8 @@
1
1
  import { styled } from "@mui/material/styles";
2
+ import { S as Skeleton } from "../../mui_extended/Skeleton/Skeleton.js";
2
3
  import { D as DYNAMIC_FILTER_KEY_COMPONENT } from "../constants.js";
3
- import { d as dynamicFilterStyles } from "../DynamicFIlter.styles.js";
4
+ import { d as dynamicFilterStyles } from "../DynamicFilter.styles.js";
4
5
  import { D as DynamicFilterSlots } from "./SlotsEnum.js";
5
- import { S as Skeleton } from "../../mui_extended/Skeleton/Skeleton.js";
6
6
  import { I as IconButton } from "../../mui_extended/IconButton/IconButton.js";
7
7
  import { T as Typography } from "../../mui_extended/Typography/Typography.js";
8
8
  import { A as ActionsContainer } from "../../CommonActions/components/ActionsContainer/ActionsContainer.js";
@@ -1,11 +1,11 @@
1
1
  import { ReactNode } from 'react';
2
- import { DynamicFilterProps } from '../types';
2
+ import { DynamicFilterProps, DynamicFilterRef } from '../types';
3
3
  declare const DynamicFilterContext: import('react').Context<import('zustand').StoreApi<import('./types').DynamicFilterStateWithActions> | null>;
4
4
  interface DynamicFilterContextProps extends DynamicFilterProps {
5
5
  children: ReactNode;
6
6
  }
7
7
  /**
8
- * TODO: Documentar
8
+ * Proveedor de contexto para el componente DynamicFilter
9
9
  */
10
- declare function DynamicFilterProvider(props: DynamicFilterContextProps): import("react/jsx-runtime").JSX.Element;
11
- export { DynamicFilterProvider, DynamicFilterContext };
10
+ declare const DynamicFilterProvider: import('react').ForwardRefExoticComponent<DynamicFilterContextProps & import('react').RefAttributes<DynamicFilterRef>>;
11
+ export { DynamicFilterContext, DynamicFilterProvider };
@@ -1,16 +1,16 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { createContext, useRef, useEffect } from "react";
3
- import { useStore } from "zustand";
4
- import { shallow } from "zustand/shallow";
5
2
  import { useModuleDictionary, useEnvironment, useModuleSkeleton } from "@m4l/core";
6
3
  import { useIsMobile, useFirstRender } from "@m4l/graphics";
4
+ import { createContext, forwardRef, useRef, useImperativeHandle, useEffect } from "react";
5
+ import { useStore } from "zustand";
6
+ import { shallow } from "zustand/shallow";
7
7
  import { A as ALL_FIELD } from "../constants.js";
8
- import { f as formatToRawFilter } from "../helpers/formatToRowFilter.js";
9
8
  import { f as formatToInitialFilters } from "../helpers/formatToInitialFilters.js";
9
+ import { f as formatToRawFilter } from "../helpers/formatToRowFilter.js";
10
10
  import { c as createDynamicFilterStore } from "./DynamicFilterStore.js";
11
11
  import { u as useComponentSize } from "../../../hooks/useComponentSize/useComponentSize.js";
12
12
  const DynamicFilterContext = createContext(null);
13
- function DynamicFilterProvider(props) {
13
+ const DynamicFilterProvider = forwardRef((props, ref) => {
14
14
  const {
15
15
  automatic = true,
16
16
  withAllField = true,
@@ -21,7 +21,8 @@ function DynamicFilterProvider(props) {
21
21
  size = "medium",
22
22
  children,
23
23
  storeId,
24
- storeDevtoolsEnabled = false
24
+ storeDevtoolsEnabled = false,
25
+ visibleRefresh = true
25
26
  } = props;
26
27
  const { currentSize } = useComponentSize(size);
27
28
  const adjustedSize = currentSize === "small" || currentSize === "medium" ? currentSize : "medium";
@@ -44,9 +45,10 @@ function DynamicFilterProvider(props) {
44
45
  dataTestId,
45
46
  size,
46
47
  storeId,
48
+ visibleRefresh,
47
49
  ownerState: {
48
50
  isSkeleton,
49
- isDirty: !automatic,
51
+ isDirty: false,
50
52
  inEdition: false,
51
53
  isValid: true,
52
54
  isMobile: !isDesktop,
@@ -56,6 +58,14 @@ function DynamicFilterProvider(props) {
56
58
  }, storeDevtoolsEnabled);
57
59
  dynamicFilterStoreRef.current.getState().actions.init(initialAppliedFilters);
58
60
  }
61
+ const fireOnChangeFilters = useStore(
62
+ dynamicFilterStoreRef.current,
63
+ (state) => state.actions.fireOnChangeFilters,
64
+ shallow
65
+ );
66
+ useImperativeHandle(ref, () => ({
67
+ fireOnChangeFilter: fireOnChangeFilters
68
+ }));
59
69
  const countOnChangeFiltersApplied = useStore(
60
70
  dynamicFilterStoreRef.current,
61
71
  (state) => state.countOnChangeFiltersApplied,
@@ -86,10 +96,15 @@ function DynamicFilterProvider(props) {
86
96
  }
87
97
  }, []);
88
98
  useEffect(() => {
89
- dynamicFilterStoreRef.current?.getState().actions.setSize(adjustedSize);
90
- }, [adjustedSize]);
99
+ if (dynamicFilterStoreRef.current?.getState().size !== adjustedSize) {
100
+ dynamicFilterStoreRef.current?.getState().actions.setSize(adjustedSize);
101
+ }
102
+ if (dynamicFilterStoreRef.current?.getState().visibleRefresh !== visibleRefresh) {
103
+ dynamicFilterStoreRef.current?.getState().actions.setVisibleRefresh(visibleRefresh);
104
+ }
105
+ }, [adjustedSize, visibleRefresh]);
91
106
  return /* @__PURE__ */ jsx(DynamicFilterContext.Provider, { value: dynamicFilterStoreRef.current, children });
92
- }
107
+ });
93
108
  export {
94
109
  DynamicFilterProvider as D,
95
110
  DynamicFilterContext as a
@@ -1,8 +1,8 @@
1
1
  import { createStore } from "zustand";
2
2
  import { devtools } from "zustand/middleware";
3
3
  import { immer } from "zustand/middleware/immer";
4
- import { g as getPurgedInitialFiltersApplied } from "../helpers/getPurgedInitialFiltersApplied.js";
5
4
  import { a as DYNAMIC_FILTER_SOTORE_ID } from "../constants.js";
5
+ import { g as getPurgedInitialFiltersApplied } from "../helpers/getPurgedInitialFiltersApplied.js";
6
6
  function updateAvailableFields(state) {
7
7
  state.availableFields = state.fields.filter((field) => {
8
8
  if (field.multiple === void 0 || field.multiple) {
@@ -47,7 +47,7 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
47
47
  ...startProps,
48
48
  actions: {
49
49
  /**
50
- * TODO: Documentar
50
+ * init: Inicializa el store, se debe llamar al iniciar el componente
51
51
  */
52
52
  init: (initialFiltersApplied) => {
53
53
  set((state) => {
@@ -70,7 +70,7 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
70
70
  return elementRef;
71
71
  },
72
72
  /**
73
- * TODO: Documentar
73
+ * Actualiza el listado de campos disponibles para filtrar
74
74
  */
75
75
  getFieldByName: (name) => {
76
76
  const field = (get().withAllField ? get().fields.concat(get().allField) : get().fields).find((f) => {
@@ -82,7 +82,7 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
82
82
  throw new Error("No exist field");
83
83
  },
84
84
  /**
85
- * TODO: Documentar
85
+ * Elimina un campo filter por su id
86
86
  */
87
87
  removeFilter: (id) => {
88
88
  set((state) => {
@@ -91,11 +91,14 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
91
91
  state.appliedFilters.splice(indexToRemoved, 1);
92
92
  state.ownerState.isEmpty = state.appliedFilters.length === 0;
93
93
  updateAutomatic(state);
94
+ if (state.appliedFilters.length === 0) {
95
+ state.ownerState.isDirty = false;
96
+ }
94
97
  }
95
98
  });
96
99
  },
97
100
  /**
98
- * TODO: Documentar
101
+ * muestra el popover para agregar un nuevo filtro
99
102
  */
100
103
  showPopoverFilterForAdd: (field) => {
101
104
  set((state) => {
@@ -109,7 +112,7 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
109
112
  });
110
113
  },
111
114
  /**
112
- * TODO: Documentar
115
+ * muestra el popover para editar un filtro
113
116
  */
114
117
  showPopoverFilterForEdit: (filterToEdit) => {
115
118
  set((state) => {
@@ -122,7 +125,7 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
122
125
  get().actions.setInEdition(true);
123
126
  },
124
127
  /**
125
- * TODO: Documentar
128
+ * oculta el popover de filtros
126
129
  */
127
130
  hidePopoverFilter: (stayInEdition) => {
128
131
  set((state) => {
@@ -131,7 +134,7 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
131
134
  get().actions.setInEdition(stayInEdition);
132
135
  },
133
136
  /**
134
- * TODO: Documentar
137
+ * Limpia todos los filters aplicados
135
138
  */
136
139
  clearFilters: () => {
137
140
  set((state) => {
@@ -139,11 +142,12 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
139
142
  state.ownerState.isEmpty = state.appliedFilters.length === 0;
140
143
  state.popoverFilterData = void 0;
141
144
  state.ownerState.inEdition = false;
145
+ state.ownerState.isDirty = false;
142
146
  updateAutomatic(state);
143
147
  });
144
148
  },
145
149
  /**
146
- * TODO: Documentar
150
+ * Acción que se ejecuta al aplicar los filtros
147
151
  */
148
152
  fireOnChangeFilters: () => {
149
153
  set((state) => {
@@ -154,7 +158,7 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
154
158
  });
155
159
  },
156
160
  /**
157
- * TODO: Documentar
161
+ * obtiene el id del nuevo filtro
158
162
  */
159
163
  getNewId: () => {
160
164
  return get().appliedFilters.reduce((prev, filterField) => {
@@ -162,17 +166,20 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
162
166
  }, 0) + 1;
163
167
  },
164
168
  /**
165
- * TODO: Documentar
169
+ * agrega un nuevo filtro
166
170
  */
167
171
  addFilter: (newFilter) => {
168
172
  set((state) => {
173
+ if (!state.automatic) {
174
+ state.ownerState.isDirty = true;
175
+ }
169
176
  state.appliedFilters.push(newFilter);
170
177
  state.ownerState.isEmpty = state.appliedFilters.length === 0;
171
178
  updateAutomatic(state);
172
179
  });
173
180
  },
174
181
  /**
175
- * TODO: Documentar
182
+ * actualiza un filtro
176
183
  */
177
184
  updateFilter: (editFilter) => {
178
185
  set((state) => {
@@ -186,7 +193,7 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
186
193
  });
187
194
  },
188
195
  /**
189
- * TODO: Documentar
196
+ * actualiza el inputData
190
197
  */
191
198
  setInputData: (inputData) => {
192
199
  set((state) => {
@@ -194,7 +201,7 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
194
201
  });
195
202
  },
196
203
  /**
197
- * TODO: Documentar
204
+ * actualiza el editor de filtros
198
205
  */
199
206
  setInEdition: (newInEdition) => {
200
207
  set((state) => {
@@ -202,7 +209,7 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
202
209
  });
203
210
  },
204
211
  /**
205
- * TODO: Documentar
212
+ * actualiza el estado externo del componente
206
213
  */
207
214
  setExternalState: (newExternalState) => {
208
215
  set((state) => {
@@ -210,7 +217,7 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
210
217
  });
211
218
  },
212
219
  /**
213
- * TODO: Documentar
220
+ * abre el popover para seleccionar los campos a filtrar
214
221
  */
215
222
  openPopoverMenuFields: () => {
216
223
  set((state) => {
@@ -219,7 +226,7 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
219
226
  });
220
227
  },
221
228
  /**
222
- * TODO: Documentar
229
+ * cierra el popover para seleccionar los campos a filtrar
223
230
  */
224
231
  closePopoverMenuFields: (newInEdition) => {
225
232
  set((state) => {
@@ -235,6 +242,14 @@ const createDynamicFilterStore = (initProps, storeDevtoolsEnabled = false) => {
235
242
  state.size = newSize;
236
243
  state.ownerState.size = newSize;
237
244
  });
245
+ },
246
+ /**
247
+ * actualiza el visibleRefresh del componente
248
+ */
249
+ setVisibleRefresh: (newVisibleRefresh) => {
250
+ set((state) => {
251
+ state.visibleRefresh = newVisibleRefresh;
252
+ });
238
253
  }
239
254
  }
240
255
  })),
@@ -1,7 +1,7 @@
1
- import { MutableRefObject } from 'react';
2
1
  import { GetLabelType } from '@m4l/core';
3
2
  import { Sizes } from '@m4l/styles';
4
- import { FilterField, FilterFieldApplied, FilterToEditApply, InitialFilterApplied, OwnerState } from '../types';
3
+ import { MutableRefObject } from 'react';
4
+ import { DynamicFilterProps, FilterField, FilterFieldApplied, FilterToEditApply, InitialFilterApplied, OwnerState } from '../types';
5
5
  export type OpenFor = 'add' | 'edit';
6
6
  export interface PopoverFilterDataBase {
7
7
  /**
@@ -35,19 +35,7 @@ export type ExternalOwnerState = Pick<OwnerState, 'isMobile' | 'isSkeleton'>;
35
35
  /**
36
36
  * Interface que define el estado del componente
37
37
  */
38
- export interface DynamicFilterState {
39
- /**
40
- * "storeId" identificador del store
41
- */
42
- storeId?: string;
43
- /**
44
- * "fields" Campos por los que se puede filtrar
45
- */
46
- fields: Array<FilterField>;
47
- /**
48
- * "withAllField" indica si permite o no filtrar por todos los campos
49
- */
50
- withAllField: boolean;
38
+ export interface DynamicFilterState extends Pick<DynamicFilterProps, 'visibleRefresh' | 'size' | 'dataTestId' | 'automatic' | 'storeId' | 'withAllField' | 'fields'> {
51
39
  /**
52
40
  * "ownerState" estado a nivel de clases del componente
53
41
  */
@@ -56,19 +44,10 @@ export interface DynamicFilterState {
56
44
  * "allField" Campo que se usa cuando se puede buscar por todos los campos
57
45
  */
58
46
  allField: FilterField;
59
- /**
60
- * "automatic" Configura si el filtro se ejecuta automaticamente cuando se agrega o se modifica un filtro
61
- */
62
- automatic: boolean;
63
47
  /**
64
48
  * "isOpenPopoverMenuFields" determina si se debe abrir el menú de campos
65
49
  */
66
50
  isOpenPopoverMenuFields?: boolean;
67
- /**
68
- * Funcion que retorna el elemento (inputFilter) desde donde se desprende el listado de campos
69
- * Si no está definida, el menú de campos no se muestra
70
- * @returns
71
- */
72
51
  /**
73
52
  * "inputData" texto en el InputFilter
74
53
  */
@@ -90,16 +69,10 @@ export interface DynamicFilterState {
90
69
  * :popoverFilterData" para emerger el popuup de modificación campos
91
70
  */
92
71
  popoverFilterData?: PopoverFilterData;
93
- getLabel: GetLabelType;
94
72
  /**
95
- * dataTestId:
96
- * Esta propiedad sirve para generar identificadores únicos.
73
+ * Función utilizada para el dictionary
97
74
  */
98
- dataTestId: string;
99
- /**
100
- * size: tamaño del componente
101
- */
102
- size: Extract<Sizes, 'small' | 'medium'>;
75
+ getLabel: GetLabelType;
103
76
  }
104
77
  export interface DynamicFilterStateWithActions extends DynamicFilterState {
105
78
  actions: {
@@ -203,6 +176,10 @@ export interface DynamicFilterStateWithActions extends DynamicFilterState {
203
176
  * actualiza el tamaño del componente
204
177
  */
205
178
  setSize: (size: Extract<Sizes, 'small' | 'medium'>) => void;
179
+ /**
180
+ * actualiza el estado del componente
181
+ */
182
+ setVisibleRefresh: (newVisibleRefresh: boolean) => void;
206
183
  };
207
184
  }
208
- export type InitialStoreProps = Pick<DynamicFilterState, 'automatic' | 'fields' | 'withAllField' | 'getLabel' | 'allField' | 'ownerState' | 'dataTestId' | 'size' | 'storeId'>;
185
+ export type InitialStoreProps = Pick<DynamicFilterState, 'automatic' | 'fields' | 'withAllField' | 'getLabel' | 'allField' | 'ownerState' | 'dataTestId' | 'size' | 'storeId' | 'visibleRefresh'>;
@@ -1,6 +1,6 @@
1
- import { useMemo } from "react";
2
1
  import { useModuleDictionary } from "@m4l/core";
3
2
  import { useFormatter } from "@m4l/graphics";
3
+ import { useMemo } from "react";
4
4
  import { u as useDynamicFilterStore } from "../../store/useDynamicFilterStore.js";
5
5
  import { f as fieldFactory } from "../FieldTypes/fieldFactory.js";
6
6
  function useAppliedFilterChip(filter) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TODO: Documentar
2
+ * AppliedFilters: Muestra los filtros aplicados en el InputFilter
3
3
  */
4
4
  declare function AppliedFilters(): import("react/jsx-runtime").JSX.Element;
5
5
  export default AppliedFilters;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TODO: Documentar
2
+ * useAppliedFilters: Hook que permite obtener los filtros aplicados y su estado de carga.
3
3
  */
4
4
  declare function useAppliedFilters(): {
5
5
  appliedFiltersSorted: import('../..').FilterFieldApply[];
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TODO: Documentar
2
+ * DynamicFilterBase: Componente base del DynamicFilter.
3
3
  */
4
4
  declare function DynamicFilterBase(): import("react/jsx-runtime").JSX.Element;
5
5
  export default DynamicFilterBase;
@@ -1,8 +1,8 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { u as useDynamicFilterBase } from "./useDynamicFilterBase.js";
3
2
  import { g as getPropDataTestId } from "../../../../test/getNameDataTestId.js";
4
3
  import { a as getComponentSlotRoot } from "../../../../utils/getComponentSlotRoot.js";
5
4
  import { D as DYNAMIC_FILTER_KEY_COMPONENT } from "../../constants.js";
5
+ import { u as useDynamicFilterBase } from "./useDynamicFilterBase.js";
6
6
  import { R as RootStyled, I as InnerContainerStyled } from "../../slots/dynamicFilterSlots.js";
7
7
  import { D as DynamicFilterSlots } from "../../slots/SlotsEnum.js";
8
8
  import { I as InputFilter } from "../InputFilter/InputFilter.js";
@@ -17,12 +17,12 @@ function DynamicFilterBase() {
17
17
  {
18
18
  className: classRoot,
19
19
  ownerState: { ...ownerState },
20
- ...getPropDataTestId(dataTestId, DynamicFilterSlots.root),
20
+ ...getPropDataTestId(DYNAMIC_FILTER_KEY_COMPONENT, DynamicFilterSlots.root, dataTestId),
21
21
  children: /* @__PURE__ */ jsxs(
22
22
  InnerContainerStyled,
23
23
  {
24
24
  ownerState: { ...ownerState },
25
- ...getPropDataTestId(dataTestId, DynamicFilterSlots.innerContainer),
25
+ ...getPropDataTestId(DYNAMIC_FILTER_KEY_COMPONENT, DynamicFilterSlots.innerContainer, dataTestId),
26
26
  children: [
27
27
  /* @__PURE__ */ jsx(InputFilter, {}),
28
28
  /* @__PURE__ */ jsx(AppliedFilters, {}),
@@ -1,8 +1,9 @@
1
1
  /**
2
- * TODO: Documentar
2
+ * Hook que hace uso del store del dynamicFilterStore
3
3
  */
4
4
  export default function useDynamicFilterBase(): {
5
5
  ownerState: import('../../types').OwnerState;
6
- dataTestId: string;
7
- size: "small" | "medium";
6
+ dataTestId: string | undefined;
7
+ size: "small" | "medium" | undefined;
8
+ visibleRefresh: boolean | undefined;
8
9
  };
@@ -3,7 +3,8 @@ function useDynamicFilterBase() {
3
3
  const ownerState = useDynamicFilterStore((state) => state.ownerState);
4
4
  const dataTestId = useDynamicFilterStore((state) => state.dataTestId);
5
5
  const size = useDynamicFilterStore((state) => state.size);
6
- return { ownerState, dataTestId, size };
6
+ const visibleRefresh = useDynamicFilterStore((state) => state.visibleRefresh);
7
+ return { ownerState, dataTestId, size, visibleRefresh };
7
8
  }
8
9
  export {
9
10
  useDynamicFilterBase as u