Skip to content

Commit

Permalink
Indicate whether pages are 0 and 1 indexed, confusing difference betw…
Browse files Browse the repository at this point in the history
…een backend and website
  • Loading branch information
corneliusroemer committed Nov 23, 2024
1 parent c43f045 commit 98e6e8b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ class SubmissionDatabaseService(
* Also returns status counts and processing result counts.
* Note that counts are totals: _not_ affected by pagination, status or processing result filter;
* i.e. the counts are for all sequences from that group and organism.
* Page and size are 0-indexed!
*/
fun getSequences(
authenticatedUser: AuthenticatedUser,
Expand Down
12 changes: 6 additions & 6 deletions website/src/components/ReviewPage/ReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const NumberAndVisibility = ({
};

const InnerReviewPage: FC<ReviewPageProps> = ({ clientConfig, organism, group, accessToken, metadataDisplayNames }) => {
const [pageQuery, setPageQuery] = useState<PageQuery>({ page: 1, size: pageSizeOptions[2] });
const [pageQuery, setPageQuery] = useState<PageQuery>({ pageOneIndexed: 1, size: pageSizeOptions[2] });

const hooks = useSubmissionOperations(organism, group, clientConfig, accessToken, toast.error, pageQuery);

Expand Down Expand Up @@ -112,7 +112,7 @@ const InnerReviewPage: FC<ReviewPageProps> = ({ clientConfig, organism, group, a

const handleSizeChange = (event: ChangeEvent<HTMLSelectElement>) => {
const newSize = parseInt(event.target.value, 10);
setPageQuery({ page: 1, size: newSize });
setPageQuery({ pageOneIndexed: 1, size: newSize });
};

let sequencesData = hooks.getSequences.data;
Expand Down Expand Up @@ -155,8 +155,8 @@ const InnerReviewPage: FC<ReviewPageProps> = ({ clientConfig, organism, group, a
(showErrors ? errorCount : 0);

// If we narrowed the selection and the selected page doesn't exist anymore, go to the last existing page instead
if ((pageQuery.page - 1) * pageQuery.size > selectedCount) {
setPageQuery({ ...pageQuery, page: Math.ceil(selectedCount / pageQuery.size) });
if ((pageQuery.pageOneIndexed - 1) * pageQuery.size > selectedCount) {
setPageQuery({ ...pageQuery, pageOneIndexed: Math.ceil(selectedCount / pageQuery.size) });
}

if (total === 0) {
Expand Down Expand Up @@ -226,9 +226,9 @@ const InnerReviewPage: FC<ReviewPageProps> = ({ clientConfig, organism, group, a
<div className='flex justify-end align-center gap-3 py-3'>
<Pagination
count={Math.ceil(selectedCount / pageQuery.size)}
page={pageQuery.page}
page={pageQuery.pageOneIndexed}
onChange={(_, newPage) => {
setPageQuery({ ...pageQuery, page: newPage });
setPageQuery({ ...pageQuery, pageOneIndexed: newPage });
}}
color='primary'
variant='outlined'
Expand Down
2 changes: 1 addition & 1 deletion website/src/hooks/useSubmissionOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function useSubmissionOperations(
initialStatusesFilter: allRelevantStatuses.join(','),
statusesFilter: includedStatuses.join(','),
processingResultFilter: includedProcessingResults.join(','),
page: pageQuery.page - 1,
page: pageQuery.pageOneIndexed - 1,
size: pageQuery.size,
},
},
Expand Down
2 changes: 1 addition & 1 deletion website/src/services/backendApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const getSequencesEndpoint = makeEndpoint({
schema: z.string().optional(),
},
{
name: 'page',
name: 'page', // 0-indexed
type: 'Query',
schema: z.number().optional(),
},
Expand Down
2 changes: 1 addition & 1 deletion website/src/types/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export const groupDetails = z.object({
export type GroupDetails = z.infer<typeof groupDetails>;

export const pageQuery = z.object({
page: z.number(),
pageOneIndexed: z.number(),
size: z.number(),
});

Expand Down

0 comments on commit 98e6e8b

Please sign in to comment.