Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,10 @@ describe('documentQuerySlice', function () {
expect(result.endItem).to.equal(3);
});

it('endItem uses the larger term when startItem is smaller for cursor queries', function () {
const pageTwoCursorState: DocumentQueryState = {
...cursorState,
currentPage: 2,
itemsPerPage: 10,
};
const docs = [];

const result = reducer(pageTwoCursorState, documentsReceived(docs));

expect(result.startItem).to.equal(11);
expect(result.endItem).to.equal(11);
it('shows 0-0 when cursor query returns no documents on page 1', function () {
const result = reducer(cursorState, documentsReceived([]));
expect(result.startItem).to.equal(0);
expect(result.endItem).to.equal(0);
});

Comment thread
tculig marked this conversation as resolved.
it('totalCountReceived(null) keeps totalPages null for cursor queries', function () {
Expand Down
21 changes: 13 additions & 8 deletions src/views/data-browsing-app/store/documentQuerySlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,19 @@ const recalculatePaginationValues = (
// next/previous page and amount per page
state.totalDocuments = null;
state.totalPages = null;
state.startItem = (state.currentPage - 1) * state.itemsPerPage + 1;
state.endItem = Math.max(
Math.min(
state.currentPage * state.itemsPerPage,
state.startItem + state.displayedDocuments.length - 1,
),
state.startItem,
);
if (state.displayedDocuments.length === 0) {
state.startItem = 0;
state.endItem = 0;
} else {
state.startItem = (state.currentPage - 1) * state.itemsPerPage + 1;
state.endItem = Math.max(
Math.min(
state.currentPage * state.itemsPerPage,
state.startItem + state.displayedDocuments.length - 1,
),
state.startItem,
);
}
Comment thread
tculig marked this conversation as resolved.
}
};

Expand Down
Loading