diff --git a/awx/ui_next/src/components/PaginatedDataList/PaginatedDataList.jsx b/awx/ui_next/src/components/PaginatedDataList/PaginatedDataList.jsx index f273971034..466b006ea2 100644 --- a/awx/ui_next/src/components/PaginatedDataList/PaginatedDataList.jsx +++ b/awx/ui_next/src/components/PaginatedDataList/PaginatedDataList.jsx @@ -38,7 +38,15 @@ class PaginatedDataList extends React.Component { this.handleSort = this.handleSort.bind(this); } - getSortOrder() { + componentDidUpdate(prevProps) { + const { itemCount: prevItemCount } = prevProps; + const { itemCount } = this.props + if (prevItemCount !== itemCount) { + this.getCurrPage(itemCount); + } + } + + getSortOrder () { const { qsConfig, location } = this.props; const queryParams = parseNamespacedQueryString(qsConfig, location.search); if (queryParams.order_by && queryParams.order_by.startsWith('-')) { @@ -47,7 +55,20 @@ class PaginatedDataList extends React.Component { return [queryParams.order_by, 'ascending']; } - handleSetPage(event, pageNumber) { + getCurrPage (itemCount) { + if (itemCount < 0) { + return; + } + const { qsConfig, location } = this.props; + const queryParams = parseNamespacedQueryString(qsConfig, location.search); + const maxPages = Math.ceil(itemCount / queryParams.page_size); + const currPage = queryParams.page; + if (currPage > maxPages) { + this.pushHistoryState({ page: (currPage + (maxPages - currPage)) || 1 }) + } + } + + handleSetPage (event, pageNumber) { this.pushHistoryState({ page: pageNumber }); } diff --git a/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx b/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx index fb07b0e7f1..3819601803 100644 --- a/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx +++ b/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx @@ -75,12 +75,13 @@ class OrganizationsList extends Component { this.setState({ deletionError: null }); } - async handleOrgDelete() { - const { selected } = this.state; + async handleOrgDelete () { + const { selected, itemCount } = this.state; this.setState({ hasContentLoading: true }); try { - await Promise.all(selected.map(org => OrganizationsAPI.destroy(org.id))); + await Promise.all(selected.map((org) => OrganizationsAPI.destroy(org.id))); + this.setState({ itemCount: itemCount - selected.length }); } catch (err) { this.setState({ deletionError: err }); } finally {