ts-japi icon indicating copy to clipboard operation
ts-japi copied to clipboard

[FR] Pagination - Not enough context

Open StevieBoyWonder opened this issue 4 years ago • 2 comments

Issues

The current pagination interface/classes do not accept enough parameters to create proper links

Details

Since the paginator is attached to a Serializer, the Paginator constructor can only accept the object or an Array of objects. However, to correctly use page-based pagination, you need the current query params supplied to a request to be available as well as a metaValue total.

Ex. (Articles Collection has 85 records) GET /articles?page[number]=1&page[size]=10 Should fetch the first ten articles and serialize them. The resulting pagination links should be

{
    first: '/articles?page[number]=1$page[size]=10',
    last: '/articles?page[number]=8&page[size]=10',
    next: 'articles?page[number]=2&page[size]=10',
    prev: null
}

Notice how the information here is only derivable given the request query params. In addition, a total needs to be supplied in some way to the serializer.

StevieBoyWonder avatar Aug 09 '21 18:08 StevieBoyWonder

It might make more sense to pass in a context object rather than what you are asking for; something that can be passed through all the functions.

jrandolf avatar Aug 15 '21 17:08 jrandolf

Yeah, I completely agree and that seems to be what alternative libraries do as well. They have this god level (extraData) param that is supplied at the top level and is propagated through as the structure is created.

StevieBoyWonder avatar Aug 18 '21 22:08 StevieBoyWonder