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: pagination on accounts listing #1196

Merged
merged 6 commits into from
Sep 27, 2024
Merged

Conversation

joshuaunity
Copy link
Contributor

@joshuaunity joshuaunity commented Sep 26, 2024

Description

This PR adds pagination to the accounts API and accounts page on the frontend

Look & Feel

Screenshot from 2024-09-26 12-44-11

How to test

Steps to test it or name of the tests functions.

Visit the accounts page.

Further Improvements

None

Related Items

This PR closes #1155


  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

@nhoening nhoening changed the title feat: uesrs pagination integration feat: users pagination integration on account page Sep 26, 2024
@nhoening nhoening changed the title feat: users pagination integration on account page feat: pagination on accounts listing Sep 26, 2024
Copy link
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

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

I believe we can delete some code in the UI code which gathers accounts for the page. Only then the loading of the page will actually improve.

flexmeasures/api/v3_0/assets.py Outdated Show resolved Hide resolved
@joshuaunity
Copy link
Contributor Author

joshuaunity commented Sep 26, 2024

I believe we can delete some code in the UI code which gathers accounts for the page. Only then the loading of the page will actually improve.

True, ill remove that.

Copy link
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

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

  • I see in the roles column something like this: "[object Object], [object Object]"
  • Let's not show the logo column. Many will not have one, so it's empty space, and we also do not show colors here anyways.

flexmeasures/ui/crud/accounts.py Outdated Show resolved Hide resolved
Copy link
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

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

Great, please add a changelog entry, then we can merge!

Signed-off-by: joshuaunity <[email protected]>
@joshuaunity
Copy link
Contributor Author

Great, please add a changelog entry, then we can merge!

Ok, adding that...

@nhoening nhoening merged commit 493bd70 into main Sep 27, 2024
9 checks passed
@nhoening nhoening deleted the feat-accounts-pagination-v2 branch September 27, 2024 12:08
Copy link
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

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

Nice work!

Just a few notes for a follow-up PR to clean up tiny docs mistakes and also a potential bug.


- If the `page` parameter is not provided, all assets are returned, without pagination information. The result will be a list of assets.
- If a `page` parameter is provided, the response will be paginated, showing a specific number of assets per page as defined by `per_page` (default is 10).
- If a search 'filter' such as 'solar "ACME corp"' is provided, the response will filter out assets where each search term is either present in their name or account name.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment needs an update. We are not actually applying the search filter to asset names.

Comment on lines +71 to +74
The endpoint supports pagination of the asset list using the `page` and `per_page` query parameters.

- If the `page` parameter is not provided, all assets are returned, without pagination information. The result will be a list of assets.
- If a `page` parameter is provided, the response will be paginated, showing a specific number of assets per page as defined by `per_page` (default is 10).
Copy link
Contributor

Choose a reason for hiding this comment

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

This should speak of accounts rather than assets.

Comment on lines +96 to +97
"num-records" : 1,
"filtered-records" : 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant spaces.

Comment on lines +91 to +92
'primary_color': '#1a3443'
'secondary_color': '#f1a122'
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing commas.

)

if filter:
search_terms = filter[0].split(" ")
Copy link
Contributor

Choose a reason for hiding this comment

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

This way of splitting does not work with search terms in quotes, such as the "ACME corp" in the docstring example.

Actually, since the SearchFilterField is used, the search string should already be split into a list of search terms, where each term may contain spaces. This line likely results in only applying the first search time, which is why it may have escaped developer testing.

@nhoening this is an example of why I suggested refactoring. The pagination implementation for assets uses a better function for splitting, which I had moved to a schema so any pagination implementation using search terms would use the same.

@@ -12,6 +12,7 @@ New features
* The data chart on the asset page splits up its color-coded sensor legend when showing more than 7 sensors, becoming a legend per subplot [see `PR #1176 <https://github.com/FlexMeasures/flexmeasures/pull/1176>`_ and `PR #1193 <https://github.com/FlexMeasures/flexmeasures/pull/1193>`_
* Speed up loading the users page, by making the pagination backend-based and adding support for that in the API [see `PR #1160 <https://github.com/FlexMeasures/flexmeasures/pull/1160>`]
* X-axis labels in CLI plots show datetime values in a readable and informative format [see `PR #1172 <https://github.com/FlexMeasures/flexmeasures/pull/1172>`_]
* Speed up loading the accounts page,by making the pagination backend-based and adding support for that in the API [see `PR #1196 <https://github.com/FlexMeasures/flexmeasures/pull/1196>`_]
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing space after comma.

from flexmeasures.data.services.accounts import get_accounts, get_audit_log_records
from flexmeasures.api.common.schemas.users import AccountIdField
from flexmeasures.data.schemas.account import AccountSchema
from flexmeasures.api.common.schemas.generic_assets import SearchFilterField
Copy link
Contributor

Choose a reason for hiding this comment

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

This schema should move to a more generic module, as it doesn't only deal with assets.

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.

Pagination for accounts
3 participants