Skip to content

Commit

Permalink
fix(custom-views): Fix unsaved changes not triggering correctly (#76869)
Browse files Browse the repository at this point in the history
This PR fixes an issue with unsaved changes where manually changing a
view's search query from unsaved changes back to the original query
would result in the unsaved changes indicator still appearing. If the
query matches the views existing query, it should always show up as not
having unsaved changes.
  • Loading branch information
MichaelSun48 committed Sep 3, 2024
1 parent 5b40e6e commit abf397d
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions static/app/views/issueList/customViewsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,30 +181,26 @@ function CustomViewsIssueListHeaderTabsContent({
if (viewId) {
const selectedTab = draggableTabs.find(tab => tab.id === viewId);
if (selectedTab && query && sort) {
// if a viewId exists but the query and sort are not what we expected, set them as unsaved changes
const isCurrentQuerySortDifferentFromExistingUnsavedChanges =
selectedTab.unsavedChanges &&
(selectedTab.unsavedChanges[0] !== query ||
selectedTab.unsavedChanges[1] !== sort);
const issueSortOption = Object.values(IssueSortOptions).includes(sort)
? sort
: IssueSortOptions.DATE;

const isCurrentQuerySortDifferentFromSelectedTabQuerySort =
query !== selectedTab.query || sort !== selectedTab.querySort;
const unsavedChanges: [string, IssueSortOptions] | undefined =
query === selectedTab.query && sort === selectedTab.querySort
? undefined
: [query as string, issueSortOption];

setDraggableTabs(
draggableTabs.map(tab =>
tab.key === selectedTab!.key
? {
...tab,
unsavedChanges,
}
: tab
)
);

if (
isCurrentQuerySortDifferentFromExistingUnsavedChanges ||
isCurrentQuerySortDifferentFromSelectedTabQuerySort
) {
setDraggableTabs(
draggableTabs.map(tab =>
tab.key === selectedTab!.key
? {
...tab,
unsavedChanges: [query, sort],
}
: tab
)
);
}
tabListState?.setSelectedKey(selectedTab.key);
return;
}
Expand Down

0 comments on commit abf397d

Please sign in to comment.