diff --git a/src/components/dialogs/network-modifications/battery/modification/battery-modification-dialog.jsx b/src/components/dialogs/network-modifications/battery/modification/battery-modification-dialog.jsx index 895036b95f..ff73c17176 100644 --- a/src/components/dialogs/network-modifications/battery/modification/battery-modification-dialog.jsx +++ b/src/components/dialogs/network-modifications/battery/modification/battery-modification-dialog.jsx @@ -45,11 +45,8 @@ import { getReactiveLimitsSchema, } from '../../../reactive-limits/reactive-limits-utils'; import { - calculateCurvePointsToStore, - completeReactiveCapabilityCurvePointsData, - getRowEmptyFormData, - insertEmptyRowAtSecondToLastIndex, REMOVE, + setCurrentReactiveCapabilityCurveTable, } from '../../../reactive-limits/reactive-capability-curve/reactive-capability-utils'; import { useOpenShortWaitFetching } from '../../../commons/handle-modification-form'; import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES } from 'components/utils/equipment-types'; @@ -73,6 +70,7 @@ import { getConnectivityWithPositionEmptyFormData, getConnectivityWithPositionValidationSchema, } from '../../../connectivity/connectivity-form-utils'; +import { isNodeBuilt } from '../../../../graph/util/model-functions'; const emptyFormData = { [EQUIPMENT_NAME]: '', @@ -156,10 +154,7 @@ const BatteryModificationDialog = ({ reactiveCapabilityCurveChoice: editData?.reactiveCapabilityCurve?.value ? 'CURVE' : 'MINMAX', maximumReactivePower: editData?.maxQ?.value ?? null, minimumReactivePower: editData?.minQ?.value ?? null, - reactiveCapabilityCurveTable: - editData?.reactiveCapabilityCurvePoints?.length > 0 - ? completeReactiveCapabilityCurvePointsData(editData?.reactiveCapabilityCurvePoints) - : [getRowEmptyFormData(), getRowEmptyFormData()], + reactiveCapabilityCurveTable: editData?.reactiveCapabilityCurvePoints ?? null, }), ...getPropertiesFromModification(editData.properties), }); @@ -203,7 +198,7 @@ const BatteryModificationDialog = ({ setDataFetchStatus(FetchStatus.RUNNING); fetchNetworkElementInfos( studyUuid, - currentNodeUuid, + currentNode.id, EQUIPMENT_TYPES.BATTERY, EQUIPMENT_INFOS_TYPES.FORM.type, equipmentId, @@ -211,35 +206,15 @@ const BatteryModificationDialog = ({ ) .then((value) => { if (value) { - // when editing modification form, first render should not trigger this reset - // which would empty the form instead of displaying data of existing form - const previousReactiveCapabilityCurveTable = value.reactiveCapabilityCurvePoints; - // on first render, we need to adjust the UI for the reactive capability curve table - // we need to check if the battery we fetch has reactive capability curve table + const previousReactiveCapabilityCurveTable = value?.reactiveCapabilityCurvePoints; if (previousReactiveCapabilityCurveTable) { - const currentReactiveCapabilityCurveTable = getValues( - `${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}` + setCurrentReactiveCapabilityCurveTable( + previousReactiveCapabilityCurveTable, + `${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}`, + getValues, + setValue, + isNodeBuilt(currentNode) ); - - const sizeDiff = - previousReactiveCapabilityCurveTable.length - - currentReactiveCapabilityCurveTable.length; - - // if there are more values in previousValues table, we need to insert rows to current tables to match the number of previousValues table rows - if (sizeDiff > 0) { - for (let i = 0; i < sizeDiff; i++) { - insertEmptyRowAtSecondToLastIndex(currentReactiveCapabilityCurveTable); - } - setValue( - `${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}`, - currentReactiveCapabilityCurveTable - ); - } else if (sizeDiff < 0) { - // if there are more values in current table, we need to add rows to previousValues tables to match the number of current table rows - for (let i = 0; i > sizeDiff; i--) { - insertEmptyRowAtSecondToLastIndex(previousReactiveCapabilityCurveTable); - } - } } setValue( `${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_CHOICE}`, @@ -270,7 +245,7 @@ const BatteryModificationDialog = ({ setBatteryToModify(null); } }, - [studyUuid, currentNodeUuid, getValues, setValue, setValuesAndEmptyOthers, reset, editData] + [studyUuid, currentNode, getValues, setValue, setValuesAndEmptyOthers, reset, editData] ); useEffect(() => { @@ -282,11 +257,6 @@ const BatteryModificationDialog = ({ const onSubmit = useCallback( (battery) => { const reactiveLimits = battery[REACTIVE_LIMITS]; - const buildCurvePointsToStore = calculateCurvePointsToStore( - reactiveLimits[REACTIVE_CAPABILITY_CURVE_TABLE], - batteryToModify - ); - const isReactiveCapabilityCurveOn = reactiveLimits[REACTIVE_CAPABILITY_CURVE_CHOICE] === 'CURVE'; modifyBattery({ @@ -310,7 +280,9 @@ const BatteryModificationDialog = ({ isReactiveCapabilityCurveOn: isReactiveCapabilityCurveOn, maxQ: isReactiveCapabilityCurveOn ? null : reactiveLimits[MAXIMUM_REACTIVE_POWER], minQ: isReactiveCapabilityCurveOn ? null : reactiveLimits[MINIMUM_REACTIVE_POWER], - reactiveCapabilityCurve: isReactiveCapabilityCurveOn ? buildCurvePointsToStore : null, + reactiveCapabilityCurve: isReactiveCapabilityCurveOn + ? reactiveLimits[REACTIVE_CAPABILITY_CURVE_TABLE] + : null, properties: toModificationProperties(battery), }).catch((error) => { snackError({ @@ -319,7 +291,7 @@ const BatteryModificationDialog = ({ }); }); }, - [selectedId, batteryToModify, studyUuid, currentNodeUuid, editData?.uuid, snackError] + [selectedId, studyUuid, currentNodeUuid, editData?.uuid, snackError] ); const open = useOpenShortWaitFetching({ diff --git a/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-constants.ts b/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-constants.ts index 193452066f..6e829d76d7 100644 --- a/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-constants.ts +++ b/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-constants.ts @@ -102,16 +102,16 @@ export const FIELD_OPTIONS = { label: 'sectionCount', dataType: DataType.INTEGER, }, - MAXIMUM_SUSCEPTANCE: { - id: FieldType.MAXIMUM_SUSCEPTANCE, + MAX_SUSCEPTANCE: { + id: FieldType.MAX_SUSCEPTANCE, label: 'maxSusceptance', unit: MICRO_SIEMENS, dataType: DataType.DOUBLE, outputConverter: (value) => microUnitToUnit(value), inputConverter: (value) => unitToMicroUnit(value), }, - MAXIMUM_Q_AT_NOMINAL_VOLTAGE: { - id: FieldType.MAXIMUM_Q_AT_NOMINAL_VOLTAGE, + MAX_Q_AT_NOMINAL_V: { + id: FieldType.MAX_Q_AT_NOMINAL_V, label: 'maxQAtNominalV', unit: MICRO_SIEMENS, dataType: DataType.DOUBLE, @@ -314,8 +314,8 @@ export const EQUIPMENTS_FIELDS = { FIELD_OPTIONS.PROPERTY, FIELD_OPTIONS.MAXIMUM_SECTION_COUNT, FIELD_OPTIONS.SECTION_COUNT, - FIELD_OPTIONS.MAXIMUM_SUSCEPTANCE, - FIELD_OPTIONS.MAXIMUM_Q_AT_NOMINAL_VOLTAGE, + FIELD_OPTIONS.MAX_SUSCEPTANCE, + FIELD_OPTIONS.MAX_Q_AT_NOMINAL_V, ], [EquipmentType.STATIC_VAR_COMPENSATOR]: [FIELD_OPTIONS.PROPERTY], [EquipmentType.HVDC_LINE]: [FIELD_OPTIONS.PROPERTY], diff --git a/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment.type.ts b/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment.type.ts index 4b2d59f43c..84ecd2651f 100644 --- a/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment.type.ts +++ b/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment.type.ts @@ -55,8 +55,8 @@ export enum FieldType { VOLTAGE_REGULATOR_ON = 'VOLTAGE_REGULATOR_ON', MAXIMUM_SECTION_COUNT = 'MAXIMUM_SECTION_COUNT', SECTION_COUNT = 'SECTION_COUNT', - MAXIMUM_SUSCEPTANCE = 'MAXIMUM_SUSCEPTANCE', - MAXIMUM_Q_AT_NOMINAL_VOLTAGE = 'MAXIMUM_Q_AT_NOMINAL_VOLTAGE', + MAX_SUSCEPTANCE = 'MAX_SUSCEPTANCE', + MAX_Q_AT_NOMINAL_V = 'MAX_Q_AT_NOMINAL_V', NOMINAL_VOLTAGE = 'NOMINAL_VOLTAGE', LOW_VOLTAGE_LIMIT = 'LOW_VOLTAGE_LIMIT', HIGH_VOLTAGE_LIMIT = 'HIGH_VOLTAGE_LIMIT', diff --git a/src/components/dialogs/network-modifications/by-filter/by-formula/formula/formula-utils.tsx b/src/components/dialogs/network-modifications/by-filter/by-formula/formula/formula-utils.tsx index f7175f3c28..d5380dba60 100644 --- a/src/components/dialogs/network-modifications/by-filter/by-formula/formula/formula-utils.tsx +++ b/src/components/dialogs/network-modifications/by-filter/by-formula/formula/formula-utils.tsx @@ -69,8 +69,8 @@ export const EQUIPMENTS_FIELDS: EquipmentFields = { [EQUIPMENT_TYPES.SHUNT_COMPENSATOR]: [ { id: 'MAXIMUM_SECTION_COUNT', label: 'maximumSectionCount' }, { id: 'SECTION_COUNT', label: 'sectionCount' }, - { id: 'MAXIMUM_SUSCEPTANCE', label: 'maxSusceptance' }, - { id: 'MAXIMUM_Q_AT_NOMINAL_VOLTAGE', label: 'maxQAtNominalV' }, + { id: 'MAX_SUSCEPTANCE', label: 'maxSusceptance' }, + { id: 'MAX_Q_AT_NOMINAL_V', label: 'maxQAtNominalV' }, ], [EQUIPMENT_TYPES.VOLTAGE_LEVEL]: [ { id: 'NOMINAL_VOLTAGE', label: 'NominalVoltage' }, diff --git a/src/components/dialogs/network-modifications/generator/modification/generator-modification-dialog.jsx b/src/components/dialogs/network-modifications/generator/modification/generator-modification-dialog.jsx index e86b6a1ace..da501f240f 100644 --- a/src/components/dialogs/network-modifications/generator/modification/generator-modification-dialog.jsx +++ b/src/components/dialogs/network-modifications/generator/modification/generator-modification-dialog.jsx @@ -61,11 +61,8 @@ import { } from '../../../reactive-limits/reactive-limits-utils'; import { getRegulatingTerminalFormData } from '../../../regulating-terminal/regulating-terminal-form-utils'; import { - calculateCurvePointsToStore, - completeReactiveCapabilityCurvePointsData, - getRowEmptyFormData, - insertEmptyRowAtSecondToLastIndex, REMOVE, + setCurrentReactiveCapabilityCurveTable, } from '../../../reactive-limits/reactive-capability-curve/reactive-capability-utils'; import { useOpenShortWaitFetching } from '../../../commons/handle-modification-form'; import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES } from 'components/utils/equipment-types'; @@ -85,6 +82,7 @@ import { getConnectivityWithPositionEmptyFormData, getConnectivityWithPositionValidationSchema, } from '../../../connectivity/connectivity-form-utils'; +import { isNodeBuilt } from '../../../../graph/util/model-functions'; const emptyFormData = { [EQUIPMENT_NAME]: '', @@ -193,10 +191,7 @@ const GeneratorModificationDialog = ({ reactiveCapabilityCurveChoice: editData?.reactiveCapabilityCurve?.value ? 'CURVE' : 'MINMAX', maximumReactivePower: editData?.maxQ?.value ?? null, minimumReactivePower: editData?.minQ?.value ?? null, - reactiveCapabilityCurveTable: - editData?.reactiveCapabilityCurvePoints?.length > 0 - ? completeReactiveCapabilityCurvePointsData(editData?.reactiveCapabilityCurvePoints) - : [getRowEmptyFormData(), getRowEmptyFormData()], + reactiveCapabilityCurveTable: editData?.reactiveCapabilityCurvePoints ?? null, }), ...getRegulatingTerminalFormData({ equipmentId: editData?.regulatingTerminalId?.value, @@ -246,7 +241,7 @@ const GeneratorModificationDialog = ({ setDataFetchStatus(FetchStatus.RUNNING); fetchNetworkElementInfos( studyUuid, - currentNodeUuid, + currentNode.id, EQUIPMENT_TYPES.GENERATOR, EQUIPMENT_INFOS_TYPES.FORM.type, equipmentId, @@ -254,35 +249,15 @@ const GeneratorModificationDialog = ({ ) .then((value) => { if (value) { - // when editing modification form, first render should not trigger this reset - // which would empty the form instead of displaying data of existing form - const previousReactiveCapabilityCurveTable = value.reactiveCapabilityCurvePoints; - // on first render, we need to adjust the UI for the reactive capability curve table - // we need to check if the generator we fetch has reactive capability curve table + const previousReactiveCapabilityCurveTable = value?.reactiveCapabilityCurvePoints; if (previousReactiveCapabilityCurveTable) { - const currentReactiveCapabilityCurveTable = getValues( - `${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}` + setCurrentReactiveCapabilityCurveTable( + previousReactiveCapabilityCurveTable, + `${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}`, + getValues, + setValue, + isNodeBuilt(currentNode) ); - - const sizeDiff = - previousReactiveCapabilityCurveTable.length - - currentReactiveCapabilityCurveTable.length; - - // if there are more values in previousValues table, we need to insert rows to current tables to match the number of previousValues table rows - if (sizeDiff > 0) { - for (let i = 0; i < sizeDiff; i++) { - insertEmptyRowAtSecondToLastIndex(currentReactiveCapabilityCurveTable); - } - setValue( - `${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}`, - currentReactiveCapabilityCurveTable - ); - } else if (sizeDiff < 0) { - // if there are more values in current table, we need to add rows to previousValues tables to match the number of current table rows - for (let i = 0; i > sizeDiff; i--) { - insertEmptyRowAtSecondToLastIndex(previousReactiveCapabilityCurveTable); - } - } } setValue(`${CONNECTIVITY}.${VOLTAGE_LEVEL}.${ID}`, value?.voltageLevelId); setValue(`${CONNECTIVITY}.${BUS_OR_BUSBAR_SECTION}.${ID}`, value?.busOrBusbarSectionId); @@ -309,7 +284,7 @@ const GeneratorModificationDialog = ({ setGeneratorToModify(null); } }, - [studyUuid, currentNodeUuid, reset, getValues, setValue, setValuesAndEmptyOthers, editData] + [studyUuid, currentNode, reset, getValues, setValue, setValuesAndEmptyOthers, editData] ); useEffect(() => { @@ -331,13 +306,7 @@ const GeneratorModificationDialog = ({ const onSubmit = useCallback( (generator) => { const reactiveLimits = generator[REACTIVE_LIMITS]; - const buildCurvePointsToStore = calculateCurvePointsToStore( - reactiveLimits[REACTIVE_CAPABILITY_CURVE_TABLE], - generatorToModify - ); - const isReactiveCapabilityCurveOn = reactiveLimits[REACTIVE_CAPABILITY_CURVE_CHOICE] === 'CURVE'; - const isDistantRegulation = generator?.[VOLTAGE_REGULATION_TYPE] === REGULATION_TYPES.DISTANT.id || (generator[VOLTAGE_REGULATION_TYPE] === null && @@ -379,7 +348,9 @@ const GeneratorModificationDialog = ({ droop: generator[DROOP], maxQ: isReactiveCapabilityCurveOn ? null : reactiveLimits[MAXIMUM_REACTIVE_POWER], minQ: isReactiveCapabilityCurveOn ? null : reactiveLimits[MINIMUM_REACTIVE_POWER], - reactiveCapabilityCurve: isReactiveCapabilityCurveOn ? buildCurvePointsToStore : null, + reactiveCapabilityCurve: isReactiveCapabilityCurveOn + ? reactiveLimits[REACTIVE_CAPABILITY_CURVE_TABLE] + : null, properties: toModificationProperties(generator), }).catch((error) => { snackError({ @@ -388,15 +359,7 @@ const GeneratorModificationDialog = ({ }); }); }, - [ - selectedId, - generatorToModify, - getPreviousRegulationType, - studyUuid, - currentNodeUuid, - editData?.uuid, - snackError, - ] + [selectedId, getPreviousRegulationType, studyUuid, currentNodeUuid, editData?.uuid, snackError] ); const open = useOpenShortWaitFetching({ 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 3947509472..678290ab08 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 @@ -40,11 +40,6 @@ import { } from '../../../../reactive-limits/reactive-limits-utils'; import { UNDEFINED_CONNECTION_DIRECTION } from '../../../../../network/constants'; import { sanitizeString } from '../../../../dialog-utils'; -import { - calculateCurvePointsToStore, - completeReactiveCapabilityCurvePointsData, - getRowEmptyFormData, -} from '../../../../reactive-limits/reactive-capability-curve/reactive-capability-utils'; import { toModificationOperation } from '../../../../../utils/utils'; export type UpdateReactiveCapabilityCurveTable = (action: string, index: number) => void; @@ -230,10 +225,6 @@ export function getConverterStationModificationData( converterStationToModify: ConverterStationElementModificationInfos | undefined ) { const reactiveLimits = converterStation[REACTIVE_LIMITS]; - const buildCurvePointsToStore = calculateCurvePointsToStore( - reactiveLimits[REACTIVE_CAPABILITY_CURVE_TABLE], - converterStationToModify - ); const isReactiveCapabilityCurveOn = reactiveLimits[REACTIVE_CAPABILITY_CURVE_CHOICE] === 'CURVE'; return { @@ -249,7 +240,9 @@ export function getConverterStationModificationData( reactiveCapabilityCurve: toModificationOperation(isReactiveCapabilityCurveOn), minQ: toModificationOperation(isReactiveCapabilityCurveOn ? null : reactiveLimits[MINIMUM_REACTIVE_POWER]), maxQ: toModificationOperation(isReactiveCapabilityCurveOn ? null : reactiveLimits[MAXIMUM_REACTIVE_POWER]), - reactiveCapabilityCurvePoints: isReactiveCapabilityCurveOn ? buildCurvePointsToStore : null, + reactiveCapabilityCurvePoints: isReactiveCapabilityCurveOn + ? reactiveLimits[REACTIVE_CAPABILITY_CURVE_TABLE] + : null, }; } @@ -313,7 +306,7 @@ function getConverterStationReactiveLimits(converterStation: ConverterStationInt reactiveCapabilityCurveChoice: 'MINMAX', minimumReactivePower: converterStation.minQ, maximumReactivePower: converterStation.maxQ, - reactiveCapabilityCurveTable: [getRowEmptyFormData(), getRowEmptyFormData()], + reactiveCapabilityCurveTable: converterStation?.reactiveCapabilityCurvePoints ?? null, }); } @@ -327,10 +320,7 @@ function getConverterStationModificationReactiveLimits( : 'MINMAX', maximumReactivePower: converterStationEditData?.maxQ?.value ?? null, minimumReactivePower: converterStationEditData?.minQ?.value ?? null, - reactiveCapabilityCurveTable: - converterStationEditData?.reactiveCapabilityCurvePoints?.length > 0 - ? completeReactiveCapabilityCurvePointsData(converterStationEditData?.reactiveCapabilityCurvePoints) - : [getRowEmptyFormData(), getRowEmptyFormData()], + reactiveCapabilityCurveTable: converterStationEditData?.reactiveCapabilityCurvePoints ?? null, }), }; } 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 563bf6989c..7a70f691a4 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 @@ -69,6 +69,7 @@ import { modificationPropertiesSchema, toModificationProperties, } from '../../../common/properties/property-utils'; +import { isNodeBuilt } from '../../../../../graph/util/model-functions'; const formSchema = yup .object() @@ -104,7 +105,6 @@ const VscModificationDialog: React.FC = ({ editDataFetchStatus, ...dialogProps }) => { - const currentNodeUuid = currentNode.id; const [tabIndex, setTabIndex] = useState(VSC_MODIFICATION_TABS.HVDC_LINE_TAB); const [equipmentId, setEquipmentId] = useState(null); // add defaultIdValue to preselect an equipment ? see GeneratorModificationDialog for an example @@ -161,7 +161,7 @@ const VscModificationDialog: React.FC = ({ setDataFetchStatus(FetchStatus.RUNNING); fetchNetworkElementInfos( studyUuid, - currentNodeUuid, + currentNode.id, EQUIPMENT_TYPES.HVDC_LINE, EQUIPMENT_INFOS_TYPES.FORM.type, equipmentId, @@ -179,7 +179,8 @@ const VscModificationDialog: React.FC = ({ previousReactiveCapabilityCurveTable1, `${CONVERTER_STATION_1}.${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}`, getValues, - setValue + setValue, + isNodeBuilt(currentNode) ); } @@ -190,7 +191,8 @@ const VscModificationDialog: React.FC = ({ previousReactiveCapabilityCurveTable2, `${CONVERTER_STATION_2}.${REACTIVE_LIMITS}.${REACTIVE_CAPABILITY_CURVE_TABLE}`, getValues, - setValue + setValue, + isNodeBuilt(currentNode) ); } setSelectedReactiveLimits( @@ -231,7 +233,7 @@ const VscModificationDialog: React.FC = ({ }); } }, - [setValuesAndEmptyOthers, studyUuid, currentNodeUuid, setValue, reset, getValues, editData?.equipmentId] + [setValuesAndEmptyOthers, studyUuid, currentNode, setValue, reset, getValues, editData?.equipmentId] ); useEffect(() => { diff --git a/src/components/dialogs/reactive-limits/reactive-capability-curve/reactive-capability-curve-row-form.jsx b/src/components/dialogs/reactive-limits/reactive-capability-curve/reactive-capability-curve-row-form.jsx index 78f5270953..9e2f63f9e8 100644 --- a/src/components/dialogs/reactive-limits/reactive-capability-curve/reactive-capability-curve-row-form.jsx +++ b/src/components/dialogs/reactive-limits/reactive-capability-curve/reactive-capability-curve-row-form.jsx @@ -6,19 +6,17 @@ */ import { FloatInput } from '@gridsuite/commons-ui'; -import { P, MAX_Q, MIN_Q } from 'components/utils/field-constants'; +import { MAX_Q, MIN_Q, P } from 'components/utils/field-constants'; import { ActivePowerAdornment, ReactivePowerAdornment } from '../../dialog-utils'; import GridItem from '../../commons/grid-item'; -const ReactiveCapabilityCurveRowForm = ({ id, index, labelSuffix, previousValues }) => { +const ReactiveCapabilityCurveRowForm = ({ id, index, labelSuffix }) => { const pField = ( ); @@ -28,8 +26,6 @@ const ReactiveCapabilityCurveRowForm = ({ id, index, labelSuffix, previousValues label={'QminP'} labelValues={{ labelSuffix: labelSuffix }} adornment={ReactivePowerAdornment} - previousValue={previousValues?.minQ} - clearable={true} /> ); @@ -39,8 +35,6 @@ const ReactiveCapabilityCurveRowForm = ({ id, index, labelSuffix, previousValues label={'QmaxP'} labelValues={{ labelSuffix: labelSuffix }} adornment={ReactivePowerAdornment} - previousValue={previousValues?.maxQ} - clearable={true} /> ); diff --git a/src/components/dialogs/reactive-limits/reactive-capability-curve/reactive-capability-curve-table.jsx b/src/components/dialogs/reactive-limits/reactive-capability-curve/reactive-capability-curve-table.jsx index 7310940293..fb7ef53630 100644 --- a/src/components/dialogs/reactive-limits/reactive-capability-curve/reactive-capability-curve-table.jsx +++ b/src/components/dialogs/reactive-limits/reactive-capability-curve/reactive-capability-curve-table.jsx @@ -12,8 +12,8 @@ import DeleteIcon from '@mui/icons-material/Delete'; import AddIcon from '@mui/icons-material/ControlPoint'; import { useFieldArray } from 'react-hook-form'; import ReactiveCapabilityCurveRowForm from './reactive-capability-curve-row-form'; -import { P, MAX_Q, MIN_Q } from 'components/utils/field-constants'; -import { MidFormError, ErrorInput } from '@gridsuite/commons-ui'; +import { MAX_Q, MIN_Q, P } from 'components/utils/field-constants'; +import { ErrorInput, MidFormError } from '@gridsuite/commons-ui'; import { INSERT, REMOVE } from './reactive-capability-utils'; const MIN_LENGTH = 2; @@ -87,7 +87,6 @@ export const ReactiveCapabilityCurveTable = ({ fieldId={value.id} index={index} labelSuffix={labelSuffix} - previousValues={previousValues?.[index]} /> [P]: yup.number().nullable().required(), }); -const getModificationRowSchema = () => - yup.object().shape({ - [MAX_Q]: yup.number().nullable(), - [MIN_Q]: yup - .number() - .nullable() - .when([MAX_Q], { - is: (value) => value != null, - then: (schema) => - schema.max(yup.ref(MAX_Q), 'ReactiveCapabilityCurveCreationErrorQminPQmaxPIncoherence'), - }), - [P]: yup.number().nullable(), - }); - export const getRowEmptyFormData = () => ({ [P]: null, [MAX_Q]: null, [MIN_Q]: null, }); -export const getReactiveCapabilityCurveEmptyFormData = (id = REACTIVE_CAPABILITY_CURVE_TABLE) => { - return { - [id]: [getRowEmptyFormData(), getRowEmptyFormData()], - }; -}; - -function getNotNullPFromArray(values, isEquipmentModification) { +function getNotNullPFromArray(values) { return values .map((element) => { const pValue = element[P]; @@ -67,14 +47,14 @@ function getNotNullPFromArray(values, isEquipmentModification) { .filter((p) => p !== null); } -function checkAllPValuesAreUnique(values, isEquipmentModification) { - const validActivePowerValues = getNotNullPFromArray(values, isEquipmentModification); +function checkAllPValuesAreUnique(values) { + const validActivePowerValues = getNotNullPFromArray(values); const setOfPs = [...new Set(validActivePowerValues)]; return setOfPs.length === validActivePowerValues.length; } -function checkAllPValuesBetweenMinMax(values, isEquipmentModification) { - const validActivePowerValues = getNotNullPFromArray(values, isEquipmentModification); +function checkAllPValuesBetweenMinMax(values) { + const validActivePowerValues = getNotNullPFromArray(values); const minP = validActivePowerValues[0]; const maxP = validActivePowerValues[validActivePowerValues.length - 1]; @@ -83,7 +63,6 @@ function checkAllPValuesBetweenMinMax(values, isEquipmentModification) { export const getReactiveCapabilityCurveValidationSchema = ( id = REACTIVE_CAPABILITY_CURVE_TABLE, - isEquipmentModification = false, positiveAndNegativePExist = false ) => ({ [id]: yup @@ -93,11 +72,7 @@ export const getReactiveCapabilityCurveValidationSchema = ( is: 'CURVE', then: (schema) => schema - .when([], { - is: () => !isEquipmentModification, - then: (schema) => schema.of(getCreationRowSchema()), - otherwise: (schema) => schema.of(getModificationRowSchema()), - }) + .of(getCreationRowSchema()) .when([], { is: () => positiveAndNegativePExist, then: (schema) => @@ -115,69 +90,14 @@ export const getReactiveCapabilityCurveValidationSchema = ( }) .min(2, 'ReactiveCapabilityCurveCreationErrorMissingPoints') .test('checkAllValuesAreUnique', 'ReactiveCapabilityCurveCreationErrorPInvalid', (values) => - checkAllPValuesAreUnique(values, isEquipmentModification) + checkAllPValuesAreUnique(values) ) .test('checkAllValuesBetweenMinMax', 'ReactiveCapabilityCurveCreationErrorPOutOfRange', (values) => - checkAllPValuesBetweenMinMax(values, isEquipmentModification) + checkAllPValuesBetweenMinMax(values) ), }), }); -export const completeReactiveCapabilityCurvePointsData = (reactiveCapabilityCurvePoints) => { - reactiveCapabilityCurvePoints.map((rcc) => { - if (!(P in rcc)) { - rcc[P] = null; - } - if (!(MAX_Q in rcc)) { - rcc[MAX_Q] = null; - } - if (!(MIN_Q in rcc)) { - rcc[MIN_Q] = null; - } - return rcc; - }); - return reactiveCapabilityCurvePoints; -}; - -export const insertEmptyRowAtSecondToLastIndex = (table) => { - table.splice(table.length - 1, 0, { - [P]: null, - [MAX_Q]: null, - [MIN_Q]: null, - }); -}; - -export const calculateCurvePointsToStore = (reactiveCapabilityCurve, equipmentToModify) => { - if (reactiveCapabilityCurve.every((point) => point.p == null && point.minQ == null && point.maxQ == null)) { - return null; - } else { - const pointsToStore = []; - reactiveCapabilityCurve.forEach((point, index) => { - if (point) { - const previousPoint = equipmentToModify?.reactiveCapabilityCurveTable?.[index]; - let pointToStore = { - p: point?.[P], - oldP: previousPoint?.p ?? null, - minQ: point?.minQ, - oldMinQ: previousPoint?.minQ ?? null, - maxQ: point?.maxQ, - oldMaxQ: previousPoint?.maxQ ?? null, - }; - pointsToStore.push(pointToStore); - } - }); - return pointsToStore.filter( - (point) => - point.p != null || - point.oldP != null || - point.maxQ != null || - point.oldMaxQ != null || - point.minQ != null || - point.oldMinQ != null - ); - } -}; - export function setSelectedReactiveLimits(id, minMaxReactiveLimits, setValue) { setValue(id, minMaxReactiveLimits ? 'MINMAX' : 'CURVE'); } @@ -186,26 +106,11 @@ export function setCurrentReactiveCapabilityCurveTable( previousReactiveCapabilityCurveTable, fieldKey, getValues, - setValue + setValue, + isNodeBuilt ) { - if (previousReactiveCapabilityCurveTable) { - const currentReactiveCapabilityCurveTable = getValues(fieldKey); - - const sizeDiff = previousReactiveCapabilityCurveTable.length - currentReactiveCapabilityCurveTable.length; - - // if there are more values in previousValues table, we need to insert rows to current tables to match the number of previousValues table rows - if (sizeDiff > 0) { - for (let i = 0; i < sizeDiff; i++) { - insertEmptyRowAtSecondToLastIndex(currentReactiveCapabilityCurveTable); - } - setValue(fieldKey, currentReactiveCapabilityCurveTable, { - shouldValidate: true, - }); - } else if (sizeDiff < 0) { - // if there are more values in current table, we need to add rows to previousValues tables to match the number of current table rows - for (let i = 0; i > sizeDiff; i--) { - insertEmptyRowAtSecondToLastIndex(previousReactiveCapabilityCurveTable); - } - } + const currentReactiveCapabilityCurveTable = getValues(fieldKey); + if (isNodeBuilt || !currentReactiveCapabilityCurveTable) { + setValue(fieldKey, previousReactiveCapabilityCurveTable); } } diff --git a/src/components/dialogs/reactive-limits/reactive-limits-utils.js b/src/components/dialogs/reactive-limits/reactive-limits-utils.js index 6210ca766f..a5557c1b86 100644 --- a/src/components/dialogs/reactive-limits/reactive-limits-utils.js +++ b/src/components/dialogs/reactive-limits/reactive-limits-utils.js @@ -67,11 +67,7 @@ export const getReactiveLimitsSchema = ( is: (minimumReactivePower) => !isEquipmentModification && minimumReactivePower != null, then: (schema) => schema.required(), }), - ...getReactiveCapabilityCurveValidationSchema( - REACTIVE_CAPABILITY_CURVE_TABLE, - isEquipmentModification, - positiveAndNegativePExist - ), + ...getReactiveCapabilityCurveValidationSchema(REACTIVE_CAPABILITY_CURVE_TABLE, positiveAndNegativePExist), }, [MAXIMUM_REACTIVE_POWER, MINIMUM_REACTIVE_POWER] ),