mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
fixed paging with NaN page numbers
This commit is contained in:
@@ -6,7 +6,7 @@ import { Route, withRouter } from "react-router-dom";
|
||||
import Changesets from "./Changesets";
|
||||
import BranchSelector from "./BranchSelector";
|
||||
import { connect } from "react-redux";
|
||||
import { Loading } from "@scm-manager/ui-components";
|
||||
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
|
||||
import {
|
||||
fetchBranches,
|
||||
getBranches,
|
||||
@@ -25,6 +25,7 @@ type Props = {
|
||||
// State props
|
||||
branches: Branch[],
|
||||
loading: boolean,
|
||||
error: Error,
|
||||
|
||||
// Dispatch props
|
||||
fetchBranches: Repository => void,
|
||||
@@ -69,17 +70,21 @@ class BranchRoot extends React.Component<Props> {
|
||||
};
|
||||
|
||||
render() {
|
||||
// TODO error???
|
||||
const { repository, loading, match, branches } = this.props;
|
||||
const url = this.stripEndingSlash(match.url);
|
||||
const { repository, error, loading, match, branches } = this.props;
|
||||
|
||||
if (error) {
|
||||
return <ErrorNotification error={error} />;
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
if (!repository || !branches) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const url = this.stripEndingSlash(match.url);
|
||||
const branch = this.findSelectedBranch();
|
||||
const changesets = <Changesets repository={repository} branch={branch} />;
|
||||
|
||||
|
||||
@@ -18,11 +18,16 @@ import {
|
||||
|
||||
import { connect } from "react-redux";
|
||||
import ChangesetList from "../components/changesets/ChangesetList";
|
||||
import { ErrorPage, LinkPaginator, Loading } from "@scm-manager/ui-components";
|
||||
import {
|
||||
ErrorNotification,
|
||||
LinkPaginator,
|
||||
Loading
|
||||
} from "@scm-manager/ui-components";
|
||||
import { translate } from "react-i18next";
|
||||
import { compose } from "redux";
|
||||
|
||||
type Props = {
|
||||
repository: Repository, //TODO: Do we really need/want this here?
|
||||
repository: Repository,
|
||||
branch: Branch,
|
||||
page: number,
|
||||
|
||||
@@ -50,18 +55,13 @@ class Changesets extends React.Component<Props> {
|
||||
const { changesets, loading, error, t } = this.props;
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<ErrorPage
|
||||
title={t("changesets.error-title")}
|
||||
subtitle={t("changesets.error-title")}
|
||||
error={error}
|
||||
/>
|
||||
);
|
||||
return <ErrorNotification error={error} />;
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
if (!changesets || changesets.length === 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -95,22 +95,30 @@ const mapDispatchToProps = dispatch => {
|
||||
};
|
||||
};
|
||||
|
||||
export function getPageFromMatch(match: any) {
|
||||
let page = parseInt(match.params.page);
|
||||
if (isNaN(page) || !page) {
|
||||
page = 1;
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
const mapStateToProps = (state: any, ownProps: Props) => {
|
||||
const { repository, branch, match } = ownProps;
|
||||
const changesets = getChangesets(state, repository, branch);
|
||||
const loading = isFetchChangesetsPending(state, repository, branch);
|
||||
const error = getFetchChangesetsFailure(state, repository, branch);
|
||||
const list = selectListAsCollection(state, repository, branch);
|
||||
|
||||
// TODO
|
||||
const page = parseInt(match.params.page || "1");
|
||||
const page = getPageFromMatch(match);
|
||||
|
||||
return { changesets, list, page, loading, error };
|
||||
};
|
||||
|
||||
export default withRouter(
|
||||
export default compose(
|
||||
withRouter,
|
||||
connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(translate("repos")(Changesets))
|
||||
);
|
||||
),
|
||||
translate("repos")
|
||||
)(Changesets);
|
||||
|
||||
26
scm-ui/src/repos/containers/Changesets.test.js
Normal file
26
scm-ui/src/repos/containers/Changesets.test.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { getPageFromMatch } from "./Changesets";
|
||||
|
||||
describe("tests for getPageFromMatch", () => {
|
||||
function createMatch(page: string) {
|
||||
return {
|
||||
params: {
|
||||
page
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
it("should return 1 for NaN", () => {
|
||||
const match = createMatch("any");
|
||||
expect(getPageFromMatch(match)).toBe(1);
|
||||
});
|
||||
|
||||
it("should return 1 for 0", () => {
|
||||
const match = createMatch("0");
|
||||
expect(getPageFromMatch(match)).toBe(1);
|
||||
});
|
||||
|
||||
it("should return the given number", () => {
|
||||
const match = createMatch("42");
|
||||
expect(getPageFromMatch(match)).toBe(42);
|
||||
});
|
||||
});
|
||||
@@ -94,7 +94,6 @@ class RepositoryRoot extends React.Component<Props> {
|
||||
}
|
||||
|
||||
const url = this.matchedUrl();
|
||||
// todo: default branch
|
||||
return (
|
||||
<Page title={repository.namespace + "/" + repository.name}>
|
||||
<div className="columns">
|
||||
|
||||
Reference in New Issue
Block a user