feat: Extend renderer functionality to work with pagination
This commit is contained in:
@@ -1,14 +1,27 @@
|
|||||||
|
const isPaginated = (object) =>
|
||||||
|
object?.pageInfo &&
|
||||||
|
object?.totalCount !== undefined &&
|
||||||
|
Array.isArray(object?.records);
|
||||||
|
|
||||||
|
const isArray = (object) =>
|
||||||
|
Array.isArray(object) || Array.isArray(object?.records);
|
||||||
|
|
||||||
|
const totalCount = (object) =>
|
||||||
|
isPaginated(object) ? object.totalCount : isArray(object) ? object.length : 1;
|
||||||
|
|
||||||
const renderObject = (response, object) => {
|
const renderObject = (response, object) => {
|
||||||
const isArray = Array.isArray(object);
|
const data = isPaginated(object) ? object.records : object;
|
||||||
|
|
||||||
const computedPayload = {
|
const computedPayload = {
|
||||||
data: object,
|
data,
|
||||||
meta: {
|
meta: {
|
||||||
type: object.constructor.name,
|
type: isPaginated(object)
|
||||||
count: isArray ? object.length : 1,
|
? object.records[0].constructor.name
|
||||||
isArray,
|
: object.constructor.name,
|
||||||
currentPage: null,
|
count: totalCount(object),
|
||||||
totalPages: null,
|
isArray: isArray(object),
|
||||||
|
currentPage: isPaginated(object) ? object.pageInfo.currentPage : null,
|
||||||
|
totalPages: isPaginated(object) ? object.pageInfo.totalPages : null,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user