Skip to content

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

chore: unify setting update UX (#15279)

ecmadaoe1431c7dd07c
diff --git a/frontend/src/components/EnvironmentForm/AccessControlConfigure.vue b/frontend/src/components/EnvironmentForm/AccessControlConfigure.vue
index 400f158116..93de3be446 100644
--- a/frontend/src/components/EnvironmentForm/AccessControlConfigure.vue
+++ b/frontend/src/components/EnvironmentForm/AccessControlConfigure.vue
@@ -9,10 +9,9 @@
<div>
<div class="w-full inline-flex items-center gap-x-2">
<Switch
- :value="disableCopyDataPolicy"
+ v-model:value="state.disableCopyDataPolicy.active"
:text="true"
:disabled="!allowUpdatePolicy || !hasAccessControlFeature"
- @update:value="updateDisableCopyDataPolicy"
/>
<span class="textlabel">{{
$t("environment.access-control.disable-copy-data-from-sql-editor")
@@ -32,14 +31,10 @@
</div>
<div v-if="adminDataSourceQueruRestrictionEnabled" class="ml-12">
<NRadioGroup
- :value="adminDataSourceQueryRestriction"
- :disabled="!allowUpdatePolicy || !hasAccessControlFeature"
- @update:value="
- (value) =>
- updateAdminDataSourceQueryRestrctionPolicy({
- adminDataSourceRestriction: value,
- })
+ v-model:value="
+ state.dataSourceQueryPolicy.adminDataSourceRestriction
"
+ :disabled="!allowUpdatePolicy || !hasAccessControlFeature"
>
<NRadio
class="w-full"
@@ -78,14 +73,9 @@
<div>
<div class="w-full inline-flex items-center gap-x-2">
<Switch
- :value="dataSourceQueryPolicy?.disallowDdl ?? false"
+ v-model:value="state.dataSourceQueryPolicy.disallowDdl"
:text="true"
:disabled="!allowUpdatePolicy"
- @update:value="
- (on: boolean) => {
- updateAdminDataSourceQueryRestrctionPolicy({ disallowDdl: on });
- }
- "
/>
<span class="textlabel">
{{ $t("environment.statement-execution.disallow-ddl") }}
@@ -93,14 +83,9 @@
</div>
<div class="w-full inline-flex items-center gap-x-2">
<Switch
- :value="dataSourceQueryPolicy?.disallowDml ?? false"
+ v-model:value="state.dataSourceQueryPolicy.disallowDml"
:text="true"
:disabled="!allowUpdatePolicy"
- @update:value="
- (on: boolean) => {
- updateAdminDataSourceQueryRestrctionPolicy({ disallowDml: on });
- }
- "
/>
<span class="textlabel">
{{ $t("environment.statement-execution.disallow-dml") }}
@@ -111,13 +96,14 @@
</template>
<script setup lang="ts">
+import { isEqual, cloneDeep } from "lodash-es";
import { NRadioGroup, NRadio } from "naive-ui";
-import { computed, watchEffect } from "vue";
-import { useI18n } from "vue-i18n";
-import { hasFeature, pushNotification, usePolicyV1Store } from "@/store";
+import { computed, watchEffect, reactive } from "vue";
+import { hasFeature, usePolicyV1Store } from "@/store";
import { environmentNamePrefix } from "@/store/modules/v1/common";
import {
DataSourceQueryPolicy,
+ DisableCopyDataPolicy,
DataSourceQueryPolicy_Restriction,
PolicyType,
} from "@/types/proto/v1/org_policy_service";
@@ -125,13 +111,36 @@ import { hasWorkspacePermissionV2 } from "@/utils";
import { FeatureBadge } from "../FeatureGuard";
import { Switch } from "../v2";
+interface LocalState {
+ disableCopyDataPolicy: DisableCopyDataPolicy;
+ dataSourceQueryPolicy: DataSourceQueryPolicy;
+}
+
const props = defineProps<{
resource: string;
allowEdit: boolean;
}>();
const policyStore = usePolicyV1Store();
-const { t } = useI18n();
+
+const getInitialState = (): LocalState => {
+ return {
+ disableCopyDataPolicy: cloneDeep(
+ policyStore.getPolicyByParentAndType({
+ parentPath: props.resource,
+ policyType: PolicyType.DISABLE_COPY_DATA,
+ })?.disableCopyDataPolicy ?? DisableCopyDataPolicy.fromPartial({})
+ ),
+ dataSourceQueryPolicy: cloneDeep(
+ policyStore.getPolicyByParentAndType({
+ parentPath: props.resource,
+ policyType: PolicyType.DATA_SOURCE_QUERY,
+ })?.dataSourceQueryPolicy ?? DataSourceQueryPolicy.fromPartial({})
+ ),
+ };
+};
+
+const state = reactive<LocalState>(getInitialState());
watchEffect(async () => {
await Promise.all([
@@ -144,33 +153,17 @@ watchEffect(async () => {
policyType: PolicyType.DATA_SOURCE_QUERY,
}),
]);
-});
-
-const disableCopyDataPolicy = computed(() => {
- return policyStore.getPolicyByParentAndType({
- parentPath: props.resource,
- policyType: PolicyType.DISABLE_COPY_DATA,
- })?.disableCopyDataPolicy?.active;
-});
-const dataSourceQueryPolicy = computed(() => {
- return policyStore.getPolicyByParentAndType({
- parentPath: props.resource,
- policyType: PolicyType.DATA_SOURCE_QUERY,
- })?.dataSourceQueryPolicy;
-});
-
-const adminDataSourceQueryRestriction = computed(() => {
- return dataSourceQueryPolicy.value?.adminDataSourceRestriction;
+ Object.assign(state, getInitialState());
});
const adminDataSourceQueruRestrictionEnabled = computed(() => {
return (
- adminDataSourceQueryRestriction.value &&
+ state.dataSourceQueryPolicy.adminDataSourceRestriction &&
[
DataSourceQueryPolicy_Restriction.DISALLOW,
DataSourceQueryPolicy_Restriction.FALLBACK,
- ].includes(adminDataSourceQueryRestriction.value)
+ ].includes(state.dataSourceQueryPolicy.adminDataSourceRestriction)
);
});
@@ -182,48 +175,53 @@ const allowUpdatePolicy = computed(() => {
return props.allowEdit && hasWorkspacePermissionV2("bb.policies.update");
});
-const updateDisableCopyDataPolicy = async (on: boolean) => {
+const updateDisableCopyDataPolicy = async () => {
await policyStore.upsertPolicy({
parentPath: props.resource,
policy: {
type: PolicyType.DISABLE_COPY_DATA,
disableCopyDataPolicy: {
- active: on,
+ ...state.disableCopyDataPolicy,
},
},
});
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.updated"),
- });
};
-const switchDataSourceQueryPolicyEnabled = async (on: boolean) => {
- await updateAdminDataSourceQueryRestrctionPolicy({
- adminDataSourceRestriction: on
- ? DataSourceQueryPolicy_Restriction.DISALLOW
- : DataSourceQueryPolicy_Restriction.RESTRICTION_UNSPECIFIED,
- });
+const switchDataSourceQueryPolicyEnabled = (on: boolean) => {
+ state.dataSourceQueryPolicy.adminDataSourceRestriction = on
+ ? DataSourceQueryPolicy_Restriction.DISALLOW
+ : DataSourceQueryPolicy_Restriction.RESTRICTION_UNSPECIFIED;
};
-const updateAdminDataSourceQueryRestrctionPolicy = async (
- policy: Partial<DataSourceQueryPolicy>
-) => {
+const updateAdminDataSourceQueryRestrctionPolicy = async () => {
await policyStore.upsertPolicy({
parentPath: props.resource,
policy: {
type: PolicyType.DATA_SOURCE_QUERY,
dataSourceQueryPolicy: DataSourceQueryPolicy.fromPartial({
- ...(dataSourceQueryPolicy.value ?? {}),
- ...policy,
+ ...state.dataSourceQueryPolicy,
}),
},
});
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.updated"),
- });
};
+
+defineExpose({
+ isDirty: computed(() => !isEqual(state, getInitialState())),
+ update: async () => {
+ const initialState = getInitialState();
+ if (
+ !isEqual(state.dataSourceQueryPolicy, initialState.dataSourceQueryPolicy)
+ ) {
+ await updateAdminDataSourceQueryRestrctionPolicy();
+ }
+ if (
+ !isEqual(state.disableCopyDataPolicy, initialState.disableCopyDataPolicy)
+ ) {
+ await updateDisableCopyDataPolicy();
+ }
+ },
+ revert: () => {
+ Object.assign(state, getInitialState());
+ },
+});
</script>
diff --git a/frontend/src/components/EnvironmentForm/Buttons.vue b/frontend/src/components/EnvironmentForm/Buttons.vue
index 886a766f50..a250c5f106 100644
--- a/frontend/src/components/EnvironmentForm/Buttons.vue
+++ b/frontend/src/components/EnvironmentForm/Buttons.vue
@@ -60,6 +60,8 @@ const revertEnvironment = () => {
state.value.environment = cloneDeep(environment.value);
state.value.rolloutPolicy = cloneDeep(rolloutPolicy.value);
state.value.environmentTier = cloneDeep(environmentTier.value);
+ events.emit("revert-access-control");
+ events.emit("revert-sql-review");
};
const createEnvironment = () => {
@@ -96,6 +98,9 @@ const updateEnvironment = () => {
});
}
+ events.emit("update-access-control");
+ events.emit("update-sql-review");
+
const env = cloneDeep(environment.value);
if (
state.value.environment.title !== env.title ||
diff --git a/frontend/src/components/EnvironmentForm/Form.vue b/frontend/src/components/EnvironmentForm/Form.vue
index 80338cd73d..437f7ee299 100644
--- a/frontend/src/components/EnvironmentForm/Form.vue
+++ b/frontend/src/components/EnvironmentForm/Form.vue
@@ -90,12 +90,14 @@
<SQLReviewForResource
v-if="features.includes('SQL_REVIEW') && !create"
+ ref="sqlReviewForResourceRef"
:resource="environment.name"
:allow-edit="allowEdit"
/>
<AccessControlConfigure
v-if="features.includes('ACCESS_CONTROL') && !create"
+ ref="accessControlConfigureRef"
:resource="environment.name"
:allow-edit="allowEdit"
/>
@@ -141,9 +143,10 @@
<script lang="tsx" setup>
import { NCheckbox, NInput, NColorPicker } from "naive-ui";
import { Status } from "nice-grpc-common";
-import { computed } from "vue";
+import { computed, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { BBButtonConfirm } from "@/bbkit";
+import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import {
useEnvironmentV1List,
useEnvironmentV1Store,
@@ -196,6 +199,25 @@ const {
} = useEnvironmentFormContext();
const environmentList = useEnvironmentV1List();
+const accessControlConfigureRef =
+ ref<InstanceType<typeof AccessControlConfigure>>();
+const sqlReviewForResourceRef =
+ ref<InstanceType<typeof SQLReviewForResource>>();
+
+watch(
+ () => [
+ accessControlConfigureRef.value?.isDirty ?? false,
+ sqlReviewForResourceRef.value?.isDirty ?? false,
+ ],
+ ([d1, d2]) => {
+ if (d1 || d2) {
+ state.value.policyChanged = true;
+ } else if (!d1 && !d2) {
+ state.value.policyChanged = false;
+ }
+ }
+);
+
const hasEnvironmentPolicyFeature = computed(() =>
hasFeature("bb.feature.environment-tier-policy")
);
@@ -285,4 +307,21 @@ const archiveEnvironment = () => {
const restoreEnvironment = () => {
events.emit("restore", state.value.environment);
};
+
+useEmitteryEventListener(events, "update-access-control", async () => {
+ if (accessControlConfigureRef.value?.isDirty) {
+ await accessControlConfigureRef.value.update();
+ }
+});
+useEmitteryEventListener(events, "revert-access-control", () => {
+ accessControlConfigureRef.value?.revert();
+});
+useEmitteryEventListener(events, "update-sql-review", async () => {
+ if (sqlReviewForResourceRef.value?.isDirty) {
+ await sqlReviewForResourceRef.value.update();
+ }
+});
+useEmitteryEventListener(events, "revert-sql-review", () => {
+ sqlReviewForResourceRef.value?.revert();
+});
</script>
diff --git a/frontend/src/components/EnvironmentForm/context.ts b/frontend/src/components/EnvironmentForm/context.ts
index 09b55a4d87..803cb94123 100644
--- a/frontend/src/components/EnvironmentForm/context.ts
+++ b/frontend/src/components/EnvironmentForm/context.ts
@@ -17,6 +17,7 @@ export type LocalState = {
environment: Environment;
rolloutPolicy: Policy;
environmentTier: EnvironmentTier;
+ policyChanged: boolean;
};
const KEY = Symbol(
@@ -42,6 +43,10 @@ export const provideEnvironmentFormContext = (baseContext: {
policyType: PolicyType;
policy: Policy;
};
+ "update-access-control": undefined;
+ "revert-access-control": undefined;
+ "update-sql-review": undefined;
+ "revert-sql-review": undefined;
archive: Environment;
restore: Environment;
cancel: undefined;
@@ -51,6 +56,7 @@ export const provideEnvironmentFormContext = (baseContext: {
environment: cloneDeep(environment.value),
rolloutPolicy: cloneDeep(rolloutPolicy.value),
environmentTier: environmentTier.value,
+ policyChanged: false,
});
const missingFeature = ref<FeatureType | undefined>(undefined);
const resourceIdField = ref<InstanceType<typeof ResourceIdField>>();
@@ -74,7 +80,8 @@ export const provideEnvironmentFormContext = (baseContext: {
return (
!isEqual(environment.value, state.value.environment) ||
!isEqual(rolloutPolicy.value, state.value.rolloutPolicy) ||
- !isEqual(environmentTier.value, state.value.environmentTier)
+ !isEqual(environmentTier.value, state.value.environmentTier) ||
+ state.value.policyChanged
);
}
};
diff --git a/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue b/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
index c868b99a3c..57cdb4c4b8 100644
--- a/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
+++ b/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
@@ -250,4 +250,8 @@ onMounted(() => {
});
}
});
+
+defineExpose({
+ isDirty: allowSave,
+});
</script>
diff --git a/frontend/src/components/GeneralSetting/AccountSetting.vue b/frontend/src/components/GeneralSetting/AccountSetting.vue
index eca728073b..0cad7443f0 100644
--- a/frontend/src/components/GeneralSetting/AccountSetting.vue
+++ b/frontend/src/components/GeneralSetting/AccountSetting.vue
@@ -15,10 +15,9 @@
<div v-if="!isSaaSMode" class="mb-7 mt-4 lg:mt-0">
<div class="flex items-center gap-x-2">
<Switch
- :value="disallowSignupEnabled"
+ v-model:value="state.disallowSignup"
:text="true"
:disabled="!allowEdit || !hasDisallowSignupFeature"
- @update:value="handleDisallowSignupToggle"
/>
<div class="textlabel flex items-center gap-x-2">
{{ $t("settings.general.workspace.disallow-signup.enable") }}
@@ -32,17 +31,19 @@
<NDivider v-if="!isSaaSMode" />
- <PasswordRestrictionSetting :allow-edit="allowEdit" />
+ <PasswordRestrictionSetting
+ ref="passwordRestrictionSettingRef"
+ :allow-edit="allowEdit"
+ />
<NDivider />
<div>
<div class="mb-7 mt-4 lg:mt-0">
<div class="flex items-center gap-x-2">
<Switch
- :value="require2FAEnabled"
+ v-model:value="state.require2fa"
:text="true"
:disabled="!allowEdit || !has2FAFeature"
- @update:value="handleRequire2FAToggle"
/>
<div class="textlabel flex items-center gap-x-2">
{{ $t("settings.general.workspace.require-2fa.enable") }}
@@ -56,15 +57,35 @@
<div class="mb-7 mt-4 lg:mt-0">
<div class="flex items-center gap-x-2">
<Switch
- :value="disallowPasswordSignin"
+ v-model:value="state.disallowPasswordSignin"
:text="true"
- :disabled="!allowEdit || !hasDisallowPasswordSigninFeature"
- @update:value="handleDisallowPasswordSigninToggle"
+ :disabled="
+ !allowEdit ||
+ !hasDisallowPasswordSigninFeature ||
+ (!state.disallowPasswordSignin && !existActiveIdentityProvider)
+ "
/>
<div class="textlabel flex items-center gap-x-2">
{{
$t("settings.general.workspace.disallow-password-signin.enable")
}}
+ <NTooltip
+ v-if="
+ allowEdit &&
+ hasDisallowPasswordSigninFeature &&
+ !state.disallowPasswordSignin &&
+ !existActiveIdentityProvider
+ "
+ >
+ <template #trigger>
+ <TriangleAlertIcon class="w-4 text-warning" />
+ </template>
+ {{
+ $t(
+ "settings.general.workspace.disallow-password-signin.require-sso-setup"
+ )
+ }}
+ </NTooltip>
<FeatureBadge feature="bb.feature.disallow-password-signin" />
</div>
</div>
@@ -79,7 +100,20 @@
</div>
<NDivider />
- <SignInFrequencySetting :allow-edit="allowEdit" />
+ <SignInFrequencySetting
+ ref="signInFrequencySettingRef"
+ :allow-edit="allowEdit"
+ />
+
+ <div class="flex justify-end">
+ <NButton
+ type="primary"
+ :disabled="!allowEdit || !isDirty"
+ @click.prevent="onUpdate"
+ >
+ {{ $t("common.update") }}
+ </NButton>
+ </div>
</div>
</div>
@@ -91,9 +125,11 @@
</template>
<script lang="ts" setup>
-import { NDivider } from "naive-ui";
+import { isEqual } from "lodash-es";
+import { TriangleAlertIcon } from "lucide-vue-next";
+import { NDivider, NButton, NTooltip } from "naive-ui";
import { storeToRefs } from "pinia";
-import { computed, reactive } from "vue";
+import { computed, reactive, ref, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import { Switch } from "@/components/v2";
import {
@@ -105,22 +141,44 @@ import {
import { useSettingV1Store } from "@/store/modules/v1/setting";
import type { FeatureType } from "@/types";
import { State } from "@/types/proto/v1/common";
+import { type WorkspaceProfileSetting } from "@/types/proto/v1/setting_service";
import { FeatureBadge, FeatureModal } from "../FeatureGuard";
import PasswordRestrictionSetting from "./PasswordRestrictionSetting.vue";
import SignInFrequencySetting from "./SignInFrequencySetting.vue";
interface LocalState {
featureNameForModal?: FeatureType;
+ disallowSignup: boolean;
+ require2fa: boolean;
+ disallowPasswordSignin: boolean;
}
defineProps<{
allowEdit: boolean;
}>();
-const state = reactive<LocalState>({});
const { t } = useI18n();
const settingV1Store = useSettingV1Store();
const actuatorStore = useActuatorV1Store();
+const idpStore = useIdentityProviderStore();
+const passwordRestrictionSettingRef =
+ ref<InstanceType<typeof PasswordRestrictionSetting>>();
+const signInFrequencySettingRef =
+ ref<InstanceType<typeof SignInFrequencySetting>>();
+
+const getInitialState = (): LocalState => {
+ return {
+ disallowSignup:
+ settingV1Store.workspaceProfileSetting?.disallowSignup ?? false,
+ require2fa: settingV1Store.workspaceProfileSetting?.require2fa ?? false,
+ disallowPasswordSignin:
+ settingV1Store.workspaceProfileSetting?.disallowPasswordSignin ?? false,
+ };
+};
+
+const state = reactive<LocalState>({
+ ...getInitialState(),
+});
const { isSaaSMode } = storeToRefs(actuatorStore);
const has2FAFeature = featureToRef("bb.feature.2fa");
@@ -129,88 +187,72 @@ const hasDisallowPasswordSigninFeature = featureToRef(
"bb.feature.disallow-password-signin"
);
-const disallowSignupEnabled = computed((): boolean => {
- return settingV1Store.workspaceProfileSetting?.disallowSignup ?? false;
+watchEffect(async () => {
+ await idpStore.fetchIdentityProviderList();
});
-const require2FAEnabled = computed((): boolean => {
- return settingV1Store.workspaceProfileSetting?.require2fa ?? false;
+
+const existActiveIdentityProvider = computed(() => {
+ return (
+ idpStore.identityProviderList.filter((idp) => idp.state === State.ACTIVE)
+ .length > 0
+ );
});
-const disallowPasswordSignin = computed((): boolean => {
+
+const isDirty = computed(() => {
return (
- settingV1Store.workspaceProfileSetting?.disallowPasswordSignin ?? false
+ passwordRestrictionSettingRef.value?.isDirty ||
+ signInFrequencySettingRef.value?.isDirty ||
+ !isEqual(state, getInitialState())
);
});
-const handleDisallowSignupToggle = async (on: boolean) => {
- if (!hasDisallowSignupFeature.value && on) {
- state.featureNameForModal = "bb.feature.disallow-signup";
- return;
+const onUpdate = async () => {
+ if (passwordRestrictionSettingRef.value?.isDirty) {
+ await passwordRestrictionSettingRef.value.update();
}
- await settingV1Store.updateWorkspaceProfile({
- payload: {
- disallowSignup: on,
- },
- updateMask: ["value.workspace_profile_setting_value.disallow_signup"],
- });
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("settings.general.workspace.config-updated"),
- });
-};
-
-const handleRequire2FAToggle = async (on: boolean) => {
- if (!has2FAFeature.value && on) {
- state.featureNameForModal = "bb.feature.2fa";
- return;
+ if (signInFrequencySettingRef.value?.isDirty) {
+ await signInFrequencySettingRef.value.update();
}
- await settingV1Store.updateWorkspaceProfile({
- payload: {
- require2fa: on,
- },
- updateMask: ["value.workspace_profile_setting_value.require_2fa"],
- });
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("settings.general.workspace.config-updated"),
- });
-};
-
-const handleDisallowPasswordSigninToggle = async (on: boolean) => {
- if (!hasDisallowPasswordSigninFeature.value && on) {
- state.featureNameForModal = "bb.feature.disallow-password-signin";
- return;
+ const updateMasks = [];
+ const payload: Partial<WorkspaceProfileSetting> = {
+ disallowSignup: state.disallowSignup,
+ require2fa: state.require2fa,
+ disallowPasswordSignin: state.disallowPasswordSignin,
+ };
+ if (
+ state.disallowSignup !==
+ settingV1Store.workspaceProfileSetting?.disallowSignup
+ ) {
+ updateMasks.push("value.workspace_profile_setting_value.disallow_signup");
+ }
+ if (state.require2fa !== settingV1Store.workspaceProfileSetting?.require2fa) {
+ updateMasks.push("value.workspace_profile_setting_value.require_2fa");
+ }
+ if (
+ state.disallowPasswordSignin !==
+ settingV1Store.workspaceProfileSetting?.disallowPasswordSignin
+ ) {
+ updateMasks.push(
+ "value.workspace_profile_setting_value.disallow_password_signin"
+ );
}
- if (on) {
- const idpStore = useIdentityProviderStore();
- const idpList = await idpStore.fetchIdentityProviderList();
- if (idpList.filter((idp) => idp.state === State.ACTIVE).length === 0) {
- pushNotification({
- module: "bytebase",
- style: "CRITICAL",
- title: t(
- "settings.general.workspace.disallow-password-signin.require-sso-setup"
- ),
- });
- return;
- }
+ if (updateMasks.length > 0) {
+ await settingV1Store.updateWorkspaceProfile({
+ payload,
+ updateMask: updateMasks,
+ });
}
- await settingV1Store.updateWorkspaceProfile({
- payload: {
- disallowPasswordSignin: on,
- },
- updateMask: [
- "value.workspace_profile_setting_value.disallow_password_signin",
- ],
- });
pushNotification({
module: "bytebase",
style: "SUCCESS",
title: t("settings.general.workspace.config-updated"),
});
};
+
+defineExpose({
+ isDirty,
+});
</script>
diff --git a/frontend/src/components/GeneralSetting/AnnouncementSetting.vue b/frontend/src/components/GeneralSetting/AnnouncementSetting.vue
index f95263591f..d3df90e0d5 100644
--- a/frontend/src/components/GeneralSetting/AnnouncementSetting.vue
+++ b/frontend/src/components/GeneralSetting/AnnouncementSetting.vue
@@ -28,7 +28,7 @@
<div class="flex flex-wrap py-2 radio-set-row gap-4">
<AnnouncementLevelSelect
v-model:level="state.announcement.level"
- :allow-edit="allowEdit"
+ :allow-edit="allowEdit && hasAnnouncementFeature"
/>
</div>
</template>
@@ -57,7 +57,7 @@
:placeholder="
$t('settings.general.workspace.announcement-text.placeholder')
"
- :disabled="!allowEdit"
+ :disabled="!allowEdit || !hasAnnouncementFeature"
/>
</template>
<span class="text-sm text-gray-400 -translate-y-2">
@@ -82,7 +82,7 @@
:placeholder="
$t('settings.general.workspace.extra-link.placeholder')
"
- :disabled="!allowEdit"
+ :disabled="!allowEdit || !hasAnnouncementFeature"
/>
</template>
<span class="text-sm text-gray-400 -translate-y-2">
@@ -100,39 +100,28 @@
:disabled="!allowEdit || !allowSave"
@click.prevent="updateAnnouncementSetting"
>
- <FeatureBadge
- feature="bb.feature.announcement"
- custom-class="mr-1 text-white pointer-events-none"
- />
{{ $t("common.update") }}
</NButton>
</div>
</div>
</div>
-
- <FeatureModal
- feature="bb.feature.announcement"
- :open="state.showFeatureModal"
- @cancel="state.showFeatureModal = false"
- />
</div>
</template>
<script lang="ts" setup>
import { cloneDeep, isEqual } from "lodash-es";
import { NButton, NInput, NTooltip } from "naive-ui";
-import { computed, reactive, watchEffect } from "vue";
+import { computed, reactive } from "vue";
import { useI18n } from "vue-i18n";
import { AnnouncementLevelSelect } from "@/components/v2";
import { pushNotification, featureToRef } from "@/store";
import { useSettingV1Store } from "@/store/modules/v1/setting";
-import type { Announcement } from "@/types/proto/v1/setting_service";
+import { Announcement } from "@/types/proto/v1/setting_service";
import { Announcement_AlertLevel } from "@/types/proto/v1/setting_service";
-import { FeatureBadge, FeatureModal } from "../FeatureGuard";
+import { FeatureBadge } from "../FeatureGuard";
interface LocalState {
announcement: Announcement;
- showFeatureModal: boolean;
}
defineProps<{
@@ -141,48 +130,26 @@ defineProps<{
const { t } = useI18n();
const settingV1Store = useSettingV1Store();
-const hasAnnouncementSetting = featureToRef("bb.feature.announcement");
+const hasAnnouncementFeature = featureToRef("bb.feature.announcement");
-const defaultAnnouncement = function (): Announcement {
- return {
- level: Announcement_AlertLevel.ALERT_LEVEL_INFO,
- text: "",
- link: "",
- };
-};
+const rawAnnouncement = computed(() =>
+ cloneDeep(
+ settingV1Store.workspaceProfileSetting?.announcement ??
+ Announcement.fromPartial({
+ level: Announcement_AlertLevel.ALERT_LEVEL_INFO,
+ })
+ )
+);
const state = reactive<LocalState>({
- announcement: defaultAnnouncement(),
- showFeatureModal: false,
-});
-
-watchEffect(() => {
- const announcement = settingV1Store.workspaceProfileSetting?.announcement;
- if (announcement) {
- state.announcement = cloneDeep(announcement);
- }
+ announcement: cloneDeep(rawAnnouncement.value),
});
const allowSave = computed((): boolean => {
- if (
- settingV1Store.workspaceProfileSetting?.announcement === undefined &&
- state.announcement.text === ""
- ) {
- return false;
- }
-
- return !isEqual(
- settingV1Store.workspaceProfileSetting?.announcement,
- state.announcement
- );
+ return !isEqual(rawAnnouncement.value, state.announcement);
});
const updateAnnouncementSetting = async () => {
- if (!hasAnnouncementSetting.value) {
- state.showFeatureModal = true;
- return;
- }
-
if (state.announcement.text === "" && state.announcement.link !== "") {
state.announcement.link = "";
}
@@ -199,19 +166,15 @@ const updateAnnouncementSetting = async () => {
},
updateMask: ["value.workspace_profile_setting_value.announcement"],
});
+ state.announcement = cloneDeep(rawAnnouncement.value);
pushNotification({
module: "bytebase",
style: "SUCCESS",
title: t("settings.general.workspace.announcement.update-success"),
});
-
- const currentSetting: Announcement | undefined = cloneDeep(
- settingV1Store.workspaceProfileSetting?.announcement
- );
- if (currentSetting === undefined) {
- state.announcement = defaultAnnouncement();
- } else {
- state.announcement = cloneDeep(currentSetting);
- }
};
+
+defineExpose({
+ isDirty: allowSave,
+});
</script>
diff --git a/frontend/src/components/GeneralSetting/BrandingSetting.vue b/frontend/src/components/GeneralSetting/BrandingSetting.vue
index 256cb304bb..c2e7664f57 100644
--- a/frontend/src/components/GeneralSetting/BrandingSetting.vue
+++ b/frontend/src/components/GeneralSetting/BrandingSetting.vue
@@ -194,4 +194,8 @@ const onLogoSelect = (file: File) => {
state.logoFile = file;
state.logoUrl = URL.createObjectURL(file);
};
+
+defineExpose({
+ isDirty: allowSave,
+});
</script>
diff --git a/frontend/src/components/GeneralSetting/DatabaseChangeModeSetting.vue b/frontend/src/components/GeneralSetting/DatabaseChangeModeSetting.vue
index 5f40fc0e53..32a36d06fc 100644
--- a/frontend/src/components/GeneralSetting/DatabaseChangeModeSetting.vue
+++ b/frontend/src/components/GeneralSetting/DatabaseChangeModeSetting.vue
@@ -183,4 +183,8 @@ const goToSQLEditor = () => {
name: SQL_EDITOR_HOME_MODULE,
});
};
+
+defineExpose({
+ isDirty: allowSave,
+});
</script>
diff --git a/frontend/src/components/GeneralSetting/DomainRestrictionSetting.vue b/frontend/src/components/GeneralSetting/DomainRestrictionSetting.vue
index 182a6f7260..ffd7699a2c 100644
--- a/frontend/src/components/GeneralSetting/DomainRestrictionSetting.vue
+++ b/frontend/src/components/GeneralSetting/DomainRestrictionSetting.vue
@@ -47,24 +47,14 @@
</NCheckbox>
</div>
</div>
- <div class="flex justify-end mt-2">
- <NButton
- type="primary"
- :disabled="!allowSaveUpdates"
- @click="saveDomainRestrictionSettings"
- >
- {{ $t("common.update") }}
- </NButton>
- </div>
</div>
</template>
<script lang="ts" setup>
import { head, isEqual } from "lodash-es";
-import { NButton, NCheckbox, NInput } from "naive-ui";
+import { NCheckbox, NInput } from "naive-ui";
import { computed, reactive } from "vue";
-import { useI18n } from "vue-i18n";
-import { pushNotification, featureToRef } from "@/store";
+import { featureToRef } from "@/store";
import { useSettingV1Store } from "@/store/modules/v1/setting";
import { FeatureBadge } from "../FeatureGuard";
@@ -94,34 +84,27 @@ defineProps<{
allowEdit: boolean;
}>();
-const { t } = useI18n();
const settingV1Store = useSettingV1Store();
const state = reactive<LocalState>(getInitialState());
-const allowSaveUpdates = computed(() => {
- return !isEqual(state, getInitialState());
-});
-
const hasFeature = featureToRef("bb.feature.domain-restriction");
-const saveDomainRestrictionSettings = async () => {
- if (state.domain.length === 0) {
- state.enableRestriction = false;
- }
- await settingV1Store.updateWorkspaceProfile({
- payload: {
- domains: state.domain ? [state.domain] : [],
- enforceIdentityDomain: state.enableRestriction,
- },
- updateMask: [
- "value.workspace_profile_setting_value.domains",
- "value.workspace_profile_setting_value.enforce_identity_domain",
- ],
- });
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("settings.general.workspace.config-updated"),
- });
-};
+defineExpose({
+ isDirty: computed(() => !isEqual(state, getInitialState())),
+ update: async () => {
+ if (state.domain.length === 0) {
+ state.enableRestriction = false;
+ }
+ await settingV1Store.updateWorkspaceProfile({
+ payload: {
+ domains: state.domain ? [state.domain] : [],
+ enforceIdentityDomain: state.enableRestriction,
+ },
+ updateMask: [
+ "value.workspace_profile_setting_value.domains",
+ "value.workspace_profile_setting_value.enforce_identity_domain",
+ ],
+ });
+ },
+});
</script>
diff --git a/frontend/src/components/GeneralSetting/MaximumRoleExpirationSetting.vue b/frontend/src/components/GeneralSetting/MaximumRoleExpirationSetting.vue
index ee1b4fa32d..1233827a28 100644
--- a/frontend/src/components/GeneralSetting/MaximumRoleExpirationSetting.vue
+++ b/frontend/src/components/GeneralSetting/MaximumRoleExpirationSetting.vue
@@ -12,7 +12,7 @@
<NInputNumber
v-model:value="state.inputValue"
class="w-40"
- :disabled="!allowChangeSetting || state.neverExpire"
+ :disabled="!allowEdit || state.neverExpire"
:min="1"
:precision="0"
>
@@ -30,11 +30,9 @@
</template>
<script lang="ts" setup>
-import { useDebounceFn } from "@vueuse/core";
+import { isEqual } from "lodash-es";
import { NInputNumber, NCheckbox } from "naive-ui";
-import { computed, reactive, watch } from "vue";
-import { useI18n } from "vue-i18n";
-import { pushNotification } from "@/store";
+import { computed, reactive } from "vue";
import { useSettingV1Store } from "@/store/modules/v1/setting";
import { Duration } from "@/types/proto/google/protobuf/duration";
@@ -60,19 +58,14 @@ interface LocalState {
neverExpire: boolean;
}
-const props = defineProps<{
+defineProps<{
allowEdit: boolean;
}>();
-const { t } = useI18n();
const settingV1Store = useSettingV1Store();
const state = reactive<LocalState>(getInitialState());
-const allowChangeSetting = computed(() => {
- return props.allowEdit;
-});
-
-const handleSettingChange = useDebounceFn(async () => {
+const handleSettingChange = async () => {
let seconds = -1;
if (!state.neverExpire) {
seconds = state.inputValue * 24 * 60 * 60;
@@ -85,17 +78,10 @@ const handleSettingChange = useDebounceFn(async () => {
"value.workspace_profile_setting_value.maximum_role_expiration",
],
});
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("settings.general.workspace.config-updated"),
- });
-}, 2000);
+};
-watch(
- () => [state.inputValue, state.neverExpire],
- () => {
- handleSettingChange();
- }
-);
+defineExpose({
+ isDirty: computed(() => !isEqual(state, getInitialState())),
+ update: handleSettingChange,
+});
</script>
diff --git a/frontend/src/components/GeneralSetting/MaximumSQLResultSizeSetting.vue b/frontend/src/components/GeneralSetting/MaximumSQLResultSizeSetting.vue
index 7c31d9ea72..8a5e5a88c5 100644
--- a/frontend/src/components/GeneralSetting/MaximumSQLResultSizeSetting.vue
+++ b/frontend/src/components/GeneralSetting/MaximumSQLResultSizeSetting.vue
@@ -19,33 +19,19 @@
<template #suffix> MB </template>
</NInputNumber>
</div>
-
- <div v-if="showUpdateButton" class="flex justify-end mt-2">
- <NButton
- type="primary"
- :disabled="!allowEdit || !allowUpdate"
- @click="handleClickUpdate"
- >
- {{ $t("common.update") }}
- </NButton>
- </div>
</div>
</template>
<script lang="ts" setup>
import Long from "long";
-import { NButton, NInputNumber } from "naive-ui";
+import { NInputNumber } from "naive-ui";
import { ref, computed } from "vue";
-import { useI18n } from "vue-i18n";
-import { pushNotification } from "@/store";
import { useSettingV1Store } from "@/store/modules/v1/setting";
-const props = defineProps<{
+defineProps<{
allowEdit: boolean;
- showUpdateButton?: boolean;
}>();
-const { t } = useI18n();
const settingV1Store = useSettingV1Store();
const timing = ref<ReturnType<typeof setTimeout>>();
@@ -77,24 +63,16 @@ const updateChange = async () => {
},
},
});
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("settings.general.workspace.config-updated"),
- });
};
const handleInput = (value: number | null) => {
if (value === null) return;
if (value === undefined) return;
maximumSQLResultLimit.value = value;
- if (props.showUpdateButton) {
- return;
- }
- updateChange();
};
-const handleClickUpdate = () => {
- updateChange();
-};
+defineExpose({
+ isDirty: allowUpdate,
+ update: updateChange,
+});
</script>
diff --git a/frontend/src/components/GeneralSetting/NetworkSetting.vue b/frontend/src/components/GeneralSetting/NetworkSetting.vue
index 0eda84d7cb..42b168bab1 100644
--- a/frontend/src/components/GeneralSetting/NetworkSetting.vue
+++ b/frontend/src/components/GeneralSetting/NetworkSetting.vue
@@ -146,4 +146,8 @@ const updateNetworkSetting = async () => {
state.gitopsWebhookUrl =
settingV1Store.workspaceProfileSetting?.gitopsWebhookUrl ?? "";
};
+
+defineExpose({
+ isDirty: allowSave,
+});
</script>
diff --git a/frontend/src/components/GeneralSetting/PasswordRestrictionSetting.vue b/frontend/src/components/GeneralSetting/PasswordRestrictionSetting.vue
index 84d015c53e..fca6a546c2 100644
--- a/frontend/src/components/GeneralSetting/PasswordRestrictionSetting.vue
+++ b/frontend/src/components/GeneralSetting/PasswordRestrictionSetting.vue
@@ -9,7 +9,7 @@
<div class="w-full flex flex-col space-y-3">
<div class="flex items-center space-x-2">
<NInputNumber
- :value="passwordRestrictionSetting.minLength"
+ :value="state.minLength"
:readonly="!allowEdit"
class="w-24"
:min="1"
@@ -28,13 +28,13 @@
<span class="textlabel">
{{
$t("settings.general.workspace.password-restriction.min-length", {
- min: passwordRestrictionSetting.minLength || DEFAULT_MIN_LENGTH,
+ min: state.minLength || DEFAULT_MIN_LENGTH,
})
}}
</span>
</div>
<NCheckbox
- :checked="passwordRestrictionSetting.requireNumber"
+ :checked="state.requireNumber"
:readonly="!allowEdit"
@update:checked="
(val) => {
@@ -49,7 +49,7 @@
</span>
</NCheckbox>
<NCheckbox
- :checked="passwordRestrictionSetting.requireLetter"
+ :checked="state.requireLetter"
:readonly="!allowEdit"
@update:checked="
(val) => {
@@ -64,7 +64,7 @@
</span>
</NCheckbox>
<NCheckbox
- :checked="passwordRestrictionSetting.requireUppercaseLetter"
+ :checked="state.requireUppercaseLetter"
:readonly="!allowEdit"
@update:checked="
(val) => {
@@ -81,7 +81,7 @@
</span>
</NCheckbox>
<NCheckbox
- :checked="passwordRestrictionSetting.requireSpecialCharacter"
+ :checked="state.requireSpecialCharacter"
:readonly="!allowEdit"
@update:checked="
(val) => {
@@ -98,7 +98,7 @@
</span>
</NCheckbox>
<NCheckbox
- :checked="passwordRestrictionSetting.requireResetPasswordForFirstLogin"
+ :checked="state.requireResetPasswordForFirstLogin"
:readonly="!allowEdit"
@update:checked="
(val) => {
@@ -115,7 +115,7 @@
</span>
</NCheckbox>
<NCheckbox
- :checked="!!passwordRestrictionSetting.passwordRotation"
+ :checked="!!state.passwordRotation"
:readonly="!allowEdit"
class="!flex !items-center"
@update:checked="
@@ -138,13 +138,9 @@
>
<template #day>
<NInputNumber
- v-if="passwordRestrictionSetting.passwordRotation"
+ v-if="state.passwordRotation"
:value="
- Number(
- passwordRestrictionSetting.passwordRotation.seconds.divide(
- 24 * 60 * 60
- )
- )
+ Number(state.passwordRotation.seconds.divide(24 * 60 * 60))
"
:readonly="!allowEdit"
:min="1"
@@ -178,10 +174,10 @@
</template>
<script setup lang="tsx">
+import { cloneDeep, isEqual } from "lodash-es";
import { NInputNumber, NCheckbox } from "naive-ui";
-import { computed, ref } from "vue";
-import { useI18n } from "vue-i18n";
-import { featureToRef, pushNotification } from "@/store";
+import { computed, ref, reactive } from "vue";
+import { featureToRef } from "@/store";
import { useSettingV1Store } from "@/store/modules/v1/setting";
import { Duration } from "@/types/proto/google/protobuf/duration";
import { PasswordRestrictionSetting } from "@/types/proto/v1/setting_service";
@@ -193,7 +189,6 @@ defineProps<{
allowEdit: boolean;
}>();
-const { t } = useI18n();
const settingV1Store = useSettingV1Store();
const showFeatureModal = ref<boolean>(false);
const hasPasswordFeature = featureToRef("bb.feature.password-restriction");
@@ -204,24 +199,29 @@ const passwordRestrictionSetting = computed(
?.passwordRestrictionSetting ?? PasswordRestrictionSetting.fromPartial({})
);
+const state = reactive<PasswordRestrictionSetting>(
+ cloneDeep(passwordRestrictionSetting.value)
+);
+
const onUpdate = async (update: Partial<PasswordRestrictionSetting>) => {
if (!hasPasswordFeature.value) {
showFeatureModal.value = true;
return;
}
- await settingV1Store.upsertSetting({
- name: "bb.workspace.password-restriction",
- value: {
- passwordRestrictionSetting: {
- ...passwordRestrictionSetting.value,
- ...update,
- },
- },
- });
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.updated"),
- });
+ Object.assign(state, update);
};
+
+defineExpose({
+ isDirty: computed(() => !isEqual(passwordRestrictionSetting.value, state)),
+ update: async () => {
+ await settingV1Store.upsertSetting({
+ name: "bb.workspace.password-restriction",
+ value: {
+ passwordRestrictionSetting: {
+ ...state,
+ },
+ },
+ });
+ },
+});
</script>
diff --git a/frontend/src/components/GeneralSetting/RestrictIssueCreationConfigure.vue b/frontend/src/components/GeneralSetting/RestrictIssueCreationConfigure.vue
index ee9a2eb005..88870e5659 100644
--- a/frontend/src/components/GeneralSetting/RestrictIssueCreationConfigure.vue
+++ b/frontend/src/components/GeneralSetting/RestrictIssueCreationConfigure.vue
@@ -2,10 +2,9 @@
<div>
<div class="flex items-center gap-x-2">
<Switch
- :value="restrictIssueCreationForSQLReview"
+ v-model:value="restrictIssueCreationForSQLReview"
:text="true"
:disabled="!allowEdit"
- @update:value="handleRestrictIssueCreationForSQLReviewToggle"
/>
<span class="textlabel">
{{
@@ -27,11 +26,9 @@
</template>
<script setup lang="ts">
-import { computed } from "vue";
-import { useI18n } from "vue-i18n";
+import { computed, ref } from "vue";
import {
hasFeature,
- pushNotification,
usePolicyV1Store,
usePolicyByParentAndType,
} from "@/store";
@@ -48,7 +45,6 @@ const props = defineProps<{
allowEdit: boolean;
}>();
-const { t } = useI18n();
const policyV1Store = usePolicyV1Store();
const allowEdit = computed(() => {
@@ -66,28 +62,29 @@ const { policy } = usePolicyByParentAndType(
}))
);
-const restrictIssueCreationForSQLReview = computed((): boolean => {
- return (
- policy.value?.restrictIssueCreationForSqlReviewPolicy?.disallow ?? false
- );
-});
+const restrictIssueCreationForSQLReview = ref<boolean>(
+ policy.value?.restrictIssueCreationForSqlReviewPolicy?.disallow ?? false
+);
-const handleRestrictIssueCreationForSQLReviewToggle = async (on: boolean) => {
+const handleRestrictIssueCreationForSQLReviewToggle = async () => {
await policyV1Store.upsertPolicy({
parentPath: props.resource,
policy: {
type: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,
resourceType: PolicyResourceType.PROJECT,
restrictIssueCreationForSqlReviewPolicy: {
- disallow: on,
+ disallow: restrictIssueCreationForSQLReview.value,
},
},
});
-
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("settings.general.workspace.config-updated"),
- });
};
+
+defineExpose({
+ isDirty: computed(
+ () =>
+ restrictIssueCreationForSQLReview.value !==
+ (policy.value?.restrictIssueCreationForSqlReviewPolicy?.disallow ?? false)
+ ),
+ update: handleRestrictIssueCreationForSQLReviewToggle,
+});
</script>
diff --git a/frontend/src/components/GeneralSetting/SecuritySetting.vue b/frontend/src/components/GeneralSetting/SecuritySetting.vue
index 4471464c1d..fdb9f3afcc 100644
--- a/frontend/src/components/GeneralSetting/SecuritySetting.vue
+++ b/frontend/src/components/GeneralSetting/SecuritySetting.vue
@@ -15,10 +15,9 @@
<div>
<div class="flex items-center gap-x-2">
<Switch
- :value="watermarkEnabled"
+ v-model:value="state.enableWatermark"
:text="true"
:disabled="!allowEdit || !hasWatermarkFeature"
- @update:value="handleWatermarkToggle"
/>
<span class="textlabel">
{{ $t("settings.general.workspace.watermark.enable") }}
@@ -32,10 +31,9 @@
<div>
<div class="flex items-center gap-x-2">
<Switch
- :value="dataExportEnable"
+ v-model:value="state.enableDataExport"
:text="true"
:disabled="!allowEdit || !hasAccessControlFeature"
- @update:value="handleDataExportToggle"
/>
<span class="textlabel">
{{ $t("settings.general.workspace.data-export.enable") }}
@@ -46,10 +44,33 @@
{{ $t("settings.general.workspace.data-export.description") }}
</div>
</div>
- <RestrictIssueCreationConfigure :resource="''" :allow-edit="allowEdit" />
- <MaximumSQLResultSizeSetting :allow-edit="allowEdit" />
- <MaximumRoleExpirationSetting :allow-edit="allowEdit" />
- <DomainRestrictionSetting :allow-edit="allowEdit" />
+ <RestrictIssueCreationConfigure
+ ref="restrictIssueCreationConfigureRef"
+ :resource="''"
+ :allow-edit="allowEdit"
+ />
+ <MaximumSQLResultSizeSetting
+ ref="maximumSQLResultSizeSettingRef"
+ :allow-edit="allowEdit"
+ />
+ <MaximumRoleExpirationSetting
+ ref="maximumRoleExpirationSettingRef"
+ :allow-edit="allowEdit"
+ />
+ <DomainRestrictionSetting
+ ref="domainRestrictionSettingRef"
+ :allow-edit="allowEdit"
+ />
+
+ <div class="flex justify-end">
+ <NButton
+ type="primary"
+ :disabled="!allowEdit || !isDirty"
+ @click.prevent="onUpdate"
+ >
+ {{ $t("common.update") }}
+ </NButton>
+ </div>
</div>
</div>
@@ -61,7 +82,9 @@
</template>
<script lang="ts" setup>
-import { computed, reactive } from "vue";
+import { isEqual } from "lodash-es";
+import { NButton } from "naive-ui";
+import { computed, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
import { Switch } from "@/components/v2";
import {
@@ -84,19 +107,29 @@ import RestrictIssueCreationConfigure from "./RestrictIssueCreationConfigure.vue
interface LocalState {
featureNameForModal?: FeatureType;
+ enableWatermark: boolean;
+ enableDataExport: boolean;
}
defineProps<{
allowEdit: boolean;
}>();
-const state = reactive<LocalState>({});
const { t } = useI18n();
const settingV1Store = useSettingV1Store();
const policyV1Store = usePolicyV1Store();
const hasWatermarkFeature = featureToRef("bb.feature.branding");
const hasAccessControlFeature = featureToRef("bb.feature.access-control");
+const domainRestrictionSettingRef =
+ ref<InstanceType<typeof DomainRestrictionSetting>>();
+const maximumRoleExpirationSettingRef =
+ ref<InstanceType<typeof MaximumRoleExpirationSetting>>();
+const maximumSQLResultSizeSettingRef =
+ ref<InstanceType<typeof MaximumSQLResultSizeSetting>>();
+const restrictIssueCreationConfigureRef =
+ ref<InstanceType<typeof RestrictIssueCreationConfigure>>();
+
const { policy: exportDataPolicy } = usePolicyByParentAndType(
computed(() => ({
parentPath: "",
@@ -104,52 +137,81 @@ const { policy: exportDataPolicy } = usePolicyByParentAndType(
}))
);
-const watermarkEnabled = computed((): boolean => {
- return (
- settingV1Store.getSettingByName("bb.workspace.watermark")?.value
- ?.stringValue === "1"
- );
+const getInitialState = (): LocalState => {
+ return {
+ enableWatermark:
+ settingV1Store.getSettingByName("bb.workspace.watermark")?.value
+ ?.stringValue === "1",
+ enableDataExport: !exportDataPolicy.value?.exportDataPolicy?.disable,
+ };
+};
+
+const state = reactive<LocalState>({
+ ...getInitialState(),
});
-const dataExportEnable = computed(() => {
- return !exportDataPolicy.value?.exportDataPolicy?.disable;
+const isDirty = computed(() => {
+ return (
+ !isEqual(state, getInitialState()) ||
+ domainRestrictionSettingRef.value?.isDirty ||
+ restrictIssueCreationConfigureRef.value?.isDirty ||
+ maximumSQLResultSizeSettingRef.value?.isDirty ||
+ maximumRoleExpirationSettingRef.value?.isDirty
+ );
});
-const handleDataExportToggle = async (on: boolean) => {
+const handleDataExportToggle = async () => {
await policyV1Store.upsertPolicy({
parentPath: "",
policy: {
type: PolicyType.DATA_EXPORT,
resourceType: PolicyResourceType.WORKSPACE,
exportDataPolicy: {
- disable: !on,
+ disable: !state.enableDataExport,
},
},
});
-
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.updated"),
- });
};
-const handleWatermarkToggle = async (on: boolean) => {
- if (!hasWatermarkFeature.value && on) {
- state.featureNameForModal = "bb.feature.watermark";
- return;
- }
- const value = on ? "1" : "0";
+const handleWatermarkToggle = async () => {
+ const value = state.enableWatermark ? "1" : "0";
await settingV1Store.upsertSetting({
name: "bb.workspace.watermark",
value: {
stringValue: value,
},
});
+};
+
+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();
+ }
+ if (maximumRoleExpirationSettingRef.value?.isDirty) {
+ await maximumRoleExpirationSettingRef.value.update();
+ }
+
+ if (state.enableWatermark !== getInitialState().enableWatermark) {
+ await handleWatermarkToggle();
+ }
+ if (state.enableDataExport !== getInitialState().enableDataExport) {
+ await handleDataExportToggle();
+ }
+
pushNotification({
module: "bytebase",
style: "SUCCESS",
- title: t("settings.general.workspace.watermark.update-success"),
+ title: t("settings.general.workspace.config-updated"),
});
};
+
+defineExpose({
+ isDirty,
+});
</script>
diff --git a/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue b/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
index a777794d36..55605b03c8 100644
--- a/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
+++ b/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
@@ -49,7 +49,7 @@
</template>
<script lang="ts" setup>
-import { useDebounceFn } from "@vueuse/core";
+import { isEqual } from "lodash-es";
import { NInputNumber, NRadioGroup, NRadio, NTooltip } from "naive-ui";
import { computed, reactive, watch } from "vue";
import { featureToRef } from "@/store";
@@ -104,7 +104,7 @@ const handleValueFieldClick = () => {
}
};
-const handleFrequencySettingChange = useDebounceFn(async () => {
+const handleFrequencySettingChange = async () => {
const seconds =
state.timeFormat === "HOURS"
? state.inputValue * 60 * 60
@@ -115,7 +115,7 @@ const handleFrequencySettingChange = useDebounceFn(async () => {
},
updateMask: ["value.workspace_profile_setting_value.token_duration"],
});
-}, 2000);
+};
watch(
() => [state.timeFormat],
@@ -126,15 +126,8 @@ watch(
}
);
-watch(
- () => [state.inputValue, state.timeFormat],
- () => {
- if (!hasSecureTokenFeature.value) {
- state.showFeatureModal = true;
- return;
- }
-
- handleFrequencySettingChange();
- }
-);
+defineExpose({
+ isDirty: computed(() => !isEqual(getInitialState(), state)),
+ update: handleFrequencySettingChange,
+});
</script>
diff --git a/frontend/src/components/Project/Settings/ProjectGeneralSettingPanel.vue b/frontend/src/components/Project/Settings/ProjectGeneralSettingPanel.vue
index 09b5e3b467..b946d844d5 100644
--- a/frontend/src/components/Project/Settings/ProjectGeneralSettingPanel.vue
+++ b/frontend/src/components/Project/Settings/ProjectGeneralSettingPanel.vue
@@ -94,4 +94,8 @@ const save = () => {
});
});
};
+
+defineExpose({
+ isDirty: allowSave,
+});
</script>
diff --git a/frontend/src/components/Project/Settings/ProjectIssueRelatedSettingPanel.vue b/frontend/src/components/Project/Settings/ProjectIssueRelatedSettingPanel.vue
index fe643d7f5d..96a0152cb9 100644
--- a/frontend/src/components/Project/Settings/ProjectIssueRelatedSettingPanel.vue
+++ b/frontend/src/components/Project/Settings/ProjectIssueRelatedSettingPanel.vue
@@ -1,9 +1,12 @@
<template>
<div class="w-full flex flex-col justify-start items-start pt-6 space-y-4">
<div class="space-y-2 mb-4">
- <span class="text-lg font-medium text-main">
+ <div class="text-lg font-medium text-main">
{{ $t("project.settings.issue-related.labels.self") }}
- </span>
+ <div class="textinfolabel">
+ {{ $t("project.settings.issue-related.labels.description") }}
+ </div>
+ </div>
<NDynamicTags
:size="'large'"
:disabled="!allowEdit"
@@ -56,10 +59,27 @@
:disabled="
!allowUpdateIssueProjectSetting || state.issueLabels.length === 0
"
- :label="
- $t('project.settings.issue-related.labels.force-issue-labels.self')
- "
- />
+ >
+ <template #default>
+ <div class="flex items-center gap-x-2">
+ {{
+ $t(
+ "project.settings.issue-related.labels.force-issue-labels.self"
+ )
+ }}
+ <NTooltip v-if="allowEdit && state.issueLabels.length === 0">
+ <template #trigger>
+ <TriangleAlertIcon class="w-4 text-warning" />
+ </template>
+ {{
+ $t(
+ "project.settings.issue-related.labels.force-issue-labels.warning"
+ )
+ }}
+ </NTooltip>
+ </div>
+ </template>
+ </NCheckbox>
<p class="text-sm text-gray-400 pl-6 ml-0.5">
{{
$t(
@@ -154,7 +174,15 @@
<script setup lang="tsx">
import { isEqual, cloneDeep } from "lodash-es";
-import { NButton, NDynamicTags, NTag, NColorPicker, NCheckbox } from "naive-ui";
+import { TriangleAlertIcon } from "lucide-vue-next";
+import {
+ NButton,
+ NDynamicTags,
+ NTag,
+ NColorPicker,
+ NCheckbox,
+ NTooltip,
+} from "naive-ui";
import { computed, reactive } from "vue";
import { useI18n } from "vue-i18n";
import { FeatureBadge } from "@/components/FeatureGuard";
@@ -312,4 +340,8 @@ const getUpdateMask = () => {
}
return mask;
};
+
+defineExpose({
+ isDirty: valueChanged,
+});
</script>
diff --git a/frontend/src/components/Project/Settings/ProjectSecuritySettingPanel.vue b/frontend/src/components/Project/Settings/ProjectSecuritySettingPanel.vue
index 52ff8bd730..6500029f07 100644
--- a/frontend/src/components/Project/Settings/ProjectSecuritySettingPanel.vue
+++ b/frontend/src/components/Project/Settings/ProjectSecuritySettingPanel.vue
@@ -5,23 +5,37 @@
</h3>
<SQLReviewForResource
v-if="databaseChangeMode === DatabaseChangeMode.PIPELINE"
+ ref="sqlReviewForResourceRef"
:resource="project.name"
:allow-edit="allowEdit"
/>
<RestrictIssueCreationConfigure
v-if="databaseChangeMode === DatabaseChangeMode.PIPELINE"
+ ref="restrictIssueCreationConfigureRef"
:resource="project.name"
:allow-edit="allowEdit"
/>
- <AccessControlConfigure :resource="project.name" :allow-edit="allowEdit" />
+ <AccessControlConfigure
+ ref="accessControlConfigureRef"
+ :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 } from "@/store";
+import { useAppFeature, pushNotification } from "@/store";
import type { ComposedProject } from "@/types";
import { DatabaseChangeMode } from "@/types/proto/v1/setting_service";
@@ -31,4 +45,40 @@ defineProps<{
}>();
const databaseChangeMode = useAppFeature("bb.feature.database-change-mode");
+const { t } = useI18n();
+
+const restrictIssueCreationConfigureRef =
+ ref<InstanceType<typeof RestrictIssueCreationConfigure>>();
+const accessControlConfigureRef =
+ ref<InstanceType<typeof AccessControlConfigure>>();
+const sqlReviewForResourceRef =
+ ref<InstanceType<typeof SQLReviewForResource>>();
+
+const isDirty = computed(
+ () =>
+ restrictIssueCreationConfigureRef.value?.isDirty ||
+ accessControlConfigureRef.value?.isDirty ||
+ sqlReviewForResourceRef.value?.isDirty
+);
+
+const onUpdate = async () => {
+ if (restrictIssueCreationConfigureRef.value?.isDirty) {
+ await restrictIssueCreationConfigureRef.value.update();
+ }
+ if (sqlReviewForResourceRef.value?.isDirty) {
+ await sqlReviewForResourceRef.value.update();
+ }
+ if (accessControlConfigureRef.value?.isDirty) {
+ await accessControlConfigureRef.value.update();
+ }
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("settings.general.workspace.config-updated"),
+ });
+};
+
+defineExpose({
+ isDirty,
+});
</script>
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vue
index a4231de59e..248253fc1f 100644
--- a/frontend/src/components/ProjectDatabasesPanel.vue
+++ b/frontend/src/components/ProjectDatabasesPanel.vue
@@ -66,13 +66,15 @@
</template>
<script lang="ts" setup>
+import { useClipboard } from "@vueuse/core";
import { PlusIcon } from "lucide-vue-next";
import { NButton } from "naive-ui";
-import { reactive, computed } from "vue";
+import { reactive, computed, onMounted } from "vue";
import { useRouter } from "vue-router";
import { CreateDatabasePrepPanel } from "@/components/CreateDatabasePrepForm";
import { Drawer } from "@/components/v2";
import DatabaseV1Table from "@/components/v2/Model/DatabaseV1Table";
+import { pushNotification } from "@/store";
import type { ComposedDatabase, ComposedProject } from "@/types";
import { UNKNOWN_ID } from "@/types";
import type { SearchParams } from "@/utils";
@@ -112,6 +114,46 @@ const state = reactive<LocalState>({
showCreateDrawer: false,
});
+const { copy: copyTextToClipboard } = useClipboard({
+ legacy: true,
+});
+
+onMounted(() => {
+ const res: string[] = [];
+ for (let i = 7000; i < 7001; i++) {
+ const database = `test${i}`;
+ const sql = `
+CREATE DATABASE IF NOT EXISTS ${database} CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
+USE ${database};
+`;
+ res.push(sql);
+ break;
+ }
+
+ for (let i = 6000; i < 7000; i++) {
+ const sql = `
+CREATE TABLE IF NOT EXISTS principal${i} (
+ id int NOT NULL,
+ name char(255) NOT NULL,
+ email char(255) NOT NULL,
+ PRIMARY KEY (id)
+);
+ `;
+ res.push(sql);
+ }
+
+ copyTextToClipboard(res.join("\n")).then(() => {
+ console.log("sql");
+ console.log(res.join("\n"));
+
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: "SQL copied!",
+ });
+ });
+});
+
const allowToCreateDB = computed(() => {
return (
hasWorkspacePermissionV2("bb.instances.list") &&
diff --git a/frontend/src/components/ProjectSettingPanel.vue b/frontend/src/components/ProjectSettingPanel.vue
index 1c04cd5bf7..ba18ff9b36 100644
--- a/frontend/src/components/ProjectSettingPanel.vue
+++ b/frontend/src/components/ProjectSettingPanel.vue
@@ -1,10 +1,19 @@
<template>
<div class="w-full space-y-6 mb-6">
<div class="divide-y divide-block-border space-y-6">
- <ProjectGeneralSettingPanel :project="project" :allow-edit="allowEdit" />
- <ProjectSecuritySettingPanel :project="project" :allow-edit="allowEdit" />
+ <ProjectGeneralSettingPanel
+ ref="projectGeneralSettingPanelRef"
+ :project="project"
+ :allow-edit="allowEdit"
+ />
+ <ProjectSecuritySettingPanel
+ ref="projectSecuritySettingPanelRef"
+ :project="project"
+ :allow-edit="allowEdit"
+ />
<ProjectIssueRelatedSettingPanel
v-if="databaseChangeMode === DatabaseChangeMode.PIPELINE"
+ ref="projectIssueRelatedSettingPanelRef"
:project="project"
:allow-edit="allowEdit"
/>
@@ -19,6 +28,10 @@
</template>
<script lang="ts" setup>
+import { useEventListener } from "@vueuse/core";
+import { ref, computed } from "vue";
+import { useI18n } from "vue-i18n";
+import { onBeforeRouteLeave } from "vue-router";
import { useAppFeature } from "@/store";
import type { ComposedProject } from "@/types";
import { DatabaseChangeMode } from "@/types/proto/v1/setting_service";
@@ -35,4 +48,37 @@ defineProps<{
}>();
const databaseChangeMode = useAppFeature("bb.feature.database-change-mode");
+const { t } = useI18n();
+
+const projectSecuritySettingPanelRef =
+ ref<InstanceType<typeof ProjectSecuritySettingPanel>>();
+const projectGeneralSettingPanelRef =
+ ref<InstanceType<typeof ProjectGeneralSettingPanel>>();
+const projectIssueRelatedSettingPanelRef =
+ ref<InstanceType<typeof ProjectIssueRelatedSettingPanel>>();
+
+const isDirty = computed(() => {
+ return (
+ projectSecuritySettingPanelRef.value?.isDirty ||
+ projectGeneralSettingPanelRef.value?.isDirty ||
+ projectIssueRelatedSettingPanelRef.value?.isDirty
+ );
+});
+
+useEventListener("beforeunload", (e) => {
+ if (!isDirty.value) {
+ return;
+ }
+ e.returnValue = t("common.leave-without-saving");
+ return e.returnValue;
+});
+
+onBeforeRouteLeave((to, from, next) => {
+ if (isDirty.value) {
+ if (!window.confirm(t("common.leave-without-saving"))) {
+ return;
+ }
+ }
+ next();
+});
</script>
diff --git a/frontend/src/components/SQLReview/components/SQLReviewForResource.vue b/frontend/src/components/SQLReview/components/SQLReviewForResource.vue
index 9c5925c825..b90a0e0e12 100644
--- a/frontend/src/components/SQLReview/components/SQLReviewForResource.vue
+++ b/frontend/src/components/SQLReview/components/SQLReviewForResource.vue
@@ -7,9 +7,8 @@
<div v-if="sqlReviewPolicy" class="inline-flex items-center gap-x-2">
<Switch
v-if="allowEditSQLReviewPolicy"
- :value="sqlReviewPolicy.enforce"
+ v-model:value="enforceSQLReviewPolicy"
:text="true"
- @update:value="toggleSQLReviewPolicy"
/>
<span
class="textlabel normal-link !text-accent"
@@ -40,15 +39,10 @@
<script setup lang="ts">
import { NButton } from "naive-ui";
import { computed, ref } from "vue";
-import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { Switch } from "@/components/v2";
import { WORKSPACE_ROUTE_SQL_REVIEW_DETAIL } from "@/router/dashboard/workspaceRoutes";
-import {
- pushNotification,
- useSQLReviewStore,
- useReviewPolicyByResource,
-} from "@/store";
+import { useSQLReviewStore, useReviewPolicyByResource } from "@/store";
import { hasWorkspacePermissionV2, sqlReviewPolicySlug } from "@/utils";
import SQLReviewPolicySelectPanel from "./SQLReviewPolicySelectPanel.vue";
@@ -57,28 +51,29 @@ const props = defineProps<{
allowEdit: boolean;
}>();
-const { t } = useI18n();
const router = useRouter();
const reviewStore = useSQLReviewStore();
const showReviewSelectPanel = ref<boolean>(false);
+const sqlReviewPolicy = useReviewPolicyByResource(
+ computed(() => props.resource)
+);
+const enforceSQLReviewPolicy = ref<boolean>(
+ sqlReviewPolicy.value?.enforce ?? false
+);
+
const allowEditSQLReviewPolicy = computed(() => {
return props.allowEdit && hasWorkspacePermissionV2("bb.policies.update");
});
-const toggleSQLReviewPolicy = async (on: boolean) => {
+const toggleSQLReviewPolicy = async () => {
const policy = sqlReviewPolicy.value;
if (!policy) return;
const originalOn = policy.enforce;
- if (on === originalOn) return;
+ if (enforceSQLReviewPolicy.value === originalOn) return;
await reviewStore.upsertReviewPolicy({
id: policy.id,
- enforce: on,
- });
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("sql-review.policy-updated"),
+ enforce: enforceSQLReviewPolicy.value,
});
};
@@ -93,7 +88,13 @@ const onSQLReviewPolicyClick = () => {
}
};
-const sqlReviewPolicy = useReviewPolicyByResource(
- computed(() => props.resource)
-);
+defineExpose({
+ isDirty: computed(
+ () =>
+ enforceSQLReviewPolicy.value !== (sqlReviewPolicy.value?.enforce ?? false)
+ ),
+ update: toggleSQLReviewPolicy,
+ revert: () =>
+ (enforceSQLReviewPolicy.value = sqlReviewPolicy.value?.enforce ?? false),
+});
</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 6ed9fd23ff..d9a630529c 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -493,7 +493,6 @@
"security": "Security",
"account": "Account",
"watermark": {
- "update-success": "Watermark setting updated",
"description": "Display watermarks on pages, including username, ID and email.",
"enable": "Enable watermark"
},
@@ -1621,10 +1620,12 @@
"self": "Issue Related",
"labels": {
"self": "Labels",
+ "description": "Labels can be attached in the issues for management",
"configure-labels": "Configure labels",
"force-issue-labels": {
"self": "Require labels for all issues",
- "description": "Require at least one label when creating issues."
+ "description": "Require at least one label when creating issues.",
+ "warning": "Require at least configured one label"
}
},
"allow-modify-statement": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 9200b8fc85..9cdd6b0b9b 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -493,7 +493,6 @@
"security": "Seguridad",
"account": "Cuenta",
"watermark": {
- "update-success": "Configuración de marca de agua actualizada",
"description": "Mostrar marcas de agua en las páginas, incluyendo el nombre de usuario, el ID y el correo electrónico.",
"enable": "Activar marca de agua"
},
@@ -1621,10 +1620,12 @@
"self": "Problema Relacionado",
"labels": {
"self": "Etiquetas",
+ "description": "Se pueden colocar etiquetas en los problemas para su gestión.",
"configure-labels": "Configurar etiquetas",
"force-issue-labels": {
"self": "Requerir etiquetas para todos los problemas",
- "description": "Exija al menos una etiqueta al crear problemas."
+ "description": "Exija al menos una etiqueta al crear problemas.",
+ "warning": "Requiere al menos una etiqueta configurada"
}
},
"allow-modify-statement": {
@@ -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 8488dd4151..725715d74f 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -493,7 +493,6 @@
"security": "セキュリティ",
"account": "アカウント",
"watermark": {
- "update-success": "ウォーターマーク設定が更新されました",
"description": "ユーザー名、ID、メールアドレスを含むページにウォーターマークを表示します。",
"enable": "ウォーターマークをオンにする"
},
@@ -1621,10 +1620,12 @@
"self": "イシュー関連",
"labels": {
"self": "ラベル",
+ "description": "問題にラベルを貼って管理できる",
"configure-labels": "ラベルを設定する",
"force-issue-labels": {
"self": "すべてのイシューにラベルが必要",
- "description": "イシューを作成するときは、少なくとも 1 つのラベルが必要です。"
+ "description": "イシューを作成するときは、少なくとも 1 つのラベルが必要です。",
+ "warning": "少なくとも 1 つのラベルを設定する必要があります"
}
},
"allow-modify-statement": {
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index c3c3641113..b433f72c68 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -493,7 +493,6 @@
"security": "Bảo mật",
"account": "Tài khoản",
"watermark": {
- "update-success": "Đã cập nhật cài đặt hình mờ",
"description": "Hiển thị hình mờ trên các trang, bao gồm tên người dùng, ID và email.",
"enable": "Bật hình mờ"
},
@@ -1621,10 +1620,12 @@
"self": "Liên quan đến vấn đề",
"labels": {
"self": "Nhãn",
+ "description": "Có thể gắn nhãn vào các vấn đề để quản lý",
"configure-labels": "Cấu hình nhãn",
"force-issue-labels": {
"self": "Yêu cầu nhãn cho tất cả các vấn đề",
- "description": "Yêu cầu ít nhất một nhãn khi tạo vấn đề."
+ "description": "Yêu cầu ít nhất một nhãn khi tạo vấn đề.",
+ "warning": "Yêu cầu ít nhất một nhãn được cấu hình"
}
},
"allow-modify-statement": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index dd579c66a1..53895ef250 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -493,7 +493,6 @@
"security": "安全",
"account": "帐户",
"watermark": {
- "update-success": "水印设置已更新",
"description": "在页面上显示水印,包含用户名、ID 和 Email。",
"enable": "开启水印"
},
@@ -1621,10 +1620,12 @@
"self": "工单相关",
"labels": {
"self": "标签",
+ "description": "可以在工单中附加标签以便管理",
"configure-labels": "配置标签",
"force-issue-labels": {
"self": "要求所有工单都必须有标签",
- "description": "创建工单时必须添加至少一个标签。"
+ "description": "创建工单时必须添加至少一个标签。",
+ "warning": "至少需要配置一个标签"
}
},
"allow-modify-statement": {
diff --git a/frontend/src/views/SettingWorkspaceGeneral.vue b/frontend/src/views/SettingWorkspaceGeneral.vue
index 263c598541..a3c724f5cf 100644
--- a/frontend/src/views/SettingWorkspaceGeneral.vue
+++ b/frontend/src/views/SettingWorkspaceGeneral.vue
@@ -1,19 +1,31 @@
<template>
<div class="space-y-0 divide-y divide-block-border pt-2">
- <DatabaseChangeModeSetting :allow-edit="allowEdit" />
- <NetworkSetting v-if="!isSaaSMode" :allow-edit="allowEdit" />
- <BrandingSetting :allow-edit="allowEdit" />
- <AccountSetting :allow-edit="allowEdit" />
- <SecuritySetting :allow-edit="allowEdit" />
- <AIAugmentationSetting :allow-edit="allowEdit" />
- <AnnouncementSetting :allow-edit="allowEdit" />
+ <DatabaseChangeModeSetting
+ ref="databaseChangeModeSettingRef"
+ :allow-edit="allowEdit"
+ />
+ <NetworkSetting
+ ref="networkSettingRef"
+ v-if="!isSaaSMode"
+ :allow-edit="allowEdit"
+ />
+ <BrandingSetting ref="brandingSettingRef" :allow-edit="allowEdit" />
+ <AccountSetting ref="accountSettingRef" :allow-edit="allowEdit" />
+ <SecuritySetting ref="securitySettingRef" :allow-edit="allowEdit" />
+ <AIAugmentationSetting
+ ref="aiAugmentationSettingRef"
+ :allow-edit="allowEdit"
+ />
+ <AnnouncementSetting ref="announcementSettingRef" :allow-edit="allowEdit" />
</div>
</template>
<script lang="ts" setup>
+import { useEventListener } from "@vueuse/core";
import { storeToRefs } from "pinia";
-import { onMounted } from "vue";
-import { useRoute } from "vue-router";
+import { onMounted, ref, computed } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRoute, onBeforeRouteLeave } from "vue-router";
import {
BrandingSetting,
SecuritySetting,
@@ -32,6 +44,17 @@ defineProps<{
const route = useRoute();
const actuatorStore = useActuatorV1Store();
+const { t } = useI18n();
+
+const accountSettingRef = ref<InstanceType<typeof AccountSetting>>();
+const databaseChangeModeSettingRef =
+ ref<InstanceType<typeof DatabaseChangeModeSetting>>();
+const networkSettingRef = ref<InstanceType<typeof NetworkSetting>>();
+const brandingSettingRef = ref<InstanceType<typeof BrandingSetting>>();
+const securitySettingRef = ref<InstanceType<typeof SecuritySetting>>();
+const aiAugmentationSettingRef =
+ ref<InstanceType<typeof AIAugmentationSetting>>();
+const announcementSettingRef = ref<InstanceType<typeof AnnouncementSetting>>();
onMounted(async () => {
await useSettingV1Store().fetchSettingList();
@@ -41,4 +64,32 @@ onMounted(async () => {
}
});
const { isSaaSMode } = storeToRefs(actuatorStore);
+
+const isDirty = computed(() => {
+ return (
+ accountSettingRef.value?.isDirty ||
+ databaseChangeModeSettingRef.value?.isDirty ||
+ networkSettingRef.value?.isDirty ||
+ brandingSettingRef.value?.isDirty ||
+ aiAugmentationSettingRef.value?.isDirty ||
+ announcementSettingRef.value?.isDirty
+ );
+});
+
+useEventListener("beforeunload", (e) => {
+ if (!isDirty.value) {
+ return;
+ }
+ e.returnValue = t("common.leave-without-saving");
+ return e.returnValue;
+});
+
+onBeforeRouteLeave((to, from, next) => {
+ if (isDirty.value) {
+ if (!window.confirm(t("common.leave-without-saving"))) {
+ return;
+ }
+ }
+ next();
+});
</script>