fix changesets routes for pagination

This commit is contained in:
Eduard Heimbuch
2020-01-10 09:19:09 +01:00
parent 28f1319935
commit 184b6e6e98
4 changed files with 41 additions and 26 deletions

View File

@@ -1,46 +1,52 @@
import React, { FC } from "react"; import React, { FC } from "react";
import styled from "styled-components"; import styled from "styled-components";
import Button from "@scm-manager/ui-components/src/buttons/Button"; import { Button, ButtonAddons } from "@scm-manager/ui-components";
import ButtonAddons from "@scm-manager/ui-components/src/buttons/ButtonAddons";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Branch } from "@scm-manager/ui-types";
const SmallButton = styled(Button).attrs(() => ({}))` const SmallButton = styled(Button).attrs(() => ({}))`
border-radius: 4px; border-radius: 4px;
font-size: 0.75rem; font-size: 1rem;
font-weight: 500; font-weight: 600;
`;
const ButtonAddonsMarginRight = styled(ButtonAddons)`
margin-right: -0.2em;
`; `;
type Props = { type Props = {
url: string; url: string;
branches: Branch[];
}; };
const CodeViewSwitcher: FC<Props> = ({ url }) => { const CodeViewSwitcher: FC<Props> = ({ url, branches }) => {
const [t] = useTranslation("repos"); const [t] = useTranslation("repos");
const createDestinationUrl = (destination: string, removePath: boolean) => { const createDestinationUrl = (destination: string, suffix?: string) => {
let splittedUrl = url.split("/"); let splittedUrl = url.split("/");
splittedUrl[5] = destination; splittedUrl[5] = destination;
if (removePath) { splittedUrl.splice(7, splittedUrl.length);
splittedUrl.splice(7, splittedUrl.length); if (suffix) {
splittedUrl.push(suffix);
} }
return splittedUrl.join("/"); return splittedUrl.join("/");
}; };
return ( return (
<ButtonAddons> <ButtonAddonsMarginRight>
<SmallButton <SmallButton
label={t("code.commits")} label={t("code.commits")}
icon="fa fa-exchange-alt" icon="fa fa-exchange-alt"
color={url.includes("/code/changesets") ? "link is-selected" : undefined} color={url.includes("/code/branch/") || url.includes("/code/changesets/") ? "link is-selected" : undefined}
link={createDestinationUrl("changesets", true)} link={branches ? createDestinationUrl("branch", "changesets/") : createDestinationUrl("changesets")}
/> />
<SmallButton <SmallButton
label={t("code.sources")} label={t("code.sources")}
icon="fa fa-code" icon="fa fa-code"
color={url.includes("/code/sources") ? "link is-selected" : undefined} color={url.includes("/code/sources") ? "link is-selected" : undefined}
link={createDestinationUrl("sources", false)} link={createDestinationUrl("sources")}
/> />
</ButtonAddons> </ButtonAddonsMarginRight>
); );
}; };

View File

