Browse Source

ref(js): Remove unused LatestContextStore.lastRoute (#30815)

Evan Purkhiser 3 years ago
parent
commit
39f7032080

+ 0 - 5
static/app/actionCreators/navigation.tsx

@@ -2,7 +2,6 @@ import {InjectedRouter} from 'react-router';
 import {Location} from 'history';
 
 import {openModal} from 'sentry/actionCreators/modal';
-import NavigationActions from 'sentry/actions/navigationActions';
 import ContextPickerModal from 'sentry/components/contextPickerModal';
 import ProjectsStore from 'sentry/stores/projectsStore';
 
@@ -46,7 +45,3 @@ export function navigateTo(
       : router.push(to);
   }
 }
-
-export function setLastRoute(route: string) {
-  NavigationActions.setLastRoute(route);
-}

+ 0 - 5
static/app/actions/navigationActions.tsx

@@ -1,5 +0,0 @@
-import Reflux from 'reflux';
-
-const NavigationActions = Reflux.createActions(['setLastRoute']);
-
-export default NavigationActions;

+ 0 - 15
static/app/stores/latestContextStore.tsx

@@ -1,6 +1,5 @@
 import Reflux from 'reflux';
 
-import NavigationActions from 'sentry/actions/navigationActions';
 import OrganizationActions from 'sentry/actions/organizationActions';
 import OrganizationsActions from 'sentry/actions/organizationsActions';
 import ProjectActions from 'sentry/actions/projectActions';
