fix(plugin-resource-manager): CB-2019 remove save action for the linked tabs

This commit is contained in:
Naumov Alexey
2022-05-17 16:02:16 +02:00
parent eac3005794
commit a514dfd6b1
4 changed files with 41 additions and 41 deletions
@@ -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,
});
@@ -22,11 +22,14 @@ export class ProjectsResource extends CachedDataResource<Project[]> {
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,
@@ -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)(
<Loader state={[resource]}>
<Loader state={resource}>
<CaptureView view={navTreeService}>
<ElementsTree
root={createPath([RESOURCES_NODE_PATH, resource.userProject?.name])}
@@ -54,7 +54,7 @@ export class PluginBootstrap extends Bootstrap {
id: 'scripts-base-handler',
isActionApplicable: (context, action) => {
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');
}
}
}