Skip to content

Commit 7dabb49

Browse files
committed
Ensure each switch condition returns a state
1 parent ed8d24f commit 7dabb49

File tree

1 file changed

+32
-26
lines changed
  • apps/webapp/app/components/primitives/TreeView

1 file changed

+32
-26
lines changed

apps/webapp/app/components/primitives/TreeView/reducer.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,16 @@ export function reducer(state: TreeState, action: Action): TreeState {
231231
const currentlySelected = state.nodes[action.payload.id]?.selected ?? false;
232232
if (currentlySelected) {
233233
return reducer(state, { type: "DESELECT_NODE", payload: { id: action.payload.id } });
234-
} else {
235-
return reducer(state, {
236-
type: "SELECT_NODE",
237-
payload: {
238-
id: action.payload.id,
239-
scrollToNode: action.payload.scrollToNode,
240-
scrollToNodeFn: action.payload.scrollToNodeFn,
241-
},
242-
});
243234
}
235+
236+
return reducer(state, {
237+
type: "SELECT_NODE",
238+
payload: {
239+
id: action.payload.id,
240+
scrollToNode: action.payload.scrollToNode,
241+
scrollToNodeFn: action.payload.scrollToNodeFn,
242+
},
243+
});
244244
}
245245
case "EXPAND_NODE": {
246246
const newNodes = {
@@ -277,16 +277,16 @@ export function reducer(state: TreeState, action: Action): TreeState {
277277
type: "COLLAPSE_NODE",
278278
payload: { id: action.payload.id },
279279
});
280-
} else {
281-
return reducer(state, {
282-
type: "EXPAND_NODE",
283-
payload: {
284-
id: action.payload.id,
285-
scrollToNode: action.payload.scrollToNode,
286-
scrollToNodeFn: action.payload.scrollToNodeFn,
287-
},
288-
});
289280
}
281+
282+
return reducer(state, {
283+
type: "EXPAND_NODE",
284+
payload: {
285+
id: action.payload.id,
286+
scrollToNode: action.payload.scrollToNode,
287+
scrollToNodeFn: action.payload.scrollToNodeFn,
288+
},
289+
});
290290
}
291291
case "EXPAND_ALL_BELOW_DEPTH": {
292292
const nodesToExpand = state.tree.filter(
@@ -396,17 +396,17 @@ export function reducer(state: TreeState, action: Action): TreeState {
396396
level: action.payload.level,
397397
},
398398
});
399-
} else {
400-
return reducer(state, {
401-
type: "EXPAND_LEVEL",
402-
payload: {
403-
level: action.payload.level,
404-
},
405-
});
406399
}
400+
401+
return reducer(state, {
402+
type: "EXPAND_LEVEL",
403+
payload: {
404+
level: action.payload.level,
405+
},
406+
});
407407
}
408408
case "SELECT_FIRST_VISIBLE_NODE": {
409-
const node = firstVisibleNode(state.tree, state.nodes);
409+
const node = firstVisibleNode(state.tree, state.filteredNodes);
410410
if (node) {
411411
return reducer(state, {
412412
type: "SELECT_NODE",
@@ -417,6 +417,8 @@ export function reducer(state: TreeState, action: Action): TreeState {
417417
},
418418
});
419419
}
420+
421+
return state;
420422
}
421423
case "SELECT_LAST_VISIBLE_NODE": {
422424
const node = lastVisibleNode(state.tree, state.nodes);
@@ -430,6 +432,8 @@ export function reducer(state: TreeState, action: Action): TreeState {
430432
},
431433
});
432434
}
435+
436+
return state;
433437
}
434438
case "SELECT_NEXT_VISIBLE_NODE": {
435439
const selected = selectedIdFromState(state.nodes);
@@ -456,6 +460,8 @@ export function reducer(state: TreeState, action: Action): TreeState {
456460
},
457461
});
458462
}
463+
464+
return state;
459465
}
460466
case "SELECT_PREVIOUS_VISIBLE_NODE": {
461467
const selected = selectedIdFromState(state.nodes);

0 commit comments

Comments
 (0)