Skip to content

Commit 65ef39b

Browse files
authored
Refactor TreeTab code organization (#3199)
* refactor(GridLayoutPanel): rename 'diagrams' folder to 'grid-layout' rename `DiagramGridLayout` component to `GridLayoutPanel` and css, translation etc associated * chore(grid-layout): code organization in cards/ folder and diagrams/ refactor(DiagramGridHeader): renamed `GridLayoutToolbar` * refactor(): move and rename `countOpenedNadDiagrams` to diagram-utils.ts as `isThereTooManyOpenedNadDiagrams` fix(): some types imports * refactor(NetworkMapTab): renamed NetworkMapPanel * refactor(MapViewer): renamed TreeTab * fix(DiagramHeader): fix sonar issue : Optional chaining should be preferred typescript:S6582 * fix(): fix sonar issue : Imports from the same module should be merged typescript:S3863 * fix(): fix sonar issue : React props should be read-only typescript:S6759 Signed-off-by: sBouzols <[email protected]>
1 parent 9b5883a commit 65ef39b

File tree

53 files changed

+347
-355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+347
-355
lines changed

src/components/diagrams/diagram-grid-layout-utils.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/components/diagrams/diagram-utils.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/components/dialogs/connectivity/connectivity-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
import { useCallback, useEffect, useMemo, useState } from 'react';
2525
import { useFormContext, useWatch } from 'react-hook-form';
2626
import { useIntl } from 'react-intl';
27-
import PositionDiagramPane from '../../diagrams/singleLineDiagram/position-diagram-pane';
27+
import PositionDiagramPane from '../../grid-layout/cards/diagrams/singleLineDiagram/positionDiagram/position-diagram-pane';
2828
import { isNodeBuilt } from '../../graph/util/model-functions';
2929
import { CONNECTION_DIRECTIONS, getConnectionDirectionLabel } from '../../network/constants';
3030
import {

src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import GridItem from '../../../commons/grid-item';
1111
import { getObjectId } from '../../../../utils/utils';
1212
import { Box, Grid, TextField, Tooltip } from '@mui/material';
1313
import { InfoOutlined } from '@mui/icons-material';
14-
import PositionDiagramPane from '../../../../diagrams/singleLineDiagram/position-diagram-pane';
14+
import PositionDiagramPane from '../../../../grid-layout/cards/diagrams/singleLineDiagram/positionDiagram/position-diagram-pane';
1515
import { useCallback, useState } from 'react';
1616
import Button from '@mui/material/Button';
1717
import { FormattedMessage, useIntl } from 'react-intl';

src/components/dialogs/network-modifications/voltage-level-topology-creation/create-voltage-level-topology-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { SECTION_COUNT } from 'components/utils/field-constants';
1010
import GridItem from '../../commons/grid-item';
1111
import { Box, Grid, TextField, Tooltip } from '@mui/material';
1212
import { InfoOutlined } from '@mui/icons-material';
13-
import PositionDiagramPane from '../../../diagrams/singleLineDiagram/position-diagram-pane';
13+
import PositionDiagramPane from '../../../grid-layout/cards/diagrams/singleLineDiagram/positionDiagram/position-diagram-pane';
1414
import { useCallback, useState } from 'react';
1515
import Button from '@mui/material/Button';
1616
import { FormattedMessage, useIntl } from 'react-intl';

src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { AutocompleteInput, Option, SelectInput } from '@gridsuite/commons-ui';
2323
import GridSection from '../../../commons/grid-section';
2424
import { isNodeBuilt } from 'components/graph/util/model-functions';
2525
import { InfoOutlined } from '@mui/icons-material';
26-
import PositionDiagramPane from 'components/diagrams/singleLineDiagram/position-diagram-pane';
26+
import PositionDiagramPane from 'components/grid-layout/cards/diagrams/singleLineDiagram/positionDiagram/position-diagram-pane';
2727
import { UUID } from 'crypto';
2828
import { POSITION_NEW_SECTION_SIDE, SWITCH_TYPE } from '../../../../network/constants';
2929
import { useFormContext, useWatch } from 'react-hook-form';

src/components/diagrams/card-styles.ts renamed to src/components/grid-layout/cards/card-styles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const cardStyles = {
2525
theme.palette.mode === 'light'
2626
? `1px solid ${theme.palette.grey[500]}`
2727
: `1px solid ${theme.palette.grey[800]}`,
28-
borderTop: 'none', // remove the top border to avoid double border with CardHeader
28+
borderTop: 'none', // remove the top border to avoid double border with CustomCardHeader
2929
borderBottom: 'none',
3030
}),
3131
diagramContainer: (theme: Theme) => ({
@@ -38,6 +38,6 @@ export const cardStyles = {
3838
theme.palette.mode === 'light'
3939
? `1px solid ${theme.palette.grey[500]}`
4040
: `1px solid ${theme.palette.grey[800]}`,
41-
borderTop: 'none', // remove the top border to avoid double border with CardHeader
41+
borderTop: 'none', // remove the top border to avoid double border with CustomCardHeader
4242
}),
4343
};

src/components/diagrams/card-header.tsx renamed to src/components/grid-layout/cards/custom-card-header.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ const styles = {
4040
}),
4141
};
4242

