Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cb 4548 sql editor resultsets can be closed one by one only when execute sql statement has been used for several queries #2503

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { createAction } from '@cloudbeaver/core-view';

export const ACTION_TAB_CLOSE_SQL_RESULT_GROUP = createAction('tab-close-sql-result-group', {
label: 'plugin_sql_editor_action_close_group',
tooltip: 'plugin_sql_editor_action_close_group',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { DATA_CONTEXT_TABS_CONTEXT, MENU_TAB } from '@cloudbeaver/core-ui';
import { ActionService, DATA_CONTEXT_MENU, MenuService } from '@cloudbeaver/core-view';

import { ACTION_TAB_CLOSE_SQL_RESULT_GROUP } from './ACTION_TAB_CLOSE_SQL_RESULT_GROUP';
import { DATA_CONTEXT_SQL_EDITOR_STATE } from './DATA_CONTEXT_SQL_EDITOR_STATE';
import { DATA_CONTEXT_SQL_EDITOR_RESULT_ID } from './SqlResultTabs/DATA_CONTEXT_SQL_EDITOR_RESULT_ID';
import { SqlResultTabsService } from './SqlResultTabs/SqlResultTabsService';

@injectable()
export class SqlEditorGroupTabsBootstrap extends Bootstrap {
constructor(
private readonly actionService: ActionService,
private readonly menuService: MenuService,
private readonly sqlResultTabsService: SqlResultTabsService,
) {
super();
}

register(): void {
this.menuService.addCreator({
isApplicable: context => {
const tab = context.tryGet(DATA_CONTEXT_SQL_EDITOR_RESULT_ID);
const state = context.tryGet(DATA_CONTEXT_TABS_CONTEXT);
const menu = context.hasValue(DATA_CONTEXT_MENU, MENU_TAB);
return !!tab && !!state?.enabledBaseActions && menu;
},
getItems: (context, items) => [...items, ACTION_TAB_CLOSE_SQL_RESULT_GROUP],
});
this.actionService.addHandler({
id: 'result-tabs-group-base-handler',
isActionApplicable: (context, action) => {
const menu = context.hasValue(DATA_CONTEXT_MENU, MENU_TAB);
const tab = context.tryGet(DATA_CONTEXT_SQL_EDITOR_RESULT_ID);
const sqlEditorState = context.tryGet(DATA_CONTEXT_SQL_EDITOR_STATE);
const groupId = sqlEditorState?.resultTabs.find(tabState => tabState.tabId === tab?.id)?.groupId;
const hasTabsInGroup = (sqlEditorState?.resultTabs.filter(tabState => tabState.groupId === groupId) ?? []).length > 1;
if (!menu || !tab || !hasTabsInGroup) {
return false;
}
return [ACTION_TAB_CLOSE_SQL_RESULT_GROUP].includes(action);
},
handler: async (context, action) => {
const state = context.get(DATA_CONTEXT_SQL_EDITOR_STATE);
const tab = context.get(DATA_CONTEXT_SQL_EDITOR_RESULT_ID);
switch (action) {
case ACTION_TAB_CLOSE_SQL_RESULT_GROUP:
this.sqlResultTabsService.closeTabGroup(state, tab.id);
Wroud marked this conversation as resolved.
Show resolved Hide resolved
break;
default:
break;
}
},
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const SqlResultTabs = observer<Props>(function SqlDataResult({ state, onT
}

async function handleClose(tab: ITabData) {
devnaumov marked this conversation as resolved.
Show resolved Hide resolved
const canClose = await sqlResultTabsService.canCloseResultTab(state, tab.tabId);
const canClose = handleCanClose(tab);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the fix of the ticket. the rest is about adding new action


if (canClose) {
sqlResultTabsService.removeResultTab(state, tab.tabId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ export class SqlResultTabsService {
}
}

async closeTabGroup(state: ISqlEditorTabState, tabId: string) {
const resultTab = state.resultTabs.find(tabState => tabState.tabId === tabId);
const groupResultTabs = state.resultTabs.filter(tab => tab.groupId === resultTab?.groupId);

if (groupResultTabs.length) {
for (const groupTab of groupResultTabs) {
const canClose = await this.sqlQueryResultService.canCloseResultTab(state, groupTab.tabId);

if (canClose) {
this.removeResultTab(state, groupTab.tabId);
}
}
}
}

private removeTab(state: ISqlEditorTabState, tab: ISqlEditorResultTab) {
state.tabs.splice(state.tabs.indexOf(tab), 1);

Expand Down
1 change: 1 addition & 0 deletions webapp/packages/plugin-sql-editor/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ export default [
['sql_editor_close_result_tabs_dialog_title', 'Confirm closing tabs'],
['plugin_sql_editor_action_overlay_title', 'Action required'],
['plugin_sql_editor_action_overlay_description', 'Please reopen editor to continue working.'],
['plugin_sql_editor_action_close_group', 'Close all of the same group'],
];
1 change: 1 addition & 0 deletions webapp/packages/plugin-sql-editor/src/locales/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export default [
['sql_editor_close_result_tabs_dialog_title', 'Confirm closing tabs'],
['plugin_sql_editor_action_overlay_title', 'Action required'],
['plugin_sql_editor_action_overlay_description', 'Please reopen editor to continue working.'],
['plugin_sql_editor_action_close_group', 'Close all of the same group'],
];
1 change: 1 addition & 0 deletions webapp/packages/plugin-sql-editor/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ export default [
['sql_editor_close_result_tabs_dialog_title', 'Подтвердить закрытие вкладок'],
['plugin_sql_editor_action_overlay_title', 'Требуется действие'],
['plugin_sql_editor_action_overlay_description', 'Пожалуйста, перезапустите редактор для продолжения работы.'],
['plugin_sql_editor_action_close_group', 'Закрыть все из группы'],
];
1 change: 1 addition & 0 deletions webapp/packages/plugin-sql-editor/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ export default [
['sql_editor_close_result_tabs_dialog_title', 'Confirm closing tabs'],
['plugin_sql_editor_action_overlay_title', 'Action required'],
['plugin_sql_editor_action_overlay_description', 'Please reopen editor to continue working.'],
['plugin_sql_editor_action_close_group', 'Close all of the same group'],
];
4 changes: 3 additions & 1 deletion webapp/packages/plugin-sql-editor/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import { MenuBootstrap } from './MenuBootstrap';
import { LocalStorageSqlDataSourceBootstrap } from './SqlDataSource/LocalStorage/LocalStorageSqlDataSourceBootstrap';
import { SqlDataSourceService } from './SqlDataSource/SqlDataSourceService';
import { SqlDialectInfoService } from './SqlDialectInfoService';
import { SqlEditorGroupTabsBootstrap } from './SqlEditorGroupTabsBootstrap';
import { SqlEditorModeService } from './SqlEditorModeService';
import { SqlEditorService } from './SqlEditorService';
import { SqlEditorSettingsService } from './SqlEditorSettingsService';
import { SqlEditorView } from './SqlEditorView';
import { SqlExecutionPlanService } from './SqlResultTabs/ExecutionPlan/SqlExecutionPlanService';
import { OutputMenuBootstrap } from './SqlResultTabs/OutputLogs/OutputMenuBootstrap';
import { OutputLogsEventHandler } from './SqlResultTabs/OutputLogs/OutputLogsEventHandler';
import { OutputLogsResource } from './SqlResultTabs/OutputLogs/OutputLogsResource';
import { OutputLogsService } from './SqlResultTabs/OutputLogs/OutputLogsService';
import { OutputMenuBootstrap } from './SqlResultTabs/OutputLogs/OutputMenuBootstrap';
import { SqlQueryResultService } from './SqlResultTabs/SqlQueryResultService';
import { SqlQueryService } from './SqlResultTabs/SqlQueryService';
import { SqlResultTabsService } from './SqlResultTabs/SqlResultTabsService';
Expand Down Expand Up @@ -48,5 +49,6 @@ export const sqlEditorPluginManifest: PluginManifest = {
OutputLogsResource,
OutputLogsService,
OutputMenuBootstrap,
SqlEditorGroupTabsBootstrap,
],
};
Loading