Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -36,11 +36,13 @@ export interface ILimitReductionsByVoltageLevel {
}

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

export const TAB_INFO = [
{ label: TabValues[TabValues.Contingencies], developerModeOnly: false },
{ label: TabValues[TabValues.General], developerModeOnly: false },
{ label: TabValues[TabValues.LimitReductions], developerModeOnly: false },
];
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 { parametersStyles } from '../parameters-style';
import { CONTINGENCY_LISTS_INFOS, ContingencyTableApi, LineSeparator, ProviderParam } from '../common';
import { ContingencyTableApi, ProviderParam } from '../common';
import { SecurityAnalysisParametersSelector } from './security-analysis-parameters-selector';
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 @@ -34,21 +33,16 @@ export function SecurityAnalysisParametersForm({
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
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 @@ -5,12 +5,23 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { SyntheticEvent, useCallback, useEffect, useMemo, useState } from 'react';
import { SyntheticEvent, useCallback, useEffect, useMemo, useState, ForwardedRef } from 'react';

import { FormattedMessage } from 'react-intl';

import { Grid2 as Grid, Tab, Tabs } from '@mui/material';
import { ILimitReductionsByVoltageLevel, LimitReductionsTableForm, TAB_INFO, TabPanel, TabValues } from '../common';
import { UUID } from 'node:crypto';
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
import {
ILimitReductionsByVoltageLevel,
LimitReductionsTableForm,
TAB_INFO,
TabPanel,
TabValues,
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';
Expand All @@ -20,31 +31,48 @@ export function SecurityAnalysisParametersSelector({
currentProvider,
isDeveloperMode,
defaultLimitReductions,
showContingencyCount,
fetchContingencyCount,
contingencyTableApiRef,
isBuiltCurrentNode,
}: Readonly<{
params: SAParametersEnriched | null;
currentProvider?: string;
isDeveloperMode: boolean;
defaultLimitReductions: ILimitReductionsByVoltageLevel[];
showContingencyCount: boolean;
fetchContingencyCount?: (contingencyListIds: UUID[] | null, abortSignal: AbortSignal) => Promise<ContingencyCount>;
contingencyTableApiRef?: ForwardedRef<ContingencyTableApi>;
isBuiltCurrentNode?: boolean;
}>) {
const [tabSelected, setTabSelected] = useState(TabValues.General);
// Default to the first tab: Contingencies
Comment thread
antoinebhs marked this conversation as resolved.
Outdated
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.General : tabSelected;
// Keep the LimitReductions guard logic
Comment thread
antoinebhs marked this conversation as resolved.
Outdated
if (tabSelected === TabValues.LimitReductions && !params?.limitReductions) {
return TabValues.General;
}
return tabSelected;
}, [params, tabSelected]);

useEffect(() => {
if (currentProvider !== PARAM_PROVIDER_OPENLOADFLOW) {
if (currentProvider !== PARAM_PROVIDER_OPENLOADFLOW && tabSelected === TabValues.LimitReductions) {
// If provider changes and LimitReductions is not available, go back to General
setTabSelected(TabValues.General);
Comment thread
antoinebhs marked this conversation as resolved.
Outdated
}
}, [currentProvider]);
}, [currentProvider, tabSelected]);

const visibleTabs = TAB_INFO.filter((t) => isDeveloperMode || !t.developerModeOnly);

return (
<Grid sx={{ width: '100%' }}>
<Tabs value={tabValue} onChange={handleTabChange}>
{TAB_INFO.filter((t) => isDeveloperMode || !t.developerModeOnly).map(
{visibleTabs.map(
(tab, index) =>
(tab.label !== TabValues[TabValues.LimitReductions] ||
(currentProvider === PARAM_PROVIDER_OPENLOADFLOW && params?.limitReductions)) && (
Expand All @@ -61,9 +89,22 @@ export function SecurityAnalysisParametersSelector({
)}
</Tabs>

{TAB_INFO.filter((t) => isDeveloperMode || !t.developerModeOnly).map((tab, index) => (
{visibleTabs.map((tab, index) => (
<TabPanel key={tab.label} value={tabValue} index={index}>
{tabValue === TabValues.Contingencies && (
<Grid sx={{ width: '100%' }}>
Comment thread
antoinebhs marked this conversation as resolved.
Outdated
<ContingencyTable
name={CONTINGENCY_LISTS_INFOS}
showContingencyCount={showContingencyCount}
fetchContingencyCount={fetchContingencyCount}
isBuiltCurrentNode={isBuiltCurrentNode}
ref={contingencyTableApiRef}
/>
</Grid>
)}

{tabValue === TabValues.General && <ViolationsHidingParameters />}

{tabValue === TabValues.LimitReductions &&
currentProvider === PARAM_PROVIDER_OPENLOADFLOW &&
params?.limitReductions && (
Expand Down
Loading