refresh database options

This commit is contained in:
SPRINX0\prochazka
2025-11-28 15:35:38 +01:00
parent c4b81e3d2c
commit c3ea155a7b
3 changed files with 71 additions and 42 deletions

View File

@@ -3,7 +3,7 @@ import { currentDatabase, getCurrentDatabase } from '../stores';
import getElectron from '../utility/getElectron';
import registerCommand from './registerCommand';
import { apiCall } from '../utility/api';
import { switchCurrentDatabase } from '../utility/common';
import { getDatabasStatusMenu, switchCurrentDatabase } from '../utility/common';
import { __t } from '../translations';
registerCommand({
@@ -18,33 +18,7 @@ registerCommand({
conid: connection._id,
database: name,
};
return [
{
text: 'Sync model (incremental)',
onClick: () => {
apiCall('database-connections/sync-model', dbid);
},
},
{
text: 'Sync model (full)',
onClick: () => {
apiCall('database-connections/sync-model', { ...dbid, isFullRefresh: true });
},
},
{
text: 'Reopen',
onClick: () => {
apiCall('database-connections/refresh', dbid);
},
},
{
text: 'Disconnect',
onClick: () => {
const electron = getElectron();
if (electron) apiCall('database-connections/disconnect', dbid);
switchCurrentDatabase(null);
},
},
];
return getDatabasStatusMenu(dbid);
},
});

View File

@@ -4,6 +4,8 @@ import _ from 'lodash';
import { getSchemaList } from './metadataLoaders';
import { showSnackbarError } from './snackbar';
import { _t } from '../translations';
import { apiCall } from './api';
import getElectron from './getElectron';
export class LoadingToken {
isCanceled = false;
@@ -63,7 +65,8 @@ export function getObjectTypeFieldLabel(objectTypeField, driver?) {
if (objectTypeField == 'procedures') return _t('dbObject.procedures', { defaultMessage: 'Procedures' });
if (objectTypeField == 'functions') return _t('dbObject.functions', { defaultMessage: 'Functions' });
if (objectTypeField == 'triggers') return _t('dbObject.triggers', { defaultMessage: 'Triggers' });
if (objectTypeField == 'schedulerEvents') return _t('dbObject.schedulerEvents', { defaultMessage: 'Scheduler Events' });
if (objectTypeField == 'schedulerEvents')
return _t('dbObject.schedulerEvents', { defaultMessage: 'Scheduler Events' });
if (objectTypeField == 'matviews') return _t('dbObject.matviews', { defaultMessage: 'Materialized Views' });
if (objectTypeField == 'collections') return _t('dbObject.collections', { defaultMessage: 'Collections/Containers' });
return _.startCase(objectTypeField);
@@ -151,3 +154,40 @@ export function getKeyTextFromEvent(e) {
keyText += e.key;
return keyText;
}
export function getDatabasStatusMenu(dbid) {
function callSchemalListChanged() {
apiCall('database-connections/dispatch-database-changed-event', { event: 'schema-list-changed', ...dbid });
}
return [
{
text: 'Refresh DB structure (incremental)',
onClick: () => {
apiCall('database-connections/sync-model', dbid);
callSchemalListChanged();
},
},
{
text: 'Refresh DB structure (full)',
onClick: () => {
apiCall('database-connections/sync-model', { ...dbid, isFullRefresh: true });
callSchemalListChanged();
},
},
{
text: 'Reopen connection',
onClick: () => {
apiCall('database-connections/refresh', dbid);
callSchemalListChanged();
},
},
{
text: 'Disconnect',
onClick: () => {
const electron = getElectron();
if (electron) apiCall('database-connections/disconnect', dbid);
switchCurrentDatabase(null);
},
},
];
}

View File

@@ -31,7 +31,7 @@
import { chevronExpandIcon } from '../icons/expandIcons';
import ErrorInfo from '../elements/ErrorInfo.svelte';
import LoadingInfo from '../elements/LoadingInfo.svelte';
import { getObjectTypeFieldLabel } from '../utility/common';
import { getDatabasStatusMenu, getObjectTypeFieldLabel } from '../utility/common';
import DropDownButton from '../buttons/DropDownButton.svelte';
import FontIcon from '../icons/FontIcon.svelte';
import CloseSearchButton from '../buttons/CloseSearchButton.svelte';
@@ -120,11 +120,6 @@
// setInterval(() => (generateIndex += 1), 2000);
// $: objectList = generateObjectList(generateIndex);
const handleRefreshDatabase = () => {
apiCall('database-connections/refresh', { conid, database });
apiCall('database-connections/dispatch-database-changed-event', { event: 'schema-list-changed', conid, database });
};
function createAddMenu() {
const res = [];
if (driver?.databaseEngineTypes?.includes('document')) {
@@ -147,6 +142,15 @@
return res;
}
function createRefreshDatabaseMenu() {
return getDatabasStatusMenu({ conid, database });
}
function handleFullRefreshDatabase() {
apiCall('database-connections/sync-model', { conid, database, isFullRefresh: true });
apiCall('database-connections/dispatch-database-changed-event', { event: 'schema-list-changed', conid, database });
}
function createSearchMenu() {
const res = [];
res.push({ label: _t('sqlObject.searchBy', { defaultMessage: 'Search by:' }), isBold: true, disabled: true });
@@ -237,7 +241,18 @@
<WidgetsInnerContainer hideContent={differentFocusedDb}>
<ErrorInfo message={$status.message} icon="img error" />
<InlineButton on:click={handleRefreshDatabase}>{_t('common.refresh', { defaultMessage: 'Refresh' })}</InlineButton>
<InlineButton on:click={handleFullRefreshDatabase}
>{_t('common.refresh', { defaultMessage: 'Refresh' })}</InlineButton
>
<DropDownButton
menu={createRefreshDatabaseMenu}
title={_t('sqlObjectList.refreshDatabase', { defaultMessage: 'Refresh database connection and object list' })}
square
narrow={false}
data-testid="SqlObjectList_refreshButton"
icon="icon dots-vertical"
/>
</WidgetsInnerContainer>
{:else if objectList.length == 0 && $status && $status.name != 'pending' && $status.name != 'checkStructure' && $status.name != 'loadStructure' && $objects}
<SchemaSelector
@@ -298,14 +313,14 @@
{#if !filter}
<DropDownButton icon="icon plus-thick" menu={createAddMenu} />
{/if}
<InlineButton
on:click={handleRefreshDatabase}
<DropDownButton
menu={createRefreshDatabaseMenu}
title={_t('sqlObjectList.refreshDatabase', { defaultMessage: 'Refresh database connection and object list' })}
square
narrow={false}
data-testid="SqlObjectList_refreshButton"
>
<FontIcon icon="icon refresh" />
</InlineButton>
icon="icon dots-vertical"
/>
</SearchBoxWrapper>
<SchemaSelector
schemaList={_.isArray($schemaList) ? $schemaList : null}