Skip to content

Commit

Permalink
fix(issue-views): Fix query being overwritten on refresh of default t…
Browse files Browse the repository at this point in the history
…ab (#78793)

Fixes an issue where attempting to navigate to a predefined query with
only a default tab would redirect you to the first tab and overwrite the
original query.
  • Loading branch information
MichaelSun48 authored Oct 9, 2024
1 parent ba002f8 commit 146cdc5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
47 changes: 47 additions & 0 deletions static/app/views/issueList/customViewsHeader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,53 @@ describe('CustomViewsHeader', () => {
})
);
});

it('updates the unsaved changes indicator for a default tab if the query is different', async () => {
MockApiClient.clearMockResponses();
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/group-search-views/`,
method: 'GET',
body: [
{
name: 'Prioritized',
query: 'is:unresolved issue.priority:[high, medium]',
querySort: IssueSortOptions.DATE,
},
],
});

const defaultTabDifferentQueryRouter = RouterFixture({
location: LocationFixture({
pathname: `/organizations/${organization.slug}/issues/`,
query: {
query: 'is:unresolved',
viewId: 'default0',
},
}),
});

render(
<CustomViewsIssueListHeader
{...defaultProps}
router={defaultTabDifferentQueryRouter}
/>,
{
router: defaultTabDifferentQueryRouter,
}
);
expect(await screen.findByRole('tab', {name: 'Prioritized'})).toBeInTheDocument();
expect(screen.getByTestId('unsaved-changes-indicator')).toBeInTheDocument();
expect(screen.queryByRole('tab', {name: 'Unsaved'})).not.toBeInTheDocument();

expect(defaultTabDifferentQueryRouter.replace).toHaveBeenCalledWith(
expect.objectContaining({
query: expect.objectContaining({
query: 'is:unresolved',
viewId: 'default0',
}),
})
);
});
});

describe('CustomViewsHeader query behavior', () => {
Expand Down
9 changes: 0 additions & 9 deletions static/app/views/issueList/customViewsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,6 @@ function CustomViewsIssueListHeaderTabsContent({
);

const getInitialTabKey = () => {
if (draggableTabs[0].key.startsWith('default')) {
if (query) {
return TEMPORARY_TAB_KEY;
}
return draggableTabs[0].key;
}
if (!query && !sort && !viewId) {
return draggableTabs[0].key;
}
if (viewId && draggableTabs.find(tab => tab.id === viewId)) {
return draggableTabs.find(tab => tab.id === viewId)!.key;
}
Expand Down

0 comments on commit 146cdc5

Please sign in to comment.