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 all 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,88 @@
/*
* 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 type { IDataContextProvider } from '@cloudbeaver/core-data-context';
devnaumov marked this conversation as resolved.
Show resolved Hide resolved
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { DATA_CONTEXT_TABS_CONTEXT, MENU_TAB } from '@cloudbeaver/core-ui';
import { ActionService, DATA_CONTEXT_MENU, menuExtractItems, 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],
orderItems: (context, items) => {
const actions = menuExtractItems(items, [ACTION_TAB_CLOSE_SQL_RESULT_GROUP]);

if (actions.length > 0) {
items.push(...actions);
}

return items;
},
});

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) => {
switch (action) {
case ACTION_TAB_CLOSE_SQL_RESULT_GROUP:
this.closeResultTabGroup(context);
break;
default:
break;
}
},
});
}

async closeResultTabGroup(context: IDataContextProvider) {
const tab = context.get(DATA_CONTEXT_SQL_EDITOR_RESULT_ID);
const sqlEditorState = context.get(DATA_CONTEXT_SQL_EDITOR_STATE);
const tabsContext = context.get(DATA_CONTEXT_TABS_CONTEXT);
const resultTabs = this.sqlResultTabsService.getResultTabs(sqlEditorState);

const resultTab = resultTabs.find(tabState => tabState.tabId === tab.id);
const groupResultTabs = resultTabs.filter(tab => tab.groupId === resultTab?.groupId);

groupResultTabs.forEach(groupTab => {
tabsContext.close(groupTab.tabId);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export const SqlResultTabs = observer<Props>(function SqlDataResult({ state, onT
onTabSelect?.(tab.tabId);
}

async function handleClose(tab: ITabData) {
const canClose = await sqlResultTabsService.canCloseResultTab(state, tab.tabId);
function handleClose(tab: ITabData) {
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 @@ -28,6 +28,10 @@ export class SqlResultTabsService {
});
}

getResultTabs(state: ISqlEditorTabState) {
return state.resultTabs;
}

async canCloseResultTab(state: ISqlEditorTabState, tabId: string): Promise<boolean> {
const tab = state.tabs.find(tab => tab.id === tabId);

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 query'],
];
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 query'],
];
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 query'],
];
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