Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(sql-editor): minor updates for setting -> instance (#12302)
Liu Ji7f2f9bb867cc
diff --git a/frontend/src/components/InstanceForm/Form.vue b/frontend/src/components/InstanceForm/Form.vueindex e55c4fc316..d63755134d 100644--- a/frontend/src/components/InstanceForm/Form.vue+++ b/frontend/src/components/InstanceForm/Form.vue@@ -407,7 +407,7 @@</div><InstanceArchiveRestoreButton- v-if="!isCreating && instance"+ v-if="!hideArchiveRestore && !isCreating && instance":instance="instance as ComposedInstance"/></div>@@ -465,6 +465,10 @@ import {} from "./constants";import { useInstanceFormContext } from "./context";+defineProps<{+ hideArchiveRestore?: boolean;+}>();+const context = useInstanceFormContext();const {state,diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.tsindex a2d4f6e39c..e401424a7d 100644--- a/frontend/src/utils/util.ts+++ b/frontend/src/utils/util.ts@@ -5,6 +5,7 @@ import relativeTime from "dayjs/plugin/relativeTime";import utc from "dayjs/plugin/utc";import { escapeRegExp, round } from "lodash-es";import semver from "semver";+import { watchEffect, type Ref } from "vue";import type { Duration } from "@/types/proto/google/protobuf/duration";dayjs.extend(dayOfYear);@@ -216,6 +217,22 @@ export function defer<T = any>() {return d;}+/**+ * Wrap a Ref as a Promise, will be resolved when the Ref turns to expectedValue+ * first time+ */+export const wrapRefAsPromise = <T>(r: Ref<T>, expectedValue: T) => {+ return new Promise<void>((resolve) => {+ watchEffect(() => {+ if (r.value === expectedValue) {+ // Need not to care about resolving more than once+ // Since `Promise` will handle this+ resolve();+ }+ });+ });+};+// emitStorageChangedEvent is used to notify the storage changed eventexport function emitStorageChangedEvent() {const iframeEl = document.createElement("iframe");diff --git a/frontend/src/views/sql-editor/Setting/Instance/Instance.vue b/frontend/src/views/sql-editor/Setting/Instance/Instance.vueindex fbd89a3d06..ea8cd313e3 100644--- a/frontend/src/views/sql-editor/Setting/Instance/Instance.vue+++ b/frontend/src/views/sql-editor/Setting/Instance/Instance.vue@@ -1,8 +1,6 @@<template><div class="w-full flex flex-col gap-4 py-4 px-2 overflow-y-auto">- <div- class="grid grid-cols-3 gap-x-2 gap-y-4 md:inline-flex items-stretch"- >+ <div class="grid grid-cols-3 gap-x-2 gap-y-4 md:inline-flex items-stretch"><NButton @click="handleClickAddInstance"><template #icon><PlusIcon class="h-4 w-4" />@@ -45,7 +43,10 @@:title="detailTitle"body-content-class="flex flex-col gap-2 overflow-hidden">- <InstanceFormBody class="flex-1 overflow-auto" />+ <InstanceFormBody+ :hide-archive-restore="true"+ class="flex-1 overflow-auto"+ /><InstanceFormButtonsclass="border-t border-block-border pt-4 pb-0":on-created="(instance) => (state.detail.instance = instance)"@@ -80,10 +81,11 @@ import {import { UNKNOWN_ID } from "@/types";import type { Instance } from "@/types/proto/v1/instance_service";import { PlanType } from "@/types/proto/v1/subscription_service";-import type { SearchParams } from "@/utils";import {+ type SearchParams,sortInstanceV1ListByEnvironmentV1,extractEnvironmentResourceName,+ wrapRefAsPromise,} from "@/utils";interface LocalState {@@ -133,14 +135,29 @@ onMounted(() => {state.detail.show = true;state.detail.instance = undefined;}- watch(- () => state.detail.show,- (show) => {- if (!show) {- router.replace({ hash: "" });+ wrapRefAsPromise(ready, true).then(() => {+ const maybeInstanceName = route.hash.replace(/^#*/g, "");+ if (maybeInstanceName) {+ const instance = rawInstanceV1List.value.find(+ (inst) => inst.name === maybeInstanceName+ );+ if (instance) {+ state.detail.show = true;+ state.detail.instance = instance;}}- );++ watch(+ [() => state.detail.show, () => state.detail.instance?.name],+ ([show, instanceName]) => {+ if (show) {+ router.replace({ hash: instanceName ? `#${instanceName}` : "#add" });+ } else {+ router.replace({ hash: "" });+ }+ }+ );+ });});const filteredInstanceV1List = computed(() => {