-
Notifications
You must be signed in to change notification settings - Fork 124
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: upload list pagination headers #1739
Conversation
Nice! Code looks good and the BE changes are ace, I found a few issues with the FE code:
We could just wipe the selection upon navigating away.
There's a few more minor issues here: I think the table and pagination components are tightly coupled and need a bit of refactoring in order to separate pins and uploads, but reuse the same components. @flea89 has worked on decoupling them from the table here: #1700 and in https://github.com/web3-storage/web3.storage/pull/1699/files I think the FE code here may require a bit more work, but the BE aspect is perfect! Would it make sense to split this into two PRs so that the Link URL, error handling changes & indexes aren't blocked by the UI? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of questions on the API/DB side, but besides these all look good.
A few FE issues, is the plan to split these out into a separate ticket or to tackle 'em all here?
@@ -109,7 +109,6 @@ const FileUploader = ({ className = '', content, uploadModalState, background }) | |||
}} | |||
icon={<FolderIcon />} | |||
dragAreaText={content.drop_prompt} | |||
maxFiles={3} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this been dropped for testing purposes? Or is it cool to no longer restrict file uploads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no error feedback in the UI and nothing that says only 3 files at a time. I don't know why we'd restrict files here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's a great point - was just double checking
getUploads(); | ||
} | ||
}, [fetchDate, getUploads, isFetchingUploads]); | ||
getUploads({ size: itemsPerPage, page, sortBy, sortOrder }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to reset the selectedFiles
here too, so that hidden selections aren't stored in that state.
packages/db/index.js
Outdated
query = query.gte('inserted_at', opts.after) | ||
async listUploads (userId, pageRequest) { | ||
let query | ||
if (pageRequest.type === DATE_TIME_PAGE_REQUEST) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the Date time pagination a little tricky,
Say I had two or more records with the exact same date time, wouldn't this break pagination & it would miss some results?
Super edge-casey, but am keen to understand why filtering by datetime is necessary, is it purely for the existing UI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's required by the pinning service API https://ipfs.github.io/pinning-services-api-spec/#section/Pagination-and-filtering and that's what was originally implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh ok, in which case should this also be replicated in listPsaPinRequests
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
listPsaPinRequests
serves the PSA (GET /pins
) primarily. It's now date ordered explicitly (and you can't change the sort field or direction from the UI). So, I've left it mostly as is and dealt with the "page number pagination" at the API handler level instead. If we want to enable that UX for the PSA table then yes we can probably refactor to use this pattern also.
…upload-list-pagination-headers
…upload-list-pagination-headers
try { | ||
data = await env.db.listUploads(request.auth.user._id, pageRequest) | ||
} catch (err) { | ||
if (err.code === 'RANGE_NOT_SATISFIABLE_ERROR_DB') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe reuse RangeNotSatisfiableDBError.CODE here
console.error(e) | ||
throw new HTTPError('No pinning resources found for user', 404) | ||
} catch (err) { | ||
if (err.code === 'RANGE_NOT_SATISFIABLE_ERROR_DB') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe reuse RangeNotSatisfiableDBError.CODE here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point! I could make a constant in the API package so that there's less dependancy on the db
package, or import it over from the db package. am struggling to weight up which would be best!
*/ | ||
export async function deletePinRequest(requestid) { | ||
const tokens = await getTokens(); | ||
if (!tokens[0]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit confusing; could we use tokens.length > 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, but with this we're checking if tokens[0]
is truthy, as it could be null.
Tokens could be [null, null]
and .length would be 2
…upload-list-pagination-headers
LGTM now conflicts are resolved, lots of changes here so would be great to get a second approval, @orvn @olizilla @vasco-santos are either you guys available to take a look? |
…upload-list-pagination-headers
Merging this since it resolves a fair few issues that are currently live, but if anyone else has any feedback feel free to leave it and will address in a separate PR. |
@joshJarr thanks for finishing this! Did the indexes get applied in prod? I just realised I should have written a migration for applying them. |
Link
headers to include required pagination variables.Visual preview:
Note new "Request ID" column for pinned items:
resolves #1610
resolves #1501
resolves #1362
resolves #1737