Skip to content

Commit

Permalink
wip edit line ok (no submit)
Browse files Browse the repository at this point in the history
Signed-off-by: David BRAQUART <[email protected]>
  • Loading branch information
dbraquart committed Feb 10, 2025
1 parent a4df119 commit 2833202
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { MEASUREMENT_P1, MEASUREMENT_Q1, MEASUREMENT_P2, MEASUREMENT_Q2 } from 'components/utils/field-constants';
import {
getPowerWithValidityEditData,
getPowerWithValidityEmptyFormData,
getPowerWithValidityValidationSchema,
} from './power-with-validity-utils';
import yup from '../../../../utils/yup-config';

export function getBranchActiveReactivePowerEmptyFormData(id: string) {
return {
[id]: {
...getPowerWithValidityEmptyFormData(MEASUREMENT_P1),
...getPowerWithValidityEmptyFormData(MEASUREMENT_Q1),
...getPowerWithValidityEmptyFormData(MEASUREMENT_P2),
...getPowerWithValidityEmptyFormData(MEASUREMENT_Q2),
},
};
}

export const getBranchActiveReactivePowerValidationSchema = (id: string) => ({
[id]: yup.object().shape({
...getPowerWithValidityValidationSchema(MEASUREMENT_P1),
...getPowerWithValidityValidationSchema(MEASUREMENT_Q1),
...getPowerWithValidityValidationSchema(MEASUREMENT_P2),
...getPowerWithValidityValidationSchema(MEASUREMENT_Q2),
}),
});

