feat: CB-694 disable active connection view

This commit is contained in:
Wroud
2021-02-04 22:45:55 +03:00
parent c969908545
commit 736a7fc7cd
12 changed files with 94 additions and 93 deletions
@@ -6,7 +6,7 @@
* you may not use this file except in compliance with the License.
*/
import { ConnectionViewService } from '@cloudbeaver/core-connections';
import { ConnectionInfoResource, isSimpleNavigatorView } from '@cloudbeaver/core-connections';
import { injectable } from '@cloudbeaver/core-di';
import { ContextMenuService, IMenuPanel } from '@cloudbeaver/core-dialogs';
import { NotificationService } from '@cloudbeaver/core-events';
@@ -25,8 +25,8 @@ export class NavigationTreeContextMenuService {
constructor(
private contextMenuService: ContextMenuService,
private navNodeManagerService: NavNodeManagerService,
private connectionViewService: ConnectionViewService,
private notificationService: NotificationService
private notificationService: NotificationService,
private connectionInfoResource: ConnectionInfoResource
) { }
getMenuToken() {
@@ -46,11 +46,23 @@ export class NavigationTreeContextMenuService {
});
}
private isConnectionSimpleView(nodeId: string): boolean {
const connectionId = NodeManagerUtils.connectionNodeIdToConnectionId(nodeId);
const connection = this.connectionInfoResource.get(connectionId);
if (!connection) {
return false;
}
return isSimpleNavigatorView(connection.navigatorSettings);
}
private async changeConnectionView(nodeId: string, simple: boolean) {
const connectionId = NodeManagerUtils.connectionNodeIdToConnectionId(nodeId);
try {
await this.connectionViewService.changeConnectionView(connectionId, simple);
await this.connectionInfoResource.changeConnectionView(connectionId, simple);
await this.navNodeManagerService.refreshTree(nodeId);
} catch (exception) {
this.notificationService.logException(exception);
@@ -76,6 +88,7 @@ export class NavigationTreeContextMenuService {
{
id: 'simple',
title: 'app_navigationTree_connection_view_option_simple',
isDisabled: context => this.isConnectionSimpleView(context.data.id),
isPresent(context) {
return context.contextType === NavigationTreeContextMenuService.nodeContextType
&& context.data.objectFeatures.includes(EObjectFeature.dataSource);
@@ -88,6 +101,7 @@ export class NavigationTreeContextMenuService {
{
id: 'advanced',
title: 'app_navigationTree_connection_view_option_advanced',
isDisabled: context => !this.isConnectionSimpleView(context.data.id),
isPresent(context) {
return context.contextType === NavigationTreeContextMenuService.nodeContextType
&& context.data.objectFeatures.includes(EObjectFeature.dataSource);
@@ -56,7 +56,6 @@ import {
NetworkHandlerResource,
DatabaseAuthModelsResource,
ConnectionAuthService,
ConnectionViewService,
ConnectionsAdministrationService,
ConnectionsResource,
ConnectionsLocaleService,
@@ -159,7 +158,6 @@ export const coreManifest: PluginManifest = {
NavigationTabsService,
DatabaseAuthModelsResource,
ConnectionAuthService,
ConnectionViewService,
ConnectionsAdministrationNavService,
ConnectionManualService,
ConnectionSearchService,
@@ -22,6 +22,7 @@ import {
} from '@cloudbeaver/core-sdk';
import { ConnectionsResource } from './Administration/ConnectionsResource';
import { CONNECTION_NAVIGATOR_VIEW_SETTINGS } from './ConnectionNavigatorViewSettings';
export type Connection = UserConnectionFragment & { authProperties?: UserConnectionAuthPropertiesFragment[] };
@@ -136,6 +137,21 @@ export class ConnectionInfoResource extends CachedMapResource<string, Connection
return this.get(id)!;
}
async changeConnectionView(id: string, simple: boolean): Promise<Connection> {
await this.performUpdate(id, async () => {
const settings = simple ? CONNECTION_NAVIGATOR_VIEW_SETTINGS.simple : CONNECTION_NAVIGATOR_VIEW_SETTINGS.advanced;
await this.graphQLService.sdk.setConnectionNavigatorSettings({
id,
settings,
});
});
await this.refresh(id); // TODO: setConnectionNavigatorSettings should return ConnectionInfo
return this.get(id)!;
}
async close(connectionId: string): Promise<Connection> {
await this.performUpdate(connectionId, async () => {
const connection = await this.closeConnection(connectionId);
@@ -32,5 +32,7 @@ export const CONNECTION_NAVIGATOR_VIEW_SETTINGS: Record<NavigatorView, Navigator
};
export function isSimpleNavigatorView(settings: NavigatorSettingsInput): boolean {
return settings.hideVirtualModel && settings.showOnlyEntities && settings.hideFolders;
const simple = CONNECTION_NAVIGATOR_VIEW_SETTINGS.simple;
return !Object.keys(simple)
.some(key => settings[key as keyof NavigatorSettingsInput] !== simple[key as keyof NavigatorSettingsInput]);
}
@@ -1,28 +0,0 @@
/*
* cloudbeaver - Cloud Database Manager
* Copyright (C) 2020 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 { injectable } from '@cloudbeaver/core-di';
import { GraphQLService } from '@cloudbeaver/core-sdk';
import { CONNECTION_NAVIGATOR_VIEW_SETTINGS } from './ConnectionNavigatorViewSettings';
@injectable()
export class ConnectionViewService {
constructor(
private graphQLService: GraphQLService,
) { }
async changeConnectionView(connectionId: string, simple: boolean): Promise<void> {
const settings = simple ? CONNECTION_NAVIGATOR_VIEW_SETTINGS.simple : CONNECTION_NAVIGATOR_VIEW_SETTINGS.advanced;
await this.graphQLService.sdk.setConnectionNavigatorSettings({
id: connectionId,
settings,
});
}
}
@@ -14,7 +14,6 @@ export * from './extensions/IConnectionSetter';
export * from './ConnectionsManagerService';
export * from './ConnectionInfoResource';
export * from './ConnectionAuthService';
export * from './ConnectionViewService';
export * from './DriverPropertiesService';
export * from './EConnectionFeature';
export * from './ContainerResource';
@@ -0,0 +1,5 @@
query getTemplateConnections {
connections: templateConnections {
...UserConnection
}
}
@@ -1,16 +0,0 @@
query getTemplateConnections {
connections: templateConnections {
id
name
description
driverId
connected
readOnly
authNeeded
authModel
features
supportedDataFormats
}
}
@@ -0,0 +1,9 @@
fragment AllNavigatorSettings on NavigatorSettings {
showSystemObjects
showUtilityObjects
showOnlyEntities
mergeEntities
hideFolders
hideSchemas
hideVirtualModel
}
@@ -11,4 +11,8 @@ fragment UserConnection on ConnectionInfo {
features
supportedDataFormats
navigatorSettings {
...AllNavigatorSettings
}
}
@@ -21,13 +21,7 @@ query serverConfig {
}
productConfiguration
defaultNavigatorSettings {
showSystemObjects
showUtilityObjects
showOnlyEntities
mergeEntities
hideFolders
hideSchemas
hideVirtualModel
...AllNavigatorSettings
}
}
}
+38 -34
View File
@@ -1157,6 +1157,10 @@ export type GetDriverByIdQueryVariables = Exact<{
export interface GetDriverByIdQuery { driverList: Array<Pick<DriverInfo, 'id' | 'name' | 'icon'>> }
export type GetTemplateConnectionsQueryVariables = Exact<{ [key: string]: never }>;
export interface GetTemplateConnectionsQuery { connections: UserConnectionFragment[] }
export type InitConnectionMutationVariables = Exact<{
id: Scalars['ID'];
credentials?: Maybe<Scalars['Object']>;
@@ -1176,10 +1180,6 @@ export type SetConnectionNavigatorSettingsMutationVariables = Exact<{
export type SetConnectionNavigatorSettingsMutation = Pick<Mutation, 'setConnectionNavigatorSettings'>;
export type GetTemplateConnectionsQueryVariables = Exact<{ [key: string]: never }>;
export interface GetTemplateConnectionsQuery { connections: Array<Pick<ConnectionInfo, 'id' | 'name' | 'description' | 'driverId' | 'connected' | 'readOnly' | 'authNeeded' | 'authModel' | 'features' | 'supportedDataFormats'>> }
export type TestConnectionMutationVariables = Exact<{
config: ConnectionConfig;
}>;
@@ -1251,6 +1251,8 @@ export type AdminUserInfoFragment = (
& { origin: ObjectOriginInfoFragment }
);
export type AllNavigatorSettingsFragment = Pick<NavigatorSettings, 'showSystemObjects' | 'showUtilityObjects' | 'showOnlyEntities' | 'mergeEntities' | 'hideFolders' | 'hideSchemas' | 'hideVirtualModel'>;
export type NavNodeInfoFragment = (
Pick<NavigatorNodeInfo, 'id' | 'name' | 'hasChildren' | 'nodeType' | 'icon' | 'folder' | 'inline' | 'navigable' | 'features'>
& { object?: Maybe<Pick<DatabaseObjectInfo, 'features'>>; nodeDetails?: Maybe<NavNodePropertiesFragment[]> }
@@ -1262,7 +1264,10 @@ export type ObjectOriginInfoFragment = Pick<ObjectOrigin, 'type' | 'subType' | '
export type SessionStateFragment = Pick<SessionInfo, 'createTime' | 'lastAccessTime' | 'cacheExpired' | 'locale'>;
export type UserConnectionFragment = Pick<ConnectionInfo, 'id' | 'name' | 'description' | 'driverId' | 'connected' | 'readOnly' | 'authNeeded' | 'authModel' | 'features' | 'supportedDataFormats'>;
export type UserConnectionFragment = (
Pick<ConnectionInfo, 'id' | 'name' | 'description' | 'driverId' | 'connected' | 'readOnly' | 'authNeeded' | 'authModel' | 'features' | 'supportedDataFormats'>
& { navigatorSettings: AllNavigatorSettingsFragment }
);
export type UserConnectionAuthPropertiesFragment = Pick<ObjectPropertyInfo, 'id' | 'displayName' | 'description' | 'category' | 'dataType' | 'value' | 'validValues' | 'defaultValue' | 'features' | 'order'>;
@@ -1480,7 +1485,7 @@ export type ServerConfigQueryVariables = Exact<{ [key: string]: never }>;
export interface ServerConfigQuery {
serverConfig: (
Pick<ServerConfig, 'name' | 'version' | 'productConfiguration' | 'supportsCustomConnections' | 'supportsConnectionBrowser' | 'supportsWorkspaces' | 'sessionExpireTime' | 'anonymousAccessEnabled' | 'authenticationEnabled' | 'configurationMode' | 'developmentMode'>
& { supportedLanguages: Array<Pick<ServerLanguage, 'isoCode' | 'displayName' | 'nativeName'>>; defaultNavigatorSettings: Pick<NavigatorSettings, 'showSystemObjects' | 'showUtilityObjects' | 'showOnlyEntities' | 'mergeEntities' | 'hideFolders' | 'hideSchemas' | 'hideVirtualModel'> }
& { supportedLanguages: Array<Pick<ServerLanguage, 'isoCode' | 'displayName' | 'nativeName'>>; defaultNavigatorSettings: AllNavigatorSettingsFragment }
);
}
@@ -1637,6 +1642,17 @@ export const SessionStateFragmentDoc = `
locale
}
`;
export const AllNavigatorSettingsFragmentDoc = `
fragment AllNavigatorSettings on NavigatorSettings {
showSystemObjects
showUtilityObjects
showOnlyEntities
mergeEntities
hideFolders
hideSchemas
hideVirtualModel
}
`;
export const UserConnectionFragmentDoc = `
fragment UserConnection on ConnectionInfo {
id
@@ -1649,8 +1665,11 @@ export const UserConnectionFragmentDoc = `
authModel
features
supportedDataFormats
navigatorSettings {
...AllNavigatorSettings
}
}
`;
${AllNavigatorSettingsFragmentDoc}`;
export const UserConnectionNetworkHandlerPropertiesFragmentDoc = `
fragment UserConnectionNetworkHandlerProperties on ObjectPropertyInfo {
id
@@ -2029,6 +2048,13 @@ export const GetDriverByIdDocument = `
}
}
`;
export const GetTemplateConnectionsDocument = `
query getTemplateConnections {
connections: templateConnections {
...UserConnection
}
}
${UserConnectionFragmentDoc}`;
export const InitConnectionDocument = `
mutation initConnection($id: ID!, $credentials: Object, $saveCredentials: Boolean) {
connection: initConnection(
@@ -2050,22 +2076,6 @@ export const SetConnectionNavigatorSettingsDocument = `
setConnectionNavigatorSettings(id: $id, settings: $settings)
}
`;
export const GetTemplateConnectionsDocument = `
query getTemplateConnections {
connections: templateConnections {
id
name
description
driverId
connected
readOnly
authNeeded
authModel
features
supportedDataFormats
}
}
`;
export const TestConnectionDocument = `
mutation testConnection($config: ConnectionConfig!) {
testConnection(config: $config) {
@@ -2469,17 +2479,11 @@ export const ServerConfigDocument = `
}
productConfiguration
defaultNavigatorSettings {
showSystemObjects
showUtilityObjects
showOnlyEntities
mergeEntities
hideFolders
hideSchemas
hideVirtualModel
...AllNavigatorSettings
}
}
}
`;
${AllNavigatorSettingsFragmentDoc}`;
export const SessionPermissionsDocument = `
query sessionPermissions {
permissions: sessionPermissions
@@ -2651,6 +2655,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
getDriverById(variables: GetDriverByIdQueryVariables): Promise<GetDriverByIdQuery> {
return withWrapper(() => client.request<GetDriverByIdQuery>(GetDriverByIdDocument, variables));
},
getTemplateConnections(variables?: GetTemplateConnectionsQueryVariables): Promise<GetTemplateConnectionsQuery> {
return withWrapper(() => client.request<GetTemplateConnectionsQuery>(GetTemplateConnectionsDocument, variables));
},
initConnection(variables: InitConnectionMutationVariables): Promise<InitConnectionMutation> {
return withWrapper(() => client.request<InitConnectionMutation>(InitConnectionDocument, variables));
},
@@ -2660,9 +2667,6 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
setConnectionNavigatorSettings(variables: SetConnectionNavigatorSettingsMutationVariables): Promise<SetConnectionNavigatorSettingsMutation> {
return withWrapper(() => client.request<SetConnectionNavigatorSettingsMutation>(SetConnectionNavigatorSettingsDocument, variables));
},
getTemplateConnections(variables?: GetTemplateConnectionsQueryVariables): Promise<GetTemplateConnectionsQuery> {
return withWrapper(() => client.request<GetTemplateConnectionsQuery>(GetTemplateConnectionsDocument, variables));
},
testConnection(variables: TestConnectionMutationVariables): Promise<TestConnectionMutation> {
return withWrapper(() => client.request<TestConnectionMutation>(TestConnectionDocument, variables));
},