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

Improve the interface of the comprehensive pagination engine #1358

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

csillag
Copy link
Contributor

@csillag csillag commented Mar 31, 2024

Currently, we have two interfaces for pagination:

  • There is SimplePaginationEngine. One such engine is returned by useSearchParamsPagination().
  • There is ComprehensivePaginationEngine. We have two implementations for this:
    • useComprehensiveSearchParamsPagination() and
    • useClientSidePagination()

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:

  • Adds lots of comments, explaining functionality
  • Renames some fields to better describe the actual meaning
  • Add some fields that are required for cleaner data encapsulation
  • Add support for arbitrary data transformation (besides the already existing filtering)

Copy link

github-actions bot commented Mar 31, 2024

Deployed to Cloudflare Pages

Latest commit: 5b3b56219088fc778b0ff0e77f51b8d8be52a03c
Status:✅ Deploy successful!
Preview URL: https://15898d4a.oasis-explorer.pages.dev

@csillag csillag force-pushed the csillag/improve-table-pagination branch from 14361c3 to 45d5b8d Compare May 9, 2024 02:25
@csillag csillag changed the title Improve how the pagination engine interfaces with other components Improve the interface of the comprehensive pagination engine May 10, 2024
@csillag csillag force-pushed the csillag/improve-table-pagination branch 2 times, most recently from b999f3d to a21dfd7 Compare May 10, 2024 02:04
@csillag csillag force-pushed the csillag/improve-table-pagination branch 4 times, most recently from ace62ea to b6c3cda Compare May 16, 2024 18:08
@csillag csillag marked this pull request as ready for review May 16, 2024 18:26
csillag and others added 2 commits May 22, 2024 09:05
- 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
@csillag csillag force-pushed the csillag/improve-table-pagination branch from b6c3cda to 5b3b562 Compare May 22, 2024 07:06
@@ -0,0 +1 @@
Improve the comprehensive pagination engine
Copy link
Member

Choose a reason for hiding this comment

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

filename typo

Comment on lines +10 to 13
/**
* How should we call the query parameter (in the URL)?
*/
paramName: string
Copy link
Member

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?

Comment on lines +23 to +24
* 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.
Copy link
Member

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 */
Copy link
Member

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
Copy link
Member

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> = {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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,
Copy link
Member

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> {
Copy link
Member

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?

Comment on lines +112 to +114
// 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
Copy link
Member

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,
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants