datacore icon indicating copy to clipboard operation
datacore copied to clipboard

separate interface for pagination

Open GamerGirlandCo opened this issue 2 years ago • 3 comments

all the views currently implemented (List and Table) have pagination props:

https://github.com/blacksmithgu/datacore/blob/b6d7ed7c0480ee2879162499388ea18da793b583/src/ui/table.tsx#L31-L40

i was thinking, maybe we could move these to a separate interface, and have TableProps and ListState extend said interface, to avoid repitition.

what do you think?

GamerGirlandCo avatar Nov 07 '23 17:11 GamerGirlandCo

something like

export interface Pagination {
     /** 
      * If a boolean, enables/disables paging with the default configuration. If a number, paging will be 
      * enabled with the given number of entries per page. 
      */ 
     paging?: number | boolean; 
  
     /** The initial page of the table. */ 
     initialPage?: number; 
     /** Controlled prop for setting the page of the table. */ 
     page?: number;
}

which could then be extended like this

export interface TableProps<T> extends Pagination {
// ...
}

GamerGirlandCo avatar Nov 07 '23 17:11 GamerGirlandCo

It saves some typing, but the main benefit of extracting is if we can actually write generic code that just needs Pagination; is there anywhere where we would benefit doing this?

blacksmithgu avatar Dec 09 '23 03:12 blacksmithgu

It saves some typing, but the main benefit of extracting is if we can actually write generic code that just needs Pagination; is there anywhere where we would benefit doing this?

i'm experimenting with creating a generic usePagination hook. as of right now, the only place where it doesn't work is the table component

GamerGirlandCo avatar Dec 09 '23 22:12 GamerGirlandCo

I've added a usePaging hook for these purposes... can review if having a paging interface is useful in the future.

blacksmithgu avatar Jul 06 '24 20:07 blacksmithgu