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

149 - Configure manual pagination in the Files Table UI #156

Merged
merged 15 commits into from
Sep 15, 2023

Conversation

MellyGray
Copy link
Contributor

@MellyGray MellyGray commented Aug 7, 2023

What this PR does / why we need it:

This PR changes the configuration of the Files Table UI to use manual pagination instead of the automatic pagination provided by react-table. We need this change because we decided to apply server-side pagination to the Files Table so the API will retrieve the data by pages instead of retrieving the whole list of files at once.

Which issue(s) this PR closes:

Special notes for your reviewer:

Changes applied:

  1. getFilesByDatasetPersistentId use case modified to accept a paginationInfo argument that indicated the number of the requested page and the size of the page
  2. TablePagination component now is FilesPagination component and instead of using the react table methods provided for the pagination now is using some custom methods.
  3. useFilesTable hook modified to use manualPagination
  4. useRowSelection hook added to manage the row selection for the is server-side pagination. There is a bug in the react-table library when manualPagination is selected and you try to use the row selection so I had to create an hybrid between a customized row selection feature and the row selection provided by react table.
  5. RowSelectionMessage refactored to take out the logic of ClearSelection and SelectAll and move it to the useRowSelection hook

Suggestions on how to test this:

  1. npm i
  2. cd packages/design-system && npm run build
  3. cd ../../
  4. npm run storybook
  5. Check the files table at localhost:6006 storybook in the Dataset page
  6. Test the pagination is working as usual going from 1 page to another.
  7. Test the row selection going through the pages selecting different rows
  8. Select a few rows and check that a message appears informing about the selection with 2 buttons to select All or to clear selection, ensure this 2 buttons work
  9. Select a few rows with a total file size greater than 500 bytes (mocked value) to see the message about the zip download limit

Does this PR introduce a user interface change? If mockups are available, please link/include them here:

No

Is there a release notes update needed for this change?:

Applied manual pagination to the Files Table UI

Additional documentation:

@MellyGray MellyGray marked this pull request as ready for review August 7, 2023 08:08
@MellyGray MellyGray added this to Ready for Review ⏩ in IQSS/dataverse (TO BE RETIRED / DELETED in favor of project 34) via automation Aug 7, 2023
@MellyGray MellyGray added the Size: 10 A percentage of a sprint. 7 hours. label Aug 7, 2023
@coveralls
Copy link

coveralls commented Aug 10, 2023

Coverage Status

coverage: 98.443% (-0.09%) from 98.531% when pulling f026545 on feature/149-react-table-manual-pagination-setup into b44205d on develop.

Base automatically changed from feature/136-files-table-checkboxes-selection-ui to develop August 14, 2023 13:38
@scolapasta scolapasta moved this from Ready for Review ⏩ to In Review 🔎 in IQSS/dataverse (TO BE RETIRED / DELETED in favor of project 34) Aug 22, 2023
@scolapasta scolapasta moved this from In Review 🔎 to Ready for Review ⏩ in IQSS/dataverse (TO BE RETIRED / DELETED in favor of project 34) Aug 22, 2023
@GPortas GPortas moved this from Ready for Review ⏩ to In Review 🔎 in IQSS/dataverse (TO BE RETIRED / DELETED in favor of project 34) Aug 31, 2023
@GPortas GPortas self-assigned this Aug 31, 2023
@MellyGray MellyGray linked an issue Aug 31, 2023 that may be closed by this pull request
@GPortas
Copy link
Contributor

GPortas commented Aug 31, 2023

@MellyGray

I still have to review the code, but I have already tested Storybook and I have found this unexpected behavior:

In file selection. The zip limit is not shown when selecting two files from different pages (their sum exceeds the limit):

selection_test_2

