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(frontend): re-invent instance scan interval input (#9652)
Liu Ji8bb512d8aa66
diff --git a/frontend/src/components/InstanceForm/InstanceForm.vue b/frontend/src/components/InstanceForm/InstanceForm.vueindex 24a77372fb..f2b0c45b65 100644--- a/frontend/src/components/InstanceForm/InstanceForm.vue+++ b/frontend/src/components/InstanceForm/InstanceForm.vue@@ -180,6 +180,7 @@<ScanIntervalInputv-if="!isCreating"+ ref="scanIntervalInputRef":scan-interval="basicInfo.options?.syncInterval":allow-edit="allowEdit"@update:scan-interval="changeScanInterval"@@ -439,6 +440,7 @@ const instanceV1Store = useInstanceV1Store();const settingV1Store = useSettingV1Store();const actuatorStore = useActuatorV1Store();const subscriptionStore = useSubscriptionV1Store();+const scanIntervalInputRef = ref<InstanceType<typeof ScanIntervalInput>>();const state = reactive<LocalState>({editingDataSourceId: props.instance?.dataSources.find(@@ -583,6 +585,12 @@ const allowUpdate = computed((): boolean => {if (!valueChanged.value) {return false;}+ if (scanIntervalInputRef.value) {+ const scanIntervalInput = scanIntervalInputRef.value;+ if (!scanIntervalInput.validate()) {+ return false;+ }+ }if (basicInfo.value.engine === Engine.SPANNER) {if (!isValidSpannerHost(adminDataSource.value.host)) {return false;diff --git a/frontend/src/components/InstanceForm/ScanIntervalInput.vue b/frontend/src/components/InstanceForm/ScanIntervalInput.vueindex 99d1bf08cf..c7f62d300f 100644--- a/frontend/src/components/InstanceForm/ScanIntervalInput.vue+++ b/frontend/src/components/InstanceForm/ScanIntervalInput.vue@@ -8,7 +8,7 @@</div><div class="flex items-center gap-x-6"><NRadio- :checked="mode === 'DEFAULT'"+ :checked="state.mode === 'DEFAULT'":disabled="!allowEdit || !hasSecretFeature"value="DEFAULT"@click="handleModeChange('DEFAULT')"@@ -18,7 +18,7 @@<div class="flex items-center"><NRadio- :checked="mode === 'CUSTOM'"+ :checked="state.mode === 'CUSTOM'":disabled="!allowEdit || !hasSecretFeature"value="CUSTOM"class="!items-center"@@ -27,15 +27,23 @@<div class="flex items-center gap-x-1.5"><span>{{ $t("common.custom") }}</span><NInputNumber- v-model:value="minutes"+ :value="state.minutes":show-button="false"- :min="30"- placeholder=""+ :placeholder="`>= ${MIN_MINUTES}`"size="small"style="width: 4rem"- :disabled="mode !== 'CUSTOM'"+ :status="state.isValid ? undefined : 'error'"+ :disabled="state.mode !== 'CUSTOM'"+ @update:value="handleMinuteChange"/>- <span>{{ $t("common.minutes") }}</span>+ <span v-if="!state.isValid" class="text-error">+ {{+ $t("instance.scan-interval.min-value", {+ value: MIN_MINUTES,+ })+ }}+ </span>+ <span v-else>{{ $t("common.minutes") }}</span></div></NRadio><FeatureBadge@@ -50,12 +58,20 @@<script setup lang="ts">import { NInputNumber, NRadio } from "naive-ui";-import { computed, reactive } from "vue";+import { computed, reactive, watch } from "vue";import { useSubscriptionV1Store } from "@/store";import { Duration } from "@/types/proto/google/protobuf/duration";import { useInstanceFormContext } from "./context";type Mode = "DEFAULT" | "CUSTOM";+type LocalState = {+ mode: Mode;+ lastValidDuration: Duration | undefined;+ isValid: boolean;+ minutes: number | undefined;+};++const MIN_MINUTES = 30;const props = defineProps<{scanInterval?: Duration | undefined;@@ -76,51 +92,76 @@ const hasSecretFeature = computed(() => {);});-const mode = computed(() => {- const duration = props.scanInterval;- if (!duration) return "DEFAULT";- if (duration.seconds.toNumber() === 0) return "DEFAULT";- return "CUSTOM";-});--const state = reactive({- minutes: undefined as number | undefined, // Local input state-});--const minutes = computed({- get() {- const duration = props.scanInterval;- if (!duration) return undefined;- if (duration.seconds.toNumber() === 0) return undefined;- return Math.floor(duration.seconds.toNumber() / 60);- },- set(value) {- if (!value) {- emit(- "update:scan-interval",- Duration.fromPartial({- seconds: 0,- })- );- return;- }+const extractStateFromDuration = (+ duration: Duration | undefined+): { mode: Mode; minutes: number | undefined } => {+ if (!duration || duration.seconds.toNumber() === 0) {+ return {+ mode: "DEFAULT",+ minutes: undefined,+ };+ }+ return {+ mode: "CUSTOM",+ minutes: Math.floor(duration.seconds.toNumber() / 60),+ };+};- state.minutes = value;- const duration = Duration.fromPartial({- seconds: value * 60,- });- emit("update:scan-interval", duration);- },+const state = reactive<LocalState>({+ ...extractStateFromDuration(props.scanInterval),+ lastValidDuration: props.scanInterval,+ isValid: true,});const handleModeChange = (targetMode: Mode) => {- if (targetMode === mode.value) {+ if (targetMode === state.mode) {return;}+ state.mode = targetMode;if (targetMode === "DEFAULT") {- minutes.value = undefined;+ emit(+ "update:scan-interval",+ Duration.fromPartial({+ seconds: 0,+ })+ );} else {- minutes.value = state.minutes ?? 1440;+ emit(+ "update:scan-interval",+ Duration.fromPartial({+ seconds: 24 * 60 * 60,+ })+ );}};++const handleMinuteChange = (minute: number | undefined) => {+ state.minutes = minute;+ if (!minute || minute < MIN_MINUTES) {+ state.isValid = false;+ return;+ }+ state.isValid = true;+ emit(+ "update:scan-interval",+ Duration.fromPartial({+ seconds: minute * 60,+ })+ );+};++watch(+ () => props.scanInterval,+ (duration) => {+ Object.assign(state, extractStateFromDuration(duration));+ state.lastValidDuration = duration;+ state.isValid = true;+ }+);++defineExpose({+ validate: () => {+ return state.isValid;+ },+});</script>diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 5e26303009..101146ff7f 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1328,7 +1328,8 @@"scan-interval": {"self": "Scan Interval","default-never": "Default (never)",- "description": "Bytebase periodically syncs instance schema and detects anomalies."+ "description": "Bytebase periodically syncs instance schema and detects anomalies.",+ "min-value": "Min value {value} minutes"}},"environment": {diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 0419e37bdd..a17583a19e 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1327,7 +1327,8 @@"scan-interval": {"self": "Intervalo de escaneo","default-never": "Predeterminado (nunca)",- "description": "Bytebase sincroniza periódicamente el esquema de instancia y detecta anomalías."+ "description": "Bytebase sincroniza periódicamente el esquema de instancia y detecta anomalías.",+ "min-value": "Valor mínimo {value} minutos"}},"environment": {diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex cf2af49055..f3c5727e39 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1325,7 +1325,8 @@"scan-interval": {"self": "扫描间隔","default-never": "默认(永不)",- "description": "Bytebase 会定期同步实例的 schema 以及进行异常检测。"+ "description": "Bytebase 会定期同步实例的 schema 以及进行异常检测。",+ "min-value": "最小值 {value} 分钟"}},"environment": {