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

Revert "Save NAD node movements in the reducer." #2277

Merged
merged 1 commit into from
Sep 27, 2024
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
23 changes: 0 additions & 23 deletions src/components/diagrams/diagram-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { DiagramType } from './diagram-common';

/**
* SORTING FUNCTIONS
*/
Expand Down Expand Up @@ -40,27 +38,6 @@ const sortByIndex = (a, b, diagramStates) => {
);
};

/**
* Will build a distinctive identifier to differenciate between network area diagram instances
* @param diagramStates the diagrams array of the redux store
* @param depth the network area diagram's selected depth
* @param initNadWithGeoData config parameter specifying if the nad uses geographical data
* @returns {string}
*/
export const getNadIdentifier = (diagramStates, depth, initNadWithGeoData) => {
const result =
diagramStates
.filter((diagram) => diagram.svgType === DiagramType.NETWORK_AREA_DIAGRAM)
.map((diagram) => diagram.id)
.sort((a, b) => a.localeCompare(b))
.join(',') +
'depth' +
depth +
'geo' +
initNadWithGeoData;
return result;
};

/**
* Create an array sorting function based on two values : first, the alignment, then, the index
* @param diagramStates the diagrams array of the redux store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import React, { useLayoutEffect, useRef, useMemo, useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import React, { useLayoutEffect, useRef } from 'react';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import { RunningStatus } from '../../utils/running-status';
import {
Expand All @@ -21,9 +21,6 @@ import LinearProgress from '@mui/material/LinearProgress';
import Box from '@mui/material/Box';
import { mergeSx } from '../../utils/functions';
import ComputingType from 'components/computing-status/computing-type';
import { storeNetworkAreaDiagramNodeMovement } from '../../../redux/actions';
import { PARAM_INIT_NAD_WITH_GEO_DATA } from '../../../utils/config-params.js';
import { getNadIdentifier } from '../diagram-utils.js';

const dynamicCssRules = [
{
Expand Down Expand Up @@ -121,26 +118,10 @@ const dynamicCssRules = [

function NetworkAreaDiagramContent(props) {
const { diagramSizeSetter } = props;
const dispatch = useDispatch();
const svgRef = useRef();
const diagramViewerRef = useRef();
const currentNode = useSelector((state) => state.currentTreeNode);
const loadFlowStatus = useSelector((state) => state.computingStatus[ComputingType.LOAD_FLOW]);
const nadNodeMovements = useSelector((state) => state.nadNodeMovements);
const diagramStates = useSelector((state) => state.diagramStates);
const networkAreaDiagramDepth = useSelector((state) => state.networkAreaDiagramDepth);
const initNadWithGeoData = useSelector((state) => state[PARAM_INIT_NAD_WITH_GEO_DATA]);

const nadIdentifier = useMemo(() => {
return getNadIdentifier(diagramStates, networkAreaDiagramDepth, initNadWithGeoData);
}, [diagramStates, networkAreaDiagramDepth, initNadWithGeoData]);

const onMoveNodeCallback = useCallback(
(equipmentId, nodeId, x, y, xOrig, yOrig) => {
dispatch(storeNetworkAreaDiagramNodeMovement(nadIdentifier, equipmentId, x, y));
},
[dispatch, nadIdentifier]
);

/**
* DIAGRAM CONTENT BUILDING
Expand All @@ -155,7 +136,7 @@ function NetworkAreaDiagramContent(props) {
MIN_HEIGHT,
MAX_WIDTH_NETWORK_AREA_DIAGRAM,
MAX_HEIGHT_NETWORK_AREA_DIAGRAM,
onMoveNodeCallback,
null,
null,
null,
true,
Expand All @@ -167,7 +148,7 @@ function NetworkAreaDiagramContent(props) {
diagramSizeSetter(props.diagramId, props.svgType, diagramViewer.getWidth(), diagramViewer.getHeight());

// If a previous diagram was loaded and the diagram's size remained the same, we keep
// the user's zoom and scroll state for the current render.
// the user's zoom and scoll state for the current render.
if (
diagramViewerRef.current &&
diagramViewer.getWidth() === diagramViewerRef.current.getWidth() &&
Expand All @@ -176,30 +157,9 @@ function NetworkAreaDiagramContent(props) {
diagramViewer.setViewBox(diagramViewerRef.current.getViewBox());
}

// Repositioning the previously moved nodes
if (!props.loadingState) {
const correspondingMovements = nadNodeMovements.filter(
(movement) => movement.nadIdentifier === nadIdentifier
);
if (correspondingMovements.length > 0) {
correspondingMovements.forEach((movement) => {
diagramViewer.moveNodeToCoordonates(movement.equipmentId, movement.x, movement.y);
});
}
}
diagramViewerRef.current = diagramViewer;
}
}, [
props.diagramId,
props.svgType,
props.svg,
currentNode,
props.loadingState,
diagramSizeSetter,
onMoveNodeCallback,
nadIdentifier,
nadNodeMovements,
]);
}, [props.diagramId, props.svgType, props.svg, currentNode, props.loadingState, diagramSizeSetter]);

/**
* RENDER
Expand Down
24 changes: 0 additions & 24 deletions src/redux/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,30 +905,6 @@ export function decrementNetworkAreaDiagramDepth(): DecrementNetworkAreaDiagramD
};
}

export const STORE_NETWORK_AREA_DIAGRAM_NODE_MOVEMENT = 'STORE_NETWORK_AREA_DIAGRAM_NODE_MOVEMENT';
export type StoreNetworkAreaDiagramNodeMovementAction = Readonly<
Action<typeof STORE_NETWORK_AREA_DIAGRAM_NODE_MOVEMENT>
> & {
nadIdentifier: string;
equipmentId: string;
x: number;
y: number;
};
export function storeNetworkAreaDiagramNodeMovement(
nadIdentifier: string,
equipmentId: string,
x: number,
y: number
): StoreNetworkAreaDiagramNodeMovementAction {
return {
type: STORE_NETWORK_AREA_DIAGRAM_NODE_MOVEMENT,
nadIdentifier: nadIdentifier,
equipmentId: equipmentId,
x: x,
y: y,
};
}

export const NETWORK_AREA_DIAGRAM_NB_VOLTAGE_LEVELS = 'NETWORK_AREA_DIAGRAM_NB_VOLTAGE_LEVELS';
export type NetworkAreaDiagramNbVoltageLevelsAction = Readonly<
Action<typeof NETWORK_AREA_DIAGRAM_NB_VOLTAGE_LEVELS>
Expand Down
32 changes: 0 additions & 32 deletions src/redux/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ import {
SpreadsheetFilterAction,
STOP_DIAGRAM_BLINK,
StopDiagramBlinkAction,
STORE_NETWORK_AREA_DIAGRAM_NODE_MOVEMENT,
StoreNetworkAreaDiagramNodeMovementAction,
STUDY_UPDATED,
StudyUpdatedAction,
SUBSTATION_LAYOUT,
Expand Down Expand Up @@ -382,13 +380,6 @@ export type DiagramState = {
needsToBlink?: boolean;
};

export type NadNodeMovement = {
nadIdentifier: string;
equipmentId: string;
x: number;
y: number;
};

export type SelectionForCopy = {
sourceStudyUuid: UUID | null;
nodeId: string | null;
Expand Down Expand Up @@ -427,7 +418,6 @@ export interface AppState extends CommonStoreState {
networkModificationTreeModel: NetworkModificationTreeModel | null;
mapDataLoading: boolean;
diagramStates: DiagramState[];
nadNodeMovements: NadNodeMovement[];
fullScreenDiagram: null | {
id: string;
svgType?: DiagramType;
Expand Down Expand Up @@ -548,7 +538,6 @@ const initialState: AppState = {
isModificationsInProgress: false,
studyDisplayMode: StudyDisplayMode.HYBRID,
diagramStates: [],
nadNodeMovements: [],
reloadMap: true,
isMapEquipmentsInitialized: false,
networkAreaDiagramDepth: 0,
Expand Down Expand Up @@ -1379,27 +1368,6 @@ export const reducer = createReducer(initialState, (builder) => {
}
});

builder.addCase(
STORE_NETWORK_AREA_DIAGRAM_NODE_MOVEMENT,
(state, action: StoreNetworkAreaDiagramNodeMovementAction) => {
const correspondingMovement: NadNodeMovement[] = state.nadNodeMovements.filter(
(movement) =>
movement.nadIdentifier === action.nadIdentifier && movement.equipmentId === action.equipmentId
);
if (correspondingMovement.length === 0) {
state.nadNodeMovements.push({
nadIdentifier: action.nadIdentifier,
equipmentId: action.equipmentId,
x: action.x,
y: action.y,
});
} else {
correspondingMovement[0].x = action.x;
correspondingMovement[0].y = action.y;
}
}
);

builder.addCase(
NETWORK_AREA_DIAGRAM_NB_VOLTAGE_LEVELS,
(state, action: NetworkAreaDiagramNbVoltageLevelsAction) => {
Expand Down
Loading