Skip to content

Commit 12fedd9

Browse files
committed
fix: enable swap branch functionality of lower branch in MTR and GZMTR
1 parent 762032d commit 12fedd9

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/components/side-panel/branch-side-panel/action-section.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export default function ActionSection() {
2525
rmgRuntime.event(Events.REVERSE_STATIONS, { style });
2626
};
2727

28-
const isExternalLine = selectedBranch !== 0 && isColineBranch(branches[selectedBranch], stn_list);
28+
const isColine =
29+
selectedBranch !== 0 && style === RmgStyle.SHMetro && isColineBranch(branches[selectedBranch], stn_list);
2930

3031
return (
3132
<Box p={1}>
@@ -85,7 +86,7 @@ export default function ActionSection() {
8586
: t('BranchSidePanel.action.reverse')}
8687
</Button>
8788

88-
{selectedBranch !== 0 && !isExternalLine && (
89+
{selectedBranch !== 0 && !isColine && (
8990
<Button
9091
size="sm"
9192
variant="outline"

src/redux/param/swap-branch.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ import { setStationsBulk } from './action';
2424
*
2525
* Implementation Details:
2626
* 1. Diverge Point (D):
27-
* - Swap `children` nodes (Main <-> Branch).
27+
* - Swap `children` nodes, to ensure the index of the branch start node
28+
* which decides drawing details unchanged.
2829
* - Update `branch.right` to point to the *new* branch start node (old Main).
2930
* 2. Converge Point (G):
30-
* - Swap `parents` nodes.
31+
* - Swap `parents` nodes, to ensure the index of the branch start node
32+
* which decides drawing details unchanged.
3133
* - Update `branch.left` to point to the *new* branch end node (old Main).
3234
*
3335
* Assumption: Strict 2-way split/merge at D/G.
@@ -61,24 +63,26 @@ export const swapBranch = (branchIndex: number) => {
6163

6264
let modified = false;
6365

64-
// Swap children of divergePoint, then assign the new children[0] to branch.right[1]
66+
// Swap children of divergePoint, then assigned the child preserving index in children to branch.right[1]
6567
if (divergePoint.branch && divergePoint.branch.right) {
68+
const indexOfRightInChildren = divergePoint.children.indexOf(divergePoint.branch.right[1]);
6669
const [child1, child2] = divergePoint.children;
6770
divergePoint.children = [child2, child1];
6871
divergePoint.branch = {
6972
...divergePoint.branch,
70-
right: [divergePoint.branch.right[0], divergePoint.children[0]],
73+
right: [divergePoint.branch.right[0], divergePoint.children[indexOfRightInChildren]],
7174
};
7275

7376
modified = true;
7477
}
75-
// Swap parents of convergePoint, then assign the new parents[0] to branch.left[1]
78+
// Swap parents of convergePoint, then assigned the parent preserving index in parents to branch.left[1]
7679
if (convergePoint.branch && convergePoint.branch.left) {
80+
const indexOfLeftInParents = convergePoint.parents.indexOf(convergePoint.branch.left[1]);
7781
const [parent1, parent2] = convergePoint.parents;
7882
convergePoint.parents = [parent2, parent1];
7983
convergePoint.branch = {
8084
...convergePoint.branch,
81-
left: [convergePoint.branch.left[0], convergePoint.parents[0]],
85+
left: [convergePoint.branch.left[0], convergePoint.parents[indexOfLeftInParents]],
8286
};
8387

8488
modified = true;

0 commit comments

Comments
 (0)