mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
fix: CB-761 autosearch in easy-config connections
This commit is contained in:
@@ -45,7 +45,8 @@ export interface ITabInfo<
|
||||
}
|
||||
|
||||
export interface ITabsContainer<TProps = Record<string, any>, TOptions extends Record<string, any> = never> {
|
||||
tabInfoList: Array<ITabInfo<TProps, TOptions>>;
|
||||
readonly tabInfoList: Array<ITabInfo<TProps, TOptions>>;
|
||||
readonly selectedId: string | null;
|
||||
getTabInfo: (tabId: string) => ITabInfo<TProps, TOptions> | undefined;
|
||||
getDisplayed: (props?: TProps) => Array<ITabInfo<TProps, TOptions>>;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import { observable, makeObservable } from 'mobx';
|
||||
|
||||
import type { ITabInfo, ITabInfoOptions, ITabsContainer } from './ITabsContainer';
|
||||
|
||||
export class TabsContainer<TProps = Record<string, any>, TOptions extends Record<string, any> = never>
|
||||
export class TabsContainer<TProps = void, TOptions extends Record<string, any> = never>
|
||||
implements ITabsContainer<TProps, TOptions> {
|
||||
readonly tabInfoMap: Map<string, ITabInfo<TProps, TOptions>>;
|
||||
|
||||
@@ -19,12 +19,40 @@ implements ITabsContainer<TProps, TOptions> {
|
||||
.sort((a, b) => a.order - b.order);
|
||||
}
|
||||
|
||||
get selectedId(): string | null {
|
||||
return this.currentTabId;
|
||||
}
|
||||
|
||||
private currentTabId: string | null;
|
||||
|
||||
constructor() {
|
||||
makeObservable(this, {
|
||||
makeObservable<TabsContainer<TProps, TOptions>, 'currentTabId'>(this, {
|
||||
tabInfoMap: observable.shallow,
|
||||
currentTabId: observable,
|
||||
});
|
||||
|
||||
this.tabInfoMap = new Map();
|
||||
this.currentTabId = null;
|
||||
}
|
||||
|
||||
select(tabId: string | null, props: TProps): void {
|
||||
if (tabId === null) {
|
||||
this.currentTabId = tabId;
|
||||
return;
|
||||
}
|
||||
|
||||
const info = this.getTabInfo(tabId);
|
||||
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
|
||||
info.onOpen?.({
|
||||
tabId,
|
||||
props,
|
||||
});
|
||||
|
||||
this.currentTabId = tabId;
|
||||
}
|
||||
|
||||
getTabInfo(tabId: string): ITabInfo<TProps, TOptions> | undefined {
|
||||
|
||||
@@ -17,7 +17,9 @@ import { useObjectRef } from '../useObjectRef';
|
||||
import type { ITabData, ITabsContainer } from './TabsContainer/ITabsContainer';
|
||||
import { TabsContext, ITabsContext } from './TabsContext';
|
||||
|
||||
type Props<T = Record<string, any>> = T & React.PropsWithChildren<{
|
||||
type ExtractContainerProps<T> = T extends void ? Record<string, any> : T;
|
||||
|
||||
type Props<T = Record<string, any>> = ExtractContainerProps<T> & React.PropsWithChildren<{
|
||||
selectedId?: string;
|
||||
orientation?: 'horizontal' | 'vertical';
|
||||
currentTabId?: string | null;
|
||||
@@ -42,12 +44,13 @@ export const TabsState = observer(function TabsState<T = Record<string, any>>({
|
||||
onClose,
|
||||
...rest
|
||||
}: Props<T>): React.ReactElement | null {
|
||||
const props = rest as any as T;
|
||||
if (
|
||||
!selectedId
|
||||
&& currentTabId === undefined
|
||||
&& container
|
||||
) {
|
||||
const displayed = container.getDisplayed(rest as T);
|
||||
const displayed = container.getDisplayed(props);
|
||||
|
||||
if (displayed.length > 0) {
|
||||
selectedId = displayed[0].key;
|
||||
@@ -68,14 +71,14 @@ export const TabsState = observer(function TabsState<T = Record<string, any>>({
|
||||
const dynamic = useObjectRef({
|
||||
open: onOpen,
|
||||
close: onClose,
|
||||
props: rest as T,
|
||||
props,
|
||||
container,
|
||||
state,
|
||||
selectedId: selectedId || currentTabId,
|
||||
}, {
|
||||
open: onOpen,
|
||||
close: onClose,
|
||||
props: rest as T,
|
||||
props,
|
||||
container,
|
||||
state,
|
||||
});
|
||||
@@ -114,7 +117,7 @@ export const TabsState = observer(function TabsState<T = Record<string, any>>({
|
||||
|
||||
openExecutor.execute({
|
||||
tabId: state.selectedId!,
|
||||
props: rest as T,
|
||||
props,
|
||||
});
|
||||
}, [state.selectedId]);
|
||||
|
||||
@@ -133,7 +136,7 @@ export const TabsState = observer(function TabsState<T = Record<string, any>>({
|
||||
const value = useMemo<ITabsContext<T>>(() => ({
|
||||
state,
|
||||
tabsState,
|
||||
props: rest as T,
|
||||
props,
|
||||
container,
|
||||
openExecutor,
|
||||
closeExecutor,
|
||||
|
||||
+1
@@ -75,6 +75,7 @@ export class ConnectionsAdministrationService extends Bootstrap {
|
||||
if (!param) {
|
||||
this.createConnectionService.setCreateMethod();
|
||||
}
|
||||
this.createConnectionService.setCreateMethod(param);
|
||||
}
|
||||
|
||||
private async deactivateCreateMethod(param: string | null, configuration: boolean, outside: boolean) {
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ export class ConnectionSearchService {
|
||||
}
|
||||
|
||||
async load(): Promise<void> {
|
||||
if (this.administrationScreenService.isConfigurationMode) {
|
||||
if (this.administrationScreenService.isConfigurationMode && this.databases.length === 0) {
|
||||
await this.search();
|
||||
}
|
||||
}
|
||||
|
||||
+9
-4
@@ -28,7 +28,7 @@ export class CreateConnectionService {
|
||||
disabled = false;
|
||||
data: IConnectionFormDataOptions | null;
|
||||
|
||||
readonly tabsContainer: TabsContainer<any, ICreateMethodOptions>;
|
||||
readonly tabsContainer: TabsContainer<void, ICreateMethodOptions>;
|
||||
|
||||
constructor(
|
||||
private readonly connectionsAdministrationNavService: ConnectionsAdministrationNavService,
|
||||
@@ -66,7 +66,7 @@ export class CreateConnectionService {
|
||||
return this.tabsContainer.tabInfoList[0].key;
|
||||
}
|
||||
|
||||
setCreateMethod(method?: string): void {
|
||||
setCreateMethod(method?: string | null): void {
|
||||
if (!method) {
|
||||
const id = this.getDefault();
|
||||
|
||||
@@ -75,7 +75,7 @@ export class CreateConnectionService {
|
||||
}
|
||||
method = id;
|
||||
}
|
||||
this.connectionsAdministrationNavService.navToCreate(method);
|
||||
this.activateMethod(method);
|
||||
}
|
||||
|
||||
cancelCreate(): void {
|
||||
@@ -89,7 +89,7 @@ export class CreateConnectionService {
|
||||
return;
|
||||
}
|
||||
|
||||
this.connectionsAdministrationNavService.navToCreate(defaultId);
|
||||
this.activateMethod(defaultId);
|
||||
}
|
||||
|
||||
setConnectionTemplate(config: ConnectionConfig, availableDrivers: string[]): void {
|
||||
@@ -109,4 +109,9 @@ export class CreateConnectionService {
|
||||
method.options?.close?.();
|
||||
}
|
||||
}
|
||||
|
||||
private activateMethod(method: string) {
|
||||
this.tabsContainer.select(method);
|
||||
this.connectionsAdministrationNavService.navToCreate(method);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user