@@ -13,14 +12,12 @@ type State = {
   lastProject: Project | null;
   organization: OrgTypes;
   environment: string | string[] | null;
-  lastRoute: string | null;
 };
 
 type LatestContextStoreInterface = {
   state: State;
   reset(): void;
   get(): State;
-  onSetLastRoute(route: string): void;
   onUpdateOrganization(organization: OrgTypes): void;
   onSetActiveOrganization(organization: OrgTypes): void;
   onSetActiveProject(project: Project | null): void;
@@ -41,7 +38,6 @@ const storeConfig: Reflux.StoreDefinition & LatestContextStoreInterface = {
     lastProject: null,
     organization: null,
     environment: null,
-    lastRoute: null,
   },
 
   get() {
@@ -55,7 +51,6 @@ const storeConfig: Reflux.StoreDefinition & LatestContextStoreInterface = {
     this.listenTo(OrganizationsActions.setActive, this.onSetActiveOrganization);
     this.listenTo(OrganizationsActions.update, this.onUpdateOrganization);
     this.listenTo(OrganizationActions.update, this.onUpdateOrganization);
-    this.listenTo(NavigationActions.setLastRoute, this.onSetLastRoute);
   },
 
   reset() {
@@ -64,20 +59,10 @@ const storeConfig: Reflux.StoreDefinition & LatestContextStoreInterface = {
       lastProject: null,
       organization: null,
       environment: null,
-      lastRoute: null,
     };
     return this.state;
   },
 
-  onSetLastRoute(route) {
-    this.state = {
-      ...this.state,
-      lastRoute: route,
-    };
-
-    this.trigger(this.state);
-  },
-
   onUpdateOrganization(org) {
     // Don't do anything if base/target orgs are falsey
     if (!this.state.organization) {

+ 0 - 1
static/app/utils/__mocks__/withLatestContext.tsx

@@ -7,7 +7,6 @@ const DEFAULTS = {
   organization: MOCK_ORG,
   organizations: [MOCK_ORG],
   project: TestStubs.Project(),
-  lastRoute: '',
 };
 
 const withLatestContextMock = WrappedComponent =>

+ 1 - 4
static/app/utils/withLatestContext.tsx

@@ -10,7 +10,6 @@ type InjectedLatestContextProps = {
   organizations?: OrganizationSummary[];
   organization?: Organization | null;
   project?: Project | null;
-  lastRoute?: string | null;
 };
 
 type HocProps = {
@@ -25,7 +24,6 @@ type State = {
 const fallbackContext: State['latestContext'] = {
   organization: null,
   project: null,
-  lastRoute: null,
 };
 
 function withLatestContext<P extends InjectedLatestContextProps>(
@@ -52,7 +50,7 @@ function withLatestContext<P extends InjectedLatestContextProps>(
     render() {
       const {organizations} = this.props;
       const {latestContext} = this.state;
-      const {organization, project, lastRoute} = latestContext || fallbackContext;
+      const {organization, project} = latestContext || fallbackContext;
 
       // Even though org details exists in LatestContextStore,
       // fetch organization from OrganizationsStore so that we can
@@ -71,7 +69,6 @@ function withLatestContext<P extends InjectedLatestContextProps>(
       return (
         <WrappedComponent
           project={project as Project}
-          lastRoute={lastRoute}
           {...(this.props as P)}
           organization={(this.props.organization || latestOrganization) as Organization}
         />

+ 4 - 10
static/app/views/organizationRoot.tsx

@@ -1,10 +1,8 @@
 import {Fragment, useEffect} from 'react';
-import {withRouter, WithRouterProps} from 'react-router';
 
-import {setLastRoute} from 'sentry/actionCreators/navigation';
 import {setActiveProject} from 'sentry/actionCreators/projects';
 
-type Props = WithRouterProps & {children: React.ReactChildren};
+type Props = {children: React.ReactChildren};
 
 /**
  * This is the parent container for organization-level views such
@@ -12,14 +10,10 @@ type Props = WithRouterProps & {children: React.ReactChildren};
  *
  * Currently is just used to unset active project
  */
-function OrganizationRoot({children, location}: Props) {
-  useEffect(() => {
-    setActiveProject(null);
-
-    return () => setLastRoute(`${location.pathname}${location.search ?? ''}`);
-  }, []);
+function OrganizationRoot({children}: Props) {
+  useEffect(() => void setActiveProject(null), []);
 
   return <Fragment>{children}</Fragment>;
 }
 
-export default withRouter(OrganizationRoot);
+export default OrganizationRoot;

+ 0 - 29
tests/js/spec/views/organizationRoot.spec.jsx

@@ -1,6 +1,5 @@
 import {mountWithTheme} from 'sentry-test/reactTestingLibrary';
 
-import {setLastRoute} from 'sentry/actionCreators/navigation';
 import {setActiveProject} from 'sentry/actionCreators/projects';
 import OrganizationRoot from 'sentry/views/organizationRoot';
 
@@ -8,38 +7,10 @@ jest.mock('sentry/actionCreators/projects', () => ({
   setActiveProject: jest.fn(),
 }));
 
-jest.mock('sentry/actionCreators/navigation', () => ({
-  setLastRoute: jest.fn(),
-}));
-
 describe('OrganizationRoot', function () {
   it('sets active project as null when mounted', function () {
     mountWithTheme(<OrganizationRoot location={{}}>{null}</OrganizationRoot>);
 
     expect(setActiveProject).toHaveBeenCalledWith(null);
   });
-
-  it('calls `setLastRoute` when unmounted', function () {
-    const {unmount} = mountWithTheme(
-      <OrganizationRoot location={{pathname: '/org-slug/dashboard/'}}>
-        {null}
-      </OrganizationRoot>
-    );
-
-    unmount();
-
-    expect(setLastRoute).toHaveBeenCalledWith('/org-slug/dashboard/');
-  });
-
-  it('calls `setLastRoute` when unmounted with query string', function () {
-    const {unmount} = mountWithTheme(
-      <OrganizationRoot location={{pathname: '/org-slug/dashboard/', search: '?test=1'}}>
-        {null}
-      </OrganizationRoot>
-    );
-
-    unmount();
-
-    expect(setLastRoute).toHaveBeenCalledWith('/org-slug/dashboard/?test=1');
-  });
 });