Files
cloudbeaver/webapp/packages/plugin-devtools/src/DevToolsService.ts
T
eaa26dfe52 CB-4619 user scope settings (#2471)
* CB-4619 feat: update gql schema

* CB-4808 bulk update user parameters

* CB-4808 param type fix

* CB-4619 feat: updateUserPreferences API


* CB-4619 refactor: settings api

* CB-4619 refactor: move file

* CB-4619 refactor: settings api

* CB-4619 fix: pr review

* CB-4619 refactor: remove web-based product settings

* CB-4619 fix: after pr review

* CB-4619 refactor: move product conf to cloudbeaver conf

* CB-4619 fix: hide settings bar and log exception with changing session language

* CB-4619 fix: revert after merge

* CB-4808 new settings api

* CB-4808 update product.conf format

* CB-4808 update product.conf format

* CB-4619 feat: support server provided settings

* CB-4619 feat: prettify settings

* CB-4619 chore: map sql editor settings group

* CB-4808 add use short/long object name settings to CloudBeaver

* CB-4808 update default product.conf

* CB-4808 mode short/long settings to SQLModelPreferences

* CB-4808 review fix

* CB-4619 refactor: unit tests

* CB-4619 fix: prevent websocket opening spam

* CB-4619 fix: dependencies

* CB-4619 fix: remove extra theme loading

* CB-4619 fix: rename settings alias resolver file

* CB-4619 fix: after review

* CB-4619 fix conflicts

* CB-4619 rename server property

* CB-4619 remove shortname property

* CB-4619 fix legacy product conf reading

* CB-4619 merge root and runtime configurations

* CB-4619 chore: remove log viewer setting

* CB-4619 integer fields with env variables fix

* CB-4619 fix: property naming

* CB-4619 fix: parseJSONFlat null values

* CB-4619 fix: settings loading

* CB-4619 fix: save only actual settings

---------

Co-authored-by: Aleksandr Skoblikov <aleksandr.skoblikov@dbeaver.com>
Co-authored-by: kseniaguzeeva <112612526+kseniaguzeeva@users.noreply.github.com>
Co-authored-by: Evgenia Bezborodova <139753579+EvgeniaBzzz@users.noreply.github.com>
2024-03-28 10:30:52 +00:00

83 lines
2.1 KiB
TypeScript

/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 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 { makeObservable, observable } from 'mobx';
import { injectable } from '@cloudbeaver/core-di';
import { ServerConfigResource } from '@cloudbeaver/core-root';
import { StorageService } from '@cloudbeaver/core-storage';
interface IDevToolsSettings {
enabled: boolean;
distributed: boolean;
configuration: boolean;
}
const DEVTOOLS = 'devtools';
@injectable()
export class DevToolsService {
get isEnabled(): boolean {
return this.settings.enabled;
}
get isDistributed(): boolean {
return this.settings.distributed;
}
get isConfiguration(): boolean {
return this.settings.configuration;
}
private readonly settings: IDevToolsSettings;
constructor(
private readonly serverConfigResource: ServerConfigResource,
private readonly storageService: StorageService,
) {
this.settings = getDefaultDevToolsSettings();
makeObservable<this, 'settings'>(this, {
settings: observable,
});
this.storageService.registerSettings(DEVTOOLS, this.settings, getDefaultDevToolsSettings);
this.serverConfigResource.onDataUpdate.addHandler(this.syncSettingsOverride.bind(this));
}
switch() {
this.settings.enabled = !this.settings.enabled;
this.syncSettingsOverride();
}
setDistributedMode(distributed: boolean) {
this.settings.distributed = distributed;
this.syncSettingsOverride();
}
setConfigurationMode(configuration: boolean) {
this.settings.configuration = configuration;
this.syncSettingsOverride();
}
private syncSettingsOverride() {
if (this.isEnabled) {
if (this.serverConfigResource.data) {
this.serverConfigResource.data.distributed = this.isDistributed;
this.serverConfigResource.data.configurationMode = this.isConfiguration;
}
}
}
}
function getDefaultDevToolsSettings(): IDevToolsSettings {
return {
enabled: process.env.NODE_ENV === 'development',
distributed: false,
configuration: false,
};
}