diff --git a/src/components/dialogs/dialog-utils.ts b/src/components/dialogs/dialog-utils.ts deleted file mode 100644 index 42bd154f76..0000000000 --- a/src/components/dialogs/dialog-utils.ts +++ /dev/null @@ -1,141 +0,0 @@ -/** - * Copyright (c) 2022, 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 { FilledTextFieldProps, StandardTextFieldProps } from '@mui/material'; -import { - AMPERE, - KILO_AMPERE, - KILO_METER, - KILO_VOLT, - MEGA_VAR, - MEGA_VOLT_AMPERE, - MEGA_WATT, - MICRO_SIEMENS, - type MuiStyles, - OHM, - PERCENTAGE, - SIEMENS, -} from '@gridsuite/commons-ui'; - -export const styles = { - helperText: { - margin: 0, - marginTop: '4px', - }, - tooltip: { - fontSize: 18, - maxWidth: 'none', - }, - button: (theme) => ({ - justifyContent: 'flex-start', - fontSize: 'small', - marginTop: theme.spacing(1), - }), - paddingButton: (theme) => ({ - paddingLeft: theme.spacing(2), - }), - formDirectoryElements1: { - display: 'flex', - gap: '8px', - flexWrap: 'wrap', - flexDirection: 'row', - border: '2px solid lightgray', - padding: '4px', - borderRadius: '4px', - overflow: 'hidden', - }, - formDirectoryElementsError: (theme) => ({ - borderColor: theme.palette.error.main, - }), - formDirectoryElements2: { - display: 'flex', - gap: '8px', - flexWrap: 'wrap', - flexDirection: 'row', - marginTop: 0, - padding: '4px', - overflow: 'hidden', - }, - labelDirectoryElements: { - marginTop: '-10px', - }, - addDirectoryElements: { - marginTop: '-5px', - }, -} as const satisfies MuiStyles; - -export const MicroSusceptanceAdornment = { - position: 'end', - text: MICRO_SIEMENS, -}; - -export const SusceptanceAdornment = { - position: 'end', - text: SIEMENS, -}; -export const OhmAdornment = { - position: 'end', - text: OHM, -}; -export const AmpereAdornment = { - position: 'end', - text: AMPERE, -}; - -export const KiloAmpereAdornment = { - position: 'end', - text: KILO_AMPERE, -}; - -export const ActivePowerAdornment = { - position: 'end', - text: MEGA_WATT, -}; -export const ReactivePowerAdornment = { - position: 'end', - text: MEGA_VAR, -}; -export const MVAPowerAdornment = { - position: 'end', - text: MEGA_VOLT_AMPERE, -}; -export const VoltageAdornment = { - position: 'end', - text: KILO_VOLT, -}; -export const KilometerAdornment = { - position: 'end', - text: KILO_METER, -}; -export const filledTextField: FilledTextFieldProps = { - variant: 'filled', -}; - -export const standardTextField: StandardTextFieldProps = { - variant: 'standard', -}; - -export const italicFontTextField = { - style: { fontStyle: 'italic' }, -}; - -export const percentageTextField = { - position: 'end', - text: PERCENTAGE, -}; - -export function parseIntData(val: string | number, defaultValue: string | number) { - const intValue = parseInt(String(val)); - return isNaN(intValue) ? defaultValue : intValue; -} - -export function sanitizeString(val: string | null | undefined): string | null { - const trimedValue = val?.trim(); - return trimedValue === undefined || trimedValue === '' ? null : trimedValue; -} - -export const getIdOrSelf = (e: any) => e?.id ?? e; diff --git a/src/components/dialogs/dynamicsimulation/dynamic-simulation-parameters-selector.tsx b/src/components/dialogs/dynamicsimulation/dynamic-simulation-parameters-selector.tsx index 1d7c3f1844..a0ab95804e 100644 --- a/src/components/dialogs/dynamicsimulation/dynamic-simulation-parameters-selector.tsx +++ b/src/components/dialogs/dynamicsimulation/dynamic-simulation-parameters-selector.tsx @@ -12,14 +12,19 @@ import Typography from '@mui/material/Typography'; import { FormattedMessage } from 'react-intl'; import Grid from '@mui/material/Grid'; import Button from '@mui/material/Button'; -import { AutocompleteInput, CustomFormProvider, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { + AutocompleteInput, + CustomFormProvider, + getIdOrSelf, + snackWithFallback, + useSnackMessage, +} from '@gridsuite/commons-ui'; import { fetchDynamicSimulationParameters, updateDynamicSimulationParameters, } from '../../../services/study/dynamic-simulation'; import { useForm } from 'react-hook-form'; import { yupResolver } from '@hookform/resolvers/yup'; -import { getIdOrSelf } from '../dialog-utils'; import GridItem from '../commons/grid-item'; import type { UUID } from 'node:crypto'; import { DynamicSimulationParametersInfos } from '../../../services/study/dynamic-simulation.type'; diff --git a/src/components/dialogs/dynamicsimulation/event/dynamic-simulation-event-form.tsx b/src/components/dialogs/dynamicsimulation/event/dynamic-simulation-event-form.tsx index edc0b23a0c..35877d01c6 100644 --- a/src/components/dialogs/dynamicsimulation/event/dynamic-simulation-event-form.tsx +++ b/src/components/dialogs/dynamicsimulation/event/dynamic-simulation-event-form.tsx @@ -5,12 +5,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { Grid, TextField } from '@mui/material'; -import { filledTextField } from '../../dialog-utils'; import { Event, EventDefinition, EventPropertyName } from './types/event.type'; import { makeComponentFor } from './util/event-rhf'; import { useIntl } from 'react-intl'; import { EQUIPMENT_TYPES } from '../../../utils/equipment-types'; import GridItem from '../../commons/grid-item'; +import { filledTextField } from '@gridsuite/commons-ui'; export type DynamicSimulationBasicEventFormProps = { equipmentId: string; diff --git a/src/components/dialogs/equipment-id/equipment-id-selector.tsx b/src/components/dialogs/equipment-id/equipment-id-selector.tsx index 4478f23652..fdf445e662 100644 --- a/src/components/dialogs/equipment-id/equipment-id-selector.tsx +++ b/src/components/dialogs/equipment-id/equipment-id-selector.tsx @@ -6,10 +6,15 @@ */ import { useEffect, useState } from 'react'; -import { filledTextField } from '../dialog-utils'; import type { UUID } from 'node:crypto'; import { Autocomplete, Box, CircularProgress, Grid, TextField } from '@mui/material'; -import { type EquipmentType, type ExtendedEquipmentType, FieldLabel, type MuiStyles } from '@gridsuite/commons-ui'; +import { + type EquipmentType, + type ExtendedEquipmentType, + FieldLabel, + filledTextField, + type MuiStyles, +} from '@gridsuite/commons-ui'; import { FormFiller } from './formFiller.js'; import { FormattedMessage } from 'react-intl'; import { fetchEquipmentsIds } from '../../../services/study/network-map'; diff --git a/src/components/dialogs/limits/limits-pane-utils.ts b/src/components/dialogs/limits/limits-pane-utils.ts index f2812d00c4..dc6bcb8029 100644 --- a/src/components/dialogs/limits/limits-pane-utils.ts +++ b/src/components/dialogs/limits/limits-pane-utils.ts @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { sanitizeString } from '../dialog-utils'; import { APPLICABILITY_FIELD, CURRENT_LIMITS, @@ -25,7 +24,6 @@ import { TEMPORARY_LIMIT_NAME, TEMPORARY_LIMIT_VALUE, TEMPORARY_LIMITS, - VALUE, } from 'components/utils/field-constants'; import { areArrayElementsUnique, @@ -46,6 +44,7 @@ import { LineModificationFormSchema } from '../network-modifications/line/modifi import { OperationalLimitsGroupFormSchema, TemporaryLimitFormSchema } from './operational-limits-groups-types'; import { TestContext } from 'yup'; import { APPLICABILITY } from 'components/network/constants'; +import { FieldConstants, sanitizeString } from '@gridsuite/commons-ui'; const limitsGroupValidationSchema = () => ({ [ID]: yup.string().nonNullable().required(), @@ -72,7 +71,7 @@ const temporaryLimitsValidationSchema = () => { const limitsPropertyValidationSchema = () => { return yup.object().shape({ [NAME]: yup.string().required(), - [VALUE]: yup.string().required(), + [FieldConstants.VALUE]: yup.string().required(), }); }; diff --git a/src/components/dialogs/limits/limits-side-pane.tsx b/src/components/dialogs/limits/limits-side-pane.tsx index dbc9b84c53..f712f59854 100644 --- a/src/components/dialogs/limits/limits-side-pane.tsx +++ b/src/components/dialogs/limits/limits-side-pane.tsx @@ -7,6 +7,7 @@ import { Box, Grid } from '@mui/material'; import { FormattedMessage, useIntl } from 'react-intl'; import { + AmpereAdornment, ColumnNumeric, ColumnText, DndColumn, @@ -32,7 +33,6 @@ import { TEMPORARY_LIMIT_VALUE, TEMPORARY_LIMITS, } from 'components/utils/field-constants'; -import { AmpereAdornment } from '../dialog-utils'; import { useCallback, useEffect, useMemo } from 'react'; import { useController, useFormContext } from 'react-hook-form'; import { isNodeBuilt } from '../../graph/util/model-functions'; diff --git a/src/components/dialogs/limits/operational-limits-groups-types.ts b/src/components/dialogs/limits/operational-limits-groups-types.ts index 324196f29b..d929a8d61d 100644 --- a/src/components/dialogs/limits/operational-limits-groups-types.ts +++ b/src/components/dialogs/limits/operational-limits-groups-types.ts @@ -21,8 +21,8 @@ import { TEMPORARY_LIMIT_NAME, TEMPORARY_LIMIT_VALUE, TEMPORARY_LIMITS, - VALUE, } from '../../utils/field-constants'; +import { FieldConstants } from '@gridsuite/commons-ui'; export interface LimitsFormSchema { [LIMITS]: OperationalLimitsGroupsFormSchema; @@ -52,7 +52,7 @@ export interface CurrentLimitsFormSchema { interface LimitsPropertyFormSchema { [NAME]: string; - [VALUE]: string; + [FieldConstants.VALUE]: string; } export interface TemporaryLimitFormSchema { diff --git a/src/components/dialogs/line-types-catalog/line-type-segment-creation.tsx b/src/components/dialogs/line-types-catalog/line-type-segment-creation.tsx index b8509b1699..c0cb2ee3ce 100644 --- a/src/components/dialogs/line-types-catalog/line-type-segment-creation.tsx +++ b/src/components/dialogs/line-types-catalog/line-type-segment-creation.tsx @@ -7,9 +7,8 @@ import { useCallback, useEffect } from 'react'; import { useWatch } from 'react-hook-form'; -import { KilometerAdornment } from '../dialog-utils'; import EditIcon from '@mui/icons-material/Edit'; -import { FloatInput } from '@gridsuite/commons-ui'; +import { FloatInput, KilometerAdornment } from '@gridsuite/commons-ui'; import { IconButton } from '@mui/material'; import { SEGMENT_DISTANCE_VALUE, diff --git a/src/components/dialogs/line-types-catalog/line-type-segment-dialog.tsx b/src/components/dialogs/line-types-catalog/line-type-segment-dialog.tsx index fc76b3c6a4..f9c20ae6a9 100644 --- a/src/components/dialogs/line-types-catalog/line-type-segment-dialog.tsx +++ b/src/components/dialogs/line-types-catalog/line-type-segment-dialog.tsx @@ -11,7 +11,7 @@ import yup from 'components/utils/yup-config'; import { ModificationDialog } from '../commons/modificationDialog'; import { useForm } from 'react-hook-form'; import { LineTypeSegmentForm } from './line-type-segment-form'; -import { CustomFormProvider } from '@gridsuite/commons-ui'; +import { CustomFormProvider, DeepNullable } from '@gridsuite/commons-ui'; import { ComputedLineCharacteristics } from './line-catalog.type'; import { SegmentSchema } from './segment-utils'; import { @@ -22,7 +22,6 @@ import { TOTAL_SUSCEPTANCE, } from '../../utils/field-constants'; import { InferType } from 'yup'; -import { DeepNullable } from '../../utils/ts-utils'; const LineTypeSegmentSchema = yup .object() diff --git a/src/components/dialogs/line-types-catalog/line-type-segment-form.tsx b/src/components/dialogs/line-types-catalog/line-type-segment-form.tsx index f6c6e9db53..0fff828477 100644 --- a/src/components/dialogs/line-types-catalog/line-type-segment-form.tsx +++ b/src/components/dialogs/line-types-catalog/line-type-segment-form.tsx @@ -9,7 +9,6 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { useFormContext } from 'react-hook-form'; import { Box, Grid } from '@mui/material'; import { FormattedMessage, useIntl } from 'react-intl'; -import { ExpandableInput } from '../../utils/rhf-inputs/expandable-input'; import { ReadOnlyInput } from '../../utils/rhf-inputs/read-only/read-only-input'; import { FINAL_CURRENT_LIMITS, @@ -32,6 +31,7 @@ import { calculateReactance, calculateResistance, calculateSusceptance } from '. import { CustomAGGrid, DefaultCellRenderer, + ExpandableInput, type MuiStyles, snackWithFallback, useSnackMessage, diff --git a/src/components/dialogs/line-types-catalog/line-types-catalog-selector-dialog.tsx b/src/components/dialogs/line-types-catalog/line-types-catalog-selector-dialog.tsx index fc51879802..c1aba96e4d 100644 --- a/src/components/dialogs/line-types-catalog/line-types-catalog-selector-dialog.tsx +++ b/src/components/dialogs/line-types-catalog/line-types-catalog-selector-dialog.tsx @@ -6,7 +6,7 @@ */ import { useCallback, useRef, useState } from 'react'; -import { CustomFormProvider, Option, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { CustomFormProvider, Option, snackWithFallback, useSnackMessage, DeepNullable } from '@gridsuite/commons-ui'; import { AgGridReact } from 'ag-grid-react'; import { CATEGORIES_TABS, CurrentLimitsInfo, LineTypeInfo } from './line-catalog.type'; import { @@ -22,7 +22,6 @@ import { getLineTypeWithLimits } from '../../../services/network-modification'; import { ModificationDialog } from '../commons/modificationDialog'; import yup from '../../utils/yup-config'; import { yupResolver } from '@hookform/resolvers/yup'; -import { DeepNullable } from 'components/utils/ts-utils'; import LineTypesCatalogSelectorForm from './line-types-catalog-selector-form'; const formSchema = yup diff --git a/src/components/dialogs/network-modifications/battery/battery-dialog.type.ts b/src/components/dialogs/network-modifications/battery/battery-dialog.type.ts index 9931ef163d..7f92555981 100644 --- a/src/components/dialogs/network-modifications/battery/battery-dialog.type.ts +++ b/src/components/dialogs/network-modifications/battery/battery-dialog.type.ts @@ -7,7 +7,6 @@ import { ACTIVE_POWER_SET_POINT, - ADDITIONAL_PROPERTIES, BUS_OR_BUSBAR_SECTION, CONNECTED, CONNECTION_DIRECTION, @@ -31,7 +30,6 @@ import { TRANSIENT_REACTANCE, VOLTAGE_LEVEL, } from '../../../utils/field-constants'; -import { Property } from '../common/properties/property-utils'; import { ConnectablePositionFormInfos } from '../../connectivity/connectivity.type'; import { MinMaxReactiveLimitsFormInfos, @@ -39,6 +37,7 @@ import { } from '../../reactive-limits/reactive-limits.type'; import { ActivePowerControlInfos } from '../../active-power-control/active-power-control.type'; import { ShortCircuitFormInfos } from '../../short-circuit/short-circuit-utils'; +import { FieldConstants, Property } from '@gridsuite/commons-ui'; export type BatteryDialogSchemaBaseForm = { [EQUIPMENT_NAME]?: string; @@ -63,7 +62,7 @@ export type BatteryDialogSchemaBaseForm = { [REACTIVE_CAPABILITY_CURVE_TABLE]?: ReactiveCapabilityCurvePoints[]; }; // Properties - [ADDITIONAL_PROPERTIES]?: Property[]; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Property[]; [TRANSFORMER_REACTANCE]?: number | null; [TRANSIENT_REACTANCE]?: number | null; }; diff --git a/src/components/dialogs/network-modifications/battery/creation/battery-creation-dialog.tsx b/src/components/dialogs/network-modifications/battery/creation/battery-creation-dialog.tsx index 181221daa2..69a84aa409 100644 --- a/src/components/dialogs/network-modifications/battery/creation/battery-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/battery/creation/battery-creation-dialog.tsx @@ -11,11 +11,18 @@ import EquipmentSearchDialog from '../../../equipment-search-dialog'; import { useCallback, useEffect } from 'react'; import { useFormSearchCopy } from '../../../commons/use-form-search-copy'; import { + copyEquipmentPropertiesForCreation, + creationPropertiesSchema, CustomFormProvider, + emptyProperties, EquipmentType, + getPropertiesFromModification, MODIFICATION_TYPES, snackWithFallback, + toModificationProperties, useSnackMessage, + DeepNullable, + sanitizeString, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; @@ -49,7 +56,6 @@ import { getConnectivityWithPositionEmptyFormData, getConnectivityWithPositionSchema, } from '../../../connectivity/connectivity-form-utils'; -import { sanitizeString } from '../../../dialog-utils'; import { FORM_LOADING_DELAY, UNDEFINED_CONNECTION_DIRECTION } from 'components/network/constants'; import { getReactiveLimitsEmptyFormData, @@ -59,15 +65,7 @@ import { import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form'; import { createBattery } from '../../../../../services/study/network-modifications'; import { FetchStatus } from '../../../../../services/utils.type'; -import { - copyEquipmentPropertiesForCreation, - creationPropertiesSchema, - emptyProperties, - getPropertiesFromModification, - toModificationProperties, -} from '../../common/properties/property-utils'; import { BatteryCreationDialogSchemaForm, BatteryFormInfos } from '../battery-dialog.type'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { getActivePowerControlEmptyFormData, getActivePowerControlSchema, diff --git a/src/components/dialogs/network-modifications/battery/creation/battery-creation-form.tsx b/src/components/dialogs/network-modifications/battery/creation/battery-creation-form.tsx index 66d8d3f88f..81decbbebe 100644 --- a/src/components/dialogs/network-modifications/battery/creation/battery-creation-form.tsx +++ b/src/components/dialogs/network-modifications/battery/creation/battery-creation-form.tsx @@ -5,18 +5,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { FloatInput, TextInput } from '@gridsuite/commons-ui'; +import { ActivePowerAdornment, filledTextField, FloatInput, PropertiesForm, TextInput } from '@gridsuite/commons-ui'; import { EQUIPMENT_ID, EQUIPMENT_NAME, MAXIMUM_ACTIVE_POWER, MINIMUM_ACTIVE_POWER, } from 'components/utils/field-constants'; -import { ActivePowerAdornment, filledTextField } from '../../../dialog-utils'; import { Grid } from '@mui/material'; import { ConnectivityForm } from '../../../connectivity/connectivity-form'; import { ReactiveLimitsForm } from '../../../reactive-limits/reactive-limits-form'; -import PropertiesForm from '../../common/properties/properties-form'; import useVoltageLevelsListInfos from '../../../../../hooks/use-voltage-levels-list-infos'; import GridItem from '../../../commons/grid-item'; import GridSection from '../../../commons/grid-section'; diff --git a/src/components/dialogs/network-modifications/battery/modification/battery-modification-dialog.tsx b/src/components/dialogs/network-modifications/battery/modification/battery-modification-dialog.tsx index 29993bcb8d..09afae65ad 100644 --- a/src/components/dialogs/network-modifications/battery/modification/battery-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/battery/modification/battery-modification-dialog.tsx @@ -8,16 +8,23 @@ import { useCallback, useEffect, useState } from 'react'; import { CustomFormProvider, + emptyProperties, EquipmentType, + getConcatenatedProperties, + getPropertiesFromModification, MODIFICATION_TYPES, + modificationPropertiesSchema, snackWithFallback, + toModificationProperties, useSnackMessage, + DeepNullable, + sanitizeString, + FieldConstants, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; import { ACTIVE_POWER_SET_POINT, - ADDITIONAL_PROPERTIES, BUS_OR_BUSBAR_SECTION, CONNECTED, CONNECTION_DIRECTION, @@ -43,7 +50,6 @@ import { TRANSIENT_REACTANCE, VOLTAGE_LEVEL, } from 'components/utils/field-constants'; -import { sanitizeString } from '../../../dialog-utils'; import { getReactiveLimitsEmptyFormData, getReactiveLimitsFormData, @@ -55,13 +61,6 @@ import { EQUIPMENT_INFOS_TYPES } from 'components/utils/equipment-types'; import { EquipmentIdSelector } from '../../../equipment-id/equipment-id-selector'; import { modifyBattery } from '../../../../../services/study/network-modifications'; import { fetchNetworkElementInfos } from '../../../../../services/study/network'; -import { - emptyProperties, - getConcatenatedProperties, - getPropertiesFromModification, - modificationPropertiesSchema, - toModificationProperties, -} from '../../common/properties/property-utils'; import { getConnectivityFormData, getConnectivityWithPositionEmptyFormData, @@ -69,7 +68,6 @@ import { } from '../../../connectivity/connectivity-form-utils'; import { isNodeBuilt } from '../../../../graph/util/model-functions'; import { BatteryFormInfos, BatteryModificationDialogSchemaForm } from '../battery-dialog.type'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { FetchStatus } from '../../../../../services/utils.type'; import { toModificationOperation } from '../../../../utils/utils'; import { @@ -255,7 +253,7 @@ export default function BatteryModificationDialog({ reset( (formValues) => ({ ...formValues, - [ADDITIONAL_PROPERTIES]: getConcatenatedProperties(value, getValues), + [FieldConstants.ADDITIONAL_PROPERTIES]: getConcatenatedProperties(value, getValues), }), { keepDirty: true } ); diff --git a/src/components/dialogs/network-modifications/battery/modification/battery-modification-form.tsx b/src/components/dialogs/network-modifications/battery/modification/battery-modification-form.tsx index 27b82a039b..67a39ef8a3 100644 --- a/src/components/dialogs/network-modifications/battery/modification/battery-modification-form.tsx +++ b/src/components/dialogs/network-modifications/battery/modification/battery-modification-form.tsx @@ -12,12 +12,17 @@ import { MINIMUM_ACTIVE_POWER, REACTIVE_POWER_SET_POINT, } from 'components/utils/field-constants'; -import { ActivePowerAdornment, filledTextField, ReactivePowerAdornment } from '../../../dialog-utils'; import { Grid, TextField } from '@mui/material'; -import { FloatInput, TextInput } from '@gridsuite/commons-ui'; +import { + ActivePowerAdornment, + filledTextField, + FloatInput, + PropertiesForm, + ReactivePowerAdornment, + TextInput, +} from '@gridsuite/commons-ui'; import { ReactiveLimitsForm } from '../../../reactive-limits/reactive-limits-form'; import { FormattedMessage } from 'react-intl'; -import PropertiesForm from '../../common/properties/properties-form'; import { ConnectivityForm } from '../../../connectivity/connectivity-form'; import GridItem from '../../../commons/grid-item'; import GridSection from '../../../commons/grid-section'; diff --git a/src/components/dialogs/network-modifications/by-filter/by-assignment/modification-by-assignment-dialog.tsx b/src/components/dialogs/network-modifications/by-filter/by-assignment/modification-by-assignment-dialog.tsx index 52edb6cf39..284fba0035 100644 --- a/src/components/dialogs/network-modifications/by-filter/by-assignment/modification-by-assignment-dialog.tsx +++ b/src/components/dialogs/network-modifications/by-filter/by-assignment/modification-by-assignment-dialog.tsx @@ -14,6 +14,7 @@ import { FieldType, snackWithFallback, useSnackMessage, + DeepNullable, } from '@gridsuite/commons-ui'; import { FC, useCallback, useEffect, useMemo } from 'react'; import { FetchStatus } from '../../../../../services/utils'; @@ -31,7 +32,6 @@ import { getDataType, } from './assignment/assignment-utils'; import { Assignment, ModificationByAssignment } from './assignment/assignment.type'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { useIntl } from 'react-intl'; const emptyFormData = { diff --git a/src/components/dialogs/network-modifications/by-filter/by-assignment/modification-by-assignment-form.tsx b/src/components/dialogs/network-modifications/by-filter/by-assignment/modification-by-assignment-form.tsx index e647b4ed2b..0810f7fff7 100644 --- a/src/components/dialogs/network-modifications/by-filter/by-assignment/modification-by-assignment-form.tsx +++ b/src/components/dialogs/network-modifications/by-filter/by-assignment/modification-by-assignment-form.tsx @@ -7,13 +7,12 @@ import { FC } from 'react'; import { ASSIGNMENTS, EQUIPMENT_TYPE_FIELD } from '../../../../utils/field-constants'; -import { ExpandableInput } from '../../../../utils/rhf-inputs/expandable-input'; import AssignmentForm from './assignment/assignment-form'; import { Box, Grid } from '@mui/material'; import { getAssignmentInitialValue } from './assignment/assignment-utils'; import { useFormContext } from 'react-hook-form'; import SelectWithConfirmationInput from '../../../commons/select-with-confirmation-input'; -import { mergeSx, unscrollableDialogStyles } from '@gridsuite/commons-ui'; +import { ExpandableInput, mergeSx, unscrollableDialogStyles } from '@gridsuite/commons-ui'; import { EQUIPMENTS_FIELDS } from './assignment/assignment-constants'; import useGetLabelEquipmentTypes from '../../../../../hooks/use-get-label-equipment-types'; import GridItem from '../../../commons/grid-item'; diff --git a/src/components/dialogs/network-modifications/by-filter/by-formula/by-formula-dialog.jsx b/src/components/dialogs/network-modifications/by-filter/by-formula/by-formula-dialog.jsx index 435f9ca10d..8fddf8ddcf 100644 --- a/src/components/dialogs/network-modifications/by-filter/by-formula/by-formula-dialog.jsx +++ b/src/components/dialogs/network-modifications/by-filter/by-formula/by-formula-dialog.jsx @@ -11,6 +11,7 @@ import { convertInputValue, convertOutputValue, CustomFormProvider, + FieldConstants, FieldType, MODIFICATION_TYPES, snackWithFallback, @@ -32,7 +33,6 @@ import { OPERATOR, REFERENCE_FIELD_OR_VALUE_1, REFERENCE_FIELD_OR_VALUE_2, - VALUE, } from '../../../../utils/field-constants'; import { modifyByFormula } from '../../../../../services/study/network-modifications'; import { getFormulaInitialValue, getFormulaSchema } from './formula/formula-utils'; @@ -43,12 +43,12 @@ function getFieldOrConvertedUnitValue(input, fieldType, convert) { if (isNumber) { return { - [VALUE]: convert ? convertOutputValue(fieldType, value) : value, + [FieldConstants.VALUE]: convert ? convertOutputValue(fieldType, value) : value, [EQUIPMENT_FIELD]: null, }; } else { return { - [VALUE]: null, + [FieldConstants.VALUE]: null, [EQUIPMENT_FIELD]: input, }; } diff --git a/src/components/dialogs/network-modifications/by-filter/by-formula/by-formula-form.tsx b/src/components/dialogs/network-modifications/by-filter/by-formula/by-formula-form.tsx index df177ea455..3c8be48930 100644 --- a/src/components/dialogs/network-modifications/by-filter/by-formula/by-formula-form.tsx +++ b/src/components/dialogs/network-modifications/by-filter/by-formula/by-formula-form.tsx @@ -8,13 +8,12 @@ import { FunctionComponent } from 'react'; import { EQUIPMENT_TYPES } from 'components/utils/equipment-types'; import { EQUIPMENT_TYPE_FIELD, FORMULAS } from '../../../../utils/field-constants'; -import { ExpandableInput } from '../../../../utils/rhf-inputs/expandable-input'; import FormulaForm from './formula/formula-form'; import { getFormulaInitialValue } from './formula/formula-utils'; import { useFormContext } from 'react-hook-form'; import SelectWithConfirmationInput from '../../../commons/select-with-confirmation-input'; import { Box, Grid } from '@mui/material'; -import { mergeSx, unscrollableDialogStyles } from '@gridsuite/commons-ui'; +import { ExpandableInput, mergeSx, unscrollableDialogStyles } from '@gridsuite/commons-ui'; import GridItem from '../../../commons/grid-item'; interface ByFormulaFormProps {} diff --git a/src/components/dialogs/network-modifications/common/measurements/power-with-validity-form.tsx b/src/components/dialogs/network-modifications/common/measurements/power-with-validity-form.tsx index 451eea107d..39cd7101c5 100644 --- a/src/components/dialogs/network-modifications/common/measurements/power-with-validity-form.tsx +++ b/src/components/dialogs/network-modifications/common/measurements/power-with-validity-form.tsx @@ -8,12 +8,18 @@ import Grid from '@mui/material/Grid'; import { FunctionComponent, useMemo } from 'react'; import { useIntl } from 'react-intl'; -import { convertInputValue, FieldType, FloatInput } from '@gridsuite/commons-ui'; +import { + ActivePowerAdornment, + convertInputValue, + FieldConstants, + FieldType, + FloatInput, + ReactivePowerAdornment, +} from '@gridsuite/commons-ui'; import { MeasurementProps } from './measurement.type'; import CheckboxNullableInput from '../../../../utils/rhf-inputs/boolean-nullable-input'; import GridItem from '../../../commons/grid-item'; -import { VALIDITY, VALUE } from '../../../../utils/field-constants'; -import { ActivePowerAdornment, ReactivePowerAdornment } from '../../../dialog-utils'; +import { VALIDITY } from '../../../../utils/field-constants'; export const PowerWithValidityForm: FunctionComponent = ({ id, field, measurement }) => { const intl = useIntl(); @@ -29,7 +35,7 @@ export const PowerWithValidityForm: FunctionComponent = ({ id, const valueField = ( { - const additionalProperties = id ? `${id}.${ADDITIONAL_PROPERTIES}` : ADDITIONAL_PROPERTIES; - const watchProps = useWatch({ - name: additionalProperties, - }); - const { getValues, setValue } = useFormContext(); - const [predefinedProperties, setPredefinedProperties] = useState({} as PredefinedProperties); - - useEffect(() => { - networkElementType && - fetchPredefinedProperties(networkElementType).then((res) => { - if (res) { - setPredefinedProperties(res); - } - }); - }, [networkElementType]); - - const getDeletionMark = useCallback( - (idx: number) => { - const properties = getValues(`${additionalProperties}`); - if (properties && typeof properties[idx] !== 'undefined') { - return watchProps && properties[idx][DELETION_MARK]; - } - return false; - }, - [getValues, watchProps, additionalProperties] - ); - - const deleteCallback = useCallback( - (idx: number) => { - let markedForDeletion = false; - const properties = getValues(`${additionalProperties}`); - if (properties && typeof properties[idx] !== 'undefined') { - markedForDeletion = properties[idx][DELETION_MARK]; - } else { - return false; - } - - let canRemoveLine = true; - if (markedForDeletion) { - // just unmark - setValue(`${additionalProperties}.${idx}.${DELETION_MARK}`, false, { shouldDirty: true }); - canRemoveLine = false; - } else { - // we should mark for deletion a property that actually exists in the network and not delete the property line straight away - if (properties[idx][PREVIOUS_VALUE] && properties[idx][ADDED] === false) { - setValue(`${additionalProperties}.${idx}.${DELETION_MARK}`, true, { shouldDirty: true }); - canRemoveLine = false; - } - } - // otherwise just delete the line - return canRemoveLine; - }, - [getValues, setValue, additionalProperties] - ); - - const modificationProperties = isModification - ? { - getDeletionMark, - deleteCallback, - watchProps, - } - : {}; - - const additionalProps = ( - - ); - - return ( - - - {additionalProps} - - ); -}; - -export default PropertiesForm; diff --git a/src/components/dialogs/network-modifications/common/properties/property-form.tsx b/src/components/dialogs/network-modifications/common/properties/property-form.tsx deleted file mode 100644 index 8d517208a6..0000000000 --- a/src/components/dialogs/network-modifications/common/properties/property-form.tsx +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (c) 2023, 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 { useMemo } from 'react'; -import { AutocompleteInput } from '@gridsuite/commons-ui'; -import { NAME, VALUE, PREVIOUS_VALUE, DELETION_MARK, ADDED } from 'components/utils/field-constants'; -import { useWatch } from 'react-hook-form'; -import { TextInput } from '@gridsuite/commons-ui'; -import { PredefinedProperties } from './property-utils'; -import { italicFontTextField } from '../../../dialog-utils'; -import GridItem from '../../../commons/grid-item'; - -type PropertyFormProps = { - name: string; - index: string; - predefinedProperties: PredefinedProperties; -}; - -const PropertyForm = ({ name, index, predefinedProperties }: PropertyFormProps) => { - const watchPropertyName = useWatch({ name: `${name}.${index}.${NAME}` }); - const watchPropertyPreviousValue = useWatch({ - name: `${name}.${index}.${PREVIOUS_VALUE}`, - }); - const watchPropertyDeletionMark = useWatch({ - name: `${name}.${index}.${DELETION_MARK}`, - }); - const watchPropertyAdded = useWatch({ - name: `${name}.${index}.${ADDED}`, - }); - - const predefinedNames = useMemo(() => { - return Object.keys(predefinedProperties ?? {}).sort(); - }, [predefinedProperties]); - - const predefinedValues = useMemo(() => { - return predefinedProperties?.[watchPropertyName]?.sort() ?? []; - }, [watchPropertyName, predefinedProperties]); - - const nameField = ( - - ); - - const nameReadOnlyField = ( - - ); - - const valueField = ( - - ); - - const valueReadOnlyField = ( - - ); - - function renderPropertyLine() { - return ( - <> - {watchPropertyDeletionMark || (watchPropertyAdded === false && watchPropertyPreviousValue) ? ( - {nameReadOnlyField} - ) : ( - {nameField} - )} - {watchPropertyDeletionMark ? ( - {valueReadOnlyField} - ) : ( - {valueField} - )} - - ); - } - - return renderPropertyLine(); -}; - -export default PropertyForm; diff --git a/src/components/dialogs/network-modifications/common/properties/property-utils.ts b/src/components/dialogs/network-modifications/common/properties/property-utils.ts deleted file mode 100644 index c2202aa856..0000000000 --- a/src/components/dialogs/network-modifications/common/properties/property-utils.ts +++ /dev/null @@ -1,203 +0,0 @@ -/** - * Copyright (c) 2024, 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 yup from 'components/utils/yup-config'; -import { - ADDED, - ADDITIONAL_PROPERTIES, - DELETION_MARK, - NAME, - PREVIOUS_VALUE, - VALUE, -} from 'components/utils/field-constants'; -import { isBlankOrEmpty } from 'components/utils/validation-functions'; -import { fetchStudyMetadata } from '@gridsuite/commons-ui'; - -export type Property = { - [NAME]: string; - [VALUE]?: string | null; - [PREVIOUS_VALUE]?: string | null; - [DELETION_MARK]: boolean; - [ADDED]: boolean; -}; - -export type Properties = { - [ADDITIONAL_PROPERTIES]?: Property[]; -}; - -export type PredefinedProperties = { - [propertyName: string]: string[]; -}; - -export type Equipment = { - properties?: Record; -}; - -export const fetchPredefinedProperties = (networkElementType: string): Promise => { - return fetchStudyMetadata().then((studyMetadata) => { - return studyMetadata.predefinedEquipmentProperties?.[networkElementType]; - }); -}; - -export const emptyProperties: Properties = { - [ADDITIONAL_PROPERTIES]: [] as Property[], -}; - -export const createPropertyModification = (name: string, value: string | null): Property => { - return { - [NAME]: name, - [VALUE]: value, - [PREVIOUS_VALUE]: value, - [DELETION_MARK]: false, - [ADDED]: true, - }; -}; - -export const initializedProperty = (): Property => { - return createPropertyModification('', null); -}; - -export const getPropertiesFromModification = (properties: Property[] | undefined | null): Properties => { - return { - [ADDITIONAL_PROPERTIES]: properties - ? properties.map((p) => { - return { - [NAME]: p[NAME], - [VALUE]: p[VALUE], - [PREVIOUS_VALUE]: p[PREVIOUS_VALUE], - [ADDED]: p[ADDED], - [DELETION_MARK]: p[DELETION_MARK], - }; - }) - : [], - }; -}; - -export const copyEquipmentPropertiesForCreation = (equipmentInfos: Equipment): Properties => { - return { - [ADDITIONAL_PROPERTIES]: equipmentInfos.properties - ? Object.entries(equipmentInfos.properties).map(([name, value]) => { - return { - [NAME]: name, - [VALUE]: value, - [PREVIOUS_VALUE]: null, - [DELETION_MARK]: false, - [ADDED]: true, - }; - }) - : [], - }; -}; - -export function getConcatenatedProperties(equipment: Equipment, getValues: (name: string) => any, id?: string): any { - // ex: current Array [ {Object { name: "p1", value: "v2", previousValue: undefined, added: true, deletionMark: false } }, {...} ] - - const path = id ? `${id}.${ADDITIONAL_PROPERTIES}` : `${ADDITIONAL_PROPERTIES}`; - const modificationProperties = getValues(path); - return mergeModificationAndEquipmentProperties(modificationProperties, equipment); -} - -/* - We first load modification properties (empty at creation but could be filled later on), then we load properties - already present on the equipment (network). If one of the equipment properties key is present in the modification - we update the previousValue of this one, it means the modification change the network property value. - If not we add it as an unmodified property. We will be able to delete it or modify its value, but not it's name. - */ -export const mergeModificationAndEquipmentProperties = ( - modificationProperties: Property[], - equipment: Equipment -): Property[] => { - const newModificationProperties = new Map(); - for (const property of modificationProperties) { - if (property.name !== null) { - newModificationProperties.set(property.name, property); - } - } - if (equipment.properties !== undefined) { - Object.entries(equipment.properties).forEach(([name, value]) => { - if (name !== null) { - let propertyToAdd; - // If the property is present in the modification and in the equipment - if (newModificationProperties.has(name)) { - const modProperty = newModificationProperties.get(name)!; - propertyToAdd = { - ...modProperty, - previousValue: value, // We set previous value of the modification to the equipment value - }; - } else { - propertyToAdd = { - [NAME]: name, - [VALUE]: null, - [PREVIOUS_VALUE]: value, - [DELETION_MARK]: false, - [ADDED]: false, - }; - } - newModificationProperties.set(name, propertyToAdd); - } - }); - } - return Array.from(newModificationProperties.values()); -}; - -export const toModificationProperties = (properties: Properties) => { - const filteredProperties = properties[ADDITIONAL_PROPERTIES]?.filter( - (p: Property) => !isBlankOrEmpty(p.value) || p[DELETION_MARK] - ); - return filteredProperties === undefined || filteredProperties?.length === 0 ? null : filteredProperties; -}; - -export const creationPropertiesSchema = yup.object({ - [ADDITIONAL_PROPERTIES]: yup - .array() - .of( - yup.object().shape({ - [NAME]: yup.string().required(), - [VALUE]: yup.string().required(), - [PREVIOUS_VALUE]: yup.string().nullable(), - [DELETION_MARK]: yup.boolean().required(), - [ADDED]: yup.boolean().required(), - }) - ) - .test('checkUniqueProperties', 'DuplicatedPropsError', (values) => checkUniquePropertyNames(values)), -}); - -export const modificationPropertiesSchema = yup.object({ - [ADDITIONAL_PROPERTIES]: yup - .array() - .of( - yup.object().shape({ - [NAME]: yup.string().required(), - [VALUE]: yup - .string() - .nullable() - .when([ADDED], { - is: (added: boolean) => added, - then: (schema) => schema.required(), - }), - [PREVIOUS_VALUE]: yup.string().nullable(), - [DELETION_MARK]: yup.boolean().required(), - [ADDED]: yup.boolean().required(), - }) - ) - .test('checkUniqueProperties', 'DuplicatedPropsError', (values) => checkUniquePropertyNames(values)), -}); - -const checkUniquePropertyNames = ( - properties: - | { - name: string; - }[] - | undefined -) => { - if (properties === undefined) { - return true; - } - const validValues = properties.filter((v) => v.name); - return validValues.length === new Set(validValues.map((v) => v.name)).size; -}; -export const getPropertyValue = (properties: Record | undefined, keyName: string): string | undefined => - properties?.[keyName]; diff --git a/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-dialog.tsx b/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-dialog.tsx index f58b9a1e4f..5170758ae3 100644 --- a/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-dialog.tsx +++ b/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-dialog.tsx @@ -22,6 +22,7 @@ import { Option, snackWithFallback, useSnackMessage, + DeepNullable, } from '@gridsuite/commons-ui'; import yup from '../../../../utils/yup-config'; import { fetchBusesOrBusbarSectionsForVoltageLevel } from '../../../../../services/study/network'; @@ -29,7 +30,6 @@ import CreateCouplingDeviceForm from './create-coupling-device-form'; import { isNodeBuilt } from '../../../../graph/util/model-functions'; import { EquipmentModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; import { CreateCouplingDeviceInfos } from '../../../../../services/network-modification-types'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { CreateCouplingDeviceDialogSchemaForm } from '../coupling-device-dialog.type'; const emptyFormData = { diff --git a/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-form.tsx b/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-form.tsx index f21fe38e17..e4a3281fea 100644 --- a/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-form.tsx +++ b/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-form.tsx @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { AutocompleteInput, Option } from '@gridsuite/commons-ui'; +import { AutocompleteInput, filledTextField, Option } from '@gridsuite/commons-ui'; import { BUS_BAR_SECTION_ID1, BUS_BAR_SECTION_ID2 } from 'components/utils/field-constants'; import GridItem from '../../../commons/grid-item'; import { getObjectId } from '../../../../utils/utils'; @@ -15,7 +15,6 @@ import PositionDiagramPane from '../../../../grid-layout/cards/diagrams/singleLi import { useCallback, useState } from 'react'; import Button from '@mui/material/Button'; import { FormattedMessage, useIntl } from 'react-intl'; -import { filledTextField } from '../../../dialog-utils'; import GridSection from '../../../commons/grid-section'; import type { UUID } from 'node:crypto'; import { isNodeBuilt } from '../../../../graph/util/model-functions'; diff --git a/src/components/dialogs/network-modifications/delete-attaching-line/delete-attaching-line-dialog.tsx b/src/components/dialogs/network-modifications/delete-attaching-line/delete-attaching-line-dialog.tsx index d238238d4b..9ce407ff25 100644 --- a/src/components/dialogs/network-modifications/delete-attaching-line/delete-attaching-line-dialog.tsx +++ b/src/components/dialogs/network-modifications/delete-attaching-line/delete-attaching-line-dialog.tsx @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { CustomFormProvider, sanitizeString, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { FORM_LOADING_DELAY } from 'components/network/constants'; import { @@ -17,7 +17,6 @@ import { } from 'components/utils/field-constants'; import { useCallback, useEffect } from 'react'; import { useForm } from 'react-hook-form'; -import { sanitizeString } from '../../dialog-utils'; import yup from 'components/utils/yup-config'; import { ModificationDialog } from '../../commons/modificationDialog'; import DeleteAttachingLineForm from './delete-attaching-line-form'; diff --git a/src/components/dialogs/network-modifications/delete-voltage-level-on-line/delete-voltage-level-on-line-dialog.tsx b/src/components/dialogs/network-modifications/delete-voltage-level-on-line/delete-voltage-level-on-line-dialog.tsx index acb1ef10bf..1782eea828 100644 --- a/src/components/dialogs/network-modifications/delete-voltage-level-on-line/delete-voltage-level-on-line-dialog.tsx +++ b/src/components/dialogs/network-modifications/delete-voltage-level-on-line/delete-voltage-level-on-line-dialog.tsx @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { CustomFormProvider, sanitizeString, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form'; import { FORM_LOADING_DELAY } from 'components/network/constants'; @@ -17,7 +17,6 @@ import { } from 'components/utils/field-constants'; import { useCallback, useEffect } from 'react'; import { useForm } from 'react-hook-form'; -import { sanitizeString } from '../../dialog-utils'; import yup from 'components/utils/yup-config'; import { ModificationDialog } from '../../commons/modificationDialog'; import DeleteVoltageLevelOnLineForm from './delete-voltage-level-on-line-form'; diff --git a/src/components/dialogs/network-modifications/equipment-deletion/equipment-deletion-form.jsx b/src/components/dialogs/network-modifications/equipment-deletion/equipment-deletion-form.jsx index 56cb62b07e..afda383e05 100644 --- a/src/components/dialogs/network-modifications/equipment-deletion/equipment-deletion-form.jsx +++ b/src/components/dialogs/network-modifications/equipment-deletion/equipment-deletion-form.jsx @@ -8,8 +8,7 @@ import { Grid } from '@mui/material'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useFormContext, useWatch } from 'react-hook-form'; -import { useSnackMessage, AutocompleteInput, snackWithFallback } from '@gridsuite/commons-ui'; -import { filledTextField } from 'components/dialogs/dialog-utils'; +import { useSnackMessage, AutocompleteInput, snackWithFallback, filledTextField } from '@gridsuite/commons-ui'; import { DELETION_SPECIFIC_DATA, EQUIPMENT_ID, diff --git a/src/components/dialogs/network-modifications/generation-dispatch/generation-dispatch-dialog.tsx b/src/components/dialogs/network-modifications/generation-dispatch/generation-dispatch-dialog.tsx index 8101c85b3b..d5ca16a070 100644 --- a/src/components/dialogs/network-modifications/generation-dispatch/generation-dispatch-dialog.tsx +++ b/src/components/dialogs/network-modifications/generation-dispatch/generation-dispatch-dialog.tsx @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { CustomFormProvider, snackWithFallback, useSnackMessage, DeepNullable } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { FORM_LOADING_DELAY } from 'components/network/constants'; import { @@ -32,7 +32,6 @@ import { addSelectedFieldToRows } from 'components/utils/utils'; import { CurrentTreeNode } from '../../../graph/tree-node.type'; import { UUID } from 'node:crypto'; import { FetchStatus } from 'services/utils.type'; -import { DeepNullable } from '../../../utils/ts-utils'; import { GenerationDispatchModificationInfos } from '../../../../services/network-modification-types'; interface GenerationDispatchProps { diff --git a/src/components/dialogs/network-modifications/generation-dispatch/generation-dispatch-form.tsx b/src/components/dialogs/network-modifications/generation-dispatch/generation-dispatch-form.tsx index 2510f12d4f..7986ba660f 100644 --- a/src/components/dialogs/network-modifications/generation-dispatch/generation-dispatch-form.tsx +++ b/src/components/dialogs/network-modifications/generation-dispatch/generation-dispatch-form.tsx @@ -6,14 +6,20 @@ */ import { EQUIPMENT_TYPES } from 'components/utils/equipment-types'; -import { DirectoryItemsInput, ElementType, EquipmentType, FieldLabel, FloatInput } from '@gridsuite/commons-ui'; +import { + DirectoryItemsInput, + ElementType, + EquipmentType, + FieldLabel, + FloatInput, + PercentageAdornment, +} from '@gridsuite/commons-ui'; import { DEFAULT_OUTAGE_RATE, GENERATORS_WITH_FIXED_ACTIVE_POWER, GENERATORS_WITHOUT_OUTAGE, LOSS_COEFFICIENT, } from 'components/utils/field-constants'; -import { percentageTextField } from '../../dialog-utils'; import { Box, Grid, Typography } from '@mui/material'; import FrequencyReservePane from './frequency-reserve-pane'; import SubstationsGeneratorsOrderingPane from './substations-generators-ordering-pane'; @@ -55,7 +61,7 @@ const GenerationDispatchForm = ({ }, [studyUuid, currentNodeUuid, currentRootNetworkUuid]); const lossCoefficientField = ( - + ); const generatorsWithFixedActivePowerField = ( @@ -83,7 +89,7 @@ const GenerationDispatchForm = ({ - + ); diff --git a/src/components/dialogs/network-modifications/generator-scaling/generator-scaling-form.tsx b/src/components/dialogs/network-modifications/generator-scaling/generator-scaling-form.tsx index 43cd02661b..444e9f4fc8 100644 --- a/src/components/dialogs/network-modifications/generator-scaling/generator-scaling-form.tsx +++ b/src/components/dialogs/network-modifications/generator-scaling/generator-scaling-form.tsx @@ -5,11 +5,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { RadioInput } from '@gridsuite/commons-ui'; +import { ExpandableInput, RadioInput } from '@gridsuite/commons-ui'; import { VARIATION_MODES, VARIATION_TYPES } from 'components/network/constants'; import { VARIATION_TYPE, VARIATIONS } from 'components/utils/field-constants'; import VariationForm from './variation/variation-form'; -import { ExpandableInput } from 'components/utils/rhf-inputs/expandable-input'; import { Grid, Theme } from '@mui/material'; import { getVariationEmptyForm } from './variation/variation-utils'; import GridItem from '../../commons/grid-item'; diff --git a/src/components/dialogs/network-modifications/generator-scaling/variation/variation-form.tsx b/src/components/dialogs/network-modifications/generator-scaling/variation/variation-form.tsx index dc3ca435c6..56c7370af7 100644 --- a/src/components/dialogs/network-modifications/generator-scaling/variation/variation-form.tsx +++ b/src/components/dialogs/network-modifications/generator-scaling/variation/variation-form.tsx @@ -14,6 +14,7 @@ import { useSnackMessage, FloatInput, SelectInput, + ActivePowerAdornment, } from '@gridsuite/commons-ui'; import { FILTERS, @@ -28,7 +29,6 @@ import { EQUIPMENT_TYPES } from 'components/utils/equipment-types'; import { useCallback, useEffect, useMemo } from 'react'; import { useFormContext, useWatch } from 'react-hook-form'; import { VARIATION_MODES, VARIATION_TYPES } from 'components/network/constants'; -import { ActivePowerAdornment } from '../../../dialog-utils'; import { IDENTIFIER_LIST } from './variation-utils'; import GridItem from '../../../commons/grid-item'; import { ItemFilterType, VariationType } from '../../../../../services/network-modification-types'; diff --git a/src/components/dialogs/network-modifications/generator/creation/generator-creation-dialog.tsx b/src/components/dialogs/network-modifications/generator/creation/generator-creation-dialog.tsx index 415961f7b4..3fc5f63175 100644 --- a/src/components/dialogs/network-modifications/generator/creation/generator-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/generator/creation/generator-creation-dialog.tsx @@ -11,11 +11,18 @@ import EquipmentSearchDialog from '../../../equipment-search-dialog'; import { useCallback, useEffect } from 'react'; import { useFormSearchCopy } from '../../../commons/use-form-search-copy'; import { + copyEquipmentPropertiesForCreation, + creationPropertiesSchema, CustomFormProvider, + emptyProperties, EquipmentType, + getPropertiesFromModification, MODIFICATION_TYPES, snackWithFallback, + toModificationProperties, useSnackMessage, + DeepNullable, + sanitizeString, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; @@ -59,7 +66,6 @@ import { } from '../../../connectivity/connectivity-form-utils'; import GeneratorCreationForm from './generator-creation-form'; import { getRegulatingTerminalFormData } from '../../../regulating-terminal/regulating-terminal-form-utils'; -import { sanitizeString } from '../../../dialog-utils'; import { FORM_LOADING_DELAY, REGULATION_TYPES, UNDEFINED_CONNECTION_DIRECTION } from 'components/network/constants'; import { getReactiveLimitsEmptyFormData, @@ -69,13 +75,6 @@ import { import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form'; import { createGenerator } from '../../../../../services/study/network-modifications'; import { FetchStatus } from '../../../../../services/utils.type'; -import { - copyEquipmentPropertiesForCreation, - creationPropertiesSchema, - emptyProperties, - getPropertiesFromModification, - toModificationProperties, -} from '../../common/properties/property-utils'; import { getVoltageRegulationEmptyFormData, getVoltageRegulationSchema, @@ -85,7 +84,6 @@ import { getActivePowerControlSchema, } from '../../../active-power-control/active-power-control-utils'; import { GeneratorCreationInfos } from '../../../../../services/network-modification-types'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { GeneratorCreationDialogSchemaForm, GeneratorFormInfos } from '../generator-dialog.type'; import { getSetPointsEmptyFormData, getSetPointsSchema } from '../../../set-points/set-points-utils'; import { NetworkModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; diff --git a/src/components/dialogs/network-modifications/generator/creation/generator-creation-form.tsx b/src/components/dialogs/network-modifications/generator/creation/generator-creation-form.tsx index 3f2037f5e1..73948e1e18 100644 --- a/src/components/dialogs/network-modifications/generator/creation/generator-creation-form.tsx +++ b/src/components/dialogs/network-modifications/generator/creation/generator-creation-form.tsx @@ -5,7 +5,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { FloatInput, SelectInput, SwitchInput, TextInput } from '@gridsuite/commons-ui'; +import { + ActivePowerAdornment, + filledTextField, + FloatInput, + italicFontTextField, + MVAPowerAdornment, + PropertiesForm, + SelectInput, + SwitchInput, + TextInput, +} from '@gridsuite/commons-ui'; import { ENERGY_SOURCE, EQUIPMENT_ID, @@ -19,13 +29,11 @@ import { RATED_NOMINAL_POWER, VOLTAGE_REGULATION, } from 'components/utils/field-constants'; -import { ActivePowerAdornment, filledTextField, italicFontTextField, MVAPowerAdornment } from '../../../dialog-utils'; import { ENERGY_SOURCES } from 'components/network/constants'; import { Box, Grid } from '@mui/material'; import { ConnectivityForm } from '../../../connectivity/connectivity-form'; import { ReactiveLimitsForm } from '../../../reactive-limits/reactive-limits-form'; import { SetPointsForm } from '../../../set-points/set-points-form'; -import PropertiesForm from '../../common/properties/properties-form'; import useVoltageLevelsListInfos from '../../../../../hooks/use-voltage-levels-list-infos'; import GridItem from '../../../commons/grid-item'; import GridSection from '../../../commons/grid-section'; diff --git a/src/components/dialogs/network-modifications/generator/generator-dialog.type.ts b/src/components/dialogs/network-modifications/generator/generator-dialog.type.ts index 76a1b62751..bc586d3632 100644 --- a/src/components/dialogs/network-modifications/generator/generator-dialog.type.ts +++ b/src/components/dialogs/network-modifications/generator/generator-dialog.type.ts @@ -7,7 +7,6 @@ import { ACTIVE_POWER_SET_POINT, - ADDITIONAL_PROPERTIES, BUS_OR_BUSBAR_SECTION, CONNECTED, CONNECTION_DIRECTION, @@ -47,7 +46,6 @@ import { VOLTAGE_REGULATION_TYPE, VOLTAGE_SET_POINT, } from '../../../utils/field-constants'; -import { Property } from '../common/properties/property-utils'; import { ConnectablePositionFormInfos } from '../../connectivity/connectivity.type'; import { MinMaxReactiveLimitsFormInfos, @@ -55,6 +53,7 @@ import { } from '../../reactive-limits/reactive-limits.type'; import { ActivePowerControlInfos } from '../../active-power-control/active-power-control.type'; import { ShortCircuitFormInfos } from '../../short-circuit/short-circuit-utils'; +import { FieldConstants, Property } from '@gridsuite/commons-ui'; export type GeneratorDialogSchemaBaseForm = { [EQUIPMENT_NAME]?: string; @@ -107,7 +106,7 @@ export type GeneratorDialogSchemaBaseForm = { [REACTIVE_CAPABILITY_CURVE_TABLE]?: ReactiveCapabilityCurvePoints[]; }; // Properties - [ADDITIONAL_PROPERTIES]?: Property[]; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Property[]; }; export type GeneratorCreationDialogSchemaForm = { [EQUIPMENT_ID]: string } & GeneratorDialogSchemaBaseForm; diff --git a/src/components/dialogs/network-modifications/generator/modification/generator-modification-dialog.tsx b/src/components/dialogs/network-modifications/generator/modification/generator-modification-dialog.tsx index e5c57a7ff7..76d0603946 100644 --- a/src/components/dialogs/network-modifications/generator/modification/generator-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/generator/modification/generator-modification-dialog.tsx @@ -9,16 +9,23 @@ import { ModificationDialog } from '../../../commons/modificationDialog'; import { useCallback, useEffect, useState } from 'react'; import { CustomFormProvider, + emptyProperties, EquipmentType, + getConcatenatedProperties, + getPropertiesFromModification, MODIFICATION_TYPES, + modificationPropertiesSchema, snackWithFallback, + toModificationProperties, useSnackMessage, + DeepNullable, + sanitizeString, + FieldConstants, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; import { ACTIVE_POWER_SET_POINT, - ADDITIONAL_PROPERTIES, BUS_OR_BUSBAR_SECTION, CONNECTED, CONNECTION_DIRECTION, @@ -55,7 +62,6 @@ import { VOLTAGE_REGULATION_TYPE, VOLTAGE_SET_POINT, } from 'components/utils/field-constants'; -import { sanitizeString } from '../../../dialog-utils'; import GeneratorModificationForm from './generator-modification-form'; import { getSetPointsEmptyFormData, getSetPointsSchema } from '../../../set-points/set-points-utils'; import { @@ -74,13 +80,6 @@ import { EquipmentIdSelector } from '../../../equipment-id/equipment-id-selector import { modifyGenerator } from '../../../../../services/study/network-modifications'; import { fetchNetworkElementInfos } from '../../../../../services/study/network'; import { FetchStatus } from '../../../../../services/utils.type'; -import { - emptyProperties, - getConcatenatedProperties, - getPropertiesFromModification, - modificationPropertiesSchema, - toModificationProperties, -} from '../../common/properties/property-utils'; import { getConnectivityFormData, getConnectivityWithPositionEmptyFormData, @@ -96,7 +95,6 @@ import { getActivePowerControlSchema, } from '../../../active-power-control/active-power-control-utils'; import { GeneratorModificationInfos } from '../../../../../services/network-modification-types'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { GeneratorFormInfos, GeneratorModificationDialogSchemaForm } from '../generator-dialog.type'; import { toModificationOperation } from '../../../../utils/utils'; import { EquipmentModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; @@ -306,7 +304,7 @@ export default function GeneratorModificationDialog({ }, } : {}), - [ADDITIONAL_PROPERTIES]: getConcatenatedProperties(value, getValues), + [FieldConstants.ADDITIONAL_PROPERTIES]: getConcatenatedProperties(value, getValues), }), { keepDirty: true } ); diff --git a/src/components/dialogs/network-modifications/generator/modification/generator-modification-form.tsx b/src/components/dialogs/network-modifications/generator/modification/generator-modification-form.tsx index d19257b225..d80849b464 100644 --- a/src/components/dialogs/network-modifications/generator/modification/generator-modification-form.tsx +++ b/src/components/dialogs/network-modifications/generator/modification/generator-modification-form.tsx @@ -5,7 +5,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { FloatInput, SelectInput, TextInput } from '@gridsuite/commons-ui'; +import { + ActivePowerAdornment, + filledTextField, + FloatInput, + MVAPowerAdornment, + SelectInput, + TextInput, +} from '@gridsuite/commons-ui'; import { ENERGY_SOURCE, EQUIPMENT_NAME, @@ -18,12 +25,11 @@ import { RATED_NOMINAL_POWER, VOLTAGE_REGULATION, } from 'components/utils/field-constants'; -import { ActivePowerAdornment, filledTextField, MVAPowerAdornment } from '../../../dialog-utils'; import { ENERGY_SOURCES, getEnergySourceLabel } from 'components/network/constants'; import { ReactiveLimitsForm } from '../../../reactive-limits/reactive-limits-form'; import { FormattedMessage, useIntl } from 'react-intl'; import { Box, Grid, TextField } from '@mui/material'; -import PropertiesForm from '../../common/properties/properties-form'; +import { PropertiesForm } from '@gridsuite/commons-ui'; import { ConnectivityForm } from '../../../connectivity/connectivity-form'; import useVoltageLevelsListInfos from '../../../../../hooks/use-voltage-levels-list-infos'; import GridItem from '../../../commons/grid-item'; diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-converter-station.tsx b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-converter-station.tsx index a60975f192..7b8858d138 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-converter-station.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-converter-station.tsx @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { FloatInput, TextInput } from '@gridsuite/commons-ui'; +import { FloatInput, PercentageAdornment, TextInput } from '@gridsuite/commons-ui'; import { CONNECTIVITY, CONVERTER_STATION_ID, @@ -13,7 +13,6 @@ import { LOSS_FACTOR, POWER_FACTOR, } from '../../../../../utils/field-constants'; -import { percentageTextField } from '../../../../dialog-utils'; import type { UUID } from 'node:crypto'; import { ConnectivityForm } from '../../../../connectivity/connectivity-form'; import { Grid } from '@mui/material'; @@ -120,7 +119,7 @@ export default function LccConverterStation({ diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-hvdc-line.tsx b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-hvdc-line.tsx index 10cdb034d6..deaaf2ba49 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-hvdc-line.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-hvdc-line.tsx @@ -5,12 +5,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { FloatInput, SelectInput } from '@gridsuite/commons-ui'; +import { + ActivePowerAdornment, + FloatInput, + OhmAdornment, + PropertiesForm, + SelectInput, + VoltageAdornment, +} from '@gridsuite/commons-ui'; import { ACTIVE_POWER_SETPOINT, CONVERTERS_MODE, MAX_P, NOMINAL_V, R } from '../../../../../utils/field-constants'; -import { ActivePowerAdornment, OhmAdornment, VoltageAdornment } from '../../../../dialog-utils'; import { VSC_CONVERTER_MODE, VscConverterMode } from 'components/network/constants'; import { Grid } from '@mui/material'; -import PropertiesForm from 'components/dialogs/network-modifications/common/properties/properties-form'; import GridSection from '../../../../commons/grid-section'; import GridItem from '../../../../commons/grid-item'; import { LccFormInfos } from './lcc-type'; diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-type.ts b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-type.ts index ecd1ab86b1..2982bb6ae2 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-type.ts +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-type.ts @@ -4,12 +4,10 @@ * 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 { Property } from '../../../common/properties/property-utils'; import { EQUIPMENT_TYPES } from '../../../../../utils/equipment-types'; import { ConnectablePositionInfos } from '../../../../connectivity/connectivity.type'; import { ACTIVE_POWER_SETPOINT, - ADDITIONAL_PROPERTIES, CONVERTER_STATION_1, CONVERTER_STATION_2, CONVERTER_STATION_NAME, @@ -24,6 +22,7 @@ import { R, } from '../../../../../utils/field-constants'; import { LccShuntCompensatorInfos } from '../../../../../../services/network-modification-types'; +import { FieldConstants, Property } from '@gridsuite/commons-ui'; export const LccDialogTab = { HVDC_LINE_TAB: 0, @@ -39,7 +38,7 @@ export type LccModificationSchemaForm = { [MAX_P]?: number; [CONVERTERS_MODE]?: string; [ACTIVE_POWER_SETPOINT]?: number; - [ADDITIONAL_PROPERTIES]?: Property[]; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Property[]; }; [CONVERTER_STATION_1]: ConverterStationType; [CONVERTER_STATION_2]: ConverterStationType; diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-utils.ts b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-utils.ts index 657984b44e..ee62a6b2a5 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-utils.ts +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-utils.ts @@ -15,7 +15,6 @@ import { CONVERTER_STATION_ID, CONVERTER_STATION_NAME, CONVERTERS_MODE, - DELETION_MARK, FILTERS_SHUNT_COMPENSATOR_TABLE, ID, LOSS_FACTOR, @@ -46,12 +45,13 @@ import { copyEquipmentPropertiesForCreation, creationPropertiesSchema, emptyProperties, + FieldConstants, getPropertiesFromModification, + MODIFICATION_TYPES, modificationPropertiesSchema, -} from '../../../common/properties/property-utils'; -import { MODIFICATION_TYPES } from '@gridsuite/commons-ui'; + sanitizeString, +} from '@gridsuite/commons-ui'; import { UNDEFINED_CONNECTION_DIRECTION } from '../../../../../network/constants'; -import { sanitizeString } from '../../../../dialog-utils'; import { getConnectivityWithPositionSchema } from 'components/dialogs/connectivity/connectivity-form-utils'; import { Connectivity } from 'components/dialogs/connectivity/connectivity.type'; import { @@ -132,7 +132,7 @@ export const getEmptyShuntCompensatorOnSideFormData = () => ({ export const getEmptyShuntCompensatorOnSideModificationFormData = () => ({ ...getEmptyShuntCompensatorOnSideFormData(), - [DELETION_MARK]: false, + [FieldConstants.DELETION_MARK]: false, }); export const getEmptyFiltersShuntCompensatorModificationTableFormData = (count = 0) => @@ -215,7 +215,7 @@ export const getShuntCompensatorOnSideFormModificationData = ( [SHUNT_COMPENSATOR_NAME]: shuntCp.name ?? '', [MAX_Q_AT_NOMINAL_V]: shuntCp.maxQAtNominalV ?? null, [SHUNT_COMPENSATOR_SELECTED]: shuntCp.connectedToHvdc === undefined ? null : shuntCp.connectedToHvdc, - [DELETION_MARK]: shuntCp.deletionMark ?? false, + [FieldConstants.DELETION_MARK]: shuntCp.deletionMark ?? false, })) ?? [] ); }; @@ -232,7 +232,7 @@ export const getConcatenatedShuntCompensatorOnSideInfos = ( [SHUNT_COMPENSATOR_NAME]: shuntCp.name ?? '', [MAX_Q_AT_NOMINAL_V]: shuntCp.maxQAtNominalV ?? null, [SHUNT_COMPENSATOR_SELECTED]: shuntCp.connectedToHvdc === undefined ? null : shuntCp.connectedToHvdc, - [DELETION_MARK]: shuntCp?.deletionMark ?? false, + [FieldConstants.DELETION_MARK]: shuntCp?.deletionMark ?? false, })) ?? [] ); }; @@ -338,7 +338,7 @@ export const getShuntCompensatorOnSideModificationData = ( name: shuntCp[SHUNT_COMPENSATOR_NAME], maxQAtNominalV: shuntCp[MAX_Q_AT_NOMINAL_V], connectedToHvdc: shuntCp[SHUNT_COMPENSATOR_SELECTED], - deletionMark: shuntCp[DELETION_MARK], + deletionMark: shuntCp[FieldConstants.DELETION_MARK], type: 'LCC_SHUNT_MODIFICATION', })) ?? [] ); diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/filters-shunt-compensator-table.tsx b/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/filters-shunt-compensator-table.tsx index eafd96ab6e..14c07ad26a 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/filters-shunt-compensator-table.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/filters-shunt-compensator-table.tsx @@ -19,8 +19,7 @@ import { SHUNT_COMPENSATOR_NAME, SHUNT_COMPENSATOR_SELECTED, } from '../../../../../utils/field-constants'; -import { FloatInput, SwitchInput, TextInput } from '@gridsuite/commons-ui'; -import { ReactivePowerAdornment } from '../../../../dialog-utils'; +import { FloatInput, ReactivePowerAdornment, SwitchInput, TextInput } from '@gridsuite/commons-ui'; interface FiltersShuntCompensatorTableProps { id: string; diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/lcc-creation-dialog-header.tsx b/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/lcc-creation-dialog-header.tsx index 4e29c3076d..fb719b5f45 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/lcc-creation-dialog-header.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/lcc-creation-dialog-header.tsx @@ -4,11 +4,10 @@ * 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 { TextInput } from '@gridsuite/commons-ui'; +import { filledTextField, TextInput } from '@gridsuite/commons-ui'; import { EQUIPMENT_ID, EQUIPMENT_NAME } from '../../../../../utils/field-constants'; import { Grid } from '@mui/material'; import GridItem from '../../../../commons/grid-item'; -import { filledTextField } from '../../../../dialog-utils'; export default function LccCreationDialogHeader() { const LccIdField = ( diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/lcc-creation-dialog.tsx b/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/lcc-creation-dialog.tsx index 6a7de7bfbb..6a3c518db2 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/lcc-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/lcc-creation-dialog.tsx @@ -6,7 +6,6 @@ */ import { ACTIVE_POWER_SETPOINT, - ADDITIONAL_PROPERTIES, CONNECTIVITY, CONVERTER_STATION_1, CONVERTER_STATION_2, @@ -26,18 +25,25 @@ import { import yup from '../../../../../utils/yup-config'; import { FetchStatus } from '../../../../../../services/utils.type'; import { useForm } from 'react-hook-form'; -import { DeepNullable } from '../../../../../utils/ts-utils'; import { yupResolver } from '@hookform/resolvers/yup'; import { LccDialogTab, LccCreationInfos, LccFormInfos, ShuntCompensatorFormSchema } from '../common/lcc-type'; -import { Property, toModificationProperties } from '../../../common/properties/property-utils'; import { useFormSearchCopy } from '../../../../commons/use-form-search-copy'; -import { CustomFormProvider, ExtendedEquipmentType, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { + CustomFormProvider, + ExtendedEquipmentType, + Property, + snackWithFallback, + toModificationProperties, + useSnackMessage, + DeepNullable, + sanitizeString, + FieldConstants, +} from '@gridsuite/commons-ui'; import { ModificationDialog } from '../../../../commons/modificationDialog'; import EquipmentSearchDialog from '../../../../equipment-search-dialog'; import { useCallback, useEffect, useState } from 'react'; import { FORM_LOADING_DELAY } from '../../../../../network/constants'; import { createLcc } from '../../../../../../services/study/network-modifications'; -import { sanitizeString } from '../../../../dialog-utils'; import { useOpenShortWaitFetching } from '../../../../commons/handle-modification-form'; import { Grid } from '@mui/material'; import LccCreationDialogHeader from './lcc-creation-dialog-header'; @@ -66,7 +72,7 @@ export type LccCreationSchemaForm = { [MAX_P]: number; [CONVERTERS_MODE]: string; [ACTIVE_POWER_SETPOINT]: number; - [ADDITIONAL_PROPERTIES]?: Property[]; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Property[]; }; [CONVERTER_STATION_1]: { [CONVERTER_STATION_ID]: string; diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/modification/filter-shunt-compensator-table-modification.tsx b/src/components/dialogs/network-modifications/hvdc-line/lcc/modification/filter-shunt-compensator-table-modification.tsx index 0474fc1bbd..46d32deaba 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/modification/filter-shunt-compensator-table-modification.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/modification/filter-shunt-compensator-table-modification.tsx @@ -13,7 +13,6 @@ import { ComponentType, useCallback, useMemo, useState } from 'react'; import DeleteIcon from '@mui/icons-material/Delete'; import { useFieldArray, useFormContext, useWatch } from 'react-hook-form'; import { - DELETION_MARK, FILTERS_SHUNT_COMPENSATOR_TABLE, MAX_Q_AT_NOMINAL_V, PREVIOUS_SHUNT_COMPENSATOR_SELECTED, @@ -21,8 +20,7 @@ import { SHUNT_COMPENSATOR_NAME, SHUNT_COMPENSATOR_SELECTED, } from '../../../../../utils/field-constants'; -import { FloatInput, TextInput } from '@gridsuite/commons-ui'; -import { ReactivePowerAdornment } from '../../../../dialog-utils'; +import { FieldConstants, FloatInput, ReactivePowerAdornment, TextInput } from '@gridsuite/commons-ui'; import TextField from '@mui/material/TextField'; import CheckboxNullableInput from '../../../../../utils/rhf-inputs/boolean-nullable-input'; import { LccShuntCompensatorInfos } from '../../../../../../services/network-modification-types'; @@ -141,12 +139,12 @@ function DeletableMarkRow({ id, RowForm, rowFormProps }: Readonly { - const newDeleteMark = !getValues(`${id}.${DELETION_MARK}`); - setValue(`${id}.${DELETION_MARK}`, newDeleteMark, { + const newDeleteMark = !getValues(`${id}.${FieldConstants.DELETION_MARK}`); + setValue(`${id}.${FieldConstants.DELETION_MARK}`, newDeleteMark, { shouldDirty: true, }); }, [getValues, id, setValue]); diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/modification/lcc-modification-dialog.tsx b/src/components/dialogs/network-modifications/hvdc-line/lcc/modification/lcc-modification-dialog.tsx index 6db92efb53..2c6a1b544f 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/modification/lcc-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/modification/lcc-modification-dialog.tsx @@ -7,7 +7,6 @@ import { ACTIVE_POWER_SETPOINT, - ADDITIONAL_PROPERTIES, CONVERTER_STATION_1, CONVERTER_STATION_2, CONVERTERS_MODE, @@ -23,9 +22,14 @@ import yup from '../../../../../utils/yup-config'; import { CustomFormProvider, ExtendedEquipmentType, + getConcatenatedProperties, MODIFICATION_TYPES, snackWithFallback, + toModificationProperties, useSnackMessage, + DeepNullable, + sanitizeString, + FieldConstants, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { LccDialogTab, LccFormInfos, LccModificationSchemaForm } from '../common/lcc-type'; @@ -43,8 +47,6 @@ import { getLccHvdcLineModificationSchema, } from '../common/lcc-utils'; import { modifyLcc } from 'services/study/network-modifications'; -import { sanitizeString } from 'components/dialogs/dialog-utils'; -import { getConcatenatedProperties, toModificationProperties } from '../../../common/properties/property-utils'; import { EquipmentModificationDialogProps } from '../../../../../graph/menus/network-modifications/network-modification-menu.type'; import { isNodeBuilt } from '../../../../../graph/util/model-functions'; import { EquipmentIdSelector } from '../../../../equipment-id/equipment-id-selector'; @@ -55,7 +57,6 @@ import { ModificationDialog } from '../../../../commons/modificationDialog'; import { LccModificationForm } from './lcc-modification-form'; import { toModificationOperation } from '../../../../../utils/utils'; import { LccConverterStationModificationInfos, LccModificationInfos } from 'services/network-modification-types'; -import { DeepNullable } from '../../../../../utils/ts-utils'; import { useFormWithDirtyTracking } from 'components/dialogs/commons/use-form-with-dirty-tracking'; const emptyFormData = { @@ -210,7 +211,7 @@ export const LccModificationDialog = ({ ...formValues, [HVDC_LINE_TAB]: { ...formValues, - [ADDITIONAL_PROPERTIES]: getConcatenatedProperties( + [FieldConstants.ADDITIONAL_PROPERTIES]: getConcatenatedProperties( value, getValues, HVDC_LINE_TAB diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/modification/lcc-modification-form.tsx b/src/components/dialogs/network-modifications/hvdc-line/lcc/modification/lcc-modification-form.tsx index 882fb0a1e8..c03edba338 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/modification/lcc-modification-form.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/modification/lcc-modification-form.tsx @@ -18,8 +18,7 @@ import { Box, Grid, TextField } from '@mui/material'; import LccHvdcLine from '../common/lcc-hvdc-line'; import LccConverterStation from '../common/lcc-converter-station'; import LccTabs from '../common/lcc-tabs'; -import { TextInput } from '@gridsuite/commons-ui'; -import { filledTextField } from '../../../../dialog-utils'; +import { filledTextField, TextInput } from '@gridsuite/commons-ui'; import GridItem from '../../../../commons/grid-item'; interface LccModificationFormProps { diff --git a/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-pane.tsx b/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-pane.tsx index 2af55a6381..a9dbc45e37 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-pane.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-pane.tsx @@ -6,7 +6,14 @@ */ import { FunctionComponent, useEffect } from 'react'; -import { FloatInput, SwitchInput, TextInput } from '@gridsuite/commons-ui'; +import { + FloatInput, + PercentageAdornment, + ReactivePowerAdornment, + SwitchInput, + TextInput, + VoltageAdornment, +} from '@gridsuite/commons-ui'; import { CONNECTIVITY, CONVERTER_STATION_ID, @@ -17,7 +24,6 @@ import { VOLTAGE, VOLTAGE_REGULATION_ON, } from '../../../../../utils/field-constants'; -import { percentageTextField, ReactivePowerAdornment, VoltageAdornment } from '../../../../dialog-utils'; import type { UUID } from 'node:crypto'; import { ConnectivityForm } from '../../../../connectivity/connectivity-form'; import { Grid, TextField } from '@mui/material'; @@ -114,7 +120,7 @@ const ConverterStationPane: FunctionComponent = ({ ); diff --git a/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-utils.tsx b/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-utils.tsx index a61353d085..2f2045c430 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-utils.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-utils.tsx @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { MODIFICATION_TYPES } from '@gridsuite/commons-ui'; +import { MODIFICATION_TYPES, sanitizeString } from '@gridsuite/commons-ui'; import yup from '../../../../../utils/yup-config'; import { BUS_OR_BUSBAR_SECTION, @@ -39,7 +39,6 @@ import { getReactiveLimitsSchema, } from '../../../../reactive-limits/reactive-limits-utils'; import { UNDEFINED_CONNECTION_DIRECTION } from '../../../../../network/constants'; -import { sanitizeString } from '../../../../dialog-utils'; import { toModificationOperation } from '../../../../../utils/utils'; import { VscConverterStationFormInfos, ConverterStationElementModificationInfos } from './converter-station-type'; import { ReactiveCapabilityCurvePoints } from '../../../../reactive-limits/reactive-limits.type'; diff --git a/src/components/dialogs/network-modifications/hvdc-line/vsc/creation/vsc-creation-dialog.tsx b/src/components/dialogs/network-modifications/hvdc-line/vsc/creation/vsc-creation-dialog.tsx index 82d4c31ead..6c6e7ebfd6 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/vsc/creation/vsc-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/vsc/creation/vsc-creation-dialog.tsx @@ -7,12 +7,20 @@ import { useCallback, useEffect, useState } from 'react'; import { + copyEquipmentPropertiesForCreation, + creationPropertiesSchema, CustomFormProvider, + emptyProperties, ExtendedEquipmentType, + getPropertiesFromModification, MODIFICATION_TYPES, snackWithFallback, TextInput, + toModificationProperties, useSnackMessage, + DeepNullable, + filledTextField, + sanitizeString, } from '@gridsuite/commons-ui'; import { FieldErrors, useForm } from 'react-hook-form'; import { yupResolver } from '@hookform/resolvers/yup'; @@ -34,7 +42,6 @@ import { R, } from '../../../../../utils/field-constants'; import { Box, Grid } from '@mui/material'; -import { filledTextField, sanitizeString } from '../../../../dialog-utils'; import VscTabs from '../vsc-tabs'; import yup from 'components/utils/yup-config'; import { FORM_LOADING_DELAY } from '../../../../../network/constants'; @@ -45,18 +52,10 @@ import VscCreationForm from './vsc-creation-form'; import { createVsc } from '../../../../../../services/study/network-modifications'; import { useFormSearchCopy } from '../../../../commons/use-form-search-copy'; import EquipmentSearchDialog from '../../../../equipment-search-dialog'; -import { - copyEquipmentPropertiesForCreation, - creationPropertiesSchema, - emptyProperties, - getPropertiesFromModification, - toModificationProperties, -} from '../../../common/properties/property-utils'; import GridItem from '../../../../commons/grid-item'; import { VSC_CREATION_TABS } from '../vsc-utils'; import { NetworkModificationDialogProps } from '../../../../../graph/menus/network-modifications/network-modification-menu.type'; import { VscCreationInfos } from '../../../../../../services/network-modification-types'; -import { DeepNullable } from '../../../../../utils/ts-utils'; import { VscCreationDialogSchemaForm, VscFormInfos } from '../vsc-dialog.type'; import { getVscHvdcLinePaneEmptyFormData, diff --git a/src/components/dialogs/network-modifications/hvdc-line/vsc/hvdc-line-pane/vsc-hvdc-line-pane.tsx b/src/components/dialogs/network-modifications/hvdc-line/vsc/hvdc-line-pane/vsc-hvdc-line-pane.tsx index 94b0e69dc9..8d7d64f11d 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/vsc/hvdc-line-pane/vsc-hvdc-line-pane.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/vsc/hvdc-line-pane/vsc-hvdc-line-pane.tsx @@ -5,7 +5,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { FloatInput, SelectInput, SwitchInput } from '@gridsuite/commons-ui'; +import { + ActivePowerAdornment, + FloatInput, + OhmAdornment, + PropertiesForm, + SelectInput, + SwitchInput, + VoltageAdornment, +} from '@gridsuite/commons-ui'; import { ACTIVE_POWER_SETPOINT, ANGLE_DROOP_ACTIVE_POWER_CONTROL, @@ -18,7 +26,6 @@ import { P0, R, } from '../../../../../utils/field-constants'; -import { ActivePowerAdornment, OhmAdornment, VoltageAdornment } from '../../../../dialog-utils'; import { VSC_CONVERTER_MODE } from 'components/network/constants'; import { FunctionComponent, useEffect } from 'react'; import { Grid } from '@mui/material'; @@ -26,7 +33,6 @@ import { useFormContext, useWatch } from 'react-hook-form'; import { VscModificationInfo } from 'services/network-modification-types'; import CheckboxNullableInput from '../../../../../utils/rhf-inputs/boolean-nullable-input'; import { useIntl } from 'react-intl'; -import PropertiesForm from 'components/dialogs/network-modifications/common/properties/properties-form'; import GridSection from '../../../../commons/grid-section'; import GridItem from '../../../../commons/grid-item'; diff --git a/src/components/dialogs/network-modifications/hvdc-line/vsc/modification/vsc-modification-dialog.tsx b/src/components/dialogs/network-modifications/hvdc-line/vsc/modification/vsc-modification-dialog.tsx index 7783f00226..7c45e77242 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/vsc/modification/vsc-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/vsc/modification/vsc-modification-dialog.tsx @@ -9,12 +9,10 @@ import { useCallback, useEffect, useState } from 'react'; import { ModificationDialog } from '../../../../commons/modificationDialog'; import { EquipmentIdSelector } from '../../../../equipment-id/equipment-id-selector'; import { EQUIPMENT_INFOS_TYPES } from 'components/utils/equipment-types'; -import { sanitizeString } from '../../../../dialog-utils'; import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; import { ACTIVE_POWER_SETPOINT, - ADDITIONAL_PROPERTIES, ANGLE_DROOP_ACTIVE_POWER_CONTROL, CONVERTER_STATION_1, CONVERTER_STATION_2, @@ -59,14 +57,19 @@ import { setCurrentReactiveCapabilityCurveTable, setSelectedReactiveLimits, } from 'components/dialogs/reactive-limits/reactive-capability-curve/reactive-capability-utils'; -import { CustomFormProvider, ExtendedEquipmentType, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; import { + CustomFormProvider, emptyProperties, + ExtendedEquipmentType, + FieldConstants, getConcatenatedProperties, getPropertiesFromModification, modificationPropertiesSchema, + sanitizeString, + snackWithFallback, toModificationProperties, -} from '../../../common/properties/property-utils'; + useSnackMessage, +} from '@gridsuite/commons-ui'; import { isNodeBuilt } from '../../../../../graph/util/model-functions'; import { ReactiveCapabilityCurvePoints } from '../../../../reactive-limits/reactive-limits.type'; import { useFormWithDirtyTracking } from 'components/dialogs/commons/use-form-with-dirty-tracking'; @@ -219,7 +222,7 @@ const VscModificationDialog: React.FC = ({ reset( (formValues) => ({ ...formValues, - [ADDITIONAL_PROPERTIES]: getConcatenatedProperties(value, getValues), + [FieldConstants.ADDITIONAL_PROPERTIES]: getConcatenatedProperties(value, getValues), }), { keepDirty: true, diff --git a/src/components/dialogs/network-modifications/hvdc-line/vsc/vsc-dialog.type.ts b/src/components/dialogs/network-modifications/hvdc-line/vsc/vsc-dialog.type.ts index e2b37ce269..06bdbf07a8 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/vsc/vsc-dialog.type.ts +++ b/src/components/dialogs/network-modifications/hvdc-line/vsc/vsc-dialog.type.ts @@ -6,7 +6,6 @@ */ import { ACTIVE_POWER_SETPOINT, - ADDITIONAL_PROPERTIES, ANGLE_DROOP_ACTIVE_POWER_CONTROL, CONVERTER_STATION_1, CONVERTER_STATION_2, @@ -22,8 +21,8 @@ import { P0, R, } from '../../../../utils/field-constants'; -import { Property } from '../../common/properties/property-utils'; import { VscConverterStation, VscConverterStationFormInfos } from './converter-station/converter-station-type'; +import { FieldConstants, Property } from '@gridsuite/commons-ui'; export type VscDialogSchemaBaseForm = { [EQUIPMENT_NAME]?: string; @@ -42,7 +41,7 @@ export type VscDialogSchemaBaseForm = { [CONVERTER_STATION_1]: VscConverterStation; [CONVERTER_STATION_2]: VscConverterStation; // Properties - [ADDITIONAL_PROPERTIES]?: Property[]; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Property[]; }; export type VscCreationDialogSchemaForm = { [EQUIPMENT_ID]: string } & VscDialogSchemaBaseForm; diff --git a/src/components/dialogs/network-modifications/line-attach-to-voltage-level/line-attach-to-voltage-level-dialog.tsx b/src/components/dialogs/network-modifications/line-attach-to-voltage-level/line-attach-to-voltage-level-dialog.tsx index 1a790e07ac..9077d13930 100644 --- a/src/components/dialogs/network-modifications/line-attach-to-voltage-level/line-attach-to-voltage-level-dialog.tsx +++ b/src/components/dialogs/network-modifications/line-attach-to-voltage-level/line-attach-to-voltage-level-dialog.tsx @@ -5,7 +5,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, ModificationType, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { + CustomFormProvider, + ModificationType, + snackWithFallback, + useSnackMessage, + DeepNullable, + sanitizeString, +} from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { ATTACHMENT_LINE_ID, @@ -24,7 +31,6 @@ import { } from 'components/utils/field-constants'; import { useCallback, useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; -import { sanitizeString } from '../../dialog-utils'; import yup from 'components/utils/yup-config'; import { ModificationDialog } from '../../commons/modificationDialog'; import { @@ -49,7 +55,6 @@ import { getNewVoltageLevelOptions } from '../../../utils/utils'; import { UUID } from 'node:crypto'; import { CurrentTreeNode } from '../../../graph/tree-node.type'; import { VoltageLevel } from '../../../utils/equipment-types'; -import { DeepNullable } from '../../../utils/ts-utils'; import { FetchStatus } from '../../../../services/utils.type'; import { AttachLineInfo, diff --git a/src/components/dialogs/network-modifications/line-split-with-voltage-level/line-split-with-voltage-level-dialog.tsx b/src/components/dialogs/network-modifications/line-split-with-voltage-level/line-split-with-voltage-level-dialog.tsx index 618cac45c7..632abbd471 100644 --- a/src/components/dialogs/network-modifications/line-split-with-voltage-level/line-split-with-voltage-level-dialog.tsx +++ b/src/components/dialogs/network-modifications/line-split-with-voltage-level/line-split-with-voltage-level-dialog.tsx @@ -5,7 +5,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, MODIFICATION_TYPES, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { + CustomFormProvider, + MODIFICATION_TYPES, + snackWithFallback, + useSnackMessage, + DeepNullable, + sanitizeString, +} from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { BUS_OR_BUSBAR_SECTION, @@ -24,7 +31,6 @@ import { } from 'components/utils/field-constants'; import { useCallback, useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; -import { sanitizeString } from '../../dialog-utils'; import yup from 'components/utils/yup-config'; import { ModificationDialog } from '../../commons/modificationDialog'; import { @@ -49,7 +55,6 @@ import { fetchVoltageLevelsListInfos } from '../../../../services/study/network' import { getNewVoltageLevelOptions } from '../../../utils/utils'; import { UUID } from 'node:crypto'; import { VoltageLevelFormInfos } from '../voltage-level/voltage-level.type'; -import { DeepNullable } from '../../../utils/ts-utils'; import { CurrentTreeNode } from '../../../graph/tree-node.type'; import { VoltageLevelCreationInfo } from '../../../../services/network-modification-types'; import { VoltageLevel } from '../../../utils/equipment-types'; diff --git a/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane.tsx b/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane.tsx index 01da6703e3..c92f097b69 100644 --- a/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane.tsx +++ b/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane.tsx @@ -6,8 +6,14 @@ */ import { Grid } from '@mui/material'; -import { MicroSusceptanceAdornment, OhmAdornment } from '../../../dialog-utils'; -import { convertInputValue, FieldType, FloatInput } from '@gridsuite/commons-ui'; +import { + convertInputValue, + FieldType, + FloatInput, + MicroSusceptanceAdornment, + OhmAdornment, + PropertiesForm, +} from '@gridsuite/commons-ui'; import { ConnectivityForm } from '../../../connectivity/connectivity-form'; import { B1, @@ -20,7 +26,6 @@ import { R, X, } from 'components/utils/field-constants'; -import PropertiesForm from '../../common/properties/properties-form'; import useVoltageLevelsListInfos from '../../../../../hooks/use-voltage-levels-list-infos'; import GridSection from '../../../commons/grid-section'; import GridItem from '../../../commons/grid-item'; diff --git a/src/components/dialogs/network-modifications/line/creation/line-creation-dialog.tsx b/src/components/dialogs/network-modifications/line/creation/line-creation-dialog.tsx index b6a123aa2f..446a0b6cca 100644 --- a/src/components/dialogs/network-modifications/line/creation/line-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/line/creation/line-creation-dialog.tsx @@ -8,12 +8,19 @@ import { convertInputValue, convertOutputValue, + copyEquipmentPropertiesForCreation, + creationPropertiesSchema, CustomFormProvider, + emptyProperties, EquipmentType, FieldType, + filledTextField, + getPropertiesFromModification, ModificationType, + sanitizeString, snackWithFallback, TextInput, + toModificationProperties, useSnackMessage, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; @@ -73,19 +80,11 @@ import { sanitizeLimitsGroups, } from '../../../limits/limits-pane-utils'; import LineDialogTabs from '../line-dialog-tabs'; -import { filledTextField, sanitizeString } from 'components/dialogs/dialog-utils'; import EquipmentSearchDialog from 'components/dialogs/equipment-search-dialog'; import { useFormSearchCopy } from 'components/dialogs/commons/use-form-search-copy'; import LineTypeSegmentDialog from '../../../line-types-catalog/line-type-segment-dialog'; import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form'; import { createLine } from '../../../../../services/study/network-modifications'; -import { - copyEquipmentPropertiesForCreation, - creationPropertiesSchema, - emptyProperties, - getPropertiesFromModification, - toModificationProperties, -} from '../../common/properties/property-utils'; import GridItem from '../../../commons/grid-item'; import { formatCompleteCurrentLimit } from '../../../../utils/utils'; import { LimitsPane } from '../../../limits/limits-pane'; diff --git a/src/components/dialogs/network-modifications/line/creation/line-creation-type.ts b/src/components/dialogs/network-modifications/line/creation/line-creation-type.ts index bc10c6db97..a8fecf1dd1 100644 --- a/src/components/dialogs/network-modifications/line/creation/line-creation-type.ts +++ b/src/components/dialogs/network-modifications/line/creation/line-creation-type.ts @@ -8,7 +8,6 @@ import { ConnectablePositionInfos, Connectivity } from '../../../connectivity/connectivity.type'; import { CurrentLimitsData } from '../../../../../services/study/network-map.type'; import { - ADDITIONAL_PROPERTIES, CHARACTERISTICS, CONNECTIVITY_1, CONNECTIVITY_2, @@ -20,9 +19,9 @@ import { SELECTED_OPERATIONAL_LIMITS_GROUP_ID2, TAB_HEADER, } from '../../../../utils/field-constants'; -import { Property } from '../../common/properties/property-utils'; import { OperationalLimitsGroupFormSchema } from '../../../limits/operational-limits-groups-types'; import { LineCharacteristics } from '../modification/line-modification-type'; +import { FieldConstants, Property } from '@gridsuite/commons-ui'; export interface LineCreationFormSchema { [TAB_HEADER]: { @@ -38,7 +37,7 @@ export interface LineCreationFormSchema { [SELECTED_OPERATIONAL_LIMITS_GROUP_ID1]?: string | null; [SELECTED_OPERATIONAL_LIMITS_GROUP_ID2]?: string | null; }; - [ADDITIONAL_PROPERTIES]?: Property[]; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Property[]; } export interface LineFormInfos { diff --git a/src/components/dialogs/network-modifications/line/modification/line-modification-dialog-header.tsx b/src/components/dialogs/network-modifications/line/modification/line-modification-dialog-header.tsx index 3ce220fa8b..55f19fa507 100644 --- a/src/components/dialogs/network-modifications/line/modification/line-modification-dialog-header.tsx +++ b/src/components/dialogs/network-modifications/line/modification/line-modification-dialog-header.tsx @@ -7,9 +7,8 @@ import { EQUIPMENT_NAME } from 'components/utils/field-constants'; import { Box, Grid, TextField } from '@mui/material'; -import { filledTextField } from 'components/dialogs/dialog-utils'; import LineDialogTabs from '../line-dialog-tabs'; -import { TextInput } from '@gridsuite/commons-ui'; +import { filledTextField, TextInput } from '@gridsuite/commons-ui'; import GridItem from '../../../commons/grid-item'; import { BranchInfos } from '../../../../../services/study/network-map.type'; diff --git a/src/components/dialogs/network-modifications/line/modification/line-modification-dialog.tsx b/src/components/dialogs/network-modifications/line/modification/line-modification-dialog.tsx index b78439be6f..125a5be73f 100644 --- a/src/components/dialogs/network-modifications/line/modification/line-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/line/modification/line-modification-dialog.tsx @@ -10,14 +10,20 @@ import { convertInputValue, convertOutputValue, CustomFormProvider, + emptyProperties, EquipmentType, + FieldConstants, FieldType, + getConcatenatedProperties, + getPropertiesFromModification, + modificationPropertiesSchema, + sanitizeString, snackWithFallback, + toModificationProperties, useSnackMessage, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { - ADDITIONAL_PROPERTIES, B1, B2, BUS_OR_BUSBAR_SECTION, @@ -47,12 +53,10 @@ import { TOTAL_RESISTANCE, TOTAL_SUSCEPTANCE, VALIDITY, - VALUE, VOLTAGE_LEVEL, X, } from 'components/utils/field-constants'; import { FieldErrors } from 'react-hook-form'; -import { sanitizeString } from 'components/dialogs/dialog-utils'; import yup from 'components/utils/yup-config'; import { ModificationDialog } from '../../../commons/modificationDialog'; import { @@ -80,13 +84,6 @@ import { EquipmentIdSelector } from '../../../equipment-id/equipment-id-selector import { modifyLine } from '../../../../../services/study/network-modifications'; import { fetchNetworkElementInfos } from '../../../../../services/study/network'; import { FetchStatus } from '../../../../../services/utils'; -import { - emptyProperties, - getConcatenatedProperties, - getPropertiesFromModification, - modificationPropertiesSchema, - toModificationProperties, -} from '../../common/properties/property-utils'; import { createConnectivityData, getCon1andCon2WithPositionValidationSchema, @@ -276,13 +273,13 @@ const LineModificationDialog = ({ connected1: connectivity1[CONNECTED], connected2: connectivity2[CONNECTED], properties: toModificationProperties(line), - p1MeasurementValue: stateEstimationData[MEASUREMENT_P1][VALUE], + p1MeasurementValue: stateEstimationData[MEASUREMENT_P1][FieldConstants.VALUE], p1MeasurementValidity: stateEstimationData[MEASUREMENT_P1][VALIDITY], - q1MeasurementValue: stateEstimationData[MEASUREMENT_Q1][VALUE], + q1MeasurementValue: stateEstimationData[MEASUREMENT_Q1][FieldConstants.VALUE], q1MeasurementValidity: stateEstimationData[MEASUREMENT_Q1][VALIDITY], - p2MeasurementValue: stateEstimationData[MEASUREMENT_P2][VALUE], + p2MeasurementValue: stateEstimationData[MEASUREMENT_P2][FieldConstants.VALUE], p2MeasurementValidity: stateEstimationData[MEASUREMENT_P2][VALIDITY], - q2MeasurementValue: stateEstimationData[MEASUREMENT_Q2][VALUE], + q2MeasurementValue: stateEstimationData[MEASUREMENT_Q2][FieldConstants.VALUE], q2MeasurementValidity: stateEstimationData[MEASUREMENT_Q2][VALIDITY], }).catch((error) => { snackWithFallback(snackError, error, { headerId: 'LineModificationError' }); @@ -329,7 +326,7 @@ const LineModificationDialog = ({ ), }, }, - [ADDITIONAL_PROPERTIES]: getConcatenatedProperties(line, getValues), + [FieldConstants.ADDITIONAL_PROPERTIES]: getConcatenatedProperties(line, getValues), }), { keepDirty: true } ); diff --git a/src/components/dialogs/network-modifications/line/modification/line-modification-type.ts b/src/components/dialogs/network-modifications/line/modification/line-modification-type.ts index b8f4883b9a..5d9002225d 100644 --- a/src/components/dialogs/network-modifications/line/modification/line-modification-type.ts +++ b/src/components/dialogs/network-modifications/line/modification/line-modification-type.ts @@ -7,7 +7,6 @@ import { OperationalLimitsGroupsFormSchema } from '../../../limits/operational-limits-groups-types'; import { - ADDITIONAL_PROPERTIES, CHARACTERISTICS, CONNECTIVITY, EQUIPMENT_ID, @@ -15,7 +14,7 @@ import { LIMITS, STATE_ESTIMATION, } from '../../../../utils/field-constants'; -import { Property } from '../../common/properties/property-utils'; +import { FieldConstants, Property } from '@gridsuite/commons-ui'; export interface LineCharacteristics { r: number | null; @@ -32,6 +31,6 @@ export interface LineModificationFormSchema { [CONNECTIVITY]: any; [CHARACTERISTICS]: any; [LIMITS]: OperationalLimitsGroupsFormSchema; - [ADDITIONAL_PROPERTIES]?: Property[]; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Property[]; [STATE_ESTIMATION]: any; } diff --git a/src/components/dialogs/network-modifications/lines-attach-to-split-lines/lines-attach-to-split-lines-dialog.tsx b/src/components/dialogs/network-modifications/lines-attach-to-split-lines/lines-attach-to-split-lines-dialog.tsx index 52b40041b5..949b6d9335 100644 --- a/src/components/dialogs/network-modifications/lines-attach-to-split-lines/lines-attach-to-split-lines-dialog.tsx +++ b/src/components/dialogs/network-modifications/lines-attach-to-split-lines/lines-attach-to-split-lines-dialog.tsx @@ -5,9 +5,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { + CustomFormProvider, + snackWithFallback, + useSnackMessage, + DeepNullable, + sanitizeString, +} from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; -import { sanitizeString } from 'components/dialogs/dialog-utils'; import { ATTACHED_LINE_ID, BUS_BAR_SECTION_ID, @@ -41,7 +46,6 @@ import { FetchStatus } from 'services/utils.type'; import LineAttachToSplitLinesIllustration from './lines-attach-to-split-lines-illustration'; import type { CurrentTreeNode } from '../../../graph/tree-node.type'; import { UUID } from 'node:crypto'; -import { DeepNullable } from '../../../utils/ts-utils'; import { LinesAttachToSplitLinesInfo } from '../../../../services/network-modification-types'; interface LinesAttachToSplitLinesProps { diff --git a/src/components/dialogs/network-modifications/load-scaling/load-scaling-form.tsx b/src/components/dialogs/network-modifications/load-scaling/load-scaling-form.tsx index 9ee107e7e5..9cbde85dcb 100644 --- a/src/components/dialogs/network-modifications/load-scaling/load-scaling-form.tsx +++ b/src/components/dialogs/network-modifications/load-scaling/load-scaling-form.tsx @@ -5,11 +5,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { RadioInput } from '@gridsuite/commons-ui'; +import { ExpandableInput, RadioInput } from '@gridsuite/commons-ui'; import { ACTIVE_VARIATION_MODES, VARIATION_TYPES } from 'components/network/constants'; import { VARIATION_TYPE, VARIATIONS } from 'components/utils/field-constants'; import VariationForm from './variation/variation-form'; -import { ExpandableInput } from 'components/utils/rhf-inputs/expandable-input'; import { Grid, Theme } from '@mui/material'; import { getVariationEmptyForm } from './variation/variation-utils'; import GridItem from '../../commons/grid-item'; diff --git a/src/components/dialogs/network-modifications/load-scaling/variation/variation-form.tsx b/src/components/dialogs/network-modifications/load-scaling/variation/variation-form.tsx index d3e7dfb8e8..0ab816c47f 100644 --- a/src/components/dialogs/network-modifications/load-scaling/variation/variation-form.tsx +++ b/src/components/dialogs/network-modifications/load-scaling/variation/variation-form.tsx @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { DirectoryItemsInput, SelectInput, FloatInput, ElementType } from '@gridsuite/commons-ui'; +import { DirectoryItemsInput, SelectInput, FloatInput, ElementType, ActivePowerAdornment } from '@gridsuite/commons-ui'; import { FILTERS, REACTIVE_VARIATION_MODE, @@ -17,7 +17,6 @@ import { EQUIPMENT_TYPES } from 'components/utils/equipment-types'; import { useCallback } from 'react'; import { useWatch } from 'react-hook-form'; import { ACTIVE_VARIATION_MODES, REACTIVE_VARIATION_MODES, VARIATION_TYPES } from 'components/network/constants'; -import { ActivePowerAdornment } from '../../../dialog-utils'; import { IDENTIFIER_LIST } from './variation-utils'; import GridItem from '../../../commons/grid-item'; import { ItemFilterType, VariationType } from '../../../../../services/network-modification-types'; diff --git a/src/components/dialogs/network-modifications/load/common/load-dialog-header.tsx b/src/components/dialogs/network-modifications/load/common/load-dialog-header.tsx index 31e3fc79b3..fc0e12082c 100644 --- a/src/components/dialogs/network-modifications/load/common/load-dialog-header.tsx +++ b/src/components/dialogs/network-modifications/load/common/load-dialog-header.tsx @@ -8,9 +8,8 @@ import React from 'react'; import { EQUIPMENT_ID, EQUIPMENT_NAME, LOAD_TYPE } from 'components/utils/field-constants'; import { Box, Grid, TextField } from '@mui/material'; -import { filledTextField } from 'components/dialogs/dialog-utils'; import { getLoadTypeLabel, LOAD_TYPES } from 'components/network/constants'; -import { SelectInput, TextInput } from '@gridsuite/commons-ui'; +import { filledTextField, SelectInput, TextInput } from '@gridsuite/commons-ui'; import GridItem from '../../../commons/grid-item'; import { useIntl } from 'react-intl'; import LoadDialogTabs from './load-dialog-tabs'; diff --git a/src/components/dialogs/network-modifications/load/common/load-dialog-tabs-content.tsx b/src/components/dialogs/network-modifications/load/common/load-dialog-tabs-content.tsx index 4373bce2cf..c5e2cdcbd8 100644 --- a/src/components/dialogs/network-modifications/load/common/load-dialog-tabs-content.tsx +++ b/src/components/dialogs/network-modifications/load/common/load-dialog-tabs-content.tsx @@ -8,7 +8,7 @@ import { Box } from '@mui/material'; import { ConnectivityForm } from 'components/dialogs/connectivity/connectivity-form'; import { SetPointsForm } from 'components/dialogs/set-points/set-points-form'; -import PropertiesForm from '../../common/properties/properties-form'; +import { Identifiable, PropertiesForm } from '@gridsuite/commons-ui'; import { LoadDialogTab } from './load-utils'; import { PowerMeasurementsForm } from '../../common/measurements/power-measurements-form'; import GridSection from 'components/dialogs/commons/grid-section'; @@ -16,7 +16,6 @@ import React from 'react'; import type { UUID } from 'node:crypto'; import { CurrentTreeNode } from 'components/graph/tree-node.type'; import { LoadFormInfos } from './load.type'; -import { Identifiable } from '@gridsuite/commons-ui'; interface LoadDialogTabsContentProps { studyUuid: UUID; diff --git a/src/components/dialogs/network-modifications/load/creation/load-creation-dialog.tsx b/src/components/dialogs/network-modifications/load/creation/load-creation-dialog.tsx index b3df616cac..98a3ebca9e 100644 --- a/src/components/dialogs/network-modifications/load/creation/load-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/load/creation/load-creation-dialog.tsx @@ -5,11 +5,23 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, EquipmentType, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { + copyEquipmentPropertiesForCreation, + creationPropertiesSchema, + CustomFormProvider, + emptyProperties, + EquipmentType, + getPropertiesFromModification, + snackWithFallback, + toModificationProperties, + useSnackMessage, + DeepNullable, + sanitizeString, + FieldConstants, +} from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { ACTIVE_POWER_SETPOINT, - ADDITIONAL_PROPERTIES, CONNECTIVITY, EQUIPMENT_ID, EQUIPMENT_NAME, @@ -18,7 +30,6 @@ import { } from 'components/utils/field-constants'; import { useCallback, useEffect, useState } from 'react'; import { FieldErrors, useForm } from 'react-hook-form'; -import { sanitizeString } from '../../../dialog-utils'; import EquipmentSearchDialog from '../../../equipment-search-dialog'; import { useFormSearchCopy } from '../../../commons/use-form-search-copy'; import { FORM_LOADING_DELAY, UNDEFINED_CONNECTION_DIRECTION, UNDEFINED_LOAD_TYPE } from 'components/network/constants'; @@ -32,14 +43,6 @@ import { import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form'; import { EQUIPMENT_TYPES } from 'components/utils/equipment-types'; import { createLoad } from '../../../../../services/study/network-modifications'; -import { - copyEquipmentPropertiesForCreation, - creationPropertiesSchema, - emptyProperties, - getPropertiesFromModification, - toModificationProperties, -} from '../../common/properties/property-utils'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { LoadCreationInfos, LoadCreationSchemaForm } from './load-creation.type'; import { FetchStatus } from '../../../../../services/utils.type'; import { NetworkModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; @@ -197,7 +200,7 @@ export function LoadCreationDialog({ if ( errors?.[ACTIVE_POWER_SETPOINT] !== undefined || errors?.[REACTIVE_POWER_SET_POINT] !== undefined || - errors?.[ADDITIONAL_PROPERTIES] !== undefined + errors?.[FieldConstants.ADDITIONAL_PROPERTIES] !== undefined ) { tabsInError.push(LoadDialogTab.CHARACTERISTICS_TAB); } diff --git a/src/components/dialogs/network-modifications/load/creation/load-creation.type.ts b/src/components/dialogs/network-modifications/load/creation/load-creation.type.ts index 4632feb51c..bf211ca18d 100644 --- a/src/components/dialogs/network-modifications/load/creation/load-creation.type.ts +++ b/src/components/dialogs/network-modifications/load/creation/load-creation.type.ts @@ -8,7 +8,6 @@ import { EQUIPMENT_TYPES } from '../../../../utils/equipment-types'; import { ACTIVE_POWER_SETPOINT, - ADDITIONAL_PROPERTIES, BUS_OR_BUSBAR_SECTION, CONNECTED, CONNECTION_DIRECTION, @@ -22,7 +21,7 @@ import { REACTIVE_POWER_SET_POINT, VOLTAGE_LEVEL, } from '../../../../utils/field-constants'; -import { Property } from '../../common/properties/property-utils'; +import { FieldConstants, Property } from '@gridsuite/commons-ui'; export type LoadCreationSchemaForm = { [EQUIPMENT_ID]: string; @@ -39,7 +38,7 @@ export type LoadCreationSchemaForm = { [CONNECTED]?: boolean; }; // Properties - [ADDITIONAL_PROPERTIES]?: Property[]; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Property[]; }; export interface LoadCreationInfos { diff --git a/src/components/dialogs/network-modifications/load/modification/load-modification-dialog.tsx b/src/components/dialogs/network-modifications/load/modification/load-modification-dialog.tsx index c7db3be7cf..f5869a223a 100644 --- a/src/components/dialogs/network-modifications/load/modification/load-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/load/modification/load-modification-dialog.tsx @@ -5,13 +5,25 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, EquipmentType, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { + CustomFormProvider, + emptyProperties, + EquipmentType, + getConcatenatedProperties, + getPropertiesFromModification, + modificationPropertiesSchema, + snackWithFallback, + toModificationProperties, + useSnackMessage, + DeepNullable, + sanitizeString, + FieldConstants, +} from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form'; import { FORM_LOADING_DELAY } from 'components/network/constants'; import { ACTIVE_POWER_SETPOINT, - ADDITIONAL_PROPERTIES, BUS_OR_BUSBAR_SECTION, CONNECTED, CONNECTION_DIRECTION, @@ -26,25 +38,16 @@ import { REACTIVE_POWER_SET_POINT, STATE_ESTIMATION, VALIDITY, - VALUE, VOLTAGE_LEVEL, } from 'components/utils/field-constants'; import { useCallback, useEffect, useState } from 'react'; import { FieldErrors } from 'react-hook-form'; -import { sanitizeString } from '../../../dialog-utils'; import yup from 'components/utils/yup-config'; import { ModificationDialog } from '../../../commons/modificationDialog'; import { EquipmentIdSelector } from '../../../equipment-id/equipment-id-selector'; import { EQUIPMENT_INFOS_TYPES } from 'components/utils/equipment-types'; import { modifyLoad } from '../../../../../services/study/network-modifications'; import { FetchStatus } from '../../../../../services/utils'; -import { - emptyProperties, - getConcatenatedProperties, - getPropertiesFromModification, - modificationPropertiesSchema, - toModificationProperties, -} from '../../common/properties/property-utils'; import { fetchNetworkElementInfos } from '../../../../../services/study/network'; import { getConnectivityFormData, @@ -63,7 +66,6 @@ import { LoadModificationInfos, LoadModificationSchemaForm } from './load-modifi import LoadDialogHeader from '../common/load-dialog-header'; import LoadDialogTabsContent from '../common/load-dialog-tabs-content'; import { LoadFormInfos } from '../common/load.type'; -import { DeepNullable } from 'components/utils/ts-utils'; import { getSetPointsEmptyFormData, getSetPointsSchema } from 'components/dialogs/set-points/set-points-utils'; import useVoltageLevelsListInfos from '../../../../../hooks/use-voltage-levels-list-infos'; import { useFormWithDirtyTracking } from 'components/dialogs/commons/use-form-with-dirty-tracking'; @@ -173,7 +175,7 @@ export default function LoadModificationDialog({ reset( (formValues) => ({ ...formValues, - [ADDITIONAL_PROPERTIES]: getConcatenatedProperties(load, getValues), + [FieldConstants.ADDITIONAL_PROPERTIES]: getConcatenatedProperties(load, getValues), }), { keepDirty: true } ); @@ -215,9 +217,9 @@ export default function LoadModificationDialog({ connectionDirection: load[CONNECTIVITY]?.[CONNECTION_DIRECTION], connectionPosition: load[CONNECTIVITY]?.[CONNECTION_POSITION], terminalConnected: load[CONNECTIVITY]?.[CONNECTED], - pMeasurementValue: stateEstimationData?.[MEASUREMENT_P]?.[VALUE], + pMeasurementValue: stateEstimationData?.[MEASUREMENT_P]?.[FieldConstants.VALUE], pMeasurementValidity: stateEstimationData?.[MEASUREMENT_P]?.[VALIDITY], - qMeasurementValue: stateEstimationData?.[MEASUREMENT_Q]?.[VALUE], + qMeasurementValue: stateEstimationData?.[MEASUREMENT_Q]?.[FieldConstants.VALUE], qMeasurementValidity: stateEstimationData?.[MEASUREMENT_Q]?.[VALIDITY], properties: toModificationProperties(load) ?? null, }).catch((error: Error) => { @@ -244,7 +246,7 @@ export default function LoadModificationDialog({ if ( errors?.[ACTIVE_POWER_SETPOINT] !== undefined || errors?.[REACTIVE_POWER_SET_POINT] !== undefined || - errors?.[ADDITIONAL_PROPERTIES] !== undefined + errors?.[FieldConstants.ADDITIONAL_PROPERTIES] !== undefined ) { tabsInError.push(LoadDialogTab.CHARACTERISTICS_TAB); } diff --git a/src/components/dialogs/network-modifications/load/modification/load-modification.type.ts b/src/components/dialogs/network-modifications/load/modification/load-modification.type.ts index 9f37be6946..e31ed43037 100644 --- a/src/components/dialogs/network-modifications/load/modification/load-modification.type.ts +++ b/src/components/dialogs/network-modifications/load/modification/load-modification.type.ts @@ -9,7 +9,6 @@ import { AttributeModification } from 'services/network-modification-types'; import { EQUIPMENT_TYPES } from '../../../../utils/equipment-types'; import { ACTIVE_POWER_SETPOINT, - ADDITIONAL_PROPERTIES, BUS_OR_BUSBAR_SECTION, CONNECTED, CONNECTION_DIRECTION, @@ -26,7 +25,7 @@ import { VOLTAGE_LEVEL, } from '../../../../utils/field-constants'; import { MeasurementInfo } from '../../common/measurements/measurement.type'; -import { Property } from '../../common/properties/property-utils'; +import { FieldConstants, Property } from '@gridsuite/commons-ui'; export type LoadModificationSchemaForm = { [EQUIPMENT_NAME]?: string; @@ -46,7 +45,7 @@ export type LoadModificationSchemaForm = { [MEASUREMENT_Q]?: MeasurementInfo; }; // Properties - [ADDITIONAL_PROPERTIES]?: Property[]; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Property[]; }; export interface LoadModificationInfos { diff --git a/src/components/dialogs/network-modifications/shunt-compensator/characteristics-pane/characteristics-form.tsx b/src/components/dialogs/network-modifications/shunt-compensator/characteristics-pane/characteristics-form.tsx index aefb639aa5..8de12850ad 100644 --- a/src/components/dialogs/network-modifications/shunt-compensator/characteristics-pane/characteristics-form.tsx +++ b/src/components/dialogs/network-modifications/shunt-compensator/characteristics-pane/characteristics-form.tsx @@ -18,8 +18,14 @@ import { } from 'components/utils/field-constants'; import { Box, Grid } from '@mui/material'; import { useFormContext, useWatch } from 'react-hook-form'; -import { FloatInput, IntegerInput, RadioInput, SelectInput } from '@gridsuite/commons-ui'; -import { ReactivePowerAdornment, SusceptanceAdornment } from '../../../dialog-utils'; +import { + FloatInput, + IntegerInput, + RadioInput, + ReactivePowerAdornment, + SelectInput, + SusceptanceAdornment, +} from '@gridsuite/commons-ui'; import { useCallback, useEffect, useMemo } from 'react'; import { useIntl } from 'react-intl'; import { SHUNT_COMPENSATOR_TYPES } from '../../../../network/constants'; diff --git a/src/components/dialogs/network-modifications/shunt-compensator/creation/shunt-compensator-creation-dialog.tsx b/src/components/dialogs/network-modifications/shunt-compensator/creation/shunt-compensator-creation-dialog.tsx index 22f9efda2e..5b05580611 100644 --- a/src/components/dialogs/network-modifications/shunt-compensator/creation/shunt-compensator-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/shunt-compensator/creation/shunt-compensator-creation-dialog.tsx @@ -6,11 +6,18 @@ */ import { + copyEquipmentPropertiesForCreation, + creationPropertiesSchema, CustomFormProvider, + emptyProperties, EquipmentType, + getPropertiesFromModification, MODIFICATION_TYPES, snackWithFallback, + toModificationProperties, useSnackMessage, + DeepNullable, + sanitizeString, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form'; @@ -35,7 +42,6 @@ import { } from 'components/utils/field-constants'; import { useCallback, useEffect } from 'react'; import { useForm } from 'react-hook-form'; -import { sanitizeString } from '../../../dialog-utils'; import EquipmentSearchDialog from '../../../equipment-search-dialog'; import { useFormSearchCopy } from '../../../commons/use-form-search-copy'; import { FORM_LOADING_DELAY, UNDEFINED_CONNECTION_DIRECTION } from 'components/network/constants'; @@ -55,16 +61,8 @@ import { import ShuntCompensatorCreationForm from './shunt-compensator-creation-form'; import { createShuntCompensator } from '../../../../../services/study/network-modifications'; import { FetchStatus } from '../../../../../services/utils'; -import { - copyEquipmentPropertiesForCreation, - creationPropertiesSchema, - emptyProperties, - getPropertiesFromModification, - toModificationProperties, -} from '../../common/properties/property-utils'; import { NetworkModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; import { ShuntCompensatorCreationDialogSchemaForm, ShuntCompensatorFormInfos } from '../shunt-compensator-dialog.type'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { ShuntCompensatorCreationInfos } from '../../../../../services/network-modification-types'; const emptyFormData = { diff --git a/src/components/dialogs/network-modifications/shunt-compensator/creation/shunt-compensator-creation-form.tsx b/src/components/dialogs/network-modifications/shunt-compensator/creation/shunt-compensator-creation-form.tsx index 86b4b65268..464908e452 100644 --- a/src/components/dialogs/network-modifications/shunt-compensator/creation/shunt-compensator-creation-form.tsx +++ b/src/components/dialogs/network-modifications/shunt-compensator/creation/shunt-compensator-creation-form.tsx @@ -8,11 +8,8 @@ import { Grid } from '@mui/material'; import { EQUIPMENT_ID, EQUIPMENT_NAME } from 'components/utils/field-constants'; -import { filledTextField } from '../../../dialog-utils'; - -import { TextInput } from '@gridsuite/commons-ui'; +import { filledTextField, PropertiesForm, TextInput } from '@gridsuite/commons-ui'; import { ConnectivityForm } from '../../../connectivity/connectivity-form'; -import PropertiesForm from '../../common/properties/properties-form'; import GridItem from '../../../commons/grid-item'; import GridSection from '../../../commons/grid-section'; import type { UUID } from 'node:crypto'; diff --git a/src/components/dialogs/network-modifications/shunt-compensator/modification/shunt-compensator-modification-dialog.tsx b/src/components/dialogs/network-modifications/shunt-compensator/modification/shunt-compensator-modification-dialog.tsx index a7aa467f01..d4d30b7cc1 100644 --- a/src/components/dialogs/network-modifications/shunt-compensator/modification/shunt-compensator-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/shunt-compensator/modification/shunt-compensator-modification-dialog.tsx @@ -7,13 +7,20 @@ import { CustomFormProvider, + emptyProperties, EquipmentType, + getConcatenatedProperties, + getPropertiesFromModification, MODIFICATION_TYPES, + modificationPropertiesSchema, snackWithFallback, + toModificationProperties, useSnackMessage, + DeepNullable, + sanitizeString, + FieldConstants, } from '@gridsuite/commons-ui'; import { - ADDITIONAL_PROPERTIES, BUS_OR_BUSBAR_SECTION, CHARACTERISTICS_CHOICE, CHARACTERISTICS_CHOICES, @@ -37,19 +44,11 @@ import { useCallback, useEffect, useState } from 'react'; import { ModificationDialog } from '../../../commons/modificationDialog'; import { useOpenShortWaitFetching } from '../../../commons/handle-modification-form'; import { FORM_LOADING_DELAY } from '../../../../network/constants'; -import { sanitizeString } from '../../../dialog-utils'; import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES } from '../../../../utils/equipment-types'; import { EquipmentIdSelector } from '../../../equipment-id/equipment-id-selector'; import { modifyShuntCompensator } from '../../../../../services/study/network-modifications'; import { fetchNetworkElementInfos } from '../../../../../services/study/network'; import { FetchStatus } from '../../../../../services/utils'; -import { - emptyProperties, - getConcatenatedProperties, - getPropertiesFromModification, - modificationPropertiesSchema, - toModificationProperties, -} from '../../common/properties/property-utils'; import { getConnectivityFormData, getConnectivityWithPositionEmptyFormData, @@ -58,7 +57,6 @@ import { import { useFormWithDirtyTracking } from 'components/dialogs/commons/use-form-with-dirty-tracking'; import { EquipmentModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; import { ShuntCompensatorModificationInfos } from '../../../../../services/network-modification-types'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { ShuntCompensatorModificationDialogSchemaForm } from '../shunt-compensator-dialog.type'; import { getCharacteristicsEmptyFormData, @@ -185,7 +183,10 @@ export default function ShuntCompensatorModificationDialog({ reset( (formValues) => ({ ...formValues, - [ADDITIONAL_PROPERTIES]: getConcatenatedProperties(shuntCompensator, getValues), + [FieldConstants.ADDITIONAL_PROPERTIES]: getConcatenatedProperties( + shuntCompensator, + getValues + ), }), { keepDirty: true } ); diff --git a/src/components/dialogs/network-modifications/shunt-compensator/modification/shunt-compensator-modification-form.tsx b/src/components/dialogs/network-modifications/shunt-compensator/modification/shunt-compensator-modification-form.tsx index a24e3b54e3..513693a1e2 100644 --- a/src/components/dialogs/network-modifications/shunt-compensator/modification/shunt-compensator-modification-form.tsx +++ b/src/components/dialogs/network-modifications/shunt-compensator/modification/shunt-compensator-modification-form.tsx @@ -5,11 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { TextInput } from '@gridsuite/commons-ui'; +import { TextInput, PropertiesForm, filledTextField } from '@gridsuite/commons-ui'; import { EQUIPMENT_NAME } from '../../../../utils/field-constants'; -import { filledTextField } from '../../../dialog-utils'; import { Grid, TextField } from '@mui/material'; -import PropertiesForm from '../../common/properties/properties-form'; import { ConnectivityForm } from '../../../connectivity/connectivity-form'; import GridItem from '../../../commons/grid-item'; import GridSection from '../../../commons/grid-section'; diff --git a/src/components/dialogs/network-modifications/shunt-compensator/shunt-compensator-dialog.type.ts b/src/components/dialogs/network-modifications/shunt-compensator/shunt-compensator-dialog.type.ts index 23d8dd9769..3b05a8d2ea 100644 --- a/src/components/dialogs/network-modifications/shunt-compensator/shunt-compensator-dialog.type.ts +++ b/src/components/dialogs/network-modifications/shunt-compensator/shunt-compensator-dialog.type.ts @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { - ADDITIONAL_PROPERTIES, BUS_OR_BUSBAR_SECTION, CHARACTERISTICS_CHOICE, CONNECTED, @@ -25,8 +24,8 @@ import { SWITCHED_ON_SUSCEPTANCE, VOLTAGE_LEVEL, } from '../../../utils/field-constants'; -import { Property } from '../common/properties/property-utils'; import { ConnectablePositionFormInfos } from '../../connectivity/connectivity.type'; +import { FieldConstants, Property } from '@gridsuite/commons-ui'; export type ShuntCompensatorDialogSchemaBaseForm = { [EQUIPMENT_NAME]?: string; @@ -46,7 +45,7 @@ export type ShuntCompensatorDialogSchemaBaseForm = { [SECTION_COUNT]: number; [SWITCHED_ON_Q_AT_NOMINAL_V]?: number; [SWITCHED_ON_SUSCEPTANCE]?: number; - [ADDITIONAL_PROPERTIES]?: Property[]; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Property[]; }; export type ShuntCompensatorCreationDialogSchemaForm = { [EQUIPMENT_ID]: string; diff --git a/src/components/dialogs/network-modifications/static-var-compensator/creation/set-points-limits-form.tsx b/src/components/dialogs/network-modifications/static-var-compensator/creation/set-points-limits-form.tsx index 3ae450fbd1..7988a18e55 100644 --- a/src/components/dialogs/network-modifications/static-var-compensator/creation/set-points-limits-form.tsx +++ b/src/components/dialogs/network-modifications/static-var-compensator/creation/set-points-limits-form.tsx @@ -20,8 +20,13 @@ import { VOLTAGE_REGULATION_TYPE, VOLTAGE_SET_POINT, } from 'components/utils/field-constants'; -import { FloatInput, SelectInput } from '@gridsuite/commons-ui'; -import { ReactivePowerAdornment, SusceptanceAdornment, VoltageAdornment } from '../../../dialog-utils'; +import { + FloatInput, + ReactivePowerAdornment, + SelectInput, + SusceptanceAdornment, + VoltageAdornment, +} from '@gridsuite/commons-ui'; import { useWatch } from 'react-hook-form'; import { FunctionComponent } from 'react'; import type { UUID } from 'node:crypto'; diff --git a/src/components/dialogs/network-modifications/static-var-compensator/creation/standby-automaton-form.tsx b/src/components/dialogs/network-modifications/static-var-compensator/creation/standby-automaton-form.tsx index 3d22e530e4..98848a2e33 100644 --- a/src/components/dialogs/network-modifications/static-var-compensator/creation/standby-automaton-form.tsx +++ b/src/components/dialogs/network-modifications/static-var-compensator/creation/standby-automaton-form.tsx @@ -17,8 +17,7 @@ import { VOLTAGE_REGULATION_MODE, VOLTAGE_REGULATION_MODES, } from 'components/utils/field-constants'; -import { CheckboxInput, FloatInput, SwitchInput } from '@gridsuite/commons-ui'; -import { VoltageAdornment } from '../../../dialog-utils'; +import { CheckboxInput, FloatInput, SwitchInput, VoltageAdornment } from '@gridsuite/commons-ui'; import { useEffect, useMemo, useState } from 'react'; import { useFormContext, useWatch } from 'react-hook-form'; import { FormattedMessage, useIntl } from 'react-intl'; diff --git a/src/components/dialogs/network-modifications/static-var-compensator/creation/static-var-compensator-creation-dialog.tsx b/src/components/dialogs/network-modifications/static-var-compensator/creation/static-var-compensator-creation-dialog.tsx index cfabee9557..e0b0e0c52a 100644 --- a/src/components/dialogs/network-modifications/static-var-compensator/creation/static-var-compensator-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/static-var-compensator/creation/static-var-compensator-creation-dialog.tsx @@ -5,12 +5,25 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, EquipmentType, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { + copyEquipmentPropertiesForCreation, + creationPropertiesSchema, + CustomFormProvider, + emptyProperties, + EquipmentType, + getPropertiesFromModification, + Property, + snackWithFallback, + toModificationProperties, + useSnackMessage, + DeepNullable, + sanitizeString, + FieldConstants, +} from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form'; import { ADD_STAND_BY_AUTOMATON, - ADDITIONAL_PROPERTIES, AUTOMATON, B0, BUS_OR_BUSBAR_SECTION, @@ -47,7 +60,6 @@ import { import { EQUIPMENT_TYPES } from 'components/utils/equipment-types'; import { FC, useCallback, useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; -import { sanitizeString } from '../../../dialog-utils'; import EquipmentSearchDialog from '../../../equipment-search-dialog'; import { useFormSearchCopy } from '../../../commons/use-form-search-copy'; import { FORM_LOADING_DELAY, REGULATION_TYPES, UNDEFINED_CONNECTION_DIRECTION } from 'components/network/constants'; @@ -60,14 +72,6 @@ import { } from '../../../connectivity/connectivity-form-utils'; import { createStaticVarCompensator } from '../../../../../services/study/network-modifications'; import { FetchStatus } from '../../../../../services/utils'; -import { - copyEquipmentPropertiesForCreation, - creationPropertiesSchema, - emptyProperties, - getPropertiesFromModification, - Property, - toModificationProperties, -} from '../../common/properties/property-utils'; import StaticVarCompensatorCreationDialogTabs from './static-var-compensator-creation-dialog-tabs'; import { Grid } from '@mui/material'; import StaticVarCompensatorCreationForm from './static-var-compensator-creation-form'; @@ -83,7 +87,6 @@ import { getStandbyAutomatonFormData, getStandbyAutomatonFormValidationSchema, } from './standby-automaton-form-utils'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { StaticVarCompensatorCreationDialogTab } from './static-var-compensator-creation-utils'; export type StaticVarCompensatorCreationSchemaForm = { @@ -127,7 +130,7 @@ export type StaticVarCompensatorCreationSchemaForm = { [Q0]?: number; }; // Properties - [ADDITIONAL_PROPERTIES]?: Property[]; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Property[]; }; const emptyFormData = { @@ -410,7 +413,7 @@ const StaticVarCompensatorCreationDialog: FC = ({ if (errors?.[AUTOMATON]) { tabsInError.push(StaticVarCompensatorCreationDialogTab.AUTOMATON_TAB); } - if (errors?.[ADDITIONAL_PROPERTIES]) { + if (errors?.[FieldConstants.ADDITIONAL_PROPERTIES]) { tabsInError.push(StaticVarCompensatorCreationDialogTab.ADDITIONAL_INFO_TAB); } diff --git a/src/components/dialogs/network-modifications/static-var-compensator/creation/static-var-compensator-creation-form.tsx b/src/components/dialogs/network-modifications/static-var-compensator/creation/static-var-compensator-creation-form.tsx index 1186f266f4..1f3690d428 100644 --- a/src/components/dialogs/network-modifications/static-var-compensator/creation/static-var-compensator-creation-form.tsx +++ b/src/components/dialogs/network-modifications/static-var-compensator/creation/static-var-compensator-creation-form.tsx @@ -8,7 +8,7 @@ import { FunctionComponent } from 'react'; import { ConnectivityForm } from '../../../connectivity/connectivity-form'; -import PropertiesForm from '../../common/properties/properties-form'; +import { PropertiesForm } from '@gridsuite/commons-ui'; import { Box, Grid } from '@mui/material'; import { StandbyAutomatonForm } from './standby-automaton-form'; import { SetPointsLimitsForm } from './set-points-limits-form'; diff --git a/src/components/dialogs/network-modifications/static-var-compensator/creation/susceptance-area.tsx b/src/components/dialogs/network-modifications/static-var-compensator/creation/susceptance-area.tsx index 07a16c9223..7905ff6225 100644 --- a/src/components/dialogs/network-modifications/static-var-compensator/creation/susceptance-area.tsx +++ b/src/components/dialogs/network-modifications/static-var-compensator/creation/susceptance-area.tsx @@ -22,8 +22,7 @@ import { Q0, SETPOINTS_LIMITS, } from 'components/utils/field-constants'; -import { FloatInput } from '@gridsuite/commons-ui'; -import { ReactivePowerAdornment, SusceptanceAdornment } from '../../../dialog-utils'; +import { FloatInput, ReactivePowerAdornment, SusceptanceAdornment } from '@gridsuite/commons-ui'; import { useEffect } from 'react'; import { useFormContext, useWatch } from 'react-hook-form'; import { InputAdornment, Grid, TextField } from '@mui/material'; diff --git a/src/components/dialogs/network-modifications/substation/creation/substation-creation-dialog.tsx b/src/components/dialogs/network-modifications/substation/creation/substation-creation-dialog.tsx index ffc22305a2..6ee2d6f866 100644 --- a/src/components/dialogs/network-modifications/substation/creation/substation-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/substation/creation/substation-creation-dialog.tsx @@ -10,67 +10,39 @@ import { ModificationDialog } from '../../../commons/modificationDialog'; import EquipmentSearchDialog from '../../../equipment-search-dialog'; import { useCallback, useEffect } from 'react'; import { + copyEquipmentPropertiesForCreation, CustomFormProvider, EquipmentType, fetchDefaultCountry, snackWithFallback, + SubstationCreationDto, + substationCreationEmptyFormData, + SubstationCreationForm, + SubstationCreationFormData, + substationCreationFormSchema, + toModificationProperties, useSnackMessage, + DeepNullable, + sanitizeString, + substationCreationDtoToForm, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; -import yup from 'components/utils/yup-config'; import { useFormSearchCopy } from '../../../commons/use-form-search-copy'; -import { ADDITIONAL_PROPERTIES, COUNTRY, EQUIPMENT_ID, EQUIPMENT_NAME } from 'components/utils/field-constants'; -import SubstationCreationForm from './substation-creation-form'; -import { sanitizeString } from '../../../dialog-utils'; import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form'; import { FORM_LOADING_DELAY } from 'components/network/constants'; import { createSubstation } from '../../../../../services/study/network-modifications'; import { FetchStatus } from '../../../../../services/utils'; -import { - copyEquipmentPropertiesForCreation, - creationPropertiesSchema, - getPropertiesFromModification, - Property, - toModificationProperties, -} from '../../common/properties/property-utils'; import { UUID } from 'node:crypto'; import { CurrentTreeNode } from '../../../../graph/tree-node.type'; -import { DeepNullable } from 'components/utils/ts-utils'; import { SubstationInfos } from '../substation-dialog.type'; -const formSchema = yup - .object() - .shape({ - [EQUIPMENT_ID]: yup.string().required(), - [EQUIPMENT_NAME]: yup.string().nullable(), - [COUNTRY]: yup.string().nullable(), - }) - .concat(creationPropertiesSchema); - -export type SubstationCreationFormData = yup.InferType; - -const emptyFormData: SubstationCreationFormData = { - [EQUIPMENT_ID]: '', - [EQUIPMENT_NAME]: '', - [COUNTRY]: null, - [ADDITIONAL_PROPERTIES]: [], -}; - -interface SubstationCreationEditData { - uuid?: UUID; - equipmentId: string; - equipmentName?: string; - country: string | null; - properties?: Property[] | null; -} - interface SubstationCreationDialogProps { studyUuid: UUID; currentNode: CurrentTreeNode; currentRootNetworkUuid: UUID; isUpdate: boolean; editDataFetchStatus?: string; - editData?: SubstationCreationEditData; + editData?: SubstationCreationDto & { uuid: UUID }; } /** @@ -96,8 +68,8 @@ const SubstationCreationDialog = ({ const { snackError } = useSnackMessage(); const formMethods = useForm>({ - defaultValues: emptyFormData, - resolver: yupResolver>(formSchema), + defaultValues: substationCreationEmptyFormData, + resolver: yupResolver>(substationCreationFormSchema), }); const { reset, getValues } = formMethods; @@ -105,9 +77,9 @@ const SubstationCreationDialog = ({ const fromSearchCopyToFormValues = (substation: SubstationInfos) => { reset( { - [EQUIPMENT_ID]: substation.id + '(1)', - [EQUIPMENT_NAME]: substation.name ?? '', - [COUNTRY]: substation.country, + equipmentID: substation.id + '(1)', + equipmentName: substation.name ?? '', + country: substation.country, ...copyEquipmentPropertiesForCreation(substation), }, { keepDefaultValues: true } @@ -118,12 +90,7 @@ const SubstationCreationDialog = ({ useEffect(() => { if (editData) { - reset({ - [EQUIPMENT_ID]: editData.equipmentId, - [EQUIPMENT_NAME]: editData.equipmentName ?? '', - [COUNTRY]: editData.country, - ...getPropertiesFromModification(editData.properties), - }); + reset(substationCreationDtoToForm(editData)); } }, [reset, editData]); @@ -134,7 +101,7 @@ const SubstationCreationDialog = ({ if (country) { reset({ ...getValues(), - [COUNTRY]: country, + country, }); } }); @@ -142,7 +109,7 @@ const SubstationCreationDialog = ({ }, [reset, getValues, isUpdate]); const clear = useCallback(() => { - reset(emptyFormData); + reset(); }, [reset]); const onSubmit = useCallback( @@ -150,9 +117,9 @@ const SubstationCreationDialog = ({ createSubstation({ studyUuid: studyUuid, nodeUuid: currentNodeUuid, - substationId: substation[EQUIPMENT_ID], - substationName: sanitizeString(substation[EQUIPMENT_NAME]), - country: substation[COUNTRY] ?? null, + substationId: substation.equipmentID, + substationName: sanitizeString(substation.equipmentName), + country: substation.country ?? null, isUpdate: !!editData, modificationUuid: editData ? editData.uuid : undefined, properties: toModificationProperties(substation), @@ -170,7 +137,7 @@ const SubstationCreationDialog = ({ }); return ( - + { - const substationIdField = ; - - const substationNameField = ; - - const substationCountryField = ( - - ); - - return ( - <> - - {substationIdField} - {substationNameField} - {substationCountryField} - - - - ); -}; - -export default SubstationCreationForm; diff --git a/src/components/dialogs/network-modifications/substation/modification/substation-modification-dialog.tsx b/src/components/dialogs/network-modifications/substation/modification/substation-modification-dialog.tsx index 5e09149392..d3e21e4abf 100644 --- a/src/components/dialogs/network-modifications/substation/modification/substation-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/substation/modification/substation-modification-dialog.tsx @@ -7,12 +7,23 @@ import { ModificationDialog } from '../../../commons/modificationDialog'; import { useCallback, useEffect, useState } from 'react'; -import { CustomFormProvider, EquipmentType, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; +import { + CustomFormProvider, + EquipmentType, + getConcatenatedProperties, + getPropertiesFromModification, + modificationPropertiesSchema, + Property, + snackWithFallback, + toModificationProperties, + useSnackMessage, + DeepNullable, + sanitizeString, + FieldConstants, +} from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; -import { ADDITIONAL_PROPERTIES, COUNTRY, EQUIPMENT_NAME } from 'components/utils/field-constants'; import SubstationModificationForm from './substation-modification-form'; -import { sanitizeString } from '../../../dialog-utils'; import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form'; import { FORM_LOADING_DELAY } from 'components/network/constants'; import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES } from 'components/utils/equipment-types'; @@ -20,35 +31,27 @@ import { EquipmentIdSelector } from '../../../equipment-id/equipment-id-selector import { modifySubstation } from '../../../../../services/study/network-modifications'; import { fetchNetworkElementInfos } from '../../../../../services/study/network'; import { FetchStatus } from '../../../../../services/utils'; -import { - getConcatenatedProperties, - getPropertiesFromModification, - modificationPropertiesSchema, - Property, - toModificationProperties, -} from '../../common/properties/property-utils'; import { isNodeBuilt } from '../../../../graph/util/model-functions'; import { UUID } from 'node:crypto'; import { CurrentTreeNode } from '../../../../graph/tree-node.type'; import { AttributeModification } from 'services/network-modification-types'; import { useForm } from 'react-hook-form'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { SubstationInfos } from '../substation-dialog.type'; const formSchema = yup .object() .shape({ - [EQUIPMENT_NAME]: yup.string().nullable(), - [COUNTRY]: yup.string().nullable(), + [FieldConstants.EQUIPMENT_NAME]: yup.string().nullable(), + [FieldConstants.COUNTRY]: yup.string().nullable(), }) .concat(modificationPropertiesSchema); export type SubstationModificationFormData = yup.InferType; const emptyFormData: SubstationModificationFormData = { - [EQUIPMENT_NAME]: '', - [COUNTRY]: null, - [ADDITIONAL_PROPERTIES]: [], + [FieldConstants.EQUIPMENT_NAME]: '', + [FieldConstants.COUNTRY]: null, + [FieldConstants.ADDITIONAL_PROPERTIES]: [], }; interface SubstationModificationEditData { @@ -108,8 +111,8 @@ const SubstationModificationDialog = ({ setSelectedId(editData.equipmentId); } reset({ - [EQUIPMENT_NAME]: editData.equipmentName?.value ?? '', - [COUNTRY]: editData.country?.value ?? null, + [FieldConstants.EQUIPMENT_NAME]: editData.equipmentName?.value ?? '', + [FieldConstants.COUNTRY]: editData.country?.value ?? null, ...getPropertiesFromModification(editData?.properties ?? undefined), }); } @@ -138,7 +141,10 @@ const SubstationModificationDialog = ({ reset( (formValues) => ({ ...formValues, - [ADDITIONAL_PROPERTIES]: getConcatenatedProperties(substation, getValues), + [FieldConstants.ADDITIONAL_PROPERTIES]: getConcatenatedProperties( + substation, + getValues + ), }), { keepDirty: true } ); @@ -172,8 +178,8 @@ const SubstationModificationDialog = ({ nodeUuid: currentNodeUuid, modificationUuid: editData?.uuid, id: selectedId, - name: sanitizeString(substation[EQUIPMENT_NAME]), - country: substation[COUNTRY] ?? null, + name: sanitizeString(substation[FieldConstants.EQUIPMENT_NAME]), + country: substation[FieldConstants.COUNTRY] ?? null, properties: toModificationProperties(substation), }).catch((error) => { snackWithFallback(snackError, error, { headerId: 'SubstationModificationError' }); diff --git a/src/components/dialogs/network-modifications/substation/modification/substation-modification-form.tsx b/src/components/dialogs/network-modifications/substation/modification/substation-modification-form.tsx index 159f4b4fdc..c9dea88af0 100644 --- a/src/components/dialogs/network-modifications/substation/modification/substation-modification-form.tsx +++ b/src/components/dialogs/network-modifications/substation/modification/substation-modification-form.tsx @@ -5,13 +5,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { filledTextField } from '../../../dialog-utils'; -import { TextInput } from '@gridsuite/commons-ui'; -import { COUNTRY, EQUIPMENT_NAME } from 'components/utils/field-constants'; -import CountrySelectionInput from 'components/utils/rhf-inputs/country-selection-input'; +import { + CountrySelectionInput, + FieldConstants, + filledTextField, + PropertiesForm, + TextInput, +} from '@gridsuite/commons-ui'; import { useLocalizedCountries } from 'components/utils/localized-countries-hook'; -import { TextField, Grid } from '@mui/material'; -import PropertiesForm from '../../common/properties/properties-form'; +import { Grid, TextField } from '@mui/material'; import GridItem from '../../../commons/grid-item'; import { SubstationInfos } from '../substation-dialog.type'; @@ -39,7 +41,7 @@ const SubstationModificationForm = ({ substationToModify, equipmentId }: Readonl const substationNameField = ( = { SUBSTATION: [ { - labelId: EQUIPMENT_NAME, - csvColumns: [EQUIPMENT_NAME], + labelId: FieldConstants.EQUIPMENT_NAME, + csvColumns: [FieldConstants.EQUIPMENT_NAME], networkFields: ['name'], }, { - labelId: COUNTRY, - csvColumns: [COUNTRY], + labelId: FieldConstants.COUNTRY, + csvColumns: [FieldConstants.COUNTRY], networkFields: ['country'], }, ], VOLTAGE_LEVEL: [ { - labelId: EQUIPMENT_NAME, - csvColumns: [EQUIPMENT_NAME], + labelId: FieldConstants.EQUIPMENT_NAME, + csvColumns: [FieldConstants.EQUIPMENT_NAME], networkFields: ['name'], }, { @@ -139,8 +138,8 @@ export const PREFILLED_COLUMNS_CONFIG: Record = LINE: [ { - labelId: EQUIPMENT_NAME, - csvColumns: [EQUIPMENT_NAME], + labelId: FieldConstants.EQUIPMENT_NAME, + csvColumns: [FieldConstants.EQUIPMENT_NAME], networkFields: ['name'], }, { @@ -191,8 +190,8 @@ export const PREFILLED_COLUMNS_CONFIG: Record = TWO_WINDINGS_TRANSFORMER: [ { - labelId: EQUIPMENT_NAME, - csvColumns: [EQUIPMENT_NAME], + labelId: FieldConstants.EQUIPMENT_NAME, + csvColumns: [FieldConstants.EQUIPMENT_NAME], networkFields: ['name'], }, { @@ -263,8 +262,8 @@ export const PREFILLED_COLUMNS_CONFIG: Record = GENERATOR: [ { - labelId: EQUIPMENT_NAME, - csvColumns: [EQUIPMENT_NAME], + labelId: FieldConstants.EQUIPMENT_NAME, + csvColumns: [FieldConstants.EQUIPMENT_NAME], networkFields: ['name'], }, { @@ -412,8 +411,8 @@ export const PREFILLED_COLUMNS_CONFIG: Record = LOAD: [ { - labelId: EQUIPMENT_NAME, - csvColumns: [EQUIPMENT_NAME], + labelId: FieldConstants.EQUIPMENT_NAME, + csvColumns: [FieldConstants.EQUIPMENT_NAME], networkFields: ['name'], }, { @@ -449,8 +448,8 @@ export const PREFILLED_COLUMNS_CONFIG: Record = BATTERY: [ { - labelId: EQUIPMENT_NAME, - csvColumns: [EQUIPMENT_NAME], + labelId: FieldConstants.EQUIPMENT_NAME, + csvColumns: [FieldConstants.EQUIPMENT_NAME], networkFields: ['name'], }, { @@ -528,8 +527,8 @@ export const PREFILLED_COLUMNS_CONFIG: Record = SHUNT_COMPENSATOR: [ { - labelId: EQUIPMENT_NAME, - csvColumns: [EQUIPMENT_NAME], + labelId: FieldConstants.EQUIPMENT_NAME, + csvColumns: [FieldConstants.EQUIPMENT_NAME], networkFields: ['name'], }, { diff --git a/src/components/dialogs/network-modifications/tabular/properties/properties-form.tsx b/src/components/dialogs/network-modifications/tabular/properties/properties-form.tsx index 4a084a211c..a25597dff1 100644 --- a/src/components/dialogs/network-modifications/tabular/properties/properties-form.tsx +++ b/src/components/dialogs/network-modifications/tabular/properties/properties-form.tsx @@ -5,12 +5,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { Grid } from '@mui/material'; -import { ExpandableInput } from '../../../../utils/rhf-inputs/expandable-input'; import { TABULAR_PROPERTIES, PREDEFINED } from '../../../../utils/field-constants'; import PropertyForm from './property-form'; import { initializedProperty } from './property-utils'; import { useCallback } from 'react'; import { useFormContext } from 'react-hook-form'; +import { ExpandableInput } from '@gridsuite/commons-ui'; const PropertiesForm = () => { const { getValues } = useFormContext(); diff --git a/src/components/dialogs/network-modifications/tabular/properties/property-form.tsx b/src/components/dialogs/network-modifications/tabular/properties/property-form.tsx index 299cf1b7cc..2eabf3f767 100644 --- a/src/components/dialogs/network-modifications/tabular/properties/property-form.tsx +++ b/src/components/dialogs/network-modifications/tabular/properties/property-form.tsx @@ -6,10 +6,9 @@ */ import { NAME, PREDEFINED, SELECTED } from 'components/utils/field-constants'; -import { CheckboxInput, TextInput } from '@gridsuite/commons-ui'; +import { CheckboxInput, italicFontTextField, TextInput } from '@gridsuite/commons-ui'; import GridItem from '../../../commons/grid-item'; import { useWatch } from 'react-hook-form'; -import { italicFontTextField } from '../../../dialog-utils'; type PropertyFormProps = { name: string; diff --git a/src/components/dialogs/network-modifications/tabular/tabular-common.ts b/src/components/dialogs/network-modifications/tabular/tabular-common.ts index 2476d89575..a220e8ed0d 100644 --- a/src/components/dialogs/network-modifications/tabular/tabular-common.ts +++ b/src/components/dialogs/network-modifications/tabular/tabular-common.ts @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { ReactiveCapabilityCurvePoints } from 'components/dialogs/reactive-limits/reactive-limits.type'; -import { createPropertyModification, Property } from '../common/properties/property-utils'; import { propertiesSchema, PROPERTY_CSV_COLUMN_PREFIX, TabularProperty } from './properties/property-utils'; import { CSV_FILENAME, @@ -27,11 +26,13 @@ import { import { BOOLEAN, ENUM, NUMBER } from '../../../network/constants'; import { IntlShape } from 'react-intl'; import { + createPropertyModification, EquipmentType, equipmentTypesForPredefinedPropertiesMapper, LANG_FRENCH, ModificationType, PredefinedProperties, + Property, } from '@gridsuite/commons-ui'; import yup from 'components/utils/yup-config'; import type { UUID } from 'node:crypto'; diff --git a/src/components/dialogs/network-modifications/tabular/tabular-modification-utils.ts b/src/components/dialogs/network-modifications/tabular/tabular-modification-utils.ts index fa4c96b216..cbac6c1388 100644 --- a/src/components/dialogs/network-modifications/tabular/tabular-modification-utils.ts +++ b/src/components/dialogs/network-modifications/tabular/tabular-modification-utils.ts @@ -5,7 +5,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { convertInputValue, convertOutputValue, FieldType, MODIFICATION_TYPES } from '@gridsuite/commons-ui'; +import { + convertInputValue, + convertOutputValue, + FieldConstants, + FieldType, + MODIFICATION_TYPES, +} from '@gridsuite/commons-ui'; import { B, B1, @@ -22,11 +28,9 @@ import { CONNECTION_POSITION, CONNECTION_POSITION1, CONNECTION_POSITION2, - COUNTRY, DROOP, ENERGY_SOURCE, EQUIPMENT_ID, - EQUIPMENT_NAME, FORCED_OUTAGE_RATE, G, G1, @@ -189,10 +193,10 @@ export const LIMIT_SETS_TABULAR_MODIFICATION_REPEATABLE_FIELDS: TabularField[] = ]; export const TABULAR_MODIFICATION_FIELDS: TabularFields = { - SUBSTATION: [{ id: EQUIPMENT_ID }, { id: EQUIPMENT_NAME }, { id: COUNTRY }], + SUBSTATION: [{ id: EQUIPMENT_ID }, { id: FieldConstants.EQUIPMENT_NAME }, { id: FieldConstants.COUNTRY }], VOLTAGE_LEVEL: [ { id: EQUIPMENT_ID }, - { id: EQUIPMENT_NAME }, + { id: FieldConstants.EQUIPMENT_NAME }, { id: NOMINAL_V, type: NUMBER }, { id: LOW_VOLTAGE_LIMIT, type: NUMBER }, { id: HIGH_VOLTAGE_LIMIT, type: NUMBER }, @@ -201,7 +205,7 @@ export const TABULAR_MODIFICATION_FIELDS: TabularFields = { ], LINE: [ { id: EQUIPMENT_ID }, - { id: EQUIPMENT_NAME }, + { id: FieldConstants.EQUIPMENT_NAME }, { id: R, type: NUMBER }, { id: X, type: NUMBER }, { id: G1, type: NUMBER }, @@ -212,7 +216,7 @@ export const TABULAR_MODIFICATION_FIELDS: TabularFields = { ], TWO_WINDINGS_TRANSFORMER: [ { id: EQUIPMENT_ID }, - { id: EQUIPMENT_NAME }, + { id: FieldConstants.EQUIPMENT_NAME }, { id: R, type: NUMBER }, { id: X, type: NUMBER }, { id: G, type: NUMBER }, @@ -230,7 +234,7 @@ export const TABULAR_MODIFICATION_FIELDS: TabularFields = { ], GENERATOR: [ { id: EQUIPMENT_ID }, - { id: EQUIPMENT_NAME }, + { id: FieldConstants.EQUIPMENT_NAME }, { id: ENERGY_SOURCE, type: ENUM, options: ENERGY_SOURCES.map((energy) => energy.id) }, ...CONNECTION_FIELDS, { id: MIN_P, type: NUMBER }, @@ -258,7 +262,7 @@ export const TABULAR_MODIFICATION_FIELDS: TabularFields = { ], LOAD: [ { id: EQUIPMENT_ID }, - { id: EQUIPMENT_NAME }, + { id: FieldConstants.EQUIPMENT_NAME }, { id: LOAD_TYPE, type: ENUM, @@ -270,7 +274,7 @@ export const TABULAR_MODIFICATION_FIELDS: TabularFields = { ], BATTERY: [ { id: EQUIPMENT_ID }, - { id: EQUIPMENT_NAME }, + { id: FieldConstants.EQUIPMENT_NAME }, ...CONNECTION_FIELDS, { id: MIN_P, type: NUMBER }, { id: MAX_P, type: NUMBER }, @@ -284,7 +288,7 @@ export const TABULAR_MODIFICATION_FIELDS: TabularFields = { ], SHUNT_COMPENSATOR: [ { id: EQUIPMENT_ID }, - { id: EQUIPMENT_NAME }, + { id: FieldConstants.EQUIPMENT_NAME }, ...CONNECTION_FIELDS, { id: MAXIMUM_SECTION_COUNT, type: NUMBER }, { id: SECTION_COUNT, type: NUMBER }, diff --git a/src/components/dialogs/network-modifications/two-windings-transformer/characteristics-pane/two-windings-transformer-characteristics-pane.jsx b/src/components/dialogs/network-modifications/two-windings-transformer/characteristics-pane/two-windings-transformer-characteristics-pane.jsx index 7ad2e2f2c2..fdafc4aace 100644 --- a/src/components/dialogs/network-modifications/two-windings-transformer/characteristics-pane/two-windings-transformer-characteristics-pane.jsx +++ b/src/components/dialogs/network-modifications/two-windings-transformer/characteristics-pane/two-windings-transformer-characteristics-pane.jsx @@ -5,14 +5,21 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +import { + convertInputValue, + FieldType, + FloatInput, + MicroSusceptanceAdornment, + MVAPowerAdornment, + OhmAdornment, + PropertiesForm, + VoltageAdornment, +} from '@gridsuite/commons-ui'; import { Grid } from '@mui/material'; -import { FormattedMessage } from 'react-intl'; -import { MicroSusceptanceAdornment, MVAPowerAdornment, OhmAdornment, VoltageAdornment } from '../../../dialog-utils'; -import { convertInputValue, FieldType, FloatInput } from '@gridsuite/commons-ui'; import { B, CHARACTERISTICS, G, R, RATED_S, RATED_U1, RATED_U2, X } from 'components/utils/field-constants'; -import PropertiesForm from '../../common/properties/properties-form'; -import GridSection from '../../../commons/grid-section'; +import { FormattedMessage } from 'react-intl'; import GridItem from '../../../commons/grid-item'; +import GridSection from '../../../commons/grid-section'; const TwoWindingsTransformerCharacteristicsPane = ({ id = CHARACTERISTICS, twtToModify, isModification = false }) => { const width = isModification ? 12 : 8; diff --git a/src/components/dialogs/network-modifications/two-windings-transformer/creation/two-windings-transformer-creation-dialog-header.jsx b/src/components/dialogs/network-modifications/two-windings-transformer/creation/two-windings-transformer-creation-dialog-header.jsx index 08472eb020..249659f277 100644 --- a/src/components/dialogs/network-modifications/two-windings-transformer/creation/two-windings-transformer-creation-dialog-header.jsx +++ b/src/components/dialogs/network-modifications/two-windings-transformer/creation/two-windings-transformer-creation-dialog-header.jsx @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +import { filledTextField, SwitchInput, TextInput } from '@gridsuite/commons-ui'; import { Grid } from '@mui/material'; import { ENABLED, @@ -13,9 +14,6 @@ import { PHASE_TAP_CHANGER, RATIO_TAP_CHANGER, } from 'components/utils/field-constants'; -import { filledTextField } from '../../../dialog-utils'; -import { TextInput } from '@gridsuite/commons-ui'; -import { SwitchInput } from '@gridsuite/commons-ui'; import GridItem from '../../../commons/grid-item'; const TwoWindingsTransformerCreationDialogHeader = () => { diff --git a/src/components/dialogs/network-modifications/two-windings-transformer/creation/two-windings-transformer-creation-dialog.jsx b/src/components/dialogs/network-modifications/two-windings-transformer/creation/two-windings-transformer-creation-dialog.jsx index ebe21e7821..9c9a3ec9b6 100644 --- a/src/components/dialogs/network-modifications/two-windings-transformer/creation/two-windings-transformer-creation-dialog.jsx +++ b/src/components/dialogs/network-modifications/two-windings-transformer/creation/two-windings-transformer-creation-dialog.jsx @@ -8,9 +8,15 @@ import { convertInputValue, convertOutputValue, + copyEquipmentPropertiesForCreation, + creationPropertiesSchema, CustomFormProvider, + emptyProperties, FieldType, + getPropertiesFromModification, + sanitizeString, snackWithFallback, + toModificationProperties, useSnackMessage, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; @@ -61,7 +67,6 @@ import PropTypes from 'prop-types'; import { useCallback, useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; import { FetchStatus } from '../../../../../services/utils'; -import { sanitizeString } from '../../../dialog-utils'; import EquipmentSearchDialog from '../../../equipment-search-dialog'; import { useFormSearchCopy } from '../../../commons/use-form-search-copy'; import { @@ -102,13 +107,6 @@ import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modi import TwoWindingsTransformerCreationDialogHeader from './two-windings-transformer-creation-dialog-header'; import { addSelectedFieldToRows, computeHighTapPosition, formatCompleteCurrentLimit } from 'components/utils/utils'; import { createTwoWindingsTransformer } from '../../../../../services/study/network-modifications'; -import { - copyEquipmentPropertiesForCreation, - creationPropertiesSchema, - emptyProperties, - getPropertiesFromModification, - toModificationProperties, -} from '../../common/properties/property-utils'; import { TwoWindingsTransformerCreationDialogTab } from '../two-windings-transformer-utils'; /** diff --git a/src/components/dialogs/network-modifications/two-windings-transformer/modification/two-windings-transformer-modification-dialog-header.jsx b/src/components/dialogs/network-modifications/two-windings-transformer/modification/two-windings-transformer-modification-dialog-header.jsx index 4d01e99e55..2405cfc79f 100644 --- a/src/components/dialogs/network-modifications/two-windings-transformer/modification/two-windings-transformer-modification-dialog-header.jsx +++ b/src/components/dialogs/network-modifications/two-windings-transformer/modification/two-windings-transformer-modification-dialog-header.jsx @@ -7,8 +7,7 @@ import { Grid, TextField } from '@mui/material'; import { ENABLED, EQUIPMENT_NAME, RATIO_TAP_CHANGER, PHASE_TAP_CHANGER } from 'components/utils/field-constants'; -import { filledTextField } from '../../../dialog-utils'; -import { SwitchInput, TextInput } from '@gridsuite/commons-ui'; +import { filledTextField, SwitchInput, TextInput } from '@gridsuite/commons-ui'; import GridItem from '../../../commons/grid-item'; const TwoWindingsTransformerModificationDialogHeader = ({ equipmentToModify, equipmentId }) => { diff --git a/src/components/dialogs/network-modifications/two-windings-transformer/modification/two-windings-transformer-modification-dialog.jsx b/src/components/dialogs/network-modifications/two-windings-transformer/modification/two-windings-transformer-modification-dialog.jsx index 272d348301..295c05d343 100644 --- a/src/components/dialogs/network-modifications/two-windings-transformer/modification/two-windings-transformer-modification-dialog.jsx +++ b/src/components/dialogs/network-modifications/two-windings-transformer/modification/two-windings-transformer-modification-dialog.jsx @@ -9,15 +9,21 @@ import { convertInputValue, convertOutputValue, CustomFormProvider, + emptyProperties, EquipmentType, + FieldConstants, FieldType, + getConcatenatedProperties, + getPropertiesFromModification, + modificationPropertiesSchema, + sanitizeString, snackWithFallback, + toModificationProperties, useSnackMessage, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { Box, Grid } from '@mui/material'; import { - ADDITIONAL_PROPERTIES, B, BUS_OR_BUSBAR_SECTION, CHARACTERISTICS, @@ -67,13 +73,11 @@ import { TO_BE_ESTIMATED, TYPE, VALIDITY, - VALUE, VOLTAGE_LEVEL, X, } from 'components/utils/field-constants'; import PropTypes from 'prop-types'; import { useCallback, useEffect, useState } from 'react'; -import { sanitizeString } from '../../../dialog-utils'; import { FORM_LOADING_DELAY, PHASE_REGULATION_MODES, @@ -128,13 +132,6 @@ import RatioTapChangerPane from '../tap-changer-pane/ratio-tap-changer-pane/rati import PhaseTapChangerPane from '../tap-changer-pane/phase-tap-changer-pane/phase-tap-changer-pane'; import { fetchNetworkElementInfos } from '../../../../../services/study/network'; import { FetchStatus } from '../../../../../services/utils'; -import { - emptyProperties, - getConcatenatedProperties, - getPropertiesFromModification, - modificationPropertiesSchema, - toModificationProperties, -} from '../../common/properties/property-utils'; import useVoltageLevelsListInfos from '../../../../../hooks/use-voltage-levels-list-infos'; import { BranchConnectivityForm } from '../../../connectivity/branch-connectivity-form'; import { @@ -518,13 +515,13 @@ const TwoWindingsTransformerModificationDialog = ({ connected1: connectivity1[CONNECTED], connected2: connectivity2[CONNECTED], properties: toModificationProperties(twt), - p1MeasurementValue: stateEstimationData[MEASUREMENT_P1][VALUE], + p1MeasurementValue: stateEstimationData[MEASUREMENT_P1][FieldConstants.VALUE], p1MeasurementValidity: stateEstimationData[MEASUREMENT_P1][VALIDITY], - q1MeasurementValue: stateEstimationData[MEASUREMENT_Q1][VALUE], + q1MeasurementValue: stateEstimationData[MEASUREMENT_Q1][FieldConstants.VALUE], q1MeasurementValidity: stateEstimationData[MEASUREMENT_Q1][VALIDITY], - p2MeasurementValue: stateEstimationData[MEASUREMENT_P2][VALUE], + p2MeasurementValue: stateEstimationData[MEASUREMENT_P2][FieldConstants.VALUE], p2MeasurementValidity: stateEstimationData[MEASUREMENT_P2][VALIDITY], - q2MeasurementValue: stateEstimationData[MEASUREMENT_Q2][VALUE], + q2MeasurementValue: stateEstimationData[MEASUREMENT_Q2][FieldConstants.VALUE], q2MeasurementValidity: stateEstimationData[MEASUREMENT_Q2][VALIDITY], ratioTapChangerToBeEstimated: stateEstimationData[TO_BE_ESTIMATED][RATIO_TAP_CHANGER_STATUS], phaseTapChangerToBeEstimated: stateEstimationData[TO_BE_ESTIMATED][PHASE_TAP_CHANGER_STATUS], @@ -714,7 +711,7 @@ const TwoWindingsTransformerModificationDialog = ({ equipmentType: getValues(`${PHASE_TAP_CHANGER}.${EQUIPMENT}.${TYPE}`), voltageLevelId: getValues(`${PHASE_TAP_CHANGER}.${VOLTAGE_LEVEL}.${ID}`), }), - [ADDITIONAL_PROPERTIES]: getConcatenatedProperties(twt, getValues), + [FieldConstants.ADDITIONAL_PROPERTIES]: getConcatenatedProperties(twt, getValues), }), { keepDirty: true } ); diff --git a/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/phase-tap-changer-pane/phase-tap-changer-pane-steps.tsx b/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/phase-tap-changer-pane/phase-tap-changer-pane-steps.tsx index 14f3986940..247b4337b8 100644 --- a/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/phase-tap-changer-pane/phase-tap-changer-pane-steps.tsx +++ b/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/phase-tap-changer-pane/phase-tap-changer-pane-steps.tsx @@ -18,8 +18,7 @@ import { import { useMemo } from 'react'; import { useIntl } from 'react-intl'; import TapChangerSteps from '../tap-changer-steps'; -import { parseIntData } from '../../../../dialog-utils'; -import { DndColumn, DndColumnType } from '@gridsuite/commons-ui'; +import { DndColumn, DndColumnType, parseIntData } from '@gridsuite/commons-ui'; import { CurrentTreeNode } from 'components/graph/tree-node.type'; import { PHASE_TAP, PhaseTapChangerData } from '../../two-windings-transformer.types'; diff --git a/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/phase-tap-changer-pane/phase-tap-changer-pane.tsx b/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/phase-tap-changer-pane/phase-tap-changer-pane.tsx index c07238558f..23b06b7842 100644 --- a/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/phase-tap-changer-pane/phase-tap-changer-pane.tsx +++ b/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/phase-tap-changer-pane/phase-tap-changer-pane.tsx @@ -17,9 +17,8 @@ import { } from 'components/utils/field-constants'; import { useWatch } from 'react-hook-form'; import { useIntl } from 'react-intl'; -import { ActivePowerAdornment, AmpereAdornment } from '../../../../dialog-utils'; import { PHASE_REGULATION_MODES } from 'components/network/constants'; -import { FloatInput, SelectInput } from '@gridsuite/commons-ui'; +import { ActivePowerAdornment, AmpereAdornment, FloatInput, SelectInput } from '@gridsuite/commons-ui'; import PhaseTapChangerPaneSteps from './phase-tap-changer-pane-steps'; import { getComputedPhaseTapChangerRegulationMode, diff --git a/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/ratio-tap-changer-pane/ratio-tap-changer-pane-steps.tsx b/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/ratio-tap-changer-pane/ratio-tap-changer-pane-steps.tsx index 345bb7c970..3c67df0508 100644 --- a/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/ratio-tap-changer-pane/ratio-tap-changer-pane-steps.tsx +++ b/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/ratio-tap-changer-pane/ratio-tap-changer-pane-steps.tsx @@ -16,8 +16,7 @@ import { } from 'components/utils/field-constants'; import { useMemo } from 'react'; import { useIntl } from 'react-intl'; -import { parseIntData } from '../../../../dialog-utils'; -import { DndColumn, DndColumnType } from '@gridsuite/commons-ui'; +import { DndColumn, DndColumnType, parseIntData } from '@gridsuite/commons-ui'; import { CurrentTreeNode } from 'components/graph/tree-node.type'; import TapChangerSteps from '../tap-changer-steps'; import { RATIO_TAP, RatioTapChangerData } from '../../two-windings-transformer.types'; diff --git a/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/ratio-tap-changer-pane/ratio-tap-changer-pane.tsx b/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/ratio-tap-changer-pane/ratio-tap-changer-pane.tsx index cbe8640b06..6eda483d3f 100644 --- a/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/ratio-tap-changer-pane/ratio-tap-changer-pane.tsx +++ b/src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/ratio-tap-changer-pane/ratio-tap-changer-pane.tsx @@ -21,8 +21,7 @@ import { import { useCallback, useEffect, useMemo } from 'react'; import { useFormContext, useWatch } from 'react-hook-form'; import { useIntl } from 'react-intl'; -import { VoltageAdornment } from '../../../../dialog-utils'; -import { FloatInput, Identifiable, SelectInput, SwitchInput } from '@gridsuite/commons-ui'; +import { FloatInput, Identifiable, SelectInput, SwitchInput, VoltageAdornment } from '@gridsuite/commons-ui'; import RatioTapChangerPaneSteps from './ratio-tap-changer-pane-steps'; import { RATIO_REGULATION_MODES } from 'components/network/constants'; import CheckboxNullableInput from 'components/utils/rhf-inputs/boolean-nullable-input'; diff --git a/src/components/dialogs/network-modifications/voltage-level/coupling-omnibus/coupling-omnibus-form.tsx b/src/components/dialogs/network-modifications/voltage-level/coupling-omnibus/coupling-omnibus-form.tsx index 5d4c174cb5..d22023d6a0 100644 --- a/src/components/dialogs/network-modifications/voltage-level/coupling-omnibus/coupling-omnibus-form.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/coupling-omnibus/coupling-omnibus-form.tsx @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { ExpandableInput } from 'components/utils/rhf-inputs/expandable-input'; import { BUS_BAR_COUNT, BUS_BAR_SECTION_ID1, @@ -18,6 +17,7 @@ import { CouplingOmnibusCreation } from './coupling-omnibus-creation'; import { useEffect, useMemo } from 'react'; import { useFormContext, useWatch } from 'react-hook-form'; import { buildNewBusbarSections } from 'components/utils/utils'; +import { ExpandableInput } from '@gridsuite/commons-ui'; export const CouplingOmnibusForm = () => { const { setValue } = useFormContext(); diff --git a/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.tsx b/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.tsx index c16d7e6b5a..1884cbc5f4 100644 --- a/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.tsx @@ -8,27 +8,33 @@ import { convertInputValue, convertOutputValue, + copyEquipmentPropertiesForCreation, + creationPropertiesSchema, CustomFormProvider, + emptyProperties, EquipmentType, FieldType, + getPropertiesFromModification, MODIFICATION_TYPES, + Properties, + Property, snackWithFallback, + toModificationProperties, useSnackMessage, + DeepNullable, + sanitizeString, + FieldConstants, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; -import { sanitizeString } from 'components/dialogs/dialog-utils'; import EquipmentSearchDialog from 'components/dialogs/equipment-search-dialog'; import { useFormSearchCopy } from 'components/dialogs/commons/use-form-search-copy'; import { ADD_SUBSTATION_CREATION, - ADDITIONAL_PROPERTIES, BUS_BAR_COUNT, BUS_BAR_SECTION_ID1, BUS_BAR_SECTION_ID2, - COUNTRY, COUPLING_OMNIBUS, EQUIPMENT_ID, - EQUIPMENT_NAME, HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, HIGH_VOLTAGE_LIMIT, ID, @@ -59,15 +65,6 @@ import { FORM_LOADING_DELAY } from 'components/network/constants'; import { useOpenShortWaitFetching } from '../../../commons/handle-modification-form'; import { createVoltageLevel } from '../../../../../services/study/network-modifications'; import { FetchStatus } from '../../../../../services/utils'; -import { - copyEquipmentPropertiesForCreation, - creationPropertiesSchema, - emptyProperties, - getPropertiesFromModification, - Properties, - Property, - toModificationProperties, -} from '../../common/properties/property-utils'; import { UUID } from 'node:crypto'; import { AttachedSubstationCreationInfo, @@ -75,19 +72,18 @@ import { VoltageLevelCreationInfo, } from '../../../../../services/network-modification-types'; import { CurrentTreeNode } from '../../../../graph/tree-node.type'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { CreateCouplingDeviceDialogSchemaForm } from '../../coupling-device/coupling-device-dialog.type'; export type SwitchKindFormData = { [SWITCH_KIND]: string }; interface VoltageLevelCreationFormData { - [ADDITIONAL_PROPERTIES]?: Property[]; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Property[]; [ADD_SUBSTATION_CREATION]: boolean; [BUS_BAR_COUNT]: number; - [COUNTRY]: string | null; + [FieldConstants.COUNTRY]: string | null; [COUPLING_OMNIBUS]: CreateCouplingDeviceDialogSchemaForm[]; [EQUIPMENT_ID]: string; - [EQUIPMENT_NAME]: string; + [FieldConstants.EQUIPMENT_NAME]: string; [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: number | null; [HIGH_VOLTAGE_LIMIT]: number | null; [IS_ATTACHMENT_POINT_CREATION]: boolean; @@ -132,7 +128,7 @@ interface VoltageLevelCreationDialogProps { const emptyFormData: VoltageLevelCreationFormData = { [EQUIPMENT_ID]: '', - [EQUIPMENT_NAME]: '', + [FieldConstants.EQUIPMENT_NAME]: '', [SUBSTATION_ID]: null, [NOMINAL_V]: null, [LOW_VOLTAGE_LIMIT]: null, @@ -147,7 +143,7 @@ const emptyFormData: VoltageLevelCreationFormData = { [ADD_SUBSTATION_CREATION]: false, [SUBSTATION_CREATION_ID]: null, [SUBSTATION_NAME]: null, - [COUNTRY]: null, + [FieldConstants.COUNTRY]: null, [IS_ATTACHMENT_POINT_CREATION]: false, [TOPOLOGY_KIND]: null, [SUBSTATION_CREATION]: emptyProperties, @@ -172,7 +168,7 @@ const formSchema = yup 'CreateSubstationInVoltageLevelIdenticalId' ), }), - [EQUIPMENT_NAME]: yup.string().nullable(), + [FieldConstants.EQUIPMENT_NAME]: yup.string().nullable(), [ADD_SUBSTATION_CREATION]: yup.boolean().required(), [SUBSTATION_ID]: yup .string() @@ -195,7 +191,7 @@ const formSchema = yup .notOneOf([yup.ref(EQUIPMENT_ID), null], 'CreateSubstationInVoltageLevelIdenticalId'), }), [SUBSTATION_NAME]: yup.string().nullable(), - [COUNTRY]: yup.string().nullable(), + [FieldConstants.COUNTRY]: yup.string().nullable(), [SUBSTATION_CREATION]: creationPropertiesSchema, [NOMINAL_V]: yup .number() @@ -321,7 +317,7 @@ const VoltageLevelCreationDialog: FC = ({ .join(' / ') || ''; const equipmentId = (voltageLevel[EQUIPMENT_ID] ?? voltageLevel[ID]) + (fromCopy ? '(1)' : ''); - const equipmentName = voltageLevel[EQUIPMENT_NAME] ?? voltageLevel[NAME]; + const equipmentName = voltageLevel[FieldConstants.EQUIPMENT_NAME] ?? voltageLevel[NAME]; const substationId = isSubstationCreation ? null : (voltageLevel[SUBSTATION_ID] ?? null); const properties = fromCopy @@ -330,7 +326,7 @@ const VoltageLevelCreationDialog: FC = ({ reset( { [EQUIPMENT_ID]: equipmentId, - [EQUIPMENT_NAME]: equipmentName, + [FieldConstants.EQUIPMENT_NAME]: equipmentName, [TOPOLOGY_KIND]: voltageLevel[TOPOLOGY_KIND], [SUBSTATION_ID]: substationId, [NOMINAL_V]: voltageLevel[NOMINAL_V], @@ -351,13 +347,13 @@ const VoltageLevelCreationDialog: FC = ({ const substationKeys = [ [SUBSTATION_CREATION_ID, voltageLevel.substationCreation?.equipmentId], [SUBSTATION_NAME, voltageLevel.substationCreation?.equipmentName], - [COUNTRY, voltageLevel.substationCreation?.country], + [FieldConstants.COUNTRY, voltageLevel.substationCreation?.country], ]; substationKeys.forEach(([key, value]) => { setValue(key, value); }); setValue( - `${SUBSTATION_CREATION}.${ADDITIONAL_PROPERTIES}`, + `${SUBSTATION_CREATION}.${FieldConstants.ADDITIONAL_PROPERTIES}`, voltageLevel.substationCreation?.properties ); setValue(ADD_SUBSTATION_CREATION, true); @@ -439,7 +435,7 @@ const VoltageLevelCreationDialog: FC = ({ type: MODIFICATION_TYPES.SUBSTATION_CREATION.type, equipmentId: voltageLevel[SUBSTATION_CREATION_ID], equipmentName: voltageLevel[SUBSTATION_NAME], - country: voltageLevel[COUNTRY], + country: voltageLevel[FieldConstants.COUNTRY], properties: toModificationProperties(voltageLevel[SUBSTATION_CREATION]), } : null; @@ -447,7 +443,7 @@ const VoltageLevelCreationDialog: FC = ({ studyUuid: studyUuid as UUID, nodeUuid: currentNodeUuid, equipmentId: voltageLevel[EQUIPMENT_ID], - equipmentName: sanitizeString(voltageLevel[EQUIPMENT_NAME]) ?? undefined, + equipmentName: sanitizeString(voltageLevel[FieldConstants.EQUIPMENT_NAME]) ?? undefined, substationId: substationCreation === null ? voltageLevel[SUBSTATION_ID] : null, substationCreation: substationCreation, nominalV: voltageLevel[NOMINAL_V], diff --git a/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-form.tsx b/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-form.tsx index 3755df24ba..7c1a128c3e 100644 --- a/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-form.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-form.tsx @@ -8,9 +8,7 @@ import { ADD_SUBSTATION_CREATION, BUS_BAR_COUNT, - COUNTRY, EQUIPMENT_ID, - EQUIPMENT_NAME, HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, HIGH_VOLTAGE_LIMIT, IS_ATTACHMENT_POINT_CREATION, @@ -24,27 +22,29 @@ import { SUBSTATION_NAME, } from 'components/utils/field-constants'; import React, { useCallback, useEffect, useState } from 'react'; -import { KiloAmpereAdornment, VoltageAdornment } from 'components/dialogs/dialog-utils'; import { AutocompleteInput, + CountrySelectionInput, EquipmentType, fetchDefaultCountry, + FieldConstants, FloatInput, IntegerInput, + KiloAmpereAdornment, + PropertiesForm, TextInput, + VoltageAdornment, } from '@gridsuite/commons-ui'; import { Box, Grid, Paper, Tooltip } from '@mui/material'; import { CouplingOmnibusForm } from '../coupling-omnibus/coupling-omnibus-form'; import { SwitchesBetweenSections } from '../switches-between-sections/switches-between-sections'; import { fetchEquipmentsIds } from '../../../../../services/study/network-map'; -import PropertiesForm from '../../common/properties/properties-form'; import { useFormContext, useWatch } from 'react-hook-form'; import GridItem from '../../../commons/grid-item'; import GridSection from '../../../commons/grid-section'; import IconButton from '@mui/material/IconButton'; import { useIntl } from 'react-intl'; -import CountrySelectionInput from '../../../../utils/rhf-inputs/country-selection-input'; import DeleteIcon from '@mui/icons-material/Delete'; import LineSeparator from '../../../commons/line-separator'; import { UUID } from 'node:crypto'; @@ -70,10 +70,10 @@ const VoltageLevelCreationForm = ({ useEffect(() => { // in new substation mode, set the default country - if (watchAddSubstationCreation && !getValues(COUNTRY)) { + if (watchAddSubstationCreation && !getValues(FieldConstants.COUNTRY)) { fetchDefaultCountry().then((country) => { if (country) { - setValue(COUNTRY, country); + setValue(FieldConstants.COUNTRY, country); } }); } @@ -120,7 +120,9 @@ const VoltageLevelCreationForm = ({ setValue(SUBSTATION_CREATION_ID, getValues(SUBSTATION_ID)); setValue(ADD_SUBSTATION_CREATION, true); }, [setValue, getValues]); - const voltageLevelNameField = ; + const voltageLevelNameField = ( + + ); const substationField = ( ; const substationCreationNameField = ; - const substationCreationCountryField = ; + const substationCreationCountryField = ( + + ); const handleDeleteButton = useCallback(() => { setValue(ADD_SUBSTATION_CREATION, false); // clear the fields of the new substation setValue(SUBSTATION_CREATION_ID, null); setValue(SUBSTATION_NAME, null); - setValue(COUNTRY, null); + setValue(FieldConstants.COUNTRY, null); }, [setValue]); return ( diff --git a/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.tsx b/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.tsx index 4f29b979b1..77d6f7eada 100644 --- a/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.tsx @@ -9,7 +9,6 @@ import { ModificationDialog } from '../../../commons/modificationDialog'; import { useCallback, useEffect, useState } from 'react'; import VoltageLevelModificationForm from './voltage-level-modification-form'; import { - ADDITIONAL_PROPERTIES, EQUIPMENT_NAME, HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, HIGH_VOLTAGE_LIMIT, @@ -24,9 +23,16 @@ import { convertInputValue, convertOutputValue, CustomFormProvider, + emptyProperties, EquipmentType, + EquipmentWithProperties, + FieldConstants, FieldType, + getConcatenatedProperties, + getPropertiesFromModification, + modificationPropertiesSchema, snackWithFallback, + toModificationProperties, useSnackMessage, } from '@gridsuite/commons-ui'; import { useOpenShortWaitFetching } from '../../../commons/handle-modification-form'; @@ -36,14 +42,6 @@ import { EquipmentIdSelector } from '../../../equipment-id/equipment-id-selector import { modifyVoltageLevel } from '../../../../../services/study/network-modifications'; import { fetchNetworkElementInfos } from '../../../../../services/study/network'; import { FetchStatus } from '../../../../../services/utils'; -import { - emptyProperties, - Equipment, - getConcatenatedProperties, - getPropertiesFromModification, - modificationPropertiesSchema, - toModificationProperties, -} from '../../common/properties/property-utils'; import { isNodeBuilt } from '../../../../graph/util/model-functions'; import { useFormWithDirtyTracking } from 'components/dialogs/commons/use-form-with-dirty-tracking'; import { UUID } from 'node:crypto'; @@ -83,7 +81,7 @@ interface VoltageLevelFormData { [HIGH_VOLTAGE_LIMIT]?: number; [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]?: number; [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]?: number; - [ADDITIONAL_PROPERTIES]?: any; + [FieldConstants.ADDITIONAL_PROPERTIES]?: any; [key: string]: any; } @@ -217,8 +215,8 @@ const VoltageLevelModificationDialog = ({ reset( (formValues) => ({ ...formValues, - [ADDITIONAL_PROPERTIES]: getConcatenatedProperties( - voltageLevel as Equipment, + [FieldConstants.ADDITIONAL_PROPERTIES]: getConcatenatedProperties( + voltageLevel as EquipmentWithProperties, getValues ), [SUBSTATION_ID]: voltageLevel?.substationId, diff --git a/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-form.tsx b/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-form.tsx index 09ce106af8..da3381b79b 100644 --- a/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-form.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-form.tsx @@ -7,7 +7,6 @@ import { getObjectId } from 'components/utils/utils'; import { - ADDITIONAL_PROPERTIES, EQUIPMENT_NAME, HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, HIGH_VOLTAGE_LIMIT, @@ -18,13 +17,20 @@ import { NOMINAL_V, SUBSTATION_ID, } from 'components/utils/field-constants'; -import { AutocompleteInput, FloatInput, TextInput } from '@gridsuite/commons-ui'; -import { filledTextField, KiloAmpereAdornment, VoltageAdornment } from '../../../dialog-utils'; -import { TextField, Grid } from '@mui/material'; -import PropertiesForm from '../../common/properties/properties-form'; +import { + AutocompleteInput, + FieldConstants, + filledTextField, + FloatInput, + KiloAmpereAdornment, + Properties, + PropertiesForm, + TextInput, + VoltageAdornment, +} from '@gridsuite/commons-ui'; +import { Grid, TextField } from '@mui/material'; import GridItem from '../../../commons/grid-item'; import GridSection from '../../../commons/grid-section'; -import { Properties } from '../../common/properties/property-utils'; interface VoltageLevelFormData { [NAME]?: string; @@ -35,7 +41,7 @@ interface VoltageLevelFormData { [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]?: number; [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]?: number; [IDENTIFIABLE_SHORT_CIRCUIT]?: { ipMin: number; ipMax: number }; - [ADDITIONAL_PROPERTIES]?: Properties; + [FieldConstants.ADDITIONAL_PROPERTIES]?: Properties; } interface VoltageLevelModificationFormProps { diff --git a/src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-dialog.tsx b/src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-dialog.tsx index b9b612ca54..9a1b5b9db7 100644 --- a/src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-dialog.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-dialog.tsx @@ -12,6 +12,7 @@ import { MODIFICATION_TYPES, snackWithFallback, useSnackMessage, + DeepNullable, } from '@gridsuite/commons-ui'; import { useCallback, useEffect, useMemo, useState } from 'react'; import { FetchStatus } from '../../../../../services/utils'; @@ -41,7 +42,6 @@ import { MoveVoltageLevelFeederBaysInfos, } from '../../../../../services/network-modification-types'; import { EquipmentModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { FeederBays, FeederBaysFormInfos } from './move-voltage-level-feeder-bays.type'; import { moveVoltageLevelFeederBays } from '../../../../../services/study/network-modifications'; import { diff --git a/src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-form.tsx b/src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-form.tsx index 283332c2ae..3d0c4e2cae 100644 --- a/src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-form.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-form.tsx @@ -8,11 +8,10 @@ import { useCallback, useMemo, useState } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import { CurrentTreeNode } from '../../../../graph/tree-node.type'; import { Box, Grid, TextField, Tooltip } from '@mui/material'; -import { filledTextField } from '../../../dialog-utils'; import { isNodeBuilt } from '../../../../graph/util/model-functions'; import { useFormContext } from 'react-hook-form'; import HeaderWithTooltip from '../topology-modification/header-with-tooltip'; -import { AutocompleteInput, CustomAGGrid, TextInput } from '@gridsuite/commons-ui'; +import { AutocompleteInput, CustomAGGrid, filledTextField, TextInput } from '@gridsuite/commons-ui'; import { BUSBAR_SECTION_ID, BUSBAR_SECTION_IDS, diff --git a/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-dialog.tsx b/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-dialog.tsx index c54e6d6da0..f4ebc781c5 100644 --- a/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-dialog.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-dialog.tsx @@ -10,6 +10,7 @@ import { MODIFICATION_TYPES, snackWithFallback, useSnackMessage, + DeepNullable, } from '@gridsuite/commons-ui'; import { EquipmentModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; import { useCallback, useEffect, useState } from 'react'; @@ -39,7 +40,6 @@ import { BusBarSections, CreateVoltageLevelSectionDialogSchemaForm } from './vol import { CreateVoltageLevelSectionInfos } from '../../../../../services/network-modification-types'; import { createVoltageLevelSection } from '../../../../../services/study/network-modifications'; import { fetchVoltageLevelBusBarSectionsInfos } from '../../../../../services/study/network'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { BusBarSectionsInfos } from '../../../../../services/study/network-map.type'; const getBusBarIndexValue = ({ busbarIndex, allBusbars }: { busbarIndex: string | null; allBusbars: boolean }) => { diff --git a/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-form.tsx b/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-form.tsx index b9855285c7..ed0b81dcf4 100644 --- a/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-form.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-form.tsx @@ -17,10 +17,9 @@ import { SWITCHES_BEFORE_SECTIONS, } from '../../../../utils/field-constants'; import { Box, Button, Grid, Slider, TextField, Tooltip, Typography } from '@mui/material'; -import { filledTextField } from '../../../dialog-utils'; import { FormattedMessage, useIntl } from 'react-intl'; import { CurrentTreeNode } from 'components/graph/tree-node.type'; -import { AutocompleteInput, Option, SelectInput, SwitchInput } from '@gridsuite/commons-ui'; +import { AutocompleteInput, filledTextField, Option, SelectInput, SwitchInput } from '@gridsuite/commons-ui'; import GridSection from '../../../commons/grid-section'; import { isNodeBuilt } from 'components/graph/util/model-functions'; import { InfoOutlined } from '@mui/icons-material'; diff --git a/src/components/dialogs/network-modifications/voltage-level/topology-creation/create-voltage-level-topology-dialog.tsx b/src/components/dialogs/network-modifications/voltage-level/topology-creation/create-voltage-level-topology-dialog.tsx index e9fb7f08f0..3cb3a3c5a7 100644 --- a/src/components/dialogs/network-modifications/voltage-level/topology-creation/create-voltage-level-topology-dialog.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/topology-creation/create-voltage-level-topology-dialog.tsx @@ -15,13 +15,13 @@ import { MODIFICATION_TYPES, snackWithFallback, useSnackMessage, + DeepNullable, } from '@gridsuite/commons-ui'; import yup from '../../../../utils/yup-config'; import { isNodeBuilt } from '../../../../graph/util/model-functions'; import { EquipmentModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; import { CreateVoltageLevelTopologyDialogSchemaForm } from './create-voltage-level-topology-dialog.type'; import CreateVoltageLevelTopologyForm from './create-voltage-level-topology-form'; -import { DeepNullable } from '../../../../utils/ts-utils'; import { EquipmentIdSelector } from '../../../equipment-id/equipment-id-selector'; import { ModificationDialog } from '../../../commons/modificationDialog'; import { FORM_LOADING_DELAY } from '../../../../network/constants'; diff --git a/src/components/dialogs/network-modifications/voltage-level/topology-creation/create-voltage-level-topology-form.tsx b/src/components/dialogs/network-modifications/voltage-level/topology-creation/create-voltage-level-topology-form.tsx index 5193ac1215..b023e018a7 100644 --- a/src/components/dialogs/network-modifications/voltage-level/topology-creation/create-voltage-level-topology-form.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/topology-creation/create-voltage-level-topology-form.tsx @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { IntegerInput } from '@gridsuite/commons-ui'; +import { filledTextField, IntegerInput } from '@gridsuite/commons-ui'; import { SECTION_COUNT } from 'components/utils/field-constants'; import GridItem from '../../../commons/grid-item'; import { Box, Grid, TextField, Tooltip } from '@mui/material'; @@ -14,7 +14,6 @@ import PositionDiagramPane from '../../../../grid-layout/cards/diagrams/singleLi import { useCallback, useMemo, useState } from 'react'; import Button from '@mui/material/Button'; import { FormattedMessage, useIntl } from 'react-intl'; -import { filledTextField } from '../../../dialog-utils'; import type { UUID } from 'node:crypto'; import { isNodeBuilt } from '../../../../graph/util/model-functions'; import { CurrentTreeNode } from '../../../../graph/tree-node.type'; diff --git a/src/components/dialogs/network-modifications/voltage-level/topology-modification/voltage-level-topology-modification-form.tsx b/src/components/dialogs/network-modifications/voltage-level/topology-modification/voltage-level-topology-modification-form.tsx index 4deb89c8e1..253ef9159b 100644 --- a/src/components/dialogs/network-modifications/voltage-level/topology-modification/voltage-level-topology-modification-form.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/topology-modification/voltage-level-topology-modification-form.tsx @@ -14,8 +14,7 @@ import { SWITCH_ID, TOPOLOGY_MODIFICATION_TABLE, } from '../../../../utils/field-constants'; -import { CustomAGGrid } from '@gridsuite/commons-ui'; -import { filledTextField } from '../../../dialog-utils'; +import { CustomAGGrid, filledTextField } from '@gridsuite/commons-ui'; import HeaderWithTooltip from './header-with-tooltip'; import { isNodeBuilt } from '../../../../graph/util/model-functions'; import ConnectionCellRenderer from './connection-cell-render'; diff --git a/src/components/dialogs/parameters/dynamicsimulation/mapping-parameters.tsx b/src/components/dialogs/parameters/dynamicsimulation/mapping-parameters.tsx index 6d489bd48c..694a49c232 100644 --- a/src/components/dialogs/parameters/dynamicsimulation/mapping-parameters.tsx +++ b/src/components/dialogs/parameters/dynamicsimulation/mapping-parameters.tsx @@ -8,8 +8,7 @@ import { Grid } from '@mui/material'; import { DefParam, makeComponents, TYPES } from '../util/make-component-utils'; import { FunctionComponent, useMemo } from 'react'; -import { getIdOrSelf } from '../../dialog-utils'; -import { AutocompleteInput } from '@gridsuite/commons-ui'; +import { AutocompleteInput, getIdOrSelf } from '@gridsuite/commons-ui'; import { MappingInfos } from 'services/study/dynamic-simulation.type'; import { MAPPING } from './dynamic-simulation-utils'; diff --git a/src/components/dialogs/percentage-area/percentage-area.tsx b/src/components/dialogs/percentage-area/percentage-area.tsx index 09f2b10475..1800949aa4 100644 --- a/src/components/dialogs/percentage-area/percentage-area.tsx +++ b/src/components/dialogs/percentage-area/percentage-area.tsx @@ -6,12 +6,11 @@ */ import { Grid, Typography } from '@mui/material'; -import { percentageTextField, standardTextField } from '../dialog-utils'; import { LEFT_SIDE_PERCENTAGE, RIGHT_SIDE_PERCENTAGE, SLIDER_PERCENTAGE } from 'components/utils/field-constants'; import { useFormContext } from 'react-hook-form'; import { formatPercentageValue, isValidPercentage, sanitizePercentageValue } from './percentage-area-utils'; import { FormattedMessage } from 'react-intl'; -import { Input, SliderInput, TextInput } from '@gridsuite/commons-ui'; +import { Input, PercentageAdornment, SliderInput, standardTextField, TextInput } from '@gridsuite/commons-ui'; /** * Component to handle a 'percentage area' (slider , left and right percentage fields) @@ -65,7 +64,7 @@ export function PercentageArea({ upperLeftText, upperRightText }: Readonly { } }, [copyInfos, studyUuid, currentNode?.id, networkModificationsToCopy, cleanClipboard, snackError]); - const removeNullFields = useCallback((data: NetworkModificationData) => { - let dataTemp = data; - if (dataTemp) { - Object.keys(dataTemp).forEach((key) => { - if (dataTemp[key] && dataTemp[key] !== null && typeof dataTemp[key] === 'object') { - dataTemp[key] = removeNullFields(dataTemp[key]); - } - - if (dataTemp[key] === null) { - delete dataTemp[key]; - } - }); - } - return dataTemp; - }, []); - const doEditModification = useCallback( (modificationUuid: UUID, modificationType: ModificationType) => { setIsUpdate(true); @@ -1044,7 +1029,7 @@ const NetworkModificationNodeEditor = () => { setEditDataFetchStatus(FetchStatus.FAILED); }); }, - [removeNullFields, snackError] + [snackError] ); const onItemClick = (id: string) => { diff --git a/src/components/network/selection-creation-panel/selection-creation-panel-form.tsx b/src/components/network/selection-creation-panel/selection-creation-panel-form.tsx index c532622e02..45ab715c17 100644 --- a/src/components/network/selection-creation-panel/selection-creation-panel-form.tsx +++ b/src/components/network/selection-creation-panel/selection-creation-panel-form.tsx @@ -4,7 +4,7 @@ * 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 { SelectInput, TextInput } from '@gridsuite/commons-ui'; +import { SelectInput, TextInput, Nullable } from '@gridsuite/commons-ui'; import { Grid } from '@mui/material'; import { NAME, SELECTION_TYPE } from 'components/utils/field-constants'; @@ -13,7 +13,6 @@ import { useWatch } from 'react-hook-form'; import { ContingencyFilterCreationFields } from './contingency-filter-creation/contingency-filter-creation-fields'; import { SELECTION_TYPES, selectionTypeToLabel } from './selection-types'; import { SelectionCreationPaneFields } from './selection-creation-schema'; -import { Nullable } from 'components/utils/ts-utils'; import GridSection from '../../dialogs/commons/grid-section'; interface SelectionCreationPanelFormProps { diff --git a/src/components/network/selection-creation-panel/selection-creation-panel-submit-button.tsx b/src/components/network/selection-creation-panel/selection-creation-panel-submit-button.tsx index f6a3643919..01b1a55492 100644 --- a/src/components/network/selection-creation-panel/selection-creation-panel-submit-button.tsx +++ b/src/components/network/selection-creation-panel/selection-creation-panel-submit-button.tsx @@ -10,7 +10,7 @@ import { useFormContext, useWatch } from 'react-hook-form'; import { FormattedMessage } from 'react-intl'; import { SELECTION_TYPES } from './selection-types'; import { SelectionCreationPaneFields } from './selection-creation-schema'; -import { Nullable } from 'components/utils/ts-utils'; +import { Nullable } from '@gridsuite/commons-ui'; interface SelectionCreationPanelSubmitButtonProps { handleValidate: (formData: SelectionCreationPaneFields) => void; diff --git a/src/components/network/selection-creation-panel/selection-creation-panel.tsx b/src/components/network/selection-creation-panel/selection-creation-panel.tsx index 17a07a8a84..b55931bbfd 100644 --- a/src/components/network/selection-creation-panel/selection-creation-panel.tsx +++ b/src/components/network/selection-creation-panel/selection-creation-panel.tsx @@ -13,6 +13,7 @@ import { EquipmentType, fetchDirectoryElementPath, Identifiable, + Nullable, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { useForm } from 'react-hook-form'; @@ -29,7 +30,6 @@ import { useSelector } from 'react-redux'; import { useSaveMap } from './use-save-map'; import { SelectionCreationPanelSubmitButton } from './selection-creation-panel-submit-button'; import { SELECTION_TYPES } from './selection-types'; -import { Nullable } from 'components/utils/ts-utils'; import { AppState } from 'redux/reducer'; import { SelectionCreationPanelForm } from './selection-creation-panel-form'; import { diff --git a/src/components/tooltips/load/load-popover-content.tsx b/src/components/tooltips/load/load-popover-content.tsx index 0700436cae..bed1487d21 100644 --- a/src/components/tooltips/load/load-popover-content.tsx +++ b/src/components/tooltips/load/load-popover-content.tsx @@ -9,7 +9,7 @@ import { Grid, Table, TableBody, TableContainer, TableRow } from '@mui/material' import { CellRender } from '../cell-render'; import { formatValue, styles } from '../generic-equipment-popover-utils'; import { LoadEquipmentInfos } from '../equipment-popover-type'; -import { getPropertyValue } from 'components/dialogs/network-modifications/common/properties/property-utils'; +import { getPropertyValue } from '@gridsuite/commons-ui'; interface LoadPopoverContentProps { equipmentInfos: LoadEquipmentInfos; } diff --git a/src/components/utils/field-constants.ts b/src/components/utils/field-constants.ts index 32b0d3a41b..7b8b3cc804 100644 --- a/src/components/utils/field-constants.ts +++ b/src/components/utils/field-constants.ts @@ -326,14 +326,6 @@ export const REPLACING_LINE_2_ID = 'replacingLine2Id'; export const REPLACING_LINE_1_NAME = 'replacingLine1Name'; export const REPLACING_LINE_2_NAME = 'replacingLine2Name'; -// substation -export const COUNTRY = 'country'; -export const VALUE = 'value'; -export const PREVIOUS_VALUE = 'previousValue'; -export const ADDED = 'added'; -export const DELETION_MARK = 'deletionMark'; -export const ADDITIONAL_PROPERTIES = 'AdditionalProperties'; - // generation dispatch export const LOSS_COEFFICIENT = 'lossCoefficient'; export const DEFAULT_OUTAGE_RATE = 'defaultOutageRate'; diff --git a/src/components/utils/inputs/input-hooks.tsx b/src/components/utils/inputs/input-hooks.tsx index 6cc357d181..0e76dcbb52 100644 --- a/src/components/utils/inputs/input-hooks.tsx +++ b/src/components/utils/inputs/input-hooks.tsx @@ -10,11 +10,17 @@ import { FormattedMessage, useIntl } from 'react-intl'; import { TextField, Tooltip, Button, Grid, TextFieldProps } from '@mui/material'; import IconButton from '@mui/material/IconButton'; -import { styles } from '../../dialogs/dialog-utils'; import { TOOLTIP_DELAY } from '../../../utils/UIconstants'; import { useCSVReader } from 'react-papaparse'; import { LANG_FRENCH } from '@gridsuite/commons-ui'; +export const styles = { + tooltip: { + fontSize: 18, + maxWidth: 'none', + }, +}; + interface UseButtonWithTooltipProps { handleClick: React.MouseEventHandler; label: string; diff --git a/src/components/utils/rhf-inputs/country-selection-input.tsx b/src/components/utils/rhf-inputs/country-selection-input.tsx deleted file mode 100644 index 5955dacdde..0000000000 --- a/src/components/utils/rhf-inputs/country-selection-input.tsx +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2023, 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 { AutocompleteInput, AutocompleteInputProps } from '@gridsuite/commons-ui'; -import { useLocalizedCountries } from '../localized-countries-hook'; - -interface CountrySelectionInputProps extends Omit {} - -const CountrySelectionInput = (props: CountrySelectionInputProps) => { - const { translate, countryCodes } = useLocalizedCountries(); - - return ( - translate(countryCode as string)} - {...props} - /> - ); -}; - -export default CountrySelectionInput; diff --git a/src/components/utils/rhf-inputs/expandable-input/deletable-row.tsx b/src/components/utils/rhf-inputs/expandable-input/deletable-row.tsx deleted file mode 100644 index c6e870056e..0000000000 --- a/src/components/utils/rhf-inputs/expandable-input/deletable-row.tsx +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (c) 2024, 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 { PropsWithChildren, useState } from 'react'; -import { useIntl } from 'react-intl'; -import { Grid, IconButton, Tooltip } from '@mui/material'; -import RestoreFromTrashIcon from '@mui/icons-material/RestoreFromTrash'; -import DeleteIcon from '@mui/icons-material/Delete'; - -export interface DeletableRowProps extends PropsWithChildren { - alignItems: string; - onClick: () => void; - deletionMark?: boolean | null; - disabledDeletion?: boolean | null; -} - -export function DeletableRow({ - alignItems, - onClick, - deletionMark, - disabledDeletion, - children, -}: Readonly) { - const intl = useIntl(); - const [isMouseHover, setIsMouseHover] = useState(false); - - return ( - setIsMouseHover(true)} - onMouseLeave={() => setIsMouseHover(false)} - > - {children} - - {isMouseHover && !disabledDeletion && ( - - - {deletionMark ? : } - - - )} - - - ); -} diff --git a/src/components/utils/rhf-inputs/expandable-input/expandable-input.tsx b/src/components/utils/rhf-inputs/expandable-input/expandable-input.tsx deleted file mode 100644 index 4608dd2193..0000000000 --- a/src/components/utils/rhf-inputs/expandable-input/expandable-input.tsx +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright (c) 2023, 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 { useFieldArray } from 'react-hook-form'; -import { Button, Grid } from '@mui/material'; -import AddIcon from '@mui/icons-material/ControlPoint'; -import { FormattedMessage } from 'react-intl'; -import { FunctionComponent } from 'react'; -import { styles } from '../../../dialogs/dialog-utils'; -import { ErrorInput, mergeSx, MidFormError } from '@gridsuite/commons-ui'; -import { DeletableRow } from './deletable-row'; - -export interface ExpandableInputProps { - name: string; - Field: React.ComponentType; - fieldProps?: any; - addButtonLabel?: string; - initialValue?: any; - getDeletionMark?: (idx: number) => boolean | null; - deleteCallback?: (idx: number) => boolean | null; - alignItems?: string; - watchProps?: boolean; - disabled?: boolean; - disabledDeletion?: (idx: number) => boolean | null; -} - -// This component is used to display Array of objects. -// We can manage 2 states for deletion: -// - only 1 state and 1 delete icon that removes the current line -// - a second state "mark for deletion" with a second icon: the line is not removed -// and we can cancel this mark to go back to normal state. -export const ExpandableInput: FunctionComponent = ({ - name, - Field, // Used to display each object of an array - fieldProps, // Props to pass to Field - addButtonLabel, - initialValue, // Initial value to display when we add a new entry to array - getDeletionMark = null, - deleteCallback = null, - alignItems = 'stretch', // default value for a flex container - watchProps = true, - disabled = false, - disabledDeletion = null, -}) => { - const { - fields: values, - append, - remove, - } = useFieldArray({ - name: name, - }); - - return ( - - - - - {watchProps && - values.map((value, idx) => ( - { - const shouldRemove = deleteCallback ? deleteCallback(idx) : true; - if (shouldRemove) { - remove(idx); - } - }} - deletionMark={getDeletionMark?.(idx)} - disabledDeletion={disabledDeletion?.(idx)} - > - - - ))} - - - - - ); -}; diff --git a/src/components/utils/rhf-inputs/expandable-input/index.ts b/src/components/utils/rhf-inputs/expandable-input/index.ts deleted file mode 100644 index bb1bb5cc32..0000000000 --- a/src/components/utils/rhf-inputs/expandable-input/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Copyright (c) 2024, 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/. - */ - -export * from './expandable-input'; diff --git a/src/components/utils/ts-utils.ts b/src/components/utils/ts-utils.ts deleted file mode 100644 index 22926c9ded..0000000000 --- a/src/components/utils/ts-utils.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright (c) 2024, 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/. - */ -export type Nullable = { [K in keyof T]: T[K] | null }; -export type DeepNullable = { - [K in keyof T]: DeepNullable | null; -}; - -export function notUndefined(value: T | undefined): value is T { - return value !== undefined; -} - -export function notNull(value: T | null): value is T { - return value !== null; -} diff --git a/src/services/network-modification-types.ts b/src/services/network-modification-types.ts index 0ecf4f830c..1f6c668660 100644 --- a/src/services/network-modification-types.ts +++ b/src/services/network-modification-types.ts @@ -6,7 +6,6 @@ */ import type { UUID } from 'node:crypto'; -import { Property } from '../components/dialogs/network-modifications/common/properties/property-utils'; import { DataType, FieldValue, @@ -14,7 +13,7 @@ import { import { Filter } from '../components/dialogs/network-modifications/by-filter/commons/by-filter.type'; import { ConverterStationElementModificationInfos } from '../components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-type'; import { ReactiveCapabilityCurvePoints } from '../components/dialogs/reactive-limits/reactive-limits.type'; -import { ModificationType, Option } from '@gridsuite/commons-ui'; +import { ModificationType, Option, Property } from '@gridsuite/commons-ui'; import { ENABLE_OLG_MODIFICATION } from '../components/utils/field-constants'; import { VARIATION_TYPES } from '../components/network/constants'; import { OperationalLimitsGroupFormSchema } from '../components/dialogs/limits/operational-limits-groups-types'; diff --git a/src/services/network-modification.ts b/src/services/network-modification.ts index 3cb84eb038..cc8ba5c7cd 100644 --- a/src/services/network-modification.ts +++ b/src/services/network-modification.ts @@ -5,21 +5,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { backendFetch, backendFetchJson } from '@gridsuite/commons-ui'; -import type { UUID } from 'node:crypto'; +import { backendFetchJson } from '@gridsuite/commons-ui'; import { LineTypeInfo } from '../components/dialogs/line-types-catalog/line-catalog.type'; const PREFIX_NETWORK_MODIFICATION_QUERIES = import.meta.env.VITE_API_GATEWAY + '/network-modification'; -export function fetchNetworkModification(modificationUuid: UUID) { - const modificationFetchUrl = `${PREFIX_NETWORK_MODIFICATION_QUERIES}/v1/network-modifications/${encodeURIComponent( - modificationUuid - )}`; - - console.debug(modificationFetchUrl); - return backendFetch(modificationFetchUrl); -} - export function getLineTypesCatalog(): Promise { console.info(`get line types catalog`); const url = `${PREFIX_NETWORK_MODIFICATION_QUERIES}/v1/network-modifications/catalog/line_types`; diff --git a/src/services/study/index.ts b/src/services/study/index.ts index 3c20ee0732..06c4be02dc 100644 --- a/src/services/study/index.ts +++ b/src/services/study/index.ts @@ -16,14 +16,11 @@ import { EquipmentType, ExtendedEquipmentType, Parameter, + safeEncodeURIComponent, } from '@gridsuite/commons-ui'; import { NetworkModificationCopyInfos } from 'components/graph/menus/network-modifications/network-modification-menu.type'; import type { Svg } from 'components/grid-layout/cards/diagrams/diagram.type'; -export function safeEncodeURIComponent(value: string | null | undefined): string { - return value != null ? encodeURIComponent(value) : ''; -} - export const PREFIX_STUDY_QUERIES = import.meta.env.VITE_API_GATEWAY + '/study'; export const getStudyUrl = (studyUuid: UUID | null) => diff --git a/src/services/study/network-map.type.ts b/src/services/study/network-map.type.ts index bfa7aae93c..75ed289e2c 100644 --- a/src/services/study/network-map.type.ts +++ b/src/services/study/network-map.type.ts @@ -5,9 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { LimitsProperty } from '../network-modification-types'; -import { Equipment } from '../../components/dialogs/network-modifications/common/properties/property-utils'; import { BusBarSections } from '../../components/dialogs/network-modifications/voltage-level/section/voltage-level-section.type'; import { ConnectablePositionInfos } from '../../components/dialogs/connectivity/connectivity.type'; +import { EquipmentWithProperties } from '@gridsuite/commons-ui'; export type SwitchInfos = { id: string; @@ -31,7 +31,7 @@ interface FeederBay { export type FeederBaysInfos = Record; -export type BranchInfos = Equipment & { +export type BranchInfos = EquipmentWithProperties & { name: string; voltageLevelId1: string; voltageLevelId2: string; diff --git a/src/services/study/network-modifications.ts b/src/services/study/network-modifications.ts index dc28b1f600..e3389e2e4b 100644 --- a/src/services/study/network-modifications.ts +++ b/src/services/study/network-modifications.ts @@ -14,9 +14,10 @@ import { MODIFICATION_TYPES, ModificationType, NetworkModificationMetadata, + safeEncodeURIComponent, } from '@gridsuite/commons-ui'; import { toModificationOperation } from '../../components/utils/utils'; -import { getStudyUrlWithNodeUuid, getStudyUrlWithNodeUuidAndRootNetworkUuid, safeEncodeURIComponent } from './index'; +import { getStudyUrlWithNodeUuid, getStudyUrlWithNodeUuidAndRootNetworkUuid } from './index'; import { EQUIPMENT_TYPES } from '../../components/utils/equipment-types'; import { BRANCH_SIDE, OPERATING_STATUS_ACTION } from '../../components/network/constants'; import type { UUID } from 'node:crypto'; @@ -61,13 +62,13 @@ import { } from '../network-modification-types'; import { Filter } from '../../components/dialogs/network-modifications/by-filter/commons/by-filter.type'; import { ExcludedNetworkModifications } from 'components/graph/menus/network-modifications/network-modification-menu.type'; -import { TabularProperty } from '../../components/dialogs/network-modifications/tabular/properties/property-utils'; import { Modification } from '../../components/dialogs/network-modifications/tabular/tabular-common'; import { ENABLE_OLG_MODIFICATION, OLGS_MODIFICATION_TYPE, OPERATIONAL_LIMITS_GROUPS_MODIFICATION_TYPE, } from '../../components/utils/field-constants'; +import { TabularProperty } from '../../components/dialogs/network-modifications/tabular/properties/property-utils'; function getNetworkModificationUrl(studyUuid: string | null | undefined, nodeUuid: string | undefined) { return getStudyUrlWithNodeUuid(studyUuid, nodeUuid) + '/network-modifications'; diff --git a/src/services/study/network.ts b/src/services/study/network.ts index 58430dd00f..c11774969a 100644 --- a/src/services/study/network.ts +++ b/src/services/study/network.ts @@ -14,9 +14,10 @@ import { EquipmentType, ExtendedEquipmentType, type Identifiable, + safeEncodeURIComponent, } from '@gridsuite/commons-ui'; import type { MapHvdcLine, MapLine, MapSubstation, MapTieLine } from '@powsybl/network-viewer'; -import { getStudyUrlWithNodeUuidAndRootNetworkUuid, PREFIX_STUDY_QUERIES, safeEncodeURIComponent } from './index'; +import { getStudyUrlWithNodeUuidAndRootNetworkUuid, PREFIX_STUDY_QUERIES } from './index'; import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES, type VoltageLevel } from '../../components/utils/equipment-types'; import { getQueryParamsList } from '../utils'; import { BusBarSectionsInfos, FeederBaysInfos, SwitchInfos } from './network-map.type'; diff --git a/src/translations/en.json b/src/translations/en.json index 979bacb615..7b098d202f 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -73,7 +73,6 @@ "geoDataLoadingFail": "An error occurred while loading geographical data.", "parameters": "Parameters", - "button.restore": "Restore", "close": "Close", "validate": "Validate", @@ -123,8 +122,6 @@ "Spreadsheet": "Spreadsheet", "Results": "Results", "ID": "ID", - "Name": "Name", - "Country": "Country", "Country1": "Country 1", "Country2": "Country 2", "Properties": "Properties", @@ -855,15 +852,8 @@ "minSusceptance": "Susceptance min", "b0": "Fixed part of susceptance", "shuntCompensatorType": "Type", - "CreateSubstation": "Create substation", - "SubstationCreationError": "Error while creating substation", - "AdditionalInformation": "Additional information", "Information": "Information", "Property": "Property", - "AddProperty": "Add property", - "PropertyName": "Property name", - "PropertyValue": "Property value", - "DuplicatedPropsError": "Duplicated properties: each property must be unique", "FillAllFields": "Please fill all fields", "ModifySubstation": "Modify substation", "ModifyVsc": "Modify HVDC (VSC)", diff --git a/src/translations/fr.json b/src/translations/fr.json index 1b998ad5bc..21f155c63e 100644 --- a/src/translations/fr.json +++ b/src/translations/fr.json @@ -73,7 +73,6 @@ "geoDataLoadingFail": "Erreur lors du chargement des données géographiques.", "parameters": "Paramètres", - "button.restore": "Restaurer", "close": "Fermer", "validate": "Valider", @@ -123,8 +122,6 @@ "Spreadsheet": "Tableur", "Results": "Résultats", "ID": "ID", - "Name": "Nom", - "Country": "Pays", "Country1": "Pays 1", "Country2": "Pays 2", "Properties": "Propriétés", @@ -847,15 +844,8 @@ "maximumSusceptance": "Susceptance max", "minSusceptance": "Susceptance min", "shuntCompensatorType": "Type", - "CreateSubstation": "Créer un site", - "SubstationCreationError": "Erreur lors de la création d'un site", - "AdditionalInformation": "Informations complémentaires", "Information": "Information", "Property": "Propriété", - "AddProperty": "Ajouter une propriété", - "PropertyName": "Nom de la propriété", - "PropertyValue": "Valeur de la propriété", - "DuplicatedPropsError": "Propriétés dupliquées : chaque propriété doit être unique", "FillAllFields": "Veuillez remplir tous les champs", "ModifySubstation": "Modifier un site", "ModifyVsc": "Modifier une HVDC (VSC)",