From abf397ded9187c6de805734b6815839f12c702b7 Mon Sep 17 00:00:00 2001 From: Michael Sun <55160142+MichaelSun48@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:19:19 -0400 Subject: [PATCH] fix(custom-views): Fix unsaved changes not triggering correctly (#76869) 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. --- .../app/views/issueList/customViewsHeader.tsx | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/static/app/views/issueList/customViewsHeader.tsx b/static/app/views/issueList/customViewsHeader.tsx index 5807d674b34f37..24d9a13d238e21 100644 --- a/static/app/views/issueList/customViewsHeader.tsx +++ b/static/app/views/issueList/customViewsHeader.tsx @@ -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; }