mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-24 01:09:48 +01:00
Filer repositories in UI by namespace
This commit is contained in:
@@ -132,9 +132,9 @@ class LinkPaginator extends React.Component<Props> {
|
||||
<nav className="pagination is-centered" aria-label="pagination">
|
||||
{this.renderPreviousButton("pagination-previous", t("paginator.previous"))}
|
||||
<ul className="pagination-list">
|
||||
{this.pageLinks().map((link, index) => {
|
||||
return <li key={index}>{link}</li>;
|
||||
})}
|
||||
{this.pageLinks().map((link, index) => (
|
||||
<li key={index}>{link}</li>
|
||||
))}
|
||||
</ul>
|
||||
{this.renderNextButton("pagination-next", t("paginator.next"))}
|
||||
</nav>
|
||||
|
||||
@@ -22,7 +22,12 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { concat, getPageFromMatch, getQueryStringFromLocation, withEndingSlash } from "./urls";
|
||||
import {
|
||||
concat,
|
||||
getNamespaceAndPageFromMatch,
|
||||
getQueryStringFromLocation,
|
||||
withEndingSlash
|
||||
} from "./urls";
|
||||
|
||||
describe("tests for withEndingSlash", () => {
|
||||
it("should append missing slash", () => {
|
||||
@@ -42,28 +47,41 @@ describe("concat tests", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("tests for getPageFromMatch", () => {
|
||||
function createMatch(page: string) {
|
||||
describe("tests for getNamespaceAndPageFromMatch", () => {
|
||||
function createMatch(namespace?: string, page?: string) {
|
||||
return {
|
||||
params: {
|
||||
page
|
||||
}
|
||||
params: { namespace, page }
|
||||
};
|
||||
}
|
||||
|
||||
it("should return 1 for NaN", () => {
|
||||
const match = createMatch("any");
|
||||
expect(getPageFromMatch(match)).toBe(1);
|
||||
it("should return no namespace and page 1 for neither namespace nor page", () => {
|
||||
const match = createMatch();
|
||||
expect(getNamespaceAndPageFromMatch(match)).toEqual({ namespace: undefined, page: 1 });
|
||||
});
|
||||
|
||||
it("should return 1 for 0", () => {
|
||||
it("should return no namespace and page 1 for 0 as only parameter", () => {
|
||||
const match = createMatch("0");
|
||||
expect(getPageFromMatch(match)).toBe(1);
|
||||
expect(getNamespaceAndPageFromMatch(match)).toEqual({ namespace: undefined, page: 1 });
|
||||
});
|
||||
|
||||
it("should return the given number", () => {
|
||||
it("should return no namespace and given number as page, when only a number is given", () => {
|
||||
const match = createMatch("42");
|
||||
expect(getPageFromMatch(match)).toBe(42);
|
||||
expect(getNamespaceAndPageFromMatch(match)).toEqual({ namespace: undefined, page: 42 });
|
||||
});
|
||||
|
||||
it("should return big number as namespace and page 1, when only a big number is given", () => {
|
||||
const match = createMatch("1337");
|
||||
expect(getNamespaceAndPageFromMatch(match)).toEqual({ namespace: "1337", page: 1 });
|
||||
});
|
||||
|
||||
it("should namespace and page 1, when only a string is given", () => {
|
||||
const match = createMatch("something");
|
||||
expect(getNamespaceAndPageFromMatch(match)).toEqual({ namespace: "something", page: 1 });
|
||||
});
|
||||
|
||||
it("should namespace and given page, when namespace and page are given", () => {
|
||||
const match = createMatch("something", "42");
|
||||
expect(getNamespaceAndPageFromMatch(match)).toEqual({ namespace: "something", page: 42 });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -46,10 +46,33 @@ export function concat(base: string, ...parts: string[]) {
|
||||
return url;
|
||||
}
|
||||
|
||||
export function getNamespaceAndPageFromMatch(match: any) {
|
||||
const namespaceFromMatch: string = match.params.namespace;
|
||||
const pageFromMatch: string = match.params.page;
|
||||
|
||||
if (!namespaceFromMatch && !pageFromMatch) {
|
||||
return { namespace: undefined, page: 1 };
|
||||
}
|
||||
|
||||
if (!pageFromMatch) {
|
||||
if (namespaceFromMatch.match(/^\d{1,3}$/)) {
|
||||
return { namespace: undefined, page: parsePageNumber(namespaceFromMatch) };
|
||||
} else {
|
||||
return { namespace: namespaceFromMatch, page: 1 };
|
||||
}
|
||||
}
|
||||
|
||||
return { namespace: namespaceFromMatch, page: parsePageNumber(pageFromMatch) };
|
||||
}
|
||||
|
||||
export function getPageFromMatch(match: any) {
|
||||
let page = parseInt(match.params.page, 10);
|
||||
return parsePageNumber(match.params.page);
|
||||
}
|
||||
|
||||
function parsePageNumber(pageAsString: string) {
|
||||
const page = parseInt(pageAsString, 10);
|
||||
if (isNaN(page) || !page) {
|
||||
page = 1;
|
||||
return 1;
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user