diff --git a/scm-ui/src/groups/containers/Groups.js b/scm-ui/src/groups/containers/Groups.js index 11d60f66c4..ea8f2c6cd3 100644 --- a/scm-ui/src/groups/containers/Groups.js +++ b/scm-ui/src/groups/containers/Groups.js @@ -5,11 +5,13 @@ import { translate } from "react-i18next"; import type { Group } from "@scm-manager/ui-types"; import type { PagedCollection } from "@scm-manager/ui-types"; import type { History } from "history"; +import queryString from "query-string"; import { Page, PageActions, Button, - Paginator + LinkPaginator, + getPageFromMatch } from "@scm-manager/ui-components"; import { GroupTable } from "./../components/table"; import CreateGroupButton from "../components/buttons/CreateGroupButton"; @@ -24,6 +26,7 @@ import { selectListAsCollection } from "../modules/groups"; import { getGroupsLink } from "../../modules/indexResource"; +import { compose } from "redux"; type Props = { groups: Group[], @@ -37,37 +40,47 @@ type Props = { // context objects t: string => string, history: History, + location: any, // dispatch functions - fetchGroupsByPage: (link: string, page: number, filter?: string) => void, + fetchGroupsByPage: (link: string, page: number, filter?: any) => void, fetchGroupsByLink: (link: string) => void }; -class Groups extends React.Component { - componentDidMount() { - this.props.fetchGroupsByPage(this.props.groupLink, this.props.page); +type State = { + page: number +}; + +class Groups extends React.Component { + constructor(props: Props) { + super(props); + + this.state = { + page: -1 + }; } - onPageChange = (link: string) => { - this.props.fetchGroupsByLink(link); - }; + componentDidMount() { + const { fetchGroupsByPage, groupLink, page } = this.props; + fetchGroupsByPage(groupLink, page, this.getQueryString()); + this.setState({ page: page }); + } - /** - * reflect page transitions in the uri - */ componentDidUpdate = (prevProps: Props) => { - const { page, list } = this.props; - if (list.page >= 0) { - // backend starts paging by 0 - const statePage: number = list.page + 1; - if (page !== statePage) { - this.props.history.push(`/groups/${statePage}`); + const { list, page, location, fetchGroupsByPage, groupLink } = this.props; + if (list && page) { + if ( + page !== this.state.page || + prevProps.location.search !== location.search + ) { + fetchGroupsByPage(groupLink, page, this.getQueryString()); + this.setState({ page: page }); } } }; render() { - const { groups, loading, error, t } = this.props; + const { groups, loading, error, history, t } = this.props; return ( { loading={loading || !groups} error={error} filter={filter => { - this.props.fetchGroupsByPage(this.props.groupLink, this.props.page, filter); + history.push("/groups/?q=" + filter); }} > @@ -86,60 +99,57 @@ class Groups extends React.Component { ); } - renderPaginator() { - const { list } = this.props; + renderPaginator = () => { + const { list, page } = this.props; if (list) { - return ; + return ( + + ); + } + return null; + }; + + renderCreateButton() { + if (this.props.canAddGroups) { + return ; } return null; } - renderCreateButton() { - if (this.props.canAddGroups) { - return ( - - ); - } else { - return; - } - } - renderPageActionCreateButton() { - if (this.props.canAddGroups) { + const { canAddGroups, t } = this.props; + if (canAddGroups) { return (