Skip to content

Commit

Permalink
CB-4548 closes group tabs via tabs context close function (to save hi…
Browse files Browse the repository at this point in the history
…ghlight tab logic)
  • Loading branch information
sergeyteleshev committed Mar 28, 2024
1 parent de2003a commit c2d9255
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class SqlEditorGroupTabsBootstrap extends Bootstrap {
return items;
},
});

this.actionService.addHandler({
id: 'result-tabs-group-base-handler',
isActionApplicable: (context, action) => {
Expand All @@ -50,11 +51,13 @@ export class SqlEditorGroupTabsBootstrap extends Bootstrap {
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);
const sqlEditorState = context.get(DATA_CONTEXT_SQL_EDITOR_STATE);
const tabs = context.get(DATA_CONTEXT_TABS_CONTEXT);

switch (action) {
case ACTION_TAB_CLOSE_SQL_RESULT_GROUP:
this.sqlResultTabsService.closeTabGroup(state, tab.id);
this.sqlResultTabsService.closeTabGroup(sqlEditorState, tabs, context, tab.id);
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/
import { action, makeObservable } from 'mobx';

import type { IDataContextProvider } from '@cloudbeaver/core-data-context';
import { injectable } from '@cloudbeaver/core-di';
import type { ITabsContext } from '@cloudbeaver/core-ui';

import type { ISqlEditorResultTab, ISqlEditorTabState } from '../ISqlEditorTabState';
import { SqlExecutionPlanService } from './ExecutionPlan/SqlExecutionPlanService';
Expand Down Expand Up @@ -75,16 +77,16 @@ export class SqlResultTabsService {
}
}

async closeTabGroup(state: ISqlEditorTabState, tabId: string) {
async closeTabGroup(state: ISqlEditorTabState, tabsContext: ITabsContext, context: IDataContextProvider, 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);
const canClose = tabsContext.canClose(groupTab.tabId);

if (canClose) {
this.removeResultTab(state, groupTab.tabId);
tabsContext.close(groupTab.tabId);
}
}
}
Expand Down

0 comments on commit c2d9255

Please sign in to comment.