mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
refactor: CB-2372 ProjectsResource
This commit is contained in:
@@ -477,7 +477,7 @@ extend type Query {
|
||||
connectionInfo( id: ID! ): ConnectionInfo!
|
||||
|
||||
# Return list of accessible user projects
|
||||
listProjects: [ ProjectInfo ]
|
||||
listProjects: [ ProjectInfo! ]!
|
||||
|
||||
readSessionLog(maxEntries: Int, clearEntries: Boolean): [ LogEntry! ]!
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@cloudbeaver/core-di": "~0.1.0",
|
||||
"@cloudbeaver/core-authentication": "~0.1.0",
|
||||
"@cloudbeaver/core-sdk": "~0.1.0",
|
||||
"@cloudbeaver/core-root": "~0.1.0",
|
||||
"@cloudbeaver/core-settings": "~0.1.0",
|
||||
"@cloudbeaver/core-utils": "~0.1.0"
|
||||
|
||||
@@ -6,38 +6,41 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { computed, makeObservable } from 'mobx';
|
||||
import { runInAction } from 'mobx';
|
||||
|
||||
import { UserInfoResource } from '@cloudbeaver/core-authentication';
|
||||
import { injectable } from '@cloudbeaver/core-di';
|
||||
import { GraphQLService, CachedDataResource, RmProject } from '@cloudbeaver/core-sdk';
|
||||
import { GraphQLService, ProjectInfo, CachedMapResource, CachedMapAllKey, ResourceKey, ResourceKeyUtils, resourceKeyList } from '@cloudbeaver/core-sdk';
|
||||
|
||||
export type Project = Omit<RmProject, 'creator' | 'description' | 'createTime'>;
|
||||
export type Project = ProjectInfo;
|
||||
|
||||
@injectable()
|
||||
export class ProjectsResource extends CachedDataResource<Project[]> {
|
||||
get userProject(): Project | undefined {
|
||||
return this.data.filter(project => !project.shared)[0];
|
||||
}
|
||||
|
||||
export class ProjectsResource extends CachedMapResource<string, Project> {
|
||||
constructor(
|
||||
private readonly graphQLService: GraphQLService,
|
||||
private readonly userInfoResource: UserInfoResource,
|
||||
) {
|
||||
super([]);
|
||||
|
||||
this.sync(this.userInfoResource);
|
||||
this.userInfoResource.onUserChange.addPostHandler(() => {
|
||||
this.loaded = false;
|
||||
this.markOutdated();
|
||||
});
|
||||
|
||||
makeObservable(this, {
|
||||
userProject: computed,
|
||||
this.clear();
|
||||
});
|
||||
}
|
||||
|
||||
protected async loader(): Promise<Project[]> {
|
||||
protected async loader(key: ResourceKey<string>): Promise<Map<string, Project>> {
|
||||
const all = ResourceKeyUtils.includes(key, CachedMapAllKey);
|
||||
|
||||
const { projects } = await this.graphQLService.sdk.getProjectList();
|
||||
return projects;
|
||||
|
||||
runInAction(() => {
|
||||
if (all) {
|
||||
this.data.clear();
|
||||
}
|
||||
|
||||
this.set(resourceKeyList(projects.map(project => project.id)), projects);
|
||||
});
|
||||
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* CloudBeaver - Cloud Database Manager
|
||||
* Copyright (C) 2020-2022 DBeaver Corp and others
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0.
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { computed, makeObservable } from 'mobx';
|
||||
|
||||
import { UserInfoResource } from '@cloudbeaver/core-authentication';
|
||||
import { injectable } from '@cloudbeaver/core-di';
|
||||
|
||||
import { Project, ProjectsResource } from './ProjectsResource';
|
||||
|
||||
@injectable()
|
||||
export class ProjectsService {
|
||||
get activeProject(): Project | undefined {
|
||||
let project: Project | undefined;
|
||||
|
||||
if (this.activeProjectId) {
|
||||
project = this.projectsResource.get(this.activeProjectId);
|
||||
}
|
||||
|
||||
if (!project && this.userInfoResource.data) {
|
||||
project = this.projectsResource.get(this.userInfoResource.data.userId);
|
||||
}
|
||||
|
||||
if (!project && this.projectsResource.values.length > 0) {
|
||||
project = this.projectsResource.values[0];
|
||||
}
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
private activeProjectId: string | null;
|
||||
|
||||
constructor(
|
||||
private readonly projectsResource: ProjectsResource,
|
||||
private readonly userInfoResource: UserInfoResource
|
||||
) {
|
||||
this.activeProjectId = null;
|
||||
|
||||
makeObservable(this, {
|
||||
activeProject: computed,
|
||||
});
|
||||
}
|
||||
|
||||
setActiveProject(project: Project): void {
|
||||
this.activeProjectId = project.id;
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './ProjectsResource';
|
||||
export * from './ProjectsService';
|
||||
export { manifest as coreProjectsManifest } from './manifest';
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
import type { PluginManifest } from '@cloudbeaver/core-di';
|
||||
|
||||
import { ProjectsResource } from './ProjectsResource';
|
||||
import { ProjectsService } from './ProjectsService';
|
||||
|
||||
export const manifest: PluginManifest = {
|
||||
info: {
|
||||
@@ -17,5 +18,6 @@ export const manifest: PluginManifest = {
|
||||
|
||||
providers: [
|
||||
ProjectsResource,
|
||||
ProjectsService,
|
||||
],
|
||||
};
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
query getProjectList {
|
||||
projects: listProjects {
|
||||
id,
|
||||
name,
|
||||
description,
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
query getProjectList {
|
||||
query getResourceProjectList {
|
||||
projects: rmListProjects {
|
||||
id,
|
||||
name,
|
||||
shared,
|
||||
description,
|
||||
}
|
||||
}
|
||||
@@ -358,7 +358,9 @@ export interface Mutation {
|
||||
openSession: SessionInfo;
|
||||
readLobValue: Scalars['String'];
|
||||
refreshSessionConnections?: Maybe<Scalars['Boolean']>;
|
||||
rmCreateProject?: Maybe<ProjectInfo>;
|
||||
rmCreateResource: Scalars['String'];
|
||||
rmDeleteProject: Scalars['Boolean'];
|
||||
rmDeleteResource?: Maybe<Scalars['Boolean']>;
|
||||
rmMoveResource: Scalars['String'];
|
||||
rmWriteResourceStringContent: Scalars['String'];
|
||||
@@ -444,33 +446,39 @@ export interface MutationCloseConnectionArgs {
|
||||
export interface MutationCopyConnectionFromNodeArgs {
|
||||
config?: InputMaybe<ConnectionConfig>;
|
||||
nodePath: Scalars['String'];
|
||||
projectId?: InputMaybe<Scalars['String']>;
|
||||
}
|
||||
|
||||
|
||||
export interface MutationCreateConnectionArgs {
|
||||
config: ConnectionConfig;
|
||||
projectId?: InputMaybe<Scalars['String']>;
|
||||
}
|
||||
|
||||
|
||||
export interface MutationCreateConnectionFolderArgs {
|
||||
folderName: Scalars['String'];
|
||||
parentFolderPath?: InputMaybe<Scalars['ID']>;
|
||||
projectId?: InputMaybe<Scalars['String']>;
|
||||
}
|
||||
|
||||
|
||||
export interface MutationCreateConnectionFromTemplateArgs {
|
||||
connectionName?: InputMaybe<Scalars['String']>;
|
||||
projectId?: InputMaybe<Scalars['String']>;
|
||||
templateId: Scalars['ID'];
|
||||
}
|
||||
|
||||
|
||||
export interface MutationDeleteConnectionArgs {
|
||||
id: Scalars['ID'];
|
||||
projectId?: InputMaybe<Scalars['String']>;
|
||||
}
|
||||
|
||||
|
||||
export interface MutationDeleteConnectionFolderArgs {
|
||||
folderPath: Scalars['ID'];
|
||||
projectId?: InputMaybe<Scalars['String']>;
|
||||
}
|
||||
|
||||
|
||||
@@ -484,18 +492,21 @@ export interface MutationInitConnectionArgs {
|
||||
|
||||
export interface MutationNavDeleteNodesArgs {
|
||||
nodePaths: Array<Scalars['ID']>;
|
||||
projectId?: InputMaybe<Scalars['ID']>;
|
||||
}
|
||||
|
||||
|
||||
export interface MutationNavMoveNodesToFolderArgs {
|
||||
folderPath: Scalars['ID'];
|
||||
nodePaths: Array<Scalars['ID']>;
|
||||
projectId?: InputMaybe<Scalars['ID']>;
|
||||
}
|
||||
|
||||
|
||||
export interface MutationNavRenameNodeArgs {
|
||||
newName: Scalars['String'];
|
||||
nodePath: Scalars['ID'];
|
||||
projectId?: InputMaybe<Scalars['ID']>;
|
||||
}
|
||||
|
||||
|
||||
@@ -518,6 +529,12 @@ export interface MutationReadLobValueArgs {
|
||||
}
|
||||
|
||||
|
||||
export interface MutationRmCreateProjectArgs {
|
||||
description?: InputMaybe<Scalars['String']>;
|
||||
projectName: Scalars['String'];
|
||||
}
|
||||
|
||||
|
||||
export interface MutationRmCreateResourceArgs {
|
||||
isFolder: Scalars['Boolean'];
|
||||
projectId: Scalars['String'];
|
||||
@@ -525,6 +542,11 @@ export interface MutationRmCreateResourceArgs {
|
||||
}
|
||||
|
||||
|
||||
export interface MutationRmDeleteProjectArgs {
|
||||
projectId: Scalars['ID'];
|
||||
}
|
||||
|
||||
|
||||
export interface MutationRmDeleteResourceArgs {
|
||||
projectId: Scalars['String'];
|
||||
recursive: Scalars['Boolean'];
|
||||
@@ -598,6 +620,7 @@ export interface MutationTestNetworkHandlerArgs {
|
||||
|
||||
export interface MutationUpdateConnectionArgs {
|
||||
config: ConnectionConfig;
|
||||
projectId?: InputMaybe<Scalars['String']>;
|
||||
}
|
||||
|
||||
|
||||
@@ -634,6 +657,7 @@ export interface NavigatorNodeInfo {
|
||||
nodeDetails?: Maybe<Array<ObjectPropertyInfo>>;
|
||||
nodeType?: Maybe<Scalars['String']>;
|
||||
object?: Maybe<DatabaseObjectInfo>;
|
||||
projectId?: Maybe<Scalars['String']>;
|
||||
}
|
||||
|
||||
export interface NavigatorSettings {
|
||||
@@ -771,6 +795,12 @@ export interface ProductInfo {
|
||||
version: Scalars['String'];
|
||||
}
|
||||
|
||||
export interface ProjectInfo {
|
||||
description?: Maybe<Scalars['String']>;
|
||||
id: Scalars['String'];
|
||||
name: Scalars['String'];
|
||||
}
|
||||
|
||||
export interface Query {
|
||||
activeUser?: Maybe<UserInfo>;
|
||||
allConnections: Array<ConnectionInfo>;
|
||||
@@ -807,6 +837,7 @@ export interface Query {
|
||||
listAuthProviderConfigurations: Array<AdminAuthProviderConfiguration>;
|
||||
listFeatureSets: Array<WebFeatureSet>;
|
||||
listPermissions: Array<AdminPermissionInfo>;
|
||||
listProjects: Array<ProjectInfo>;
|
||||
listRoles: Array<AdminRoleInfo>;
|
||||
listUserProfileProperties: Array<ObjectPropertyInfo>;
|
||||
listUsers: Array<AdminUserInfo>;
|
||||
@@ -1026,6 +1057,7 @@ export interface QueryNavGetStructContainersArgs {
|
||||
catalog?: InputMaybe<Scalars['ID']>;
|
||||
connectionId: Scalars['ID'];
|
||||
contextId?: InputMaybe<Scalars['ID']>;
|
||||
projectId?: InputMaybe<Scalars['ID']>;
|
||||
}
|
||||
|
||||
|
||||
@@ -1034,21 +1066,25 @@ export interface QueryNavNodeChildrenArgs {
|
||||
offset?: InputMaybe<Scalars['Int']>;
|
||||
onlyFolders?: InputMaybe<Scalars['Boolean']>;
|
||||
parentPath: Scalars['ID'];
|
||||
projectId?: InputMaybe<Scalars['ID']>;
|
||||
}
|
||||
|
||||
|
||||
export interface QueryNavNodeInfoArgs {
|
||||
nodePath: Scalars['ID'];
|
||||
projectId?: InputMaybe<Scalars['ID']>;
|
||||
}
|
||||
|
||||
|
||||
export interface QueryNavNodeParentsArgs {
|
||||
nodePath: Scalars['ID'];
|
||||
projectId?: InputMaybe<Scalars['ID']>;
|
||||
}
|
||||
|
||||
|
||||
export interface QueryNavRefreshNodeArgs {
|
||||
nodePath: Scalars['ID'];
|
||||
projectId?: InputMaybe<Scalars['ID']>;
|
||||
}
|
||||
|
||||
|
||||
@@ -1218,6 +1254,8 @@ export interface QueryUserConnectionsArgs {
|
||||
}
|
||||
|
||||
export interface RmProject {
|
||||
canEditConnection: Scalars['Boolean'];
|
||||
canEditResource: Scalars['Boolean'];
|
||||
createTime: Scalars['DateTime'];
|
||||
creator: Scalars['String'];
|
||||
description?: Maybe<Scalars['String']>;
|
||||
@@ -1226,6 +1264,10 @@ export interface RmProject {
|
||||
shared: Scalars['Boolean'];
|
||||
}
|
||||
|
||||
export enum RmProjectPermission {
|
||||
ResourceEdit = 'resource_edit'
|
||||
}
|
||||
|
||||
export interface RmResource {
|
||||
folder: Scalars['Boolean'];
|
||||
length: Scalars['Int'];
|
||||
@@ -2297,6 +2339,11 @@ export type NavRenameNodeMutationVariables = Exact<{
|
||||
|
||||
export type NavRenameNodeMutation = { navRenameNode?: string };
|
||||
|
||||
export type GetProjectListQueryVariables = Exact<{ [key: string]: never }>;
|
||||
|
||||
|
||||
export type GetProjectListQuery = { projects: Array<{ id: string; name: string; description?: string }> };
|
||||
|
||||
export type CreateResourceMutationVariables = Exact<{
|
||||
projectId: Scalars['String'];
|
||||
resourcePath: Scalars['String'];
|
||||
@@ -2315,11 +2362,6 @@ export type DeleteResourceMutationVariables = Exact<{
|
||||
|
||||
export type DeleteResourceMutation = { rmDeleteResource?: boolean };
|
||||
|
||||
export type GetProjectListQueryVariables = Exact<{ [key: string]: never }>;
|
||||
|
||||
|
||||
export type GetProjectListQuery = { projects: Array<{ id: string; name: string; shared: boolean }> };
|
||||
|
||||
export type GetResourceListQueryVariables = Exact<{
|
||||
projectId: Scalars['String'];
|
||||
folder?: InputMaybe<Scalars['String']>;
|
||||
@@ -2331,6 +2373,11 @@ export type GetResourceListQueryVariables = Exact<{
|
||||
|
||||
export type GetResourceListQuery = { resources: Array<{ name: string; folder: boolean; length: number }> };
|
||||
|
||||
export type GetResourceProjectListQueryVariables = Exact<{ [key: string]: never }>;
|
||||
|
||||
|
||||
export type GetResourceProjectListQuery = { projects: Array<{ id: string; name: string; shared: boolean; description?: string }> };
|
||||
|
||||
export type MoveResourceMutationVariables = Exact<{
|
||||
projectId: Scalars['String'];
|
||||
oldPath: Scalars['String'];
|
||||
@@ -3684,6 +3731,15 @@ export const NavRenameNodeDocument = `
|
||||
navRenameNode(nodePath: $nodePath, newName: $newName)
|
||||
}
|
||||
`;
|
||||
export const GetProjectListDocument = `
|
||||
query getProjectList {
|
||||
projects: listProjects {
|
||||
id
|
||||
name
|
||||
description
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const CreateResourceDocument = `
|
||||
mutation createResource($projectId: String!, $resourcePath: String!, $isFolder: Boolean!) {
|
||||
rmCreateResource(
|
||||
@@ -3702,15 +3758,6 @@ export const DeleteResourceDocument = `
|
||||
)
|
||||
}
|
||||
`;
|
||||
export const GetProjectListDocument = `
|
||||
query getProjectList {
|
||||
projects: rmListProjects {
|
||||
id
|
||||
name
|
||||
shared
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const GetResourceListDocument = `
|
||||
query getResourceList($projectId: String!, $folder: String, $nameMask: String, $readProperties: Boolean, $readHistory: Boolean) {
|
||||
resources: rmListResources(
|
||||
@@ -3726,6 +3773,16 @@ export const GetResourceListDocument = `
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const GetResourceProjectListDocument = `
|
||||
query getResourceProjectList {
|
||||
projects: rmListProjects {
|
||||
id
|
||||
name
|
||||
shared
|
||||
description
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const MoveResourceDocument = `
|
||||
mutation moveResource($projectId: String!, $oldPath: String!, $newPath: String!) {
|
||||
rmMoveResource(
|
||||
@@ -4229,18 +4286,21 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
|
||||
navRenameNode(variables: NavRenameNodeMutationVariables, requestHeaders?: Dom.RequestInit['headers']): Promise<NavRenameNodeMutation> {
|
||||
return withWrapper(wrappedRequestHeaders => client.request<NavRenameNodeMutation>(NavRenameNodeDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'navRenameNode', 'mutation');
|
||||
},
|
||||
getProjectList(variables?: GetProjectListQueryVariables, requestHeaders?: Dom.RequestInit['headers']): Promise<GetProjectListQuery> {
|
||||
return withWrapper(wrappedRequestHeaders => client.request<GetProjectListQuery>(GetProjectListDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'getProjectList', 'query');
|
||||
},
|
||||
createResource(variables: CreateResourceMutationVariables, requestHeaders?: Dom.RequestInit['headers']): Promise<CreateResourceMutation> {
|
||||
return withWrapper(wrappedRequestHeaders => client.request<CreateResourceMutation>(CreateResourceDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'createResource', 'mutation');
|
||||
},
|
||||
deleteResource(variables: DeleteResourceMutationVariables, requestHeaders?: Dom.RequestInit['headers']): Promise<DeleteResourceMutation> {
|
||||
return withWrapper(wrappedRequestHeaders => client.request<DeleteResourceMutation>(DeleteResourceDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'deleteResource', 'mutation');
|
||||
},
|
||||
getProjectList(variables?: GetProjectListQueryVariables, requestHeaders?: Dom.RequestInit['headers']): Promise<GetProjectListQuery> {
|
||||
return withWrapper(wrappedRequestHeaders => client.request<GetProjectListQuery>(GetProjectListDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'getProjectList', 'query');
|
||||
},
|
||||
getResourceList(variables: GetResourceListQueryVariables, requestHeaders?: Dom.RequestInit['headers']): Promise<GetResourceListQuery> {
|
||||
return withWrapper(wrappedRequestHeaders => client.request<GetResourceListQuery>(GetResourceListDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'getResourceList', 'query');
|
||||
},
|
||||
getResourceProjectList(variables?: GetResourceProjectListQueryVariables, requestHeaders?: Dom.RequestInit['headers']): Promise<GetResourceProjectListQuery> {
|
||||
return withWrapper(wrappedRequestHeaders => client.request<GetResourceProjectListQuery>(GetResourceProjectListDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'getResourceProjectList', 'query');
|
||||
},
|
||||
moveResource(variables: MoveResourceMutationVariables, requestHeaders?: Dom.RequestInit['headers']): Promise<MoveResourceMutation> {
|
||||
return withWrapper(wrappedRequestHeaders => client.request<MoveResourceMutation>(MoveResourceDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'moveResource', 'mutation');
|
||||
},
|
||||
|
||||
@@ -16,7 +16,6 @@ import { NotificationService } from '@cloudbeaver/core-events';
|
||||
import type { IExecutionContextProvider } from '@cloudbeaver/core-executor';
|
||||
import { LocalizationService } from '@cloudbeaver/core-localization';
|
||||
import { NavTreeResource, NavNodeManagerService, NavNodeInfoResource, type INodeMoveData, navNodeMoveContext, getNodesFromContext, ENodeMoveType, type NavNode } from '@cloudbeaver/core-navigation-tree';
|
||||
import { ProjectsResource } from '@cloudbeaver/core-projects';
|
||||
import { ResourceKey, resourceKeyList, ResourceKeyUtils } from '@cloudbeaver/core-sdk';
|
||||
import { createPath } from '@cloudbeaver/core-utils';
|
||||
import { ActionService, MenuService, ACTION_NEW_FOLDER, DATA_CONTEXT_MENU, IAction, IDataContextProvider } from '@cloudbeaver/core-view';
|
||||
@@ -25,6 +24,7 @@ import { DATA_CONTEXT_ELEMENTS_TREE, MENU_ELEMENTS_TREE_TOOLS, type IElementsTre
|
||||
import { NAV_NODE_TYPE_RM_PROJECT } from '../NAV_NODE_TYPE_RM_PROJECT';
|
||||
import { NavResourceNodeService } from '../NavResourceNodeService';
|
||||
import { ResourceManagerResource } from '../ResourceManagerResource';
|
||||
import { ResourceProjectsResource } from '../ResourceProjectsResource';
|
||||
import { RESOURCES_NODE_PATH } from '../RESOURCES_NODE_PATH';
|
||||
import { NAV_NODE_TYPE_RM_RESOURCE } from './NAV_NODE_TYPE_RM_RESOURCE';
|
||||
|
||||
@@ -39,7 +39,7 @@ export class ResourceFoldersBootstrap extends Bootstrap {
|
||||
private readonly navNodeManagerService: NavNodeManagerService,
|
||||
private readonly navResourceNodeService: NavResourceNodeService,
|
||||
private readonly resourceManagerResource: ResourceManagerResource,
|
||||
private readonly projectsResource: ProjectsResource,
|
||||
private readonly resourceProjectsResource: ResourceProjectsResource,
|
||||
private readonly commonDialogService: CommonDialogService,
|
||||
private readonly actionService: ActionService,
|
||||
private readonly menuService: MenuService,
|
||||
@@ -70,7 +70,7 @@ export class ResourceFoldersBootstrap extends Bootstrap {
|
||||
return true;
|
||||
}
|
||||
|
||||
untracked(async () => await this.projectsResource.load());
|
||||
untracked(async () => await this.resourceProjectsResource.load());
|
||||
return this.getTargetNode(tree) === undefined;
|
||||
},
|
||||
handler: this.elementsTreeActionHandler.bind(this),
|
||||
@@ -111,10 +111,10 @@ export class ResourceFoldersBootstrap extends Bootstrap {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.projectsResource.load();
|
||||
const projectPath = createPath(RESOURCES_NODE_PATH, this.projectsResource.userProject?.id);
|
||||
await this.resourceProjectsResource.load();
|
||||
const projectPath = createPath(RESOURCES_NODE_PATH, this.resourceProjectsResource.userProject?.id);
|
||||
|
||||
if (!(this.projectsResource.userProject?.id === data.key.projectId)) {
|
||||
if (!(this.resourceProjectsResource.userProject?.id === data.key.projectId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ export class ResourceFoldersBootstrap extends Bootstrap {
|
||||
if (tree === undefined) {
|
||||
return;
|
||||
}
|
||||
await this.projectsResource.load();
|
||||
await this.resourceProjectsResource.load();
|
||||
|
||||
switch (action) {
|
||||
case ACTION_NEW_FOLDER: {
|
||||
@@ -245,7 +245,7 @@ export class ResourceFoldersBootstrap extends Bootstrap {
|
||||
targetNode = this.navNodeInfoResource.get(targetFolder);
|
||||
}
|
||||
|
||||
const projectPath = createPath(RESOURCES_NODE_PATH, this.projectsResource.userProject?.id);
|
||||
const projectPath = createPath(RESOURCES_NODE_PATH, this.resourceProjectsResource.userProject?.id);
|
||||
if (!targetNode?.id.startsWith(projectPath)) {
|
||||
targetNode = undefined;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* CloudBeaver - Cloud Database Manager
|
||||
* Copyright (C) 2020-2022 DBeaver Corp and others
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0.
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { computed, makeObservable } from 'mobx';
|
||||
|
||||
import { UserInfoResource } from '@cloudbeaver/core-authentication';
|
||||
import { injectable } from '@cloudbeaver/core-di';
|
||||
import { GraphQLService, CachedDataResource, RmProject } from '@cloudbeaver/core-sdk';
|
||||
|
||||
export type Project = Omit<RmProject, 'creator' | 'createTime' | 'canEditConnection' | 'canEditResource'>;
|
||||
|
||||
@injectable()
|
||||
export class ResourceProjectsResource extends CachedDataResource<Project[]> {
|
||||
get userProject(): Project | undefined {
|
||||
return this.data.filter(project => !project.shared)[0];
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly graphQLService: GraphQLService,
|
||||
private readonly userInfoResource: UserInfoResource,
|
||||
) {
|
||||
super([]);
|
||||
|
||||
this.userInfoResource.onUserChange.addPostHandler(() => {
|
||||
this.loaded = false;
|
||||
this.markOutdated();
|
||||
});
|
||||
|
||||
makeObservable(this, {
|
||||
userProject: computed,
|
||||
});
|
||||
}
|
||||
|
||||
protected async loader(): Promise<Project[]> {
|
||||
const { projects } = await this.graphQLService.sdk.getResourceProjectList();
|
||||
return projects;
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,11 @@ import styled, { css } from 'reshadow';
|
||||
import { Loader, useDataResource } from '@cloudbeaver/core-blocks';
|
||||
import { useService } from '@cloudbeaver/core-di';
|
||||
import { useTranslate } from '@cloudbeaver/core-localization';
|
||||
import { ProjectsResource } from '@cloudbeaver/core-projects';
|
||||
import { createPath } from '@cloudbeaver/core-utils';
|
||||
import { CaptureView } from '@cloudbeaver/core-view';
|
||||
import { NavigationTreeService, ElementsTree, NavigationNodeControl } from '@cloudbeaver/plugin-navigation-tree';
|
||||
|
||||
import { ResourceProjectsResource } from '../ResourceProjectsResource';
|
||||
import { RESOURCES_NODE_PATH } from '../RESOURCES_NODE_PATH';
|
||||
|
||||
const styles = css`
|
||||
@@ -56,7 +56,7 @@ export const ResourceManagerTree = observer(function ResourceManagerTree() {
|
||||
const translate = useTranslate();
|
||||
const navTreeService = useService(NavigationTreeService);
|
||||
|
||||
const { resource } = useDataResource(ResourceManagerTree, ProjectsResource, undefined);
|
||||
const { resource } = useDataResource(ResourceManagerTree, ResourceProjectsResource, undefined);
|
||||
|
||||
return styled(styles)(
|
||||
<Loader state={resource}>
|
||||
|
||||
@@ -7,4 +7,5 @@ export * from './NavResourceNodeService';
|
||||
export * from './ResourceManagerResource';
|
||||
export * from './SaveScriptDialog';
|
||||
export * from './ResourceManagerService';
|
||||
export * from './ResourceProjectsResource';
|
||||
export * from './RESOURCES_NODE_PATH';
|
||||
@@ -15,6 +15,7 @@ import { PluginBootstrap } from './PluginBootstrap';
|
||||
import { ResourceManagerResource } from './ResourceManagerResource';
|
||||
import { ResourceManagerService } from './ResourceManagerService';
|
||||
import { ResourceManagerSettingsService } from './ResourceManagerSettingsService';
|
||||
import { ResourceProjectsResource } from './ResourceProjectsResource';
|
||||
|
||||
export const resourceManagerPlugin: PluginManifest = {
|
||||
info: { name: 'Resource manager plugin' },
|
||||
@@ -26,5 +27,6 @@ export const resourceManagerPlugin: PluginManifest = {
|
||||
ResourceManagerResource,
|
||||
NavResourceNodeService,
|
||||
ResourceFoldersBootstrap,
|
||||
ResourceProjectsResource,
|
||||
],
|
||||
};
|
||||
@@ -11,12 +11,11 @@ import { CommonDialogService, DialogueStateResult } from '@cloudbeaver/core-dial
|
||||
import { NotificationService } from '@cloudbeaver/core-events';
|
||||
import type { IExecutionContextProvider } from '@cloudbeaver/core-executor';
|
||||
import { NavNodeManagerService, NavTreeResource, NavNodeInfoResource, NodeManagerUtils, type INodeNavigationData, NavigationType } from '@cloudbeaver/core-navigation-tree';
|
||||
import { ProjectsResource } from '@cloudbeaver/core-projects';
|
||||
import { DATA_CONTEXT_TAB_ID } from '@cloudbeaver/core-ui';
|
||||
import { createPath } from '@cloudbeaver/core-utils';
|
||||
import { ActionService, ACTION_SAVE, DATA_CONTEXT_MENU, MenuService } from '@cloudbeaver/core-view';
|
||||
import { NavigationTabsService } from '@cloudbeaver/plugin-navigation-tabs';
|
||||
import { NavResourceNodeService, RESOURCE_NODE_TYPE, SaveScriptDialog, ResourceManagerService, RESOURCES_NODE_PATH } from '@cloudbeaver/plugin-resource-manager';
|
||||
import { NavResourceNodeService, RESOURCE_NODE_TYPE, SaveScriptDialog, ResourceManagerService, RESOURCES_NODE_PATH, ResourceProjectsResource } from '@cloudbeaver/plugin-resource-manager';
|
||||
import { DATA_CONTEXT_SQL_EDITOR_STATE, getSqlEditorName, SqlDataSourceService, SqlEditorService, SqlEditorSettingsService, SQL_EDITOR_ACTIONS_MENU } from '@cloudbeaver/plugin-sql-editor';
|
||||
import { isSQLEditorTab, SqlEditorNavigatorService } from '@cloudbeaver/plugin-sql-editor-navigation-tab';
|
||||
|
||||
@@ -37,7 +36,7 @@ export class PluginBootstrap extends Bootstrap {
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly sqlEditorNavigatorService: SqlEditorNavigatorService,
|
||||
private readonly resourceManagerService: ResourceManagerService,
|
||||
private readonly projectsResource: ProjectsResource,
|
||||
private readonly resourceProjectsResource: ResourceProjectsResource,
|
||||
private readonly sqlEditorTabResourceService: SqlEditorTabResourceService,
|
||||
private readonly commonDialogService: CommonDialogService,
|
||||
private readonly actionService: ActionService,
|
||||
@@ -86,9 +85,9 @@ export class PluginBootstrap extends Bootstrap {
|
||||
|
||||
if (result !== DialogueStateResult.Rejected && result !== DialogueStateResult.Resolved) {
|
||||
try {
|
||||
await this.projectsResource.load();
|
||||
await this.resourceProjectsResource.load();
|
||||
const scriptName = `${result.trim()}.${SCRIPT_EXTENSION}`;
|
||||
const folder = createPath(RESOURCES_NODE_PATH, this.projectsResource.userProject?.id);
|
||||
const folder = createPath(RESOURCES_NODE_PATH, this.resourceProjectsResource.userProject?.id);
|
||||
const resourceData = this.navResourceNodeService.getResourceData(folder);
|
||||
|
||||
if (!resourceData) {
|
||||
|
||||
Reference in New Issue
Block a user