Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add state measurements for line and 2wt modification update #2580

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* 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 { 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, {
value: branchData?.p1MeasurementValue?.value,
validity: branchData?.p1MeasurementValidity?.value,
}),
...getPowerWithValidityEditData(MEASUREMENT_Q1, {
value: branchData?.q1MeasurementValue?.value,
validity: branchData?.q1MeasurementValidity?.value,
}),
...getPowerWithValidityEditData(MEASUREMENT_P2, {
value: branchData?.p2MeasurementValue?.value,
validity: branchData?.p2MeasurementValidity?.value,
}),
...getPowerWithValidityEditData(MEASUREMENT_Q2, {
value: branchData?.q2MeasurementValue?.value,
validity: branchData?.q2MeasurementValidity?.value,
}),
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* 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="MeasurementsSection" />
<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,58 @@
/**
* 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(() => {
if (measurement?.validity == null) {
return '';
}
return measurement.validity
? intl.formatMessage({ id: 'ValidMeasurement' })
: intl.formatMessage({ id: 'InvalidMeasurement' });
}, [intl, measurement?.validity]);

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}
/>
);

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

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) 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 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 ?? null,
[VALIDITY]: measurement?.validity ?? null,
},
};
}
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 @@ -44,6 +45,10 @@ const LineModificationDialogTabs = ({ studyUuid, currentNode, currentRootNetwork
onlySelectedLimitsGroup
/>
</Box>

<Box hidden={tabIndex !== LineModificationDialogTab.MEASUREMENTS_TAB} p={1}>
<BranchActiveReactivePowerMeasurementsForm equipmentToModify={lineToModify} />
</Box>
</>
);
};
Expand Down
Loading
Loading