mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
refactor(core): navigation tabs api cleanup
This commit is contained in:
@@ -10,8 +10,6 @@ export interface ITabOptions<T = any> {
|
||||
id?: string;
|
||||
handlerId: string;
|
||||
handlerState: T;
|
||||
name?: string;
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
export interface ITab<T = any> extends ITabOptions<T> {
|
||||
|
||||
@@ -47,8 +47,8 @@ export class NavigationTabsService {
|
||||
return this.state.tabs;
|
||||
}
|
||||
|
||||
onTabSelect = new Subject<ITab>();
|
||||
onTabClose = new Subject<ITab>();
|
||||
readonly onTabSelect = new Subject<ITab>();
|
||||
readonly onTabClose = new Subject<ITab>();
|
||||
|
||||
constructor(
|
||||
private notificationService: NotificationService,
|
||||
@@ -64,8 +64,6 @@ export class NavigationTabsService {
|
||||
if (
|
||||
typeof value.id === 'string'
|
||||
&& typeof value.handlerId === 'string'
|
||||
&& (!value.name || typeof value.name === 'string')
|
||||
&& (!value.icon || typeof value.icon === 'string')
|
||||
) {
|
||||
map[key] = value;
|
||||
}
|
||||
|
||||
@@ -31,8 +31,6 @@ export type TabRestoreEvent<T = any> = (tab: ITab<T>) => Promise<boolean> | bool
|
||||
|
||||
export type TabHandlerOptions<TState = any> = {
|
||||
key: string;
|
||||
navigatorId: string;
|
||||
priority: number;
|
||||
getTabComponent(): TabHandlerTabComponent<TState>;
|
||||
getPanelComponent(): TabHandlerPanelComponent<TState>;
|
||||
onSelect?: TabHandlerEvent<TState>;
|
||||
@@ -43,7 +41,6 @@ export type TabHandlerOptions<TState = any> = {
|
||||
|
||||
export class TabHandler<TState = any> {
|
||||
key: string
|
||||
navigatorId: string
|
||||
getTabComponent: () => TabHandlerTabComponent<TState>;
|
||||
getPanelComponent: () => TabHandlerPanelComponent<TState>;
|
||||
onSelect?: TabHandlerEvent<TState>
|
||||
@@ -53,7 +50,6 @@ export class TabHandler<TState = any> {
|
||||
|
||||
constructor(options: TabHandlerOptions<TState>) {
|
||||
this.key = options.key;
|
||||
this.navigatorId = options.navigatorId;
|
||||
this.getTabComponent = options.getTabComponent;
|
||||
this.getPanelComponent = options.getPanelComponent;
|
||||
this.onSelect = options.onSelect;
|
||||
|
||||
@@ -34,7 +34,7 @@ export interface ITableViewerModelOptions {
|
||||
containerNodePath?: string;
|
||||
resultId?: string | null; // will be filled after fist data fetch
|
||||
executionContext?: IExecutionContext | null; // will be filled before fist data fetch
|
||||
sourceName?: string;
|
||||
sourceName?: string; // TODO: refactor it, used for showing sql query for export
|
||||
initialState?: IRequestDataResult;
|
||||
noLoaderWhileRequestingDataAsync?: boolean;
|
||||
requestDataAsync(model: TableViewerModel, rowOffset: number, count: number): Promise<IRequestDataResult>;
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
export interface IObjectViewerTabState {
|
||||
objectId: string;
|
||||
folderId: string;
|
||||
tabIcon?: string;
|
||||
tabTitle?: string;
|
||||
pageId: string;
|
||||
pagesState: Map<string, any>;
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ export const ObjectViewerTab = observer(function ObjectViewerTab({
|
||||
|
||||
return styled(useStyles(...style))(
|
||||
<Tab tabId={tab.id} onOpen={onSelect} onClose={onClose} >
|
||||
<TabIcon icon={node?.icon || tab.icon} />
|
||||
<TabTitle title={node?.name || tab.name} />
|
||||
<TabIcon icon={node?.icon || tab.handlerState.tabIcon} />
|
||||
<TabTitle title={node?.name || tab.handlerState.tabTitle} />
|
||||
</Tab>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -46,8 +46,6 @@ export class ObjectViewerTabService {
|
||||
this.tabHandler = this.navigationTabsService
|
||||
.registerTabHandler<IObjectViewerTabState>({
|
||||
key: objectViewerTabHandlerKey,
|
||||
navigatorId: 'database',
|
||||
priority: 1,
|
||||
getTabComponent: () => ObjectViewerTab,
|
||||
getPanelComponent: () => ObjectViewerPanel,
|
||||
onRestore: this.restoreObjectTab.bind(this),
|
||||
@@ -132,11 +130,16 @@ export class ObjectViewerTabService {
|
||||
}
|
||||
|
||||
async restoreObjectTab(tab: ITab<IObjectViewerTabState>) {
|
||||
if (typeof tab.handlerState?.folderId === 'string' && typeof tab.handlerState?.objectId === 'string') {
|
||||
if (
|
||||
typeof tab.handlerState?.folderId === 'string'
|
||||
&& typeof tab.handlerState?.objectId === 'string'
|
||||
&& (!tab.handlerState.tabIcon || typeof tab.handlerState.tabIcon === 'string')
|
||||
&& (!tab.handlerState.tabTitle || typeof tab.handlerState.tabTitle === 'string')
|
||||
) {
|
||||
const node = await this.nodesManagerService.loadNodeInfo(tab.handlerState.objectId);
|
||||
if (node) {
|
||||
tab.icon = node.icon;
|
||||
tab.name = node.name;
|
||||
tab.handlerState.tabIcon = node.icon;
|
||||
tab.handlerState.tabTitle = node.name;
|
||||
|
||||
return this.dbObjectPageService.restorePages(tab);
|
||||
}
|
||||
@@ -162,8 +165,8 @@ export class ObjectViewerTabService {
|
||||
);
|
||||
|
||||
if (tab) {
|
||||
tab.name = nodeInfo.name;
|
||||
tab.icon = nodeInfo.icon;
|
||||
tab.handlerState.tabIcon = nodeInfo.icon;
|
||||
tab.handlerState.tabTitle = nodeInfo.name;
|
||||
tabInfo.registerTab(tab);
|
||||
} else {
|
||||
tabInfo.openNewTab<IObjectViewerTabState>({
|
||||
@@ -173,9 +176,9 @@ export class ObjectViewerTabService {
|
||||
folderId: nodeInfo.folderId,
|
||||
pageId: '',
|
||||
pagesState: new Map(),
|
||||
tabIcon: nodeInfo.icon,
|
||||
tabTitle: nodeInfo.name,
|
||||
},
|
||||
name: nodeInfo.name,
|
||||
icon: nodeInfo.icon,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,8 +43,6 @@ export class SqlEditorTabService {
|
||||
this.tabHandler = this.navigationTabsService
|
||||
.registerTabHandler<ISqlEditorTabState>({
|
||||
key: sqlEditorTabHandlerKey,
|
||||
navigatorId: 'sql-editor',
|
||||
priority: 1,
|
||||
getTabComponent: () => SqlEditorTab,
|
||||
getPanelComponent: () => SqlEditorPanel,
|
||||
onRestore: this.handleTabRestore.bind(this),
|
||||
|
||||
Reference in New Issue
Block a user