diff --git a/scm-ui/public/locales/en/commons.json b/scm-ui/public/locales/en/commons.json index cfa2032bdd..e6d8fb305e 100644 --- a/scm-ui/public/locales/en/commons.json +++ b/scm-ui/public/locales/en/commons.json @@ -32,5 +32,9 @@ "repositories": "Repositories", "users": "Users", "logout": "Logout" + }, + "paginator": { + "next": "Next", + "previous": "Previous" } } diff --git a/scm-ui/public/locales/en/users.json b/scm-ui/public/locales/en/users.json index 7f8e026fb9..2f8a225c2a 100644 --- a/scm-ui/public/locales/en/users.json +++ b/scm-ui/public/locales/en/users.json @@ -9,8 +9,10 @@ }, "users": { "title": "Users", - "subtitle": "Create, read, update and delete users", - "add-button": "Add User" + "subtitle": "Create, read, update and delete users" + }, + "create-user-button": { + "label": "Create" }, "delete-user-button": { "label": "Delete", diff --git a/scm-ui/src/components/Paginator.js b/scm-ui/src/components/Paginator.js new file mode 100644 index 0000000000..8eb56c243b --- /dev/null +++ b/scm-ui/src/components/Paginator.js @@ -0,0 +1,119 @@ +//@flow +import React from "react"; +import { translate } from "react-i18next"; +import type { PagedCollection } from "../types/Collection"; +import { Button } from "./buttons"; + +type Props = { + collection: PagedCollection, + onPageChange: string => void, + t: string => string +}; + +class Paginator extends React.Component { + isLinkUnavailable(linkType: string) { + return !this.props.collection || !this.props.collection._links[linkType]; + } + + createAction = (linkType: string) => () => { + const { collection, onPageChange } = this.props; + const link = collection._links[linkType].href; + onPageChange(link); + }; + + renderFirstButton() { + return this.renderPageButton(1, "first"); + } + + renderPreviousButton() { + return this.renderButton( + "pagination-previous", + "paginator.previous", + "prev" + ); + } + + renderNextButton() { + return this.renderButton("pagination-next", "paginator.next", "next"); + } + + renderLastButton() { + const { collection } = this.props; + return this.renderPageButton(collection.pageTotal, "last"); + } + + renderPageButton(page: number, linkType: string) { + return this.renderButton("pagination-link", page.toString(), linkType); + } + + renderButton(className: string, label: string, linkType: string) { + const { t } = this.props; + return ( +