mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
refactor codeViewSwitcher
This commit is contained in:
@@ -30,16 +30,25 @@ const CodeViewSwitcher: FC<Props> = ({ baseUrl, currentUrl, branches, selectedBr
|
|||||||
}
|
}
|
||||||
let splittedUrl = currentUrl.split("/");
|
let splittedUrl = currentUrl.split("/");
|
||||||
splittedUrl[5] = destination;
|
splittedUrl[5] = destination;
|
||||||
|
splittedUrl.splice(6, splittedUrl.length);
|
||||||
if (branch) {
|
if (branch) {
|
||||||
splittedUrl[6] = branch;
|
splittedUrl[6] = branch;
|
||||||
}
|
}
|
||||||
splittedUrl.splice(7, splittedUrl.length);
|
|
||||||
if (suffix) {
|
if (suffix) {
|
||||||
splittedUrl.push(suffix);
|
splittedUrl.push(suffix);
|
||||||
}
|
}
|
||||||
return splittedUrl.join("/");
|
return splittedUrl.join("/");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const evaluateDestinationBranch = () => {
|
||||||
|
return (
|
||||||
|
branches &&
|
||||||
|
(branches.filter(branch => branch.name === selectedBranch).length === 0
|
||||||
|
? branches.filter(branch => branch.defaultBranch === true)[0].name
|
||||||
|
: branches.filter(branch => branch.name === selectedBranch)[0].name)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ButtonAddonsMarginRight>
|
<ButtonAddonsMarginRight>
|
||||||
<SmallButton
|
<SmallButton
|
||||||
@@ -52,13 +61,7 @@ const CodeViewSwitcher: FC<Props> = ({ baseUrl, currentUrl, branches, selectedBr
|
|||||||
}
|
}
|
||||||
link={
|
link={
|
||||||
branches
|
branches
|
||||||
? branches.filter(branch => branch.name === selectedBranch).length === 0
|
? createDestinationUrl("branch", evaluateDestinationBranch(), "changesets/")
|
||||||
? createDestinationUrl(
|
|
||||||
"branch",
|
|
||||||
branches.filter(branch => branch.defaultBranch === true)[0].name,
|
|
||||||
"changesets/"
|
|
||||||
)
|
|
||||||
: createDestinationUrl("branch", selectedBranch, "changesets/")
|
|
||||||
: createDestinationUrl("changesets")
|
: createDestinationUrl("changesets")
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -66,7 +69,7 @@ const CodeViewSwitcher: FC<Props> = ({ baseUrl, currentUrl, branches, selectedBr
|
|||||||
label={t("code.sources")}
|
label={t("code.sources")}
|
||||||
icon="fa fa-code"
|
icon="fa fa-code"
|
||||||
color={currentUrl.includes("/code/sources") ? "link is-selected" : undefined}
|
color={currentUrl.includes("/code/sources") ? "link is-selected" : undefined}
|
||||||
link={createDestinationUrl("sources")}
|
link={createDestinationUrl("sources", evaluateDestinationBranch())}
|
||||||
/>
|
/>
|
||||||
</ButtonAddonsMarginRight>
|
</ButtonAddonsMarginRight>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user