-
Notifications
You must be signed in to change notification settings - Fork 9
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
Improve the interface of the comprehensive pagination engine #1358
base: master
Are you sure you want to change the base?
Conversation
Deployed to Cloudflare Pages
|
14361c3
to
45d5b8d
Compare
b999f3d
to
a21dfd7
Compare
ace62ea
to
b6c3cda
Compare
- Add documentation - Rename things for clarity - Add support for transforming the data, besides filtering - Add support for also specifying filters as an array - Add a bunch of more status fields
b6c3cda
to
5b3b562
Compare
@@ -0,0 +1 @@ | |||
Improve the comprehensive pagination engine |
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.
filename typo
/** | ||
* How should we call the query parameter (in the URL)? | ||
*/ | ||
paramName: string |
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.
This is where selected page is stored?
* Please note that currently this engine doesn't handle when the data consumer requires data which is not | ||
* part of the initial window on the server side. |
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 don't understand
* - transform() | ||
* - filter | ||
* - filters | ||
* - order */ |
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.
"order" doesn't exist
/** | ||
* Transformation to be applied after loading the data from the server, before presenting it to the data consumer component | ||
* | ||
* Can be used for ordering, aggregation, etc.D |
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.
typo
type ClientSizePaginationParams<Item> = { | ||
type Filter<Item> = (item: Item) => boolean | ||
|
||
type ClientSizePaginationParams<Item, QueryResult extends List, ExtractedData = typeof undefined> = { |
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.
type ClientSizePaginationParams<Item, QueryResult extends List, ExtractedData = typeof undefined> = { | |
type ClientSitePaginationParams<Item, QueryResult extends List, ExtractedData = typeof undefined> = { |
? (queryResult[key] as Item[]) | ||
: findListIn<QueryResult, Item>(queryResult) | ||
selectedPageForClient: selectedClientPage, | ||
paramsForServer: paramsForQuery, |
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.
rename both to paramsForServer?
/** | ||
* The data returned by a comprehensive pagination engine to the data consumer component | ||
*/ | ||
export interface ComprehensivePaginatedResults<Item, ExtractedData = typeof undefined> { |
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.
what is typeof undefined
type? is it string?
// From the server, we always want to load the first batch of data, with the provided (big) window. | ||
// In theory, we could move this window as required, but currently this is not implemented. | ||
const selectedServerPage = 1 |
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.
Is batch a different concept from window and page?
const offset = (selectedClientPage - 1) * clientPageSize | ||
const limit = clientPageSize | ||
const dataWindow = filteredData ? filteredData.slice(offset, offset + limit) : undefined | ||
|
||
// The control interface for the data consumer component (i.e. Table) | ||
const tableProps: TablePaginationProps = { | ||
selectedPage: selectedClientPage, | ||
linkToPage, |
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.
Can you improve the comment below?
? // This correction is here to simulate the bogus behavior of server-side pagination
// Remove this when server-side pagination is fixed,
// and so the work-around in the pagination widget is fixed.
it doesn't say TODO, it doesn't say what's wrong, and repeats last line?
Currently, we have two interfaces for pagination:
SimplePaginationEngine
. One such engine is returned byuseSearchParamsPagination()
.ComprehensivePaginationEngine
. We have two implementations for this:useComprehensiveSearchParamsPagination()
anduseClientSidePagination()
As you can guess from the name, the "Simple" engine is only used to provide parameters for queries, and driving the pagination ui. The "Comprehensive" engine has more responsibilities: it sits between the data source and the UI, completely encapsulating the data source, and therefore it is able to do various transformations (like sorting, filtering, etc).
Currently we only using this comprehensive engine on the token dashboard (plus on some feature branches, mostly where we want client-side pagination), so it's easy to introduce breaking API changes.
This PR polishes the interface of the comprehensive engine a little bit: