-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David BRAQUART <[email protected]>
- Loading branch information
Showing
11 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...logs/network-modifications/common/measurements/branch-active-reactive-power-form-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}, | ||
}; | ||
} |
79 changes: 79 additions & 0 deletions
79
...s/dialogs/network-modifications/common/measurements/branch-active-reactive-power-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
23 changes: 23 additions & 0 deletions
23
src/components/dialogs/network-modifications/common/measurements/measurement.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
55 changes: 55 additions & 0 deletions
55
...components/dialogs/network-modifications/common/measurements/power-with-validity-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
</> | ||
); | ||
}; |
37 changes: 37 additions & 0 deletions
37
...components/dialogs/network-modifications/common/measurements/power-with-validity-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters