Fix Org list returning a 404 by redirecting user to current page.

- Update itemCount after an org has been successfully deleted.
- Update PaginatedDataList to get current page when the number of items has changed.
This commit is contained in:
Kia Lam 2019-07-01 10:55:11 -04:00
parent 7178c1d9e0
commit 58444a75b9
No known key found for this signature in database
GPG Key ID: 294F9BE53C241D03
2 changed files with 27 additions and 5 deletions

View File

@ -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 });
}

View File

@ -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 {