refresh schema list

This commit is contained in:
Jan Prochazka
2024-09-19 11:15:44 +02:00
parent 3e5b45de8f
commit 9eb27f5e92
4 changed files with 40 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
<script context="module">
<script context="module" lang="ts">
export async function saveScriptToDatabase({ conid, database }, sql, syncModel = true) {
const resp = await apiCall('database-connections/run-script', {
conid,
@@ -15,7 +15,7 @@
}
}
export async function runOperationOnDatabase({ conid, database }, operation, syncModel = true) {
export async function runOperationOnDatabase({ conid, database }, operation, syncModel: string | boolean = true) {
const resp = await apiCall('database-connections/run-operation', {
conid,
database,
@@ -27,7 +27,11 @@
showModal(ErrorMessageModal, { title: 'Error when executing operation', message: errorMessage });
} else {
showSnackbarSuccess('Saved to database');
if (syncModel) apiCall('database-connections/sync-model', { conid, database });
if (_.isString(syncModel)) {
apiCall('database-connections/dispatch-database-changed-event', { event: syncModel, conid, database });
} else if (syncModel) {
apiCall('database-connections/sync-model', { conid, database });
}
}
}
</script>

View File

@@ -42,7 +42,7 @@
return res;
}
$: schemaList = _.uniq(
$: realSchemaList = _.uniq(
_.compact([selectedSchema, ...Object.keys(countBySchema), ...(schemaList?.map(x => x.schemaName) ?? [])])
);
$: countBySchema = computeCountBySchema(objectList ?? []);
@@ -54,10 +54,14 @@
label: 'Schema name',
onConfirm: async name => {
const dbid = { conid, database };
await runOperationOnDatabase(dbid, {
type: 'createSchema',
schemaName: name,
});
await runOperationOnDatabase(
dbid,
{
type: 'createSchema',
schemaName: name,
},
'schema-list-changed'
);
if (selectedSchema) {
selectedSchema = name;
}
@@ -69,10 +73,14 @@
message: `Really drop schema ${$appliedCurrentSchema}?`,
onConfirm: async () => {
const dbid = { conid, database };
runOperationOnDatabase(dbid, {
type: 'dropSchema',
schemaName: $appliedCurrentSchema,
});
runOperationOnDatabase(
dbid,
{
type: 'dropSchema',
schemaName: $appliedCurrentSchema,
},
'schema-list-changed'
);
selectedSchema = null;
},
});
@@ -81,14 +89,14 @@
$: selectedSchema = localStorage.getItem(valueStorageKey ?? '');
</script>
{#if schemaList.length > 0}
{#if realSchemaList.length > 0}
<div class="wrapper">
<div class="mr-1">Schema:</div>
<SelectField
isNative
options={[
{ label: `All schemas (${objectList?.length ?? 0})`, value: '' },
...schemaList.map(x => ({ label: `${x} (${countBySchema[x] ?? 0})`, value: x })),
...realSchemaList.map(x => ({ label: `${x} (${countBySchema[x] ?? 0})`, value: x })),
// ...schemaList.filter(x => countBySchema[x]).map(x => ({ label: `${x} (${countBySchema[x] ?? 0})`, value: x })),
// ...schemaList.filter(x => !countBySchema[x]).map(x => ({ label: `${x} (${countBySchema[x] ?? 0})`, value: x })),
]}

View File

@@ -16,7 +16,13 @@
import InlineButton from '../buttons/InlineButton.svelte';
import SearchInput from '../elements/SearchInput.svelte';
import WidgetsInnerContainer from './WidgetsInnerContainer.svelte';
import { useConnectionInfo, useDatabaseInfo, useDatabaseStatus, useSchemaList, useUsedApps } from '../utility/metadataLoaders';
import {
useConnectionInfo,
useDatabaseInfo,
useDatabaseStatus,
useSchemaList,
useUsedApps,
} from '../utility/metadataLoaders';
import SearchBoxWrapper from '../elements/SearchBoxWrapper.svelte';
import AppObjectList from '../appobj/AppObjectList.svelte';
import _ from 'lodash';
@@ -80,6 +86,7 @@
const handleRefreshDatabase = () => {
apiCall('database-connections/refresh', { conid, database });
apiCall('database-connections/dispatch-database-changed-event', { event: 'schema-list-changed', conid, database });
};
function createAddMenu() {