Skip to content
Merged
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
7 changes: 0 additions & 7 deletions src/features/parameters/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
export const PROVIDER = 'provider';
export const VOLTAGE_LEVEL = 'voltageLevel';

export const PARAM_SA_PROVIDER = 'provider';
export const PARAM_SA_FLOW_PROPORTIONAL_THRESHOLD = 'flowProportionalThreshold';
export const PARAM_SA_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD = 'lowVoltageProportionalThreshold';
export const PARAM_SA_LOW_VOLTAGE_ABSOLUTE_THRESHOLD = 'lowVoltageAbsoluteThreshold';
export const PARAM_SA_HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD = 'highVoltageProportionalThreshold';
export const PARAM_SA_HIGH_VOLTAGE_ABSOLUTE_THRESHOLD = 'highVoltageAbsoluteThreshold';

export const VERSION_PARAMETER = 'version';
export const COMMON_PARAMETERS = 'commonParameters';
export const ADVANCED_PARAMETERS = 'advancedParameters';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ export interface ILimitReductionsByVoltageLevel {
temporaryLimitReductions: ITemporaryLimitReduction[];
}

export enum TabValues {
General = 0,
LimitReductions = 1,
}

export const TAB_INFO = [
{ label: TabValues[TabValues.General], developerModeOnly: false },
{ label: TabValues[TabValues.LimitReductions], developerModeOnly: false },
];

