Skip to content

Commit 9270c6a

Browse files
authored
Fix diagram card title (#3183)
Signed-off-by: Ayoub LABIDI <[email protected]>
1 parent 40a9cc5 commit 9270c6a

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/components/diagrams/diagram-card.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { Box } from '@mui/material';
9-
import { forwardRef, MouseEventHandler, Ref, TouchEventHandler, useCallback, useState } from 'react';
9+
import { forwardRef, MouseEventHandler, Ref, TouchEventHandler, useCallback, useMemo, useState } from 'react';
1010
import CardHeader from './card-header';
1111
import { Diagram, DiagramParams, DiagramType } from './diagram.type';
1212
import { UUID } from 'crypto';
@@ -16,7 +16,7 @@ import NetworkAreaDiagramContent from './networkAreaDiagram/network-area-diagram
1616
import { ElementType, EquipmentType, mergeSx } from '@gridsuite/commons-ui';
1717
import { DiagramMetadata, SLDMetadata } from '@powsybl/network-viewer';
1818
import { DiagramAdditionalMetadata } from './diagram-common';
19-
import { FormattedMessage } from 'react-intl';
19+
import { useIntl } from 'react-intl';
2020
import { cardStyles } from './card-styles';
2121
import { v4 } from 'uuid';
2222

@@ -64,6 +64,7 @@ export const DiagramCard = forwardRef((props: DiagramCardProps, ref: Ref<HTMLDiv
6464
const { style, children, ...otherProps } = reactGridLayoutCustomChildComponentProps;
6565

6666
const [diagramsInEditMode, setDiagramsInEditMode] = useState<boolean>(false);
67+
const intl = useIntl();
6768

6869
const handleExpandAllVoltageLevels = useCallback(() => {
6970
if (diagram.type === DiagramType.NETWORK_AREA_DIAGRAM) {
@@ -151,13 +152,19 @@ export const DiagramCard = forwardRef((props: DiagramCardProps, ref: Ref<HTMLDiv
151152
[createDiagram]
152153
);
153154

155+
const cardTitle = useMemo((): string => {
156+
if (loading) {
157+
return intl.formatMessage({ id: 'loadingOptions' });
158+
}
159+
if (errorMessage) {
160+
return intl.formatMessage({ id: 'diagramLoadingFail' }, { diagramName: diagram.name });
161+
}
162+
return diagram.name;
163+
}, [loading, errorMessage, diagram.name, intl]);
164+
154165
return (
155166
<Box sx={mergeSx(style, cardStyles.card)} ref={ref} {...otherProps}>
156-
<CardHeader
157-
title={loading ? <FormattedMessage id="loadingOptions" /> : diagram.name}
158-
blinking={blinking}
159-
onClose={onClose}
160-
/>
167+
<CardHeader title={cardTitle} blinking={blinking} onClose={onClose} />
161168
{errorMessage ? (
162169
<>
163170
<AlertCustomMessageNode message={errorMessage} noMargin style={cardStyles.alertMessage} />

src/components/diagrams/hooks/use-diagram-model.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,6 @@ export const useDiagramModel = ({ diagramTypes, onAddDiagram, onDiagramAlreadyEx
292292

293293
newDiagrams[diagram.diagramUuid] = {
294294
...diagrams[diagram.diagramUuid],
295-
name: intl.formatMessage(
296-
{
297-
id: 'diagramLoadingFail',
298-
},
299-
{ diagramName: getDiagramTitle(diagram) }
300-
),
301295
};
302296
return newDiagrams;
303297
});
@@ -324,7 +318,7 @@ export const useDiagramModel = ({ diagramTypes, onAddDiagram, onDiagramAlreadyEx
324318
});
325319
});
326320
},
327-
[getDiagramTitle, getUrl, intl, snackInfo, networkVisuParams.networkAreaDiagramParameters.initNadWithGeoData]
321+
[getDiagramTitle, getUrl, snackInfo, networkVisuParams.networkAreaDiagramParameters.initNadWithGeoData]
328322
);
329323

330324
const findSimilarDiagram = useCallback(

0 commit comments

Comments
 (0)