43-
interface CardHeaderProps {
43+
interface CustomCardHeaderProps {
4444
title?: React.ReactNode;
4545
onClose?: () => void;
4646
blinking?: boolean;
4747
}
4848

49-
const CardHeader: React.FC<CardHeaderProps> = ({ title, onClose, blinking }) => {
49+
const CustomCardHeader: React.FC<CustomCardHeaderProps> = ({ title, onClose, blinking }) => {
5050
return (
5151
<Box sx={mergeSx(styles.header, blinking ? styles.blink : undefined)}>
5252
<OverflowableText
@@ -70,4 +70,4 @@ const CardHeader: React.FC<CardHeaderProps> = ({ title, onClose, blinking }) =>
7070
);
7171
};
7272

73-
export default CardHeader;
73+
export default CustomCardHeader;

src/components/diagrams/diagram-card.tsx renamed to src/components/grid-layout/cards/diagrams/diagram-card.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77

88
import { Box } from '@mui/material';
99
import { forwardRef, MouseEventHandler, Ref, TouchEventHandler, useCallback, useMemo, useState } from 'react';
10-
import CardHeader from './card-header';
11-
import { Diagram, DiagramParams, DiagramType } from './diagram.type';
10+
import CustomCardHeader from '../custom-card-header';
11+
import { Diagram, DiagramAdditionalMetadata, DiagramParams, DiagramType } from './diagram.type';
1212
import { UUID } from 'crypto';
1313
import AlertCustomMessageNode from 'components/utils/alert-custom-message-node';
1414
import SingleLineDiagramContent from './singleLineDiagram/single-line-diagram-content';
1515
import NetworkAreaDiagramContent from './networkAreaDiagram/network-area-diagram-content';
1616
import { ElementType, EquipmentType, mergeSx } from '@gridsuite/commons-ui';
1717
import { DiagramMetadata, SLDMetadata } from '@powsybl/network-viewer';
18-
import { DiagramAdditionalMetadata } from './diagram-common';
1918
import { useIntl } from 'react-intl';
20-
import { cardStyles } from './card-styles';
19+
import { cardStyles } from '../card-styles';
2120
import { v4 } from 'uuid';
2221

2322
interface ReactGridLayoutCustomChildComponentProps {
@@ -181,7 +180,7 @@ export const DiagramCard = forwardRef((props: DiagramCardProps, ref: Ref<HTMLDiv
181180

182181
return (
183182
<Box sx={mergeSx(style, cardStyles.card)} ref={ref} {...otherProps}>
184-
<CardHeader title={cardTitle} blinking={blinking} onClose={onClose} />
183+
<CustomCardHeader title={cardTitle} blinking={blinking} onClose={onClose} />
185184
{errorMessage ? (
186185
<>
187186
<AlertCustomMessageNode message={errorMessage} noMargin style={cardStyles.alertMessage} />
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* Copyright (c) 2022, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
import { Theme } from '@mui/material';
9+
import { INVALID_LOADFLOW_OPACITY } from 'utils/colors';
10+
11+
export const styles = {
12+
divDiagram: {
13+
'& #nad-viewer, & #svg-container': {
14+
/* This is a patch to alter the divs generated by NetworkAreaDiagramViewer(), which sizes management is broken.
15+
* It seems to be linked to the code introduced in https://github.com/powsybl/powsybl-network-viewer/pull/161
16+
*/
17+
height: '100%',
18+
width: '100%',
19+
},
20+
'& svg': {
21+
display: 'block',
22+
width: '100%',
23+
height: '100%',
24+
},
25+
overflow: 'hidden',
26+
},
27+
divNetworkAreaDiagram: (theme: Theme) => ({
28+
height: '100%',
29+
'& .nad-label-box': {
30+
color: theme.palette.text.primary,
31+
fontFamily: theme.typography.fontFamily,
32+
},
33+
}),
34+
divSingleLineDiagram: (theme: Theme) => ({
35+
'& polyline': {
36+
pointerEvents: 'none',
37+
},
38+
'& .sld-label, .sld-graph-label, .sld-legend': {
39+
fill: theme.palette.text.primary,
40+
fontFamily: theme.typography.fontFamily,
41+
},
42+
'& .sld-disconnector:not(.sld-fictitious), :not(.sld-breaker):not(.sld-disconnector):not(.sld-load-break-switch):not(.sld-lock .sld-disconnected):not(.sld-flash .sld-disconnected).sld-disconnected, .sld-feeder-disconnected, .sld-feeder-disconnected-connected':
43+
{
44+
stroke: theme.palette.text.primary,
45+
},
46+
'& .sld-flash, .sld-lock': {
47+
stroke: 'none',
48+
fill: theme.palette.text.primary,
49+
},
50+
'& .arrow': {
51+
fill: theme.palette.text.primary,
52+
},
53+
}),
54+
divDiagramReadOnly: {
55+
'& .sld-in .sld-label': {
56+
display: 'none',
57+
},
58+
'& .sld-out .sld-label': {
59+
display: 'none',
60+
},
61+
'& .sld-arrow-in': {
62+
display: 'none',
63+
},
64+
'& .sld-arrow-out': {
65+
display: 'none',
66+
},
67+
'& .arrow': {
68+
pointerEvents: 'none',
69+
},
70+
},
71+
divDiagramInvalid: {
72+
'& .sld-active-power polygon, & .sld-reactive-power polygon, & .sld-voltage polygon, & .sld-angle polygon': {
73+
opacity: INVALID_LOADFLOW_OPACITY,
74+
},
75+
'& .sld-active-power text, & .sld-reactive-power text, & .sld-voltage text, & .sld-angle text, & .sld-voltage.sld-bus-legend-info, & .sld-angle.sld-bus-legend-info':
76+
{
77+
fill: '#787F81',
78+
},
79+
'& .sld-overload, & .sld-vl-overvoltage, & .sld-vl-undervoltage': {
80+
animation: 'none !important',
81+
},
82+
'& .nad-active': {
83+
fill: '#787F81', // Text color of the values and arrows on lines (same color in light and dark mode)
84+
},
85+
'& .nad-bus-descr': {
86+
color: '#787F81',
87+
},
88+
'& .nad-branch-edges .nad-overload .nad-edge-path, & .nad-vl-nodes .nad-overvoltage, & .nad-vl-nodes .nad-undervoltage':
89+
{
90+
animation: 'none !important',
91+
},
92+
},
93+
paperBorders: (theme: Theme) => ({
94+
borderLeft: '1px solid ' + theme.palette.action.disabled,
95+
borderBottom: '1px solid ' + theme.palette.action.disabledBackground,
96+
borderRight: '1px solid ' + theme.palette.action.hover,
97+
}),
98+
};

0 commit comments

Comments
 (0)