Skip to content

Commit

Permalink
CB-4548 pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyteleshev committed Mar 29, 2024
1 parent c2d9255 commit 2d6c8b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { IDataContextProvider } from '@cloudbeaver/core-data-context';
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';
Expand Down Expand Up @@ -43,26 +44,38 @@ export class SqlEditorGroupTabsBootstrap extends Bootstrap {
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 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(sqlEditorState, tabs, context, tab.id);
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 @@ -7,9 +7,7 @@
*/
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 All @@ -30,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 Expand Up @@ -77,21 +79,6 @@ export class SqlResultTabsService {
}
}

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 = tabsContext.canClose(groupTab.tabId);

if (canClose) {
tabsContext.close(groupTab.tabId);
}
}
}
}

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

Expand Down

0 comments on commit 2d6c8b1

Please sign in to comment.