more concise conditions for api calls

This commit is contained in:
Alex Corey 2019-07-03 16:16:09 -04:00
parent 320581a6c0
commit 3b17170533
3 changed files with 12 additions and 5 deletions

View File

@ -43,8 +43,15 @@ class Organization extends Component {
async componentDidUpdate(prevProps) {
const { location, match } = this.props;
const url = `/organizations/${match.params.id}/`;
const shouldUpdate = prevProps.location.pathname.includes(url);
if (location !== prevProps.location && shouldUpdate) {
const tabs = ['details', 'access', 'teams', 'notifications', 'edit'].map(
tab => `${url}${tab}`
);
const didNavigateFromTab = tabs.includes(prevProps.location.pathname);
if (
prevProps.location !== location &&
didNavigateFromTab &&
location.pathname === `${url}details`
) {
await this.loadOrganization();
}
}

View File

@ -38,7 +38,7 @@ class OrganizationEdit extends Component {
organization: { id },
history,
} = this.props;
history.push(`/organizations/${id}`);
history.push(`/organizations/${id}/details`);
}
handleSuccess() {
@ -46,7 +46,7 @@ class OrganizationEdit extends Component {
organization: { id },
history,
} = this.props;
history.push(`/organizations/${id}`);
history.push(`/organizations/${id}/details`);
}
async submitInstanceGroups(groupsToAssociate, groupsToDisassociate) {

View File

@ -76,6 +76,6 @@ describe('<OrganizationEdit />', () => {
expect(history.push).not.toHaveBeenCalled();
wrapper.find('button[aria-label="Cancel"]').prop('onClick')();
expect(history.push).toHaveBeenCalledWith('/organizations/1');
expect(history.push).toHaveBeenCalledWith('/organizations/1/details');
});
});