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

fix: Under Review pagination issues for big screens. #2581

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/hooks/api/useProposalsBatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,16 @@ export default function useProposalsBatch({
actions: {
initial: () => send(START),
start: () => {
if (remainingTokens.length >= proposalPageSize) return send(VERIFY);

if (remainingTokens.length > proposalPageSize) return send(VERIFY);
// If remaining tokens length is smaller than proposal page size.
// Find more tokens from inventory or scan from the next status

// scanNextStatus: inventory is initialized and
// there are no tokens to be fetched from the next page
const scanNextStatus =
initializedInventory &&
!(tokens.length % INVENTORY_PAGE_SIZE === 0 && tokens.length > 0);
(!(tokens.length % INVENTORY_PAGE_SIZE === 0 && tokens.length > 0) ||
remainingTokens.length === proposalPageSize);
if (scanNextStatus) {
const { index, tokens } = scanNextStatusTokens(
statusIndex + 1,
Expand Down Expand Up @@ -198,12 +198,19 @@ export default function useProposalsBatch({
const tokens = [...newTokens, ...remainingTokens];
setRemainingTokens(tokens);

// Go to the next status when the remaining tokens still be smaller
// than proposal page size and current status is not the last one.
if (
// Means the current batch request accepts more tokens than
// the current amount.
const needsToCompletePaginationBatch =
tokens.length < proposalPageSize &&
statusIndex + 1 < currentStatuses.length
) {
statusIndex + 1 < currentStatuses.length;

// can scan more tokens from next status list in order to
// populate the remainingTokens array and don't lose any token
const needsNextStatusScan =
tokens.length === proposalPageSize ||
needsToCompletePaginationBatch;

if (needsNextStatusScan) {
const nextIndex = statusIndex + 1;
const nextStatus = currentStatuses[nextIndex];
const nextStatusTokens = getUnfetchedTokens(
Expand Down
60 changes: 60 additions & 0 deletions teste2e/cypress/e2e/proposal/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,64 @@ describe("Records list", () => {
cy.assertListLengthByTestId("record-title", 10);
});
});

describe("Big screens and inventory length multiple of proposals page size", () => {
beforeEach(() => {
cy.viewport(1500, 1500);
});
it("can render under review records with 5 autorized tokens", () => {
// setup
cy.middleware("ticketvote.inventory", {
authorized: 5,
started: 0,
unauthorized: 13
});
cy.middleware("records.records");
// test
cy.visit(`/`);
cy.wait("@ticketvote.inventory");
// Should trigger at least 2 records batch requests
cy.wait("@records.records");
cy.wait("@records.records");
cy.assertListLengthByTestId("record-title", 10);
cy.scrollTo("bottom");
cy.wait(1000);
cy.assertListLengthByTestId("record-title", 15);
});
it("can render under review records with 5 started tokens", () => {
cy.middleware("ticketvote.inventory", {
authorized: 0,
started: 5,
unauthorized: 13
});
cy.middleware("records.records");
});
it("can render under review records with 5 tokens started and authorized", () => {
cy.middleware("ticketvote.inventory", {
authorized: 5,
started: 5,
unauthorized: 13
});
cy.middleware("records.records");
});
it("can render 10 authorized proposals", () => {
cy.middleware("ticketvote.inventory", {
authorized: 10,
started: 0,
unauthorized: 13
});
cy.middleware("records.records");
});
afterEach(() => {
cy.visit(`/`);
cy.wait("@ticketvote.inventory");
// Should trigger at least 2 records batch requests
cy.wait("@records.records");
cy.wait("@records.records");
cy.assertListLengthByTestId("record-title", 10);
cy.scrollTo("bottom");
cy.wait(1000);
cy.assertListLengthByTestId("record-title", 15);
});
});
});