mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 20:13:57 +00:00
dropdown for default database
This commit is contained in:
@@ -222,7 +222,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
test_meta: true,
|
test_meta: true,
|
||||||
test(connection) {
|
test({ connection, requestDbList }) {
|
||||||
const subprocess = fork(
|
const subprocess = fork(
|
||||||
global['API_PACKAGE'] || process.argv[1],
|
global['API_PACKAGE'] || process.argv[1],
|
||||||
[
|
[
|
||||||
@@ -237,7 +237,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
pipeForkLogs(subprocess);
|
pipeForkLogs(subprocess);
|
||||||
subprocess.send(connection);
|
subprocess.send({ connection, requestDbList });
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
subprocess.on('message', resp => {
|
subprocess.on('message', resp => {
|
||||||
if (handleProcessCommunication(resp, subprocess)) return;
|
if (handleProcessCommunication(resp, subprocess)) return;
|
||||||
|
|||||||
@@ -16,13 +16,19 @@ Platform: ${process.platform}
|
|||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
childProcessChecker();
|
childProcessChecker();
|
||||||
process.on('message', async connection => {
|
process.on('message', async args => {
|
||||||
|
// @ts-ignore
|
||||||
|
const { connection, requestDbList } = args;
|
||||||
if (handleProcessCommunication(connection)) return;
|
if (handleProcessCommunication(connection)) return;
|
||||||
try {
|
try {
|
||||||
const driver = requireEngineDriver(connection);
|
const driver = requireEngineDriver(connection);
|
||||||
const dbhan = await connectUtility(driver, connection, 'app');
|
const dbhan = await connectUtility(driver, connection, 'app');
|
||||||
const res = await driver.getVersion(dbhan);
|
const res = await driver.getVersion(dbhan);
|
||||||
process.send({ msgtype: 'connected', ...res });
|
let databases = undefined;
|
||||||
|
if (requestDbList) {
|
||||||
|
databases = await driver.listDatabases(dbhan);
|
||||||
|
}
|
||||||
|
process.send({ msgtype: 'connected', ...res, databases });
|
||||||
await driver.close(dbhan);
|
await driver.close(dbhan);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|||||||
@@ -7,21 +7,32 @@
|
|||||||
|
|
||||||
export let icon = 'icon chevron-down';
|
export let icon = 'icon chevron-down';
|
||||||
export let menu;
|
export let menu;
|
||||||
|
export let asyncMenu = undefined;
|
||||||
export let narrow = false;
|
export let narrow = false;
|
||||||
export let square = true;
|
export let square = true;
|
||||||
export let disabled = false;
|
export let disabled = false;
|
||||||
let domButton;
|
|
||||||
|
|
||||||
function handleClick() {
|
let domButton;
|
||||||
|
let isLoading = false;
|
||||||
|
|
||||||
|
async function handleClick() {
|
||||||
if (disabled) return;
|
if (disabled) return;
|
||||||
|
|
||||||
|
let items = menu;
|
||||||
|
|
||||||
|
if (asyncMenu) {
|
||||||
|
isLoading = true;
|
||||||
|
items = await asyncMenu();
|
||||||
|
isLoading = false;
|
||||||
|
}
|
||||||
|
|
||||||
const rect = domButton.getBoundingClientRect();
|
const rect = domButton.getBoundingClientRect();
|
||||||
const left = rect.left;
|
const left = rect.left;
|
||||||
const top = rect.bottom;
|
const top = rect.bottom;
|
||||||
currentDropDownMenu.set({ left, top, items: menu });
|
currentDropDownMenu.set({ left, top, items });
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<InlineButton {square} {narrow} on:click={handleClick} bind:this={domButton} {disabled}>
|
<InlineButton {square} {narrow} on:click={handleClick} bind:this={domButton} {disabled}>
|
||||||
<FontIcon {icon} />
|
<FontIcon icon={isLoading ? 'icon loading' : icon} />
|
||||||
</InlineButton>
|
</InlineButton>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
export let disabled = false;
|
export let disabled = false;
|
||||||
export let defaultValue;
|
export let defaultValue;
|
||||||
export let menu;
|
export let menu;
|
||||||
|
export let asyncMenu;
|
||||||
|
|
||||||
const { values, setFieldValue } = getFormContext();
|
const { values, setFieldValue } = getFormContext();
|
||||||
|
|
||||||
@@ -26,5 +27,5 @@
|
|||||||
value={$values[name] ?? defaultValue}
|
value={$values[name] ?? defaultValue}
|
||||||
on:input={e => setFieldValue(name, e.target['value'])}
|
on:input={e => setFieldValue(name, e.target['value'])}
|
||||||
/>
|
/>
|
||||||
<DropDownButton {menu} {disabled} />
|
<DropDownButton {menu} {asyncMenu} {disabled} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,7 +17,9 @@
|
|||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
import FormDropDownTextField from '../forms/FormDropDownTextField.svelte';
|
import FormDropDownTextField from '../forms/FormDropDownTextField.svelte';
|
||||||
|
|
||||||
const { values } = getFormContext();
|
export let getDatabaseList;
|
||||||
|
|
||||||
|
const { values, setFieldValue } = getFormContext();
|
||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
|
|
||||||
$: authType = $values.authType;
|
$: authType = $values.authType;
|
||||||
@@ -69,6 +71,14 @@
|
|||||||
'me-central-1',
|
'me-central-1',
|
||||||
'sa-east-1',
|
'sa-east-1',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
async function createDatabasesMenu() {
|
||||||
|
const databases = await getDatabaseList();
|
||||||
|
return databases.map(db => ({
|
||||||
|
text: db.name,
|
||||||
|
onClick: () => setFieldValue('defaultDatabase', db.name),
|
||||||
|
}));
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FormSelectField
|
<FormSelectField
|
||||||
@@ -377,11 +387,12 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if driver?.showConnectionField('defaultDatabase', $values, showConnectionFieldArgs)}
|
{#if driver?.showConnectionField('defaultDatabase', $values, showConnectionFieldArgs)}
|
||||||
<FormTextField
|
<FormDropDownTextField
|
||||||
label="Default database"
|
label="Default database"
|
||||||
name="defaultDatabase"
|
name="defaultDatabase"
|
||||||
disabled={isConnected}
|
disabled={isConnected}
|
||||||
data-testid="ConnectionDriverFields_defaultDatabase"
|
data-testid="ConnectionDriverFields_defaultDatabase"
|
||||||
|
asyncMenu={createDatabasesMenu}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@@ -412,7 +423,7 @@
|
|||||||
templateProps={{ noMargin: true }}
|
templateProps={{ noMargin: true }}
|
||||||
disabled={isConnected}
|
disabled={isConnected}
|
||||||
data-testid="ConnectionDriverFields_displayName"
|
data-testid="ConnectionDriverFields_displayName"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6 mr-1">
|
<div class="col-6 mr-1">
|
||||||
<FormColorField
|
<FormColorField
|
||||||
|
|||||||
@@ -63,15 +63,16 @@
|
|||||||
|
|
||||||
const testIdRef = createRef(0);
|
const testIdRef = createRef(0);
|
||||||
|
|
||||||
async function handleTest(e) {
|
async function handleTest(e, requestDbList = false) {
|
||||||
isTesting = true;
|
isTesting = true;
|
||||||
testIdRef.update(x => x + 1);
|
testIdRef.update(x => x + 1);
|
||||||
const testid = testIdRef.get();
|
const testid = testIdRef.get();
|
||||||
const resp = await apiCall('connections/test', e.detail);
|
const resp = await apiCall('connections/test', { connection: e.detail, requestDbList });
|
||||||
if (testIdRef.get() != testid) return;
|
if (testIdRef.get() != testid) return;
|
||||||
|
|
||||||
isTesting = false;
|
isTesting = false;
|
||||||
sqlConnectResult = resp;
|
sqlConnectResult = resp;
|
||||||
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCancelTest() {
|
function handleCancelTest() {
|
||||||
@@ -190,6 +191,14 @@
|
|||||||
$: isConnected = $openedConnections.includes($values._id) || $openedSingleDatabaseConnections.includes($values._id);
|
$: isConnected = $openedConnections.includes($values._id) || $openedSingleDatabaseConnections.includes($values._id);
|
||||||
|
|
||||||
// $: console.log('CONN VALUES', $values);
|
// $: console.log('CONN VALUES', $values);
|
||||||
|
|
||||||
|
async function getDatabaseList() {
|
||||||
|
const resp = await handleTest({ detail: getCurrentConnection() }, true);
|
||||||
|
if (resp && resp.msgtype == 'connected') {
|
||||||
|
return resp.databases;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FormProviderCore template={FormFieldTemplateLarge} {values}>
|
<FormProviderCore template={FormFieldTemplateLarge} {values}>
|
||||||
@@ -202,6 +211,7 @@
|
|||||||
{
|
{
|
||||||
label: 'General',
|
label: 'General',
|
||||||
component: ConnectionDriverFields,
|
component: ConnectionDriverFields,
|
||||||
|
props: { getDatabaseList },
|
||||||
},
|
},
|
||||||
driver?.showConnectionTab('sshTunnel', $values) && {
|
driver?.showConnectionTab('sshTunnel', $values) && {
|
||||||
label: 'SSH Tunnel',
|
label: 'SSH Tunnel',
|
||||||
@@ -223,20 +233,24 @@
|
|||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
{#if onlyTestButton}
|
{#if onlyTestButton}
|
||||||
{#if isTesting}
|
{#if isTesting}
|
||||||
<FormButton value="Cancel test" on:click={handleCancelTest} data-testid="ConnectionTab_buttonCancelTest" />
|
<FormButton
|
||||||
|
value="Cancel test"
|
||||||
|
on:click={handleCancelTest}
|
||||||
|
data-testid="ConnectionTab_buttonCancelTest"
|
||||||
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<FormButton value="Test connection" on:click={handleTest} data-testid="ConnectionTab_buttonDisconnect" />
|
<FormButton value="Test connection" on:click={handleTest} data-testid="ConnectionTab_buttonDisconnect" />
|
||||||
{/if}
|
{/if}
|
||||||
{:else if isConnected}
|
{:else if isConnected}
|
||||||
<FormButton value="Disconnect" on:click={handleDisconnect} data-testid='ConnectionTab_buttonDisconnect' />
|
<FormButton value="Disconnect" on:click={handleDisconnect} data-testid="ConnectionTab_buttonDisconnect" />
|
||||||
{:else}
|
{:else}
|
||||||
<FormButton value="Connect" on:click={handleConnect} data-testid='ConnectionTab_buttonConnect' />
|
<FormButton value="Connect" on:click={handleConnect} data-testid="ConnectionTab_buttonConnect" />
|
||||||
{#if isTesting}
|
{#if isTesting}
|
||||||
<FormButton value="Cancel test" on:click={handleCancelTest} />
|
<FormButton value="Cancel test" on:click={handleCancelTest} />
|
||||||
{:else}
|
{:else}
|
||||||
<FormButton value="Test" on:click={handleTest} data-testid='ConnectionTab_buttonTest' />
|
<FormButton value="Test" on:click={handleTest} data-testid="ConnectionTab_buttonTest" />
|
||||||
{/if}
|
{/if}
|
||||||
<FormButton value="Save" on:click={handleSave} data-testid='ConnectionTab_buttonSave' />
|
<FormButton value="Save" on:click={handleSave} data-testid="ConnectionTab_buttonSave" />
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="test-result">
|
<div class="test-result">
|
||||||
|
|||||||
Reference in New Issue
Block a user