mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 01:16:01 +00:00
single database configuration
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import _ from 'lodash';
|
||||
import React from 'react';
|
||||
import useStorage from './useStorage';
|
||||
import { useConnectionInfo, useConfig } from './metadataLoaders';
|
||||
import { useConnectionInfo, useConfig, getConnectionInfo } from './metadataLoaders';
|
||||
import usePrevious from './usePrevious';
|
||||
import useNewQuery from '../query/useNewQuery';
|
||||
import useShowModal from '../modals/showModal';
|
||||
@@ -48,11 +48,11 @@ function createStorageState(storageKey, defaultValue) {
|
||||
const [CurrentWidgetProvider, useCurrentWidget, useSetCurrentWidget] = createGlobalState('database');
|
||||
export { CurrentWidgetProvider, useCurrentWidget, useSetCurrentWidget };
|
||||
|
||||
const [CurrentDatabaseProvider, useCurrentDatabase, useSetCurrentDatabaseCore] = createGlobalState(null);
|
||||
const [CurrentDatabaseProvider, useCurrentDatabaseCore, useSetCurrentDatabaseCore] = createGlobalState(null);
|
||||
|
||||
function useSetCurrentDatabase() {
|
||||
const setDb = useSetCurrentDatabaseCore();
|
||||
const db = useCurrentDatabase();
|
||||
const db = useCurrentDatabaseCore();
|
||||
return (value) => {
|
||||
if (_.get(db, 'name') !== _.get(value, 'name') || _.get(db, 'connection._id') != _.get(value, 'connection._id')) {
|
||||
setDb(value);
|
||||
@@ -60,6 +60,33 @@ function useSetCurrentDatabase() {
|
||||
};
|
||||
}
|
||||
|
||||
function useCurrentDatabase() {
|
||||
const config = useConfig();
|
||||
const db = useCurrentDatabaseCore();
|
||||
|
||||
const [connection, setConnection] = React.useState(null);
|
||||
const loadSingleConnection = async () => {
|
||||
if (config && config.singleDatabase) {
|
||||
const conn = await getConnectionInfo({ conid: config.singleDatabase.conid });
|
||||
setConnection(conn);
|
||||
}
|
||||
};
|
||||
React.useEffect(() => {
|
||||
loadSingleConnection();
|
||||
}, [config]);
|
||||
|
||||
if (config && config.singleDatabase) {
|
||||
if (connection) {
|
||||
return {
|
||||
connection,
|
||||
name: config.singleDatabase.database,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
export { CurrentDatabaseProvider, useCurrentDatabase, useSetCurrentDatabase };
|
||||
|
||||
const [OpenedTabsProvider, useOpenedTabs, useSetOpenedTabs] = createStorageState('openedTabs', []);
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
useServerStatus,
|
||||
useDatabaseStatus,
|
||||
useDatabaseInfo,
|
||||
useConfig,
|
||||
} from '../utility/metadataLoaders';
|
||||
import {
|
||||
SearchBoxWrapper,
|
||||
@@ -131,7 +132,11 @@ function SqlObjectListWrapper() {
|
||||
const db = useCurrentDatabase();
|
||||
|
||||
if (!db) {
|
||||
return <ErrorInfo message="Database not selected" icon="img alert" />;
|
||||
return (
|
||||
<WidgetsInnerContainer>
|
||||
<ErrorInfo message="Database not selected" icon="img alert" />
|
||||
</WidgetsInnerContainer>
|
||||
);
|
||||
}
|
||||
const { name, connection } = db;
|
||||
|
||||
@@ -141,11 +146,14 @@ function SqlObjectListWrapper() {
|
||||
}
|
||||
|
||||
export default function DatabaseWidget() {
|
||||
const config = useConfig();
|
||||
return (
|
||||
<WidgetColumnBar>
|
||||
<WidgetColumnBarItem title="Connections" name="connections" height="50%">
|
||||
<ConnectionList />
|
||||
</WidgetColumnBarItem>
|
||||
{!config.singleDatabase && (
|
||||
<WidgetColumnBarItem title="Connections" name="connections" height="50%">
|
||||
<ConnectionList />
|
||||
</WidgetColumnBarItem>
|
||||
)}
|
||||
<WidgetColumnBarItem title="Tables, views, functions" name="dbObjects">
|
||||
<SqlObjectListWrapper />
|
||||
</WidgetColumnBarItem>
|
||||
|
||||
Reference in New Issue
Block a user