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..481fa0b883 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 @@ -6,9 +6,9 @@ */ import type { ReadonlyDeep } from 'type-fest'; -import { DataType, FieldOptionType, FieldType } from './assignment.type'; +import { DataType, FieldOptionType } from './assignment.type'; import { LOAD_TYPES } from '../../../../../network/constants'; -import { EquipmentType, kiloUnitToUnit, microUnitToUnit, unitToKiloUnit, unitToMicroUnit } from '@gridsuite/commons-ui'; +import { EquipmentType, FieldType } from '@gridsuite/commons-ui'; import { KILO_AMPERE, MICRO_SIEMENS } from '../../../../../utils/field-constants'; export const FIELD_OPTIONS = { @@ -102,21 +102,17 @@ 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, - outputConverter: (value) => microUnitToUnit(value), - inputConverter: (value) => unitToMicroUnit(value), }, NOMINAL_VOLTAGE: { id: FieldType.NOMINAL_VOLTAGE, @@ -138,16 +134,12 @@ export const FIELD_OPTIONS = { label: 'LowShortCircuitCurrentLimit', unit: KILO_AMPERE, dataType: DataType.DOUBLE, - outputConverter: (value) => kiloUnitToUnit(value), - inputConverter: (value) => unitToKiloUnit(value), }, HIGH_SHORT_CIRCUIT_CURRENT_LIMIT: { id: FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, label: 'HighShortCircuitCurrentLimit', unit: KILO_AMPERE, dataType: DataType.DOUBLE, - outputConverter: (value) => kiloUnitToUnit(value), - inputConverter: (value) => unitToKiloUnit(value), }, ACTIVE_POWER: { id: FieldType.ACTIVE_POWER, @@ -174,16 +166,12 @@ export const FIELD_OPTIONS = { label: 'G', unit: MICRO_SIEMENS, dataType: DataType.DOUBLE, - outputConverter: (value) => microUnitToUnit(value), - inputConverter: (value) => unitToMicroUnit(value), }, B: { id: FieldType.B, label: 'B', unit: MICRO_SIEMENS, dataType: DataType.DOUBLE, - outputConverter: (value) => microUnitToUnit(value), - inputConverter: (value) => unitToMicroUnit(value), }, RATED_U1: { id: FieldType.RATED_U1, @@ -314,8 +302,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-utils.ts b/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-utils.ts index b4a468345b..4c8dfe48c2 100644 --- a/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-utils.ts +++ b/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-utils.ts @@ -26,18 +26,6 @@ export const getFieldOption = (fieldName?: string | null) => { return Object.values(FIELD_OPTIONS).find((fieldOption) => fieldOption.id === fieldName); }; -export const convertOutputValue = (fieldName?: string | null, fieldValue?: FieldValue) => { - const fieldOption = getFieldOption(fieldName); - // @ts-expect-error TODO TS2339: Property outputConverter does not exist on typeof FIELD_OPTIONS[*] - return fieldOption?.outputConverter ? fieldOption.outputConverter(Number(fieldValue)) : fieldValue; -}; - -export const convertInputValue = (fieldName?: string | null, fieldValue?: FieldValue) => { - const fieldOption = getFieldOption(fieldName); - // @ts-expect-error TODO TS2339: Property inputConverter does not exist on typeof FIELD_OPTIONS[*] - return fieldOption?.inputConverter ? fieldOption.inputConverter(Number(fieldValue)) : fieldValue; -}; - // ("undefined" is accepted here in RHF, but it conflicts with MUI behaviour which does not like undefined values) export const getAssignmentInitialValue = () => ({ [FILTERS]: [], 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..d9a67d811d 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 @@ -36,52 +36,6 @@ export type FieldOptionType = { inputConverter?: (value: number) => number | undefined; }; -export enum FieldType { - PROPERTY = 'PROPERTY', - RATED_NOMINAL_POWER = 'RATED_NOMINAL_POWER', - MINIMUM_ACTIVE_POWER = 'MINIMUM_ACTIVE_POWER', - MAXIMUM_ACTIVE_POWER = 'MAXIMUM_ACTIVE_POWER', - ACTIVE_POWER_SET_POINT = 'ACTIVE_POWER_SET_POINT', - REACTIVE_POWER_SET_POINT = 'REACTIVE_POWER_SET_POINT', - VOLTAGE_SET_POINT = 'VOLTAGE_SET_POINT', - PLANNED_ACTIVE_POWER_SET_POINT = 'PLANNED_ACTIVE_POWER_SET_POINT', - MARGINAL_COST = 'MARGINAL_COST', - PLANNED_OUTAGE_RATE = 'PLANNED_OUTAGE_RATE', - FORCED_OUTAGE_RATE = 'FORCED_OUTAGE_RATE', - DROOP = 'DROOP', - TRANSIENT_REACTANCE = 'TRANSIENT_REACTANCE', - STEP_UP_TRANSFORMER_REACTANCE = 'STEP_UP_TRANSFORMER_REACTANCE', - Q_PERCENT = 'Q_PERCENT', - 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', - NOMINAL_VOLTAGE = 'NOMINAL_VOLTAGE', - LOW_VOLTAGE_LIMIT = 'LOW_VOLTAGE_LIMIT', - HIGH_VOLTAGE_LIMIT = 'HIGH_VOLTAGE_LIMIT', - LOW_SHORT_CIRCUIT_CURRENT_LIMIT = 'LOW_SHORT_CIRCUIT_CURRENT_LIMIT', - HIGH_SHORT_CIRCUIT_CURRENT_LIMIT = 'HIGH_SHORT_CIRCUIT_CURRENT_LIMIT', - ACTIVE_POWER = 'ACTIVE_POWER', - REACTIVE_POWER = 'REACTIVE_POWER', - R = 'R', - X = 'X', - G = 'G', - B = 'B', - RATED_U1 = 'RATED_U1', - RATED_U2 = 'RATED_U2', - RATED_S = 'RATED_S', - TARGET_V = 'TARGET_V', - RATIO_LOW_TAP_POSITION = 'RATIO_LOW_TAP_POSITION', - RATIO_TAP_POSITION = 'RATIO_TAP_POSITION', - RATIO_TARGET_DEADBAND = 'RATIO_TARGET_DEADBAND', - REGULATION_VALUE = 'REGULATION_VALUE', - PHASE_LOW_TAP_POSITION = 'PHASE_LOW_TAP_POSITION', - PHASE_TAP_POSITION = 'PHASE_TAP_POSITION', - PHASE_TARGET_DEADBAND = 'PHASE_TARGET_DEADBAND', - LOAD_TYPE = 'LOAD_TYPE', -} - // --- types for the form model --- // export type Assignment = { 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 5a553e0288..8d2e851f46 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 @@ -7,7 +7,13 @@ import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; -import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui'; +import { + convertInputValues, + convertOutputValues, + CustomFormProvider, + FieldType, + useSnackMessage, +} from '@gridsuite/commons-ui'; import { FC, useCallback, useEffect } from 'react'; import { FetchStatus } from '../../../../../services/utils'; import { useForm } from 'react-hook-form'; @@ -18,8 +24,6 @@ import ModificationByAssignmentForm from './modification-by-assignment-form'; import { ASSIGNMENTS, EDITED_FIELD, EQUIPMENT_TYPE_FIELD, VALUE_FIELD } from '../../../../utils/field-constants'; import { modifyByAssignment } from '../../../../../services/study/network-modifications'; import { - convertInputValue, - convertOutputValue, getAssignmentFromEditData, getAssignmentInitialValue, getAssignmentsSchema, @@ -72,7 +76,10 @@ const ModificationByAssignmentDialog: FC = ({ const assignments: Assignment[] = editData.assignmentInfosList?.map((info: Assignment) => { const assignment = getAssignmentFromEditData(info); - const valueConverted = convertInputValue(assignment[EDITED_FIELD], assignment[VALUE_FIELD]); + const fieldKey = assignment[EDITED_FIELD] as keyof typeof FieldType; + const field = FieldType[fieldKey]; + const value = assignment[VALUE_FIELD]; + const valueConverted = convertInputValues(field, value); return { ...assignment, [VALUE_FIELD]: valueConverted, @@ -93,7 +100,10 @@ const ModificationByAssignmentDialog: FC = ({ (formData: ModificationByAssignment) => { const assignmentsList = formData[ASSIGNMENTS].map((assignment) => { const dataType = getDataType(assignment[EDITED_FIELD]); - const valueConverted = convertOutputValue(assignment[EDITED_FIELD], assignment[VALUE_FIELD]); + const fieldKey = assignment[EDITED_FIELD] as keyof typeof FieldType; + const field = FieldType[fieldKey]; + const value = assignment[VALUE_FIELD]; + const valueConverted = convertOutputValues(field, value); return { ...assignment, dataType, 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 7d5e11ae49..d866b6e8ec 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 @@ -7,7 +7,13 @@ import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; -import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui'; +import { + convertInputValues, + convertOutputValues, + CustomFormProvider, + FieldType, + useSnackMessage, +} from '@gridsuite/commons-ui'; import { useCallback, useEffect } from 'react'; import { FetchStatus } from '../../../../../services/utils'; import { useForm } from 'react-hook-form'; @@ -29,11 +35,11 @@ import { import { modifyByFormula } from '../../../../../services/study/network-modifications'; import { getFormulaInitialValue, getFormulaSchema } from './formula/formula-utils'; -function getFieldOrValue(input) { +function getFieldOrConvertedUnitValue(input, fieldType) { const value = input.replace(',', '.'); const isNumber = !isNaN(parseFloat(value)); return { - [VALUE]: isNumber ? value : null, + [VALUE]: isNumber ? convertOutputValues(fieldType, value) : null, [EQUIPMENT_FIELD]: isNumber ? null : input, }; } @@ -71,8 +77,16 @@ const ByFormulaDialog = ({ editData, currentNode, studyUuid, isUpdate, editDataF useEffect(() => { if (editData) { const formulas = editData.formulaInfosList?.map((formula) => { - const ref1 = formula?.fieldOrValue1?.value?.toString() ?? formula?.fieldOrValue1?.equipmentField; - const ref2 = formula?.fieldOrValue2?.value?.toString() ?? formula?.fieldOrValue2?.equipmentField; + const valueConverted1 = convertInputValues( + FieldType[formula[EDITED_FIELD]], + formula?.fieldOrValue1?.value + ); + const valueConverted2 = convertInputValues( + FieldType[formula[EDITED_FIELD]], + formula?.fieldOrValue2?.value + ); + const ref1 = valueConverted1?.toString() ?? formula?.fieldOrValue1?.equipmentField; + const ref2 = valueConverted2?.toString() ?? formula?.fieldOrValue2?.equipmentField; return { [REFERENCE_FIELD_OR_VALUE_1]: ref1, [REFERENCE_FIELD_OR_VALUE_2]: ref2, @@ -95,8 +109,14 @@ const ByFormulaDialog = ({ editData, currentNode, studyUuid, isUpdate, editDataF const onSubmit = useCallback( (data) => { const formulas = data[FORMULAS].map((formula) => { - const fieldOrValue1 = getFieldOrValue(formula[REFERENCE_FIELD_OR_VALUE_1]); - const fieldOrValue2 = getFieldOrValue(formula[REFERENCE_FIELD_OR_VALUE_2]); + const fieldOrValue1 = getFieldOrConvertedUnitValue( + formula[REFERENCE_FIELD_OR_VALUE_1], + FieldType[formula[EDITED_FIELD]] + ); + const fieldOrValue2 = getFieldOrConvertedUnitValue( + formula[REFERENCE_FIELD_OR_VALUE_2], + FieldType[formula[EDITED_FIELD]] + ); return { fieldOrValue1, fieldOrValue2, 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/line/characteristics-pane/line-characteristics-pane.jsx b/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane.jsx index b4a8e3faf7..faeb3410b0 100644 --- a/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane.jsx +++ b/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane.jsx @@ -7,7 +7,7 @@ import { Grid } from '@mui/material'; import { MicroSusceptanceAdornment, OhmAdornment } from '../../../dialog-utils'; -import { FloatInput } from '@gridsuite/commons-ui'; +import { convertInputValues, FieldType, FloatInput } from '@gridsuite/commons-ui'; import { ConnectivityForm } from '../../../connectivity/connectivity-form'; import { B1, @@ -20,7 +20,6 @@ import { R, X, } from 'components/utils/field-constants'; -import { unitToMicroUnit } from 'utils/unit-converter'; import PropertiesForm from '../../common/properties/properties-form'; import useVoltageLevelsListInfos from '../../../../../hooks/use-voltage-levels-list-infos'; import GridSection from '../../../commons/grid-section'; @@ -70,7 +69,7 @@ const LineCharacteristicsPane = ({ name={`${id}.${G1}`} label="ShuntConductanceText" adornment={MicroSusceptanceAdornment} - previousValue={unitToMicroUnit(lineToModify?.g1)} + previousValue={convertInputValues(FieldType.G1, lineToModify?.g1)} clearable={clearableFields} /> ); @@ -80,7 +79,7 @@ const LineCharacteristicsPane = ({ name={`${id}.${B1}`} label="ShuntSusceptanceText" adornment={MicroSusceptanceAdornment} - previousValue={unitToMicroUnit(lineToModify?.b1)} + previousValue={convertInputValues(FieldType.B1, lineToModify?.b1)} clearable={clearableFields} /> ); @@ -90,7 +89,7 @@ const LineCharacteristicsPane = ({ name={`${id}.${G2}`} label="ShuntConductanceText" adornment={MicroSusceptanceAdornment} - previousValue={unitToMicroUnit(lineToModify?.g2)} + previousValue={convertInputValues(FieldType.G2, lineToModify?.g2)} clearable={clearableFields} /> ); @@ -100,7 +99,7 @@ const LineCharacteristicsPane = ({ name={`${id}.${B2}`} label="ShuntSusceptanceText" adornment={MicroSusceptanceAdornment} - previousValue={unitToMicroUnit(lineToModify?.b2)} + previousValue={convertInputValues(FieldType.B2, lineToModify?.b2)} clearable={clearableFields} /> ); diff --git a/src/components/dialogs/network-modifications/line/creation/line-creation-dialog.jsx b/src/components/dialogs/network-modifications/line/creation/line-creation-dialog.jsx index e0ccfb08b7..50b3150592 100644 --- a/src/components/dialogs/network-modifications/line/creation/line-creation-dialog.jsx +++ b/src/components/dialogs/network-modifications/line/creation/line-creation-dialog.jsx @@ -5,7 +5,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, TextInput, useSnackMessage } from '@gridsuite/commons-ui'; +import { + convertInputValues, + convertOutputValues, + CustomFormProvider, + FieldType, + TextInput, + useSnackMessage, +} from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { Box, Grid } from '@mui/material'; import { @@ -41,7 +48,6 @@ import PropTypes from 'prop-types'; import { useCallback, useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; import { FetchStatus } from '../../../../../services/utils'; -import { microUnitToUnit, unitToMicroUnit } from 'utils/unit-converter'; import { FORM_LOADING_DELAY, UNDEFINED_CONNECTION_DIRECTION } from 'components/network/constants'; import yup from 'components/utils/yup-config'; import ModificationDialog from '../../../commons/modificationDialog'; @@ -149,10 +155,10 @@ const LineCreationDialog = ({ ...getCharacteristicsFormData({ r: line.r, x: line.x, - g1: unitToMicroUnit(line.g1), // this form uses and displays microSiemens - b1: unitToMicroUnit(line.b1), - g2: unitToMicroUnit(line.g2), - b2: unitToMicroUnit(line.b2), + g1: convertInputValues(FieldType.G1, line.g1), // this form uses and displays microSiemens + b1: convertInputValues(FieldType.B1, line.b1), + g2: convertInputValues(FieldType.G2, line.g2), + b2: convertInputValues(FieldType.B2, line.b2), ...(displayConnectivity && getConnectivityFormData( { @@ -200,10 +206,10 @@ const LineCreationDialog = ({ ...getCharacteristicsFormData({ r: line.r, x: line.x, - g1: unitToMicroUnit(line.g1), - b1: unitToMicroUnit(line.b1), - g2: unitToMicroUnit(line.g2), - b2: unitToMicroUnit(line.b2), + g1: convertInputValues(FieldType.G1, line.g1), + b1: convertInputValues(FieldType.B1, line.b1), + g2: convertInputValues(FieldType.G2, line.g2), + b2: convertInputValues(FieldType.B2, line.b2), ...getConnectivityFormData( { busbarSectionId: line.busOrBusbarSectionId1, @@ -290,10 +296,10 @@ const LineCreationDialog = ({ sanitizeString(header[EQUIPMENT_NAME]), characteristics[R], characteristics[X], - microUnitToUnit(characteristics[G1]), - microUnitToUnit(characteristics[B1]), - microUnitToUnit(characteristics[G2]), - microUnitToUnit(characteristics[B2]), + convertOutputValues(FieldType.G1, characteristics[G1]), + convertOutputValues(FieldType.B1, characteristics[B1]), + convertOutputValues(FieldType.G2, characteristics[G2]), + convertOutputValues(FieldType.B2, characteristics[B2]), characteristics[CONNECTIVITY_1]?.[VOLTAGE_LEVEL]?.id, characteristics[CONNECTIVITY_1]?.[BUS_OR_BUSBAR_SECTION]?.id, characteristics[CONNECTIVITY_2]?.[VOLTAGE_LEVEL]?.id, diff --git a/src/components/dialogs/network-modifications/line/modification/line-modification-dialog.jsx b/src/components/dialogs/network-modifications/line/modification/line-modification-dialog.jsx index fb6f3c83a1..3941631208 100644 --- a/src/components/dialogs/network-modifications/line/modification/line-modification-dialog.jsx +++ b/src/components/dialogs/network-modifications/line/modification/line-modification-dialog.jsx @@ -6,7 +6,13 @@ */ import { useCallback, useEffect, useMemo, useState } from 'react'; -import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui'; +import { + convertInputValues, + convertOutputValues, + CustomFormProvider, + FieldType, + useSnackMessage, +} from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { ADDITIONAL_PROPERTIES, @@ -39,7 +45,6 @@ import { } from 'components/utils/field-constants'; import { useForm } from 'react-hook-form'; import { sanitizeString } from 'components/dialogs/dialog-utils'; -import { microUnitToUnit, unitToMicroUnit } from 'utils/unit-converter'; import yup from 'components/utils/yup-config'; import ModificationDialog from '../../../commons/modificationDialog'; @@ -161,10 +166,10 @@ const LineModificationDialog = ({ ...getCharacteristicsWithOutConnectivityFormData({ r: line.r?.value ?? null, x: line.x?.value ?? null, - g1: unitToMicroUnit(line.g1?.value ?? null), - b1: unitToMicroUnit(line.b1?.value ?? null), - g2: unitToMicroUnit(line.g2?.value ?? null), - b2: unitToMicroUnit(line.b2?.value ?? null), + g1: convertInputValues(FieldType.G1, line.g1?.value ?? null), + b1: convertInputValues(FieldType.B1, line.b1?.value ?? null), + g2: convertInputValues(FieldType.G2, line.g2?.value ?? null), + b2: convertInputValues(FieldType.B2, line.b2?.value ?? null), }), ...getLimitsFormData({ permanentLimit1: line.currentLimits1?.permanentLimit, @@ -242,10 +247,10 @@ const LineModificationDialog = ({ sanitizeString(line[EQUIPMENT_NAME]), characteristics[R], characteristics[X], - microUnitToUnit(characteristics[G1]), - microUnitToUnit(characteristics[B1]), - microUnitToUnit(characteristics[G2]), - microUnitToUnit(characteristics[B2]), + convertOutputValues(FieldType.G1, characteristics[G1]), + convertOutputValues(FieldType.B1, characteristics[B1]), + convertOutputValues(FieldType.G2, characteristics[G2]), + convertOutputValues(FieldType.B2, characteristics[B2]), currentLimits1, currentLimits2, connectivity1[VOLTAGE_LEVEL]?.id, diff --git a/src/components/dialogs/network-modifications/tabular-modification/tabular-modification-dialog.jsx b/src/components/dialogs/network-modifications/tabular-modification/tabular-modification-dialog.jsx index 6cba2d0d11..8602017f6a 100644 --- a/src/components/dialogs/network-modifications/tabular-modification/tabular-modification-dialog.jsx +++ b/src/components/dialogs/network-modifications/tabular-modification/tabular-modification-dialog.jsx @@ -19,8 +19,8 @@ import { createTabulareModification } from 'services/study/network-modifications import { FetchStatus } from 'services/utils'; import TabularModificationForm from './tabular-modification-form'; import { - convertValueFromBackToFront, - convertValueFromFrontToBack, + convertInputValue, + convertOutputValue, formatModification, getEquipmentTypeFromModificationType, TABULAR_MODIFICATION_TYPES, @@ -76,7 +76,7 @@ const TabularModificationDialog = ({ const modifications = editData?.modifications.map((modif) => { const modification = {}; Object.keys(formatModification(modif)).forEach((key) => { - modification[key] = convertValueFromBackToFront(key, modif[key]); + modification[key] = convertInputValue(key, modif[key]); }); return modification; }); @@ -95,7 +95,7 @@ const TabularModificationDialog = ({ type: modificationType, }; Object.keys(row).forEach((key) => { - modification[key] = convertValueFromFrontToBack(key, row[key]); + modification[key] = convertOutputValue(key, row[key]); }); return modification; }); diff --git a/src/components/dialogs/network-modifications/tabular-modification/tabular-modification-utils.ts b/src/components/dialogs/network-modifications/tabular-modification/tabular-modification-utils.ts index 8cd238357e..1afd638b22 100644 --- a/src/components/dialogs/network-modifications/tabular-modification/tabular-modification-utils.ts +++ b/src/components/dialogs/network-modifications/tabular-modification/tabular-modification-utils.ts @@ -5,19 +5,24 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { MODIFICATION_TYPES } from '@gridsuite/commons-ui'; +import { convertInputValues, convertOutputValues, FieldType, MODIFICATION_TYPES } from '@gridsuite/commons-ui'; import { + B, + B1, + B2, CONNECTED, CONNECTED1, CONNECTED2, + COUNTRY, ENERGY_SOURCE, EQUIPMENT_ID, FORCED_OUTAGE_RATE, + G, + G1, + G2, HIGH_VOLTAGE_LIMIT, LOAD_TYPE, LOW_VOLTAGE_LIMIT, - G, - B, MARGINAL_COST, MAX_P, MAX_Q_AT_NOMINAL_V, @@ -29,27 +34,21 @@ import { PLANNED_ACTIVE_POWER_SET_POINT, PLANNED_OUTAGE_RATE, Q0, + R, RATED_S, RATED_U1, RATED_U2, SECTION_COUNT, - R, - X, SHUNT_COMPENSATOR_TYPE, - G1, - B1, - G2, - B2, STEP_UP_TRANSFORMER_REACTANCE, - COUNTRY, TARGET_P, TARGET_Q, TARGET_V, TRANSIENT_REACTANCE, VOLTAGE_REGULATION_ON, + X, } from 'components/utils/field-constants'; -import { microUnitToUnit, unitToMicroUnit } from 'utils/unit-converter'; -import { toModificationOperation } from 'components/utils/utils'; +import { toModificationOperation } from '../../../utils/utils'; export interface TabularModificationFields { [key: string]: string[]; @@ -112,42 +111,52 @@ export const formatModification = (modification: Modification) => { return rest; }; -export const convertValueFromBackToFront = (key: string, value: { value: string | number }) => { +export const getEquipmentTypeFromModificationType = (type: string) => { + return Object.keys(TABULAR_MODIFICATION_TYPES).find((key) => TABULAR_MODIFICATION_TYPES[key] === type); +}; + +export const styles = { + grid: { height: 500, width: '100%' }, +}; + +export const convertInputValue = (key: string, value: { value: string | number }) => { switch (key) { case EQUIPMENT_ID: return value; case G: + return convertInputValues(FieldType.G, value?.value); case B: + return convertInputValues(FieldType.B, value?.value); case G1: + return convertInputValues(FieldType.G1, value?.value); case G2: + return convertInputValues(FieldType.G2, value?.value); case B1: + return convertInputValues(FieldType.B1, value?.value); case B2: - return unitToMicroUnit(value?.value); + return convertInputValues(FieldType.B2, value?.value); default: return value?.value; } }; -export const convertValueFromFrontToBack = (key: string, value: string | number) => { +export const convertOutputValue = (key: string, value: string | number) => { switch (key) { case EQUIPMENT_ID: return value; case G: + return toModificationOperation(convertOutputValues(FieldType.G, value)); case B: + return toModificationOperation(convertOutputValues(FieldType.B, value)); case G1: + return toModificationOperation(convertOutputValues(FieldType.G1, value)); case G2: + return toModificationOperation(convertOutputValues(FieldType.G2, value)); case B1: + return toModificationOperation(convertOutputValues(FieldType.B1, value)); case B2: - return toModificationOperation(microUnitToUnit(value)); + return toModificationOperation(convertOutputValues(FieldType.B2, value)); default: return toModificationOperation(value); } }; - -export const getEquipmentTypeFromModificationType = (type: string) => { - return Object.keys(TABULAR_MODIFICATION_TYPES).find((key) => TABULAR_MODIFICATION_TYPES[key] === type); -}; - -export const styles = { - grid: { height: 500, width: '100%' }, -}; 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 a4f71c0da3..d7e45be246 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 @@ -8,9 +8,8 @@ import { Grid } from '@mui/material'; import { FormattedMessage } from 'react-intl'; import { MicroSusceptanceAdornment, MVAPowerAdornment, OhmAdornment, VoltageAdornment } from '../../../dialog-utils'; -import { FloatInput } from '@gridsuite/commons-ui'; +import { convertInputValues, FieldType, FloatInput } from '@gridsuite/commons-ui'; import { B, CHARACTERISTICS, G, R, RATED_S, RATED_U1, RATED_U2, X } from 'components/utils/field-constants'; -import { unitToMicroUnit } from '../../../../../utils/unit-converter'; import PropertiesForm from '../../common/properties/properties-form'; import GridSection from '../../../commons/grid-section'; import GridItem from '../../../commons/grid-item'; @@ -43,7 +42,7 @@ const TwoWindingsTransformerCharacteristicsPane = ({ id = CHARACTERISTICS, twtTo name={`${id}.${G}`} label="G" adornment={MicroSusceptanceAdornment} - previousValue={unitToMicroUnit(twtToModify?.g)} + previousValue={convertInputValues(FieldType.G, twtToModify?.g)} clearable={isModification} /> ); @@ -53,7 +52,7 @@ const TwoWindingsTransformerCharacteristicsPane = ({ id = CHARACTERISTICS, twtTo name={`${id}.${B}`} label="B" adornment={MicroSusceptanceAdornment} - previousValue={unitToMicroUnit(twtToModify?.b)} + previousValue={convertInputValues(FieldType.B, twtToModify?.b)} clearable={isModification} /> ); 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 3b1e2aa021..fd4060d496 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 @@ -5,7 +5,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui'; +import { + convertInputValues, + convertOutputValues, + CustomFormProvider, + FieldType, + useSnackMessage, +} from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { Grid } from '@mui/material'; import { @@ -55,7 +61,6 @@ import PropTypes from 'prop-types'; import { useCallback, useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; import { FetchStatus } from '../../../../../services/utils'; -import { microUnitToUnit, unitToMicroUnit } from 'utils/unit-converter'; import { sanitizeString } from '../../../dialog-utils'; import EquipmentSearchDialog from '../../../equipment-search-dialog'; import { useFormSearchCopy } from '../../../form-search-copy-hook'; @@ -218,8 +223,8 @@ const TwoWindingsTransformerCreationDialog = ({ ...getTwoWindingsTransformerFormData({ r: twt.r, x: twt.x, - g: unitToMicroUnit(twt.g), - b: unitToMicroUnit(twt.b), + g: convertInputValues(FieldType.G, twt.g), + b: convertInputValues(FieldType.B, twt.b), ratedU1: twt.ratedU1, ratedU2: twt.ratedU2, ratedS: twt.ratedS, @@ -311,8 +316,8 @@ const TwoWindingsTransformerCreationDialog = ({ ...getTwoWindingsTransformerFormData({ r: twt.r, x: twt.x, - g: unitToMicroUnit(twt.g), - b: unitToMicroUnit(twt.b), + g: convertInputValues(FieldType.G, twt.g), + b: convertInputValues(FieldType.B, twt.b), ratedU1: twt.ratedU1, ratedU2: twt.ratedU2, ratedS: twt.ratedS, @@ -503,8 +508,8 @@ const TwoWindingsTransformerCreationDialog = ({ temporaryLimits: sanitizeLimitNames(limits[CURRENT_LIMITS_2]?.[TEMPORARY_LIMITS]), }; - characteristics[G] = microUnitToUnit(characteristics[G]); - characteristics[B] = microUnitToUnit(characteristics[B]); + characteristics[G] = convertOutputValues(FieldType.G, characteristics[G]); + characteristics[B] = convertOutputValues(FieldType.B, characteristics[B]); let ratioTap = undefined; if (enableRatioTapChanger) { const ratioTapChangerFormValues = twt[RATIO_TAP_CHANGER]; 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 50b554707d..e92888c8fe 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 @@ -5,7 +5,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui'; +import { + convertInputValues, + convertOutputValues, + CustomFormProvider, + FieldType, + useSnackMessage, +} from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { Box, Grid } from '@mui/material'; import { @@ -54,7 +60,6 @@ import { import PropTypes from 'prop-types'; import { useCallback, useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; -import { microUnitToUnit, unitToMicroUnit } from 'utils/unit-converter'; import { sanitizeString } from '../../../dialog-utils'; import { FORM_LOADING_DELAY, @@ -236,8 +241,8 @@ const TwoWindingsTransformerModificationDialog = ({ ...getCharacteristicsFormData({ r: twt.r?.value, x: twt.x?.value, - g: unitToMicroUnit(twt.g?.value), - b: unitToMicroUnit(twt.b?.value), + g: convertInputValues(FieldType.G, twt.g?.value), + b: convertInputValues(FieldType.B, twt.b?.value), ratedU1: twt.ratedU1?.value, ratedU2: twt.ratedU2?.value, ratedS: twt.ratedS?.value, @@ -490,8 +495,8 @@ const TwoWindingsTransformerModificationDialog = ({ twoWindingsTransformerName: toModificationOperation(sanitizeString(twt[EQUIPMENT_NAME])), r: toModificationOperation(characteristics[R]), x: toModificationOperation(characteristics[X]), - g: toModificationOperation(microUnitToUnit(characteristics[G])), - b: toModificationOperation(microUnitToUnit(characteristics[B])), + g: toModificationOperation(convertOutputValues(FieldType.G, characteristics[G])), + b: toModificationOperation(convertOutputValues(FieldType.B, characteristics[B])), ratedS: toModificationOperation(characteristics[RATED_S]), ratedU1: toModificationOperation(characteristics[RATED_U1]), ratedU2: toModificationOperation(characteristics[RATED_U2]), diff --git a/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.jsx b/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.jsx index 82278e28b8..89ba2bafac 100644 --- a/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.jsx +++ b/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.jsx @@ -5,7 +5,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui'; +import { + convertInputValues, + convertOutputValues, + CustomFormProvider, + FieldType, + useSnackMessage, +} 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'; @@ -41,7 +47,6 @@ import VoltageLevelCreationForm from './voltage-level-creation-form'; import { controlCouplingOmnibusBetweenSections } from '../voltage-level-creation-utils'; import { EQUIPMENT_TYPES } from 'components/utils/equipment-types'; import { useIntl } from 'react-intl'; -import { kiloUnitToUnit, unitToKiloUnit } from 'utils/unit-converter'; import { FORM_LOADING_DELAY } from 'components/network/constants'; import { useOpenShortWaitFetching } from '../../../commons/handle-modification-form'; import { createVoltageLevel } from '../../../../../services/study/network-modifications'; @@ -159,10 +164,12 @@ const VoltageLevelCreationDialog = ({ [NOMINAL_V]: voltageLevel[NOMINAL_V], [LOW_VOLTAGE_LIMIT]: voltageLevel[LOW_VOLTAGE_LIMIT], [HIGH_VOLTAGE_LIMIT]: voltageLevel[HIGH_VOLTAGE_LIMIT], - [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]: unitToKiloUnit( + [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]: convertInputValues( + FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, fromCopy ? voltageLevel.identifiableShortCircuit?.ipMin : voltageLevel.ipMin ), - [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: unitToKiloUnit( + [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: convertInputValues( + FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, fromCopy ? voltageLevel.identifiableShortCircuit?.ipMax : voltageLevel.ipMax ), [BUS_BAR_COUNT]: voltageLevel[BUS_BAR_COUNT] ?? 1, @@ -215,8 +222,14 @@ const VoltageLevelCreationDialog = ({ nominalV: voltageLevel[NOMINAL_V], lowVoltageLimit: voltageLevel[LOW_VOLTAGE_LIMIT], highVoltageLimit: voltageLevel[HIGH_VOLTAGE_LIMIT], - ipMin: kiloUnitToUnit(voltageLevel[LOW_SHORT_CIRCUIT_CURRENT_LIMIT]), - ipMax: kiloUnitToUnit(voltageLevel[HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]), + ipMin: convertOutputValues( + FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, + voltageLevel[LOW_SHORT_CIRCUIT_CURRENT_LIMIT] + ), + ipMax: convertOutputValues( + FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, + voltageLevel[HIGH_SHORT_CIRCUIT_CURRENT_LIMIT] + ), busbarCount: voltageLevel[BUS_BAR_COUNT], sectionCount: voltageLevel[SECTION_COUNT], switchKinds: voltageLevel[SWITCH_KINDS].map((e) => { diff --git a/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.jsx b/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.jsx index cdbb0ab781..4575202a44 100644 --- a/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.jsx +++ b/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.jsx @@ -21,10 +21,15 @@ import { } from 'components/utils/field-constants'; import yup from 'components/utils/yup-config'; import { yupResolver } from '@hookform/resolvers/yup'; -import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui'; +import { + convertInputValues, + convertOutputValues, + CustomFormProvider, + FieldType, + useSnackMessage, +} from '@gridsuite/commons-ui'; import { useOpenShortWaitFetching } from '../../../commons/handle-modification-form'; import { FORM_LOADING_DELAY } from 'components/network/constants'; -import { kiloUnitToUnit, unitToKiloUnit } from 'utils/unit-converter'; import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES } from 'components/utils/equipment-types'; import { EquipmentIdSelector } from '../../../equipment-id/equipment-id-selector'; import { modifyVoltageLevel } from '../../../../../services/study/network-modifications'; @@ -105,8 +110,10 @@ const VoltageLevelModificationDialog = ({ [NOMINAL_V]: editData?.nominalV?.value ?? null, [LOW_VOLTAGE_LIMIT]: editData?.lowVoltageLimit?.value ?? null, [HIGH_VOLTAGE_LIMIT]: editData?.highVoltageLimit?.value ?? null, - [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]: unitToKiloUnit(editData?.ipMin?.value) ?? null, - [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: unitToKiloUnit(editData?.ipMax?.value) ?? null, + [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]: + convertInputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, editData?.ipMin?.value) ?? null, + [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: + convertInputValues(FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, editData?.ipMax?.value) ?? null, ...getPropertiesFromModification(editData.properties), }); } @@ -128,10 +135,12 @@ const VoltageLevelModificationDialog = ({ if (voltageLevel) { //We convert values of low short circuit current limit and high short circuit current limit from A to KA if (voltageLevel.identifiableShortCircuit) { - voltageLevel.identifiableShortCircuit.ipMax = unitToKiloUnit( + voltageLevel.identifiableShortCircuit.ipMax = convertInputValues( + FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevel.identifiableShortCircuit?.ipMax ); - voltageLevel.identifiableShortCircuit.ipMin = unitToKiloUnit( + voltageLevel.identifiableShortCircuit.ipMin = convertInputValues( + FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevel.identifiableShortCircuit?.ipMin ); } @@ -176,8 +185,14 @@ const VoltageLevelModificationDialog = ({ nominalV: voltageLevel[NOMINAL_V], lowVoltageLimit: voltageLevel[LOW_VOLTAGE_LIMIT], highVoltageLimit: voltageLevel[HIGH_VOLTAGE_LIMIT], - lowShortCircuitCurrentLimit: kiloUnitToUnit(voltageLevel[LOW_SHORT_CIRCUIT_CURRENT_LIMIT]), - highShortCircuitCurrentLimit: kiloUnitToUnit(voltageLevel[HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]), + lowShortCircuitCurrentLimit: convertOutputValues( + FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, + voltageLevel[LOW_SHORT_CIRCUIT_CURRENT_LIMIT] + ), + highShortCircuitCurrentLimit: convertOutputValues( + FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, + voltageLevel[HIGH_SHORT_CIRCUIT_CURRENT_LIMIT] + ), properties: toModificationProperties(voltageLevel), }).catch((error) => { snackError({ diff --git a/src/components/results/shortcircuit/shortcircuit-analysis-result-content.ts b/src/components/results/shortcircuit/shortcircuit-analysis-result-content.ts index c20c883b50..0b944cd7e9 100644 --- a/src/components/results/shortcircuit/shortcircuit-analysis-result-content.ts +++ b/src/components/results/shortcircuit/shortcircuit-analysis-result-content.ts @@ -8,7 +8,7 @@ import { ALL_BUSES, ONE_BUS } from 'utils/store-sort-filter-fields'; import { ShortCircuitAnalysisType } from './shortcircuit-analysis-result.type'; import { FilterSelectorType } from '../../custom-aggrid/custom-aggrid-header.type'; -import { kiloUnitToUnit } from '../../../utils/unit-converter'; +import { kiloUnitToUnit } from '@gridsuite/commons-ui'; export const PAGE_OPTIONS = [25, 100, 500, 1000]; @@ -57,8 +57,8 @@ export const convertFilterValues = (filterSelector: FilterSelectorType[]) => { case 'limitMax': return { ...filter, - value: kiloUnitToUnit(filter.value), - tolerance: kiloUnitToUnit(filter.tolerance), + value: kiloUnitToUnit(Number(filter.value)), + tolerance: kiloUnitToUnit(Number(filter.tolerance)), }; default: return filter; diff --git a/src/components/results/shortcircuit/shortcircuit-analysis-result-table.tsx b/src/components/results/shortcircuit/shortcircuit-analysis-result-table.tsx index b7ca08ca6d..8b2b7e6054 100644 --- a/src/components/results/shortcircuit/shortcircuit-analysis-result-table.tsx +++ b/src/components/results/shortcircuit/shortcircuit-analysis-result-table.tsx @@ -24,8 +24,7 @@ import { FilterParams, } from '../../custom-aggrid/custom-aggrid-header.type'; import { makeAgGridCustomHeaderColumn } from '../../custom-aggrid/custom-aggrid-header-utils'; -import { unitToKiloUnit } from '../../../utils/unit-converter'; -import { CustomAGGrid } from '@gridsuite/commons-ui'; +import { CustomAGGrid, unitToKiloUnit } from '@gridsuite/commons-ui'; import { convertSide } from '../loadflow/load-flow-result-utils'; import { CustomAggridComparatorFilter } from '../../custom-aggrid/custom-aggrid-filters/custom-aggrid-comparator-filter'; import { CustomAggridAutocompleteFilter } from '../../custom-aggrid/custom-aggrid-filters/custom-aggrid-autocomplete-filter'; diff --git a/src/components/spreadsheet/config/equipment/line.ts b/src/components/spreadsheet/config/equipment/line.ts index 6585d2dfdc..8bd6b822d2 100644 --- a/src/components/spreadsheet/config/equipment/line.ts +++ b/src/components/spreadsheet/config/equipment/line.ts @@ -19,8 +19,8 @@ import { typeAndFetchers, } from './common-config'; import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; -import { unitToMicroUnit } from '../../../../utils/unit-converter'; import { genericColumnOfProperties } from '../common/column-properties'; +import { convertInputValues, FieldType } from '@gridsuite/commons-ui'; export const LINE_TAB_DEF = { index: 2, @@ -134,7 +134,7 @@ export const LINE_TAB_DEF = { numeric: true, ...defaultNumericFilterConfig, fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.g1), + valueGetter: (params) => convertInputValues(FieldType.G1, params.data.g1), getQuickFilterText: excludeFromGlobalFilter, }, { @@ -143,7 +143,7 @@ export const LINE_TAB_DEF = { numeric: true, ...defaultNumericFilterConfig, fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.g2), + valueGetter: (params) => convertInputValues(FieldType.G2, params.data.g2), getQuickFilterText: excludeFromGlobalFilter, }, { @@ -152,7 +152,7 @@ export const LINE_TAB_DEF = { numeric: true, ...defaultNumericFilterConfig, fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.b1), + valueGetter: (params) => convertInputValues(FieldType.B1, params.data.b1), getQuickFilterText: excludeFromGlobalFilter, }, { @@ -161,7 +161,7 @@ export const LINE_TAB_DEF = { numeric: true, ...defaultNumericFilterConfig, fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.b2), + valueGetter: (params) => convertInputValues(FieldType.B2, params.data.b2), getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/tie-line.ts b/src/components/spreadsheet/config/equipment/tie-line.ts index 08e6cbe1f0..9f0a8b5957 100644 --- a/src/components/spreadsheet/config/equipment/tie-line.ts +++ b/src/components/spreadsheet/config/equipment/tie-line.ts @@ -19,8 +19,8 @@ import { typeAndFetchers, } from './common-config'; import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; -import { unitToMicroUnit } from '../../../../utils/unit-converter'; import { genericColumnOfPropertiesReadonly } from '../common/column-properties'; +import { convertInputValues, FieldType } from '@gridsuite/commons-ui'; export const TIE_LINE_TAB_DEF = { index: 15, @@ -134,7 +134,7 @@ export const TIE_LINE_TAB_DEF = { numeric: true, ...defaultNumericFilterConfig, fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.g1), + valueGetter: (params) => convertInputValues(FieldType.G1, params.data.g1), getQuickFilterText: excludeFromGlobalFilter, }, { @@ -143,7 +143,7 @@ export const TIE_LINE_TAB_DEF = { numeric: true, ...defaultNumericFilterConfig, fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.g2), + valueGetter: (params) => convertInputValues(FieldType.G2, params.data.g2), getQuickFilterText: excludeFromGlobalFilter, }, { @@ -152,7 +152,7 @@ export const TIE_LINE_TAB_DEF = { numeric: true, ...defaultNumericFilterConfig, fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.b1), + valueGetter: (params) => convertInputValues(FieldType.B1, params.data.b1), getQuickFilterText: excludeFromGlobalFilter, }, { @@ -161,7 +161,7 @@ export const TIE_LINE_TAB_DEF = { numeric: true, ...defaultNumericFilterConfig, fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.b2), + valueGetter: (params) => convertInputValues(FieldType.B2, params.data.b2), getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/two-windings-transformer.ts b/src/components/spreadsheet/config/equipment/two-windings-transformer.ts index 83e8ba90ae..d4f66b1aa1 100644 --- a/src/components/spreadsheet/config/equipment/two-windings-transformer.ts +++ b/src/components/spreadsheet/config/equipment/two-windings-transformer.ts @@ -29,7 +29,6 @@ import { import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; import { PHASE_REGULATION_MODES, RATIO_REGULATION_MODES, REGULATION_TYPES, SIDE } from '../../../network/constants'; import { computeHighTapPosition, getTapChangerRegulationTerminalValue } from '../../../utils/utils'; -import { unitToMicroUnit } from '../../../../utils/unit-converter'; import { getComputedRegulationMode } from '../../../dialogs/network-modifications/two-windings-transformer/tap-changer-pane/ratio-tap-changer-pane/ratio-tap-changer-pane-utils'; import { genericColumnOfPropertiesEditPopup } from '../common/column-properties'; import { @@ -39,6 +38,7 @@ import { numericalCellEditorConfig, standardSelectCellEditorConfig, } from '../common/cell-editors'; +import { convertInputValues, FieldType } from '@gridsuite/commons-ui'; function getTwtRatioRegulationModeId(twt: any) { //regulationMode is set by the user (in edit mode) @@ -600,7 +600,7 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { numeric: true, ...defaultNumericFilterConfig, fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.g), + valueGetter: (params) => convertInputValues(FieldType.G, params.data.g), getQuickFilterText: excludeFromGlobalFilter, }, { @@ -609,7 +609,7 @@ export const TWO_WINDINGS_TRANSFORMER_TAB_DEF = { numeric: true, ...defaultNumericFilterConfig, fractionDigits: 1, - valueGetter: (params) => unitToMicroUnit(params.data.b), + valueGetter: (params) => convertInputValues(FieldType.B, params.data.b), getQuickFilterText: excludeFromGlobalFilter, }, { diff --git a/src/components/spreadsheet/config/equipment/voltage-level.ts b/src/components/spreadsheet/config/equipment/voltage-level.ts index 9728d292e8..2c341c96ec 100644 --- a/src/components/spreadsheet/config/equipment/voltage-level.ts +++ b/src/components/spreadsheet/config/equipment/voltage-level.ts @@ -18,9 +18,9 @@ import { excludeFromGlobalFilter, typeAndFetchers, } from './common-config'; -import { kiloUnitToUnit, unitToKiloUnit } from '../../../../utils/unit-converter'; import { genericColumnOfPropertiesEditPopup } from '../common/column-properties'; import { numericalCellEditorConfig } from '../common/cell-editors'; +import { convertInputValues, convertOutputValues, FieldType } from '@gridsuite/commons-ui'; function generateEditableNumericColumnDefinition< TId extends string, @@ -91,12 +91,21 @@ export const VOLTAGE_LEVEL_TAB_DEF = { fractionDigits: 1, ...editableColumnConfig, numeric: true, - ...numericalCellEditorConfig((params) => unitToKiloUnit(params.data?.identifiableShortCircuit?.ipMin)), - valueGetter: (params) => unitToKiloUnit(params.data?.identifiableShortCircuit?.ipMin), + ...numericalCellEditorConfig((params) => + convertInputValues( + FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, + params.data?.identifiableShortCircuit?.ipMin + ) + ), + valueGetter: (params) => + convertInputValues( + FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, + params.data?.identifiableShortCircuit?.ipMin + ), valueSetter: (params) => { params.data.identifiableShortCircuit = { ...params.data.identifiableShortCircuit, - ipMin: kiloUnitToUnit(params.newValue), + ipMin: convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.newValue), }; return true; }, @@ -112,12 +121,21 @@ export const VOLTAGE_LEVEL_TAB_DEF = { fractionDigits: 1, ...editableColumnConfig, numeric: true, - ...numericalCellEditorConfig((params) => unitToKiloUnit(params.data?.identifiableShortCircuit?.ipMax)), - valueGetter: (params) => unitToKiloUnit(params.data?.identifiableShortCircuit?.ipMax), + ...numericalCellEditorConfig((params) => + convertInputValues( + FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, + params.data?.identifiableShortCircuit?.ipMax + ) + ), + valueGetter: (params) => + convertInputValues( + FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, + params.data?.identifiableShortCircuit?.ipMax + ), valueSetter: (params) => { params.data.identifiableShortCircuit = { ...params.data.identifiableShortCircuit, - ipMax: kiloUnitToUnit(params.newValue), + ipMax: convertOutputValues(FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, params.newValue), }; return true; }, diff --git a/src/components/tooltips/equipment-popover.jsx b/src/components/tooltips/equipment-popover.jsx index 65df5187c6..958aa9b50e 100644 --- a/src/components/tooltips/equipment-popover.jsx +++ b/src/components/tooltips/equipment-popover.jsx @@ -16,8 +16,7 @@ import { RunningStatus } from '../utils/running-status'; import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES } from 'components/utils/equipment-types'; import { fetchNetworkElementInfos } from '../../services/study/network'; import { mergeSx } from '../utils/functions'; -import { unitToMicroUnit } from 'utils/unit-converter'; -import { useDebounce } from '@gridsuite/commons-ui'; +import { convertInputValues, FieldType, useDebounce } from '@gridsuite/commons-ui'; const styles = { tableCells: { @@ -220,12 +219,12 @@ const EquipmentPopover = ({ studyUuid, anchorEl, anchorPosition, equipmentId, eq }; const renderVoltageLevelCharacteristics = (equipmentInfo, equipmentType) => { - const renderShuntSusceptanceRow = (voltageLevelId, susceptanceValue) => ( + const renderShuntSusceptanceRow = (voltageLevelId, susceptanceValue, fieldType) => ( {renderTableCell({ value: voltageLevelId, isLabel: false })} {renderTableCell({ label: 'shuntSusceptance', isLabel: true })} {renderTableCell({ - value: unitToMicroUnit(susceptanceValue)?.toFixed(2), + value: convertInputValues(fieldType, susceptanceValue)?.toFixed(2), isLabel: false, })} @@ -234,11 +233,11 @@ const EquipmentPopover = ({ studyUuid, anchorEl, anchorPosition, equipmentId, eq return ( <> {equipmentType === EQUIPMENT_TYPES.TWO_WINDINGS_TRANSFORMER ? ( - renderShuntSusceptanceRow(equipmentInfo.voltageLevelId2, equipmentInfo?.b) + renderShuntSusceptanceRow(equipmentInfo.voltageLevelId2, equipmentInfo?.b, FieldType.B) ) : ( <> - {renderShuntSusceptanceRow(equipmentInfo.voltageLevelId1, equipmentInfo.b1)} - {renderShuntSusceptanceRow(equipmentInfo.voltageLevelId2, equipmentInfo?.b2)} + {renderShuntSusceptanceRow(equipmentInfo.voltageLevelId1, equipmentInfo.b1, FieldType.B1)} + {renderShuntSusceptanceRow(equipmentInfo.voltageLevelId2, equipmentInfo?.b2, FieldType.B2)} )} diff --git a/src/utils/unit-converter.ts b/src/utils/unit-converter.ts deleted file mode 100644 index bd031f68e9..0000000000 --- a/src/utils/unit-converter.ts +++ /dev/null @@ -1,14 +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 { isBlankOrEmpty } from '../components/utils/validation-functions'; -import { roundToDefaultPrecision } from './rounding'; - -export const unitToMicroUnit = (num: any) => (isBlankOrEmpty(num) ? undefined : roundToDefaultPrecision(num * 1e6)); -export const microUnitToUnit = (num: any) => (isBlankOrEmpty(num) ? undefined : roundToDefaultPrecision(num / 1e6)); -export const kiloUnitToUnit = (num: any) => (isBlankOrEmpty(num) ? undefined : roundToDefaultPrecision(num * 1e3)); -export const unitToKiloUnit = (num: any) => (isBlankOrEmpty(num) ? undefined : roundToDefaultPrecision(num / 1e3));