Skip to content

Commit c604f00

Browse files
authored
fix(dashboards): Invalidate the sidebar on favorite action (#96556)
When favoriting from the dashboard specifically, we aren't invalidating the sidebar cache so it wasn't updating. Previously this hardcoded the old endpoint, but now that I have a helper that gives the starred dashboard key, I've imported it and changed the helper to pass along `organization` to do the feature flag check and invalidate the query for the sidebar.
1 parent 68dfeb8 commit c604f00

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

static/app/actionCreators/dashboards.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
66
import {t} from 'sentry/locale';
77
import PageFiltersStore from 'sentry/stores/pageFiltersStore';
88
import type {PageFilters} from 'sentry/types/core';
9+
import type {Organization} from 'sentry/types/organization';
910
import {defined} from 'sentry/utils';
1011
import {TOP_N} from 'sentry/utils/discover/types';
1112
import type {QueryClient} from 'sentry/utils/queryClient';
13+
import {getQueryKey} from 'sentry/views/dashboards/hooks/useGetStarredDashboards';
1214
import {
1315
type DashboardDetails,
1416
type DashboardListItem,
@@ -105,13 +107,13 @@ export function updateDashboardVisit(
105107
export async function updateDashboardFavorite(
106108
api: Client,
107109
queryClient: QueryClient,
108-
orgId: string,
110+
organization: Organization,
109111
dashboardId: string | string[],
110112
isFavorited: boolean
111113
): Promise<void> {
112114
try {
113115
await api.requestPromise(
114-
`/organizations/${orgId}/dashboards/${dashboardId}/favorite/`,
116+
`/organizations/${organization.slug}/dashboards/${dashboardId}/favorite/`,
115117
{
116118
method: 'PUT',
117119
data: {
@@ -120,10 +122,7 @@ export async function updateDashboardFavorite(
120122
}
121123
);
122124
queryClient.invalidateQueries({
123-
queryKey: [
124-
`/organizations/${orgId}/dashboards/`,
125-
{query: {filter: 'onlyFavorites'}},
126-
],
125+
queryKey: getQueryKey(organization),
127126
});
128127
addSuccessMessage(isFavorited ? t('Added as favorite') : t('Removed as favorite'));
129128
} catch (response) {

static/app/views/dashboards/controls.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function Controls({
217217
await updateDashboardFavorite(
218218
api,
219219
queryClient,
220-
organization.slug,
220+
organization,
221221
dashboard.id,
222222
!isFavorited
223223
);

static/app/views/dashboards/manage/dashboardGrid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function DashboardGrid({
7474
await updateDashboardFavorite(
7575
api,
7676
queryClient,
77-
organization.slug,
77+
organization,
7878
dashboard.id,
7979
isFavorited
8080
);

static/app/views/dashboards/manage/dashboardTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function FavoriteButton({
9898
await updateDashboardFavorite(
9999
api,
100100
queryClient,
101-
organization.slug,
101+
organization,
102102
dashboardId,
103103
!favorited
104104
);

static/app/views/dashboards/manage/tableView/table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function DashboardTable({
106106
await updateDashboardFavorite(
107107
api,
108108
queryClient,
109-
organization.slug,
109+
organization,
110110
dashboard.id,
111111
!dashboard.isFavorited
112112
);

0 commit comments

Comments
 (0)