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

implement pagination on VASP List #988

Merged
merged 9 commits into from
Mar 28, 2023
Merged

implement pagination on VASP List #988

merged 9 commits into from
Mar 28, 2023

Conversation

masskoder
Copy link
Collaborator

@masskoder masskoder commented Mar 27, 2023

Scope of changes

feat: implement pagination

Type of change

  • bug fix
  • new feature
  • documentation
  • other (describe)

Acceptance criteria

https://www.awesomescreenshot.com/video/15983926?key=520bc0334afaaa0566d399dca5c9c2db

Author checklist

  • I have manually tested the change and/or added automation in the form of unit tests or integration tests
  • I have updated the dependencies list
  • I have recompiled and included new protocol buffers to reflect changes I made
  • I have added new test fixtures as needed to support added tests
  • Check this box if a reviewer can merge this pull request after approval (leave it unchecked if you want to do it yourself)
  • I have moved the associated Shortcut story to "Ready for Review"

Reviewer(s) checklist

  • Any new user-facing content that has been added for this PR has been QA'ed to ensure correct grammar, spelling, and understandability.

@masskoder masskoder changed the title feat: implement pagination implement pagination on VASP List Mar 27, 2023
@masskoder masskoder requested a review from elysee15 March 27, 2023 19:58
@@ -13,7 +13,7 @@ export function useOrganizationListQuery(): OrganizationQuery {

return {
getAllOrganizations: query.refetch,
organizations: query.data?.data as Organization[],
organizations: query.data?.data as any,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is a bad idea to add any here because it could make debugging harder. What if you create a type based on what you get from backend ?

errorMessage?: any;
getAllOrganizations(): void;
reset?(): void;
organizations?: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind adding the right type instead of any ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure thanks. But s story is planned to migrate all the any type definitions. it has been added when the backend is not ready yet and was the best way to go quickly.

refreshToken?: string;
}

export interface organizationResponse {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export interface organizationResponse {
export interface OrganizationResponse {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch, we need to handle that with Eslint. i will create a story to check that.


export const GetAllOrganisations = async () => {
const response = await axiosInstance.get(`/organizations`);
export const getAllOrganisations = async (page?: number) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export const getAllOrganisations = async (page?: number) => {
export const getAllOrganisations = async (page = 1) => {

export const GetAllOrganisations = async () => {
const response = await axiosInstance.get(`/organizations`);
export const getAllOrganisations = async (page?: number) => {
const currentPage = page || 1;
Copy link
Contributor

@elysee15 elysee15 Mar 27, 2023

Choose a reason for hiding this comment

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

Comment on lines 38 to 59
const NextPage = () => {
setCurrentPage(currentPage + 1);
};

const PreviousPage = () => {
setCurrentPage(currentPage - 1);
};

useEffect(() => {
if (currentPage !== 1) {
getAllOrganizations();
}
}, [currentPage, getAllOrganizations]);

useEffect(() => {
if (page && page_size && count && page * page_size >= count) {
setWasLastPage(true);
}
return () => {
setWasLastPage(false);
};
}, [page, page_size, count]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Put all this logic inside a hooks will make those logics more testable if you planned to write unit tests

Comment on lines 61 to 85
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// useEffect(() => {
// if (prevPage !== currentPage) {
// setPrevPage(currentPage + 1);
// if (organizations && organizations.organizations.length === 0) {
// setOrgList([...orgList, ...organizations.organizations]);
// }
// }
// }, [currentPage, organizations, orgList, prevPage]);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
// const onScroll = () => {
// if (listInnerRef.current) {
// const { scrollTop, scrollHeight, clientHeight } = listInnerRef.current;
// // console.log('[scrollTop]', scrollTop);
// // console.log('[scrollHeight]', scrollHeight);
// // console.log('[clientHeight]', clientHeight);
// // console.log('[scrollTop + clientHeight]', scrollTop + clientHeight);

// if (scrollTop + clientHeight === scrollHeight) {
// setCurrentPage(currentPage + 1);
// }
// }
// };

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you planned to use this logic later ?

@@ -76,6 +143,14 @@ function ChooseAnOrganization() {
</Stack>
</Stack>
</Stack>
<HStack>
<Button onClick={PreviousPage} disabled={currentPage === 1}>
Copy link
Contributor

@elysee15 elysee15 Mar 27, 2023

Choose a reason for hiding this comment

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

We can create here something like isCurrentPage and add it inside a hooks (#988 (comment))

Suggested change
<Button onClick={PreviousPage} disabled={currentPage === 1}>
<Button onClick={PreviousPage} disabled={isCurrentPage}>

Copy link
Contributor

@elysee15 elysee15 left a comment

Choose a reason for hiding this comment

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

Looks good! I have asked some questions and suggested changements at some level

@elysee15 elysee15 self-requested a review March 27, 2023 23:16
@masskoder masskoder merged commit 9bbfe8d into main Mar 28, 2023
@masskoder masskoder deleted the sc-12056 branch March 28, 2023 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants