@m4l/components 9.3.25 → 9.3.26
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/CommonActions/components/ActionFormCancel/ActionFormCancel.js +17 -8
- package/components/CommonActions/components/ActionFormCancel/types.d.ts +9 -0
- package/components/DataGrid/formatters/ColumnIconFormatter/index.d.ts +1 -0
- package/components/DataGrid/index.d.ts +1 -1
- package/components/DataGrid/types.d.ts +2 -0
- package/components/Label/Label.js +1 -1
- package/components/PaperForm/PaperForm.js +1 -1
- package/components/PaperForm/components/Header.js +9 -7
- package/components/PaperForm/styles.js +9 -4
- package/components/PaperForm/types.d.ts +3 -2
- package/components/Stepper/Stepper.styles.js +2 -0
- package/components/Stepper/dictionary.js +0 -1
- package/components/Stepper/subcomponents/StepArea/hooks/useStepArea.d.ts +13 -0
- package/components/Stepper/subcomponents/StepArea/hooks/useStepArea.js +111 -0
- package/components/Stepper/subcomponents/StepArea/hooks/useVisibileSteps.d.ts +8 -0
- package/components/Stepper/subcomponents/StepArea/hooks/useVisibileSteps.js +79 -0
- package/components/Stepper/subcomponents/StepArea/index.js +7 -115
- package/components/Stepper/subcomponents/StepperButtons/StepperCancelButton/index.d.ts +2 -2
- package/components/Stepper/subcomponents/StepperButtons/StepperCancelButton/index.js +3 -53
- package/components/Stepper/subcomponents/StepperButtons/StepperNextButton/index.js +3 -2
- package/components/Stepper/subcomponents/StepperButtons/StepperPrevButton/index.js +3 -2
- package/components/Stepper/subcomponents/StepperButtons/StepperSubmitButton/index.js +24 -5
- package/components/Stepper/subcomponents/StepperContent/subcomponents/Step/hooks/useIsStepVisible.d.ts +8 -0
- package/components/Stepper/subcomponents/StepperContent/subcomponents/Step/hooks/useIsStepVisible.js +93 -0
- package/components/Stepper/subcomponents/StepperContent/subcomponents/Step/index.js +2 -51
- package/components/Stepper/types.d.ts +4 -0
- package/components/ToastContainer/ToastContainer.js +1 -0
- package/components/ToastContainer/constants.d.ts +1 -1
- package/components/ToastContainer/constants.js +1 -1
- package/components/WindowBase/contexts/WindowToolsMFContext/WindowToolsMFContext.js +47 -3
- package/components/WindowBase/contexts/WindowToolsMFContext/types.d.ts +1 -1
- package/components/WindowBase/subcomponents/Component/index.d.ts +12 -1
- package/components/WindowBase/subcomponents/Component/index.js +56 -2
- package/components/WindowBase/subcomponents/Component/types.d.ts +1 -0
- package/components/WindowBase/types.d.ts +1 -1
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/Window.js +1 -0
- package/components/areas/components/AreasViewer/subcomponents/Area/subcomponents/Window/hooks/useWindow.js +1 -1
- package/components/areas/contexts/AreasContext/store.js +7 -3
- package/components/areas/contexts/AreasContext/types.d.ts +1 -1
- package/components/hook-form/RHFormContext/index.d.ts +1 -1
- package/components/hook-form/RHFormContext/styles.js +2 -1
- package/components/mui_extended/CircularProgress/types.d.ts +1 -1
- package/components/popups/components/PopupsProvider/contexts/PopupsContext/store.js +5 -1
- package/components/popups/components/PopupsProvider/contexts/PopupsContext/types.d.ts +1 -1
- package/components/popups/components/PopupsProvider/hooks/usePopups.d.ts +2 -4
- package/components/popups/components/PopupsProvider/hooks/usePopups.js +19 -7
- package/components/popups/components/PopupsViewer/PopupsViewer.js +1 -1
- package/components/popups/components/PopupsViewer/PopupsViewer.styles.js +1 -1
- package/components/popups/components/PopupsViewer/subcomponents/Popup/Popup.js +32 -21
- package/index.js +62 -60
- package/package.json +1 -1
|
@@ -10,17 +10,23 @@ import { D as DICTIONARY } from "../../dictionary.js";
|
|
|
10
10
|
import { W as WindowConfirm } from "../../../WindowConfirm/WindowConfirm.js";
|
|
11
11
|
import { B as ButtonRootStyled } from "./slots/ActionFormCancelSlots.js";
|
|
12
12
|
function ActionFormCancel(props) {
|
|
13
|
-
const {
|
|
13
|
+
const {
|
|
14
|
+
className,
|
|
15
|
+
onClose,
|
|
16
|
+
linkToCloseWindow,
|
|
17
|
+
"data-testid": dataTestId
|
|
18
|
+
} = props;
|
|
14
19
|
const { getLabel } = useModuleDictionary();
|
|
15
20
|
const { openModal } = useModal();
|
|
16
|
-
const { close
|
|
21
|
+
const { close, setFnQueryClose } = useWindowToolsMF();
|
|
17
22
|
const { control } = useFormContext();
|
|
18
23
|
const { isDirty } = useFormState({
|
|
19
24
|
control
|
|
20
25
|
});
|
|
21
26
|
const onConfirmQuit = useCallback(() => {
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
close(false);
|
|
28
|
+
onClose?.();
|
|
29
|
+
}, [close, onClose]);
|
|
24
30
|
const onClickCancel = useCallback(() => {
|
|
25
31
|
if (isDirty) {
|
|
26
32
|
openModal({
|
|
@@ -38,10 +44,12 @@ function ActionFormCancel(props) {
|
|
|
38
44
|
} else {
|
|
39
45
|
onConfirmQuit();
|
|
40
46
|
}
|
|
41
|
-
}, [
|
|
47
|
+
}, [isDirty, openModal, getLabel, onConfirmQuit]);
|
|
42
48
|
useEffect(() => {
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
if (linkToCloseWindow) {
|
|
50
|
+
setFnQueryClose(onClickCancel);
|
|
51
|
+
}
|
|
52
|
+
}, [onClickCancel, setFnQueryClose, linkToCloseWindow]);
|
|
45
53
|
return /* @__PURE__ */ jsx(
|
|
46
54
|
ButtonRootStyled,
|
|
47
55
|
{
|
|
@@ -49,7 +57,8 @@ function ActionFormCancel(props) {
|
|
|
49
57
|
variant: "outlined",
|
|
50
58
|
onClick: onClickCancel,
|
|
51
59
|
className: clsx(classActoinFormCancelRoot, className),
|
|
52
|
-
label: getLabel(DICTIONARY.LABEL_CANCEL)
|
|
60
|
+
label: getLabel(DICTIONARY.LABEL_CANCEL),
|
|
61
|
+
"data-testid": dataTestId
|
|
53
62
|
}
|
|
54
63
|
);
|
|
55
64
|
}
|
|
@@ -10,6 +10,15 @@ export interface ActionFormCancelProps extends ButtonProps {
|
|
|
10
10
|
size?: Extract<Sizes, 'small' | 'medium'>;
|
|
11
11
|
dictionaryId?: string;
|
|
12
12
|
className?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Cuando efectivamente se cierrar la ventana se ejecuta esta función.
|
|
15
|
+
*/
|
|
16
|
+
onClose?: () => void;
|
|
17
|
+
/**
|
|
18
|
+
* Vicular la funcion de cierre de consulta con la funcion de cierre de la ventana.
|
|
19
|
+
*/
|
|
20
|
+
linkToCloseWindow: boolean;
|
|
21
|
+
'data-testid'?: string;
|
|
13
22
|
}
|
|
14
23
|
export interface ActionFormCancelOwnerState {
|
|
15
24
|
size?: Extract<Sizes, 'small' | 'medium'>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { DataGrid } from './DataGrid';
|
|
2
2
|
export * from './formatters';
|
|
3
3
|
export type { Column, RenderEditCellProps, RenderCellProps } from 'react-data-grid';
|
|
4
|
-
export type { RowKey, ChangeUserColumn } from './types';
|
|
4
|
+
export type { RowKey, ChangeUserColumn, RowActionsGetter, RowKeyGetter } from './types';
|
|
5
5
|
export { getDataGridComponentsDictionary } from './dictionary';
|
|
6
6
|
export { TextEditor, NumberEditor } from './subcomponents/editors/TextEditor';
|
|
7
7
|
export { getDataGridRowsFromSet } from './utils/getDataGridRowsFromSet';
|
|
@@ -112,6 +112,8 @@ export interface FilterSettings {
|
|
|
112
112
|
filtersApplied: FilterApplied[];
|
|
113
113
|
onChange: (event: FilterChangeEvent) => void;
|
|
114
114
|
}
|
|
115
|
+
export type RowActionsGetter<TRow> = (row: TRow) => MenuAction[];
|
|
116
|
+
export type RowKeyGetter<TRow, TKey extends RowKey = RowKey> = (row: TRow) => TKey;
|
|
115
117
|
/**--------------------Termina tipado de filtros-------------------------------------------- */
|
|
116
118
|
export interface GridProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> extends Omit<NativeDataGridProps<TRow, TSummaryRow>, 'rowKeyGetter' | 'rows' | 'columns' | 'onRowsChange' | 'selectedRows' | 'onSelectedRowsChange' | 'renderers'> {
|
|
117
119
|
id: string;
|
|
@@ -9,7 +9,7 @@ const Label = (props) => {
|
|
|
9
9
|
const { host_static_assets, environment_assets } = useEnvironment();
|
|
10
10
|
const isSkeleton = useModuleSkeleton();
|
|
11
11
|
const { currentSize } = useComponentSize(size);
|
|
12
|
-
const hasHelperIcon = typeof helperMessage === "string" ? true : false;
|
|
12
|
+
const hasHelperIcon = typeof helperMessage === "string" && helperMessage.length > 0 ? true : false;
|
|
13
13
|
const adjustedSize = currentSize === "small" || currentSize === "medium" ? currentSize : "medium";
|
|
14
14
|
const ownerState = {
|
|
15
15
|
disabled,
|
|
@@ -45,7 +45,7 @@ function PaperForm(props) {
|
|
|
45
45
|
ownerState: { ...ownerState },
|
|
46
46
|
...process.env.NODE_ENV !== "production" ? { "data-testid": dataTestId } : {},
|
|
47
47
|
children: [
|
|
48
|
-
variant !== "
|
|
48
|
+
variant !== "onlyContainer" && /* @__PURE__ */ jsx(Header, { urlIcon, title, color, size, variant }),
|
|
49
49
|
/* @__PURE__ */ jsx(ContentStyled, { ownerState: { ...ownerState }, children: renderChildren(children) })
|
|
50
50
|
]
|
|
51
51
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { I as IconStyled, T as TitleStyled, H as HeaderStyled } from "../slots/PaperFormSlots.js";
|
|
3
|
+
import { useMemo } from "react";
|
|
3
4
|
const Header = (props) => {
|
|
4
|
-
const { urlIcon, title, size, dataTestId, color } = props;
|
|
5
|
+
const { urlIcon, title, size, dataTestId, color, variant } = props;
|
|
5
6
|
const ownerState = {
|
|
6
|
-
color
|
|
7
|
+
color,
|
|
8
|
+
variant
|
|
7
9
|
};
|
|
8
|
-
const
|
|
10
|
+
const contentHeader = useMemo(() => {
|
|
9
11
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
10
12
|
urlIcon ? /* @__PURE__ */ jsx(IconStyled, { src: urlIcon, size }) : null,
|
|
11
13
|
/* @__PURE__ */ jsx(TitleStyled, { variant: "bodyDens", size, children: title })
|
|
12
14
|
] });
|
|
13
|
-
};
|
|
14
|
-
return /* @__PURE__ */ jsx(HeaderStyled, { role: "heading", ownerState, ...process.env.NODE_ENV !== "production" ? { "data-testid": dataTestId } : {}, children:
|
|
15
|
+
}, [urlIcon, title, size]);
|
|
16
|
+
return /* @__PURE__ */ jsx(HeaderStyled, { role: "heading", ownerState, ...process.env.NODE_ENV !== "production" ? { "data-testid": dataTestId } : {}, children: contentHeader });
|
|
15
17
|
};
|
|
16
18
|
export {
|
|
17
19
|
Header as H
|
|
@@ -8,11 +8,14 @@ const paperFormStyles = {
|
|
|
8
8
|
*/
|
|
9
9
|
paperFormRoot: ({ theme, ownerState }) => ({
|
|
10
10
|
background: theme.vars.palette.background.default,
|
|
11
|
-
...ownerState?.paperFormVariant
|
|
11
|
+
...ownerState?.paperFormVariant === "standard" && {
|
|
12
12
|
borderRadius: theme.size.borderRadius.r1,
|
|
13
13
|
border: `${theme.size.borderStroke.container}`,
|
|
14
14
|
borderColor: theme.vars.palette.border.default
|
|
15
15
|
},
|
|
16
|
+
// ...(ownerState?.paperFormVariant === 'text' && {
|
|
17
|
+
// borderRadius: theme.size.borderRadius.r1,
|
|
18
|
+
// }),
|
|
16
19
|
width: "100%",
|
|
17
20
|
overflow: "auto",
|
|
18
21
|
...ownerState?.height === "full" && {
|
|
@@ -41,8 +44,10 @@ const paperFormStyles = {
|
|
|
41
44
|
gap: theme.vars.size.baseSpacings.sp1,
|
|
42
45
|
overflow: "hidden",
|
|
43
46
|
padding: `${theme.vars.size.baseSpacings.sp1} ${theme.vars.size.baseSpacings.sp2}`,
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
...ownerState?.paperFormVariant === "standard" && {
|
|
48
|
+
borderRadius: `${theme.vars.size.borderRadius.r1} ${theme.vars.size.borderRadius.r1} 0 0`,
|
|
49
|
+
background: theme.vars.palette[ownerState?.color ?? "default"].hoverOpacity
|
|
50
|
+
},
|
|
46
51
|
alignSelf: "stretch",
|
|
47
52
|
...getSizeStyles(
|
|
48
53
|
theme,
|
|
@@ -90,7 +95,7 @@ const paperFormStyles = {
|
|
|
90
95
|
justifyContent: ownerState?.isForm ? "flex-start" : "center",
|
|
91
96
|
gap: ownerState?.isForm ? theme.vars.size.baseSpacings.sp3 : theme.vars.size.baseSpacings.sp0,
|
|
92
97
|
flexWrap: ownerState?.isForm ? "wrap" : "nowrap",
|
|
93
|
-
padding: ownerState?.paperFormVariant === "
|
|
98
|
+
padding: ownerState?.paperFormVariant === "onlyContainer" ? "0px" : theme.vars.size.baseSpacings.sp3,
|
|
94
99
|
background: theme.vars.palette.background.default,
|
|
95
100
|
flex: 1,
|
|
96
101
|
overflow: "auto"
|
|
@@ -9,11 +9,12 @@ export interface PaperFormProps {
|
|
|
9
9
|
urlIcon?: string;
|
|
10
10
|
title: string;
|
|
11
11
|
children?: ReactNode | PropertyValueProps[];
|
|
12
|
-
variant?: 'standard' | 'text';
|
|
12
|
+
variant?: 'standard' | 'text' | 'onlyContainer';
|
|
13
13
|
color?: Extract<ComponentPalletColor, 'default'>;
|
|
14
14
|
size?: Extract<Sizes, 'small' | 'medium'>;
|
|
15
15
|
isForm?: boolean;
|
|
16
16
|
dataTestId?: string;
|
|
17
|
+
border?: boolean;
|
|
17
18
|
height?: 'auto' | 'full';
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
@@ -25,7 +26,7 @@ export interface PaperFormProps {
|
|
|
25
26
|
interface CommonsProps {
|
|
26
27
|
paperFormVariant?: PaperFormProps['variant'];
|
|
27
28
|
}
|
|
28
|
-
export type HeaderProps = Omit<PaperFormProps, 'children' | 'isForm'
|
|
29
|
+
export type HeaderProps = Omit<PaperFormProps, 'children' | 'isForm'> & CommonsProps;
|
|
29
30
|
export type PaperFormOwnerState = Pick<PaperFormProps, 'isForm' | 'color' | 'size' | 'height'> & CommonsProps;
|
|
30
31
|
/**
|
|
31
32
|
* ***********************************
|
|
@@ -56,6 +56,7 @@ const stepperStyles = {
|
|
|
56
56
|
display: "flex",
|
|
57
57
|
flexDirection: "column",
|
|
58
58
|
gap: theme.vars.size.baseSpacings.sp6,
|
|
59
|
+
overflowY: "auto",
|
|
59
60
|
...ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? {
|
|
60
61
|
borderTop: "1px solid",
|
|
61
62
|
paddingTop: theme.vars.size.baseSpacings.sp8
|
|
@@ -152,6 +153,7 @@ const stepperStyles = {
|
|
|
152
153
|
alignItems: "center",
|
|
153
154
|
justifyContent: "center",
|
|
154
155
|
flexShrink: 0,
|
|
156
|
+
zIndex: 1,
|
|
155
157
|
order: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? 0 : 1,
|
|
156
158
|
background: !isValidStep && ownerState?.hasBeenValidated ? theme.vars.palette.error.enabled : isCompleted && isValidStep ? ownerState?.indicatorType === "dot" || theme.generalSettings.isMobile ? theme.vars.palette.background.default : theme.vars.palette.primary.toneOpacity : isCurrent ? ownerState?.indicatorType === "dot" || theme.generalSettings.isMobile ? theme.vars.palette.background.default : theme.vars.palette.primary.enabled : ownerState?.indicatorType === "dot" || theme.generalSettings.isMobile ? theme.vars.palette.background.default : theme.vars.palette.default.enabled,
|
|
157
159
|
borderRadius: theme.vars.size.borderRadius.r2,
|
|
@@ -5,7 +5,6 @@ function getStepperComponentsDictionary() {
|
|
|
5
5
|
const DICTIONARY = {
|
|
6
6
|
LABEL_PREV_BUTTON: `${STEPPER_DICTIONARY_ID}.label_prev_button`,
|
|
7
7
|
LABEL_NEXT_BUTTON: `${STEPPER_DICTIONARY_ID}.label_next_button`,
|
|
8
|
-
LABEL_CANCEL_BUTTON: `${STEPPER_DICTIONARY_ID}.label_cancel_button`,
|
|
9
8
|
LABEL_SUBMIT_BUTTON: `${STEPPER_DICTIONARY_ID}.label_submit_button`
|
|
10
9
|
};
|
|
11
10
|
export {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Step } from '../../../types';
|
|
2
|
+
/**
|
|
3
|
+
* useStepArea hook is responsible for managing the step area of the stepper
|
|
4
|
+
*/
|
|
5
|
+
export declare function useStepArea(props: {
|
|
6
|
+
visibleSteps: Step[];
|
|
7
|
+
}): {
|
|
8
|
+
visibleTitle: boolean | undefined;
|
|
9
|
+
orientation: import('../../../types').Orientation | undefined;
|
|
10
|
+
handleStepClick: (targetIndex: number) => Promise<void>;
|
|
11
|
+
steps: Step[];
|
|
12
|
+
currentStep: number;
|
|
13
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
|
2
|
+
import { useFormContext } from "react-hook-form";
|
|
3
|
+
import { u as useStepper } from "../../../hooks/useStepper/index.js";
|
|
4
|
+
import { u as useDynamicValidation } from "../../../hooks/useDynamicValidation/index.js";
|
|
5
|
+
import { d as deepShallow } from "../../../../../utils/deepShallow.js";
|
|
6
|
+
function useStepArea(props) {
|
|
7
|
+
const { visibleSteps } = props;
|
|
8
|
+
const { trigger, clearErrors } = useFormContext();
|
|
9
|
+
const {
|
|
10
|
+
activateFieldsValidation,
|
|
11
|
+
startExternalValidation,
|
|
12
|
+
endExternalValidation
|
|
13
|
+
} = useDynamicValidation();
|
|
14
|
+
const {
|
|
15
|
+
currentStep,
|
|
16
|
+
steps,
|
|
17
|
+
visibleTitle,
|
|
18
|
+
setCurrentStep,
|
|
19
|
+
orientation,
|
|
20
|
+
setStepValidationStatus,
|
|
21
|
+
stepValidationStatus
|
|
22
|
+
} = useStepper(
|
|
23
|
+
(state) => ({
|
|
24
|
+
currentStep: state.currentStep,
|
|
25
|
+
steps: state.steps,
|
|
26
|
+
visibleTitle: state.visibleTitle,
|
|
27
|
+
setCurrentStep: state.actions.setCurrentStep,
|
|
28
|
+
indicatorType: state.indicatorType,
|
|
29
|
+
orientation: state.orientation,
|
|
30
|
+
setStepValidationStatus: state.actions.setStepValidationStatus,
|
|
31
|
+
stepValidationStatus: state.stepValidationStatus
|
|
32
|
+
}),
|
|
33
|
+
deepShallow
|
|
34
|
+
);
|
|
35
|
+
const handleStepClick = useCallback(async (targetIndex) => {
|
|
36
|
+
const currentIndex = visibleSteps.findIndex(
|
|
37
|
+
(step) => step.key === steps[currentStep].key
|
|
38
|
+
);
|
|
39
|
+
if (targetIndex === currentIndex) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const isNavigatingForward = targetIndex > currentIndex;
|
|
43
|
+
const targetOriginalIndex = steps.findIndex(
|
|
44
|
+
(s) => s.key === visibleSteps[targetIndex].key
|
|
45
|
+
);
|
|
46
|
+
if (!isNavigatingForward) {
|
|
47
|
+
setCurrentStep(targetOriginalIndex);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const isSkippingSteps = targetIndex > currentIndex + 1;
|
|
51
|
+
if (isSkippingSteps) {
|
|
52
|
+
for (let i = currentIndex; i < targetIndex; i++) {
|
|
53
|
+
const step = visibleSteps[i];
|
|
54
|
+
const stepOriginalIndex = steps.findIndex((s) => s.key === step.key);
|
|
55
|
+
startExternalValidation();
|
|
56
|
+
const isValid = await trigger(step.validationFields);
|
|
57
|
+
endExternalValidation();
|
|
58
|
+
if (!isValid) {
|
|
59
|
+
setCurrentStep(stepOriginalIndex);
|
|
60
|
+
setStepValidationStatus(stepOriginalIndex, false);
|
|
61
|
+
activateFieldsValidation(step.validationFields || []);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
setStepValidationStatus(stepOriginalIndex, true);
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
const currentStepData = visibleSteps[currentIndex];
|
|
68
|
+
const currentStepOriginalIndex = steps.findIndex(
|
|
69
|
+
(s) => s.key === currentStepData.key
|
|
70
|
+
);
|
|
71
|
+
startExternalValidation();
|
|
72
|
+
const isCurrentValid = await trigger(currentStepData.validationFields);
|
|
73
|
+
endExternalValidation();
|
|
74
|
+
if (!isCurrentValid) {
|
|
75
|
+
setStepValidationStatus(currentStepOriginalIndex, false);
|
|
76
|
+
activateFieldsValidation(currentStepData.validationFields || []);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
setStepValidationStatus(currentStepOriginalIndex, true);
|
|
80
|
+
}
|
|
81
|
+
setCurrentStep(targetOriginalIndex);
|
|
82
|
+
if (isNavigatingForward) {
|
|
83
|
+
const currentStepData = visibleSteps[currentIndex];
|
|
84
|
+
const currentStepOriginalIndex = steps.findIndex(
|
|
85
|
+
(s) => s.key === currentStepData.key
|
|
86
|
+
);
|
|
87
|
+
const isCurrentStepValid = stepValidationStatus[currentStepOriginalIndex] !== false;
|
|
88
|
+
if (isCurrentStepValid) {
|
|
89
|
+
const targetStep = visibleSteps[targetIndex];
|
|
90
|
+
const targetStepFields = targetStep.validationFields || [];
|
|
91
|
+
if (targetStepFields.length > 0) {
|
|
92
|
+
clearErrors(targetStepFields);
|
|
93
|
+
setTimeout(() => {
|
|
94
|
+
clearErrors(targetStepFields);
|
|
95
|
+
setStepValidationStatus(targetOriginalIndex, true);
|
|
96
|
+
}, 100);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}, [visibleSteps, steps, setCurrentStep, currentStep, startExternalValidation, trigger, endExternalValidation, setStepValidationStatus, activateFieldsValidation, stepValidationStatus, clearErrors]);
|
|
101
|
+
return useMemo(() => ({
|
|
102
|
+
visibleTitle,
|
|
103
|
+
orientation,
|
|
104
|
+
handleStepClick,
|
|
105
|
+
steps,
|
|
106
|
+
currentStep
|
|
107
|
+
}), [visibleTitle, orientation, handleStepClick, steps, currentStep]);
|
|
108
|
+
}
|
|
109
|
+
export {
|
|
110
|
+
useStepArea as u
|
|
111
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Step as StepType } from '../../../types';
|
|
2
|
+
/**
|
|
3
|
+
* useVisibileSteps hook is responsible for calculating the visible steps based on the form values and the visibility data
|
|
4
|
+
* Optimizado con useSyncExternalStore para evitar re-renders innecesarios
|
|
5
|
+
*/
|
|
6
|
+
export declare function useVisibileSteps(): {
|
|
7
|
+
visibleSteps: StepType[];
|
|
8
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useRef, useCallback, useSyncExternalStore, useMemo } from "react";
|
|
2
|
+
import { useFormContext } from "react-hook-form";
|
|
3
|
+
import { u as useStepper } from "../../../hooks/useStepper/index.js";
|
|
4
|
+
import { e as evaluateVisibilityStepCondition } from "../../../helpers/evaluateVisibilityStepCondition/index.js";
|
|
5
|
+
import { d as deepShallow } from "../../../../../utils/deepShallow.js";
|
|
6
|
+
function calculateVisibleSteps(steps, formValues, visibilityData) {
|
|
7
|
+
return steps.filter(
|
|
8
|
+
(step) => evaluateVisibilityStepCondition(step, formValues || {}, visibilityData || {})
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
function generateStepsKey(steps) {
|
|
12
|
+
return steps.map((step) => step.key).join(",");
|
|
13
|
+
}
|
|
14
|
+
function useVisibileSteps() {
|
|
15
|
+
const formContext = useFormContext();
|
|
16
|
+
const {
|
|
17
|
+
steps,
|
|
18
|
+
visibilityData
|
|
19
|
+
} = useStepper(
|
|
20
|
+
(state) => ({
|
|
21
|
+
steps: state.steps,
|
|
22
|
+
visibilityData: state.visibilityData
|
|
23
|
+
}),
|
|
24
|
+
deepShallow
|
|
25
|
+
);
|
|
26
|
+
const previousStepsKeyRef = useRef(null);
|
|
27
|
+
const cachedVisibleStepsRef = useRef([]);
|
|
28
|
+
const listenersRef = useRef(/* @__PURE__ */ new Set());
|
|
29
|
+
const subscribe = useCallback((callback) => {
|
|
30
|
+
listenersRef.current.add(callback);
|
|
31
|
+
const { unsubscribe } = formContext.watch((formValues) => {
|
|
32
|
+
const newVisibleSteps = calculateVisibleSteps(
|
|
33
|
+
steps,
|
|
34
|
+
formValues,
|
|
35
|
+
visibilityData
|
|
36
|
+
);
|
|
37
|
+
const newStepsKey = generateStepsKey(newVisibleSteps);
|
|
38
|
+
if (newStepsKey !== previousStepsKeyRef.current) {
|
|
39
|
+
previousStepsKeyRef.current = newStepsKey;
|
|
40
|
+
cachedVisibleStepsRef.current = newVisibleSteps;
|
|
41
|
+
listenersRef.current.forEach((listener) => listener());
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return () => {
|
|
45
|
+
listenersRef.current.delete(callback);
|
|
46
|
+
unsubscribe();
|
|
47
|
+
};
|
|
48
|
+
}, [formContext, steps, visibilityData]);
|
|
49
|
+
const getSnapshot = useCallback(() => {
|
|
50
|
+
const formValues = formContext.getValues();
|
|
51
|
+
const currentVisibleSteps = calculateVisibleSteps(
|
|
52
|
+
steps,
|
|
53
|
+
formValues,
|
|
54
|
+
visibilityData
|
|
55
|
+
);
|
|
56
|
+
const stepsKey = generateStepsKey(currentVisibleSteps);
|
|
57
|
+
if (previousStepsKeyRef.current === null) {
|
|
58
|
+
previousStepsKeyRef.current = stepsKey;
|
|
59
|
+
cachedVisibleStepsRef.current = currentVisibleSteps;
|
|
60
|
+
}
|
|
61
|
+
if (stepsKey === previousStepsKeyRef.current) {
|
|
62
|
+
return cachedVisibleStepsRef.current;
|
|
63
|
+
}
|
|
64
|
+
previousStepsKeyRef.current = stepsKey;
|
|
65
|
+
cachedVisibleStepsRef.current = currentVisibleSteps;
|
|
66
|
+
return currentVisibleSteps;
|
|
67
|
+
}, [formContext, steps, visibilityData]);
|
|
68
|
+
const visibleSteps = useSyncExternalStore(
|
|
69
|
+
subscribe,
|
|
70
|
+
getSnapshot,
|
|
71
|
+
getSnapshot
|
|
72
|
+
);
|
|
73
|
+
return useMemo(() => ({
|
|
74
|
+
visibleSteps
|
|
75
|
+
}), [visibleSteps]);
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
useVisibileSteps as u
|
|
79
|
+
};
|
|
@@ -1,127 +1,19 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
import { useFormContext, useWatch } from "react-hook-form";
|
|
4
|
-
import { u as useStepper } from "../../hooks/useStepper/index.js";
|
|
5
2
|
import { e as StepAreaStyled, f as StepStyled, g as StepNameStyled } from "../../slots/StepperSlot.js";
|
|
6
3
|
import { I as Indicator } from "./subcomponents/Inidicator/index.js";
|
|
7
|
-
import {
|
|
8
|
-
import { u as
|
|
9
|
-
import { e as evaluateVisibilityStepCondition } from "../../helpers/evaluateVisibilityStepCondition/index.js";
|
|
4
|
+
import { u as useStepArea } from "./hooks/useStepArea.js";
|
|
5
|
+
import { u as useVisibileSteps } from "./hooks/useVisibileSteps.js";
|
|
10
6
|
function StepArea() {
|
|
11
|
-
const {
|
|
12
|
-
const
|
|
13
|
-
const {
|
|
14
|
-
activateFieldsValidation,
|
|
15
|
-
startExternalValidation,
|
|
16
|
-
endExternalValidation
|
|
17
|
-
} = useDynamicValidation();
|
|
18
|
-
const {
|
|
19
|
-
currentStep,
|
|
20
|
-
steps,
|
|
21
|
-
visibleTitle,
|
|
22
|
-
setCurrentStep,
|
|
23
|
-
orientation,
|
|
24
|
-
setStepValidationStatus,
|
|
25
|
-
stepValidationStatus,
|
|
26
|
-
visibilityData
|
|
27
|
-
} = useStepper(
|
|
28
|
-
(state) => ({
|
|
29
|
-
currentStep: state.currentStep,
|
|
30
|
-
steps: state.steps,
|
|
31
|
-
visibleTitle: state.visibleTitle,
|
|
32
|
-
setCurrentStep: state.actions.setCurrentStep,
|
|
33
|
-
indicatorType: state.indicatorType,
|
|
34
|
-
orientation: state.orientation,
|
|
35
|
-
setStepValidationStatus: state.actions.setStepValidationStatus,
|
|
36
|
-
stepValidationStatus: state.stepValidationStatus,
|
|
37
|
-
visibilityData: state.visibilityData
|
|
38
|
-
}),
|
|
39
|
-
shallow
|
|
40
|
-
);
|
|
41
|
-
const allSteps = steps;
|
|
42
|
-
const visibleSteps = useMemo(() => {
|
|
43
|
-
return steps.filter(
|
|
44
|
-
(step) => evaluateVisibilityStepCondition(step, formValues || {}, visibilityData)
|
|
45
|
-
);
|
|
46
|
-
}, [steps, formValues, visibilityData]);
|
|
7
|
+
const { visibleSteps } = useVisibileSteps();
|
|
8
|
+
const { handleStepClick, visibleTitle, orientation, steps, currentStep } = useStepArea({ visibleSteps });
|
|
47
9
|
const ownerState = {
|
|
48
10
|
visibleTitle,
|
|
49
11
|
orientation,
|
|
50
12
|
totalSteps: visibleSteps.length
|
|
51
13
|
};
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
);
|
|
56
|
-
if (targetIndex === currentIndex) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const isNavigatingForward = targetIndex > currentIndex;
|
|
60
|
-
const targetOriginalIndex = steps.findIndex(
|
|
61
|
-
(s) => s.key === visibleSteps[targetIndex].key
|
|
62
|
-
);
|
|
63
|
-
if (!isNavigatingForward) {
|
|
64
|
-
setCurrentStep(targetOriginalIndex);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const isSkippingSteps = targetIndex > currentIndex + 1;
|
|
68
|
-
if (isSkippingSteps) {
|
|
69
|
-
for (let i = currentIndex; i < targetIndex; i++) {
|
|
70
|
-
const step = visibleSteps[i];
|
|
71
|
-
const stepOriginalIndex = steps.findIndex((s) => s.key === step.key);
|
|
72
|
-
startExternalValidation();
|
|
73
|
-
const isValid = await trigger(step.validationFields);
|
|
74
|
-
endExternalValidation();
|
|
75
|
-
if (!isValid) {
|
|
76
|
-
setCurrentStep(stepOriginalIndex);
|
|
77
|
-
setStepValidationStatus(stepOriginalIndex, false);
|
|
78
|
-
activateFieldsValidation(step.validationFields || []);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
setStepValidationStatus(stepOriginalIndex, true);
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
const currentStepData = visibleSteps[currentIndex];
|
|
85
|
-
const currentStepOriginalIndex = steps.findIndex(
|
|
86
|
-
(s) => s.key === currentStepData.key
|
|
87
|
-
);
|
|
88
|
-
startExternalValidation();
|
|
89
|
-
const isCurrentValid = await trigger(currentStepData.validationFields);
|
|
90
|
-
endExternalValidation();
|
|
91
|
-
if (!isCurrentValid) {
|
|
92
|
-
setStepValidationStatus(currentStepOriginalIndex, false);
|
|
93
|
-
activateFieldsValidation(currentStepData.validationFields || []);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
setStepValidationStatus(currentStepOriginalIndex, true);
|
|
97
|
-
}
|
|
98
|
-
setCurrentStep(targetOriginalIndex);
|
|
99
|
-
if (isNavigatingForward) {
|
|
100
|
-
const currentStepData = visibleSteps[currentIndex];
|
|
101
|
-
const currentStepOriginalIndex = steps.findIndex(
|
|
102
|
-
(s) => s.key === currentStepData.key
|
|
103
|
-
);
|
|
104
|
-
const isCurrentStepValid = stepValidationStatus[currentStepOriginalIndex] !== false;
|
|
105
|
-
if (isCurrentStepValid) {
|
|
106
|
-
const targetStep = visibleSteps[targetIndex];
|
|
107
|
-
const targetStepFields = targetStep.validationFields || [];
|
|
108
|
-
if (targetStepFields.length > 0) {
|
|
109
|
-
clearErrors(targetStepFields);
|
|
110
|
-
setTimeout(() => {
|
|
111
|
-
clearErrors(targetStepFields);
|
|
112
|
-
setStepValidationStatus(targetOriginalIndex, true);
|
|
113
|
-
}, 100);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
return /* @__PURE__ */ jsx(StepAreaStyled, { ownerState, children: allSteps.map((step, originalIndex) => {
|
|
119
|
-
const isStepVisible = evaluateVisibilityStepCondition(
|
|
120
|
-
step,
|
|
121
|
-
formValues || {},
|
|
122
|
-
visibilityData
|
|
123
|
-
);
|
|
124
|
-
const visibleStepIndex = isStepVisible ? visibleSteps.findIndex((visStep) => visStep.key === step.key) : -1;
|
|
14
|
+
return /* @__PURE__ */ jsx(StepAreaStyled, { ownerState, children: steps.map((step, originalIndex) => {
|
|
15
|
+
const visibleStepIndex = visibleSteps.findIndex((visibleStep) => visibleStep.key === step.key);
|
|
16
|
+
const isStepVisible = visibleStepIndex !== -1;
|
|
125
17
|
return /* @__PURE__ */ jsxs(
|
|
126
18
|
StepStyled,
|
|
127
19
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ActionFormCancelProps } from '../../../../CommonActions/components/ActionFormCancel/types';
|
|
2
2
|
/**
|
|
3
3
|
* Botón modular para cancelar el proceso del Stepper
|
|
4
4
|
*/
|
|
5
|
-
export declare function StepperCancelButton(props:
|
|
5
|
+
export declare function StepperCancelButton(props: ActionFormCancelProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,58 +1,8 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { useFormContext, useFormState } from "react-hook-form";
|
|
4
|
-
import { u as useStepperActions } from "../../../hooks/useStepperActions/index.js";
|
|
5
|
-
import { D as DICTIONARY$1 } from "../../../dictionary.js";
|
|
6
|
-
import { D as DICTIONARY } from "../../../../CommonActions/dictionary.js";
|
|
7
|
-
import { useModuleDictionary } from "@m4l/core";
|
|
8
|
-
import { u as useModal } from "../../../../../hooks/useModal/index.js";
|
|
9
|
-
import { u as useWindowToolsMF } from "../../../../WindowBase/hooks/useWindowToolsMF/index.js";
|
|
10
|
-
import { W as WindowConfirm } from "../../../../WindowConfirm/WindowConfirm.js";
|
|
11
|
-
import { B as Button } from "../../../../mui_extended/Button/Button.js";
|
|
2
|
+
import { A as ActionFormCancel } from "../../../../CommonActions/components/ActionFormCancel/ActionFormCancel.js";
|
|
12
3
|
function StepperCancelButton(props) {
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
const { cancelAction } = useStepperActions();
|
|
16
|
-
const { openModal } = useModal();
|
|
17
|
-
const { close: closeWindow } = useWindowToolsMF();
|
|
18
|
-
const { control } = useFormContext();
|
|
19
|
-
const { isDirty } = useFormState({
|
|
20
|
-
control
|
|
21
|
-
});
|
|
22
|
-
const onConfirmQuit = useCallback(() => {
|
|
23
|
-
cancelAction();
|
|
24
|
-
closeWindow();
|
|
25
|
-
}, [cancelAction, closeWindow]);
|
|
26
|
-
const handleCancel = useCallback(() => {
|
|
27
|
-
if (isDirty) {
|
|
28
|
-
openModal({
|
|
29
|
-
window: /* @__PURE__ */ jsx(
|
|
30
|
-
WindowConfirm,
|
|
31
|
-
{
|
|
32
|
-
variant: "warning",
|
|
33
|
-
title: getLabel(DICTIONARY.CONFIRM_QUIT_TITLE),
|
|
34
|
-
msg: getLabel(DICTIONARY.CONFIRM_QUIT_MSG),
|
|
35
|
-
onClickIntro: onConfirmQuit
|
|
36
|
-
}
|
|
37
|
-
),
|
|
38
|
-
variant: "warning"
|
|
39
|
-
});
|
|
40
|
-
} else {
|
|
41
|
-
onConfirmQuit();
|
|
42
|
-
}
|
|
43
|
-
}, [getLabel, isDirty, openModal, onConfirmQuit]);
|
|
44
|
-
return /* @__PURE__ */ jsx(
|
|
45
|
-
Button,
|
|
46
|
-
{
|
|
47
|
-
type: "button",
|
|
48
|
-
label: label || getLabel(DICTIONARY$1.LABEL_CANCEL_BUTTON),
|
|
49
|
-
variant: "outlined",
|
|
50
|
-
color: "default",
|
|
51
|
-
onClick: handleCancel,
|
|
52
|
-
...rest,
|
|
53
|
-
"data-testid": "stepper-cancel-button"
|
|
54
|
-
}
|
|
55
|
-
);
|
|
4
|
+
const { ...rest } = props;
|
|
5
|
+
return /* @__PURE__ */ jsx(ActionFormCancel, { "data-testid": "stepper-cancel-button", ...rest });
|
|
56
6
|
}
|
|
57
7
|
export {
|
|
58
8
|
StepperCancelButton as S
|