Skip to content

Commit

Permalink
Merge branch 'devel' into CB-5158-te-the-pop-up-message-with-a-reload…
Browse files Browse the repository at this point in the history
…-button-appears-when-a-domain-is-changed
  • Loading branch information
kseniaguzeeva authored May 27, 2024
2 parents 622e327 + ea1f346 commit 6ca0041
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void expireIdleSessions() {

public Collection<BaseWebSession> getAllActiveSessions() {
synchronized (sessionMap) {
return sessionMap.values();
return new ArrayList<>(sessionMap.values());
}
}

Expand Down
9 changes: 8 additions & 1 deletion webapp/packages/core-connections/src/locales/en.ts
Original file line number Diff line number Diff line change
@@ -1,3 +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.
*/
export default [
['core_connections_connections_settings_group', 'Connections'],
['connections_administration_item', 'Connection Templates'],
Expand Down Expand Up @@ -28,7 +35,7 @@ export default [
['connections_connection_create_search_database', 'Search'],
['connections_connection_edit_save_credentials', 'Save credentials'],
['connections_connection_share_credentials', 'Share credentials'],
['connections_connection_share_credentials_tooltip', 'Share credentials across all users'],
['connections_connection_share_credentials_tooltip', 'Share credentials based on the team'],
['connections_connection_credentials_provisioning', 'Authentication credentials'],
['connections_connection_credentials_provisioning_description', 'You need to fill in or confirm the credentials to test this connection'],
['connections_connection_edit_authentication', 'Authentication'],
Expand Down
9 changes: 8 additions & 1 deletion webapp/packages/core-connections/src/locales/it.ts
Original file line number Diff line number Diff line change
@@ -1,3 +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.
*/
export default [
['core_connections_connections_settings_group', 'Connections'],
['connections_administration_item', 'Connection Templates'],
Expand Down Expand Up @@ -26,7 +33,7 @@ export default [
['connections_connection_create_search_database', 'Cerca'],
['connections_connection_edit_save_credentials', 'Salva le credenziali'],
['connections_connection_share_credentials', 'Share credentials'],
['connections_connection_share_credentials_tooltip', 'Share credentials across all users'],
['connections_connection_share_credentials_tooltip', 'Share credentials based on the team'],
['connections_connection_credentials_provisioning', 'Credenziali di autenticazione'],
['connections_connection_credentials_provisioning_description', 'Devi compilare o confermare le credenziali per provare questa connessione'],
['connections_connection_edit_authentication', 'Autenticazione'],
Expand Down
11 changes: 9 additions & 2 deletions webapp/packages/core-connections/src/locales/ru.ts
Original file line number Diff line number Diff line change
@@ -1,3 +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.
*/
export default [
['core_connections_connections_settings_group', 'Подключения'],
['connections_administration_item', 'Шаблоны подключений'],
Expand All @@ -24,8 +31,8 @@ export default [
['connections_connection_create_custom', 'Настроить'],
['connections_connection_create_search_database', 'Найти'],
['connections_connection_edit_save_credentials', ' Запомнить данные'],
['connections_connection_share_credentials', 'Запомнить данные для всех пользователей'],
['connections_connection_share_credentials_tooltip', 'Запомнить данные для всех пользователей'],
['connections_connection_share_credentials', 'Запомнить данные для команды'],
['connections_connection_share_credentials_tooltip', 'Запомнить данные для команды'],
['connections_connection_credentials_provisioning', 'Аутентификационные данные'],
['connections_connection_credentials_provisioning_description', 'Чтобы проверить подключение, необходимо заполнить или подтвердить данные доступа'],
['connections_connection_edit_authentication', 'Авторизация'],
Expand Down
9 changes: 8 additions & 1 deletion webapp/packages/core-connections/src/locales/zh.ts
Original file line number Diff line number Diff line change
@@ -1,3 +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.
*/
export default [
['core_connections_connections_settings_group', 'Connections'],
['connections_administration_item', 'Connection Templates'],
Expand Down Expand Up @@ -27,7 +34,7 @@ export default [
['connections_connection_create_search_database', '搜索'],
['connections_connection_edit_save_credentials', '保存凭据'],
['connections_connection_share_credentials', 'Share credentials'],
['connections_connection_share_credentials_tooltip', 'Share credentials across all users'],
['connections_connection_share_credentials_tooltip', 'Share credentials based on the team'],
['connections_connection_credentials_provisioning', '认证凭据'],
['connections_connection_credentials_provisioning_description', '您却要填写或确认凭据以测试此连接。'],
['connections_connection_edit_authentication', '认证'],
Expand Down
20 changes: 18 additions & 2 deletions webapp/packages/core-utils/src/debounce.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { debounce } from './debounce';
import { debounce, debounceAsync } from './debounce';

// https://jestjs.io/docs/timer-mocks
// Tell Jest to mock all timeout functions
Expand All @@ -23,6 +23,22 @@ describe('Debounce', () => {
// Fast-forward time
jest.runAllTimers();

expect(func).toBeCalledTimes(1);
expect(func).toHaveBeenCalledTimes(1);
});
});

describe('DebounceAsync', () => {
test('function should be executed just once', async () => {
const func = jest.fn(() => Promise.resolve(true));
const debouncedFunction = debounceAsync(func, 1000);

debouncedFunction();
debouncedFunction();
debouncedFunction();

// Fast-forward time
jest.runAllTimers();

expect(func).toHaveBeenCalledTimes(1);
});
});
24 changes: 24 additions & 0 deletions webapp/packages/core-utils/src/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,27 @@ export function debounce<T extends (...args: any[]) => any>(func: T, delay: numb
}, delay);
};
}

export function debounceAsync<T extends (...args: any[]) => Promise<any>>(func: T, delay: number): T {
let timeoutId: NodeJS.Timeout | null;

return function (this: any, ...args: Parameters<T>): Promise<ReturnType<T>> {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const context = this;

return new Promise((resolve, reject) => {
if (timeoutId) {
clearTimeout(timeoutId);
}

timeoutId = setTimeout(async () => {
try {
const result = await func.apply(context, args);
resolve(result);
} catch (error) {
reject(error);
}
}, delay);
});
} as T;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export interface ISQLEditorData {
readonly cursorSegment: ISQLScriptSegment | undefined;
readonly readonly: boolean;
readonly editing: boolean;
readonly isLineScriptEmpty: boolean;
readonly isScriptEmpty: boolean;
readonly isDisabled: boolean;
readonly isIncomingChanges: boolean;
Expand All @@ -42,7 +41,7 @@ export interface ISQLEditorData {
/** displays if last getHintProposals call ended with limit */
readonly hintsLimitIsMet: boolean;

updateParserScriptsThrottle(): Promise<void>;
updateParserScriptsDebounced(): Promise<void>;
setScript(query: string): void;
init(): void;
destruct(): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const SQLEditorActions = observer<Props>(function SQLEditorActions({ data
const styles = useS(style);
const translate = useTranslate();
const isActiveSegmentMode = getComputed(() => data.activeSegmentMode.activeSegmentMode);
const disabled = getComputed(() => data.isLineScriptEmpty || data.isDisabled);
const disabled = getComputed(() => data.isScriptEmpty || data.isDisabled);
const isQuery = data.dataSource?.hasFeature(ESqlDataSourceFeatures.query);
const isExecutable = data.dataSource?.hasFeature(ESqlDataSourceFeatures.executable);

Expand Down
36 changes: 20 additions & 16 deletions webapp/packages/plugin-sql-editor/src/SqlEditor/useSqlEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CommonDialogService, DialogueStateResult } from '@cloudbeaver/core-dial
import { NotificationService } from '@cloudbeaver/core-events';
import { SyncExecutor } from '@cloudbeaver/core-executor';
import type { SqlCompletionProposal, SqlDialectInfo, SqlScriptInfoFragment } from '@cloudbeaver/core-sdk';
import { createLastPromiseGetter, LastPromiseGetter, throttleAsync } from '@cloudbeaver/core-utils';
import { createLastPromiseGetter, debounceAsync, LastPromiseGetter, throttleAsync } from '@cloudbeaver/core-utils';

import type { ISqlEditorTabState } from '../ISqlEditorTabState';
import { ESqlDataSourceFeatures } from '../SqlDataSource/ESqlDataSourceFeatures';
Expand Down Expand Up @@ -104,12 +104,8 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData {
return this.dataSource?.isEditing() ?? false;
},

get isLineScriptEmpty(): boolean {
return !this.activeSegment?.query;
},

get isScriptEmpty(): boolean {
return this.value === '' || this.parser.scripts.length === 0;
return this.value === '';
},

get isDisabled(): boolean {
Expand Down Expand Up @@ -166,7 +162,7 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData {
untracked(() => {
this.sqlDialectInfoService.loadSqlDialectInfo(key).then(async () => {
try {
await this.updateParserScriptsThrottle();
await this.updateParserScriptsDebounced();
} catch {}
});
});
Expand Down Expand Up @@ -205,13 +201,14 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData {
this.hintsLimitIsMet = hints.length >= MAX_HINTS_LIMIT;

return hints;
}, 1000 / 3),
}, 300),

async formatScript(): Promise<void> {
if (this.isDisabled || this.isScriptEmpty || !this.dataSource?.executionContext) {
return;
}

await this.updateParserScripts();
const query = this.value;
const script = this.getExecutingQuery(false);

Expand All @@ -238,6 +235,8 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData {
if (!isQuery || !isExecutable) {
return;
}

await this.updateParserScripts();
const query = this.getSubQuery();

try {
Expand Down Expand Up @@ -269,6 +268,8 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData {
if (!isQuery || !isExecutable) {
return;
}

await this.updateParserScripts();
const query = this.getSubQuery();

try {
Expand All @@ -286,6 +287,7 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData {
return;
}

await this.updateParserScripts();
const query = this.getSubQuery();

try {
Expand Down Expand Up @@ -362,9 +364,9 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData {
this.dataSource?.setScript(query);
},

updateParserScriptsThrottle: throttleAsync(async function updateParserScriptsThrottle() {
updateParserScriptsDebounced: debounceAsync(async function updateParserScriptsThrottle() {
await data.updateParserScripts();
}, 1000 / 2),
}, 2000),

async updateParserScripts() {
if (!this.dataSource?.hasFeature(ESqlDataSourceFeatures.script)) {
Expand Down Expand Up @@ -402,7 +404,7 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData {
passEmpty?: boolean,
passDisabled?: boolean,
): Promise<T | undefined> {
if (!segment || (this.isDisabled && !passDisabled) || (!passEmpty && this.isLineScriptEmpty)) {
if (!segment || (this.isDisabled && !passDisabled) || (!passEmpty && this.isScriptEmpty)) {
return;
}

Expand Down Expand Up @@ -433,6 +435,8 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData {
const projectId = this.dataSource?.executionContext?.projectId;
const connectionId = this.dataSource?.executionContext?.connectionId;

await data.updateParserScripts();

if (!projectId || !connectionId || this.cursor.begin !== this.cursor.end) {
return this.getSubQuery();
}
Expand All @@ -443,12 +447,11 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData {

const result = await this.sqlEditorService.parseSQLQuery(projectId, connectionId, this.value, this.cursor.begin);

const segment = this.parser.getSegment(result.start, result.end);

if (!segment) {
throw new Error('Failed to get position');
if (result.end === 0 && result.start === 0) {
return;
}

const segment = this.parser.getSegment(result.start, result.end);
return segment;
},

Expand All @@ -469,6 +472,7 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData {
},
}),
{
getHintProposals: action.bound,
formatScript: action.bound,
executeQuery: action.bound,
executeQueryNewTab: action.bound,
Expand Down Expand Up @@ -507,7 +511,7 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData {
// ensure that cursor is in script boundaries
data.setCursor(data.cursor.begin, data.cursor.end);
data.parser.setScript(script);
data.updateParserScriptsThrottle().catch(() => {});
data.updateParserScriptsDebounced().catch(() => {});
data.onUpdate.execute();
},
],
Expand Down

0 comments on commit 6ca0041

Please sign in to comment.