Browse Source

fix(ui): Update localstorage when project is deleted (#29104)

* fix(ui): Update localstorage when project is deleted

Update localStorage when a project is deleted. Previously, the project ID would still be in localStorage causing a 403 from several endpoints on the issue list page.

FIXES WOR-1384

* refactor: update as function

* add test
Kelly Carino 3 years ago
parent
commit
c5ee03be2a

+ 14 - 1
static/app/components/organizations/globalSelectionHeader/utils.tsx

@@ -4,10 +4,15 @@ import isEqual from 'lodash/isEqual';
 import pick from 'lodash/pick';
 import pickBy from 'lodash/pickBy';
 
-import {DATE_TIME_KEYS, URL_PARAM} from 'app/constants/globalSelectionHeader';
+import {
+  DATE_TIME_KEYS,
+  LOCAL_STORAGE_KEY,
+  URL_PARAM,
+} from 'app/constants/globalSelectionHeader';
 import {GlobalSelection} from 'app/types';
 import {defined} from 'app/utils';
 import {getUtcToLocalDateObject} from 'app/utils/dates';
+import localStorage from 'app/utils/localStorage';
 
 import {getParams} from './getParams';
 
@@ -117,3 +122,11 @@ export function isSelectionEqual(
   }
   return true;
 }
+
+/**
+ * Removes globalselection from localstorage
+ */
+export function removeGlobalSelectionStorage(orgId) {
+  const localStorageKey = `${LOCAL_STORAGE_KEY}:${orgId}`;
+  localStorage.removeItem(localStorageKey);
+}

+ 4 - 0
static/app/views/settings/projectGeneralSettings.tsx

@@ -9,6 +9,7 @@ import {
 import ProjectActions from 'app/actions/projectActions';
 import Button from 'app/components/button';
 import Confirm from 'app/components/confirm';
+import {removeGlobalSelectionStorage} from 'app/components/organizations/globalSelectionHeader/utils';
 import {Panel, PanelAlert, PanelHeader} from 'app/components/panels';
 import {fields} from 'app/data/forms/projectGeneralSettings';
 import {t, tct} from 'app/locale';
@@ -59,6 +60,9 @@ class ProjectGeneralSettings extends AsyncView<Props, State> {
   handleRemoveProject = () => {
     const {orgId} = this.props.params;
     const project = this.state.data;
+
+    removeGlobalSelectionStorage(orgId);
+
     if (!project) {
       return;
     }

+ 4 - 0
tests/js/spec/views/settings/projectGeneralSettings.spec.jsx

@@ -5,11 +5,13 @@ import {mountGlobalModal} from 'sentry-test/modal';
 import {selectByValue} from 'sentry-test/select-new';
 
 import {addErrorMessage, addSuccessMessage} from 'app/actionCreators/indicator';
+import {removeGlobalSelectionStorage} from 'app/components/organizations/globalSelectionHeader/utils';
 import ProjectsStore from 'app/stores/projectsStore';
 import ProjectContext from 'app/views/projects/projectContext';
 import ProjectGeneralSettings from 'app/views/settings/projectGeneralSettings';
 
 jest.mock('app/actionCreators/indicator');
+jest.mock('app/components/organizations/globalSelectionHeader/utils');
 
 describe('projectGeneralSettings', function () {
   const org = TestStubs.Organization();
@@ -136,6 +138,8 @@ describe('projectGeneralSettings', function () {
     modal.find('Button[priority="danger"]').simulate('click');
 
     expect(deleteMock).toHaveBeenCalled();
+
+    expect(removeGlobalSelectionStorage).toHaveBeenCalledWith('org-slug');
   });
 
   it('project admins can transfer project', async function () {