Skip to content

Commit

Permalink
CB-4461 fixes pagination for new resources
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyteleshev committed Sep 16, 2024
1 parent 3a24404 commit 398a7f5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { runInAction } from 'mobx';

import { injectable } from '@cloudbeaver/core-di';
import {
CACHED_RESOURCE_DEFAULT_PAGE_LIMIT,
Expand Down Expand Up @@ -42,6 +44,7 @@ export class UsersMetaParametersResource extends CachedMapResource<string, UserM
protected async loader(originalKey: ResourceKey<string>): Promise<Map<string, UserMetaParameter>> {
const all = this.aliases.isAlias(originalKey, CachedMapAllKey);
const keys: string[] = [];
const pages: Parameters<typeof this.offsetPagination.setPage>[] = [];

if (all) {
throw new Error('Loading all users is prohibited');
Expand Down Expand Up @@ -96,11 +99,22 @@ export class UsersMetaParametersResource extends CachedMapResource<string, UserM
userMetaParametersList.push(...users.map(user => user.metaParameters));
keys.push(...users.map(user => user.userId));

this.offsetPagination.setPageEnd(CachedResourceOffsetPageListKey(offset, users.length).setTarget(filterKey), users.length === limit);
pages.push([
CachedResourceOffsetPageListKey(offset, users.length).setParent(filterKey!),
users.map(user => user.userId),
users.length === limit,
]);
}
});

this.set(resourceKeyList(keys), userMetaParametersList);
const key = resourceKeyList(keys);

runInAction(() => {
this.set(key, userMetaParametersList);
for (const pageArgs of pages) {
this.offsetPagination.setPage(...pageArgs);
}
});

return this.data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { runInAction } from 'mobx';

import { injectable } from '@cloudbeaver/core-di';
import {
CACHED_RESOURCE_DEFAULT_PAGE_LIMIT,
Expand Down Expand Up @@ -36,6 +38,7 @@ export class UsersOriginDetailsResource extends CachedMapResource<string, AdminO
protected async loader(originalKey: ResourceKey<string>): Promise<Map<string, AdminOriginDetailsFragment>> {
const all = this.aliases.isAlias(originalKey, CachedMapAllKey);
const keys: string[] = [];
const pages: Parameters<typeof this.offsetPagination.setPage>[] = [];

if (all) {
throw new Error('Loading all users is prohibited');
Expand Down Expand Up @@ -90,11 +93,22 @@ export class UsersOriginDetailsResource extends CachedMapResource<string, AdminO
userMetaParametersList.push(...users);
keys.push(...users.map(user => user.userId));

this.offsetPagination.setPageEnd(CachedResourceOffsetPageListKey(offset, users.length).setTarget(filterKey), users.length === limit);
pages.push([
CachedResourceOffsetPageListKey(offset, users.length).setParent(filterKey!),
users.map(user => user.userId),
users.length === limit,
]);
}
});

this.set(resourceKeyList(keys), userMetaParametersList);
const key = resourceKeyList(keys);

runInAction(() => {
this.set(key, userMetaParametersList);
for (const pageArgs of pages) {
this.offsetPagination.setPage(...pageArgs);
}
});

return this.data;
}
Expand Down

0 comments on commit 398a7f5

Please sign in to comment.