Show BranchChooser div only when there are branches to choose from

This commit is contained in:
Philipp Czora
2018-10-09 09:22:06 +02:00
parent dbe9ee59a8
commit 1606add59a
3 changed files with 19 additions and 19 deletions

View File

@@ -18,7 +18,8 @@ type Props = {
callback: (?Branch) => void,
branches: Branch[],
selectedBranchName: string,
loading: boolean
loading: boolean,
label: string
};
type State = {
@@ -39,17 +40,20 @@ class BranchChooser extends React.Component<Props, State> {
}
render() {
const { branches, loading } = this.props;
const { branches, loading, label } = this.props;
if (loading) {
return <Loading />;
}
if (branches && branches.length > 0) {
return (
<DropDown
options={branches.map(b => b.name)}
preselectedOption={this.state.selectedBranchName}
optionSelected={branch => this.branchChanged(branch)}
/>
<div className={"box"}>
<label className="label">{label}</label>
<DropDown
options={branches.map(b => b.name)}
preselectedOption={this.state.selectedBranchName}
optionSelected={branch => this.branchChanged(branch)}
/>
</div>
);
}

View File

@@ -144,16 +144,12 @@ class Changesets extends React.PureComponent<Props, State> {
return (
<>
<div className={"box"}>
<label className="label">
{t("changesets.branchselector-label")}
</label>
<BranchChooser
repository={repository}
selectedBranchName={branch}
callback={branch => this.branchChanged(branch)}
/>
</div>
<BranchChooser
repository={repository}
selectedBranchName={branch}
label={t("changesets.branchselector-label")}
callback={branch => this.branchChanged(branch)}
/>
<ChangesetList repository={repository} changesets={changesets} />
</>
);

View File

@@ -132,14 +132,14 @@ export function getBranch(
state: Object,
repository: Repository,
name: string
): ?Branch {
): Branch {
const key = createKey(repository);
if (state.branches[key]) {
if (state.branches[key].byNames[name]) {
return state.branches[key].byNames[name];
}
}
return undefined;
return null;
}
export function isFetchBranchesPending(