Skip to content

Commit

Permalink
feat(dashboards): add pin favorites as parameter to endpoint (#81814)
Browse files Browse the repository at this point in the history
Add `pin: favourites` as parameter to dashboards list endpoint. This
will result in the favourite dashboards always showing up first in the
dashboards grid and table view.

Related backend change: #81811
Issue: #78023
  • Loading branch information
harshithadurai authored Dec 10, 2024
1 parent 95a99ea commit 708696a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions static/app/views/dashboards/manage/dashboardGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function DashboardGrid({
async function handleFavorite(dashboard: DashboardListItem, isFavorited: boolean) {
try {
await updateDashboardFavorite(api, organization.slug, dashboard.id, isFavorited);
onDashboardsChange();
} catch (error) {
throw error;
}
Expand Down
5 changes: 5 additions & 0 deletions static/app/views/dashboards/manage/dashboardTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type FavoriteButtonProps = {
api: Client;
dashboardId: string;
isFavorited: boolean;
onDashboardsChange: () => void;
organization: Organization;
};

Expand All @@ -68,6 +69,7 @@ function FavoriteButton({
api,
organization,
dashboardId,
onDashboardsChange,
}: FavoriteButtonProps) {
const [favorited, setFavorited] = useState(isFavorited);
return (
Expand All @@ -93,6 +95,7 @@ function FavoriteButton({
dashboardId,
!favorited
);
onDashboardsChange();
} catch (error) {
// If the api call fails, revert the state
setFavorited(favorited);
Expand Down Expand Up @@ -177,6 +180,8 @@ function DashboardTable({
api={api}
organization={organization}
dashboardId={dataRow.id}
onDashboardsChange={onDashboardsChange}
key={dataRow.id}
/>
);
}
Expand Down
3 changes: 3 additions & 0 deletions static/app/views/dashboards/manage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ function ManageDashboards() {
query: {
...pick(location.query, ['cursor', 'query']),
sort: getActiveSort().value,
...(organization.features.includes('dashboards-favourite')
? {pin: 'favorites'}
: {}),
per_page:
dashboardsLayout === GRID ? rowCount * columnCount : DASHBOARD_TABLE_NUM_ROWS,
},
Expand Down

0 comments on commit 708696a

Please sign in to comment.