constructor(
public readonly page: number = 1,
public readonly pageSize: number = 10,
public readonly total: number = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

By reading this model without much context I don't understand what this "total" property refers to and why it can be 0. Maybe renaming it can help?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see 🤔 This total refers to the total number of files, the total number of elements to be paginated, maybe rename it to totalFiles? filesTotal?

The total number of pages is called here totalPages so I guess we can call this totalFiles

Copy link
Contributor

Choose a reason for hiding this comment

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

totalFiles makes sense!

const rowSelection: Record<string, boolean> = {}

for (let i = 0; i < numberOfRows; i++) {
rowSelection[i as unknown as string] = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this kind of double casting here? just curious

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Typescript doesn't allow conversion of type number to string, so the unknown is an intermediate step to convert the number to string. I'm forcing the type conversion because I think it's a controlled situation, but it would be best if I do the proper casting String(i). Yep, I can change this for better readability and proper casting

Copy link
Contributor

@GPortas GPortas left a comment

Choose a reason for hiding this comment

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

Code looks good! Just a couple of comments. Also, please take a look at my comment about the Storybook test.

@GPortas GPortas assigned MellyGray and GPortas and unassigned GPortas Aug 31, 2023
@GPortas
Copy link
Contributor

GPortas commented Sep 1, 2023

I have created this issue: IQSS/dataverse-client-javascript#86

We need a use case to get the total space consumed by the files of a particular dataset version. This use case will allow the SPA to know the total space consumed by the files when the user selects "select all" in the files tab, without needing to retrieve all the files (without pagination, could be an expensive operation) and apply client side logic to calculate the size.

Once the use case is ready, we will integrate it into the UI logic of the files tab.

@MellyGray
Copy link
Contributor Author

@GPortas I added some commits with the requested changes

@MellyGray MellyGray removed their assignment Sep 4, 2023
@@ -48,8 +49,10 @@ export function ZipDownloadLimitMessage({ selectedFiles }: ZipDownloadLimitMessa
)
}

function getFilesTotalSizeInBytes(files: File[]) {
return files.map((file) => file.size).reduce((bytes, size) => bytes + size.toBytes(), 0)
function getFilesTotalSizeInBytes(files: (File | undefined)[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you consider undefined now and not before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because before your review I wasn't counting with the selectAll for manual pagination, which means that I need to select all files which I don't know because the pagination only retrieves 10 files, so those files that I cannot know are saving their place in the fileSelection list with an undefined

then the fileSelection object can have File | undefined, so this function getFilesTotalSizeInBytes that is reading the fileSelection now needs to accept some undefined files, to get the totalSizeInBytes it just ignores the undefined files

in the future we'll get the totalFileSize using a different endpoint but for the moment it can only read the size of the files of the current page

@GPortas
Copy link
Contributor

GPortas commented Sep 4, 2023

Zip limit message now works on multiple page selection!

multipage-zip-selection

IQSS/dataverse (TO BE RETIRED / DELETED in favor of project 34) automation moved this from In Review 🔎 to Ready for QA ⏩ Sep 4, 2023
@GPortas GPortas removed their assignment Sep 4, 2023
@kcondon kcondon self-assigned this Sep 11, 2023
@kcondon
Copy link
Contributor

kcondon commented Sep 11, 2023

@MellyGray This works well, thanks. I did find one difference from the current UI which is unintuitive and was an issue we'd encountered before, why we added that select all link: selecting the global checkbox on a page in the existing ui selects all rows in the current page only. In this pr it selects all files in the dataset.

@MellyGray
Copy link
Contributor Author

@MellyGray This works well, thanks. I did find one difference from the current UI which is unintuitive and was an issue we'd encountered before, why we added that select all link: selecting the global checkbox on a page in the existing ui selects all rows in the current page only. In this pr it selects all files in the dataset.

@kcondon
Ok, so if I understood you well there are 2 different behaviors:

Global checkbox: selects all rows in the current page -> This is wrong in this PR
Select All: selects all files in the dataset

I can fix that, should we move this back to in progress to work on that fix? Or do we leave this in QA while I work on the fix? Sorry, I get lost in the workflow

@kcondon
Copy link
Contributor

kcondon commented Sep 12, 2023

@MellyGray Yes, that is correct. This part of the workflow is a bit informal -if you are able to work on it and it is relatively small, just leave it in QA. If it will stay for a while or very large, move back to In Progress. My motto is whatever works.

@MellyGray
Copy link
Contributor Author

@kcondon ok, I committed the fix! It was a small change after all

@kcondon kcondon merged commit 2f5126a into develop Sep 15, 2023
10 of 12 checks passed
IQSS/dataverse (TO BE RETIRED / DELETED in favor of project 34) automation moved this from QA ✅ to Done 🚀 Sep 15, 2023
@kcondon kcondon deleted the feature/149-react-table-manual-pagination-setup branch September 15, 2023 07:25
jayanthkomarraju pushed a commit to jayanthkomarraju/dataverse-frontend that referenced this pull request May 31, 2024
…pagination-setup

149 - Configure manual pagination in the Files Table UI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: 10 A percentage of a sprint. 7 hours.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

[Spike - Frontend] [1/2] React table manual pagination setup
4 participants