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: implement pagination #379

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Zied-Dahmani
Copy link
Collaborator

@Zied-Dahmani Zied-Dahmani commented Nov 28, 2024

Scope

Ticket

Added pagination for proposals and refactored code to improve readability and adhere to coding standards.

Note: The proposals were filtered by Payout and Policy since the latest version will only support these 2 types for simplification purposes.
Note: The valid states for history proposals are: Approved, Rejected, Archived, and Proposed.
Note: The pagination is happening when scrolling.

Video:

https://files.fm/f/tyrbchb4bh

@Zied-Dahmani Zied-Dahmani requested a review from n13 November 28, 2024 16:09
@Zied-Dahmani Zied-Dahmani self-assigned this Nov 28, 2024
@Zied-Dahmani Zied-Dahmani linked an issue Nov 28, 2024 that may be closed by this pull request
final List<ProposalModel> proposals = event is _Initial ? proposalsResult.asValue!.value : state.proposals + proposalsResult.asValue!.value;

final List<int> daoIds = GetIt.instance<FilterProposalsBloc>().selectedDaoIds ?? daos.map((DaoData dao) => dao.docId).toList();
if (nb < 3 && proposalsResult.asValue!.value.filterByDao(daoIds).isEmpty) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the "nb" magic number - this needs to have a real name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. I think retryCounter is a great choice because, in this case, the query can return an empty list or the filtering that happens after the query, even though there are more proposals on the next pages. So, if the initial list is empty (and we cannot scroll), the function calls itself up to a maximum of three times. This logic applies not only at the start of the list but also in the middle and the end.

final List<int> daoIds = GetIt.instance<FilterProposalsBloc>().selectedDaoIds ?? daos.map((DaoData dao) => dao.docId).toList();
if (nb < 3 && proposalsResult.asValue!.value.filterByDao(daoIds).isEmpty) {
offset += first;
nb ++;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand this code - offset += first

What is first?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Offset starts at 0 and increments by first (the number of items per page).

if (proposalsResult.isValue) {
final List<ProposalModel> proposals = event is _Initial ? proposalsResult.asValue!.value : state.proposals + proposalsResult.asValue!.value;

final List<int> daoIds = GetIt.instance<FilterProposalsBloc>().selectedDaoIds ?? daos.map((DaoData dao) => dao.docId).toList();
Copy link
Collaborator

Choose a reason for hiding this comment

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

does it always need to filter by daoID even if all daoIDs are selected? e.g. are there results that aren't even in a dao the user is a member of?

I mean it could be - they could have joined a dao and left,

but I would expect that to be part of the query, not additional code running after the query?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The selected daos, when null, means that all the daos are selected. The filterByDao is for UI purposes: the filter page should display the proposal count for all your daos, while the proposals page will show only the selected dao proposals. And yes, you can see only your daos, and all of this is already part of the existing code, which I haven’t changed.

Regarding the scenario where a user could have joined a dao and left, when the filter is initiated (not during pagination), the daos will be up to date. This ensures that the user only sees active daos they are currently a member of.

Copy link
Collaborator

@n13 n13 left a comment

Choose a reason for hiding this comment

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

Movie looks good!

But, I don't really understand the pagination code

Added a few questions to that

Normally you'd just have offset and limit, and go with that... I guess we are doing some additional filtering here which complicates things - would be easier to make all filters be part of the query so pagination works as expected.

If all filtering is part of the query then the database takes care of pagination

Explicit change requests:
variable naming ("nb", "first")
typing ("dynamic")

@n13
Copy link
Collaborator

n13 commented Nov 29, 2024

Upon review, the website proposals query is extremely long ...
dao-proposals-active-vote.gql.zip

@Zied-Dahmani Zied-Dahmani requested a review from n13 November 29, 2024 08:59
Copy link
Collaborator

@n13 n13 left a comment

Choose a reason for hiding this comment

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

Approved.

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.

Proposals Pagination
2 participants