From 2f8957344b88934f5381c1c1c57f193554323527 Mon Sep 17 00:00:00 2001 From: Florent MILLOT Date: Fri, 10 Oct 2025 18:57:30 +0200 Subject: [PATCH] Add `ArrayAction` enum and enhance `DirectoryItemsInput` with action-tracking logic. Introduce `RefreshButton` component. Signed-off-by: Florent MILLOT --- .../reactHookForm/DirectoryItemsInput.tsx | 9 +++++---- .../reactHookForm/utils/RefreshButton.tsx | 17 +++++++++++++++++ .../inputs/reactHookForm/utils/index.ts | 1 + src/utils/types/types.ts | 5 +++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/components/inputs/reactHookForm/utils/RefreshButton.tsx diff --git a/src/components/inputs/reactHookForm/DirectoryItemsInput.tsx b/src/components/inputs/reactHookForm/DirectoryItemsInput.tsx index cb0c4e5f7..e444315a0 100644 --- a/src/components/inputs/reactHookForm/DirectoryItemsInput.tsx +++ b/src/components/inputs/reactHookForm/DirectoryItemsInput.tsx @@ -21,7 +21,7 @@ import { type MuiStyles } from '../../../utils/styles'; import { OverflowableText } from '../../overflowableText'; import { DirectoryItemSelector } from '../../directoryItemSelector'; import { fetchDirectoryElementPath } from '../../../services'; -import { ElementAttributes, mergeSx } from '../../../utils'; +import { ArrayAction, ElementAttributes, mergeSx } from '../../../utils'; import { NAME } from './constants'; import { getFilterEquipmentTypeLabel } from '../../filter/expert/expertFilterUtils'; @@ -62,7 +62,7 @@ export interface DirectoryItemsInputProps { titleId?: string; hideErrorMessage?: boolean; onRowChanged?: (a: boolean) => void; - onChange?: (e: any) => void; + onChange?: (e: any, action?: ArrayAction, element?: any) => void; disable?: boolean; allowMultiSelect?: boolean; labelRequiredFromContext?: boolean; @@ -131,7 +131,7 @@ export function DirectoryItemsInput({ } else { append(otherElementAttributes); onRowChanged?.(true); - onChange?.(getValues(name)); + onChange?.(getValues(name), ArrayAction.ADD, otherElementAttributes); } }); setDirectoryItemSelectorOpen(false); @@ -142,9 +142,10 @@ export function DirectoryItemsInput({ const removeElements = useCallback( (index: number) => { + const currentValues = getValues(name); remove(index); onRowChanged?.(true); - onChange?.(getValues(name)); + onChange?.(currentValues, ArrayAction.REMOVE, currentValues[index]); }, [onRowChanged, remove, getValues, name, onChange] ); diff --git a/src/components/inputs/reactHookForm/utils/RefreshButton.tsx b/src/components/inputs/reactHookForm/utils/RefreshButton.tsx new file mode 100644 index 000000000..3ca7e18fe --- /dev/null +++ b/src/components/inputs/reactHookForm/utils/RefreshButton.tsx @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2025, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import { ButtonProps, IconButton } from '@mui/material'; +import { Refresh } from '@mui/icons-material'; + +export function RefreshButton(buttonProps: Readonly) { + return ( + + + + ); +} diff --git a/src/components/inputs/reactHookForm/utils/index.ts b/src/components/inputs/reactHookForm/utils/index.ts index f1ab5168c..34a53121a 100644 --- a/src/components/inputs/reactHookForm/utils/index.ts +++ b/src/components/inputs/reactHookForm/utils/index.ts @@ -8,6 +8,7 @@ export * from './CancelButton'; export * from './FieldLabel'; export * from './SubmitButton'; +export * from './RefreshButton'; export * from './TextFieldWithAdornment'; export * from './functions'; export * from './HelperPreviousValue'; diff --git a/src/utils/types/types.ts b/src/utils/types/types.ts index 87376a611..43276a921 100644 --- a/src/utils/types/types.ts +++ b/src/utils/types/types.ts @@ -72,3 +72,8 @@ export type AnnouncementDto = { severity: AnnouncementSeverity; remainingDuration: number; }; + +export enum ArrayAction { + ADD = 'ADD', + REMOVE = 'REMOVE', +}