export function getBranchActiveReactivePowerEditData(id: string, branchData: any) {
return {
[id]: {
...getPowerWithValidityEditData(MEASUREMENT_P1, branchData.measurementP1),
...getPowerWithValidityEditData(MEASUREMENT_Q1, branchData.measurementQ1),
...getPowerWithValidityEditData(MEASUREMENT_P2, branchData.measurementP2),
...getPowerWithValidityEditData(MEASUREMENT_Q2, branchData.measurementQ2),
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Copyright (c) 2025, 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 { Grid } from '@mui/material';
import {
BRANCH_MEASUREMENTS,
MEASUREMENT_P1,
MEASUREMENT_P2,
MEASUREMENT_Q1,
MEASUREMENT_Q2,
} from 'components/utils/field-constants';
import { FunctionComponent } from 'react';
import GridSection from '../../../commons/grid-section';
import GridItem from '../../../commons/grid-item';
import { BranchActiveReactivePowerMeasurementsFormProps } from './measurement.type';
import { PowerWithValidityForm } from './power-with-validity-form';
import { FieldType } from '@gridsuite/commons-ui';

const BranchActiveReactivePowerMeasurementsForm: FunctionComponent<BranchActiveReactivePowerMeasurementsFormProps> = ({
equipmentToModify,
}) => {
const activePower1 = `${BRANCH_MEASUREMENTS}.${MEASUREMENT_P1}`;
const reactivePower1 = `${BRANCH_MEASUREMENTS}.${MEASUREMENT_Q1}`;
const activePower2 = `${BRANCH_MEASUREMENTS}.${MEASUREMENT_P2}`;
const reactivePower2 = `${BRANCH_MEASUREMENTS}.${MEASUREMENT_Q2}`;

const activePower1Field = (
<PowerWithValidityForm
id={activePower1}
field={FieldType.ACTIVE_POWER}
measurement={equipmentToModify?.measurementP1}
/>
);

const reactivePower1Field = (
<PowerWithValidityForm
id={reactivePower1}
field={FieldType.REACTIVE_POWER}
measurement={equipmentToModify?.measurementQ1}
/>
);

const activePower2Field = (
<PowerWithValidityForm
id={activePower2}
field={FieldType.ACTIVE_POWER}
measurement={equipmentToModify?.measurementP2}
/>
);

const reactivePower2Field = (
<PowerWithValidityForm
id={reactivePower2}
field={FieldType.REACTIVE_POWER}
measurement={equipmentToModify?.measurementQ2}
/>
);

return (
<>
<GridSection title="Side1" heading={4} />
<Grid container spacing={2}>
<GridItem size={12}>{activePower1Field}</GridItem>
<GridItem size={12}>{reactivePower1Field}</GridItem>
</Grid>
<GridSection title="Side2" heading={4} />
<Grid container spacing={2}>
<GridItem size={12}>{activePower2Field}</GridItem>
<GridItem size={12}>{reactivePower2Field}</GridItem>
</Grid>
</>
);
};

export default BranchActiveReactivePowerMeasurementsForm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2025, 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 { FieldType } from '@gridsuite/commons-ui/dist/utils/types/fieldType';

export interface BranchActiveReactivePowerMeasurementsFormProps {
equipmentToModify: any;
}

export interface MeasurementInfo {
value: number;
validity: boolean;
}

export interface MeasurementProps {
id: string;
field: FieldType;
measurement?: MeasurementInfo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (c) 2025, 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 Grid from '@mui/material/Grid';
import { FunctionComponent, useMemo } from 'react';
import { useIntl } from 'react-intl';
import { convertInputValue, FieldType, FloatInput } from '@gridsuite/commons-ui';
import { MeasurementProps } from './measurement.type';
import CheckboxNullableInput from '../../../../utils/rhf-inputs/boolean-nullable-input';
import GridItem from '../../../commons/grid-item';
import { VALIDITY, VALUE } from '../../../../utils/field-constants';
import { ActivePowerAdornment, ReactivePowerAdornment } from '../../../dialog-utils';

export const PowerWithValidityForm: FunctionComponent<MeasurementProps> = ({ id, field, measurement }) => {
const intl = useIntl();

const previousValidityField = useMemo(() => {
return measurement?.validity
? intl.formatMessage({ id: 'ValidMeasurement' })
: intl.formatMessage({ id: 'UnvalidMeasurement' });
}, [intl, measurement?.validity]);

const validityField = (
<CheckboxNullableInput
name={`${id}.${VALIDITY}`}
label="ValidMeasurement"
previousValue={previousValidityField}
id={undefined}
formProps={undefined}
/>
);

const valueField = (
<FloatInput
name={`${id}.${VALUE}`}
label={field === FieldType.ACTIVE_POWER ? 'ActivePowerText' : 'ReactivePowerText'}
adornment={field === FieldType.ACTIVE_POWER ? ActivePowerAdornment : ReactivePowerAdornment}
previousValue={convertInputValue(field, measurement?.value)}
clearable={true}
/>
);

return (
<>
<Grid container spacing={2}>
<GridItem size={6}>{valueField}</GridItem>
<GridItem size={6}>{validityField}</GridItem>
</Grid>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2022, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import yup from '../../../../utils/yup-config';
import { VALIDITY, VALUE } from '../../../../utils/field-constants';
import { MeasurementInfo } from './measurement.type';

export function getPowerWithValidityEmptyFormData(id: string) {
return {
[id]: {
[VALUE]: null,
[VALIDITY]: null,
},
};
}

export function getPowerWithValidityValidationSchema(id: string) {
return {
[id]: yup.object().shape({
[VALUE]: yup.number().nullable(),
[VALIDITY]: yup.boolean().nullable(),
}),
};
}

export function getPowerWithValidityEditData(id: string, measurement: MeasurementInfo) {
return {
[id]: {
[VALUE]: measurement?.value,
[VALIDITY]: measurement?.validity,
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const LineDialogTabs = ({ tabIndex, tabIndexesWithError, setTabIndex, isModifica
label={<FormattedMessage id="LimitsTab" />}
sx={getTabStyle(tabIndexesWithError, LineDialogTab.LIMITS_TAB)}
/>
<Tab
label={<FormattedMessage id="StateEstimationTab" />}
sx={getTabStyle(tabIndexesWithError, LineDialogTab.MEASUREMENTS_TAB)}
/>
</Tabs>
</Grid>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Box } from '@mui/material';
import LimitsPane from '../../../limits/limits-pane';
import LineCharacteristicsPane from '../characteristics-pane/line-characteristics-pane';
import BranchConnectivityForm from '../../../connectivity/branch-connectivity-form';
import BranchActiveReactivePowerMeasurementsForm from '../../common/measurements/branch-active-reactive-power-form.tsx';

const LineModificationDialogTabs = ({ studyUuid, currentNode, currentRootNetworkUuid, lineToModify, tabIndex }) => {
return (
Expand Down Expand Up @@ -39,6 +40,10 @@ const LineModificationDialogTabs = ({ studyUuid, currentNode, currentRootNetwork
<Box hidden={tabIndex !== LineModificationDialogTab.LIMITS_TAB} p={1}>
<LimitsPane currentNode={currentNode} equipmentToModify={lineToModify} clearableFields={true} />
</Box>

<Box hidden={tabIndex !== LineModificationDialogTab.MEASUREMENTS_TAB} p={1}>
<BranchActiveReactivePowerMeasurementsForm equipmentToModify={lineToModify} />
</Box>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ADDITIONAL_PROPERTIES,
B1,
B2,
BRANCH_MEASUREMENTS,
BUS_OR_BUSBAR_SECTION,
CHARACTERISTICS,
CONNECTED,
Expand Down Expand Up @@ -86,11 +87,17 @@ import {
getConnectivityFormData,
getCont1Cont2WithPositionEmptyFormData,
} from '../../../connectivity/connectivity-form-utils';
import {
getBranchActiveReactivePowerEditData,
getBranchActiveReactivePowerEmptyFormData,
getBranchActiveReactivePowerValidationSchema,
} from '../../common/measurements/branch-active-reactive-power-form-utils.ts';

export const LineModificationDialogTab = {
CONNECTIVITY_TAB: 0,
CHARACTERISTICS_TAB: 1,
LIMITS_TAB: 2,
MEASUREMENTS_TAB: 3,
};

/**
Expand Down Expand Up @@ -129,6 +136,7 @@ const LineModificationDialog = ({
...getCont1Cont2WithPositionEmptyFormData(true),
...getCharacteristicsEmptyFormData(CHARACTERISTICS, displayConnectivity),
...getLimitsEmptyFormData(),
...getBranchActiveReactivePowerEmptyFormData(BRANCH_MEASUREMENTS),
...emptyProperties,
}),
[displayConnectivity]
Expand All @@ -141,6 +149,7 @@ const LineModificationDialog = ({
...getCon1andCon2WithPositionValidationSchema(true),
...getCharacteristicsValidationSchema(CHARACTERISTICS, displayConnectivity, true),
...getLimitsValidationSchema(),
...getBranchActiveReactivePowerValidationSchema(BRANCH_MEASUREMENTS),
})
.concat(modificationPropertiesSchema)
.required();
Expand All @@ -163,6 +172,7 @@ const LineModificationDialog = ({
...getConnectivityFormData(createConnectivityData(line, 1), CONNECTIVITY_1),
...getConnectivityFormData(createConnectivityData(line, 2), CONNECTIVITY_2),
},
...getBranchActiveReactivePowerEditData(BRANCH_MEASUREMENTS, line),
...getCharacteristicsWithOutConnectivityFormData({
r: line.r?.value ?? null,
x: line.x?.value ?? null,
Expand Down
7 changes: 7 additions & 0 deletions src/components/utils/field-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,10 @@ export const MAX_S_AUTOMATON = 'maxSAutomaton';
export const STAND_BY_AUTOMATON = 'StandbyAutomaton';
export const FILTERS_SHUNT_COMPENSATOR_TABLE = 'shuntCompensatorInfos';
export const SPREADSHEET_GS_FILTER = 'SpreadsheetGsFilter';

export const BRANCH_MEASUREMENTS = 'branchMeasurements';
export const MEASUREMENT_P1 = 'measurementP1';
export const MEASUREMENT_P2 = 'measurementP2';
export const MEASUREMENT_Q1 = 'measurementQ1';
export const MEASUREMENT_Q2 = 'measurementQ2';
export const VALIDITY = 'validity';
4 changes: 4 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,10 @@
"TemporaryLimitValue": "Value (A)",
"TemporaryLimitNameUnicityError": "Temporary limit names must be unique in the table",
"TemporaryLimitDurationUnicityError": "Temporary limit acceptable durations must be unique in the table",
"StateEstimationTab": "State estimation",
"ValidMeasurement": "Valid",
"UnvalidMeasurement": "Unvalid",

"shuntCompensatorId": "Shunt compensator ID",
"shuntCompensatorName": "Shunt compensator name",
"connectedToHvdc": "Connected To HVDC",
Expand Down
3 changes: 3 additions & 0 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,9 @@
"TemporaryLimitValue": "Valeur (A)",
"TemporaryLimitNameUnicityError": "Les noms des limites temporaires doivent être uniques dans la table",
"TemporaryLimitDurationUnicityError": "Les tempos des limites temporaires doivent être uniques dans la table",
"StateEstimationTab": "Télémesures",
"ValidMeasurement": "Valide",
"UnvalidMeasurement": "Invalide",

"ShuntSusceptancePerSection": "Susceptance par section",
"ShuntIdenticalSections": "Sections identiques",
Expand Down

0 comments on commit 2833202

Please sign in to comment.