Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashboards): add new endpoint for favourite dashboards #81438

Merged
merged 15 commits into from
Dec 3, 2024

Conversation

harshithadurai
Copy link
Contributor

@harshithadurai harshithadurai commented Nov 28, 2024

  1. Add new endpoint for favouriting dashboards (supports PUT req)
  2. Return isFavourite field in DashboardDetails endpoint's GET request

#78023

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 28, 2024
@@ -252,6 +254,7 @@ def serialize(self, obj, attrs, user, **kwargs) -> DashboardListResponse:
"widgetDisplay": attrs.get("widget_display", []),
"widgetPreview": attrs.get("widget_preview", []),
"permissions": serialize(obj.permissions) if hasattr(obj, "permissions") else None,
"isFavourited": user.id in obj.favourited_by,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: what happens when favourited_by doesn't exist in dashboard obj

This comment was marked as outdated.

Comment on lines 234 to 239
if is_favourited and request.user.id not in current_favourites:
current_favourites.add(request.user.id) # Add user to the set
elif not is_favourited and request.user.id in current_favourites:
current_favourites.remove(request.user.id)
else:
Response(status=204)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conditions:
not fav, not in list -> do nothing
not fav, in lits -> remove frm list
in fav, in list -> do nothing
in fav, not in list -> add to list

@harshithadurai harshithadurai marked this pull request as ready for review December 2, 2024 16:16
@harshithadurai harshithadurai requested review from a team as code owners December 2, 2024 16:16
"GET": ApiPublishStatus.PRIVATE,
}

def get(self, request: Request, organization, dashboard) -> Response:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support GET on this endpoint? I thought we wanted to add isFavourited to the dashboard list endpoints, that way we get the value in one call. If we expect to call this endpoint to get the favourite status, we'll make one call for each dashboard result which is an N+1 performance issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is just to support test validation, we can just check the database values in our tests and once we get support in the dashboard serializers, we can mock the value and show that it's exposed properly

Copy link
Contributor Author

@harshithadurai harshithadurai Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was to use this when displaying the favourite status for an individual dashboard endpoint which will be used for the star here:
Screenshot 2024-12-02 at 1 53 29 PM

And the PUT request is used when clicking on the star

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, should I just add it to the GET of the dashboard details endpoint?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we should just include it in the GET for dashboard details so we can cut down on the number of requests (we're already querying the dashboard with that request anyways). It'll just be ignored in the endpoint when there are updates

Comment on lines +231 to +232
if isinstance(dashboard, dict):
return Response(status=204)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to handle prebuilt dashboards? Our implementation of prebuilt dashboard is a little wonky on the backend, and it doesn't seem like this block actually sets up any relationships. Can we make it so prebuilt ones aren't favouritable, or otherwise we'll have to do something to actually handle favouriting those

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, it was for the pre-built dashboards. Would it make sense to keep this check in the GET and PUT methods, and not render the favourite option in the frontend? So, favouriting pre-built dashboards would just do nothing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check with Ale how we expect to handle the prebuilt dashboard, but I'm okay with leaving it in until we figure out what to do with it. If we don't want to let people favourite prebuilt dashboards (we only have one) then I think we should just 400 the request or something

Copy link
Member

@narsaynorath narsaynorath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment about the feature flag, otherwise looks good!

Toggle favorite status for current user by adding or removing
current user from dashboard favorites
"""
if not features.has(EDIT_FEATURE, organization, actor=request.user):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add a check for the feature flag so this 404s if they don't have the favourite rollout?

@harshithadurai harshithadurai merged commit cbadcc6 into master Dec 3, 2024
48 of 50 checks passed
@harshithadurai harshithadurai deleted the harshi/feat/add-favourite-dashboards-endpoint branch December 3, 2024 20:17
harshithadurai added a commit that referenced this pull request Dec 4, 2024
Add 'return' to endpoint response for POST request.

Should have added it in this PR:
#81438
@github-actions github-actions bot locked and limited conversation to collaborators Dec 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants