sorted branches and show defaultbranch label

This commit is contained in:
Florian Scholdei
2019-03-29 14:24:54 +01:00
parent be03863847
commit b7178d3332
3 changed files with 46 additions and 9 deletions

View File

@@ -35,16 +35,47 @@ type Props = {
match: any,
t: string => string
};
// master, default should always be the first one,
// followed by develop the rest should be ordered by its name
export function orderBranches(branches: Branch[]) {
branches.sort((a, b) => {
if (a.defaultBranch && !b.defaultBranch ) {
return -20;
} else if (!a.defaultBranch && b.defaultBranch ) {
return 20;
} else if (a.name === "master" && b.name !== "master") {
return -10;
} else if (a.name !== "master" && b.name === "master") {
return 10;
} else if (a.name === "default" && b.name !== "default") {
return -10;
} else if (a.name !== "default" && b.name === "default") {
return 10;
} else if (a.name === "develop" && b.name !== "develop") {
return -5;
} else if (a.name !== "develop" && b.name === "develop") {
return 5;
} else if (a.name < b.name) {
return -1;
} else if (a.name > b.name) {
return 1;
}
return 0;
});
}
class BranchesOverview extends React.Component<Props> {
componentDidMount() {
const { fetchBranches, repository } = this.props;
fetchBranches(repository);
}
render() {
const { baseUrl, loading, error, branches, t } = this.props;
orderBranches(branches);
if (error) {
return <ErrorNotification error={error} />;
}
@@ -64,9 +95,13 @@ class BranchesOverview extends React.Component<Props> {
renderCreateButton() {
const { showCreateButton, t } = this.props;
if (showCreateButton || true ) { // TODO
if (showCreateButton || true) {
// TODO
return (
<CreateButton label={t("branches.overview.createButton")} link="./create" />
<CreateButton
label={t("branches.overview.createButton")}
link="./create"
/>
);
}
return null;