Skip to content

Commit 722cab5

Browse files
authored
Fix modifications highlighting on search bugs (#3332)
Signed-off-by: Ayoub LABIDI <[email protected]>
1 parent 90ed5c5 commit 722cab5

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

src/components/graph/menus/network-modifications/network-modifications-table.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ const NetworkModificationsTable: React.FC<NetworkModificationsTableProps> = ({
221221
if (highlightedModificationUuid && gridRef.current?.api) {
222222
const selectedRow = gridRef.current.api.getRowNode(highlightedModificationUuid);
223223
if (selectedRow) {
224-
gridRef.current.api.ensureNodeVisible(selectedRow, 'top');
224+
// Ensure the row is visible, using a timeout to wait for the grid to finish any ongoing rendering
225+
setTimeout(() => {
226+
gridRef?.current?.api.ensureNodeVisible(selectedRow, 'top');
227+
}, 0);
225228
}
226229
}
227230
}, [highlightedModificationUuid]);
@@ -250,7 +253,6 @@ const NetworkModificationsTable: React.FC<NetworkModificationsTableProps> = ({
250253
getRowStyle={getRowStyle}
251254
onRowDragEnter={onRowDragStart}
252255
onRowDragEnd={onRowDragEnd}
253-
onFirstDataRendered={handleScroll}
254256
rowDragManaged={!isRowDragDisabled}
255257
suppressNoRowsOverlay={true}
256258
overrideLocales={AGGRID_LOCALES}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const ModificationResults: React.FC<ModificationResultsProps> = ({ modifi
6565
(modification: Modification) => {
6666
const node = treeNodes?.find((node) => node.id === nodeUuid);
6767
if (node) {
68-
setCurrentTreeNodeWithSync(node);
68+
setCurrentTreeNodeWithSync({ ...node });
6969
triggerTreeNodeFocus();
7070
}
7171
dispatch(setModificationsDrawerOpen());

src/components/graph/menus/root-network/root-network-nodes-search-results.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const RootNetworkNodesSearchResults: React.FC<RootNetworkNodesSearchResul
5151
(nodeName: string) => {
5252
const node = treeNodes?.find((node) => node.data.label === nodeName);
5353
if (node) {
54-
setCurrentTreeNodeWithSync(node);
54+
setCurrentTreeNodeWithSync({ ...node });
5555
triggerTreeNodeFocus();
5656
}
5757
},

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ const RootNetworkSearchPanel: React.FC<RootNetworkSearchPanelProps> = ({ setIsSe
8080
nodesSearch.reset();
8181
modificationsSearch.reset();
8282
setIsSearchActive(false);
83-
dispatch(setHighlightModification(null));
8483
};
8584

8685
const handleOnChange = (e: React.ChangeEvent<HTMLInputElement>) => {

src/components/graph/menus/root-network/use-root-network-modification-search.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
88
import { ModificationsSearchResult } from './root-network.types';
99
import { getModifications } from '../../../../services/root-network';
1010
import { UUID } from 'crypto';
11-
import { useSelector } from 'react-redux';
11+
import { useDispatch, useSelector } from 'react-redux';
1212
import { AppState } from '../../../../redux/reducer';
1313
import { useSnackMessage, useDebounce } from '@gridsuite/commons-ui';
14+
import { setHighlightModification } from 'redux/actions';
1415

1516
function reOrderSearchResults(
1617
results: ModificationsSearchResult[],
@@ -33,6 +34,7 @@ export const useRootNetworkModificationSearch = () => {
3334
const [searchTerm, setSearchTerm] = useState('');
3435
const [modificationsResults, setModificationsResults] = useState<ModificationsSearchResult[]>([]);
3536
const [isLoading, setIsLoading] = useState(false);
37+
const dispatch = useDispatch();
3638

3739
const studyUuid = useSelector((s: AppState) => s.studyUuid);
3840
const currentRootNetworkUuid = useSelector((s: AppState) => s.currentRootNetworkUuid);
@@ -42,7 +44,8 @@ export const useRootNetworkModificationSearch = () => {
4244
const reset = useCallback(() => {
4345
setSearchTerm('');
4446
setModificationsResults([]);
45-
}, []);
47+
dispatch(setHighlightModification(null));
48+
}, [dispatch]);
4649

4750
const searchMatchingElements = useCallback(
4851
(searchTerm: string) => {

0 commit comments

Comments
 (0)