export interface LimitReductionIColumnsDef {
label: React.ReactNode;
dataKey: string;
Expand Down
38 changes: 20 additions & 18 deletions src/features/parameters/security-analysis/columns-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ import * as yup from 'yup';
import {
getLimitReductionsFormSchema,
ILimitReductionsByVoltageLevel,
PARAM_SA_FLOW_PROPORTIONAL_THRESHOLD,
PARAM_SA_HIGH_VOLTAGE_ABSOLUTE_THRESHOLD,
PARAM_SA_HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD,
PARAM_SA_LOW_VOLTAGE_ABSOLUTE_THRESHOLD,
PARAM_SA_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD,
PARAM_SA_PROVIDER,
PROVIDER,
toFormValuesLimitReductions,
} from '../common';
import { getNameElementEditorSchema } from '../common/name-element-editor';
import { getContingencyListsInfosFormSchema, toFormValuesContingencyListsInfos } from '../common/contingency-table';
import { SAParametersEnriched } from '../../../utils';
import {
FLOW_PROPORTIONAL_THRESHOLD,
HIGH_VOLTAGE_ABSOLUTE_THRESHOLD,
HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD,
LOW_VOLTAGE_ABSOLUTE_THRESHOLD,
LOW_VOLTAGE_PROPORTIONAL_THRESHOLD,
} from './constants';

export const getSAParametersFormSchema = (name: string | null, limitReductions?: ILimitReductionsByVoltageLevel[]) => {
const providerSchema = yup.object().shape({
[PARAM_SA_PROVIDER]: yup.string().required(),
[PROVIDER]: yup.string().required(),
});

const contingencyListsInfosSchema = getContingencyListsInfosFormSchema();
Expand All @@ -32,23 +34,23 @@ export const getSAParametersFormSchema = (name: string | null, limitReductions?:
);

const thresholdsSchema = yup.object().shape({
[PARAM_SA_FLOW_PROPORTIONAL_THRESHOLD]: yup
[FLOW_PROPORTIONAL_THRESHOLD]: yup
.number()
.min(0, 'NormalizedPercentage')
.max(100, 'NormalizedPercentage')
.required(),
[PARAM_SA_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD]: yup
[LOW_VOLTAGE_PROPORTIONAL_THRESHOLD]: yup
.number()
.min(0, 'NormalizedPercentage')
.max(100, 'NormalizedPercentage')
.required(),
[PARAM_SA_LOW_VOLTAGE_ABSOLUTE_THRESHOLD]: yup.number().required(),
[PARAM_SA_HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD]: yup
[LOW_VOLTAGE_ABSOLUTE_THRESHOLD]: yup.number().required(),
[HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD]: yup
.number()
.min(0, 'NormalizedPercentage')
.max(100, 'NormalizedPercentage')
.required(),
[PARAM_SA_HIGH_VOLTAGE_ABSOLUTE_THRESHOLD]: yup.number().required(),
[HIGH_VOLTAGE_ABSOLUTE_THRESHOLD]: yup.number().required(),
});

return yup
Expand All @@ -63,13 +65,13 @@ export const getSAParametersFormSchema = (name: string | null, limitReductions?:
};

export const toFormValueSaParameters = (params: SAParametersEnriched) => ({
[PARAM_SA_PROVIDER]: params.provider,
[PROVIDER]: params.provider,
...toFormValuesContingencyListsInfos(params?.contingencyListsInfos ?? []),
...toFormValuesLimitReductions(params?.limitReductions),
// SA specific form values
[PARAM_SA_FLOW_PROPORTIONAL_THRESHOLD]: params.flowProportionalThreshold * 100,
[PARAM_SA_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD]: params.lowVoltageProportionalThreshold * 100,
[PARAM_SA_LOW_VOLTAGE_ABSOLUTE_THRESHOLD]: params.lowVoltageAbsoluteThreshold,
[PARAM_SA_HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD]: params.highVoltageProportionalThreshold * 100,
[PARAM_SA_HIGH_VOLTAGE_ABSOLUTE_THRESHOLD]: params.highVoltageAbsoluteThreshold,
[FLOW_PROPORTIONAL_THRESHOLD]: params.flowProportionalThreshold * 100,
[LOW_VOLTAGE_PROPORTIONAL_THRESHOLD]: params.lowVoltageProportionalThreshold * 100,
[LOW_VOLTAGE_ABSOLUTE_THRESHOLD]: params.lowVoltageAbsoluteThreshold,
[HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD]: params.highVoltageProportionalThreshold * 100,
[HIGH_VOLTAGE_ABSOLUTE_THRESHOLD]: params.highVoltageAbsoluteThreshold,
});
18 changes: 18 additions & 0 deletions src/features/parameters/security-analysis/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* 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/.
*/

export const FLOW_PROPORTIONAL_THRESHOLD = 'flowProportionalThreshold';
export const LOW_VOLTAGE_PROPORTIONAL_THRESHOLD = 'lowVoltageProportionalThreshold';
export const LOW_VOLTAGE_ABSOLUTE_THRESHOLD = 'lowVoltageAbsoluteThreshold';
export const HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD = 'highVoltageProportionalThreshold';
export const HIGH_VOLTAGE_ABSOLUTE_THRESHOLD = 'highVoltageAbsoluteThreshold';

export enum TabValues {
Contingencies = 0,
Aggravation = 1,
LimitReductions = 2,
}
1 change: 1 addition & 0 deletions src/features/parameters/security-analysis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

export * from './security-analysis-parameters-inline';
export * from './security-analysis-parameters-dialog';
export * from './constants';
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* 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 { SyntheticEvent, useCallback, useEffect, useMemo, useState, ForwardedRef } from 'react';

import { FormattedMessage } from 'react-intl';

import { Tab, Tabs } from '@mui/material';
import type { UUID } from 'node:crypto';
import {
ILimitReductionsByVoltageLevel,
LimitReductionsTableForm,
TabPanel,
CONTINGENCY_LISTS_INFOS,
ContingencyTableApi,
} from '../common';
import { ContingencyTable } from '../common/contingency-table';
import { ContingencyCount } from '../common/contingency-table/types';
import { PARAM_PROVIDER_OPENLOADFLOW } from '../loadflow';
import { ViolationsHidingParameters } from './security-analysis-violations-hiding';
import { SAParametersEnriched } from '../../../utils/types';
import { TabValues } from './constants';
import type { MuiStyles } from '../../../utils/styles';

const styles = {
tab: {
fontSize: 17,
fontWeight: 'bold',
},
} as const satisfies MuiStyles;

export function SecurityAnalysisParametersContent({
params,
currentProvider,
defaultLimitReductions,
showContingencyCount,
fetchContingencyCount,
contingencyTableApiRef,
isBuiltCurrentNode,
}: Readonly<{
params: SAParametersEnriched | null;
currentProvider?: string;
defaultLimitReductions: ILimitReductionsByVoltageLevel[];
showContingencyCount: boolean;
fetchContingencyCount?: (contingencyListIds: UUID[] | null, abortSignal: AbortSignal) => Promise<ContingencyCount>;
contingencyTableApiRef?: ForwardedRef<ContingencyTableApi>;
isBuiltCurrentNode?: boolean;
}>) {
const [tabSelected, setTabSelected] = useState(TabValues.Contingencies);

const handleTabChange = useCallback((event: SyntheticEvent, newValue: number) => {
setTabSelected(newValue);
}, []);

const tabValue = useMemo(() => {
return tabSelected === TabValues.LimitReductions && !params?.limitReductions
? TabValues.Contingencies
: tabSelected;
}, [params, tabSelected]);

useEffect(() => {
if (currentProvider !== PARAM_PROVIDER_OPENLOADFLOW && tabSelected === TabValues.LimitReductions) {
setTabSelected(TabValues.Contingencies);
}
}, [currentProvider, tabSelected]);

return (
<>
<Tabs value={tabValue} onChange={handleTabChange}>
<Tab
label={<FormattedMessage id={TabValues[TabValues.Contingencies]} />}
value={TabValues.Contingencies}
sx={styles.tab}
/>
<Tab
label={<FormattedMessage id={TabValues[TabValues.Aggravation]} />}
value={TabValues.Aggravation}
sx={styles.tab}
/>
{currentProvider === PARAM_PROVIDER_OPENLOADFLOW && params?.limitReductions && (
<Tab
label={<FormattedMessage id={TabValues[TabValues.LimitReductions]} />}
value={TabValues.LimitReductions}
sx={styles.tab}
/>
)}
</Tabs>

<TabPanel value={tabValue} index={TabValues.Contingencies} keepState>
<ContingencyTable
name={CONTINGENCY_LISTS_INFOS}
showContingencyCount={showContingencyCount}
fetchContingencyCount={fetchContingencyCount}
isBuiltCurrentNode={isBuiltCurrentNode}
ref={contingencyTableApiRef}
/>
</TabPanel>
<TabPanel value={tabValue} index={TabValues.Aggravation}>
<ViolationsHidingParameters />
</TabPanel>
<TabPanel value={tabValue} index={TabValues.LimitReductions}>
{currentProvider === PARAM_PROVIDER_OPENLOADFLOW && params?.limitReductions && (
<LimitReductionsTableForm limits={params.limitReductions ?? defaultLimitReductions} />
)}
</TabPanel>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export function SecurityAnalysisParametersDialog({
activeDirectory,
language,
userProfile,
isDeveloperMode = false,
}: Readonly<ParametersEditionDialogProps>) {
const parametersBackend = useParametersBackend(
userProfile,
Expand Down Expand Up @@ -80,7 +79,6 @@ export function SecurityAnalysisParametersDialog({
<SecurityAnalysisParametersForm
securityAnalysisMethods={securityAnalysisMethods}
showContingencyCount={false}
isDeveloperMode={isDeveloperMode}
/>
) : (
<LinearProgress />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
* 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 { Box, Stack } from '@mui/material';
import { Stack } from '@mui/material';
import { ForwardedRef } from 'react';
import { UUID } from 'node:crypto';
import type { UUID } from 'node:crypto';
import { parametersStyles } from '../parameters-style';
import { CONTINGENCY_LISTS_INFOS, ContingencyTableApi, LineSeparator, ProviderParam } from '../common';
import { SecurityAnalysisParametersSelector } from './security-analysis-parameters-selector';
import { ContingencyTableApi, ProviderParam } from '../common';
import { SecurityAnalysisParametersContent } from './security-analysis-parameters-content';
import { UseSecurityAnalysisParametersFormReturn } from './use-security-analysis-parameters-form';
import { ContingencyTable } from '../common/contingency-table';
import { ContingencyCount } from '../common/contingency-table/types';

export type SecurityAnalysisParametersFormProps = {
Expand All @@ -20,7 +19,6 @@ export type SecurityAnalysisParametersFormProps = {
fetchContingencyCount?: (contingencyListIds: UUID[] | null, abortSignal: AbortSignal) => Promise<ContingencyCount>;
contingencyTableApiRef?: ForwardedRef<ContingencyTableApi>;
isBuiltCurrentNode?: boolean;
isDeveloperMode: boolean;
};

export function SecurityAnalysisParametersForm({
Expand All @@ -29,26 +27,18 @@ export function SecurityAnalysisParametersForm({
fetchContingencyCount,
contingencyTableApiRef,
isBuiltCurrentNode,
isDeveloperMode,
}: Readonly<SecurityAnalysisParametersFormProps>) {
return (
<Stack sx={parametersStyles.scrollableGrid}>
<ProviderParam options={securityAnalysisMethods.formattedProviders} id="Sa" sx={{ paddingBottom: 1 }} />
<ContingencyTable
name={CONTINGENCY_LISTS_INFOS}
showContingencyCount={showContingencyCount}
fetchContingencyCount={fetchContingencyCount}
isBuiltCurrentNode={isBuiltCurrentNode}
ref={contingencyTableApiRef}
/>
<Box paddingTop={4} paddingBottom={2}>
<LineSeparator />
</Box>
<SecurityAnalysisParametersSelector
<SecurityAnalysisParametersContent
params={securityAnalysisMethods.params}
currentProvider={securityAnalysisMethods.watchProvider?.trim()}
isDeveloperMode={isDeveloperMode}
defaultLimitReductions={securityAnalysisMethods.defaultLimitReductions}
showContingencyCount={showContingencyCount}
fetchContingencyCount={fetchContingencyCount}
contingencyTableApiRef={contingencyTableApiRef}
isBuiltCurrentNode={isBuiltCurrentNode}
/>
</Stack>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export function SecurityAnalysisParametersInline({
fetchContingencyCount,
isBuiltCurrentNode,
setHaveDirtyFields,
isDeveloperMode,
}: Readonly<{
studyUuid: UUID | null;
parametersBackend: UseParametersBackendReturnProps<ComputingType.SECURITY_ANALYSIS>;
Expand Down Expand Up @@ -100,7 +99,6 @@ export function SecurityAnalysisParametersInline({
fetchContingencyCount={fetchContingencyCount}
contingencyTableApiRef={contingencyTableApiRef}
isBuiltCurrentNode={isBuiltCurrentNode}
isDeveloperMode={isDeveloperMode}
/>
</ParameterLayout>
</CustomFormProvider>
Expand Down
Loading
Loading