fetch changesets for selected branch // fetch changesets for default branch if trying to fetch changesets for specific revision

This commit is contained in:
Eduard Heimbuch
2020-01-13 14:49:17 +01:00
parent 3011b4d3e8
commit 0e544d694f
2 changed files with 39 additions and 11 deletions

View File

@@ -15,16 +15,24 @@ const ButtonAddonsMarginRight = styled(ButtonAddons)`
`;
type Props = {
url: string;
baseUrl: string;
currentUrl: string;
branches: Branch[];
selectedBranch: string;
};
const CodeViewSwitcher: FC<Props> = ({ url, branches }) => {
const CodeViewSwitcher: FC<Props> = ({ baseUrl, currentUrl, branches, selectedBranch }) => {
const [t] = useTranslation("repos");
const createDestinationUrl = (destination: string, suffix?: string) => {
let splittedUrl = url.split("/");
const createDestinationUrl = (destination: string, branch?: string, suffix?: string) => {
if (!branches) {
return baseUrl + "/" + destination + "/";
}
let splittedUrl = currentUrl.split("/");
splittedUrl[5] = destination;
if (branch) {
splittedUrl[6] = branch;
}
splittedUrl.splice(7, splittedUrl.length);
if (suffix) {
splittedUrl.push(suffix);
@@ -37,13 +45,27 @@ const CodeViewSwitcher: FC<Props> = ({ url, branches }) => {
<SmallButton
label={t("code.commits")}
icon="fa fa-exchange-alt"
color={url.includes("/code/branch") || url.includes("/code/changesets") ? "link is-selected" : undefined}
link={branches ? createDestinationUrl("branch", "changesets/") : createDestinationUrl("changesets")}
color={
currentUrl.includes("/code/branch") || currentUrl.includes("/code/changesets")
? "link is-selected"
: undefined
}
link={
branches
? branches.filter(branch => branch.name === selectedBranch).length === 0
? createDestinationUrl(
"branch",
branches.filter(branch => branch.defaultBranch === true)[0].name,
"changesets/"
)
: createDestinationUrl("branch", selectedBranch, "changesets/")
: createDestinationUrl("changesets")
}
/>
<SmallButton
label={t("code.sources")}
icon="fa fa-code"
color={url.includes("/code/sources") ? "link is-selected" : undefined}
color={currentUrl.includes("/code/sources") ? "link is-selected" : undefined}
link={createDestinationUrl("sources")}
/>
</ButtonAddonsMarginRight>

View File

@@ -82,7 +82,7 @@ class CodeOverview extends React.Component<Props> {
};
render() {
const { repository, baseUrl, branches, error, loading, t } = this.props;
const { repository, baseUrl, branches, selectedBranch, error, loading, t } = this.props;
const url = baseUrl;
if (loading) {
@@ -103,11 +103,11 @@ class CodeOverview extends React.Component<Props> {
<BranchSelector
label={t("code.branchSelector")}
branches={branches}
selectedBranch={this.props.selectedBranch}
selectedBranch={selectedBranch}
onSelectBranch={this.branchSelected}
/>
}
right={<CodeViewSwitcher url={this.props.location.pathname} branches={branches} />}
right={<CodeViewSwitcher baseUrl={url} currentUrl={this.props.location.pathname} branches={branches} selectedBranch={selectedBranch}/>}
/>
</CodeActionBar>
<Route
@@ -125,7 +125,13 @@ class CodeOverview extends React.Component<Props> {
/>
<Route
path={`${url}/branch/:branch/changesets/`}
render={() => <ChangesetsRoot repository={repository} baseUrl={`${url}/changesets`} />}
render={() => (
<ChangesetsRoot
repository={repository}
baseUrl={`${url}/changesets`}
selectedBranch={branches && branches.filter(b => b.name === this.props.selectedBranch)[0]}
/>
)}
/>
</div>
);