diff --git a/webapp/packages/plugin-resource-manager/src/PluginBootstrap.ts b/webapp/packages/plugin-resource-manager/src/PluginBootstrap.ts index fb4c90d660..ba35f410d6 100644 --- a/webapp/packages/plugin-resource-manager/src/PluginBootstrap.ts +++ b/webapp/packages/plugin-resource-manager/src/PluginBootstrap.ts @@ -10,6 +10,7 @@ import { DATA_CONTEXT_NAV_NODE, EMainMenu, MainMenuService } from '@cloudbeaver/ import { AuthInfoService } from '@cloudbeaver/core-authentication'; import { Bootstrap, injectable } from '@cloudbeaver/core-di'; import { CommonDialogService, ConfirmationDialogDelete, DialogueStateResult } from '@cloudbeaver/core-dialogs'; +import { ServerConfigResource } from '@cloudbeaver/core-root'; import { SideBarPanelService } from '@cloudbeaver/core-ui'; import { ActionService, ACTION_DELETE, MenuService } from '@cloudbeaver/core-view'; import { isScript } from '@cloudbeaver/plugin-sql-editor-navigation-tab-resource'; @@ -26,6 +27,7 @@ export class PluginBootstrap extends Bootstrap { private readonly resourceManagerService: ResourceManagerService, private readonly sideBarPanelService: SideBarPanelService, private readonly navResourceNodeService: NavResourceNodeService, + private readonly serverConfigResource: ServerConfigResource, private readonly commonDialogService: CommonDialogService, private readonly actionService: ActionService, private readonly menuService: MenuService, @@ -41,7 +43,8 @@ export class PluginBootstrap extends Bootstrap { order: 3, type: 'checkbox', title: 'plugin_resource_manager_title', - isHidden: () => !this.resourceManagerService.enabled || !this.authInfoService.userInfo, + isHidden: () => !this.resourceManagerService.enabled + || (!this.authInfoService.userInfo && !this.serverConfigResource.data?.anonymousAccessEnabled), isChecked: () => this.resourceManagerService.panelEnabled, onClick: this.resourceManagerService.togglePanel, } @@ -53,7 +56,7 @@ export class PluginBootstrap extends Bootstrap { name: 'plugin_resource_manager_title', isHidden: () => !this.resourceManagerService.enabled || !this.resourceManagerService.panelEnabled - || !this.authInfoService.userInfo, + || (!this.authInfoService.userInfo && !this.serverConfigResource.data?.anonymousAccessEnabled), onClose: this.resourceManagerService.togglePanel, panel: () => ResourceManager, }); diff --git a/webapp/packages/plugin-resource-manager/src/ProjectsResource.ts b/webapp/packages/plugin-resource-manager/src/ProjectsResource.ts index 9d98092fba..f736f45c2e 100644 --- a/webapp/packages/plugin-resource-manager/src/ProjectsResource.ts +++ b/webapp/packages/plugin-resource-manager/src/ProjectsResource.ts @@ -22,11 +22,14 @@ export class ProjectsResource extends CachedDataResource { constructor( private readonly graphQLService: GraphQLService, - userInfoResource: UserInfoResource, + private readonly userInfoResource: UserInfoResource, ) { super([]); - this.sync(userInfoResource); + this.userInfoResource.userChange.addPostHandler(() => { + this.loaded = false; + this.markOutdated(); + }); makeObservable(this, { userProject: computed, diff --git a/webapp/packages/plugin-resource-manager/src/Tree/ResourceManagerTree.tsx b/webapp/packages/plugin-resource-manager/src/Tree/ResourceManagerTree.tsx index 684e1bee24..1297e291cd 100644 --- a/webapp/packages/plugin-resource-manager/src/Tree/ResourceManagerTree.tsx +++ b/webapp/packages/plugin-resource-manager/src/Tree/ResourceManagerTree.tsx @@ -31,6 +31,12 @@ const styles = css` min-width: 100%; width: max-content; } + Loader { + display: flex; + height: 100%; + width: 100%; + min-width: 240px; + } div { box-sizing: border-box; max-width: 240px; @@ -48,7 +54,7 @@ export const ResourceManagerTree = observer(function ResourceManagerTree() { const { resource } = useDataResource(ResourceManagerTree, ProjectsResource, undefined); return styled(styles)( - + { if (action === ACTION_SAVE) { - return context.has(DATA_CONTEXT_SQL_EDITOR_STATE); + return !this.sqlEditorTabResourceService.state.has(this.navigationTabsService.currentTab?.id ?? '') && context.has(DATA_CONTEXT_SQL_EDITOR_STATE); } return false; @@ -63,46 +63,34 @@ export class PluginBootstrap extends Bootstrap { const state = context.get(DATA_CONTEXT_SQL_EDITOR_STATE); if (action === ACTION_SAVE) { - const currentTab = this.navigationTabsService.currentTab; - const resourceTabState = this.sqlEditorTabResourceService.state.get(currentTab?.id ?? ''); + const tabName = this.sqlEditorTabService.getName(state); + const result = await this.commonDialogService.open(SaveScriptDialog, { + defaultScriptName: tabName, + }); - if (resourceTabState) { + if (result != DialogueStateResult.Rejected && result !== DialogueStateResult.Resolved) { try { - await this.navResourceNodeService.write(resourceTabState.nodeId, state.query); - this.notificationService.logSuccess({ title: 'plugin_resource_manager_update_script_success' }); - } catch (exception) { - this.notificationService.logException(exception as any, 'plugin_resource_manager_update_script_error'); - } - } else { - const tabName = this.sqlEditorTabService.getName(state); - const result = await this.commonDialogService.open(SaveScriptDialog, { - defaultScriptName: tabName, - }); + await this.projectsResource.load(); + const scriptName = `${result.trim()}.${SCRIPT_EXTENSION}`; + const folder = createPath([RESOURCES_NODE_PATH, this.projectsResource.userProject?.name]); + const nodeId = await this.navResourceNodeService.saveScript(folder, scriptName, state.query); - if (result != DialogueStateResult.Rejected && result !== DialogueStateResult.Resolved) { - try { - await this.projectsResource.load(); - const scriptName = `${result.trim()}.${SCRIPT_EXTENSION}`; - const folder = createPath([RESOURCES_NODE_PATH, this.projectsResource.userProject?.name]); - const nodeId = await this.navResourceNodeService.saveScript(folder, scriptName, state.query); + await this.navTreeResource.preloadNodeParents(NodeManagerUtils.parentsFromPath(nodeId), nodeId); + const node = await this.navNodeInfoResource.load(nodeId); - await this.navTreeResource.preloadNodeParents(NodeManagerUtils.parentsFromPath(nodeId), nodeId); - const node = await this.navNodeInfoResource.load(nodeId); - - if (currentTab) { - this.sqlEditorTabResourceService.linkTab(currentTab.id, node.id); - } - - this.sqlEditorService.setName(node.name ?? scriptName, state); - this.notificationService.logSuccess({ title: 'plugin_resource_manager_save_script_success', message: node.name }); - - if (!this.resourceManagerService.panelEnabled) { - this.resourceManagerService.togglePanel(); - } - - } catch (exception) { - this.notificationService.logException(exception as any, 'plugin_resource_manager_save_script_error'); + if (this.navigationTabsService.currentTab) { + this.sqlEditorTabResourceService.linkTab(this.navigationTabsService.currentTab.id, node.id); } + + this.sqlEditorService.setName(node.name ?? scriptName, state); + this.notificationService.logSuccess({ title: 'plugin_resource_manager_save_script_success', message: node.name }); + + if (!this.resourceManagerService.panelEnabled) { + this.resourceManagerService.togglePanel(); + } + + } catch (exception) { + this.notificationService.logException(exception as any, 'plugin_resource_manager_save_script_error'); } } }