mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
fix(plugin-resource-manager): CB-2019 1925 add createPath
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export function createPath(names: Array<string | undefined>): string {
|
||||
return names.filter(Boolean).join('/');
|
||||
}
|
||||
@@ -36,4 +36,5 @@ export * from './getTextFileReadingProcess';
|
||||
export * from './getTextBetween';
|
||||
export * from './timestampToDate';
|
||||
export * from './bytesToSize';
|
||||
export * from './isDefined';
|
||||
export * from './isDefined';
|
||||
export * from './createPath';
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
import { NavNodeInfoResource, NavTreeResource } from '@cloudbeaver/core-app';
|
||||
import { injectable } from '@cloudbeaver/core-di';
|
||||
import { createPath } from '@cloudbeaver/core-utils';
|
||||
|
||||
import { ResourceManagerResource } from './ResourceManagerResource';
|
||||
import { RESOURCES_NODE_PATH } from './RESOURCES_NODE_PATH';
|
||||
@@ -30,7 +31,7 @@ export class NavResourceNodeService {
|
||||
|
||||
async saveScript(folderNodeId: string, name: string, script: string) {
|
||||
const resourceData = this.getResourceData(folderNodeId);
|
||||
const resourcePath = [resourceData.resourcePath, name].filter(Boolean).join('/');
|
||||
const resourcePath = createPath([resourceData.resourcePath, name]);
|
||||
await this.resourceManagerResource.createResource(resourceData.projectId, resourcePath, false);
|
||||
await this.resourceManagerResource.writeResource(resourceData.projectId, resourcePath, script);
|
||||
await this.navTreeResource.refreshTree(folderNodeId);
|
||||
|
||||
@@ -13,6 +13,7 @@ import { ElementsTree, NavigationTreeService, NavigationNodeControl } from '@clo
|
||||
import { Loader, useDataResource } from '@cloudbeaver/core-blocks';
|
||||
import { useService } from '@cloudbeaver/core-di';
|
||||
import { useTranslate } from '@cloudbeaver/core-localization';
|
||||
import { createPath } from '@cloudbeaver/core-utils';
|
||||
import { CaptureView } from '@cloudbeaver/core-view';
|
||||
|
||||
import { ProjectsResource } from '../ProjectsResource';
|
||||
@@ -50,7 +51,7 @@ export const ResourceManagerTree = observer(function ResourceManagerTree() {
|
||||
<Loader state={[resource]}>
|
||||
<CaptureView view={navTreeService}>
|
||||
<ElementsTree
|
||||
root={[RESOURCES_NODE_PATH, resource.userProject?.name].filter(Boolean).join('/')}
|
||||
root={createPath([RESOURCES_NODE_PATH, resource.userProject?.name])}
|
||||
getChildren={navTreeService.getChildren}
|
||||
loadChildren={navTreeService.loadNestedNodes}
|
||||
control={NavigationNodeControl}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { INodeNavigationData, NavigationTabsService, NavNodeInfoResource, NavNod
|
||||
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
|
||||
import { CommonDialogService, DialogueStateResult } from '@cloudbeaver/core-dialogs';
|
||||
import { NotificationService } from '@cloudbeaver/core-events';
|
||||
import { createPath } from '@cloudbeaver/core-utils';
|
||||
import { ActionService, ACTION_SAVE, DATA_CONTEXT_MENU, MenuService } from '@cloudbeaver/core-view';
|
||||
import { NavResourceNodeService, RESOURCE_NODE_TYPE, SaveScriptDialog, ResourceManagerService, ProjectsResource, RESOURCES_NODE_PATH } from '@cloudbeaver/plugin-resource-manager';
|
||||
import { DATA_CONTEXT_SQL_EDITOR_STATE, SqlEditorService, SQL_EDITOR_ACTIONS_MENU } from '@cloudbeaver/plugin-sql-editor';
|
||||
@@ -69,7 +70,7 @@ export class PluginBootstrap extends Bootstrap {
|
||||
try {
|
||||
await this.projectsResource.load();
|
||||
const scriptName = `${result.trim()}.${SCRIPT_EXTENSION}`;
|
||||
const folder = [RESOURCES_NODE_PATH, this.projectsResource.userProject?.name].filter(Boolean).join('/');
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user