Skip to content

Commit 2c0cce8

Browse files
authored
fix(ui) Going to a global saved search from a project based one (#12358)
Going from a project based saved search to a global one should retain the current global search so that users without global views don't get a backend error. Fixes SEN-251
1 parent 3ddd8ee commit 2c0cce8

File tree

2 files changed

+88
-18
lines changed

2 files changed

+88
-18
lines changed

src/sentry/static/sentry/app/views/organizationStream/overview.jsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ const DEFAULT_QUERY = 'is:unresolved';
4343
const DEFAULT_SORT = 'date';
4444
const DEFAULT_STATS_PERIOD = '24h';
4545
const STATS_PERIODS = new Set(['14d', '24h']);
46-
// TODO: Delete this after testing production counts cc/ @wedamija
47-
const NEW_FILTERS_TEST = 'use_new_filters';
4846

4947
const OrganizationStream = createReactClass({
5048
displayName: 'OrganizationStream',
@@ -261,12 +259,6 @@ const OrganizationStream = createReactClass({
261259
const currentQuery = this.props.location.query || {};
262260
if ('cursor' in currentQuery) {
263261
requestParams.cursor = currentQuery.cursor;
264-
} else if (NEW_FILTERS_TEST in currentQuery) {
265-
// TODO: Delete this after testing production counts cc/ @wedamija
266-
requestParams[NEW_FILTERS_TEST] = currentQuery[NEW_FILTERS_TEST];
267-
} else if (ConfigStore.get('user').isSuperuser) {
268-
// TODO: Delete this after testing production counts cc/ @wedamija
269-
requestParams[NEW_FILTERS_TEST] = 1;
270262
}
271263

272264
if (this.lastRequest) {
@@ -463,16 +455,19 @@ const OrganizationStream = createReactClass({
463455
if (savedSearch.projectId) {
464456
query.project = [savedSearch.projectId];
465457
}
458+
459+
// If the saved search is project-less and the user doesn't have
460+
// global-views we retain their current project filter
461+
// so that the backend doesn't reject their request.
462+
const hasMultipleProjectSelection = organization.features.includes('global-views');
463+
if (!savedSearch.projectId && !hasMultipleProjectSelection) {
464+
query.project = this.props.selection.projects;
465+
}
466466
} else {
467467
path = `/organizations/${organization.slug}/issues/`;
468468
}
469469

470470
if (path !== this.props.location.path && !isEqual(query, this.props.location.query)) {
471-
// TODO: Delete/revert this after testing production counts cc/ @wedamija
472-
if (this.props.location.query[NEW_FILTERS_TEST]) {
473-
query[NEW_FILTERS_TEST] = 1;
474-
}
475-
476471
browserHistory.push({
477472
pathname: path,
478473
query,

tests/js/spec/views/organizationStream/overview.spec.jsx

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const DEFAULT_LINKS_HEADER =
1212
'<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575731:0:0>; rel="next"; results="true"; cursor="1443575731:0:0';
1313

1414
describe('OrganizationStream', function() {
15-
let sandbox;
1615
let wrapper;
1716
let props;
1817

@@ -25,8 +24,6 @@ describe('OrganizationStream', function() {
2524
let fetchMembersRequest;
2625

2726
beforeEach(function() {
28-
sandbox = sinon.sandbox.create();
29-
3027
project = TestStubs.ProjectDetails({
3128
id: '3559',
3229
name: 'Foo Project',
@@ -81,7 +78,6 @@ describe('OrganizationStream', function() {
8178
body: [TestStubs.Member({projects: [project.slug]})],
8279
});
8380

84-
sandbox.stub(browserHistory, 'push');
8581
TagStore.init();
8682

8783
props = {
@@ -97,10 +93,89 @@ describe('OrganizationStream', function() {
9793
});
9894

9995
afterEach(function() {
100-
sandbox.restore();
10196
MockApiClient.clearMockResponses();
10297
});
10398

99+
describe('transitionTo', function() {
100+
let instance;
101+
beforeEach(function() {
102+
wrapper = shallow(<OrganizationStream {...props} />);
103+
instance = wrapper.instance();
104+
});
105+
106+
it('transitions to query updates', function() {
107+
instance.transitionTo({query: 'is:ignored'});
108+
109+
expect(browserHistory.push).toHaveBeenCalledWith({
110+
pathname: '/organizations/org-slug/issues/',
111+
query: {
112+
environment: [],
113+
project: [parseInt(project.id, 10)],
114+
query: 'is:ignored',
115+
statsPeriod: '14d',
116+
},
117+
});
118+
});
119+
120+
it('transitions to saved search that has a projectId', function() {
121+
savedSearch = {
122+
id: 123,
123+
projectId: 99,
124+
query: 'foo:bar',
125+
};
126+
instance.setState({savedSearch});
127+
instance.transitionTo();
128+
129+
expect(browserHistory.push).toHaveBeenCalledWith({
130+
pathname: '/organizations/org-slug/issues/searches/123/',
131+
query: {
132+
environment: [],
133+
project: [savedSearch.projectId],
134+
statsPeriod: '14d',
135+
},
136+
});
137+
});
138+
139+
it('goes to all projects when using a basic saved searches and global-views feature', function() {
140+
organization.features = ['global-views'];
141+
savedSearch = {
142+
id: 1,
143+
project: null,
144+
query: 'is:unresolved',
145+
};
146+
instance.setState({savedSearch});
147+
instance.transitionTo();
148+
149+
expect(browserHistory.push).toHaveBeenCalledWith({
150+
pathname: '/organizations/org-slug/issues/searches/1/',
151+
query: {
152+
environment: [],
153+
statsPeriod: '14d',
154+
},
155+
});
156+
});
157+
158+
it('retains project selection when using a basic saved search and no global-views feature', function() {
159+
organization.features = [];
160+
savedSearch = {
161+
id: 1,
162+
projectId: null,
163+
query: 'is:unresolved',
164+
};
165+
instance.setState({savedSearch});
166+
instance.transitionTo();
167+
168+
expect(browserHistory.push).toHaveBeenCalledWith({
169+
pathname: '/organizations/org-slug/issues/searches/1/',
170+
query: {
171+
environment: [],
172+
project: props.selection.projects,
173+
statsPeriod: '14d',
174+
},
175+
});
176+
});
177+
});
178+
104179
describe('getEndpointParams', function() {
105180
beforeEach(function() {
106181
wrapper = shallow(<OrganizationStream {...props} />);

0 commit comments

Comments
 (0)