@@ -25,7 +25,6 @@ type Props = RouteComponentProps &
branches: Branch[]; branches: Branch[];
error: Error; error: Error;
loading: boolean; loading: boolean;
selectedView: string;
selectedBranch: string; selectedBranch: string;
// Dispatch props // Dispatch props
@@ -64,10 +63,22 @@ class CodeOverview extends React.Component<Props> {
branchSelected = (branch?: Branch) => { branchSelected = (branch?: Branch) => {
let splittedUrl = this.props.location.pathname.split("/"); let splittedUrl = this.props.location.pathname.split("/");
if (branch) { if (
splittedUrl[6] = encodeURIComponent(branch.name); this.props.location.pathname.includes("/code/sources/") ||
this.props.location.pathname.includes("/code/branch/")
) {
if (branch) {
splittedUrl[6] = encodeURIComponent(branch.name);
}
this.props.history.push(splittedUrl.join("/"));
}
if (this.props.location.pathname.includes("/code/changesets/")) {
this.props.history.push(
`${splittedUrl[0]}/${splittedUrl[1]}/${splittedUrl[2]}/${splittedUrl[3]}/${
splittedUrl[4]
}/branch/${encodeURIComponent(branch.name)}/${splittedUrl[5]}/`
);
} }
this.props.history.push(splittedUrl.join("/"));
}; };
render() { render() {
@@ -96,7 +107,7 @@ class CodeOverview extends React.Component<Props> {
onSelectBranch={this.branchSelected} onSelectBranch={this.branchSelected}
/> />
} }
right={<CodeViewSwitcher url={this.props.location.pathname} />} right={<CodeViewSwitcher url={this.props.location.pathname} branches={branches} />}
/> />
</CodeActionBar> </CodeActionBar>
<Route <Route
@@ -110,11 +121,10 @@ class CodeOverview extends React.Component<Props> {
/> />
<Route <Route
path={`${url}/changesets`} path={`${url}/changesets`}
exact={true}
render={() => <ChangesetsRoot repository={repository} baseUrl={`${url}/changesets`} />} render={() => <ChangesetsRoot repository={repository} baseUrl={`${url}/changesets`} />}
/> />
<Route <Route
path={`${url}/changesets/:branch/`} path={`${url}/branch/:branch/changesets/`}
render={() => <ChangesetsRoot repository={repository} baseUrl={`${url}/changesets`} />} render={() => <ChangesetsRoot repository={repository} baseUrl={`${url}/changesets`} />}
/> />
</div> </div>
@@ -135,14 +145,13 @@ const mapStateToProps = (state: any, ownProps: Props) => {
const error = getFetchBranchesFailure(state, repository); const error = getFetchBranchesFailure(state, repository);
const loading = isFetchBranchesPending(state, repository); const loading = isFetchBranchesPending(state, repository);
const branches = getBranches(state, repository); const branches = getBranches(state, repository);
const selectedView = decodeURIComponent(location.pathname.split("/")[5]); const branchFromURL =
const branchFromURL = decodeURIComponent(location.pathname.split("/")[6]); !location.pathname.includes("/code/changesets/") && decodeURIComponent(location.pathname.split("/")[6]);
const selectedBranch = branchFromURL && branchFromURL !== "undefined" ? branchFromURL : ""; const selectedBranch = branchFromURL && branchFromURL !== "undefined" ? branchFromURL : "";
return { return {
error, error,
loading, loading,
branches, branches,
selectedView,
selectedBranch selectedBranch
}; };
}; };

View File

@@ -22,14 +22,14 @@ class RepositoryEntry extends React.Component<Props> {
renderChangesetsLink = (repository: Repository, repositoryLink: string) => { renderChangesetsLink = (repository: Repository, repositoryLink: string) => {
if (repository._links["changesets"]) { if (repository._links["changesets"]) {
return <RepositoryEntryLink icon="exchange-alt" to={repositoryLink + "/code/changesets"} />; return <RepositoryEntryLink icon="exchange-alt" to={repositoryLink + "/code/changesets/"} />;
} }
return null; return null;
}; };
renderSourcesLink = (repository: Repository, repositoryLink: string) => { renderSourcesLink = (repository: Repository, repositoryLink: string) => {
if (repository._links["sources"]) { if (repository._links["sources"]) {
return <RepositoryEntryLink icon="code" to={repositoryLink + "/code/sources"} />; return <RepositoryEntryLink icon="code" to={repositoryLink + "/code/sources/"} />;
} }
return null; return null;
}; };

View File

@@ -126,7 +126,7 @@ class RepositoryRoot extends React.Component<Props> {
<Redirect exact from={`${url}/sources`} to={`${url}/code/sources`} /> <Redirect exact from={`${url}/sources`} to={`${url}/code/sources`} />
<Redirect from={`${url}/sources/:revision/:path*`} to={`${url}/code/sources/:revision/:path*`} /> <Redirect from={`${url}/sources/:revision/:path*`} to={`${url}/code/sources/:revision/:path*`} />
<Redirect exact from={`${url}/changesets`} to={`${url}/code/changesets`} /> <Redirect exact from={`${url}/changesets`} to={`${url}/code/changesets`} />
<Redirect from={`${url}/branch/:branch/changesets`} to={`${url}/code/changesets/:branch`} /> <Redirect from={`${url}/branch/:branch/changesets`} to={`${url}/code/branch/:branch/changesets/`} />
<Route path={`${url}/info`} exact component={() => <RepositoryDetails repository={repository} />} /> <Route path={`${url}/info`} exact component={() => <RepositoryDetails repository={repository} />} />
<Route path={`${url}/settings/general`} component={() => <EditRepo repository={repository} />} /> <Route path={`${url}/settings/general`} component={() => <EditRepo repository={repository} />} />
<Route <Route