Skip to content

Commit

Permalink
Merge branch 'devel' into feat/cb-4541/tree-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
kseniaguzeeva authored Sep 17, 2024
2 parents 5371c7d + 03d0f26 commit b782d15
Show file tree
Hide file tree
Showing 39 changed files with 650 additions and 459 deletions.
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"streetsidesoftware.code-spell-checker",
"streetsidesoftware.code-spell-checker-russian",
"syler.sass-indented",
"VisualStudioExptTeam.intellicode-api-usage-examples",
"VisualStudioExptTeam.vscodeintellicode",
"yzhang.markdown-all-in-one",
"GraphQL.vscode-graphql-syntax",
Expand Down
16 changes: 14 additions & 2 deletions webapp/packages/core-authentication/src/UsersResource.ts
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 @@ -240,6 +242,7 @@ export class UsersResource extends CachedMapResource<string, AdminUser, UserReso
}

const usersList: AdminUser[] = [];
const pages: Parameters<typeof this.offsetPagination.setPage>[] = [];

await ResourceKeyUtils.forEachAsync(originalKey, async key => {
let userId: string | undefined;
Expand Down Expand Up @@ -290,12 +293,21 @@ export class UsersResource extends CachedMapResource<string, AdminUser, UserReso

usersList.push(...users);

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,
]);
}
});

