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

augment API response pagination attributes #2471

Merged
merged 13 commits into from
Jul 14, 2023

Conversation

joeyorlando
Copy link
Contributor

@joeyorlando joeyorlando commented Jul 7, 2023

What this PR does

This PR:

  • adds a few attributes to paginated API responses
  • removes channel filter "send demo alert" internal API endpoint + tests (this endpoint was marked as deprecated + not consumed by the web UI)

With the new paginated API response schema, the web UI will no longer need to:

  • hardcode ITEMS_PER_PAGE for each table
  • manually calculate total number of pages

(these two things ☝️ will be done in #2476)

For GET /api/internal/v1/alertgroups the response will now look like this:

{
    "next": <url> | None,
    "previous": <url> | None,
    "results": [],
++  "page_size": <int>
}

For all other paginated API responses, the response will now look like:

{
    "count": <int>,
    "next": <url> | None,
    "previous": <url> | None,
    "results": [],
++  "page_size": <int>,
++  "current_page_number": <int>,
++  "total_pages": <int>
}

TODO

  • update public API docs to include these new attributes

Checklist

  • Unit, integration, and e2e (if applicable) tests updated
  • Documentation added (or pr:no public docs PR label added if not required)
  • CHANGELOG.md updated (or pr:no changelog PR label added if not required)

@joeyorlando joeyorlando changed the title augment API response pagination attributes augment API response pagination attributes + remove hardcoded ITEMS_PER_PAGE from frontend Jul 7, 2023
Copy link
Contributor Author

Choose a reason for hiding this comment

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

main change for the backend

@joeyorlando joeyorlando changed the title augment API response pagination attributes + remove hardcoded ITEMS_PER_PAGE from frontend augment API response pagination attributes Jul 10, 2023
@@ -527,8 +527,8 @@ def heartbeat_module(self):
return getattr(heartbeat, self.INTEGRATIONS_TO_REVERSE_URL_MAP[self.integration], None)

# Demo alerts
def send_demo_alert(self, force_route_id=None, payload=None):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

force_route_id seemed to only be passed in when this method was called from ChannelFilter. send_demo_alert (which was already deprecated and is now removed in this PR)

Comment on lines -65 to +71
def get_paginated_response_with_matched_users_count(self, data, matched_users_count):
return Response(
OrderedDict(
[
("count", self.page.paginator.count),
("matched_users_count", matched_users_count),
("next", self.get_next_link()),
("previous", self.get_previous_link()),
("results", data),
]
)
)
return self.get_paginated_response(data, len(cloud_identities))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

HundredPageSizePaginator inherits from PathPrefixedPagePagination and therefore all of these attributes, except for matched_users_count would be set. matched_users_count is being set above in the new CloudUsersPagination paginator class.

@joeyorlando joeyorlando changed the title augment API response pagination attributes augment API response pagination attributes + remove unused frontend route/code Jul 10, 2023
@joeyorlando joeyorlando marked this pull request as ready for review July 14, 2023 11:42
@joeyorlando joeyorlando requested a review from a team as a code owner July 14, 2023 11:42
@joeyorlando joeyorlando requested a review from a team July 14, 2023 11:42
@joeyorlando joeyorlando changed the title augment API response pagination attributes + remove unused frontend route/code augment API response pagination attributes Jul 14, 2023
Copy link
Contributor

@matiasb matiasb left a comment

Choose a reason for hiding this comment

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

Looks good

@joeyorlando joeyorlando enabled auto-merge July 14, 2023 15:06
@joeyorlando joeyorlando disabled auto-merge July 14, 2023 15:19
@joeyorlando joeyorlando merged commit 767c535 into dev Jul 14, 2023
@joeyorlando joeyorlando deleted the jorlando/augment-api-pagination-response branch July 14, 2023 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants