mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
chore: CB-1034 navigation tree improvements
This commit is contained in:
@@ -79,7 +79,7 @@ export class NavigationTreeService {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
await this.navNodeManagerService.loadTree(id);
|
||||
await this.navTreeResource.load(id);
|
||||
return true;
|
||||
} catch (exception) {
|
||||
this.notificationService.logException(exception);
|
||||
|
||||
@@ -240,13 +240,13 @@ export function useElementsTree(options: IOptions): IElementsTree {
|
||||
|
||||
useExecutor({
|
||||
executor: navNodeInfoResource.onDataOutdated,
|
||||
handlers: [function refreshRoot() {
|
||||
postHandlers: [function refreshRoot() {
|
||||
loadTree(options.root);
|
||||
}],
|
||||
});
|
||||
useExecutor({
|
||||
executor: navTreeResource.onNodeRefresh,
|
||||
handlers: [loadTree],
|
||||
postHandlers: [loadTree],
|
||||
});
|
||||
|
||||
useExecutor({
|
||||
|
||||
@@ -226,7 +226,7 @@ export class NavTreeResource extends CachedMapResource<string, string[]> {
|
||||
private async connectionUpdateHandler(key: ResourceKey<string>) {
|
||||
await this.markOutdated(ROOT_NODE_PATH);
|
||||
|
||||
ResourceKeyUtils.forEach(key, async key => {
|
||||
await ResourceKeyUtils.forEachAsync(key, async key => {
|
||||
const nodeId = NodeManagerUtils.connectionIdToConnectionNodeId(key);
|
||||
|
||||
if (this.has(nodeId)) {
|
||||
@@ -235,14 +235,14 @@ export class NavTreeResource extends CachedMapResource<string, string[]> {
|
||||
if (!connectionInfo?.connected) {
|
||||
this.delete(nodeId);
|
||||
} else {
|
||||
this.markTreeOutdated(nodeId);
|
||||
await this.markTreeOutdated(nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
const node = this.navNodeInfoResource.get(nodeId);
|
||||
|
||||
if (node) {
|
||||
this.markOutdated(node.parentId);
|
||||
await this.markOutdated(node.parentId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -59,16 +59,15 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void>
|
||||
}
|
||||
|
||||
async login(provider: string, credentials: Record<string, string>, link?: boolean): Promise<UserInfo | null> {
|
||||
const processedCredentials = await this.authProviderService.processCredentials(provider, credentials);
|
||||
|
||||
const { authToken } = await this.graphQLService.sdk.authLogin({
|
||||
provider,
|
||||
credentials: processedCredentials,
|
||||
linkUser: link,
|
||||
customIncludeOriginDetails: true,
|
||||
});
|
||||
|
||||
await this.performUpdate(undefined, undefined, async () => {
|
||||
const processedCredentials = await this.authProviderService.processCredentials(provider, credentials);
|
||||
|
||||
const { authToken } = await this.graphQLService.sdk.authLogin({
|
||||
provider,
|
||||
credentials: processedCredentials,
|
||||
linkUser: link,
|
||||
customIncludeOriginDetails: true,
|
||||
});
|
||||
if (this.data === null || link) {
|
||||
this.data = await this.loader();
|
||||
} else {
|
||||
|
||||
@@ -147,7 +147,7 @@ export abstract class CachedMapResource<
|
||||
markOutdated(key: ResourceKey<TKey>): Promise<void>
|
||||
async markOutdated(key?: ResourceKey<TKey>): Promise<void> {
|
||||
if (!key) {
|
||||
key = resourceKeyList(Array.from(this.data.keys()));
|
||||
key = resourceKeyList(this.keys);
|
||||
} else {
|
||||
key = this.transformParam(key);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ export abstract class CachedMapResource<
|
||||
markUpdated(key: ResourceKey<TKey>): void
|
||||
markUpdated(key?: ResourceKey<TKey>): void {
|
||||
if (!key) {
|
||||
key = resourceKeyList(Array.from(this.data.keys()));
|
||||
key = resourceKeyList(this.keys);
|
||||
} else {
|
||||
key = this.transformParam(key);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { computed, observable } from 'mobx';
|
||||
|
||||
import { AuthProviderService, UserInfoResource } from '@cloudbeaver/core-authentication';
|
||||
import { useObjectRef } from '@cloudbeaver/core-blocks';
|
||||
import { useService } from '@cloudbeaver/core-di';
|
||||
@@ -18,11 +20,12 @@ interface IAuthenticationAction {
|
||||
auth: () => Promise<void>;
|
||||
}
|
||||
interface IAuthenticationData extends IAuthenticationAction {
|
||||
onAuthenticate?: () => void;
|
||||
authenticating: boolean;
|
||||
onAuthenticate?: () => Promise<any> | void;
|
||||
}
|
||||
|
||||
export type Options = {
|
||||
onAuthenticate?: () => void;
|
||||
onAuthenticate?: () => Promise<any> | void;
|
||||
} & ({
|
||||
origin: ObjectOrigin;
|
||||
} | {
|
||||
@@ -45,19 +48,28 @@ export function useAuthenticationAction(options: Options): IAuthenticationAction
|
||||
}
|
||||
|
||||
return useObjectRef<IAuthenticationData>({
|
||||
authenticating: false,
|
||||
type,
|
||||
subType,
|
||||
onAuthenticate: options.onAuthenticate,
|
||||
get authorized() {
|
||||
return userInfoService.hasToken(this.type, this.subType);
|
||||
return !this.authenticating && userInfoService.hasToken(this.type, this.subType);
|
||||
},
|
||||
async auth() {
|
||||
await authProviderService.requireProvider(this.type, this.subType);
|
||||
this.onAuthenticate?.();
|
||||
this.authenticating = true;
|
||||
try {
|
||||
await authProviderService.requireProvider(this.type, this.subType);
|
||||
await this.onAuthenticate?.();
|
||||
} finally {
|
||||
this.authenticating = false;
|
||||
}
|
||||
},
|
||||
}, {
|
||||
type,
|
||||
subType,
|
||||
onAuthenticate: options.onAuthenticate,
|
||||
}, undefined, ['auth']);
|
||||
}, {
|
||||
authorized: computed,
|
||||
authenticating: observable,
|
||||
}, ['auth']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user