const key = resourceKeyList(usersList.map(user => user.userId));
this.set(key, usersList);
runInAction(() => {
this.set(key, usersList);
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 @@ -14,8 +14,10 @@ import {
CachedMapResource,
CachedResourceOffsetPageKey,
CachedResourceOffsetPageListKey,
CachedResourceOffsetPageTargetKey,
getNextPageOffset,
ICachedResourceOffsetPageOptions,
isResourceAlias,
ResourceKey,
ResourceKeyAlias,
ResourceKeyList,
Expand All @@ -30,7 +32,10 @@ interface IOptions<TKey extends ResourceKey<any>> {
}

interface IOffsetPagination<TKey> {
key: TKey extends ResourceKeyListAlias<any, any> | ResourceKeyList<any>
currentPage: TKey extends ResourceKeyListAlias<any, any> | ResourceKeyList<any>
? ResourceKeyListAlias<any, Readonly<ICachedResourceOffsetPageOptions>>
: ResourceKeyAlias<any, Readonly<ICachedResourceOffsetPageOptions>>;
allPages: TKey extends ResourceKeyListAlias<any, any> | ResourceKeyList<any>
? ResourceKeyListAlias<any, Readonly<ICachedResourceOffsetPageOptions>>
: ResourceKeyAlias<any, Readonly<ICachedResourceOffsetPageOptions>>;
hasNextPage: boolean;
Expand All @@ -42,6 +47,7 @@ interface IOffsetPaginationPrivate<TKey extends ResourceKey<any>> extends IOffse
offset: number;
resource: CachedMapResource<any, any, any, any>;
_key: ResourceKeyAlias<any, Readonly<ICachedResourceOffsetPageOptions>> | ResourceKeyListAlias<any, Readonly<ICachedResourceOffsetPageOptions>>;
_target: TKey | undefined;
}

export function useOffsetPagination<TResource extends CachedMapResource<any, any, any, any>, TKey extends ResourceKey<any>>(
Expand All @@ -61,40 +67,47 @@ export function useOffsetPagination<TResource extends CachedMapResource<any, any
() => ({
offset,
_key: createPageKey(offset, pageSize, targetKey),
get key() {
const pageInfo = resource.offsetPagination.getPageInfo(createPageKey(0, 0, this._key.target));

for (const page of pageInfo?.pages || []) {
if (page.outdated && page.from < this._key.options.offset) {
return createPageKey(page.from, this._key.options.limit, this._key.target);
_target: targetKey,
get currentPage() {
for (let i = 0; i < this.offset; i += this._key.options.limit) {
const key = createPageKey(i, this._key.options.limit, this._target);
if (resource.isOutdated(key)) {
return key;
}
}

return this._key as any;
},
get allPages(): any {
return createPageKey(0, this._key.options.offset + this._key.options.limit, this._target);
},
get hasNextPage(): boolean {
return this.resource.offsetPagination.hasNextPage(this._key);
},
loadMore() {
if (this.hasNextPage) {
this._key = createPageKey(this._key.options.offset + this._key.options.limit, this._key.options.limit, this._key.target);
this._key = createPageKey(this._key.options.offset + this._key.options.limit, this._key.options.limit, this._target);
}
},
refresh() {
this.resource.markOutdated(this._key.target);
this.resource.markOutdated(this._target);
},
}),
{
_key: observable.ref,
key: computed,
offset: observable.ref,
currentPage: computed,
allPages: computed,
hasNextPage: computed,
loadMore: action.bound,
refresh: action.bound,
},
{ resource },
);

if (!resource.isIntersect(targetKey, pagination._key.target)) {
if (!resource.isIntersect(targetKey, pagination._target)) {
pagination._key = createPageKey(offset, pageSize, targetKey);
pagination._target = targetKey;
}

return pagination;
Expand All @@ -103,10 +116,11 @@ export function useOffsetPagination<TResource extends CachedMapResource<any, any
function createPageKey(
offset: number,
limit: number,
target: ResourceKey<any>,
next: ResourceKey<any>,
): ResourceKeyAlias<any, Readonly<ICachedResourceOffsetPageOptions>> | ResourceKeyListAlias<any, Readonly<ICachedResourceOffsetPageOptions>> {
if (target instanceof ResourceKeyList || target instanceof ResourceKeyListAlias) {
return CachedResourceOffsetPageListKey(offset, limit).setTarget(target);
const parent = isResourceAlias(next) ? next : CachedResourceOffsetPageTargetKey(next);
if (next instanceof ResourceKeyList || next instanceof ResourceKeyListAlias) {
return CachedResourceOffsetPageListKey(offset, limit).setParent(parent);
}
return CachedResourceOffsetPageKey(offset, limit).setTarget(target);
return CachedResourceOffsetPageKey(offset, limit).setParent(parent);
}
48 changes: 21 additions & 27 deletions webapp/packages/core-blocks/src/Table/TableState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,28 @@ import { action, computed, makeObservable, observable } from 'mobx';

import { Executor, IExecutor } from '@cloudbeaver/core-executor';

type Key = string | string[];

interface IData {
key: string;
interface IData<Key> {
key: Key;
value: boolean;
}

export class TableState {
readonly onExpand: IExecutor<IData>;
export class TableState<K = string> {
readonly onExpand: IExecutor<IData<K>>;

selected: Map<string, boolean>;
expanded: Map<string, boolean>;
selected: Map<K, boolean>;
expanded: Map<K, boolean>;

get itemsSelected(): boolean {
return Array.from(this.selected.values()).some(v => v);
}

get selectedList(): string[] {
get selectedList(): K[] {
return Array.from(this.selected)
.filter(([_, value]) => value)
.map(([key]) => key);
}

get expandedList(): string[] {
get expandedList(): K[] {
return Array.from(this.expanded)
.filter(([_, value]) => value)
.map(([key]) => key);
Expand All @@ -41,8 +39,8 @@ export class TableState {
constructor() {
this.onExpand = new Executor();

this.selected = new Map();
this.expanded = new Map();
this.selected = new Map<K, boolean>();
this.expanded = new Map<K, boolean>();

makeObservable(this, {
selected: observable,
Expand All @@ -55,37 +53,33 @@ export class TableState {
});
}

unselect(key?: Key): Map<string, boolean> {
unselect(key?: K | K[]): Map<K, boolean> {
if (key === undefined) {
this.selected.clear();
} else {
if (typeof key === 'string') {
this.selected.delete(key);
} else {
for (const id of key) {
this.selected.delete(id);
}
const keys = Array.isArray(key) ? key : [key];

for (const id of keys) {
this.selected.delete(id);
}
}

return this.selected;
}

expand(key: string, value: boolean) {
expand(key: K, value: boolean) {
this.expanded.set(key, value);
this.onExpand.execute({ key, value });
}

collapse(key?: Key): Map<string, boolean> {
collapse(key?: K | K[]): Map<K, boolean> {
if (key === undefined) {
this.expanded.clear();
} else {
if (typeof key === 'string') {
this.expanded.delete(key);
} else {
for (const id of key) {
this.expanded.delete(id);
}
const keys = Array.isArray(key) ? key : [key];

for (const id of keys) {
this.expanded.delete(id);
}
}

Expand Down
4 changes: 2 additions & 2 deletions webapp/packages/core-blocks/src/Table/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useState } from 'react';

import { TableState } from './TableState';

export function useTable(): TableState {
const [table] = useState(() => new TableState());
export function useTable<K = string>(): TableState<K> {
const [table] = useState(() => new TableState<K>());
return table;
}
6 changes: 1 addition & 5 deletions webapp/packages/core-di/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Executor, IExecutor } from '@cloudbeaver/core-executor';
import { Bootstrap } from './Bootstrap';
import { Dependency } from './Dependency';
import type { DIContainer } from './DIContainer';
import type { IServiceCollection, IServiceConstructor, IServiceInjector } from './IApp';
import type { IServiceCollection, IServiceConstructor } from './IApp';
import { IDiWrapper, inversifyWrapper } from './inversifyWrapper';
import { IServiceProvider } from './IServiceProvider';
import type { PluginManifest } from './PluginManifest';
Expand Down Expand Up @@ -92,10 +92,6 @@ export class App {
return this.diWrapper.collection;
}

getServiceInjector(): IServiceInjector {
return this.diWrapper.injector;
}

// first phase register all dependencies
private async registerServices(preload?: boolean): Promise<void> {
if (!this.isAppServiceBound) {
Expand Down
1 change: 0 additions & 1 deletion webapp/packages/core-di/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export * from './DIService';
export * from './injectable';
export * from './PluginManifest';
export * from './useService';
export * from './useController';
export * from './ITypedConstructor';
export * from './isConstructor';
export * from './IServiceProvider';
Expand Down
62 changes: 0 additions & 62 deletions webapp/packages/core-di/src/useController.ts

This file was deleted.

Loading

0 comments on commit b782d15

Please sign in to comment.