Skip to content

Commit 796080c

Browse files
authored
Group modifications search results by modification (#3417)
The results of the modification search are now grouped: the name of a modification is displayed, followed by the list of impacted equipments.
1 parent 8e93a8f commit 796080c

File tree

5 files changed

+58
-21
lines changed

5 files changed

+58
-21
lines changed

src/components/graph/menus/root-network/root-network-modification-results.tsx

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ const styles = {
2929
backgroundColor: theme.aggrid.highlightColor,
3030
},
3131
}),
32-
modificationLabel: {
32+
modifiedEquipmentLabel: (theme: Theme) => ({
3333
cursor: 'pointer',
34-
pt: 0.5,
35-
pb: 0.5,
36-
pl: 0.5,
37-
},
34+
pt: theme.spacing(0.5),
35+
pb: theme.spacing(0.5),
36+
pl: theme.spacing(1.5),
37+
}),
38+
modificationLabel: (theme: Theme) => ({
39+
cursor: 'pointer',
40+
pt: theme.spacing(1.5),
41+
pb: theme.spacing(0.5),
42+
pl: theme.spacing(0.5),
43+
}),
3844
};
3945
export const ModificationResults: React.FC<ModificationResultsProps> = ({ modifications, nodeUuid }) => {
4046
const intl = useIntl();
@@ -77,10 +83,27 @@ export const ModificationResults: React.FC<ModificationResultsProps> = ({ modifi
7783
return (
7884
<>
7985
{modifications.map((modification) => (
80-
<Box sx={styles.itemHover} key={modification.impactedEquipmentId + modification.modificationUuid}>
81-
<Typography variant="body2" onClick={() => handleClick(modification)} sx={styles.modificationLabel}>
82-
<strong>{modification.impactedEquipmentId + ' - '}</strong> {getModificationLabel(modification)}
86+
<Box key={modification.modificationUuid}>
87+
<Typography
88+
variant="body2"
89+
onClick={() => handleClick(modification)}
90+
sx={[styles.itemHover, styles.modificationLabel]}
91+
>
92+
{getModificationLabel(modification)}
93+
{` (${modification.impactedEquipmentIds.length})`}
8394
</Typography>
95+
<Box key={modification.modificationUuid}>
96+
{modification.impactedEquipmentIds.map((equipmentId) => (
97+
<Typography
98+
key={equipmentId}
99+
variant="body2"
100+
onClick={() => handleClick(modification)}
101+
sx={[styles.itemHover, styles.modifiedEquipmentLabel]}
102+
>
103+
<strong>{equipmentId}</strong>
104+
</Typography>
105+
))}
106+
</Box>
84107
</Box>
85108
))}
86109
</>

src/components/graph/menus/root-network/root-network-panel-search.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ interface RootNetworkSearchPanelProps {
3030
}
3131

3232
function getModificationResultsCount(results: ModificationsSearchResult[]): number {
33-
return results.reduce((sum, r) => sum + r.modifications.length, 0);
33+
return results.reduce((sum, node) => {
34+
const countForNode = node.modifications.reduce((innerSum, modif) => {
35+
return innerSum + modif.impactedEquipmentIds.length;
36+
}, 0);
37+
return sum + countForNode;
38+
}, 0);
3439
}
3540

3641
function getNodeResultsCount(results: string[]): number {
@@ -139,19 +144,26 @@ const RootNetworkSearchPanel: React.FC<RootNetworkSearchPanelProps> = ({ setIsSe
139144

140145
{isLoading && (
141146
<Typography variant="body2" sx={{ mt: 1, color: 'gray' }}>
142-
{intl.formatMessage({ id: 'rootNetwork.loading' })}
147+
<FormattedMessage id="rootNetwork.loading" />
143148
</Typography>
144149
)}
145150
{showResultsCount && (
146151
<Typography variant="body2" sx={{ mt: 1, color: 'gray' }}>
147-
<FormattedMessage
148-
id="rootNetwork.results"
149-
values={{
150-
count: isNodeTab(tabValue)
151-
? getNodeResultsCount(nodesSearch.results)
152-
: getModificationResultsCount(modificationsSearch.results),
153-
}}
154-
/>
152+
{isNodeTab(tabValue) ? (
153+
<FormattedMessage
154+
id="rootNetwork.nodeResults"
155+
values={{
156+
count: getNodeResultsCount(nodesSearch.results),
157+
}}
158+
/>
159+
) : (
160+
<FormattedMessage
161+
id="rootNetwork.modificationResults"
162+
values={{
163+
count: getModificationResultsCount(modificationsSearch.results),
164+
}}
165+
/>
166+
)}
155167
</Typography>
156168
)}
157169

src/components/graph/menus/root-network/root-network.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import type { UUID } from 'node:crypto';
88

99
export interface Modification {
1010
modificationUuid: UUID;
11-
impactedEquipmentId: string;
1211
messageValues: string;
1312
messageType: string;
13+
impactedEquipmentIds: string[];
1414
}
1515

1616
export interface ModificationsSearchResult {

src/translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,8 @@
14501450
"rootNetwork.searchPlaceholder.nodes": "Search for a node…",
14511451
"rootNetwork.modificationTab": "Modifications",
14521452
"rootNetwork.nodeTab": "Nodes",
1453-
"rootNetwork.results": "{count, plural, =0 {No result} =1 {# result} other {# results}}",
1453+
"rootNetwork.nodeResults": "{count, plural, =0 {No result} =1 {# result} other {# results}}",
1454+
"rootNetwork.modificationResults": "{count, plural, =0 {No equipment found} =1 {# equipment found} other {# equipments found}}",
14541455
"rootNetwork.loading": "Loading...",
14551456
"rootNetwork.originalNotFound": "The original case was not found",
14561457
"rootNetwork.unknownPath": "<Unknown>",

src/translations/fr.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,8 @@
14521452
"rootNetwork.searchPlaceholder.nodes": "Rechercher un nœud...",
14531453
"rootNetwork.modificationTab": "Modifications",
14541454
"rootNetwork.nodeTab": "Nœuds",
1455-
"rootNetwork.results": "{count, plural, =0 {Aucun résultat} =1 {# résultat} other {# résultats}}",
1455+
"rootNetwork.nodeResults": "{count, plural, =0 {Aucun résultat} =1 {# résultat} other {# résultats}}",
1456+
"rootNetwork.modificationResults": "{count, plural, =0 {Aucun ouvrage trouvé} =1 {# ouvrage trouvé} other {# ouvrages trouvés}}",
14561457
"rootNetwork.loading": "Chargement...",
14571458
"rootNetwork.originalNotFound": "La situation d'origine est introuvable",
14581459
"rootNetwork.unknownPath": "<Inconnu>",

0 commit comments

Comments
 (0)