From e091acb4a706a4518fcd790435861824e85e7b97 Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Wed, 11 Dec 2024 13:41:57 +0100 Subject: [PATCH 01/13] gather all the unit conversions into one file --- .../dialogs/converter-unit-utils.ts | 87 +++++++++++++++++++ .../assignment/assignment-constants.ts | 14 +-- .../assignment/assignment-utils.ts | 6 -- .../modification-by-assignment-dialog.tsx | 8 +- .../line-characteristics-pane.jsx | 10 +-- .../line/creation/line-creation-dialog.jsx | 26 +++--- .../modification/line-modification-dialog.jsx | 18 ++-- .../tabular-modification-dialog.jsx | 8 +- .../tabular-modification-utils.ts | 52 ++--------- ...dings-transformer-characteristics-pane.jsx | 6 +- ...o-windings-transformer-creation-dialog.jsx | 14 +-- ...ndings-transformer-modification-dialog.jsx | 10 +-- .../voltage-level-creation-dialog.jsx | 18 ++-- .../voltage-level-modification-dialog.jsx | 24 +++-- .../shortcircuit-analysis-result-content.ts | 8 +- .../shortcircuit-analysis-result-table.tsx | 17 ++-- .../spreadsheet/config/equipment/line.ts | 10 +-- .../spreadsheet/config/equipment/tie-line.ts | 10 +-- .../equipment/two-windings-transformer.ts | 6 +- .../config/equipment/voltage-level.ts | 32 +++++-- src/components/tooltips/equipment-popover.jsx | 12 +-- src/utils/unit-converter.ts | 14 --- 22 files changed, 239 insertions(+), 171 deletions(-) create mode 100644 src/components/dialogs/converter-unit-utils.ts delete mode 100644 src/utils/unit-converter.ts diff --git a/src/components/dialogs/converter-unit-utils.ts b/src/components/dialogs/converter-unit-utils.ts new file mode 100644 index 0000000000..e0913ffa26 --- /dev/null +++ b/src/components/dialogs/converter-unit-utils.ts @@ -0,0 +1,87 @@ +import { kiloUnitToUnit, microUnitToUnit, unitToKiloUnit, unitToMicroUnit } from '@gridsuite/commons-ui'; + +export enum FieldType { + ID = 'ID', + NAME = 'NAME', + NOMINAL_VOLTAGE = 'NOMINAL_VOLTAGE', + TARGET_V = 'TARGET_V', + TARGET_P = 'TARGET_P', + COUNTRY = 'COUNTRY', + 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', + P0 = 'P0', + Q0 = 'Q0', + LOW_VOLTAGE_LIMIT = 'LOW_VOLTAGE_LIMIT', + HIGH_VOLTAGE_LIMIT = 'HIGH_VOLTAGE_LIMIT', + SECTION_COUNT = 'SECTION_COUNT', + MAXIMUM_SECTION_COUNT = 'MAXIMUM_SECTION_COUNT', + CONNECTED = 'CONNECTED', + MAX_Q_AT_NOMINAL_V = 'MAX_Q_AT_NOMINAL_V', + SHUNT_CONDUCTANCE_1 = 'SHUNT_CONDUCTANCE_1', + SHUNT_CONDUCTANCE_2 = 'SHUNT_CONDUCTANCE_2', + SHUNT_SUSCEPTANCE = 'SHUNT_SUSCEPTANCE', + SHUNT_SUSCEPTANCE_1 = 'SHUNT_SUSCEPTANCE_1', + SHUNT_SUSCEPTANCE_2 = 'SHUNT_SUSCEPTANCE_2', + VOLTAGE_SET_POINT = 'VOLTAGE_SET_POINT', + ACTIVE_POWER_SET_POINT = 'ACTIVE_POWER_SET_POINT', + REACTIVE_POWER_SET_POINT = 'REACTIVE_POWER_SET_POINT', + LOW_SHORT_CIRCUIT_CURRENT_LIMIT = 'LOW_SHORT_CIRCUIT_CURRENT_LIMIT', + HIGH_SHORT_CIRCUIT_CURRENT_LIMIT = 'HIGH_SHORT_CIRCUIT_CURRENT_LIMIT', + MAXIMUM_SUSCEPTANCE = 'MAXIMUM_SUSCEPTANCE', + R = 'R', + X = 'X', + G = 'G', + B = 'B', + G1 = 'G1', + B1 = 'B1', + G2 = 'G2', + B2 = 'B2', +} + +const microUnits = [ + FieldType.SHUNT_CONDUCTANCE_1, + FieldType.SHUNT_CONDUCTANCE_2, + FieldType.SHUNT_SUSCEPTANCE_1, + FieldType.SHUNT_SUSCEPTANCE_2, + FieldType.G, + FieldType.B, + FieldType.G1, + FieldType.B1, + FieldType.G2, + FieldType.B2, +]; + +const kiloUnits = [FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT]; +export function convertInputValues(field: FieldType, value: any) { + if (microUnits.includes(field)) { + if (!Array.isArray(value)) { + return value ? unitToMicroUnit(value) : value; + } + return value.map((a: number) => unitToMicroUnit(a)); + } + if (kiloUnits.includes(field)) { + if (!Array.isArray(value)) { + return value ? kiloUnitToUnit(value) : value; + } + return value.map((a: number) => kiloUnitToUnit(a)); + } + return value; +} + +export function convertOutputValues(field: FieldType, value: any) { + if (microUnits.includes(field)) { + if (!Array.isArray(value)) { + return value ? microUnitToUnit(value) : value; + } + return value.map((a: number) => microUnitToUnit(a)); + } + if (kiloUnits.includes(field)) { + if (!Array.isArray(value)) { + return value ? unitToKiloUnit(value) : value; + } + return value.map((a: number) => unitToKiloUnit(a)); + } + return value; +} 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..80a2ab5225 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 @@ -8,7 +8,7 @@ import type { ReadonlyDeep } from 'type-fest'; import { DataType, FieldOptionType, FieldType } from './assignment.type'; import { LOAD_TYPES } from '../../../../../network/constants'; -import { EquipmentType, kiloUnitToUnit, microUnitToUnit, unitToKiloUnit, unitToMicroUnit } from '@gridsuite/commons-ui'; +import { EquipmentType } from '@gridsuite/commons-ui'; import { KILO_AMPERE, MICRO_SIEMENS } from '../../../../../utils/field-constants'; export const FIELD_OPTIONS = { @@ -107,16 +107,12 @@ export const FIELD_OPTIONS = { 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, 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, 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..5c2a062a4b 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,12 +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[*] 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..e9c566cddc 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 @@ -19,7 +19,6 @@ import { ASSIGNMENTS, EDITED_FIELD, EQUIPMENT_TYPE_FIELD, VALUE_FIELD } from '.. import { modifyByAssignment } from '../../../../../services/study/network-modifications'; import { convertInputValue, - convertOutputValue, getAssignmentFromEditData, getAssignmentInitialValue, getAssignmentsSchema, @@ -27,6 +26,7 @@ import { } from './assignment/assignment-utils'; import { Assignment, ModificationByAssignment } from './assignment/assignment.type'; import { DeepNullable } from '../../../../utils/ts-utils'; +import { convertOutputValues, FieldType } from '../../../converter-unit-utils'; const formSchema = yup .object() @@ -93,7 +93,11 @@ 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]); + console.log('=================assignment[EDITED_FIELD]', assignment[EDITED_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/line/characteristics-pane/line-characteristics-pane.jsx b/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane.jsx index b4a8e3faf7..bd5043825e 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 @@ -20,11 +20,11 @@ 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'; import GridItem from '../../../commons/grid-item'; +import { convertInputValues, FieldType } from '../../../converter-unit-utils'; const styles = { h3: { @@ -70,7 +70,7 @@ const LineCharacteristicsPane = ({ name={`${id}.${G1}`} label="ShuntConductanceText" adornment={MicroSusceptanceAdornment} - previousValue={unitToMicroUnit(lineToModify?.g1)} + previousValue={convertInputValues(FieldType.G1, lineToModify?.g1)} clearable={clearableFields} /> ); @@ -80,7 +80,7 @@ const LineCharacteristicsPane = ({ name={`${id}.${B1}`} label="ShuntSusceptanceText" adornment={MicroSusceptanceAdornment} - previousValue={unitToMicroUnit(lineToModify?.b1)} + previousValue={convertInputValues(FieldType.B1, lineToModify?.b1)} clearable={clearableFields} /> ); @@ -90,7 +90,7 @@ const LineCharacteristicsPane = ({ name={`${id}.${G2}`} label="ShuntConductanceText" adornment={MicroSusceptanceAdornment} - previousValue={unitToMicroUnit(lineToModify?.g2)} + previousValue={convertInputValues(FieldType.G2, lineToModify?.g2)} clearable={clearableFields} /> ); @@ -100,7 +100,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..777588e2d9 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 @@ -41,7 +41,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'; @@ -76,6 +75,7 @@ import { toModificationProperties, } from '../../common/properties/property-utils'; import GridItem from '../../../commons/grid-item'; +import { convertInputValues, convertOutputValues, FieldType } from '../../../converter-unit-utils'; const emptyFormData = { ...getHeaderEmptyFormData(), @@ -149,10 +149,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 +200,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 +290,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..17d1497780 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 @@ -39,7 +39,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'; @@ -81,6 +80,7 @@ import { getConnectivityFormData, getCont1Cont2WithPositionEmptyFormData, } from '../../../connectivity/connectivity-form-utils'; +import { convertInputValues, convertOutputValues, FieldType } from '../../../converter-unit-utils'; export const LineModificationDialogTab = { CONNECTIVITY_TAB: 0, @@ -161,10 +161,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 +242,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..8d1083db0e 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,13 +19,13 @@ import { createTabulareModification } from 'services/study/network-modifications import { FetchStatus } from 'services/utils'; import TabularModificationForm from './tabular-modification-form'; import { - convertValueFromBackToFront, - convertValueFromFrontToBack, formatModification, getEquipmentTypeFromModificationType, TABULAR_MODIFICATION_TYPES, } from './tabular-modification-utils'; import { useIntl } from 'react-intl'; +import { convertInputValues, convertOutputValues, FieldType } from '../../converter-unit-utils'; +import { toModificationOperation } from '../../../utils/utils.js'; const formSchema = yup .object() @@ -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] = convertInputValues(FieldType[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] = toModificationOperation(convertOutputValues(FieldType[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..2962ef59be 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 @@ -7,17 +7,22 @@ import { 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,20 @@ 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'; export interface TabularModificationFields { [key: string]: string[]; @@ -112,38 +110,6 @@ export const formatModification = (modification: Modification) => { return rest; }; -export const convertValueFromBackToFront = (key: string, value: { value: string | number }) => { - switch (key) { - case EQUIPMENT_ID: - return value; - case G: - case B: - case G1: - case G2: - case B1: - case B2: - return unitToMicroUnit(value?.value); - default: - return value?.value; - } -}; - -export const convertValueFromFrontToBack = (key: string, value: string | number) => { - switch (key) { - case EQUIPMENT_ID: - return value; - case G: - case B: - case G1: - case G2: - case B1: - case B2: - return toModificationOperation(microUnitToUnit(value)); - default: - return toModificationOperation(value); - } -}; - export const getEquipmentTypeFromModificationType = (type: string) => { return Object.keys(TABULAR_MODIFICATION_TYPES).find((key) => TABULAR_MODIFICATION_TYPES[key] === type); }; 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..a3affc2ad4 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 @@ -10,10 +10,10 @@ import { FormattedMessage } from 'react-intl'; import { MicroSusceptanceAdornment, MVAPowerAdornment, OhmAdornment, VoltageAdornment } from '../../../dialog-utils'; import { 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'; +import { convertInputValues, FieldType } from '../../../converter-unit-utils'; const TwoWindingsTransformerCharacteristicsPane = ({ id = CHARACTERISTICS, twtToModify, isModification = false }) => { const width = isModification ? 12 : 8; @@ -43,7 +43,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 +53,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 64a8cf2e42..f3dff2912f 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 @@ -55,7 +55,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'; @@ -104,6 +103,7 @@ import { getPropertiesFromModification, toModificationProperties, } from '../../common/properties/property-utils'; +import { convertInputValues, convertOutputValues, FieldType } from '../../../converter-unit-utils'; /** * Dialog to create a two windings transformer in the network @@ -218,8 +218,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 +311,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 +503,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..b739d10190 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 @@ -54,7 +54,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, @@ -125,6 +124,7 @@ import { getConnectivityFormData, getCont1Cont2WithPositionEmptyFormData, } from '../../../connectivity/connectivity-form-utils'; +import { convertInputValues, convertOutputValues, FieldType } from '../../../converter-unit-utils'; const emptyFormData = { [EQUIPMENT_NAME]: '', @@ -236,8 +236,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 +490,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..325fca485e 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 @@ -41,7 +41,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'; @@ -53,6 +52,7 @@ import { getPropertiesFromModification, toModificationProperties, } from '../../common/properties/property-utils'; +import { convertInputValues, convertOutputValues, FieldType } from '../../../converter-unit-utils.js'; /** * Dialog to create a load in the network @@ -159,10 +159,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]: convertOutputValues( + FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, fromCopy ? voltageLevel.identifiableShortCircuit?.ipMin : voltageLevel.ipMin ), - [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: unitToKiloUnit( + [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: convertOutputValues( + FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, fromCopy ? voltageLevel.identifiableShortCircuit?.ipMax : voltageLevel.ipMax ), [BUS_BAR_COUNT]: voltageLevel[BUS_BAR_COUNT] ?? 1, @@ -215,8 +217,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: convertInputValues( + FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, + voltageLevel[LOW_SHORT_CIRCUIT_CURRENT_LIMIT] + ), + ipMax: convertInputValues( + FieldType.LOW_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..3e94d01234 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 @@ -24,7 +24,6 @@ import { yupResolver } from '@hookform/resolvers/yup'; import { CustomFormProvider, 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'; @@ -37,6 +36,7 @@ import { modificationPropertiesSchema, toModificationProperties, } from '../../common/properties/property-utils'; +import { convertInputValues, convertOutputValues, FieldType } from '../../../converter-unit-utils.js'; const emptyFormData = { [EQUIPMENT_NAME]: '', @@ -105,8 +105,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]: + convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, editData?.ipMin?.value) ?? null, + [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: + convertOutputValues(FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, editData?.ipMax?.value) ?? null, ...getPropertiesFromModification(editData.properties), }); } @@ -128,10 +130,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 = convertOutputValues( + FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevel.identifiableShortCircuit?.ipMax ); - voltageLevel.identifiableShortCircuit.ipMin = unitToKiloUnit( + voltageLevel.identifiableShortCircuit.ipMin = convertOutputValues( + FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevel.identifiableShortCircuit?.ipMin ); } @@ -176,8 +180,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: convertInputValues( + FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, + voltageLevel[LOW_SHORT_CIRCUIT_CURRENT_LIMIT] + ), + highShortCircuitCurrentLimit: convertInputValues( + FieldType.LOW_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..03cd715d77 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 { convertInputValues, FieldType } from '../../dialogs/converter-unit-utils'; export const PAGE_OPTIONS = [25, 100, 500, 1000]; @@ -49,6 +49,8 @@ export const mappingTabs = (analysisType: ShortCircuitAnalysisType): string => { export const convertFilterValues = (filterSelector: FilterSelectorType[]) => { return filterSelector.map((filter) => { + const fieldKey = filter.column as keyof typeof FieldType; + const field = FieldType[fieldKey]; switch (filter.column) { case 'current': case 'deltaCurrentIpMax': @@ -57,8 +59,8 @@ export const convertFilterValues = (filterSelector: FilterSelectorType[]) => { case 'limitMax': return { ...filter, - value: kiloUnitToUnit(filter.value), - tolerance: kiloUnitToUnit(filter.tolerance), + value: convertInputValues(field, filter.value), + tolerance: convertInputValues(field, 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 cd29297d11..b33171a983 100644 --- a/src/components/results/shortcircuit/shortcircuit-analysis-result-table.tsx +++ b/src/components/results/shortcircuit/shortcircuit-analysis-result-table.tsx @@ -24,9 +24,9 @@ import { FilterPropsType, } 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 { convertSide } from '../loadflow/load-flow-result-utils'; +import { convertOutputValues, FieldType } from '../../dialogs/converter-unit-utils'; interface ShortCircuitAnalysisResultProps { result: SCAFaultResult[]; @@ -143,7 +143,8 @@ const ShortCircuitAnalysisResultTable: FunctionComponent unitToKiloUnit(params.data?.current), + valueGetter: (params: ValueGetterParams) => + convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.current), }), makeAgGridCustomHeaderColumn({ headerName: intl.formatMessage({ id: 'Side' }), @@ -171,7 +172,8 @@ const ShortCircuitAnalysisResultTable: FunctionComponent unitToKiloUnit(params.data?.limitMin), + valueGetter: (params: ValueGetterParams) => + convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.limitMin), }), makeAgGridCustomHeaderColumn({ headerName: intl.formatMessage({ id: 'IscMaxKA' }), @@ -182,7 +184,8 @@ const ShortCircuitAnalysisResultTable: FunctionComponent unitToKiloUnit(params.data?.limitMax), + valueGetter: (params: ValueGetterParams) => + convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.limitMax), }), makeAgGridCustomHeaderColumn({ headerName: intl.formatMessage({ id: 'PscMVA' }), @@ -203,7 +206,8 @@ const ShortCircuitAnalysisResultTable: FunctionComponent unitToKiloUnit(params.data?.deltaCurrentIpMin), + valueGetter: (params: ValueGetterParams) => + convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.deltaCurrentIpMin), }), makeAgGridCustomHeaderColumn({ headerName: intl.formatMessage({ id: 'deltaCurrentIpMax' }), @@ -214,7 +218,8 @@ const ShortCircuitAnalysisResultTable: FunctionComponent unitToKiloUnit(params.data?.deltaCurrentIpMax), + valueGetter: (params: ValueGetterParams) => + convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.deltaCurrentIpMax), }), { field: 'linkedElementId', diff --git a/src/components/spreadsheet/config/equipment/line.ts b/src/components/spreadsheet/config/equipment/line.ts index 6585d2dfdc..dc6bc85b71 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 '../../../dialogs/converter-unit-utils'; 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..182769a329 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 '../../../dialogs/converter-unit-utils'; 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..486a6e48d5 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 '../../../dialogs/converter-unit-utils'; 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..3bfb5ac4e1 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 '../../../dialogs/converter-unit-utils'; 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) => + convertOutputValues( + FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, + params.data?.identifiableShortCircuit?.ipMin + ) + ), + valueGetter: (params) => + convertOutputValues( + FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, + params.data?.identifiableShortCircuit?.ipMin + ), valueSetter: (params) => { params.data.identifiableShortCircuit = { ...params.data.identifiableShortCircuit, - ipMin: kiloUnitToUnit(params.newValue), + ipMin: convertInputValues(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) => + convertOutputValues( + FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, + params.data?.identifiableShortCircuit?.ipMax + ) + ), + valueGetter: (params) => + convertOutputValues( + FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, + params.data?.identifiableShortCircuit?.ipMax + ), valueSetter: (params) => { params.data.identifiableShortCircuit = { ...params.data.identifiableShortCircuit, - ipMax: kiloUnitToUnit(params.newValue), + ipMax: convertInputValues(FieldType.LOW_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..2a411e1a74 100644 --- a/src/components/tooltips/equipment-popover.jsx +++ b/src/components/tooltips/equipment-popover.jsx @@ -16,8 +16,8 @@ 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 } from '../dialogs/converter-unit-utils'; const styles = { tableCells: { @@ -220,12 +220,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 +234,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)); From 16ef55eea70614f0dd664ffa179cc72de803e979 Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Wed, 11 Dec 2024 13:46:07 +0100 Subject: [PATCH 02/13] add licence --- src/components/dialogs/converter-unit-utils.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/dialogs/converter-unit-utils.ts b/src/components/dialogs/converter-unit-utils.ts index e0913ffa26..3ee4ddf1bf 100644 --- a/src/components/dialogs/converter-unit-utils.ts +++ b/src/components/dialogs/converter-unit-utils.ts @@ -1,3 +1,10 @@ +/** + * Copyright (c) 2020, 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 { kiloUnitToUnit, microUnitToUnit, unitToKiloUnit, unitToMicroUnit } from '@gridsuite/commons-ui'; export enum FieldType { From 013ee588b24491c16e5f49425261782adc4da76d Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Mon, 16 Dec 2024 15:13:12 +0100 Subject: [PATCH 03/13] Merge two fieldType from commons-ui and study Signed-off-by: Thang PHAM --- .../dialogs/converter-unit-utils.ts | 94 ------------------- .../assignment/assignment-constants.ts | 10 +- .../assignment/assignment-utils.ts | 6 -- .../assignment/assignment.type.ts | 46 --------- .../modification-by-assignment-dialog.tsx | 16 +++- .../by-formula/formula/formula-utils.tsx | 2 +- .../line-characteristics-pane.jsx | 3 +- .../line/creation/line-creation-dialog.jsx | 10 +- .../modification/line-modification-dialog.jsx | 9 +- .../tabular-modification-dialog.jsx | 9 +- ...dings-transformer-characteristics-pane.jsx | 3 +- ...o-windings-transformer-creation-dialog.jsx | 9 +- ...ndings-transformer-modification-dialog.jsx | 9 +- .../voltage-level-creation-dialog.jsx | 9 +- .../voltage-level-modification-dialog.jsx | 9 +- .../shortcircuit-analysis-result-content.ts | 2 +- .../shortcircuit-analysis-result-table.tsx | 3 +- .../spreadsheet/config/equipment/line.ts | 2 +- .../spreadsheet/config/equipment/tie-line.ts | 2 +- .../equipment/two-windings-transformer.ts | 2 +- .../config/equipment/voltage-level.ts | 2 +- src/components/tooltips/equipment-popover.jsx | 3 +- 22 files changed, 76 insertions(+), 184 deletions(-) delete mode 100644 src/components/dialogs/converter-unit-utils.ts diff --git a/src/components/dialogs/converter-unit-utils.ts b/src/components/dialogs/converter-unit-utils.ts deleted file mode 100644 index 3ee4ddf1bf..0000000000 --- a/src/components/dialogs/converter-unit-utils.ts +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Copyright (c) 2020, 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 { kiloUnitToUnit, microUnitToUnit, unitToKiloUnit, unitToMicroUnit } from '@gridsuite/commons-ui'; - -export enum FieldType { - ID = 'ID', - NAME = 'NAME', - NOMINAL_VOLTAGE = 'NOMINAL_VOLTAGE', - TARGET_V = 'TARGET_V', - TARGET_P = 'TARGET_P', - COUNTRY = 'COUNTRY', - 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', - P0 = 'P0', - Q0 = 'Q0', - LOW_VOLTAGE_LIMIT = 'LOW_VOLTAGE_LIMIT', - HIGH_VOLTAGE_LIMIT = 'HIGH_VOLTAGE_LIMIT', - SECTION_COUNT = 'SECTION_COUNT', - MAXIMUM_SECTION_COUNT = 'MAXIMUM_SECTION_COUNT', - CONNECTED = 'CONNECTED', - MAX_Q_AT_NOMINAL_V = 'MAX_Q_AT_NOMINAL_V', - SHUNT_CONDUCTANCE_1 = 'SHUNT_CONDUCTANCE_1', - SHUNT_CONDUCTANCE_2 = 'SHUNT_CONDUCTANCE_2', - SHUNT_SUSCEPTANCE = 'SHUNT_SUSCEPTANCE', - SHUNT_SUSCEPTANCE_1 = 'SHUNT_SUSCEPTANCE_1', - SHUNT_SUSCEPTANCE_2 = 'SHUNT_SUSCEPTANCE_2', - VOLTAGE_SET_POINT = 'VOLTAGE_SET_POINT', - ACTIVE_POWER_SET_POINT = 'ACTIVE_POWER_SET_POINT', - REACTIVE_POWER_SET_POINT = 'REACTIVE_POWER_SET_POINT', - LOW_SHORT_CIRCUIT_CURRENT_LIMIT = 'LOW_SHORT_CIRCUIT_CURRENT_LIMIT', - HIGH_SHORT_CIRCUIT_CURRENT_LIMIT = 'HIGH_SHORT_CIRCUIT_CURRENT_LIMIT', - MAXIMUM_SUSCEPTANCE = 'MAXIMUM_SUSCEPTANCE', - R = 'R', - X = 'X', - G = 'G', - B = 'B', - G1 = 'G1', - B1 = 'B1', - G2 = 'G2', - B2 = 'B2', -} - -const microUnits = [ - FieldType.SHUNT_CONDUCTANCE_1, - FieldType.SHUNT_CONDUCTANCE_2, - FieldType.SHUNT_SUSCEPTANCE_1, - FieldType.SHUNT_SUSCEPTANCE_2, - FieldType.G, - FieldType.B, - FieldType.G1, - FieldType.B1, - FieldType.G2, - FieldType.B2, -]; - -const kiloUnits = [FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT]; -export function convertInputValues(field: FieldType, value: any) { - if (microUnits.includes(field)) { - if (!Array.isArray(value)) { - return value ? unitToMicroUnit(value) : value; - } - return value.map((a: number) => unitToMicroUnit(a)); - } - if (kiloUnits.includes(field)) { - if (!Array.isArray(value)) { - return value ? kiloUnitToUnit(value) : value; - } - return value.map((a: number) => kiloUnitToUnit(a)); - } - return value; -} - -export function convertOutputValues(field: FieldType, value: any) { - if (microUnits.includes(field)) { - if (!Array.isArray(value)) { - return value ? microUnitToUnit(value) : value; - } - return value.map((a: number) => microUnitToUnit(a)); - } - if (kiloUnits.includes(field)) { - if (!Array.isArray(value)) { - return value ? unitToKiloUnit(value) : value; - } - return value.map((a: number) => unitToKiloUnit(a)); - } - return value; -} 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 80a2ab5225..f4c2e455e9 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 } from '@gridsuite/commons-ui'; +import { EquipmentType, FieldType } from '@gridsuite/commons-ui'; import { KILO_AMPERE, MICRO_SIEMENS } from '../../../../../utils/field-constants'; export const FIELD_OPTIONS = { @@ -108,8 +108,8 @@ export const FIELD_OPTIONS = { unit: MICRO_SIEMENS, dataType: DataType.DOUBLE, }, - 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, @@ -303,7 +303,7 @@ export const EQUIPMENTS_FIELDS = { FIELD_OPTIONS.MAXIMUM_SECTION_COUNT, FIELD_OPTIONS.SECTION_COUNT, FIELD_OPTIONS.MAXIMUM_SUSCEPTANCE, - FIELD_OPTIONS.MAXIMUM_Q_AT_NOMINAL_VOLTAGE, + 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 5c2a062a4b..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,12 +26,6 @@ export const getFieldOption = (fieldName?: string | null) => { return Object.values(FIELD_OPTIONS).find((fieldOption) => fieldOption.id === fieldName); }; -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 e9c566cddc..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,7 +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, getAssignmentFromEditData, getAssignmentInitialValue, getAssignmentsSchema, @@ -26,7 +31,6 @@ import { } from './assignment/assignment-utils'; import { Assignment, ModificationByAssignment } from './assignment/assignment.type'; import { DeepNullable } from '../../../../utils/ts-utils'; -import { convertOutputValues, FieldType } from '../../../converter-unit-utils'; const formSchema = yup .object() @@ -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,6 @@ const ModificationByAssignmentDialog: FC = ({ (formData: ModificationByAssignment) => { const assignmentsList = formData[ASSIGNMENTS].map((assignment) => { const dataType = getDataType(assignment[EDITED_FIELD]); - console.log('=================assignment[EDITED_FIELD]', assignment[EDITED_FIELD]); const fieldKey = assignment[EDITED_FIELD] as keyof typeof FieldType; const field = FieldType[fieldKey]; const value = assignment[VALUE_FIELD]; 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..da7000a8a4 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 @@ -70,7 +70,7 @@ export const EQUIPMENTS_FIELDS: EquipmentFields = { { 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_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 bd5043825e..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, @@ -24,7 +24,6 @@ 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'; -import { convertInputValues, FieldType } from '../../../converter-unit-utils'; const styles = { h3: { 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 777588e2d9..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 { @@ -75,7 +82,6 @@ import { toModificationProperties, } from '../../common/properties/property-utils'; import GridItem from '../../../commons/grid-item'; -import { convertInputValues, convertOutputValues, FieldType } from '../../../converter-unit-utils'; const emptyFormData = { ...getHeaderEmptyFormData(), 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 17d1497780..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, @@ -80,7 +86,6 @@ import { getConnectivityFormData, getCont1Cont2WithPositionEmptyFormData, } from '../../../connectivity/connectivity-form-utils'; -import { convertInputValues, convertOutputValues, FieldType } from '../../../converter-unit-utils'; export const LineModificationDialogTab = { CONNECTIVITY_TAB: 0, 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 8d1083db0e..b2311d96f1 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 @@ -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 { useForm } from 'react-hook-form'; import { useCallback, useEffect } from 'react'; import PropTypes from 'prop-types'; @@ -24,7 +30,6 @@ import { TABULAR_MODIFICATION_TYPES, } from './tabular-modification-utils'; import { useIntl } from 'react-intl'; -import { convertInputValues, convertOutputValues, FieldType } from '../../converter-unit-utils'; import { toModificationOperation } from '../../../utils/utils.js'; const formSchema = yup 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 a3affc2ad4..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,12 +8,11 @@ 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 PropertiesForm from '../../common/properties/properties-form'; import GridSection from '../../../commons/grid-section'; import GridItem from '../../../commons/grid-item'; -import { convertInputValues, FieldType } from '../../../converter-unit-utils'; 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.jsx b/src/components/dialogs/network-modifications/two-windings-transformer/creation/two-windings-transformer-creation-dialog.jsx index d1bf25478b..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 { @@ -103,7 +109,6 @@ import { getPropertiesFromModification, toModificationProperties, } from '../../common/properties/property-utils'; -import { convertInputValues, convertOutputValues, FieldType } from '../../../converter-unit-utils'; /** * Dialog to create a two windings transformer in the network 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 b739d10190..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 { @@ -124,7 +130,6 @@ import { getConnectivityFormData, getCont1Cont2WithPositionEmptyFormData, } from '../../../connectivity/connectivity-form-utils'; -import { convertInputValues, convertOutputValues, FieldType } from '../../../converter-unit-utils'; const emptyFormData = { [EQUIPMENT_NAME]: '', 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 325fca485e..3a57d809e5 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'; @@ -52,7 +58,6 @@ import { getPropertiesFromModification, toModificationProperties, } from '../../common/properties/property-utils'; -import { convertInputValues, convertOutputValues, FieldType } from '../../../converter-unit-utils.js'; /** * Dialog to create a load in the network 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 3e94d01234..16067b6a65 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,7 +21,13 @@ 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 { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES } from 'components/utils/equipment-types'; @@ -36,7 +42,6 @@ import { modificationPropertiesSchema, toModificationProperties, } from '../../common/properties/property-utils'; -import { convertInputValues, convertOutputValues, FieldType } from '../../../converter-unit-utils.js'; const emptyFormData = { [EQUIPMENT_NAME]: '', diff --git a/src/components/results/shortcircuit/shortcircuit-analysis-result-content.ts b/src/components/results/shortcircuit/shortcircuit-analysis-result-content.ts index 03cd715d77..2defea16dd 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 { convertInputValues, FieldType } from '../../dialogs/converter-unit-utils'; +import { convertInputValues, FieldType } from '@gridsuite/commons-ui'; export const PAGE_OPTIONS = [25, 100, 500, 1000]; diff --git a/src/components/results/shortcircuit/shortcircuit-analysis-result-table.tsx b/src/components/results/shortcircuit/shortcircuit-analysis-result-table.tsx index b33171a983..60a5ce419b 100644 --- a/src/components/results/shortcircuit/shortcircuit-analysis-result-table.tsx +++ b/src/components/results/shortcircuit/shortcircuit-analysis-result-table.tsx @@ -24,9 +24,8 @@ import { FilterPropsType, } from '../../custom-aggrid/custom-aggrid-header.type'; import { makeAgGridCustomHeaderColumn } from '../../custom-aggrid/custom-aggrid-header-utils'; -import { CustomAGGrid } from '@gridsuite/commons-ui'; +import { convertOutputValues, CustomAGGrid, FieldType } from '@gridsuite/commons-ui'; import { convertSide } from '../loadflow/load-flow-result-utils'; -import { convertOutputValues, FieldType } from '../../dialogs/converter-unit-utils'; interface ShortCircuitAnalysisResultProps { result: SCAFaultResult[]; diff --git a/src/components/spreadsheet/config/equipment/line.ts b/src/components/spreadsheet/config/equipment/line.ts index dc6bc85b71..8bd6b822d2 100644 --- a/src/components/spreadsheet/config/equipment/line.ts +++ b/src/components/spreadsheet/config/equipment/line.ts @@ -20,7 +20,7 @@ import { } from './common-config'; import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; import { genericColumnOfProperties } from '../common/column-properties'; -import { convertInputValues, FieldType } from '../../../dialogs/converter-unit-utils'; +import { convertInputValues, FieldType } from '@gridsuite/commons-ui'; export const LINE_TAB_DEF = { index: 2, diff --git a/src/components/spreadsheet/config/equipment/tie-line.ts b/src/components/spreadsheet/config/equipment/tie-line.ts index 182769a329..9f0a8b5957 100644 --- a/src/components/spreadsheet/config/equipment/tie-line.ts +++ b/src/components/spreadsheet/config/equipment/tie-line.ts @@ -20,7 +20,7 @@ import { } from './common-config'; import { MEDIUM_COLUMN_WIDTH } from '../../utils/constants'; import { genericColumnOfPropertiesReadonly } from '../common/column-properties'; -import { convertInputValues, FieldType } from '../../../dialogs/converter-unit-utils'; +import { convertInputValues, FieldType } from '@gridsuite/commons-ui'; export const TIE_LINE_TAB_DEF = { index: 15, diff --git a/src/components/spreadsheet/config/equipment/two-windings-transformer.ts b/src/components/spreadsheet/config/equipment/two-windings-transformer.ts index 486a6e48d5..d4f66b1aa1 100644 --- a/src/components/spreadsheet/config/equipment/two-windings-transformer.ts +++ b/src/components/spreadsheet/config/equipment/two-windings-transformer.ts @@ -38,7 +38,7 @@ import { numericalCellEditorConfig, standardSelectCellEditorConfig, } from '../common/cell-editors'; -import { convertInputValues, FieldType } from '../../../dialogs/converter-unit-utils'; +import { convertInputValues, FieldType } from '@gridsuite/commons-ui'; function getTwtRatioRegulationModeId(twt: any) { //regulationMode is set by the user (in edit mode) diff --git a/src/components/spreadsheet/config/equipment/voltage-level.ts b/src/components/spreadsheet/config/equipment/voltage-level.ts index 3bfb5ac4e1..75289fdc68 100644 --- a/src/components/spreadsheet/config/equipment/voltage-level.ts +++ b/src/components/spreadsheet/config/equipment/voltage-level.ts @@ -20,7 +20,7 @@ import { } from './common-config'; import { genericColumnOfPropertiesEditPopup } from '../common/column-properties'; import { numericalCellEditorConfig } from '../common/cell-editors'; -import { convertInputValues, convertOutputValues, FieldType } from '../../../dialogs/converter-unit-utils'; +import { convertInputValues, convertOutputValues, FieldType } from '@gridsuite/commons-ui'; function generateEditableNumericColumnDefinition< TId extends string, diff --git a/src/components/tooltips/equipment-popover.jsx b/src/components/tooltips/equipment-popover.jsx index 2a411e1a74..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 { useDebounce } from '@gridsuite/commons-ui'; -import { convertInputValues, FieldType } from '../dialogs/converter-unit-utils'; +import { convertInputValues, FieldType, useDebounce } from '@gridsuite/commons-ui'; const styles = { tableCells: { From 1e7eb1f0c0936276924fadb3bf917027439efd68 Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Tue, 17 Dec 2024 14:02:44 +0100 Subject: [PATCH 04/13] fix fieldType --- .../voltage-level/creation/voltage-level-creation-dialog.jsx | 2 +- .../modification/voltage-level-modification-dialog.jsx | 2 +- src/components/spreadsheet/config/equipment/voltage-level.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 3a57d809e5..7f91dc858b 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 @@ -227,7 +227,7 @@ const VoltageLevelCreationDialog = ({ voltageLevel[LOW_SHORT_CIRCUIT_CURRENT_LIMIT] ), ipMax: convertInputValues( - FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, + FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevel[HIGH_SHORT_CIRCUIT_CURRENT_LIMIT] ), busbarCount: voltageLevel[BUS_BAR_COUNT], 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 16067b6a65..c6548c4922 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 @@ -190,7 +190,7 @@ const VoltageLevelModificationDialog = ({ voltageLevel[LOW_SHORT_CIRCUIT_CURRENT_LIMIT] ), highShortCircuitCurrentLimit: convertInputValues( - FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, + FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevel[HIGH_SHORT_CIRCUIT_CURRENT_LIMIT] ), properties: toModificationProperties(voltageLevel), diff --git a/src/components/spreadsheet/config/equipment/voltage-level.ts b/src/components/spreadsheet/config/equipment/voltage-level.ts index 75289fdc68..fa55ec070e 100644 --- a/src/components/spreadsheet/config/equipment/voltage-level.ts +++ b/src/components/spreadsheet/config/equipment/voltage-level.ts @@ -135,7 +135,7 @@ export const VOLTAGE_LEVEL_TAB_DEF = { valueSetter: (params) => { params.data.identifiableShortCircuit = { ...params.data.identifiableShortCircuit, - ipMax: convertInputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.newValue), + ipMax: convertInputValues(FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, params.newValue), }; return true; }, From bdfed42f9fbe8de6482c9e982eae0d19db101b96 Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Tue, 17 Dec 2024 15:43:38 +0100 Subject: [PATCH 05/13] revert conversion unit for result table --- .../shortcircuit-analysis-result-content.ts | 8 +++----- .../shortcircuit-analysis-result-table.tsx | 17 ++++++----------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/components/results/shortcircuit/shortcircuit-analysis-result-content.ts b/src/components/results/shortcircuit/shortcircuit-analysis-result-content.ts index 2defea16dd..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 { convertInputValues, FieldType } from '@gridsuite/commons-ui'; +import { kiloUnitToUnit } from '@gridsuite/commons-ui'; export const PAGE_OPTIONS = [25, 100, 500, 1000]; @@ -49,8 +49,6 @@ export const mappingTabs = (analysisType: ShortCircuitAnalysisType): string => { export const convertFilterValues = (filterSelector: FilterSelectorType[]) => { return filterSelector.map((filter) => { - const fieldKey = filter.column as keyof typeof FieldType; - const field = FieldType[fieldKey]; switch (filter.column) { case 'current': case 'deltaCurrentIpMax': @@ -59,8 +57,8 @@ export const convertFilterValues = (filterSelector: FilterSelectorType[]) => { case 'limitMax': return { ...filter, - value: convertInputValues(field, filter.value), - tolerance: convertInputValues(field, 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 60a5ce419b..a5cf613850 100644 --- a/src/components/results/shortcircuit/shortcircuit-analysis-result-table.tsx +++ b/src/components/results/shortcircuit/shortcircuit-analysis-result-table.tsx @@ -24,7 +24,7 @@ import { FilterPropsType, } from '../../custom-aggrid/custom-aggrid-header.type'; import { makeAgGridCustomHeaderColumn } from '../../custom-aggrid/custom-aggrid-header-utils'; -import { convertOutputValues, CustomAGGrid, FieldType } from '@gridsuite/commons-ui'; +import { CustomAGGrid, unitToKiloUnit } from '@gridsuite/commons-ui'; import { convertSide } from '../loadflow/load-flow-result-utils'; interface ShortCircuitAnalysisResultProps { @@ -142,8 +142,7 @@ const ShortCircuitAnalysisResultTable: FunctionComponent - convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.current), + valueGetter: (params: ValueGetterParams) => unitToKiloUnit(params.data?.current), }), makeAgGridCustomHeaderColumn({ headerName: intl.formatMessage({ id: 'Side' }), @@ -171,8 +170,7 @@ const ShortCircuitAnalysisResultTable: FunctionComponent - convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.limitMin), + valueGetter: (params: ValueGetterParams) => unitToKiloUnit(params.data?.limitMin), }), makeAgGridCustomHeaderColumn({ headerName: intl.formatMessage({ id: 'IscMaxKA' }), @@ -183,8 +181,7 @@ const ShortCircuitAnalysisResultTable: FunctionComponent - convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.limitMax), + valueGetter: (params: ValueGetterParams) => unitToKiloUnit(params.data?.limitMax), }), makeAgGridCustomHeaderColumn({ headerName: intl.formatMessage({ id: 'PscMVA' }), @@ -205,8 +202,7 @@ const ShortCircuitAnalysisResultTable: FunctionComponent - convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.deltaCurrentIpMin), + valueGetter: (params: ValueGetterParams) => unitToKiloUnit(params.data?.deltaCurrentIpMin), }), makeAgGridCustomHeaderColumn({ headerName: intl.formatMessage({ id: 'deltaCurrentIpMax' }), @@ -217,8 +213,7 @@ const ShortCircuitAnalysisResultTable: FunctionComponent - convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.deltaCurrentIpMax), + valueGetter: (params: ValueGetterParams) => unitToKiloUnit(params.data?.deltaCurrentIpMax), }), { field: 'linkedElementId', From 0865e4a928666f197a8e0b72ad46356dc5d75bbc Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Tue, 17 Dec 2024 16:32:20 +0100 Subject: [PATCH 06/13] add conversion unit to modification by formula --- .../by-formula/by-formula-dialog.jsx | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) 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, From 853950c69ffb400eefbd0037e3b0401e8b03bb68 Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Tue, 17 Dec 2024 18:41:38 +0100 Subject: [PATCH 07/13] adapt the conversion unit to modifcation by tabular --- .../tabular-modification-dialog.jsx | 15 ++++------- .../tabular-modification-utils.ts | 25 ++++++++++++++++++- 2 files changed, 29 insertions(+), 11 deletions(-) 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 b2311d96f1..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 @@ -7,13 +7,7 @@ import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; -import { - convertInputValues, - convertOutputValues, - CustomFormProvider, - FieldType, - useSnackMessage, -} from '@gridsuite/commons-ui'; +import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui'; import { useForm } from 'react-hook-form'; import { useCallback, useEffect } from 'react'; import PropTypes from 'prop-types'; @@ -25,12 +19,13 @@ import { createTabulareModification } from 'services/study/network-modifications import { FetchStatus } from 'services/utils'; import TabularModificationForm from './tabular-modification-form'; import { + convertInputValue, + convertOutputValue, formatModification, getEquipmentTypeFromModificationType, TABULAR_MODIFICATION_TYPES, } from './tabular-modification-utils'; import { useIntl } from 'react-intl'; -import { toModificationOperation } from '../../../utils/utils.js'; const formSchema = yup .object() @@ -81,7 +76,7 @@ const TabularModificationDialog = ({ const modifications = editData?.modifications.map((modif) => { const modification = {}; Object.keys(formatModification(modif)).forEach((key) => { - modification[key] = convertInputValues(FieldType[key], modif[key]); + modification[key] = convertInputValue(key, modif[key]); }); return modification; }); @@ -100,7 +95,7 @@ const TabularModificationDialog = ({ type: modificationType, }; Object.keys(row).forEach((key) => { - modification[key] = toModificationOperation(convertOutputValues(FieldType[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 2962ef59be..fd79e32a96 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,7 +5,7 @@ * 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, @@ -48,6 +48,7 @@ import { VOLTAGE_REGULATION_ON, X, } from 'components/utils/field-constants'; +import { toModificationOperation } from '../../../utils/utils'; export interface TabularModificationFields { [key: string]: string[]; @@ -117,3 +118,25 @@ export const getEquipmentTypeFromModificationType = (type: string) => { export const styles = { grid: { height: 500, width: '100%' }, }; + +const keyToFieldType = (key: string) => + FieldType[ + key + .split(/\.?(?=[A-Z])/) + .join('_') + .toUpperCase() as keyof typeof FieldType + ]; + +export const convertInputValue = (key: string, value: { value: string | number }) => { + if (key === EQUIPMENT_ID) { + return value; + } + return convertInputValues(keyToFieldType(key), value?.value); +}; + +export const convertOutputValue = (key: string, value: string | number) => { + if (key === EQUIPMENT_ID) { + return value; + } + return toModificationOperation(convertOutputValues(keyToFieldType(key), value)); +}; From ebadd4a241945bf687ded016b66af88acec30e18 Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Wed, 18 Dec 2024 09:11:03 +0100 Subject: [PATCH 08/13] fix converter unit input or output --- .../creation/voltage-level-creation-dialog.jsx | 8 ++++---- .../voltage-level-modification-dialog.jsx | 12 ++++++------ .../spreadsheet/config/equipment/voltage-level.ts | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) 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 7f91dc858b..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 @@ -164,11 +164,11 @@ 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]: convertOutputValues( + [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]: convertInputValues( FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, fromCopy ? voltageLevel.identifiableShortCircuit?.ipMin : voltageLevel.ipMin ), - [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: convertOutputValues( + [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: convertInputValues( FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, fromCopy ? voltageLevel.identifiableShortCircuit?.ipMax : voltageLevel.ipMax ), @@ -222,11 +222,11 @@ const VoltageLevelCreationDialog = ({ nominalV: voltageLevel[NOMINAL_V], lowVoltageLimit: voltageLevel[LOW_VOLTAGE_LIMIT], highVoltageLimit: voltageLevel[HIGH_VOLTAGE_LIMIT], - ipMin: convertInputValues( + ipMin: convertOutputValues( FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevel[LOW_SHORT_CIRCUIT_CURRENT_LIMIT] ), - ipMax: convertInputValues( + ipMax: convertOutputValues( FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevel[HIGH_SHORT_CIRCUIT_CURRENT_LIMIT] ), 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 c6548c4922..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 @@ -111,9 +111,9 @@ const VoltageLevelModificationDialog = ({ [LOW_VOLTAGE_LIMIT]: editData?.lowVoltageLimit?.value ?? null, [HIGH_VOLTAGE_LIMIT]: editData?.highVoltageLimit?.value ?? null, [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]: - convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, editData?.ipMin?.value) ?? null, + convertInputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, editData?.ipMin?.value) ?? null, [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: - convertOutputValues(FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, editData?.ipMax?.value) ?? null, + convertInputValues(FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, editData?.ipMax?.value) ?? null, ...getPropertiesFromModification(editData.properties), }); } @@ -135,11 +135,11 @@ 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 = convertOutputValues( + voltageLevel.identifiableShortCircuit.ipMax = convertInputValues( FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevel.identifiableShortCircuit?.ipMax ); - voltageLevel.identifiableShortCircuit.ipMin = convertOutputValues( + voltageLevel.identifiableShortCircuit.ipMin = convertInputValues( FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevel.identifiableShortCircuit?.ipMin ); @@ -185,11 +185,11 @@ const VoltageLevelModificationDialog = ({ nominalV: voltageLevel[NOMINAL_V], lowVoltageLimit: voltageLevel[LOW_VOLTAGE_LIMIT], highVoltageLimit: voltageLevel[HIGH_VOLTAGE_LIMIT], - lowShortCircuitCurrentLimit: convertInputValues( + lowShortCircuitCurrentLimit: convertOutputValues( FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevel[LOW_SHORT_CIRCUIT_CURRENT_LIMIT] ), - highShortCircuitCurrentLimit: convertInputValues( + highShortCircuitCurrentLimit: convertOutputValues( FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevel[HIGH_SHORT_CIRCUIT_CURRENT_LIMIT] ), diff --git a/src/components/spreadsheet/config/equipment/voltage-level.ts b/src/components/spreadsheet/config/equipment/voltage-level.ts index fa55ec070e..2c341c96ec 100644 --- a/src/components/spreadsheet/config/equipment/voltage-level.ts +++ b/src/components/spreadsheet/config/equipment/voltage-level.ts @@ -92,20 +92,20 @@ export const VOLTAGE_LEVEL_TAB_DEF = { ...editableColumnConfig, numeric: true, ...numericalCellEditorConfig((params) => - convertOutputValues( + convertInputValues( FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.identifiableShortCircuit?.ipMin ) ), valueGetter: (params) => - convertOutputValues( + convertInputValues( FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.identifiableShortCircuit?.ipMin ), valueSetter: (params) => { params.data.identifiableShortCircuit = { ...params.data.identifiableShortCircuit, - ipMin: convertInputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.newValue), + ipMin: convertOutputValues(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, params.newValue), }; return true; }, @@ -122,20 +122,20 @@ export const VOLTAGE_LEVEL_TAB_DEF = { ...editableColumnConfig, numeric: true, ...numericalCellEditorConfig((params) => - convertOutputValues( + convertInputValues( FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.identifiableShortCircuit?.ipMax ) ), valueGetter: (params) => - convertOutputValues( + convertInputValues( FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, params.data?.identifiableShortCircuit?.ipMax ), valueSetter: (params) => { params.data.identifiableShortCircuit = { ...params.data.identifiableShortCircuit, - ipMax: convertInputValues(FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, params.newValue), + ipMax: convertOutputValues(FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, params.newValue), }; return true; }, From c38b717c429529d6bad1778dff9a18abab7d5193 Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Wed, 18 Dec 2024 10:00:10 +0100 Subject: [PATCH 09/13] enhance the name of the mapper function --- .../tabular-modification-utils.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 fd79e32a96..d57de883c7 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 @@ -119,7 +119,12 @@ export const styles = { grid: { height: 500, width: '100%' }, }; -const keyToFieldType = (key: string) => +/** + * Convert a camelCase string to SNAKE_CASE format and map it to a key in the FieldType enum. + * @param key - The camelCase string to be converted. + * @returns The corresponding value from the FieldType enum. + */ +const convertCamelToSnake = (key: string) => FieldType[ key .split(/\.?(?=[A-Z])/) @@ -131,12 +136,12 @@ export const convertInputValue = (key: string, value: { value: string | number } if (key === EQUIPMENT_ID) { return value; } - return convertInputValues(keyToFieldType(key), value?.value); + return convertInputValues(convertCamelToSnake(key), value?.value); }; export const convertOutputValue = (key: string, value: string | number) => { if (key === EQUIPMENT_ID) { return value; } - return toModificationOperation(convertOutputValues(keyToFieldType(key), value)); + return toModificationOperation(convertOutputValues(convertCamelToSnake(key), value)); }; From 2df7d906401cb2140cacca0bb5f0e51efa2952e3 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Wed, 18 Dec 2024 15:22:08 +0100 Subject: [PATCH 10/13] rename MAXIMUM_SUSCEPTANCE to MAX_SUSCEPTANCE Signed-off-by: Thang PHAM --- package-lock.json | 10 ++++++---- package.json | 4 ++-- .../by-assignment/assignment/assignment-constants.ts | 6 +++--- .../by-filter/by-formula/formula/formula-utils.tsx | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3226817bf2..9f73fdd2b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", - "@gridsuite/commons-ui": "0.73.1", + "@gridsuite/commons-ui": "file:../commons-ui/gridsuite-commons-ui-0.74.0.tgz", "@hookform/resolvers": "^3.3.4", "@mui/icons-material": "^5.15.14", "@mui/lab": "5.0.0-alpha.169", @@ -3202,9 +3202,10 @@ } }, "node_modules/@gridsuite/commons-ui": { - "version": "0.73.1", - "resolved": "https://registry.npmjs.org/@gridsuite/commons-ui/-/commons-ui-0.73.1.tgz", - "integrity": "sha512-VGcZrThKBbHwofCGq7NxomRth0aI3ARr0cyGndnmRe5GF4IOyXysKBqqyt3T/FTJeiD+6flq+T6BW9lk0Bnb5Q==", + "version": "0.74.0", + "resolved": "file:../commons-ui/gridsuite-commons-ui-0.74.0.tgz", + "integrity": "sha512-Ar1g83IWCAzs3Jr5lBB73golBOge1wgyhUnPW4l3uHnJnP2U4Ff/wZGU5z5CkhpeX3enRYxr88NSkuOaIZ6/8g==", + "license": "MPL-2.0", "dependencies": { "@react-querybuilder/dnd": "^7.2.0", "@react-querybuilder/material": "^7.2.0", @@ -3221,6 +3222,7 @@ "react-dnd-html5-backend": "^16.0.1", "react-querybuilder": "^7.2.0", "react-virtualized": "^9.22.5", + "reconnecting-websocket": "^4.4.0", "uuid": "^9.0.1" }, "engines": { diff --git a/package.json b/package.json index 980ab99b6a..39eb05c1d7 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dependencies": { "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", - "@gridsuite/commons-ui": "0.73.1", + "@gridsuite/commons-ui": "file:../commons-ui/gridsuite-commons-ui-0.74.0.tgz", "@hookform/resolvers": "^3.3.4", "@mui/icons-material": "^5.15.14", "@mui/lab": "5.0.0-alpha.169", @@ -17,6 +17,7 @@ "@reduxjs/toolkit": "^2.2.3", "@svgdotjs/svg.js": "^3.2.0", "@svgdotjs/svg.panzoom.js": "^2.1.2", + "@xyflow/react": "^12.3.2", "ag-grid-community": "^31.0.0", "ag-grid-react": "^31.2.0", "cheap-ruler": "^3.0.2", @@ -35,7 +36,6 @@ "react-beautiful-dnd": "^13.1.1", "react-csv-downloader": "^3.1.0", "react-dom": "^18.2.0", - "@xyflow/react": "^12.3.2", "react-grid-layout": "^1.4.4", "react-hook-form": "^7.51.2", "react-intl": "^6.6.4", 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 f4c2e455e9..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 @@ -102,8 +102,8 @@ 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, @@ -302,7 +302,7 @@ export const EQUIPMENTS_FIELDS = { FIELD_OPTIONS.PROPERTY, FIELD_OPTIONS.MAXIMUM_SECTION_COUNT, FIELD_OPTIONS.SECTION_COUNT, - FIELD_OPTIONS.MAXIMUM_SUSCEPTANCE, + FIELD_OPTIONS.MAX_SUSCEPTANCE, FIELD_OPTIONS.MAX_Q_AT_NOMINAL_V, ], [EquipmentType.STATIC_VAR_COMPENSATOR]: [FIELD_OPTIONS.PROPERTY], 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 da7000a8a4..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,7 +69,7 @@ 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: 'MAX_SUSCEPTANCE', label: 'maxSusceptance' }, { id: 'MAX_Q_AT_NOMINAL_V', label: 'maxQAtNominalV' }, ], [EQUIPMENT_TYPES.VOLTAGE_LEVEL]: [ From f0fa241af07833e01fde27f0f00199ad1c0c1d8d Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Wed, 18 Dec 2024 15:29:36 +0100 Subject: [PATCH 11/13] revert modif in package.json Signed-off-by: Thang PHAM --- package-lock.json | 9 ++++----- package.json | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9f73fdd2b1..94d23e9734 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", - "@gridsuite/commons-ui": "file:../commons-ui/gridsuite-commons-ui-0.74.0.tgz", + "@gridsuite/commons-ui": "0.73.1", "@hookform/resolvers": "^3.3.4", "@mui/icons-material": "^5.15.14", "@mui/lab": "5.0.0-alpha.169", @@ -3202,10 +3202,9 @@ } }, "node_modules/@gridsuite/commons-ui": { - "version": "0.74.0", - "resolved": "file:../commons-ui/gridsuite-commons-ui-0.74.0.tgz", - "integrity": "sha512-Ar1g83IWCAzs3Jr5lBB73golBOge1wgyhUnPW4l3uHnJnP2U4Ff/wZGU5z5CkhpeX3enRYxr88NSkuOaIZ6/8g==", - "license": "MPL-2.0", + "version": "0.73.1", + "resolved": "https://registry.npmjs.org/@gridsuite/commons-ui/-/commons-ui-0.73.1.tgz", + "integrity": "sha512-VGcZrThKBbHwofCGq7NxomRth0aI3ARr0cyGndnmRe5GF4IOyXysKBqqyt3T/FTJeiD+6flq+T6BW9lk0Bnb5Q==", "dependencies": { "@react-querybuilder/dnd": "^7.2.0", "@react-querybuilder/material": "^7.2.0", diff --git a/package.json b/package.json index 39eb05c1d7..980ab99b6a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dependencies": { "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", - "@gridsuite/commons-ui": "file:../commons-ui/gridsuite-commons-ui-0.74.0.tgz", + "@gridsuite/commons-ui": "0.73.1", "@hookform/resolvers": "^3.3.4", "@mui/icons-material": "^5.15.14", "@mui/lab": "5.0.0-alpha.169", @@ -17,7 +17,6 @@ "@reduxjs/toolkit": "^2.2.3", "@svgdotjs/svg.js": "^3.2.0", "@svgdotjs/svg.panzoom.js": "^2.1.2", - "@xyflow/react": "^12.3.2", "ag-grid-community": "^31.0.0", "ag-grid-react": "^31.2.0", "cheap-ruler": "^3.0.2", @@ -36,6 +35,7 @@ "react-beautiful-dnd": "^13.1.1", "react-csv-downloader": "^3.1.0", "react-dom": "^18.2.0", + "@xyflow/react": "^12.3.2", "react-grid-layout": "^1.4.4", "react-hook-form": "^7.51.2", "react-intl": "^6.6.4", From 631011d50e761ab1023d9297e97abffdb6ae18a9 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Wed, 18 Dec 2024 15:35:14 +0100 Subject: [PATCH 12/13] revert modif in package-lock.json Signed-off-by: Thang PHAM --- package-lock.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 94d23e9734..3226817bf2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3221,7 +3221,6 @@ "react-dnd-html5-backend": "^16.0.1", "react-querybuilder": "^7.2.0", "react-virtualized": "^9.22.5", - "reconnecting-websocket": "^4.4.0", "uuid": "^9.0.1" }, "engines": { From 7b7d98bb7c097a4ff220dc0777287e8e50a65c59 Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Wed, 18 Dec 2024 19:18:31 +0100 Subject: [PATCH 13/13] Ignore maxSusceptance and maxQAtNominalV conversion in tabular Signed-off-by: Thang PHAM --- .../tabular-modification-utils.ts | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) 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 d57de883c7..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 @@ -119,29 +119,44 @@ export const styles = { grid: { height: 500, width: '100%' }, }; -/** - * Convert a camelCase string to SNAKE_CASE format and map it to a key in the FieldType enum. - * @param key - The camelCase string to be converted. - * @returns The corresponding value from the FieldType enum. - */ -const convertCamelToSnake = (key: string) => - FieldType[ - key - .split(/\.?(?=[A-Z])/) - .join('_') - .toUpperCase() as keyof typeof FieldType - ]; - export const convertInputValue = (key: string, value: { value: string | number }) => { - if (key === EQUIPMENT_ID) { - return value; + 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 convertInputValues(FieldType.B2, value?.value); + default: + return value?.value; } - return convertInputValues(convertCamelToSnake(key), value?.value); }; export const convertOutputValue = (key: string, value: string | number) => { - if (key === EQUIPMENT_ID) { - return value; + 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(convertOutputValues(FieldType.B2, value)); + default: + return toModificationOperation(value); } - return toModificationOperation(convertOutputValues(convertCamelToSnake(key), value)); };