Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: unify setting ux for project/instance/environment/workspace (#15287)

ecmadao2f1135679141
diff --git a/frontend/src/components/EnvironmentForm/Buttons.vue b/frontend/src/components/EnvironmentForm/Buttons.vue
index a250c5f106..c3bcc05cdd 100644
--- a/frontend/src/components/EnvironmentForm/Buttons.vue
+++ b/frontend/src/components/EnvironmentForm/Buttons.vue
@@ -17,19 +17,15 @@
</div>
<div
- v-if="!create && allowEdit"
- class="flex items-center justify-end gap-x-3"
+ v-if="!create && allowEdit && valueChanged()"
+ class="flex items-center justify-between gap-x-3"
v-bind="$attrs"
>
- <NButton v-if="valueChanged()" @click.prevent="revertEnvironment">
- {{ $t("common.revert") }}
+ <NButton @click.prevent="revertEnvironment">
+ {{ $t("common.cancel") }}
</NButton>
- <NButton
- type="primary"
- :disabled="!valueChanged()"
- @click.prevent="updateEnvironment"
- >
- {{ $t("common.update") }}
+ <NButton type="primary" @click.prevent="updateEnvironment">
+ {{ $t("common.confirm-and-update") }}
</NButton>
</div>
</template>
@@ -115,5 +111,13 @@ const updateEnvironment = () => {
};
events.emit("update", environmentPatch);
}
+
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("environment.successfully-updated-environment", {
+ name: state.value.environment.title,
+ }),
+ });
};
</script>
diff --git a/frontend/src/components/EnvironmentForm/Form.vue b/frontend/src/components/EnvironmentForm/Form.vue
index 437f7ee299..0323b9a419 100644
--- a/frontend/src/components/EnvironmentForm/Form.vue
+++ b/frontend/src/components/EnvironmentForm/Form.vue
@@ -105,7 +105,7 @@
<div
v-if="!create && !hideArchiveRestore"
- class="mt-6 flex justify-between items-center pt-5"
+ class="mt-6 border-t border-block-border flex justify-between items-center pt-4 pb-2"
>
<template v-if="state.environment.state === State.ACTIVE">
<BBButtonConfirm
diff --git a/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue b/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
index 269ef9272e..94353184c0 100644
--- a/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
+++ b/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
@@ -49,7 +49,7 @@
<NInput
v-model:value="state.openAIKey"
class="mb-4 w-full"
- :disabled="!allowEdit"
+ :disabled="!allowEdit || !hasAIFeature"
:placeholder="
$t(
'settings.general.workspace.ai-assistant.openai-key.placeholder'
@@ -79,7 +79,7 @@
<NInput
v-model:value="state.openAIEndpoint"
class="mb-4 w-full"
- :disabled="!allowEdit"
+ :disabled="!allowEdit || !hasAIFeature"
/>
</template>
<span class="text-sm text-gray-400 -translate-y-2">
@@ -104,7 +104,7 @@
<NInput
v-model:value="state.openAIModel"
class="mb-4 w-full"
- :disabled="!allowEdit"
+ :disabled="!allowEdit || !hasAIFeature"
/>
</template>
<span class="text-sm text-gray-400 -translate-y-2">
@@ -113,12 +113,6 @@
</NTooltip>
</div>
</div>
-
- <FeatureModal
- feature="bb.feature.ai-assistant"
- :open="state.showFeatureModal"
- @cancel="state.showFeatureModal = false"
- />
</div>
</template>
@@ -129,13 +123,12 @@ import { computed, onMounted, reactive, ref, watchEffect } from "vue";
import LearnMoreLink from "@/components/LearnMoreLink.vue";
import { hasFeature } from "@/store";
import { useSettingV1Store } from "@/store/modules/v1/setting";
-import { FeatureBadge, FeatureModal } from "../FeatureGuard";
+import { FeatureBadge } from "../FeatureGuard";
interface LocalState {
openAIKey: string;
openAIEndpoint: string;
openAIModel: string;
- showFeatureModal: boolean;
}
const props = defineProps<{
@@ -150,7 +143,6 @@ const state = reactive<LocalState>({
openAIKey: "",
openAIEndpoint: "",
openAIModel: "",
- showFeatureModal: false,
});
const openAIKeySetting = settingV1Store.getSettingByName(
@@ -163,10 +155,18 @@ const openAIModelSetting = settingV1Store.getSettingByName(
"bb.plugin.openai.model"
);
+const hasAIFeature = computed(() => hasFeature("bb.feature.ai-assistant"));
+
+const getInitialState = (): LocalState => {
+ return {
+ openAIKey: maskKey(openAIKeySetting?.value?.stringValue),
+ openAIEndpoint: openAIEndpointSetting?.value?.stringValue ?? "",
+ openAIModel: openAIModelSetting?.value?.stringValue ?? "",
+ };
+};
+
watchEffect(() => {
- state.openAIKey = maskKey(openAIKeySetting?.value?.stringValue);
- state.openAIEndpoint = openAIEndpointSetting?.value?.stringValue ?? "";
- state.openAIModel = openAIModelSetting?.value?.stringValue ?? "";
+ Object.assign(state, getInitialState);
});
const allowSave = computed((): boolean => {
@@ -185,13 +185,6 @@ function maskKey(key: string | undefined): string {
}
const updateOpenAIKeyEndpoint = async () => {
- // Always allow to unset the key.
- const isUnset = state.openAIKey === "" && state.openAIEndpoint === "";
- if (!isUnset && !hasFeature("bb.feature.ai-assistant")) {
- state.showFeatureModal = true;
- return;
- }
-
if (
state.openAIKey !== maskKey(openAIKeySetting?.value?.stringValue) ||
!state.openAIKey.includes("***")
@@ -235,5 +228,8 @@ defineExpose({
isDirty: allowSave,
title: props.title,
update: updateOpenAIKeyEndpoint,
+ revert: () => {
+ Object.assign(state, getInitialState());
+ },
});
</script>
diff --git a/frontend/src/components/GeneralSetting/AccountSetting.vue b/frontend/src/components/GeneralSetting/AccountSetting.vue
index a4809242d3..00ca25e2a0 100644
--- a/frontend/src/components/GeneralSetting/AccountSetting.vue
+++ b/frontend/src/components/GeneralSetting/AccountSetting.vue
@@ -238,5 +238,10 @@ defineExpose({
isDirty,
title: props.title,
update: onUpdate,
+ revert: () => {
+ Object.assign(state, getInitialState());
+ passwordRestrictionSettingRef.value?.revert();
+ signInFrequencySettingRef.value?.revert();
+ },
});
</script>
diff --git a/frontend/src/components/GeneralSetting/AnnouncementSetting.vue b/frontend/src/components/GeneralSetting/AnnouncementSetting.vue
index 210238ae0b..fca2e80fda 100644
--- a/frontend/src/components/GeneralSetting/AnnouncementSetting.vue
+++ b/frontend/src/components/GeneralSetting/AnnouncementSetting.vue
@@ -27,7 +27,7 @@
<template #trigger>
<div class="flex flex-wrap py-2 radio-set-row gap-4">
<AnnouncementLevelSelect
- v-model:level="state.announcement.level"
+ v-model:level="state.level"
:allow-edit="allowEdit && hasAnnouncementFeature"
/>
</div>
@@ -52,7 +52,7 @@
<NTooltip placement="top-start" :disabled="allowEdit">
<template #trigger>
<NInput
- v-model:value="state.announcement.text"
+ v-model:value="state.text"
class="mb-3 w-full"
:placeholder="
$t('settings.general.workspace.announcement-text.placeholder')
@@ -77,7 +77,7 @@
<NTooltip placement="top-start" :disabled="allowEdit">
<template #trigger>
<NInput
- v-model:value="state.announcement.link"
+ v-model:value="state.link"
class="mb-5 w-full"
:placeholder="
$t('settings.general.workspace.extra-link.placeholder')
@@ -109,10 +109,6 @@ import { Announcement } from "@/types/proto/v1/setting_service";
import { Announcement_AlertLevel } from "@/types/proto/v1/setting_service";
import { FeatureBadge } from "../FeatureGuard";
-interface LocalState {
- announcement: Announcement;
-}
-
const props = defineProps<{
title: string;
allowEdit: boolean;
@@ -130,27 +126,27 @@ const rawAnnouncement = computed(() =>
)
);
-const state = reactive<LocalState>({
- announcement: cloneDeep(rawAnnouncement.value),
-});
+const state = reactive<Announcement>(rawAnnouncement.value);
const allowSave = computed((): boolean => {
- return !isEqual(rawAnnouncement.value, state.announcement);
+ return !isEqual(rawAnnouncement.value, state);
});
const updateAnnouncementSetting = async () => {
await settingV1Store.updateWorkspaceProfile({
payload: {
- announcement: state.announcement,
+ announcement: { ...state },
},
updateMask: ["value.workspace_profile_setting_value.announcement"],
});
- state.announcement = cloneDeep(rawAnnouncement.value);
};
defineExpose({
isDirty: allowSave,
title: props.title,
update: updateAnnouncementSetting,
+ revert: () => {
+ Object.assign(state, rawAnnouncement.value);
+ },
});
</script>
diff --git a/frontend/src/components/GeneralSetting/BrandingSetting.vue b/frontend/src/components/GeneralSetting/BrandingSetting.vue
index 02c0e3b3b2..4b350fa10b 100644
--- a/frontend/src/components/GeneralSetting/BrandingSetting.vue
+++ b/frontend/src/components/GeneralSetting/BrandingSetting.vue
@@ -138,5 +138,6 @@ defineExpose({
title: props.title,
isDirty: allowSave,
update: uploadLogo,
+ revert: () => (state.logoUrl = settingV1Store.brandingLogo),
});
</script>
diff --git a/frontend/src/components/GeneralSetting/DatabaseChangeModeSetting.vue b/frontend/src/components/GeneralSetting/DatabaseChangeModeSetting.vue
index 4f95b21f7e..9719c88221 100644
--- a/frontend/src/components/GeneralSetting/DatabaseChangeModeSetting.vue
+++ b/frontend/src/components/GeneralSetting/DatabaseChangeModeSetting.vue
@@ -171,5 +171,8 @@ defineExpose({
isDirty: allowSave,
update: onUpdate,
title: props.title,
+ revert: () => {
+ Object.assign(state, getInitialState());
+ },
});
</script>
diff --git a/frontend/src/components/GeneralSetting/DomainRestrictionSetting.vue b/frontend/src/components/GeneralSetting/DomainRestrictionSetting.vue
index ffd7699a2c..7a4aa43b64 100644
--- a/frontend/src/components/GeneralSetting/DomainRestrictionSetting.vue
+++ b/frontend/src/components/GeneralSetting/DomainRestrictionSetting.vue
@@ -106,5 +106,8 @@ defineExpose({
],
});
},
+ revert: () => {
+ Object.assign(state, getInitialState());
+ },
});
</script>
diff --git a/frontend/src/components/GeneralSetting/MaximumRoleExpirationSetting.vue b/frontend/src/components/GeneralSetting/MaximumRoleExpirationSetting.vue
index 1233827a28..27b18b19c0 100644
--- a/frontend/src/components/GeneralSetting/MaximumRoleExpirationSetting.vue
+++ b/frontend/src/components/GeneralSetting/MaximumRoleExpirationSetting.vue
@@ -38,6 +38,11 @@ import { Duration } from "@/types/proto/google/protobuf/duration";
const DEFAULT_EXPIRATION_DAYS = 90;
+interface LocalState {
+ inputValue: number;
+ neverExpire: boolean;
+}
+
const getInitialState = (): LocalState => {
const defaultState: LocalState = {
inputValue: DEFAULT_EXPIRATION_DAYS,
@@ -53,11 +58,6 @@ const getInitialState = (): LocalState => {
return defaultState;
};
-interface LocalState {
- inputValue: number;
- neverExpire: boolean;
-}
-
defineProps<{
allowEdit: boolean;
}>();
@@ -82,6 +82,9 @@ const handleSettingChange = async () => {
defineExpose({
isDirty: computed(() => !isEqual(state, getInitialState())),
+ revert: () => {
+ Object.assign(state, getInitialState());
+ },
update: handleSettingChange,
});
</script>
diff --git a/frontend/src/components/GeneralSetting/MaximumSQLResultSizeSetting.vue b/frontend/src/components/GeneralSetting/MaximumSQLResultSizeSetting.vue
index 8a5e5a88c5..aaa6b093e6 100644
--- a/frontend/src/components/GeneralSetting/MaximumSQLResultSizeSetting.vue
+++ b/frontend/src/components/GeneralSetting/MaximumSQLResultSizeSetting.vue
@@ -74,5 +74,6 @@ const handleInput = (value: number | null) => {
defineExpose({
isDirty: allowUpdate,
update: updateChange,
+ revert: () => (maximumSQLResultLimit.value = initialState()),
});
</script>
diff --git a/frontend/src/components/GeneralSetting/NetworkSetting.vue b/frontend/src/components/GeneralSetting/NetworkSetting.vue
index 2c30c85f67..179240ab49 100644
--- a/frontend/src/components/GeneralSetting/NetworkSetting.vue
+++ b/frontend/src/components/GeneralSetting/NetworkSetting.vue
@@ -89,11 +89,15 @@ const { t } = useI18n();
const settingV1Store = useSettingV1Store();
const actuatorV1Store = useActuatorV1Store();
-const state = reactive<LocalState>({
- externalUrl: settingV1Store.workspaceProfileSetting?.externalUrl ?? "",
- gitopsWebhookUrl:
- settingV1Store.workspaceProfileSetting?.gitopsWebhookUrl ?? "",
-});
+const getInitialState = (): LocalState => {
+ return {
+ externalUrl: settingV1Store.workspaceProfileSetting?.externalUrl ?? "",
+ gitopsWebhookUrl:
+ settingV1Store.workspaceProfileSetting?.gitopsWebhookUrl ?? "",
+ };
+};
+
+const state = reactive<LocalState>(getInitialState());
const { isSaaSMode } = storeToRefs(actuatorV1Store);
@@ -132,5 +136,8 @@ defineExpose({
title: props.title,
isDirty: allowSave,
update: updateNetworkSetting,
+ revert: () => {
+ return Object.assign(state, getInitialState());
+ },
});
</script>
diff --git a/frontend/src/components/GeneralSetting/PasswordRestrictionSetting.vue b/frontend/src/components/GeneralSetting/PasswordRestrictionSetting.vue
index fca6a546c2..3d1014fddb 100644
--- a/frontend/src/components/GeneralSetting/PasswordRestrictionSetting.vue
+++ b/frontend/src/components/GeneralSetting/PasswordRestrictionSetting.vue
@@ -223,5 +223,8 @@ defineExpose({
},
});
},
+ revert: () => {
+ Object.assign(state, passwordRestrictionSetting.value);
+ },
});
</script>
diff --git a/frontend/src/components/GeneralSetting/RestrictIssueCreationConfigure.vue b/frontend/src/components/GeneralSetting/RestrictIssueCreationConfigure.vue
index 88870e5659..ffa46f550d 100644
--- a/frontend/src/components/GeneralSetting/RestrictIssueCreationConfigure.vue
+++ b/frontend/src/components/GeneralSetting/RestrictIssueCreationConfigure.vue
@@ -26,7 +26,7 @@
</template>
<script setup lang="ts">
-import { computed, ref } from "vue";
+import { computed, ref, watch } from "vue";
import {
hasFeature,
usePolicyV1Store,
@@ -55,15 +55,27 @@ const allowEdit = computed(() => {
);
});
-const { policy } = usePolicyByParentAndType(
+const { policy, ready } = usePolicyByParentAndType(
computed(() => ({
parentPath: props.resource,
policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,
}))
);
-const restrictIssueCreationForSQLReview = ref<boolean>(
- policy.value?.restrictIssueCreationForSqlReviewPolicy?.disallow ?? false
+const restrictIssueCreationForSQLReview = ref<boolean>(false);
+
+const resetState = () => {
+ restrictIssueCreationForSQLReview.value =
+ policy.value?.restrictIssueCreationForSqlReviewPolicy?.disallow ?? false;
+};
+
+watch(
+ () => ready.value,
+ () => {
+ if (ready.value) {
+ resetState();
+ }
+ }
);
const handleRestrictIssueCreationForSQLReviewToggle = async () => {
@@ -86,5 +98,6 @@ defineExpose({
(policy.value?.restrictIssueCreationForSqlReviewPolicy?.disallow ?? false)
),
update: handleRestrictIssueCreationForSQLReviewToggle,
+ revert: resetState,
});
</script>
diff --git a/frontend/src/components/GeneralSetting/SecuritySetting.vue b/frontend/src/components/GeneralSetting/SecuritySetting.vue
index 4ceb02182c..286f9fcf00 100644
--- a/frontend/src/components/GeneralSetting/SecuritySetting.vue
+++ b/frontend/src/components/GeneralSetting/SecuritySetting.vue
@@ -117,6 +117,13 @@ const maximumSQLResultSizeSettingRef =
const restrictIssueCreationConfigureRef =
ref<InstanceType<typeof RestrictIssueCreationConfigure>>();
+const settingRefList = computed(() => [
+ domainRestrictionSettingRef,
+ maximumRoleExpirationSettingRef,
+ maximumSQLResultSizeSettingRef,
+ restrictIssueCreationConfigureRef,
+]);
+
const { policy: exportDataPolicy } = usePolicyByParentAndType(
computed(() => ({
parentPath: "",
@@ -140,10 +147,7 @@ const state = reactive<LocalState>({
const isDirty = computed(() => {
return (
!isEqual(state, getInitialState()) ||
- domainRestrictionSettingRef.value?.isDirty ||
- restrictIssueCreationConfigureRef.value?.isDirty ||
- maximumSQLResultSizeSettingRef.value?.isDirty ||
- maximumRoleExpirationSettingRef.value?.isDirty
+ settingRefList.value.some((settingRef) => settingRef.value?.isDirty)
);
});
@@ -171,19 +175,11 @@ const handleWatermarkToggle = async () => {
};
const onUpdate = async () => {
- if (domainRestrictionSettingRef.value?.isDirty) {
- await domainRestrictionSettingRef.value.update();
- }
- if (restrictIssueCreationConfigureRef.value?.isDirty) {
- await restrictIssueCreationConfigureRef.value.update();
- }
- if (maximumSQLResultSizeSettingRef.value?.isDirty) {
- await maximumSQLResultSizeSettingRef.value.update();
+ for (const settingRef of settingRefList.value) {
+ if (settingRef.value?.isDirty) {
+ await settingRef.value.update();
+ }
}
- if (maximumRoleExpirationSettingRef.value?.isDirty) {
- await maximumRoleExpirationSettingRef.value.update();
- }
-
if (state.enableWatermark !== getInitialState().enableWatermark) {
await handleWatermarkToggle();
}
@@ -196,5 +192,11 @@ defineExpose({
isDirty,
update: onUpdate,
title: props.title,
+ revert: () => {
+ Object.assign(state, getInitialState());
+ for (const settingRef of settingRefList.value) {
+ settingRef.value?.revert();
+ }
+ },
});
</script>
diff --git a/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue b/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
index 55605b03c8..6225906562 100644
--- a/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
+++ b/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
@@ -129,5 +129,8 @@ watch(
defineExpose({
isDirty: computed(() => !isEqual(getInitialState(), state)),
update: handleFrequencySettingChange,
+ revert: () => {
+ Object.assign(state, getInitialState());
+ },
});
</script>
diff --git a/frontend/src/components/Instance/InstanceArchiveRestoreButton.vue b/frontend/src/components/Instance/InstanceArchiveRestoreButton.vue
index e8984a9c73..4920117dfd 100644
--- a/frontend/src/components/Instance/InstanceArchiveRestoreButton.vue
+++ b/frontend/src/components/Instance/InstanceArchiveRestoreButton.vue
@@ -1,5 +1,8 @@
<template>
- <template v-if="allowArchiveOrRestore">
+ <div
+ v-if="allowArchiveOrRestore"
+ class="t-6 border-t border-block-border flex justify-between items-center pt-4 pb-2"
+ >
<template v-if="instance.state === State.ACTIVE">
<BBButtonConfirm
:type="'ARCHIVE'"
@@ -40,7 +43,7 @@
@confirm="archiveOrRestoreInstance(false)"
/>
</template>
- </template>
+ </div>
<FeatureModal
feature="bb.feature.instance-count"
:open="state.showFeatureModal"
diff --git a/frontend/src/components/InstanceForm/Buttons.vue b/frontend/src/components/InstanceForm/Buttons.vue
index b09e8a4544..930d43109b 100644
--- a/frontend/src/components/InstanceForm/Buttons.vue
+++ b/frontend/src/components/InstanceForm/Buttons.vue
@@ -110,6 +110,7 @@ const {
checkDataSource,
extractDataSourceFromEdit,
pendingCreateInstance,
+ valueChanged,
} = context;
const router = useRouter();
@@ -124,15 +125,6 @@ const resetChanges = () => {
dataSourceEditState.value.dataSources = cloneDeep(original.dataSources);
};
-const valueChanged = computed(() => {
- const original = getOriginalEditState();
- const editing = {
- basicInfo: basicInfo.value,
- dataSources: dataSourceEditState.value.dataSources,
- };
- return !isEqual(editing, original);
-});
-
const allowUpdate = computed((): boolean => {
if (!valueChanged.value) {
return false;
diff --git a/frontend/src/components/InstanceForm/InstanceForm.vue b/frontend/src/components/InstanceForm/InstanceForm.vue
index d001ac21de..11736e66d9 100644
--- a/frontend/src/components/InstanceForm/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm/InstanceForm.vue
@@ -11,7 +11,10 @@
</template>
<script lang="ts" setup>
+import { useEventListener } from "@vueuse/core";
import { watch, onMounted, toRef } from "vue";
+import { useI18n } from "vue-i18n";
+import { onBeforeRouteLeave } from "vue-router";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import { useActuatorV1Store, useSettingV1Store } from "@/store";
import { Engine } from "@/types/proto/v1/common";
@@ -31,15 +34,42 @@ const emit = defineEmits<{
const settingV1Store = useSettingV1Store();
const actuatorStore = useActuatorV1Store();
+const { t } = useI18n();
const instance = toRef(props, "instance");
const hideAdvancedFeatures = toRef(props, "hideAdvancedFeatures");
const context = provideInstanceFormContext({ instance, hideAdvancedFeatures });
-const { events, isCreating, basicInfo, adminDataSource, missingFeature } =
- context;
+const {
+ events,
+ isCreating,
+ valueChanged,
+ basicInfo,
+ adminDataSource,
+ missingFeature,
+} = context;
+
+useEventListener("beforeunload", (e) => {
+ if (isCreating.value || !valueChanged.value) {
+ return;
+ }
+ e.returnValue = t("common.leave-without-saving");
+ return e.returnValue;
+});
+
+onBeforeRouteLeave((to, from, next) => {
+ if (!isCreating.value && valueChanged.value) {
+ if (!window.confirm(t("common.leave-without-saving"))) {
+ return;
+ }
+ }
+ next();
+});
+
onMounted(async () => {
if (isCreating.value) {
- adminDataSource.value.host = actuatorStore.isDocker ? "host.docker.internal" : "127.0.0.1";
+ adminDataSource.value.host = actuatorStore.isDocker
+ ? "host.docker.internal"
+ : "127.0.0.1";
if (basicInfo.value.engine === Engine.DYNAMODB) {
adminDataSource.value.host = "";
}
diff --git a/frontend/src/components/InstanceForm/context.ts b/frontend/src/components/InstanceForm/context.ts
index be2168fe8e..19351e0938 100644
--- a/frontend/src/components/InstanceForm/context.ts
+++ b/frontend/src/components/InstanceForm/context.ts
@@ -1,5 +1,5 @@
import Emittery from "emittery";
-import { cloneDeep, omit } from "lodash-es";
+import { cloneDeep, omit, isEqual } from "lodash-es";
import { useDialog } from "naive-ui";
import type { InjectionKey, Ref } from "vue";
import { provide, inject, computed, ref } from "vue";
@@ -433,6 +433,18 @@ export const provideInstanceFormContext = (baseContext: {
}
};
+ const valueChanged = computed(() => {
+ const original = {
+ basicInfo: extractBasicInfo(instance.value),
+ dataSources: extractDataSourceEditState(instance.value).dataSources,
+ };
+ const editing = {
+ basicInfo: basicInfo.value,
+ dataSources: dataSourceEditState.value.dataSources,
+ };
+ return !isEqual(editing, original);
+ });
+
const context = {
...baseContext,
$d,
@@ -457,6 +469,7 @@ export const provideInstanceFormContext = (baseContext: {
extractDataSourceFromEdit,
testConnection,
pendingCreateInstance,
+ valueChanged,
};
provide(KEY, context);
diff --git a/frontend/src/components/Project/Settings/ProjectGeneralSettingPanel.vue b/frontend/src/components/Project/Settings/ProjectGeneralSettingPanel.vue
index b946d844d5..cec5f5996e 100644
--- a/frontend/src/components/Project/Settings/ProjectGeneralSettingPanel.vue
+++ b/frontend/src/components/Project/Settings/ProjectGeneralSettingPanel.vue
@@ -25,37 +25,21 @@
</div>
</dl>
</div>
-
- <div v-if="allowEdit" class="flex justify-end">
- <NButton type="primary" :disabled="!allowSave" @click.prevent="save">
- {{ $t("common.update") }}
- </NButton>
- </div>
-
- <FeatureModal
- :open="!!state.requiredFeature"
- :feature="state.requiredFeature"
- @cancel="state.requiredFeature = undefined"
- />
</form>
</template>
<script lang="ts" setup>
import { cloneDeep, isEmpty } from "lodash-es";
-import { NButton, NInput } from "naive-ui";
+import { NInput } from "naive-ui";
import { computed, reactive } from "vue";
-import { useI18n } from "vue-i18n";
-import { FeatureModal } from "@/components/FeatureGuard";
import ResourceIdField from "@/components/v2/Form/ResourceIdField.vue";
-import { pushNotification, useProjectV1Store } from "@/store";
-import type { FeatureType } from "@/types";
+import { useProjectV1Store } from "@/store";
import { DEFAULT_PROJECT_NAME } from "@/types";
import type { Project } from "@/types/proto/v1/project_service";
import { extractProjectResourceName } from "@/utils";
interface LocalState {
title: string;
- requiredFeature: FeatureType | undefined;
}
const props = defineProps<{
@@ -63,12 +47,10 @@ const props = defineProps<{
allowEdit: boolean;
}>();
-const { t } = useI18n();
const projectV1Store = useProjectV1Store();
const state = reactive<LocalState>({
title: props.project.title,
- requiredFeature: undefined,
});
const allowSave = computed((): boolean => {
@@ -79,23 +61,19 @@ const allowSave = computed((): boolean => {
);
});
-const save = () => {
+const onUpdate = async () => {
const projectPatch = cloneDeep(props.project);
- const updateMask: string[] = [];
if (state.title !== props.project.title) {
projectPatch.title = state.title;
- updateMask.push("title");
+ await projectV1Store.updateProject(projectPatch, ["title"]);
}
- projectV1Store.updateProject(projectPatch, updateMask).then(() => {
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("project.settings.success-updated"),
- });
- });
};
defineExpose({
isDirty: allowSave,
+ update: onUpdate,
+ revert: () => {
+ state.title = props.project.title;
+ },
});
</script>
diff --git a/frontend/src/components/Project/Settings/ProjectIssueRelatedSettingPanel.vue b/frontend/src/components/Project/Settings/ProjectIssueRelatedSettingPanel.vue
index 96a0152cb9..949937adcc 100644
--- a/frontend/src/components/Project/Settings/ProjectIssueRelatedSettingPanel.vue
+++ b/frontend/src/components/Project/Settings/ProjectIssueRelatedSettingPanel.vue
@@ -160,15 +160,6 @@
</p>
</div>
</div>
- <div class="w-full flex justify-end gap-x-3">
- <NButton
- type="primary"
- :disabled="!valueChanged || !allowEdit"
- @click.prevent="doUpdate"
- >
- {{ $t("common.update") }}
- </NButton>
- </div>
</div>
</template>
@@ -176,7 +167,6 @@
import { isEqual, cloneDeep } from "lodash-es";
import { TriangleAlertIcon } from "lucide-vue-next";
import {
- NButton,
NDynamicTags,
NTag,
NColorPicker,
@@ -184,9 +174,8 @@ import {
NTooltip,
} from "naive-ui";
import { computed, reactive } from "vue";
-import { useI18n } from "vue-i18n";
import { FeatureBadge } from "@/components/FeatureGuard";
-import { hasFeature, pushNotification, useProjectV1Store } from "@/store";
+import { hasFeature, useProjectV1Store } from "@/store";
import type { ComposedProject } from "@/types";
import { Label } from "@/types/proto/v1/project_service";
@@ -224,7 +213,6 @@ const props = defineProps<{
allowEdit: boolean;
}>();
-const { t } = useI18n();
const projectStore = useProjectV1Store();
const state = reactive<LocalState>(getInitialLocalState());
@@ -292,16 +280,15 @@ const renderLabel = (value: string, index: number) => {
};
const doUpdate = async () => {
+ const updateMask = getUpdateMask();
+ if (updateMask.length === 0) {
+ return;
+ }
const projectPatch = {
...cloneDeep(props.project),
...state,
};
- await projectStore.updateProject(projectPatch, getUpdateMask());
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.updated"),
- });
+ await projectStore.updateProject(projectPatch, updateMask);
};
const getUpdateMask = () => {
@@ -343,5 +330,9 @@ const getUpdateMask = () => {
defineExpose({
isDirty: valueChanged,
+ update: doUpdate,
+ revert: () => {
+ Object.assign(state, getInitialLocalState());
+ },
});
</script>
diff --git a/frontend/src/components/Project/Settings/ProjectSecuritySettingPanel.vue b/frontend/src/components/Project/Settings/ProjectSecuritySettingPanel.vue
index 6500029f07..a2849ff505 100644
--- a/frontend/src/components/Project/Settings/ProjectSecuritySettingPanel.vue
+++ b/frontend/src/components/Project/Settings/ProjectSecuritySettingPanel.vue
@@ -20,22 +20,15 @@
:resource="project.name"
:allow-edit="allowEdit"
/>
- <div v-if="allowEdit" class="w-full flex justify-end">
- <NButton type="primary" :disabled="!isDirty" @click.prevent="onUpdate">
- {{ $t("common.update") }}
- </NButton>
- </div>
</div>
</template>
<script setup lang="ts">
-import { NButton } from "naive-ui";
import { ref, computed } from "vue";
-import { useI18n } from "vue-i18n";
import AccessControlConfigure from "@/components/EnvironmentForm/AccessControlConfigure.vue";
import RestrictIssueCreationConfigure from "@/components/GeneralSetting/RestrictIssueCreationConfigure.vue";
import { SQLReviewForResource } from "@/components/SQLReview";
-import { useAppFeature, pushNotification } from "@/store";
+import { useAppFeature } from "@/store";
import type { ComposedProject } from "@/types";
import { DatabaseChangeMode } from "@/types/proto/v1/setting_service";
@@ -45,7 +38,6 @@ defineProps<{
}>();
const databaseChangeMode = useAppFeature("bb.feature.database-change-mode");
-const { t } = useI18n();
const restrictIssueCreationConfigureRef =
ref<InstanceType<typeof RestrictIssueCreationConfigure>>();
@@ -71,14 +63,17 @@ const onUpdate = async () => {
if (accessControlConfigureRef.value?.isDirty) {
await accessControlConfigureRef.value.update();
}
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("settings.general.workspace.config-updated"),
- });
+};
+
+const resetState = () => {
+ sqlReviewForResourceRef.value?.revert();
+ accessControlConfigureRef.value?.revert();
+ restrictIssueCreationConfigureRef.value?.revert();
};
defineExpose({
isDirty,
+ update: onUpdate,
+ revert: resetState,
});
</script>
diff --git a/frontend/src/components/ProjectSettingPanel.vue b/frontend/src/components/ProjectSettingPanel.vue
index ba18ff9b36..9d1f3379a8 100644
--- a/frontend/src/components/ProjectSettingPanel.vue
+++ b/frontend/src/components/ProjectSettingPanel.vue
@@ -1,5 +1,5 @@
<template>
- <div class="w-full space-y-6 mb-6">
+ <div class="w-full space-y-6">
<div class="divide-y divide-block-border space-y-6">
<ProjectGeneralSettingPanel
ref="projectGeneralSettingPanelRef"
@@ -23,16 +23,30 @@
>
<ProjectArchiveRestoreButton :project="project" />
</div>
+
+ <div v-if="allowEdit && isDirty" class="sticky bottom-0 z-10">
+ <div
+ class="flex justify-between w-full pt-4 border-block-border bg-white"
+ >
+ <NButton @click.prevent="onRevert">
+ {{ $t("common.cancel") }}
+ </NButton>
+ <NButton type="primary" @click.prevent="onUpdate">
+ {{ $t("common.confirm-and-update") }}
+ </NButton>
+ </div>
+ </div>
</div>
</div>
</template>
<script lang="ts" setup>
import { useEventListener } from "@vueuse/core";
+import { NButton } from "naive-ui";
import { ref, computed } from "vue";
import { useI18n } from "vue-i18n";
import { onBeforeRouteLeave } from "vue-router";
-import { useAppFeature } from "@/store";
+import { useAppFeature, pushNotification } from "@/store";
import type { ComposedProject } from "@/types";
import { DatabaseChangeMode } from "@/types/proto/v1/setting_service";
import ProjectArchiveRestoreButton from "./Project/ProjectArchiveRestoreButton.vue";
@@ -57,12 +71,16 @@ const projectGeneralSettingPanelRef =
const projectIssueRelatedSettingPanelRef =
ref<InstanceType<typeof ProjectIssueRelatedSettingPanel>>();
+const settingRefList = computed(() => {
+ return [
+ projectGeneralSettingPanelRef,
+ projectSecuritySettingPanelRef,
+ projectIssueRelatedSettingPanelRef,
+ ];
+});
+
const isDirty = computed(() => {
- return (
- projectSecuritySettingPanelRef.value?.isDirty ||
- projectGeneralSettingPanelRef.value?.isDirty ||
- projectIssueRelatedSettingPanelRef.value?.isDirty
- );
+ return settingRefList.value.some((settingRef) => settingRef.value?.isDirty);
});
useEventListener("beforeunload", (e) => {
@@ -81,4 +99,33 @@ onBeforeRouteLeave((to, from, next) => {
}
next();
});
+
+const onUpdate = async () => {
+ for (const settingRef of settingRefList.value) {
+ if (!settingRef.value?.isDirty) {
+ continue;
+ }
+ try {
+ await settingRef.value.update();
+ } catch {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: t("project.settings.update-failed"),
+ });
+ return;
+ }
+ }
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("project.settings.success-updated"),
+ });
+};
+
+const onRevert = () => {
+ for (const settingRef of settingRefList.value) {
+ settingRef.value?.revert();
+ }
+};
</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 184a396138..87c75320b1 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1605,6 +1605,7 @@
},
"settings": {
"success-updated": "Project settings updated successfully.",
+ "update-failed": "Failed to update the project setting.",
"success-member-added-prompt": "Successfully added to the project.",
"archive": {
"title": "Archive project",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 9e85040ef0..eef8c73949 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1605,6 +1605,7 @@
},
"settings": {
"success-updated": "La configuración del proyecto se actualizó correctamente.",
+ "update-failed": "No se pudo actualizar la configuración del proyecto.",
"success-member-added-prompt": "Se agregó correctamente al proyecto.",
"archive": {
"title": "Archivar proyecto",
@@ -2718,4 +2719,4 @@
"last-visit": "Última visita",
"changelog-for-version": "Registro de cambios para {version}"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index e8b682e1c6..dd9a904271 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1605,6 +1605,7 @@
},
"settings": {
"success-updated": "プロジェクト設定が正常に更新されました",
+ "update-failed": "プロジェクト設定の更新に失敗しました。",
"success-member-added-prompt": "現在のプロジェクトに正常に追加されました。",
"archive": {
"title": "アーカイブアイテム",
@@ -2718,4 +2719,4 @@
"last-visit": "最終訪問",
"changelog-for-version": "{version} の変更履歴"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index a21ff6e456..366a9d9dc5 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1605,6 +1605,7 @@
},
"settings": {
"success-updated": "Đã cập nhật thành công cài đặt dự án.",
+ "update-failed": "Không cập nhật được cài đặt dự án.",
"success-member-added-prompt": "Đã thêm thành công vào dự án.",
"archive": {
"title": "Lưu trữ dự án",
@@ -2718,4 +2719,4 @@
"last-visit": "Lần truy cập cuối",
"changelog-for-version": "Nhật ký thay đổi cho phiên bản {version}"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index fe43b869ec..9e216aaa7b 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1605,6 +1605,7 @@
},
"settings": {
"success-updated": "项目设置更新成功",
+ "update-failed": "无法更新项目设置。",
"success-member-added-prompt": "成功添加到当前项目中.",
"archive": {
"title": "归档项目",
@@ -2718,4 +2719,4 @@
"last-visit": "上次访问",
"changelog-for-version": "{version} 的更新日志"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/views/EnvironmentDashboard.vue b/frontend/src/views/EnvironmentDashboard.vue
index 0c42facd4e..a54529cbd4 100644
--- a/frontend/src/views/EnvironmentDashboard.vue
+++ b/frontend/src/views/EnvironmentDashboard.vue
@@ -1,5 +1,5 @@
<template>
- <div class="w-full flex flex-col gap-4 px-2 overflow-y-auto">
+ <div class="w-full flex flex-col gap-4 px-2">
<NTabs
type="line"
:bar-width="200"
diff --git a/frontend/src/views/EnvironmentDetail.vue b/frontend/src/views/EnvironmentDetail.vue
index 486956f11e..5c18944e91 100644
--- a/frontend/src/views/EnvironmentDetail.vue
+++ b/frontend/src/views/EnvironmentDetail.vue
@@ -16,11 +16,11 @@
<EnvironmentFormBody
:features="features"
:hide-archive-restore="hideArchiveRestore"
- class="w-full px-4 pb-2"
+ class="w-full px-4 pb-4"
:class="bodyClass"
/>
<EnvironmentFormButtons
- class="sticky bottom-0 bg-white py-2 px-4 border-t border-block-border"
+ class="sticky bottom-0 bg-white py-4 px-2 border-t border-block-border"
:class="buttonsClass"
/>
</EnvironmentForm>
@@ -29,7 +29,6 @@
<script lang="ts" setup>
import { cloneDeep } from "lodash-es";
import { reactive, watch, watchEffect } from "vue";
-import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import ArchiveBanner from "@/components/ArchiveBanner.vue";
import {
@@ -39,7 +38,6 @@ import {
} from "@/components/EnvironmentForm";
import { ENVIRONMENT_V1_ROUTE_DETAIL } from "@/router/dashboard/environmentV1";
import { ENVIRONMENT_V1_ROUTE_DASHBOARD } from "@/router/dashboard/workspaceRoutes";
-import { pushNotification } from "@/store";
import { environmentNamePrefix } from "@/store/modules/v1/common";
import { useEnvironmentV1Store } from "@/store/modules/v1/environment";
import {
@@ -76,7 +74,6 @@ const props = defineProps<{
const emit = defineEmits(["archive"]);
-const { t } = useI18n();
const router = useRouter();
const environmentV1Store = useEnvironmentV1Store();
const policyV1Store = usePolicyV1Store();
@@ -138,20 +135,9 @@ const doUpdate = (environmentPatch: Environment) => {
pendingUpdate.color = environmentPatch.color;
}
- environmentV1Store
- .updateEnvironment(pendingUpdate)
- .then((environment) => {
- assignEnvironment(environment);
- })
- .then(() => {
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("environment.successfully-updated-environment", {
- name: state.environment.title,
- }),
- });
- });
+ environmentV1Store.updateEnvironment(pendingUpdate).then((environment) => {
+ assignEnvironment(environment);
+ });
};
const doArchive = (environment: Environment) => {
@@ -181,16 +167,6 @@ const doRestore = (environment: Environment) => {
});
};
-const success = () => {
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("environment.successfully-updated-environment", {
- name: state.environment.title,
- }),
- });
-};
-
const updatePolicy = async (params: {
environment: Environment;
policyType: PolicyType;
@@ -207,7 +183,5 @@ const updatePolicy = async (params: {
state.rolloutPolicy = updatedPolicy;
break;
}
-
- success();
};
</script>
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index 39e434752c..321087a354 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -1,5 +1,5 @@
<template>
- <div class="space-y-2 px-6 mb-4" v-bind="$attrs">
+ <div class="space-y-2 px-6" v-bind="$attrs">
<ArchiveBanner v-if="instance.state === State.DELETED" />
<div v-if="!embedded" class="flex items-center justify-between">
diff --git a/frontend/src/views/SettingWorkspaceGeneral.vue b/frontend/src/views/SettingWorkspaceGeneral.vue
index aadddb9224..a0517e412c 100644
--- a/frontend/src/views/SettingWorkspaceGeneral.vue
+++ b/frontend/src/views/SettingWorkspaceGeneral.vue
@@ -38,7 +38,12 @@
/>
<div v-if="allowEdit && isDirty" class="sticky -bottom-4 z-10">
- <div class="flex justify-end w-full py-4 border-block-border bg-white">
+ <div
+ class="flex justify-between w-full py-4 border-block-border bg-white"
+ >
+ <NButton @click.prevent="onRevert">
+ {{ $t("common.cancel") }}
+ </NButton>
<NButton type="primary" @click.prevent="onUpdate">
{{ $t("common.confirm-and-update") }}
</NButton>
@@ -110,6 +115,12 @@ const isDirty = computed(() => {
return settingRefList.value.some((settingRef) => settingRef.value?.isDirty);
});
+const onRevert = () => {
+ for (const settingRef of settingRefList.value) {
+ settingRef.value?.revert();
+ }
+};
+
const onUpdate = async () => {
let failedCount = 0;
let totalCount = 0;