@m4l/components 9.4.14 → 9.4.15-JT21012026.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/DynamicFilter/subcomponents/FieldTypes/BooleanFilter/helpers.js +10 -1
- package/components/DynamicFilter/types.d.ts +22 -0
- package/components/datagrids/formatters/ColumnNestedValueFormatter/formatter.d.ts +33 -1
- package/components/datagrids/formatters/ColumnNestedValueFormatter/formatter.js +3 -2
- package/components/datagrids/formatters/ColumnNestedValueFormatter/types.d.ts +19 -1
- package/components/datagrids/formatters/ColumnNestedValueFormatter/useColumnNestedValue.d.ts +34 -2
- package/components/datagrids/formatters/ColumnNestedValueFormatter/useColumnNestedValue.js +23 -9
- package/components/datagrids/tests/helpers/types.d.ts +10 -0
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import * as Yup from "yup";
|
|
|
2
2
|
import { B as BOOLEAN_OPERATORS } from "../../../constants.js";
|
|
3
3
|
import { B as BooleanFilter } from "./index.js";
|
|
4
4
|
import { D as DYNAMIC_FILTER_DICTIONARY_ID, a as DICCTIONARY } from "../../../dictionary.js";
|
|
5
|
+
import { g as getFormatBoolean } from "../../../../formatters/BooleanFormatter/BooleanFormatter.js";
|
|
5
6
|
import { c as createValidationSchema, a as createValidationFullObject, b as createValidationPartialObject } from "../../../../hook-form/RHFormProvider/schema.js";
|
|
6
7
|
class BooleanFilterHelpers {
|
|
7
8
|
getComponent() {
|
|
@@ -67,7 +68,15 @@ class BooleanFilterHelpers {
|
|
|
67
68
|
* getLabel devuelve las etiquetas para el filtro booleano.
|
|
68
69
|
*/
|
|
69
70
|
getLabels(filter, getLabel, _formatters, _field) {
|
|
70
|
-
const
|
|
71
|
+
const presentationType = filter.field.presentationType;
|
|
72
|
+
const value = filter.operand1;
|
|
73
|
+
let labelOperands;
|
|
74
|
+
if (presentationType && typeof presentationType === "object" && "trueLabel" in presentationType) {
|
|
75
|
+
labelOperands = value ? presentationType.trueLabel : presentationType.falseLabel;
|
|
76
|
+
} else {
|
|
77
|
+
const preset = presentationType ?? "string_true_false";
|
|
78
|
+
labelOperands = getFormatBoolean(preset, value, getLabel);
|
|
79
|
+
}
|
|
71
80
|
return {
|
|
72
81
|
labelField: filter.field.label ?? getLabel(filter.field.dictionaryId),
|
|
73
82
|
labelOperator: getLabel(
|
|
@@ -5,6 +5,19 @@ import { M4LOverridesStyleRules } from '../../@types/augmentations';
|
|
|
5
5
|
import { RHFAutocompleteAsyncProps } from '../hook-form/RHFAutocompleteAsync/types';
|
|
6
6
|
import { RHFSelectProps } from '../hook-form/RHFSelect';
|
|
7
7
|
import { DynamicFilterSlots } from './slots';
|
|
8
|
+
import { PresentationType } from '../formatters/BooleanFormatter/types';
|
|
9
|
+
/**
|
|
10
|
+
* Labels personalizados para valores booleanos
|
|
11
|
+
*/
|
|
12
|
+
export interface BooleanCustomLabels {
|
|
13
|
+
trueLabel: string;
|
|
14
|
+
falseLabel: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Tipo de presentación para campos booleanos en DynamicFilter.
|
|
18
|
+
* Solo incluye las presentaciones de texto del BooleanFormatter más labels personalizados.
|
|
19
|
+
*/
|
|
20
|
+
export type BooleanPresentationType = Extract<PresentationType, 'string_true_false' | 'string_yes_no'> | BooleanCustomLabels;
|
|
8
21
|
export type FieldType = 'number' | 'string' | 'boolean' | 'datetime' | 'select' | 'selectAsync';
|
|
9
22
|
export type OperandType = number | string | boolean | Date | [] | object;
|
|
10
23
|
export type OperandInitialFilterType = number | string | boolean | [] | object;
|
|
@@ -47,6 +60,15 @@ export interface FieldBase<T extends FieldType = FieldType, TOption = any> {
|
|
|
47
60
|
selectOptions?: SelectOptions;
|
|
48
61
|
selectAsyncOptions?: SelectAsyncOptions<TOption>;
|
|
49
62
|
skipColumnValidation?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Tipo de presentación para campos booleanos.
|
|
65
|
+
* Solo aplica cuando type es 'boolean'.
|
|
66
|
+
* - 'string_true_false': "Verdadero" / "Falso" (default)
|
|
67
|
+
* - 'string_yes_no': "Sí" / "No"
|
|
68
|
+
* - { trueLabel: string, falseLabel: string }: Labels personalizados
|
|
69
|
+
* @default 'string_true_false'
|
|
70
|
+
*/
|
|
71
|
+
presentationType?: BooleanPresentationType;
|
|
50
72
|
}
|
|
51
73
|
export interface FieldWithSelectAsync<T extends 'selectAsync', TOption = any> extends FieldBase<T, TOption> {
|
|
52
74
|
selectAsyncOptions: SelectAsyncOptions<TOption>;
|
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
import { ColumnNestedValueFormatterProps } from './types';
|
|
2
2
|
import { RenderCellProps } from 'react-data-grid';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Formatter para mostrar valores de propiedades anidadas en columnas del DataGrid.
|
|
5
|
+
*
|
|
6
|
+
* Este formatter permite acceder a propiedades dentro de objetos anidados usando
|
|
7
|
+
* "dot notation" (notación de punto). Es útil cuando los datos tienen estructuras
|
|
8
|
+
* complejas y necesitas mostrar un valor específico dentro de un objeto.
|
|
9
|
+
* @param props - Configuración del formatter
|
|
10
|
+
* @param props.fieldValue - Ruta a la propiedad usando dot notation (ej: 'user.profile.name')
|
|
11
|
+
* @param props.Component - Componente opcional para envolver el valor (default: React.Fragment)
|
|
12
|
+
* @param props.defaultValue - Valor a mostrar si es null/undefined (default: '-')
|
|
13
|
+
* @returns Función formatter compatible con react-data-grid
|
|
14
|
+
* @example
|
|
15
|
+
* // Filas de ejemplo:
|
|
16
|
+
* // { id: 1, user: { profile: { name: 'Juan' } } }
|
|
17
|
+
* // { id: 2, user: { profile: { name: null } } }
|
|
18
|
+
*
|
|
19
|
+
* // Uso recomendado con hook:
|
|
20
|
+
* const nestedColumn = useColumnNestedValue<MyRow>({
|
|
21
|
+
* fieldValue: 'user.profile.name',
|
|
22
|
+
* defaultValue: 'Sin nombre',
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* const columns = [
|
|
26
|
+
* {
|
|
27
|
+
* key: 'userName',
|
|
28
|
+
* name: 'Nombre',
|
|
29
|
+
* type: 'custom',
|
|
30
|
+
* ...nestedColumn, // Incluye formatter, customFilter y customSort
|
|
31
|
+
* }
|
|
32
|
+
* ];
|
|
33
|
+
*
|
|
34
|
+
* // Resultado en DataGrid:
|
|
35
|
+
* // Fila 1: "Juan"
|
|
36
|
+
* // Fila 2: "Sin nombre" (porque el valor es null)
|
|
5
37
|
*/
|
|
6
38
|
export declare function ColumnNestedValueFormatter<TRow>(props: ColumnNestedValueFormatterProps<TRow>): (formatterProps: RenderCellProps<TRow>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -3,10 +3,11 @@ import { getPropertyByString } from "@m4l/core";
|
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { g as getNullGuard } from "../../../../utils/getNullGuard.js";
|
|
5
5
|
function ColumnNestedValueFormatter(props) {
|
|
6
|
-
const { fieldValue, Component = React.Fragment } = props;
|
|
6
|
+
const { fieldValue, Component = React.Fragment, defaultValue = "-" } = props;
|
|
7
7
|
return (formatterProps) => {
|
|
8
8
|
const property = getNullGuard(
|
|
9
|
-
getPropertyByString(formatterProps.row, fieldValue)
|
|
9
|
+
getPropertyByString(formatterProps.row, fieldValue),
|
|
10
|
+
defaultValue
|
|
10
11
|
);
|
|
11
12
|
const value = typeof property === "object" ? JSON.stringify(property) : property;
|
|
12
13
|
return /* @__PURE__ */ jsx(Component, { children: value });
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { DeepKeyOf } from '../../../../utils/types';
|
|
2
2
|
export interface ColumnNestedValueFormatterProps<TRow> {
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Ruta a la propiedad anidada usando dot notation.
|
|
5
|
+
* Permite acceder a valores dentro de objetos anidados.
|
|
6
|
+
* @example
|
|
7
|
+
* // Para acceder a { user: { profile: { name: 'Juan' } } }
|
|
8
|
+
* fieldValue: 'user.profile.name' // Retorna 'Juan'
|
|
9
|
+
*/
|
|
4
10
|
fieldValue: DeepKeyOf<TRow>;
|
|
11
|
+
/**
|
|
12
|
+
* Componente opcional para envolver el valor renderizado.
|
|
13
|
+
* Por defecto usa React.Fragment.
|
|
14
|
+
* @example
|
|
15
|
+
* Component: Typography // Envuelve el valor en <Typography>{valor}</Typography>
|
|
16
|
+
*/
|
|
17
|
+
Component?: React.ElementType;
|
|
18
|
+
/**
|
|
19
|
+
* Valor a mostrar cuando la propiedad es null o undefined.
|
|
20
|
+
* Por defecto es '-'.
|
|
21
|
+
*/
|
|
22
|
+
defaultValue?: string;
|
|
5
23
|
}
|
package/components/datagrids/formatters/ColumnNestedValueFormatter/useColumnNestedValue.d.ts
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
1
|
import { ColumnNestedValueFormatterProps } from './types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Hook para crear una columna que muestra valores de propiedades anidadas.
|
|
4
|
+
* @param props - Configuración del formatter
|
|
5
|
+
* @param props.fieldValue - Ruta a la propiedad usando dot notation (ej: 'user.profile.name')
|
|
6
|
+
* @param props.Component - Componente opcional para envolver el valor (default: React.Fragment)
|
|
7
|
+
* @param props.defaultValue - Valor a mostrar si es null/undefined (default: '-')
|
|
8
|
+
* @returns Objeto con { formatter, customFilter, customSort } para usar en la columna
|
|
9
|
+
* @example
|
|
10
|
+
* // Datos de ejemplo en el DataGrid:
|
|
11
|
+
* // [
|
|
12
|
+
* // { id: 1, nestedValue: { value: 'Activo' } },
|
|
13
|
+
* // { id: 2, nestedValue: { value: null } },
|
|
14
|
+
* // { id: 3, nestedValue: { value: 'Pendiente' } },
|
|
15
|
+
* // ]
|
|
16
|
+
*
|
|
17
|
+
* // Crear la columna con el hook
|
|
18
|
+
* const nestedColumn = useColumnNestedValue<RowType>({
|
|
19
|
+
* fieldValue: 'nestedValue.value',
|
|
20
|
+
* defaultValue: 'N/A', // Opcional, por defecto es '-'
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Usar en la definición de columnas
|
|
24
|
+
* const columns = [
|
|
25
|
+
* {
|
|
26
|
+
* key: 'nestedValue',
|
|
27
|
+
* name: 'Estado',
|
|
28
|
+
* type: 'custom',
|
|
29
|
+
* ...nestedColumn, // Spread incluye formatter, customFilter y customSort
|
|
30
|
+
* }
|
|
31
|
+
* ];
|
|
32
|
+
*
|
|
33
|
+
* // Resultado en el DataGrid:
|
|
34
|
+
* // Fila 1: "Activo"
|
|
35
|
+
* // Fila 2: "N/A" (porque el valor es null)
|
|
36
|
+
* // Fila 3: "Pendiente"
|
|
5
37
|
*/
|
|
6
38
|
export declare const useColumnNestedValue: <TRow>(props: ColumnNestedValueFormatterProps<TRow>) => {
|
|
7
39
|
formatter: (formatterProps: import('react-data-grid').RenderCellProps<TRow, unknown>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -6,8 +6,12 @@ import { g as getNullGuard } from "../../../../utils/getNullGuard.js";
|
|
|
6
6
|
import { C as ColumnNestedValueFormatter } from "./formatter.js";
|
|
7
7
|
import { g as getColumnKey } from "../../helpers/shared/getColumnKey/getColumnKey.js";
|
|
8
8
|
const getCustomNestedValueFilter = (props) => {
|
|
9
|
+
const { defaultValue = "-" } = props;
|
|
9
10
|
return (row, value) => {
|
|
10
|
-
const property = getNullGuard(
|
|
11
|
+
const property = getNullGuard(
|
|
12
|
+
getPropertyByString(row, props.fieldValue),
|
|
13
|
+
defaultValue
|
|
14
|
+
);
|
|
11
15
|
if (typeof property === "object") {
|
|
12
16
|
return Object.values(property).includes(value);
|
|
13
17
|
}
|
|
@@ -15,10 +19,17 @@ const getCustomNestedValueFilter = (props) => {
|
|
|
15
19
|
};
|
|
16
20
|
};
|
|
17
21
|
const getCustomNestedValueSort = (props) => {
|
|
22
|
+
const { defaultValue = "-" } = props;
|
|
18
23
|
return (a, b) => {
|
|
19
24
|
const keyWiouthRow = getColumnKey(props.fieldValue);
|
|
20
|
-
const valueA = getNullGuard(
|
|
21
|
-
|
|
25
|
+
const valueA = getNullGuard(
|
|
26
|
+
getPropertyByString(a, keyWiouthRow),
|
|
27
|
+
defaultValue
|
|
28
|
+
);
|
|
29
|
+
const valueB = getNullGuard(
|
|
30
|
+
getPropertyByString(b, keyWiouthRow),
|
|
31
|
+
defaultValue
|
|
32
|
+
);
|
|
22
33
|
if (typeof valueA === "object" || typeof valueB === "object" || valueA === void 0 || valueB === void 0) {
|
|
23
34
|
return 0;
|
|
24
35
|
}
|
|
@@ -40,12 +51,15 @@ const useColumnNestedValue = (props) => {
|
|
|
40
51
|
setStateProps(props);
|
|
41
52
|
}
|
|
42
53
|
}, [props]);
|
|
43
|
-
return useMemo(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
return useMemo(
|
|
55
|
+
() => ({
|
|
56
|
+
formatter: ColumnNestedValueFormatter(stateProps),
|
|
57
|
+
renderGroupCell: ColumnNestedValueGroupFormatter(stateProps),
|
|
58
|
+
customFilter: getCustomNestedValueFilter(stateProps),
|
|
59
|
+
customSort: getCustomNestedValueSort(stateProps)
|
|
60
|
+
}),
|
|
61
|
+
[stateProps]
|
|
62
|
+
);
|
|
49
63
|
};
|
|
50
64
|
export {
|
|
51
65
|
useColumnNestedValue as u
|
|
@@ -12,6 +12,16 @@ export interface SeedProps {
|
|
|
12
12
|
withMultipleIcons?: boolean;
|
|
13
13
|
withInteractiveCheck?: boolean;
|
|
14
14
|
withNestedValue?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Si es true, genera valores anidados con algunos null/undefined
|
|
17
|
+
* para mostrar el comportamiento del defaultValue ('-')
|
|
18
|
+
*/
|
|
19
|
+
withNestedValueWithNulls?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Si es true, genera valores anidados con null/undefined
|
|
22
|
+
* y usa un defaultValue personalizado ('N/A')
|
|
23
|
+
*/
|
|
24
|
+
withNestedValueCustomDefaultValue?: boolean;
|
|
15
25
|
withPoints?: boolean;
|
|
16
26
|
withPrice?: boolean;
|
|
17
27
|
withUncertainty?: boolean;
|