mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-10-24 11:35:54 +08:00
CB-3703 save product configuration from ui (#2334)
* CB-4560 api for saving product configuration * CB-4560 save product config in te * CB-4560 move update product config to mutations * CB-3703 feat: extend base components * CB-3703 feat: settings editor * CB-3703 chore: review fixes * CB-3703 chore: pr review * CB-3703 feat: update server configuration icon * CB-4560 add events * CB-3703 fix: localization * CB-3703 chore: localization --------- Co-authored-by: Alexey <wrouds@gmail.com> Co-authored-by: Evgenia Bezborodova <139753579+EvgeniaBzzz@users.noreply.github.com>
This commit is contained in:
co-authored by
Alexey
Evgenia Bezborodova
parent
11adc7d3d6
commit
fdde4348a2
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* 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 { ROOT_SETTINGS_GROUP } from '@cloudbeaver/core-plugin';
|
||||
|
||||
export const SQL_EDITOR_SETTINGS_GROUP = ROOT_SETTINGS_GROUP.createSubGroup('plugin_sql_editor_sql_editor_settings_group');
|
||||
+3
-3
@@ -8,7 +8,7 @@
|
||||
import { action, makeObservable, observable } from 'mobx';
|
||||
|
||||
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
|
||||
import { LocalStorageSaveService } from '@cloudbeaver/core-settings';
|
||||
import { SettingsService } from '@cloudbeaver/core-settings';
|
||||
|
||||
import { createSqlDataSourceHistoryInitialState } from '../SqlDataSourceHistory/createSqlDataSourceHistoryInitialState';
|
||||
import { validateSqlDataSourceHistoryState } from '../SqlDataSourceHistory/validateSqlDataSourceHistoryState';
|
||||
@@ -22,7 +22,7 @@ const localStorageKey = 'local-storage-sql-data-source';
|
||||
export class LocalStorageSqlDataSourceBootstrap extends Bootstrap {
|
||||
private readonly dataSourceStateState = new Map<string, ILocalStorageSqlDataSourceState>();
|
||||
|
||||
constructor(private readonly sqlDataSourceService: SqlDataSourceService, localStorageSaveService: LocalStorageSaveService) {
|
||||
constructor(private readonly sqlDataSourceService: SqlDataSourceService, settingsService: SettingsService) {
|
||||
super();
|
||||
this.dataSourceStateState = new Map();
|
||||
|
||||
@@ -31,7 +31,7 @@ export class LocalStorageSqlDataSourceBootstrap extends Bootstrap {
|
||||
dataSourceStateState: observable.deep,
|
||||
});
|
||||
|
||||
localStorageSaveService.withAutoSave(
|
||||
settingsService.registerSettings(
|
||||
localStorageKey,
|
||||
this.dataSourceStateState,
|
||||
() => new Map(),
|
||||
|
||||
@@ -71,9 +71,7 @@ export function useTools(state: ISqlEditorTabState): Readonly<State> {
|
||||
},
|
||||
|
||||
checkFileValidity(file: File) {
|
||||
const maxSize = this.sqlEditorSettingsService.settings.isValueDefault('maxFileSize')
|
||||
? this.sqlEditorSettingsService.deprecatedSettings.getValue('maxFileSize')
|
||||
: this.sqlEditorSettingsService.settings.getValue('maxFileSize');
|
||||
const maxSize = this.sqlEditorSettingsService.settings.getValue('maxFileSize');
|
||||
|
||||
const size = Math.round(file.size / 1024); // kilobyte
|
||||
const aboveMaxSize = size > maxSize;
|
||||
|
||||
@@ -74,31 +74,46 @@ const server = mockGraphQL(...mockAppInit(endpoint), ...mockAuthentication(endpo
|
||||
|
||||
beforeAll(() => app.init());
|
||||
|
||||
const testValue = 1;
|
||||
const testValueNew = 1;
|
||||
const testValueDeprecated = 2;
|
||||
|
||||
const equalConfig = {
|
||||
const deprecatedSettings = {
|
||||
core: {
|
||||
app: {
|
||||
sqlEditor: {
|
||||
maxFileSize: testValue,
|
||||
maxFileSize: testValueDeprecated,
|
||||
} as SqlEditorSettings,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const newSettings = {
|
||||
...deprecatedSettings,
|
||||
plugin: {
|
||||
'sql-editor': {
|
||||
maxFileSize: testValue,
|
||||
maxFileSize: testValueNew,
|
||||
} as SqlEditorSettings,
|
||||
},
|
||||
};
|
||||
|
||||
test('New settings equal deprecated settings', async () => {
|
||||
test('New settings override deprecated settings', async () => {
|
||||
const settings = app.injector.getServiceByClass(SqlEditorSettingsService);
|
||||
const config = app.injector.getServiceByClass(ServerConfigResource);
|
||||
|
||||
server.use(endpoint.query('serverConfig', mockServerConfig(equalConfig)));
|
||||
server.use(endpoint.query('serverConfig', mockServerConfig(newSettings)));
|
||||
|
||||
await config.refresh();
|
||||
|
||||
expect(settings.settings.getValue('maxFileSize')).toBe(testValue);
|
||||
expect(settings.deprecatedSettings.getValue('maxFileSize')).toBe(testValue);
|
||||
expect(settings.settings.getValue('maxFileSize')).toBe(testValueNew);
|
||||
});
|
||||
|
||||
test('Deprecated settings are used if new settings are not defined', async () => {
|
||||
const settings = app.injector.getServiceByClass(SqlEditorSettingsService);
|
||||
const config = app.injector.getServiceByClass(ServerConfigResource);
|
||||
|
||||
server.use(endpoint.query('serverConfig', mockServerConfig(deprecatedSettings)));
|
||||
|
||||
await config.refresh();
|
||||
|
||||
expect(settings.settings.getValue('maxFileSize')).toBe(testValueDeprecated);
|
||||
});
|
||||
|
||||
@@ -5,25 +5,61 @@
|
||||
* 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 { PluginManagerService, PluginSettings } from '@cloudbeaver/core-plugin';
|
||||
import { Dependency, injectable } from '@cloudbeaver/core-di';
|
||||
import { createSettingsAliasResolver, PluginManagerService, PluginSettings, SettingsManagerService } from '@cloudbeaver/core-plugin';
|
||||
import { ServerSettingsResolverService, ServerSettingsService } from '@cloudbeaver/core-root';
|
||||
import { schema } from '@cloudbeaver/core-utils';
|
||||
|
||||
const defaultSettings = {
|
||||
maxFileSize: 10 * 1024, // kilobyte
|
||||
disabled: false,
|
||||
autoSave: true,
|
||||
};
|
||||
const defaultSettings = schema.object({
|
||||
maxFileSize: schema.coerce.number().default(10 * 1024), // kilobyte
|
||||
disabled: schema.coerce.boolean().default(false),
|
||||
autoSave: schema.coerce.boolean().default(true),
|
||||
});
|
||||
|
||||
export type SqlEditorSettings = typeof defaultSettings;
|
||||
export type SqlEditorSettings = schema.infer<typeof defaultSettings>;
|
||||
|
||||
@injectable()
|
||||
export class SqlEditorSettingsService {
|
||||
readonly settings: PluginSettings<SqlEditorSettings>;
|
||||
/** @deprecated Use settings instead, will be removed in 23.0.0 */
|
||||
readonly deprecatedSettings: PluginSettings<SqlEditorSettings>;
|
||||
export class SqlEditorSettingsService extends Dependency {
|
||||
readonly settings: PluginSettings<typeof defaultSettings>;
|
||||
|
||||
constructor(private readonly pluginManagerService: PluginManagerService) {
|
||||
constructor(
|
||||
private readonly pluginManagerService: PluginManagerService,
|
||||
private readonly settingsManagerService: SettingsManagerService,
|
||||
private readonly serverSettingsService: ServerSettingsService,
|
||||
private readonly serverSettingsResolverService: ServerSettingsResolverService,
|
||||
) {
|
||||
super();
|
||||
this.settings = this.pluginManagerService.createSettings('sql-editor', 'plugin', defaultSettings);
|
||||
this.deprecatedSettings = this.pluginManagerService.getDeprecatedPluginSettings('core.app.sqlEditor', defaultSettings);
|
||||
this.serverSettingsResolverService.addResolver(
|
||||
/** @deprecated Use settings instead, will be removed in 23.0.0 */
|
||||
createSettingsAliasResolver(this.serverSettingsService, this.settings, 'core.app.sqlEditor'),
|
||||
);
|
||||
|
||||
this.registerSettings();
|
||||
}
|
||||
|
||||
private registerSettings() {
|
||||
this.settingsManagerService.registerSettings(this.settings, () => [
|
||||
// {
|
||||
// group: SQL_EDITOR_SETTINGS_GROUP,
|
||||
// key: 'disabled',
|
||||
// type: ESettingsValueType.Checkbox,
|
||||
// name: 'Disable SQL editor',
|
||||
// },
|
||||
// {
|
||||
// group: SQL_EDITOR_SETTINGS_GROUP,
|
||||
// key: 'maxFileSize',
|
||||
// type: ESettingsValueType.Input,
|
||||
// name: 'Max file size (KB)',
|
||||
// description: 'Max file size for SQL editor in kilobytes',
|
||||
// },
|
||||
// {
|
||||
// group: SQL_EDITOR_SETTINGS_GROUP,
|
||||
// key: 'autoSave',
|
||||
// type: ESettingsValueType.Checkbox,
|
||||
// name: 'Auto save',
|
||||
// description: 'Auto save SQL editor content',
|
||||
// },
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export default [
|
||||
['plugin_sql_editor_sql_editor_settings_group', 'SQL Editor'],
|
||||
['sql_editor_menu', 'SQL Editor'],
|
||||
['sql_editor_script_editor', 'SQL Editor'],
|
||||
['sql_editor_alias_loading_error', 'Error occurred while loading node alias'],
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export default [
|
||||
['plugin_sql_editor_sql_editor_settings_group', 'SQL Editor'],
|
||||
['sql_editor_menu', 'SQL Editor'],
|
||||
['sql_editor_script_editor', 'SQL Editor'],
|
||||
['sql_editor_alias_loading_error', 'Error occurred while loading node alias'],
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export default [
|
||||
['plugin_sql_editor_sql_editor_settings_group', 'SQL Редактор'],
|
||||
['sql_editor_menu', 'SQL Редактор'],
|
||||
['sql_editor_script_editor', 'Редактор SQL'],
|
||||
['sql_editor_alias_loading_error', 'Возникла ошибка при загрузке псевдонима'],
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export default [
|
||||
['plugin_sql_editor_sql_editor_settings_group', 'SQL Editor'],
|
||||
['sql_editor_menu', 'SQL编辑器'],
|
||||
['sql_editor_script_editor', 'SQL Editor'],
|
||||
['sql_editor_alias_loading_error', 'Error occurred while loading node alias'],
|
||||
|
||||
Reference in New Issue
Block a user