Skip to content

Commit 282f05a

Browse files
authored
feat(dashboards): Use starred endpoint for ordered dashboards (#94810)
This endpoint returns starred dashboards in order of position. It uses the same serializer so the handling of the response does not need to change. In the backend, behind the scenes, it also backfills in position data from the original sorting if there are no positions set yet (i.e. it'll order by title)
1 parent c04feb3 commit 282f05a

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1+
import type {Organization} from 'sentry/types/organization';
2+
import type {ApiQueryKey} from 'sentry/utils/queryClient';
13
import {useApiQuery} from 'sentry/utils/queryClient';
24
import useOrganization from 'sentry/utils/useOrganization';
35
import type {DashboardListItem} from 'sentry/views/dashboards/types';
46

7+
function getQueryKey(organization: Organization): ApiQueryKey {
8+
const DASHBOARDS_QUERY_KEY = [
9+
`/organizations/${organization.slug}/dashboards/`,
10+
{
11+
query: {
12+
filter: 'onlyFavorites',
13+
},
14+
},
15+
] as const;
16+
const STARRED_DASHBOARDS_QUERY_KEY = [
17+
`/organizations/${organization.slug}/dashboards/starred/`,
18+
{},
19+
] as const;
20+
return organization.features.includes('dashboards-starred-reordering')
21+
? STARRED_DASHBOARDS_QUERY_KEY
22+
: DASHBOARDS_QUERY_KEY;
23+
}
24+
525
export function useGetStarredDashboards() {
626
const organization = useOrganization();
7-
return useApiQuery<DashboardListItem[]>(
8-
[
9-
`/organizations/${organization.slug}/dashboards/`,
10-
{
11-
query: {
12-
filter: 'onlyFavorites',
13-
},
14-
},
15-
],
16-
{
17-
staleTime: Infinity,
18-
}
19-
);
27+
return useApiQuery<DashboardListItem[]>(getQueryKey(organization), {
28+
staleTime: Infinity,
29+
});
2030
}

0 commit comments

Comments
 (0)