Skip to content
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { memo, useCallback, useLayoutEffect, useRef, useState } from 'react';
import { FormattedMessage } from 'react-intl';
import { useDispatch, useSelector } from 'react-redux';
import { RunningStatus } from '../../../../utils/running-status';
import {
Expand All @@ -28,7 +29,7 @@ import {
} from '@powsybl/network-viewer';
import { isNodeReadOnly } from '../../../../graph/util/model-functions';
import { useIsAnyNodeBuilding } from '../../../../utils/is-any-node-building-hook';
import { useTheme } from '@mui/material/styles';
import { darken, lighten, Theme, useTheme } from '@mui/material/styles';
import {
ComputingType,
EquipmentType,
Expand All @@ -38,12 +39,18 @@ import {
useSnackMessage,
} from '@gridsuite/commons-ui';
import Box from '@mui/material/Box';
import Chip from '@mui/material/Chip';
import LinearProgress from '@mui/material/LinearProgress';

import { updateSwitchState } from '../../../../../services/study/network-modifications';
import { BusMenu } from 'components/menus/bus-menu';
import { startShortCircuitAnalysis } from '../../../../../services/study/short-circuit-analysis';
import { useOneBusShortcircuitAnalysisLoader } from './hooks/use-one-bus-shortcircuit-analysis-loader';
import { setComputationStarting, setComputingStatus, updateColumnFiltersAction } from '../../../../../redux/actions';
import {
setComputationStarting,
setComputingStatus,
setOneBusShortcircuitAnalysisContext,
updateColumnFiltersAction,
} from '../../../../../redux/actions';
import { TableType } from '../../../../../types/custom-aggrid-types';
import { AppState } from 'redux/reducer.type';
import type { UUID } from 'node:crypto';
Expand All @@ -57,10 +64,20 @@ import { GenericEquipmentInfos } from 'components/tooltips/equipment-popover-typ
import { GenericPopoverContent } from 'components/tooltips/generic-popover-content';
import useDebugSubscription from '../../../../../hooks/computation-debug/use-debug-subscription';

const oneBusLoaderStyle = (theme: Theme) => ({
display: 'flex',
position: 'relative',
width: 'fit-content',
margin: '5px auto',
backgroundColor:
theme.palette.mode === 'light'
? darken(theme.palette.background.paper, 0.1)
: lighten(theme.palette.background.paper, 0.2),
});

interface SingleLineDiagramContentProps {
readonly showInSpreadsheet: (menu: { equipmentId: string | null; equipmentType: EquipmentType | null }) => void;
readonly studyUuid: UUID;
readonly panelId: UUID;
readonly svg?: string;
readonly svgMetadata?: SLDMetadata;
readonly loadingState: boolean;
Expand Down Expand Up @@ -88,7 +105,6 @@ const defaultBusMenuState: BusMenuState = {
const SingleLineDiagramContent = memo(function SingleLineDiagramContent(props: SingleLineDiagramContentProps) {
const {
studyUuid,
panelId,
visible,
diagramParams,
onNextVoltageLevelDiagram,
Expand Down Expand Up @@ -119,13 +135,15 @@ const SingleLineDiagramContent = memo(function SingleLineDiagramContent(props: S
const loadFlowStatus = useSelector((state: AppState) => state.computingStatus[ComputingType.LOAD_FLOW]);
const shortCircuitStatus = useSelector((state: AppState) => state.computingStatus[ComputingType.SHORT_CIRCUIT]);

const [
oneBusShortcircuitAnalysisLoaderMessage,
isDiagramRunningOneBusShortcircuitAnalysis,
displayOneBusShortcircuitAnalysisLoader,
resetOneBusShortcircuitAnalysisLoader,
] = useOneBusShortcircuitAnalysisLoader(panelId);

const equipmentId =
diagramParams.type === DiagramType.VOLTAGE_LEVEL ? diagramParams.voltageLevelId : diagramParams.substationId;
const isOneBusScRunning = useSelector(
(state: AppState) =>
state.computingStatus[ComputingType.SHORT_CIRCUIT_ONE_BUS] === RunningStatus.RUNNING &&
state.oneBusShortCircuitAnalysisContext?.equipmentId === equipmentId &&
state.oneBusShortCircuitAnalysisContext?.nodeId === state.currentTreeNode?.id &&
state.oneBusShortCircuitAnalysisContext?.rootNetworkUuid === state.currentRootNetworkUuid
);
/**
* DIAGRAM INTERACTIVITY
*/
Expand Down Expand Up @@ -226,34 +244,27 @@ const SingleLineDiagramContent = memo(function SingleLineDiagramContent(props: S

const handleRunShortcircuitAnalysis = useCallback(
(busId: string, debug: boolean) => {
if (!currentNode || !currentRootNetworkUuid) {
return;
}
dispatch(setComputingStatus(ComputingType.SHORT_CIRCUIT_ONE_BUS, RunningStatus.RUNNING));
displayOneBusShortcircuitAnalysisLoader();
dispatch(setOneBusShortcircuitAnalysisContext(equipmentId, currentRootNetworkUuid, currentNode.id));
dispatch(setComputationStarting(true));
startShortCircuitAnalysis(studyUuid, currentNode?.id, currentRootNetworkUuid, busId, debug)
startShortCircuitAnalysis(studyUuid, currentNode.id, currentRootNetworkUuid, busId, debug)
.then(() => {
debug && subscribeDebug(ComputingType.SHORT_CIRCUIT_ONE_BUS);
})
.catch((error) => {
snackWithFallback(snackError, error, { headerId: 'startShortCircuitError' });
dispatch(setComputingStatus(ComputingType.SHORT_CIRCUIT_ONE_BUS, RunningStatus.FAILED));
resetOneBusShortcircuitAnalysisLoader();
})
.finally(() => {
dispatch(setComputationStarting(false));
// we clear the computation logs filter when a new computation is started
dispatch(updateColumnFiltersAction(TableType.Logs, ComputingType.SHORT_CIRCUIT_ONE_BUS, []));
});
},
[
dispatch,
displayOneBusShortcircuitAnalysisLoader,
studyUuid,
currentNode?.id,
currentRootNetworkUuid,
snackError,
resetOneBusShortcircuitAnalysisLoader,
subscribeDebug,
]
[dispatch, equipmentId, studyUuid, currentNode, currentRootNetworkUuid, snackError, subscribeDebug]
);

const displayBusMenu = () => {
Expand Down Expand Up @@ -450,10 +461,14 @@ const SingleLineDiagramContent = memo(function SingleLineDiagramContent(props: S
return (
<>
<Box height={2}>
{(loadingState || modificationInProgress || isDiagramRunningOneBusShortcircuitAnalysis) && (
<LinearProgress />
{(loadingState || modificationInProgress || isOneBusScRunning) && <LinearProgress />}
{isOneBusScRunning && (
<Chip
label={<FormattedMessage id="ShortcircuitInProgress" />}
variant="outlined"
sx={oneBusLoaderStyle}
/>
)}
{oneBusShortcircuitAnalysisLoaderMessage}
</Box>
<Box
ref={svgRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export const SubstationPanelContent = ({
}}
showInSpreadsheet={handleShowInSpreadsheet}
studyUuid={studyUuid}
panelId={panelId}
svg={diagram.svg?.svg ?? undefined}
svgMetadata={diagram.svg?.metadata as SLDMetadata}
loadingState={loading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export const VoltageLevelPanelContent = ({
}}
showInSpreadsheet={handleShowInSpreadsheet}
studyUuid={studyUuid}
panelId={panelId}
svg={diagram.svg?.svg ?? undefined}
svgMetadata={diagram.svg?.metadata as SLDMetadata}
loadingState={loading}
Expand Down
47 changes: 16 additions & 31 deletions src/redux/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type {
ComputingStatusParameters,
CopiedNetworkModifications,
NodeSelectionForCopy,
OneBusShortCircuitAnalysisDiagram,
OneBusShortCircuitAnalysisContext,
} from './reducer.type';
import type { TableSortConfig, TableSortKeysType } from '../types/custom-aggrid-types';
import {
Expand Down Expand Up @@ -108,8 +108,7 @@ export type AppActions =
| SetComputationStartingAction
| SetRootNetworkIndexationStatusAction
| SetOptionalServicesAction
| SetOneBusShortcircuitAnalysisDiagramAction
| ResetOneBusShortcircuitAnalysisDiagramAction
| SetOneBusShortcircuitAnalysisContextAction
| AddToGlobalFilterOptionsAction
| RemoveFromGlobalFilterOptionsAction
| SetLastCompletedComputationAction
Expand Down Expand Up @@ -899,35 +898,21 @@ export function setOptionalServices(optionalServices: IOptionalService[]): SetOp
};
}

export const SET_ONE_BUS_SHORTCIRCUIT_ANALYSIS_DIAGRAM = 'SET_ONE_BUS_SHORTCIRCUIT_ANALYSIS_DIAGRAM';
export type SetOneBusShortcircuitAnalysisDiagramAction = Action<typeof SET_ONE_BUS_SHORTCIRCUIT_ANALYSIS_DIAGRAM> &
OneBusShortCircuitAnalysisDiagram & {
[key: string]: any;
};
export function setOneBusShortcircuitAnalysisDiagram(
diagramId: OneBusShortCircuitAnalysisDiagram['diagramId'],
studyUuid: OneBusShortCircuitAnalysisDiagram['studyUuid'],
rootNetworkUuid: OneBusShortCircuitAnalysisDiagram['rootNetworkUuid'],
nodeId: OneBusShortCircuitAnalysisDiagram['nodeId']
): SetOneBusShortcircuitAnalysisDiagramAction {
export const SET_ONE_BUS_SHORTCIRCUIT_ANALYSIS_CONTEXT = 'SET_ONE_BUS_SHORTCIRCUIT_ANALYSIS_CONTEXT';
export type SetOneBusShortcircuitAnalysisContextAction = Readonly<
Action<typeof SET_ONE_BUS_SHORTCIRCUIT_ANALYSIS_CONTEXT>
> &
OneBusShortCircuitAnalysisContext;
export function setOneBusShortcircuitAnalysisContext(
equipmentId: string,
rootNetworkUuid: UUID,
nodeId: UUID
): SetOneBusShortcircuitAnalysisContextAction {
return {
type: SET_ONE_BUS_SHORTCIRCUIT_ANALYSIS_DIAGRAM,
diagramId: diagramId,
studyUuid: studyUuid,
rootNetworkUuid: rootNetworkUuid,
nodeId: nodeId,
};
}

export const RESET_ONE_BUS_SHORTCIRCUIT_ANALYSIS_DIAGRAM = 'RESET_ONE_BUS_SHORTCIRCUIT_ANALYSIS_DIAGRAM';
export type ResetOneBusShortcircuitAnalysisDiagramAction = Action<
typeof RESET_ONE_BUS_SHORTCIRCUIT_ANALYSIS_DIAGRAM
> & {
[key: string]: any;
};
export function resetOneBusShortcircuitAnalysisDiagram(): ResetOneBusShortcircuitAnalysisDiagramAction {
return {
type: RESET_ONE_BUS_SHORTCIRCUIT_ANALYSIS_DIAGRAM,
type: SET_ONE_BUS_SHORTCIRCUIT_ANALYSIS_CONTEXT,
equipmentId,
nodeId,
rootNetworkUuid,
};
}

Expand Down
Loading
Loading