Skip to content

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

refactor: gh-ost setting section (#16160)

boojack1a40041fc312
diff --git a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/GhostConfigButton.vue b/frontend/src/components/IssueV1/components/Sidebar/GhostSection/GhostConfigButton.vue
deleted file mode 100644
index a27b61e4fd..0000000000
--- a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/GhostConfigButton.vue
+++ /dev/null
@@ -1,23 +0,0 @@
-<template>
- <NButton
- tag="div"
- size="small"
- style="--n-padding: 0 5px"
- @click="showFlagsPanel = true"
- >
- <template #icon>
- <Wrench class="w-4 h-4" />
- </template>
- <template #default>
- {{ $t("task.online-migration.configure") }}
- </template>
- </NButton>
-</template>
-
-<script setup lang="ts">
-import { Wrench } from "lucide-vue-next";
-import { NButton } from "naive-ui";
-import { useIssueGhostContext } from "./common";
-
-const { showFlagsPanel } = useIssueGhostContext();
-</script>
diff --git a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/GhostFlagsPanel.vue b/frontend/src/components/IssueV1/components/Sidebar/GhostSection/GhostFlagsPanel.vue
deleted file mode 100644
index 5d15cc54a5..0000000000
--- a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/GhostFlagsPanel.vue
+++ /dev/null
@@ -1,240 +0,0 @@
-<template>
- <Drawer v-model:show="showFlagsPanel">
- <DrawerContent
- :title="title"
- class="w-[100vw] md:max-w-[calc(100vw-8rem)] md:w-[40vw]"
- >
- <template #default>
- <div class="flex flex-col gap-y-4">
- <div
- class="grid gap-y-4 gap-x-4 items-center text-sm"
- style="grid-template-columns: auto 1fr"
- >
- <div v-if="stage" class="contents">
- <label class="font-medium text-control">
- {{ $t("common.stage") }}
- </label>
- <div class="textinfolabel break-all">
- {{
- environmentStore.getEnvironmentByName(stage.environment).title
- }}
- </div>
- </div>
- <div class="contents">
- <label class="font-medium text-control">
- {{ $t("common.database") }}
- </label>
- <div class="textinfolabel break-all">
- <RichDatabaseName :database="database" />
- </div>
- </div>
- </div>
-
- <p class="font-medium text-control">
- {{ $t("task.online-migration.gho\st-parameters") }}
- <LearnMoreLink
- class="text-sm ml-1"
- url="https://github.com/github/gh-ost/blob/master/doc/command-line-flags.md"
- hide-when-embedded
- />
- </p>
- <FlagsForm v-model:flags="flags" :readonly="readonly" />
- </div>
- </template>
- <template #footer>
- <div class="flex flex-row justify-end gap-x-3">
- <NButton @click="close">{{ $t("common.cancel") }}</NButton>
-
- <NTooltip :disabled="errors.length === 0">
- <template #trigger>
- <NButton
- type="primary"
- :disabled="!isDirty"
- :loading="isUpdating"
- @click="trySave"
- >
- {{ $t("common.save") }}
- </NButton>
- </template>
- <template #default>
- <ErrorList :errors="errors" />
- </template>
- </NTooltip>
- </div>
- </template>
- </DrawerContent>
- </Drawer>
-</template>
-
-<script setup lang="ts">
-import { cloneDeep, isEqual, uniqBy } from "lodash-es";
-import { NButton, NTooltip } from "naive-ui";
-import { computed, ref, watch } from "vue";
-import { useI18n } from "vue-i18n";
-import {
- chooseUpdateTarget,
- notifyNotEditableLegacyIssue,
- specForTask,
- stageForTask,
- useIssueContext,
-} from "@/components/IssueV1/logic";
-import LearnMoreLink from "@/components/LearnMoreLink.vue";
-import { databaseForTask } from "@/components/Rollout/RolloutDetail";
-import ErrorList from "@/components/misc/ErrorList.vue";
-import { Drawer, DrawerContent, RichDatabaseName } from "@/components/v2";
-import { planServiceClient } from "@/grpcweb";
-import {
- pushNotification,
- useDBGroupStore,
- useEnvironmentV1Store,
-} from "@/store";
-import type { Plan_Spec } from "@/types/proto/v1/plan_service";
-import { Task_Type } from "@/types/proto/v1/rollout_service";
-import { extractDatabaseGroupName } from "@/utils";
-import FlagsForm from "./FlagsForm";
-import { allowChangeTaskGhostFlags, useIssueGhostContext } from "./common";
-
-const { t } = useI18n();
-const { showFlagsPanel, denyEditGhostFlagsReasons } = useIssueGhostContext();
-const {
- isCreating,
- issue,
- selectedTask: task,
- dialog,
- events,
-} = useIssueContext();
-const environmentStore = useEnvironmentV1Store();
-const dbGroupStore = useDBGroupStore();
-const isUpdating = ref(false);
-
-const stage = computed(() => {
- return stageForTask(issue.value, task.value);
-});
-const database = computed(() => {
- return databaseForTask(issue.value.projectEntity, task.value);
-});
-const title = computed(() => {
- return t("task.online-migration.configure-ghost-parameters");
-});
-const spec = computed(() => {
- return specForTask(issue.value.planEntity, task.value);
-});
-const config = computed(() => {
- return spec.value?.changeDatabaseConfig;
-});
-const flags = ref<Record<string, string>>({});
-
-const isDirty = computed(() => {
- return !isEqual(config.value?.ghostFlags ?? {}, flags.value);
-});
-const errors = computed(() => {
- if (denyEditGhostFlagsReasons.value.length > 0) {
- return denyEditGhostFlagsReasons.value;
- }
- const errors: string[] = [];
- if (!isDirty.value) {
- errors.push(t("task.online-migration.error.nothing-changed"));
- }
- return errors;
-});
-
-const readonly = computed(() => {
- if (isCreating.value) return false;
- return denyEditGhostFlagsReasons.value.length > 0;
-});
-
-const chooseUpdateSpecs = async () => {
- let isBatchMode = false;
- const target = spec.value?.changeDatabaseConfig?.target;
- if (target && extractDatabaseGroupName(target)) {
- const dbGroup = dbGroupStore.getDBGroupByName(target);
- if (dbGroup) {
- isBatchMode = true;
- }
- }
- const { tasks } = await chooseUpdateTarget(
- issue.value,
- task.value,
- (task) =>
- task.type === Task_Type.DATABASE_SCHEMA_UPDATE_GHOST &&
- allowChangeTaskGhostFlags(issue.value, task),
- dialog,
- t("task.online-migration.ghost-parameters"),
- isBatchMode
- );
-
- const specs = tasks
- .map((task) => specForTask(issue.value.planEntity, task))
- .filter((spec) => !!spec) as Plan_Spec[];
-
- return uniqBy(specs, (spec) => spec.id);
-};
-
-const close = () => {
- flags.value = cloneDeep(config.value?.ghostFlags ?? {});
- showFlagsPanel.value = false;
-};
-
-const trySave = async () => {
- const specs = await chooseUpdateSpecs();
- if (specs.length === 0) return;
-
- if (isCreating.value) {
- specs.forEach((spec) => {
- const config = spec.changeDatabaseConfig;
- if (!config) return;
- config.ghostFlags = cloneDeep(flags.value);
- });
- close();
- } else {
- isUpdating.value = true;
- try {
- const planPatch = cloneDeep(issue.value.planEntity);
- if (!planPatch) {
- notifyNotEditableLegacyIssue();
- return;
- }
-
- const distinctSpecIds = new Set(specs.map((spec) => spec.id));
- const specsToPatch = planPatch.steps
- .flatMap((step) => step.specs)
- .filter((spec) => distinctSpecIds.has(spec.id));
-
- for (let i = 0; i < specsToPatch.length; i++) {
- const spec = specsToPatch[i];
- const config = spec.changeDatabaseConfig;
- if (!config) continue;
- config.ghostFlags = cloneDeep(flags.value);
- }
-
- const updatedPlan = await planServiceClient.updatePlan({
- plan: planPatch,
- updateMask: ["steps"],
- });
-
- issue.value.planEntity = updatedPlan;
-
- events.emit("status-changed", { eager: true });
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.updated"),
- });
- close();
- } finally {
- isUpdating.value = false;
- }
- }
-};
-
-watch(
- () => config.value?.ghostFlags,
- (newFlags, oldFlags) => {
- if (isEqual(newFlags, oldFlags)) {
- return;
- }
- flags.value = cloneDeep(newFlags ?? {});
- },
- { immediate: true, deep: true }
-);
-</script>
diff --git a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/GhostSection.vue b/frontend/src/components/IssueV1/components/Sidebar/GhostSection/GhostSection.vue
deleted file mode 100644
index 370e091728..0000000000
--- a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/GhostSection.vue
+++ /dev/null
@@ -1,87 +0,0 @@
-<template>
- <div v-if="shouldShowGhostSection" class="flex flex-col items-start gap-1">
- <div
- class="w-full flex flex-row items-center justify-between whitespace-nowrap"
- >
- <div class="textlabel flex items-center gap-x-1 whitespace-nowrap">
- <NTooltip>
- <template #trigger>
- {{ $t("task.online-migration.self") }}
- </template>
- <template #default>
- <i18n-t
- tag="p"
- keypath="issue.migration-mode.online.description"
- class="whitespace-pre-line max-w-[20rem]"
- >
- <template #link>
- <!-- TODO: update docs for mariadb -->
- <LearnMoreLink
- url="https://www.bytebase.com/docs/change-database/online-schema-migration-for-mysql?source=console"
- color="light"
- hide-when-embedded
- />
- </template>
- </i18n-t>
- </template>
- </NTooltip>
- <FeatureBadge
- feature="bb.feature.online-migration"
- :instance="instance"
- />
- </div>
- <GhostSwitch />
- </div>
-
- <GhostConfigButton v-if="viewType === 'ON'" />
-
- <GhostFlagsPanel />
-
- <FeatureModal
- :open="showFeatureModal"
- feature="bb.feature.online-migration"
- @cancel="showFeatureModal = false"
- />
- </div>
-</template>
-
-<script lang="ts" setup>
-import { NTooltip } from "naive-ui";
-import { computed } from "vue";
-import { FeatureBadge, FeatureModal } from "@/components/FeatureGuard";
-import { useIssueContext } from "@/components/IssueV1/logic";
-import LearnMoreLink from "@/components/LearnMoreLink.vue";
-import { databaseForTask } from "@/components/Rollout/RolloutDetail";
-import { isDatabaseChangeRelatedIssue } from "@/utils";
-import GhostConfigButton from "./GhostConfigButton.vue";
-import GhostFlagsPanel from "./GhostFlagsPanel.vue";
-import GhostSwitch from "./GhostSwitch.vue";
-import { allowGhostForTask, provideIssueGhostContext } from "./common";
-
-const { issue, selectedTask } = useIssueContext();
-
-const { viewType, showFeatureModal } = provideIssueGhostContext();
-
-const shouldShowGhostSection = computed(() => {
- if (!isDatabaseChangeRelatedIssue(issue.value)) {
- return false;
- }
-
- // Hide ghost section if the release source is set for now.
- // TODO(steven): maybe we can support gh-ost for release source later.
- if (issue.value.planEntity?.releaseSource?.release) {
- return false;
- }
-
- if (!allowGhostForTask(issue.value, selectedTask.value)) {
- return false;
- }
-
- return viewType.value !== "NONE";
-});
-
-const instance = computed(() => {
- return databaseForTask(issue.value.projectEntity, selectedTask.value)
- .instanceResource;
-});
-</script>
diff --git a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/GhostSwitch.vue b/frontend/src/components/IssueV1/components/Sidebar/GhostSection/GhostSwitch.vue
deleted file mode 100644
index 0a9b15f335..0000000000
--- a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/GhostSwitch.vue
+++ /dev/null
@@ -1,209 +0,0 @@
-<template>
- <NTooltip :disabled="errors.length === 0">
- <template #trigger>
- <NSwitch
- :value="checked"
- :disabled="!allowChange"
- :loading="isUpdating"
- class="bb-ghost-switch"
- @update:value="toggleChecked"
- >
- <template #checked>
- <span style="font-size: 10px">{{ $t("common.on") }}</span>
- </template>
- <template #unchecked>
- <span style="font-size: 10px">{{ $t("common.off") }}</span>
- </template>
- </NSwitch>
- </template>
- <template #default>
- <ErrorList :errors="errors" />
- </template>
- </NTooltip>
-
- <InstanceAssignment
- v-if="showMissingInstanceLicense"
- :show="showInstanceAssignmentDrawer"
- @dismiss="showInstanceAssignmentDrawer = false"
- />
-</template>
-
-<script setup lang="tsx">
-import { cloneDeep } from "lodash-es";
-import { NSwitch, NTooltip } from "naive-ui";
-import { computed, ref } from "vue";
-import { useI18n } from "vue-i18n";
-import InstanceAssignment from "@/components/InstanceAssignment.vue";
-import {
- notifyNotEditableLegacyIssue,
- specForTask,
- useIssueContext,
-} from "@/components/IssueV1/logic";
-import { databaseForTask } from "@/components/Rollout/RolloutDetail";
-import type { ErrorItem } from "@/components/misc/ErrorList.vue";
-import { default as ErrorList } from "@/components/misc/ErrorList.vue";
-import { planServiceClient } from "@/grpcweb";
-import { hasFeature, pushNotification, useIssueCommentStore } from "@/store";
-import { Engine } from "@/types/proto/v1/common";
-import { Plan_ChangeDatabaseConfig_Type } from "@/types/proto/v1/plan_service";
-import { Task_Status } from "@/types/proto/v1/rollout_service";
-import { engineNameV1, hasWorkspacePermissionV2 } from "@/utils";
-import {
- allowGhostForTask,
- MIN_GHOST_SUPPORT_MARIADB_VERSION,
- MIN_GHOST_SUPPORT_MYSQL_VERSION,
- useIssueGhostContext,
-} from "./common";
-
-const { t } = useI18n();
-const { isCreating, issue, events, selectedTask } = useIssueContext();
-const { viewType, showFeatureModal, showMissingInstanceLicense } =
- useIssueGhostContext();
-const isUpdating = ref(false);
-const showInstanceAssignmentDrawer = ref(false);
-
-const checked = computed(() => {
- return viewType.value === "ON";
-});
-
-const canManageSubscription = computed((): boolean => {
- return hasWorkspacePermissionV2("bb.settings.set");
-});
-
-const errors = computed(() => {
- const errors: ErrorItem[] = [];
- if (showMissingInstanceLicense.value && !canManageSubscription.value) {
- // Only show the tooltip when current user is not allowed to manage subscription
- // since we will show the InstanceAssignmentDrawer for high-privileged users
- // when clicking on the switch
- errors.push(
- t("subscription.instance-assignment.missing-license-attention")
- );
- }
- const database = databaseForTask(
- issue.value.projectEntity,
- selectedTask.value
- );
- // As we use the same database from backup to save temp tables in gh-ost, check if backup is available.
- if (!database.backupAvailable) {
- errors.push(
- t(
- "task.online-migration.error.not-applicable.needs-database-for-saving-temp-data",
- {
- // The same database name as backup.
- database: "bbdataarchive",
- }
- )
- );
- }
- if (!allowGhostForTask(issue.value, selectedTask.value)) {
- errors.push(
- t(
- "task.online-migration.error.not-applicable.task-doesnt-meet-ghost-requirement"
- )
- );
- errors.push({
- error: `${engineNameV1(Engine.MYSQL)} >= ${MIN_GHOST_SUPPORT_MYSQL_VERSION}, ${engineNameV1(Engine.MARIADB)} >= ${MIN_GHOST_SUPPORT_MARIADB_VERSION}`,
- indent: 1,
- });
- }
- return errors;
-});
-
-const allowChange = computed(() => {
- if (errors.value.length > 0) {
- return false;
- }
- // Always allow changing ghost status when creating.
- if (isCreating.value) {
- return true;
- }
- // Allow changing ghost status only when task is in one of the following states.
- if (
- [
- Task_Status.FAILED,
- Task_Status.CANCELED,
- Task_Status.NOT_STARTED,
- ].includes(selectedTask.value.status)
- ) {
- return true;
- }
- // Otherwise, disallow changing ghost status.
- return false;
-});
-
-const toggleChecked = async (on: boolean) => {
- if (!hasFeature("bb.feature.online-migration")) {
- showFeatureModal.value = true;
- return;
- }
- if (showMissingInstanceLicense.value) {
- if (canManageSubscription.value) {
- showInstanceAssignmentDrawer.value = true;
- }
- return;
- }
- if (errors.value.length > 0) {
- return;
- }
-
- if (isCreating.value) {
- const spec = specForTask(issue.value.planEntity, selectedTask.value);
- if (!spec || !spec.changeDatabaseConfig) return;
- spec.changeDatabaseConfig.type = on
- ? Plan_ChangeDatabaseConfig_Type.MIGRATE_GHOST
- : Plan_ChangeDatabaseConfig_Type.MIGRATE;
- } else {
- const planPatch = cloneDeep(issue.value.planEntity);
- const spec = specForTask(planPatch, selectedTask.value);
- if (!planPatch || !spec || !spec.changeDatabaseConfig) {
- notifyNotEditableLegacyIssue();
- return;
- }
-
- spec.changeDatabaseConfig.type = on
- ? Plan_ChangeDatabaseConfig_Type.MIGRATE_GHOST
- : Plan_ChangeDatabaseConfig_Type.MIGRATE;
- const updatedPlan = await planServiceClient.updatePlan({
- plan: planPatch,
- updateMask: ["steps"],
- });
- issue.value.planEntity = updatedPlan;
-
- const action = on ? "Enable" : "Disable";
- try {
- await useIssueCommentStore().createIssueComment({
- issueName: issue.value.name,
- comment: `${action} online migration for task [${selectedTask.value.target}].`,
- });
- } catch {
- // fail to comment won't be too bad.
- }
-
- events.emit("status-changed", { eager: true });
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.updated"),
- });
- }
-};
-</script>
-
-<style lang="postcss" scoped>
-.bb-ghost-switch {
- --n-width: max(
- var(--n-rail-width),
- calc(var(--n-rail-width) + var(--n-button-width) - var(--n-rail-height))
- ) !important;
-}
-.bb-ghost-switch :deep(.n-switch__checked) {
- padding-right: calc(var(--n-rail-height) - var(--n-offset) + 1px);
-}
-.bb-ghost-switch :deep(.n-switch__unchecked) {
- padding-left: calc(var(--n-rail-height) - var(--n-offset) + 1px);
-}
-.bb-ghost-switch :deep(.n-switch__button-placeholder) {
- width: calc(1.25 * var(--n-rail-height));
-}
-</style>
diff --git a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/common.ts b/frontend/src/components/IssueV1/components/Sidebar/GhostSection/common.ts
deleted file mode 100644
index afaee6a8b7..0000000000
--- a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/common.ts
+++ /dev/null
@@ -1,226 +0,0 @@
-import { uniqBy } from "lodash-es";
-import { v4 as uuidv4 } from "uuid";
-import type { InjectionKey, Ref } from "vue";
-import { computed, inject, provide, ref } from "vue";
-import { useI18n } from "vue-i18n";
-import {
- getLocalSheetByName,
- isGroupingChangeTaskV1,
- sheetNameForSpec,
- specForTask,
- useIssueContext,
-} from "@/components/IssueV1/logic";
-import { databaseForTask } from "@/components/Rollout/RolloutDetail";
-import {
- useCurrentUserV1,
- useStorageStore,
- useSubscriptionV1Store,
- extractUserId,
-} from "@/store";
-import type { ComposedDatabase, ComposedIssue } from "@/types";
-import { Engine } from "@/types/proto/v1/common";
-import { IssueStatus } from "@/types/proto/v1/issue_service";
-import {
- Plan_ChangeDatabaseConfig_Type,
- type Plan_Spec,
-} from "@/types/proto/v1/plan_service";
-import type { Task } from "@/types/proto/v1/rollout_service";
-import {
- Task_Status,
- task_StatusToJSON,
-} from "@/types/proto/v1/rollout_service";
-import {
- flattenTaskV1List,
- getSheetStatement,
- hasProjectPermissionV2,
- semverCompare,
-} from "@/utils";
-
-export const MIN_GHOST_SUPPORT_MYSQL_VERSION = "5.6.0";
-
-export const MIN_GHOST_SUPPORT_MARIADB_VERSION = "10.6.0";
-
-export type GhostUIViewType = "NONE" | "OFF" | "ON";
-
-export type IssueGhostContext = {
- viewType: Ref<GhostUIViewType>;
- showFlagsPanel: Ref<boolean>;
- denyEditGhostFlagsReasons: Ref<string[]>;
- showFeatureModal: Ref<boolean>;
- showMissingInstanceLicense: Ref<boolean>;
- toggleGhost: (on: boolean) => Promise<void>;
-};
-
-export const KEY = Symbol(
- "bb.issue.context.ghost"
-) as InjectionKey<IssueGhostContext>;
-
-export const useIssueGhostContext = () => {
- return inject(KEY)!;
-};
-
-export const provideIssueGhostContext = () => {
- const { t } = useI18n();
- const me = useCurrentUserV1();
- const {
- isCreating,
- issue,
- selectedTask: task,
- reInitialize,
- } = useIssueContext();
-
- const viewType = computed((): GhostUIViewType => {
- return ghostViewTypeForTask(issue.value, task.value);
- });
- const showFlagsPanel = ref(false);
-
- const denyEditGhostFlagsReasons = computed(() => {
- if (isCreating.value) {
- return [];
- }
-
- if (issue.value.status !== IssueStatus.OPEN) {
- return [t("issue.error.issue-is-not-open")];
- }
-
- const errors: string[] = [];
-
- if (extractUserId(issue.value.creator) !== me.value.email) {
- if (
- !hasProjectPermissionV2(issue.value.projectEntity, "bb.plans.update")
- ) {
- return [t("issue.error.you-don-have-privilege-to-edit-this-issue")];
- }
- }
- if (!allowChangeTaskGhostFlags(issue.value, task.value)) {
- errors.push(
- t("task.online-migration.error.x-status-task-is-not-editable", {
- status: task_StatusToJSON(task.value.status),
- })
- );
- }
- return errors;
- });
-
- const showFeatureModal = ref(false);
- const showMissingInstanceLicense = computed(() => {
- const instances = uniqBy(
- flattenTaskV1List(issue.value.rolloutEntity).map(
- (task) =>
- databaseForTask(issue.value.projectEntity, task).instanceResource
- ),
- (instance) => instance.name
- );
- const subscriptionStore = useSubscriptionV1Store();
- return instances.some((instance) => {
- return subscriptionStore.instanceMissingLicense(
- "bb.feature.online-migration",
- instance
- );
- });
- });
-
- const toggleGhost = async (on: boolean) => {
- const overrides: Record<string, string> = {};
- if (on) {
- overrides["ghost"] = "1";
- } else {
- overrides["ghost"] = "";
- }
-
- // Backup editing statements to `overrides.sqlMap`
- const flattenSpecs = (issue.value.planEntity?.steps ?? []).flatMap(
- (step) => step.specs
- );
- const sqlMap: Record<string, string> = {};
- flattenSpecs.forEach((spec) => {
- const target = spec.changeDatabaseConfig!.target;
- const sheetName = sheetNameForSpec(spec);
- const sheet = getLocalSheetByName(sheetName);
- sqlMap[target] = getSheetStatement(sheet);
- });
- const sqlMapStorageKey = `bb.issues.sql-map.${uuidv4()}`;
- useStorageStore().put(sqlMapStorageKey, sqlMap);
- overrides["sqlMapStorageKey"] = sqlMapStorageKey;
-
- await reInitialize(overrides);
- };
-
- const context: IssueGhostContext = {
- viewType,
- showFlagsPanel,
- denyEditGhostFlagsReasons,
- showFeatureModal,
- showMissingInstanceLicense,
- toggleGhost,
- };
-
- provide(KEY, context);
-
- return context;
-};
-
-export const allowChangeTaskGhostFlags = (issue: ComposedIssue, task: Task) => {
- return [
- Task_Status.STATUS_UNSPECIFIED, // Pending create
- Task_Status.NOT_STARTED,
- Task_Status.FAILED,
- Task_Status.CANCELED,
- ].includes(task.status);
-};
-
-export const allowGhostForDatabase = (database: ComposedDatabase) => {
- return (
- (database.instanceResource.engine === Engine.MYSQL &&
- semverCompare(
- database.instanceResource.engineVersion,
- MIN_GHOST_SUPPORT_MYSQL_VERSION,
- "gte"
- )) ||
- (database.instanceResource.engine === Engine.MARIADB &&
- semverCompare(
- database.instanceResource.engineVersion,
- MIN_GHOST_SUPPORT_MARIADB_VERSION,
- "gte"
- ))
- );
-};
-
-export const allowGhostForSpec = (spec: Plan_Spec | undefined) => {
- const config = spec?.changeDatabaseConfig;
- if (!config) return false;
-
- return [
- Plan_ChangeDatabaseConfig_Type.MIGRATE,
- Plan_ChangeDatabaseConfig_Type.MIGRATE_GHOST,
- ].includes(config.type);
-};
-
-export const allowGhostForTask = (issue: ComposedIssue, task: Task) => {
- return (
- allowGhostForSpec(specForTask(issue.planEntity, task)) &&
- allowGhostForDatabase(databaseForTask(issue.projectEntity, task))
- );
-};
-
-export const ghostViewTypeForTask = (
- issue: ComposedIssue,
- task: Task
-): GhostUIViewType => {
- if (isGroupingChangeTaskV1(issue, task)) {
- return "NONE";
- }
-
- const spec = specForTask(issue.planEntity, task);
- const config = spec?.changeDatabaseConfig;
- if (!config) {
- return "NONE";
- }
- if (config.type === Plan_ChangeDatabaseConfig_Type.MIGRATE) {
- return "OFF";
- }
- if (config.type === Plan_ChangeDatabaseConfig_Type.MIGRATE_GHOST) {
- return "ON";
- }
- return "NONE";
-};
diff --git a/frontend/src/components/IssueV1/components/Sidebar/Sidebar.vue b/frontend/src/components/IssueV1/components/Sidebar/Sidebar.vue
index 6ea27205c2..5668c48a02 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/Sidebar.vue
+++ b/frontend/src/components/IssueV1/components/Sidebar/Sidebar.vue
@@ -9,16 +9,40 @@
<EarliestAllowedTime />
<PreBackupSection />
- <GhostSection />
+ <GhostSection v-if="shouldShowGhostSection" />
</div>
</template>
<script lang="ts" setup>
+import { computed } from "vue";
+import { GhostSection } from "@/components/Plan/components/Sidebar";
+import { provideGhostSettingContext } from "@/components/Plan/components/Sidebar/GhostSection/context";
+import type { Plan } from "@/types/proto/v1/plan_service";
+import { specForTask, useIssueContext } from "../../logic";
import EarliestAllowedTime from "./EarliestAllowedTime.vue";
-import GhostSection from "./GhostSection";
import IssueLabels from "./IssueLabels.vue";
import PreBackupSection from "./PreBackupSection";
import ReleaseInfo from "./ReleaseInfo.vue";
import ReviewSection from "./ReviewSection";
import TaskCheckSummarySection from "./TaskCheckSummarySection";
+
+const { isCreating, selectedTask, issue, events } = useIssueContext();
+
+const { shouldShow: shouldShowGhostSection, events: ghostEvents } =
+ provideGhostSettingContext({
+ isCreating,
+ project: computed(() => issue.value.projectEntity),
+ plan: computed(() => issue.value.planEntity as Plan),
+ selectedSpec: computed(() =>
+ specForTask(issue.value.planEntity, selectedTask.value)
+ ),
+ selectedTask: selectedTask,
+ issue,
+ });
+
+ghostEvents.on("update", () => {
+ events.emit("status-changed", {
+ eager: true,
+ });
+});
</script>
diff --git a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/FlagsForm/BoolFlag.vue b/frontend/src/components/Plan/components/Sidebar/GhostSection/FlagsForm/BoolFlag.vue
similarity index 100%
rename from frontend/src/components/IssueV1/components/Sidebar/GhostSection/FlagsForm/BoolFlag.vue
rename to frontend/src/components/Plan/components/Sidebar/GhostSection/FlagsForm/BoolFlag.vue
diff --git a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/FlagsForm/FlagsForm.vue b/frontend/src/components/Plan/components/Sidebar/GhostSection/FlagsForm/FlagsForm.vue
similarity index 100%
rename from frontend/src/components/IssueV1/components/Sidebar/GhostSection/FlagsForm/FlagsForm.vue
rename to frontend/src/components/Plan/components/Sidebar/GhostSection/FlagsForm/FlagsForm.vue
diff --git a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/FlagsForm/constants.ts b/frontend/src/components/Plan/components/Sidebar/GhostSection/FlagsForm/constants.ts
similarity index 100%
rename from frontend/src/components/IssueV1/components/Sidebar/GhostSection/FlagsForm/constants.ts
rename to frontend/src/components/Plan/components/Sidebar/GhostSection/FlagsForm/constants.ts
diff --git a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/FlagsForm/index.ts b/frontend/src/components/Plan/components/Sidebar/GhostSection/FlagsForm/index.ts
similarity index 100%
rename from frontend/src/components/IssueV1/components/Sidebar/GhostSection/FlagsForm/index.ts
rename to frontend/src/components/Plan/components/Sidebar/GhostSection/FlagsForm/index.ts
diff --git a/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostFlagsPanel.vue b/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostFlagsPanel.vue
new file mode 100644
index 0000000000..d183a8a689
--- /dev/null
+++ b/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostFlagsPanel.vue
@@ -0,0 +1,140 @@
+<template>
+ <Drawer :show="show">
+ <DrawerContent
+ :title="title"
+ class="w-[100vw] md:max-w-[calc(100vw-8rem)] md:w-[40vw]"
+ >
+ <template #default>
+ <div class="flex flex-col gap-y-4">
+ <p class="font-medium text-control">
+ {{ $t("task.online-migration.gho\st-parameters") }}
+ <LearnMoreLink
+ class="text-sm ml-1"
+ url="https://github.com/github/gh-ost/blob/master/doc/command-line-flags.md"
+ hide-when-embedded
+ />
+ </p>
+ <FlagsForm v-model:flags="flags" :readonly="readonly" />
+ </div>
+ </template>
+ <template #footer>
+ <div class="flex flex-row justify-end gap-x-3">
+ <NButton @click="close">{{ $t("common.cancel") }}</NButton>
+ <NTooltip :disabled="errors.length === 0">
+ <template #trigger>
+ <NButton type="primary" :disabled="!isDirty" @click="trySave">
+ {{ $t("common.save") }}
+ </NButton>
+ </template>
+ <template #default>
+ <ErrorList :errors="errors" />
+ </template>
+ </NTooltip>
+ </div>
+ </template>
+ </DrawerContent>
+ </Drawer>
+</template>
+
+<script setup lang="ts">
+import { cloneDeep, isEqual } from "lodash-es";
+import { NButton, NTooltip } from "naive-ui";
+import { computed, ref, watch } from "vue";
+import { useI18n } from "vue-i18n";
+import LearnMoreLink from "@/components/LearnMoreLink.vue";
+import ErrorList from "@/components/misc/ErrorList.vue";
+import { Drawer, DrawerContent } from "@/components/v2";
+import { planServiceClient } from "@/grpcweb";
+import { pushNotification } from "@/store";
+import { flattenSpecList } from "@/utils";
+import FlagsForm from "./FlagsForm";
+import { useGhostSettingContext } from "./context";
+
+defineProps<{
+ show: boolean;
+}>();
+
+const emits = defineEmits<{
+ (e: "update:show", value: boolean): void;
+}>();
+
+const { t } = useI18n();
+const { isCreating, allowChange, plan, selectedSpec, events } =
+ useGhostSettingContext();
+
+const title = computed(() => {
+ return t("task.online-migration.configure-ghost-parameters");
+});
+const config = computed(() => {
+ return selectedSpec.value?.changeDatabaseConfig;
+});
+const flags = ref<Record<string, string>>({});
+
+const isDirty = computed(() => {
+ return !isEqual(config.value?.ghostFlags ?? {}, flags.value);
+});
+const errors = computed(() => {
+ const errors: string[] = [];
+ if (!isDirty.value) {
+ errors.push(t("task.online-migration.error.nothing-changed"));
+ }
+ return errors;
+});
+
+const readonly = computed(() => {
+ if (isCreating.value) return false;
+ return !allowChange.value;
+});
+
+const close = () => {
+ flags.value = cloneDeep(config.value?.ghostFlags ?? {});
+ emits("update:show", false);
+};
+
+const trySave = async () => {
+ if (errors.value.length > 0) {
+ return;
+ }
+
+ if (isCreating.value) {
+ if (!selectedSpec.value || !selectedSpec.value.changeDatabaseConfig) return;
+ selectedSpec.value.changeDatabaseConfig.ghostFlags = cloneDeep(flags.value);
+ } else {
+ const planPatch = cloneDeep(plan.value);
+ const spec = flattenSpecList(planPatch).find((spec) => {
+ return spec.id === selectedSpec.value?.id;
+ });
+ if (!planPatch || !spec || !spec.changeDatabaseConfig) {
+ // Should not reach here.
+ throw new Error(
+ "Plan or spec is not defined. Cannot update gh-ost flags."
+ );
+ }
+
+ spec.changeDatabaseConfig.ghostFlags = cloneDeep(flags.value);
+ await planServiceClient.updatePlan({
+ plan: planPatch,
+ updateMask: ["steps"],
+ });
+
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.updated"),
+ });
+ events.emit("update");
+ }
+ close();
+};
+
+watch(
+ () => config.value?.ghostFlags,
+ (newFlags, oldFlags) => {
+ if (isEqual(newFlags, oldFlags)) {
+ return;
+ }
+ flags.value = cloneDeep(newFlags ?? {});
+ },
+ { immediate: true, deep: true }
+);
+</script>
diff --git a/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSection.vue b/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSection.vue
new file mode 100644
index 0000000000..68b27cc28d
--- /dev/null
+++ b/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSection.vue
@@ -0,0 +1,75 @@
+<template>
+ <div class="flex flex-col items-start gap-1">
+ <div
+ class="w-full flex flex-row items-center justify-between whitespace-nowrap"
+ >
+ <div class="textlabel flex items-center gap-x-1 whitespace-nowrap">
+ <NTooltip>
+ <template #trigger>
+ {{ $t("task.online-migration.self") }}
+ </template>
+ <template #default>
+ <i18n-t
+ tag="p"
+ keypath="issue.migration-mode.online.description"
+ class="whitespace-pre-line max-w-[20rem]"
+ >
+ <template #link>
+ <!-- TODO: update docs for mariadb -->
+ <LearnMoreLink
+ url="https://www.bytebase.com/docs/change-database/online-schema-migration-for-mysql?source=console"
+ color="light"
+ hide-when-embedded
+ />
+ </template>
+ </i18n-t>
+ </template>
+ </NTooltip>
+ <FeatureBadge
+ feature="bb.feature.online-migration"
+ :instance="instance"
+ />
+ </div>
+ <GhostSwitch />
+ </div>
+
+ <NButton
+ v-if="enabled && allowChange"
+ tag="div"
+ size="small"
+ style="--n-padding: 0 5px"
+ @click="showFlagsPanel = true"
+ >
+ <template #icon>
+ <WrenchIcon class="w-4 h-4" />
+ </template>
+ <template #default>
+ {{ $t("task.online-migration.configure") }}
+ </template>
+ </NButton>
+
+ <GhostFlagsPanel
+ :show="showFlagsPanel"
+ @update:show="(show) => (showFlagsPanel = show)"
+ />
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { WrenchIcon } from "lucide-vue-next";
+import { NButton, NTooltip } from "naive-ui";
+import { computed, ref } from "vue";
+import { FeatureBadge } from "@/components/FeatureGuard";
+import LearnMoreLink from "@/components/LearnMoreLink.vue";
+import GhostFlagsPanel from "./GhostFlagsPanel.vue";
+import GhostSwitch from "./GhostSwitch.vue";
+import { useGhostSettingContext } from "./context";
+
+const showFlagsPanel = ref(false);
+
+const { allowChange, enabled, database } = useGhostSettingContext();
+
+const instance = computed(() => {
+ return database.value.instanceResource;
+});
+</script>
diff --git a/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSwitch.vue b/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSwitch.vue
new file mode 100644
index 0000000000..4ab1f187b0
--- /dev/null
+++ b/frontend/src/components/Plan/components/Sidebar/GhostSection/GhostSwitch.vue
@@ -0,0 +1,117 @@
+<template>
+ <NTooltip :disabled="errors.length === 0">
+ <template #trigger>
+ <NSwitch
+ :value="enabled"
+ :disabled="!allowChange"
+ @update:value="toggleChecked"
+ />
+ </template>
+ <template #default>
+ <ErrorList :errors="errors" />
+ </template>
+ </NTooltip>
+</template>
+
+<script setup lang="tsx">
+import { cloneDeep } from "lodash-es";
+import { NSwitch, NTooltip } from "naive-ui";
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
+import type { ErrorItem } from "@/components/misc/ErrorList.vue";
+import { default as ErrorList } from "@/components/misc/ErrorList.vue";
+import { planServiceClient } from "@/grpcweb";
+import { pushNotification } from "@/store";
+import { Engine } from "@/types/proto/v1/common";
+import { Plan_ChangeDatabaseConfig_Type } from "@/types/proto/v1/plan_service";
+import { engineNameV1, flattenSpecList } from "@/utils";
+import {
+ allowGhostForDatabase,
+ MIN_GHOST_SUPPORT_MARIADB_VERSION,
+ MIN_GHOST_SUPPORT_MYSQL_VERSION,
+} from "./common";
+import { useGhostSettingContext } from "./context";
+
+const { t } = useI18n();
+const {
+ isCreating,
+ plan,
+ selectedSpec,
+ allowChange,
+ enabled,
+ database,
+ events,
+} = useGhostSettingContext();
+
+const errors = computed(() => {
+ const errors: ErrorItem[] = [];
+ if (!database.value.instanceResource.activation) {
+ errors.push(
+ t("subscription.instance-assignment.missing-license-attention")
+ );
+ }
+ // As we use the same database from backup to save temp tables in gh-ost, check if backup is available.
+ if (!database.value.backupAvailable) {
+ errors.push(
+ t(
+ "task.online-migration.error.not-applicable.needs-database-for-saving-temp-data",
+ {
+ // The same database name as backup.
+ database: "bbdataarchive",
+ }
+ )
+ );
+ }
+ if (!allowGhostForDatabase(database.value)) {
+ errors.push(
+ t(
+ "task.online-migration.error.not-applicable.task-doesnt-meet-ghost-requirement"
+ )
+ );
+ errors.push({
+ error: `${engineNameV1(Engine.MYSQL)} >= ${MIN_GHOST_SUPPORT_MYSQL_VERSION}, ${engineNameV1(Engine.MARIADB)} >= ${MIN_GHOST_SUPPORT_MARIADB_VERSION}`,
+ indent: 1,
+ });
+ }
+ return errors;
+});
+
+const toggleChecked = async (on: boolean) => {
+ if (errors.value.length > 0) {
+ return;
+ }
+
+ if (isCreating.value) {
+ if (!selectedSpec.value || !selectedSpec.value.changeDatabaseConfig) return;
+ selectedSpec.value.changeDatabaseConfig.type = on
+ ? Plan_ChangeDatabaseConfig_Type.MIGRATE_GHOST
+ : Plan_ChangeDatabaseConfig_Type.MIGRATE;
+ } else {
+ const planPatch = cloneDeep(plan.value);
+ const spec = flattenSpecList(planPatch).find((spec) => {
+ return spec.id === selectedSpec.value?.id;
+ });
+ if (!planPatch || !spec || !spec.changeDatabaseConfig) {
+ // Should not reach here.
+ throw new Error(
+ "Plan or spec is not defined. Cannot update gh-ost setting."
+ );
+ }
+
+ spec.changeDatabaseConfig.type = on
+ ? Plan_ChangeDatabaseConfig_Type.MIGRATE_GHOST
+ : Plan_ChangeDatabaseConfig_Type.MIGRATE;
+ await planServiceClient.updatePlan({
+ plan: planPatch,
+ updateMask: ["steps"],
+ });
+
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.updated"),
+ });
+ events.emit("update");
+ }
+};
+</script>
diff --git a/frontend/src/components/Plan/components/Sidebar/GhostSection/common.ts b/frontend/src/components/Plan/components/Sidebar/GhostSection/common.ts
new file mode 100644
index 0000000000..65cfc48bd0
--- /dev/null
+++ b/frontend/src/components/Plan/components/Sidebar/GhostSection/common.ts
@@ -0,0 +1,58 @@
+import { isGroupingChangeSpec } from "@/components/Plan/logic";
+import type { ComposedDatabase } from "@/types";
+import { Engine } from "@/types/proto/v1/common";
+import {
+ Plan_ChangeDatabaseConfig_Type,
+ type Plan_Spec,
+} from "@/types/proto/v1/plan_service";
+import { semverCompare } from "@/utils";
+
+export const MIN_GHOST_SUPPORT_MYSQL_VERSION = "5.6.0";
+
+export const MIN_GHOST_SUPPORT_MARIADB_VERSION = "10.6.0";
+
+export const allowGhostForDatabase = (database: ComposedDatabase) => {
+ return (
+ (database.instanceResource.engine === Engine.MYSQL &&
+ semverCompare(
+ database.instanceResource.engineVersion,
+ MIN_GHOST_SUPPORT_MYSQL_VERSION,
+ "gte"
+ )) ||
+ (database.instanceResource.engine === Engine.MARIADB &&
+ semverCompare(
+ database.instanceResource.engineVersion,
+ MIN_GHOST_SUPPORT_MARIADB_VERSION,
+ "gte"
+ ))
+ );
+};
+
+export const allowGhostForSpec = (spec: Plan_Spec | undefined) => {
+ const config = spec?.changeDatabaseConfig;
+ if (!config) return false;
+
+ return [
+ Plan_ChangeDatabaseConfig_Type.MIGRATE,
+ Plan_ChangeDatabaseConfig_Type.MIGRATE_GHOST,
+ ].includes(config.type);
+};
+
+export const getGhostEnabledForSpec = (
+ spec: Plan_Spec
+): boolean | undefined => {
+ if (isGroupingChangeSpec(spec)) {
+ return undefined;
+ }
+ const config = spec?.changeDatabaseConfig;
+ if (!config) {
+ return undefined;
+ }
+ if (config.type === Plan_ChangeDatabaseConfig_Type.MIGRATE) {
+ return false;
+ }
+ if (config.type === Plan_ChangeDatabaseConfig_Type.MIGRATE_GHOST) {
+ return true;
+ }
+ return undefined;
+};
diff --git a/frontend/src/components/Plan/components/Sidebar/GhostSection/context.ts b/frontend/src/components/Plan/components/Sidebar/GhostSection/context.ts
new file mode 100644
index 0000000000..4b0f027d80
--- /dev/null
+++ b/frontend/src/components/Plan/components/Sidebar/GhostSection/context.ts
@@ -0,0 +1,144 @@
+import Emittery from "emittery";
+import type { InjectionKey, Ref } from "vue";
+import { computed, inject, provide, unref } from "vue";
+import { databaseForSpec } from "@/components/Plan/logic";
+import { databaseForTask } from "@/components/Rollout/RolloutDetail";
+import { useCurrentUserV1, extractUserId } from "@/store";
+import { unknownDatabase, type ComposedProject } from "@/types";
+import { Issue, IssueStatus } from "@/types/proto/v1/issue_service";
+import type { Plan, Plan_Spec } from "@/types/proto/v1/plan_service";
+import {
+ Task,
+ Task_Status,
+ type Rollout,
+} from "@/types/proto/v1/rollout_service";
+import {
+ flattenTaskV1List,
+ hasProjectPermissionV2,
+ isNullOrUndefined,
+} from "@/utils";
+import {
+ allowGhostForDatabase,
+ allowGhostForSpec,
+ getGhostEnabledForSpec,
+} from "./common";
+
+export const KEY = Symbol(
+ "bb.plan.setting.gh-ost"
+) as InjectionKey<GhostSettingContext>;
+
+export const useGhostSettingContext = () => {
+ return inject(KEY)!;
+};
+
+export const provideGhostSettingContext = (refs: {
+ isCreating: Ref<boolean>;
+ project: Ref<ComposedProject>;
+ plan: Ref<Plan>;
+ selectedSpec: Ref<Plan_Spec | undefined>;
+ selectedTask?: Ref<Task | undefined>;
+ issue?: Ref<Issue | undefined>;
+ rollout?: Ref<Rollout | undefined>;
+}) => {
+ const currentUser = useCurrentUserV1();
+ const {
+ isCreating,
+ project,
+ plan,
+ selectedSpec,
+ selectedTask,
+ issue,
+ rollout,
+ } = refs;
+
+ const events = new Emittery<{
+ update: never;
+ }>();
+
+ const database = computed(() => {
+ if (selectedTask?.value) {
+ return databaseForTask(project.value, selectedTask.value);
+ } else if (selectedSpec.value) {
+ return databaseForSpec(project.value, selectedSpec.value);
+ }
+ return unknownDatabase();
+ });
+
+ const shouldShow = computed(() => {
+ return (
+ selectedSpec.value &&
+ allowGhostForSpec(selectedSpec.value) &&
+ allowGhostForDatabase(database.value) &&
+ !isNullOrUndefined(getGhostEnabledForSpec(selectedSpec.value))
+ );
+ });
+
+ const allowChange = computed(() => {
+ // Allow toggle pre-backup when creating.
+ if (isCreating.value) {
+ return true;
+ }
+
+ // If issue is not open, disallow.
+ if (issue?.value && issue.value.status !== IssueStatus.OPEN) {
+ return false;
+ }
+
+ let task: Task | undefined;
+ if (selectedTask?.value) {
+ task = selectedTask.value;
+ } else if (rollout?.value) {
+ const tasks = flattenTaskV1List(rollout.value);
+ task = tasks.find((t) => t.specId === selectedSpec.value?.id);
+ }
+ // If task of the spec is running/done/etc..., disallow.
+ if (
+ task &&
+ [
+ Task_Status.PENDING,
+ Task_Status.RUNNING,
+ Task_Status.DONE,
+ Task_Status.SKIPPED,
+ ].includes(task.status)
+ ) {
+ return false;
+ }
+
+ // Allowed to the plan/issue creator.
+ if (currentUser.value.email === extractUserId(unref(plan).creator)) {
+ return true;
+ }
+
+ // Allowed to the permission holder.
+ if (hasProjectPermissionV2(project.value, "bb.plans.update")) {
+ return true;
+ }
+
+ return false;
+ });
+
+ const enabled = computed(() => {
+ return (
+ (selectedSpec.value && getGhostEnabledForSpec(selectedSpec.value)) ||
+ false
+ );
+ });
+
+ const context = {
+ isCreating,
+ selectedSpec,
+ selectedTask,
+ plan,
+ shouldShow,
+ allowChange,
+ enabled,
+ database,
+ events,
+ };
+
+ provide(KEY, context);
+
+ return context;
+};
+
+type GhostSettingContext = ReturnType<typeof provideGhostSettingContext>;
diff --git a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/index.ts b/frontend/src/components/Plan/components/Sidebar/GhostSection/index.ts
similarity index 100%
rename from frontend/src/components/IssueV1/components/Sidebar/GhostSection/index.ts
rename to frontend/src/components/Plan/components/Sidebar/GhostSection/index.ts
diff --git a/frontend/src/components/Plan/components/Sidebar/PreBackupSection/context.ts b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/context.ts
index 406d9cbe75..46cdd52160 100644
--- a/frontend/src/components/Plan/components/Sidebar/PreBackupSection/context.ts
+++ b/frontend/src/components/Plan/components/Sidebar/PreBackupSection/context.ts
@@ -54,7 +54,7 @@ export const providePreBackupSettingContext = (refs: {
project: Ref<ComposedProject>;
plan: Ref<Plan>;
selectedSpec: Ref<Plan_Spec | undefined>;
- selectedTask: Ref<Task | undefined>;
+ selectedTask?: Ref<Task | undefined>;
issue?: Ref<Issue | undefined>;
rollout?: Ref<Rollout | undefined>;
}) => {
@@ -74,7 +74,7 @@ export const providePreBackupSettingContext = (refs: {
}>();
const database = computed(() => {
- if (selectedTask.value) {
+ if (selectedTask?.value) {
return databaseForTask(project.value, selectedTask.value);
} else if (selectedSpec.value) {
return databaseForSpec(project.value, selectedSpec.value);
diff --git a/frontend/src/components/Plan/components/Sidebar/Sidebar.vue b/frontend/src/components/Plan/components/Sidebar/Sidebar.vue
index 0c17cfb0b4..37dab0625c 100644
--- a/frontend/src/components/Plan/components/Sidebar/Sidebar.vue
+++ b/frontend/src/components/Plan/components/Sidebar/Sidebar.vue
@@ -1,6 +1,7 @@
<template>
<div v-if="shouldShow" class="flex flex-col gap-y-3 py-2 px-3">
<p class="textinfolabel -mb-2">{{ $t("common.options") }}</p>
+ <GhostSection v-if="shouldShowGhostSection" />
<PreBackupSection v-if="shouldShowPreBackupSection" />
</div>
</template>
@@ -8,22 +9,31 @@
<script lang="ts" setup>
import { computed } from "vue";
import { usePlanContext } from "../../logic";
+import GhostSection from "./GhostSection";
+import { provideGhostSettingContext } from "./GhostSection/context";
import PreBackupSection from "./PreBackupSection";
import { providePreBackupSettingContext } from "./PreBackupSection/context";
const { isCreating, plan, selectedSpec, events } = usePlanContext();
+const { shouldShow: shouldShowGhostSection, events: ghostEvents } =
+ provideGhostSettingContext({
+ project: computed(() => plan.value.projectEntity),
+ plan: plan,
+ selectedSpec: selectedSpec,
+ isCreating,
+ });
+
const { shouldShow: shouldShowPreBackupSection, events: preBackupEvents } =
providePreBackupSettingContext({
project: computed(() => plan.value.projectEntity),
plan: plan,
selectedSpec: selectedSpec,
- selectedTask: computed(() => undefined),
isCreating,
});
const shouldShow = computed(() => {
- return shouldShowPreBackupSection.value;
+ return shouldShowGhostSection.value || shouldShowPreBackupSection.value;
});
preBackupEvents.on("update", () => {
@@ -31,4 +41,10 @@ preBackupEvents.on("update", () => {
eager: true,
});
});
+
+ghostEvents.on("update", () => {
+ events.emit("status-changed", {
+ eager: true,
+ });
+});
</script>
diff --git a/frontend/src/components/Plan/components/Sidebar/index.ts b/frontend/src/components/Plan/components/Sidebar/index.ts
index 9343c6934b..6e71b5d5d3 100644
--- a/frontend/src/components/Plan/components/Sidebar/index.ts
+++ b/frontend/src/components/Plan/components/Sidebar/index.ts
@@ -1,6 +1,7 @@
import PreBackupSection from "./PreBackupSection";
+import GhostSection from "./GhostSection";
import Sidebar from "./Sidebar.vue";
export default Sidebar;
-export { PreBackupSection };
+export { PreBackupSection, GhostSection };
diff --git a/frontend/src/components/Project/ProjectSwitch/ProjectSwitchPopover.vue b/frontend/src/components/Project/ProjectSwitch/ProjectSwitchPopover.vue
index 1cbd0821d9..4f0b3177f3 100644
--- a/frontend/src/components/Project/ProjectSwitch/ProjectSwitchPopover.vue
+++ b/frontend/src/components/Project/ProjectSwitch/ProjectSwitchPopover.vue
@@ -12,6 +12,7 @@
class="hidden sm:inline"
size="small"
@click="state.showPopover = !state.showPopover"
+ icon-placement="right"
>
<div class="min-w-[8rem] text-left">
<ProjectNameCell
@@ -23,7 +24,9 @@
{{ $t("project.select") }}
</span>
</div>
- <ChevronDownIcon class="w-5 h-auto text-gray-400" />
+ <template #icon>
+ <ChevronDownIcon class="w-5 h-auto opacity-80" />
+ </template>
</NButton>
</template>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index f847869747..9fd167de88 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -278,7 +278,6 @@
"ghost-parameters": "gh-ost parameters",
"configure": "Configure",
"error": {
- "x-status-task-is-not-editable": "{status} task is not editable",
"nothing-changed": "Nothing changed",
"not-applicable": {
"task-doesnt-meet-ghost-requirement": "Task doesn't meet gh-ost's requirement",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 4b12112621..92d3245d8e 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -278,7 +278,6 @@
"ghost-parameters": "parámetros de gh-ost",
"configure": "Configurar",
"error": {
- "x-status-task-is-not-editable": "La tarea {status} no es editable",
"nothing-changed": "nada ha cambiado",
"not-applicable": {
"task-doesnt-meet-ghost-requirement": "La tarea no cumple con el requisito de gh-ost",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 823c6ae2ce..beace98dea 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -278,7 +278,6 @@
"ghost-parameters": "gh-ostパラメータ",
"configure": "設定",
"error": {
- "x-status-task-is-not-editable": "{status} のタスクは編集できません",
"nothing-changed": "変化なし",
"not-applicable": {
"task-doesnt-meet-ghost-requirement": "タスクは gh-ost の要件を満たしていません",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index fb3a97936a..ae283323a1 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -278,7 +278,6 @@
"ghost-parameters": "Tham số gh-ost",
"configure": "Cấu hình",
"error": {
- "x-status-task-is-not-editable": "Tác vụ trạng thái {status} không thể chỉnh sửa",
"nothing-changed": "Không có gì thay đổi",
"not-applicable": {
"task-doesnt-meet-ghost-requirement": "Nhiệm vụ không đáp ứng được yêu cầu của gh-ost",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 32050b2eb8..9541e2ea02 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -278,7 +278,6 @@
"ghost-parameters": "gh-ost 参数",
"configure": "配置",
"error": {
- "x-status-task-is-not-editable": "{status} 的任务不可编辑",
"nothing-changed": "无任何改变",
"not-applicable": {
"task-doesnt-meet-ghost-requirement": "任务不符合 gh-ost 的要求",