Skip to content

Commit d3f2dbd

Browse files
committed
extract function for resolving selected branch
1 parent abca195 commit d3f2dbd

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

app/src/ui/rebase/rebase-branch-dialog.tsx

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ export class RebaseBranchDialog extends React.Component<
6868
public constructor(props: IRebaseBranchDialogProps) {
6969
super(props)
7070

71-
const selectedBranch = this.resolveSelectedBranch()
71+
const { initialBranch, currentBranch, defaultBranch } = props
72+
73+
const selectedBranch = resolveSelectedBranch(
74+
currentBranch,
75+
defaultBranch,
76+
initialBranch
77+
)
7278

7379
this.state = {
7480
selectedBranch,
@@ -168,21 +174,25 @@ export class RebaseBranchDialog extends React.Component<
168174

169175
this.setState({ isRebasing: false })
170176
}
177+
}
171178

172-
/**
173-
* Returns the branch to use as the selected branch
174-
*
175-
* The initial branch is used if passed
176-
* otherwise, the default branch will be used if it's
177-
* not the currently checked out branch
178-
*/
179-
private resolveSelectedBranch() {
180-
const { currentBranch, defaultBranch, initialBranch } = this.props
181-
182-
if (initialBranch !== undefined) {
183-
return initialBranch
184-
}
185-
186-
return currentBranch === defaultBranch ? null : defaultBranch
179+
/**
180+
* Returns the branch to use as the selected branch in the dialog.
181+
*
182+
* The initial branch is used if defined, otherwise the default branch will be
183+
* compared to the current branch.
184+
*
185+
* If the current branch is the default branch, `null` is returned. Otherwise
186+
* the default branch is used.
187+
*/
188+
function resolveSelectedBranch(
189+
currentBranch: Branch,
190+
defaultBranch: Branch | null,
191+
initialBranch: Branch | undefined
192+
) {
193+
if (initialBranch !== undefined) {
194+
return initialBranch
187195
}
196+
197+
return currentBranch === defaultBranch ? null : defaultBranch
188198
}

0 commit comments

Comments
 (0)