Skip to content

Commit

Permalink
fix(icons): fix list pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Mar 21, 2024
1 parent 51adcc6 commit e9acbde
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/config/custom-models/icon/IconModelDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,45 @@ export default class IconModelDefinition extends ModelDefinition {
return this.api.get(`icons/${id}`).then(icon => this.iconToModel(icon));
}

list() {
list(listParams = {}) {
// Read the query string manually from the filters instance because we don't want to transform
// it to query parameters for API calls. We will do client side filtering instead.
const nameFilter = this.filters.filters.find(
({ propertyName }) => propertyName === 'identifiable'
);
const queryString = nameFilter && nameFilter.filterValue;

const search = nameFilter && nameFilter.filterValue;
const params = {
fields:
'key,description,custom,created,lastUpdated,createdBy[id,displayName,name],fileResource,href',
type: 'custom',
search: queryString || '',
...(search && { search }),
...(listParams.page && { page: listParams.page }),
};

const res = this.api
return this.api
.get('icons', params)
.then(response => ({
...response,
icons: response.icons.map(icon => this.iconToModel(icon)),
}))
.then(response => {
// icons API doesnt have nextPage and prevPage...
// we only need these to be defined for it to work
const pager = {
...response.pager,
nextPage:
response.pager.page < response.pager.pageCount ||
undefined,
prevPage: response.pager.page === 1 && undefined,
};
const collection = IconModelCollection.create(
this,
response.icons,
response.pager
pager
);
console.log({ collection });
return collection;
});
return res;
}

async save(model) {
Expand Down

0 comments on commit e9acbde

Please sign in to comment.