Skip to content

Commit 6a84dfb

Browse files
committed
fix(NavigationTree): expand tree to initial active path
1 parent 7ed43dd commit 6a84dfb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/components/NavigationTree/NavigationTreeDirectory.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function NavigationTreeDirectory({
4444
.then((data) => {
4545
dispatch({
4646
type: NavigationTreeActionType.FinishLoading,
47-
payload: {path, data},
47+
payload: {path, activePath, data},
4848
});
4949
})
5050
.catch((error) => {

src/components/NavigationTree/state.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ export function reducer(state: NavigationTreeState = {}, action: NavigationTreeA
6363
const name = item.name;
6464
const type = item.type;
6565

66+
// expand the tree according to the active path
67+
// prioritize the existing state to expand the tree only on first load
68+
const {activePath = ''} = action.payload;
69+
const collapsed = state[path]?.collapsed ?? !activePath.startsWith(`${path}/`);
70+
6671
newState[path] = {
6772
...getDefaultNodeState(),
73+
collapsed,
6874
path,
6975
name,
7076
type,

0 commit comments

Comments
 (0)