Browse Source

fix(ui): Fix Project Chooser from settings (#8980)

This changes setLastRoute to save query string.

Fixes JAVASCRIPT-33C
Billy Vong 6 years ago
parent
commit
1c802d2361

+ 3 - 1
src/sentry/static/sentry/app/views/organizationRoot.jsx

@@ -15,8 +15,10 @@ class OrganizationRoot extends React.Component {
     setActiveProject(null);
   }
   componentWillUnmount() {
+    let {location} = this.props;
+    let {pathname, search} = location;
     // Save last route so that we can jump back to view from settings
-    setLastRoute(this.props.location.pathname);
+    setLastRoute(`${pathname}${search || ''}`);
   }
 
   render() {

+ 3 - 3
src/sentry/static/sentry/app/views/projectChooser.jsx

@@ -37,12 +37,12 @@ const ProjectChooser = createReactClass({
     let org = this.getOrganization();
     let projects = org.projects;
     let tasks = TodoList.TASKS.filter(
-      task_inst => task_inst.task == this.props.location.query.task
+      task_inst => task_inst.task === this.props.location.query.task
     );
 
     if (projects.length === 0) {
       browserHistory.push(`/organizations/${org.slug}/projects/new/`);
-    } else if (projects.length === 1 && tasks.length === 1) {
+    } else if (projects.length === 1 && tasks && tasks.length === 1) {
       let project = projects[0];
       browserHistory.push(`/${org.slug}/${project.slug}/${tasks[0].location}`);
     }
@@ -56,7 +56,7 @@ const ProjectChooser = createReactClass({
 
     // Expect onboarding=1 and task=<task id> parameters and task.featureLocation == 'project'
     // TODO throw up report dialog if not true
-    if (task.featureLocation != 'project') {
+    if (!task || task.featureLocation !== 'project') {
       throw new Error('User arrived on project chooser without a valid task id.');
     }
     return (

+ 3 - 1
src/sentry/static/sentry/app/views/projectDetailsLayout.jsx

@@ -27,8 +27,10 @@ const ProjectDetailsLayout = createReactClass({
   },
 
   componentWillUnmount() {
+    let {location} = this.props;
+    let {pathname, search} = location;
     // Save last route so that we can jump back to view from settings
-    setLastRoute(this.props.location.pathname);
+    setLastRoute(`${pathname}${search || ''}`);
   },
 
   /**

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

@@ -31,4 +31,16 @@ describe('OrganizationRoot', function() {
 
     expect(setLastRoute).toHaveBeenCalledWith('/org-slug/dashboard/');
   });
+
+  it('calls `setLastRoute` when unmounted with query string', function() {
+    let wrapper = mount(
+      <OrganizationRoot location={{pathname: '/org-slug/dashboard/', search: '?test=1'}}>
+        {null}
+      </OrganizationRoot>
+    );
+
+    wrapper.unmount();
+
+    expect(setLastRoute).toHaveBeenCalledWith('/org-slug/dashboard/?test=1');
+  });
 });