Skip to content

Commit bad44d3

Browse files
authored
Use default equipment type according to tabular modification dialog mode (#3215)
Signed-off-by: David BRAQUART <[email protected]>
1 parent ccfac29 commit bad44d3

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/components/dialogs/network-modifications/tabular/tabular-common.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
PredefinedProperties,
3535
} from '@gridsuite/commons-ui';
3636
import yup from 'components/utils/yup-config';
37-
import { EQUIPMENT_TYPES } from '../../../utils/equipment-types';
3837
import { UUID } from 'crypto';
3938

4039
type TabularModificationCommonType = {
@@ -71,11 +70,13 @@ export const tabularFormSchema = yup
7170

7271
export type TabularFormType = yup.InferType<typeof tabularFormSchema>;
7372

74-
export const emptyTabularFormData: TabularFormType = {
75-
[TYPE]: EQUIPMENT_TYPES.GENERATOR,
76-
[MODIFICATIONS_TABLE]: [],
77-
[TABULAR_PROPERTIES]: [],
78-
[CSV_FILENAME]: undefined,
73+
export const getEmptyTabularFormData = (equipmentType: string) => {
74+
return {
75+
[TYPE]: equipmentType,
76+
[MODIFICATIONS_TABLE]: [],
77+
[TABULAR_PROPERTIES]: [],
78+
[CSV_FILENAME]: undefined,
79+
};
7980
};
8081

8182
export interface Modification {

src/components/dialogs/network-modifications/tabular/tabular-dialog.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ import {
2020
convertInputValues,
2121
getEquipmentTypeFromModificationType,
2222
getFieldType,
23+
TABULAR_MODIFICATION_FIELDS,
2324
TABULAR_MODIFICATION_TYPES,
2425
transformModificationsTable,
2526
} from './tabular-modification-utils.js';
2627
import {
2728
addPropertiesFromBack,
2829
convertReactiveCapabilityCurvePointsFromFrontToBack,
29-
emptyTabularFormData,
3030
formatModification,
31+
getEmptyTabularFormData,
3132
Modification,
3233
tabularFormSchema,
3334
TabularFormType,
@@ -42,6 +43,7 @@ import {
4243
convertCreationFieldFromBackToFront,
4344
convertCreationFieldFromFrontToBack,
4445
getEquipmentTypeFromCreationType,
46+
TABULAR_CREATION_FIELDS,
4547
TABULAR_CREATION_TYPES,
4648
} from './tabular-creation-utils';
4749
import { NetworkModificationDialogProps } from '../../../graph/menus/network-modifications/network-modification-menu.type';
@@ -63,8 +65,14 @@ export function TabularDialog({
6365
const currentNodeUuid = currentNode?.id;
6466
const { snackError } = useSnackMessage();
6567

68+
const defaultEquipmentType = useMemo(() => {
69+
return dialogMode === TabularModificationType.CREATION
70+
? (Object.keys(TABULAR_CREATION_FIELDS).at(0) ?? '')
71+
: (Object.keys(TABULAR_MODIFICATION_FIELDS).at(0) ?? '');
72+
}, [dialogMode]);
73+
6674
const formMethods = useForm<TabularFormType>({
67-
defaultValues: emptyTabularFormData,
75+
defaultValues: getEmptyTabularFormData(defaultEquipmentType),
6876
resolver: yupResolver(tabularFormSchema),
6977
});
7078

@@ -207,8 +215,8 @@ export function TabularDialog({
207215
);
208216

209217
const clear = useCallback(() => {
210-
reset(emptyTabularFormData);
211-
}, [reset]);
218+
reset(getEmptyTabularFormData(defaultEquipmentType));
219+
}, [defaultEquipmentType, reset]);
212220

213221
const open = useOpenShortWaitFetching({
214222
isDataFetched:

0 commit comments

Comments
 (0)