fix: order when loading more than 10 relations (#21855)

* fix: relations page loading

* chore: comment

* fix: do not regenerate all keys
This commit is contained in:
Marc Roig 2024-10-22 10:45:20 +02:00 committed by GitHub
parent df298029ec
commit 3db8f1fc61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -66,9 +66,13 @@ const relationsApi = contentManagerApi.injectEndpoints({
/**
* Relations will always have unique IDs, so we can therefore assume
* that we only need to push the new items to the cache.
*
* Push new items at the beginning as latest items are shown first
*/
currentCache.results.push(...prepareTempKeys(newItems.results, currentCache.results));
currentCache.results = [
...prepareTempKeys(newItems.results, currentCache.results),
...currentCache.results,
];
currentCache.pagination = newItems.pagination;
} else if (newItems.pagination.page === 1) {
/**
@ -180,7 +184,6 @@ const relationsApi = contentManagerApi.injectEndpoints({
*/
const prepareTempKeys = (relations: RelResult[], existingRelations: RelationResult[] = []) => {
const [firstItem] = existingRelations.slice(0);
const keys = generateNKeysBetween(null, firstItem?.__temp_key__ ?? null, relations.length);
return relations.map((datum, index) => ({