Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: improve plan detail page description UX (#17295)
Danny Xubcc0eb30d916
diff --git a/frontend/src/components/Plan/components/IssueReviewView/DescriptionSection/DescriptionSection.vue b/frontend/src/components/Plan/components/IssueReviewView/DescriptionSection/DescriptionSection.vueindex 7a53eaeccb..ceed4e1d04 100644--- a/frontend/src/components/Plan/components/IssueReviewView/DescriptionSection/DescriptionSection.vue+++ b/frontend/src/components/Plan/components/IssueReviewView/DescriptionSection/DescriptionSection.vue@@ -1,46 +1,74 @@<template>- <div class="space-y-2">- <div class="flex items-center justify-between gap-2">- <h3 class="text-base font-medium">- {{ $t("common.description") }}- </h3>- <NButton- v-if="!isEditing && allowEdit"- size="small"- @click="startEditing"+ <div ref="descriptionRef" class="flex-1">+ <div v-if="!state.isExpanded" class="py-1">+ <button+ v-if="!state.description && allowEdit"+ class="flex items-center gap-1 text-sm italic text-gray-400 hover:text-gray-600 hover:bg-gray-50 px-2 py-0.5 -ml-2 rounded"+ @click="handleExpand($event)">- {{ $t("common.edit") }}- </NButton>- <div v-if="isEditing" class="flex items-center gap-2">- <NButton size="small" @click="saveChanges">- {{ $t("common.save") }}- </NButton>- <NButton size="small" quaternary @click="cancelEditing">- {{ $t("common.cancel") }}- </NButton>+ <svg+ class="w-4 h-4"+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M12 4v16m8-8H4"+ />+ </svg>+ {{ $t("plan.description.placeholder") }}+ </button>+ <div+ v-else+ class="cursor-pointer hover:bg-gray-50 px-3 py-2 -ml-3 rounded border border-transparent hover:border-gray-200 transition-colors"+ @click="handleExpand($event)"+ >+ <MarkdownEditor+ :content="state.description"+ mode="preview"+ :project="project"+ :issue-list="[]"+ class="pointer-events-none"+ /></div></div>- <div v-if="!isEditing">- <MarkdownEditor- v-if="plan.description"- :content="plan.description"- mode="preview"- :project="project"- :issue-list="[]"- />- <div v-else class="text-control-placeholder text-sm italic">- {{ $t("issue.add-some-description") }}+ <div v-else class="py-2">+ <div class="flex items-center justify-between mb-3">+ <span class="text-base font-medium">{{+ $t("common.description")+ }}</span>+ <button+ class="inline-flex items-center gap-1 px-3 py-1 text-sm font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 border border-gray-300 rounded-md"+ :disabled="state.isUpdating"+ @click="handleCollapse"+ >+ <svg+ class="w-4 h-4"+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M5 15l7-7 7 7"+ />+ </svg>+ {{ $t("common.collapse") }}+ </button></div>- </div>- <div v-else><MarkdownEditor- :content="editingDescription"+ :content="state.description"mode="editor"- autofocus+ :autofocus="state.shouldAutoFocus":project="project"- :placeholder="$t('issue.add-some-description')"+ :placeholder="$t('plan.description.placeholder')":issue-list="[]"- @change="onDescriptionChange"+ @change="onUpdateValue"/></div></div>@@ -48,33 +76,37 @@<script setup lang="ts">import { create } from "@bufbuild/protobuf";-import { NButton } from "naive-ui";-import { computed, ref } from "vue";+import { computed, reactive, watch, onMounted, onUnmounted, ref } from "vue";import { useI18n } from "vue-i18n";import MarkdownEditor from "@/components/MarkdownEditor";import { useResourcePoller } from "@/components/Plan/logic/poller";import { planServiceClientConnect } from "@/grpcweb";import {- extractUserId,pushNotification,- useCurrentProjectV1,useCurrentUserV1,+ extractUserId,+ useCurrentProjectV1,} from "@/store";-import {- PlanSchema,- UpdatePlanRequestSchema,-} from "@/types/proto-es/v1/plan_service_pb";+import { UpdatePlanRequestSchema } from "@/types/proto-es/v1/plan_service_pb";+import { PlanSchema } from "@/types/proto-es/v1/plan_service_pb";import { hasProjectPermissionV2 } from "@/utils";import { usePlanContext } from "../../..";const { t } = useI18n();const currentUser = useCurrentUserV1();const { project } = useCurrentProjectV1();-const { plan, readonly, isCreating } = usePlanContext();+const { isCreating, plan, readonly } = usePlanContext();const { refreshResources } = useResourcePoller();-const isEditing = ref(false);-const editingDescription = ref("");+const descriptionRef = ref<HTMLDivElement>();++const state = reactive({+ isUpdating: false,+ description: plan.value.description,+ isExpanded: false,+ shouldAutoFocus: false,+ justExpanded: false,+});const allowEdit = computed(() => {if (readonly.value) {@@ -83,52 +115,108 @@ const allowEdit = computed(() => {if (isCreating.value) {return true;}- // Allowed if current user is the creator.if (extractUserId(plan.value.creator) === currentUser.value.email) {return true;}- // Allowed if current user has related permission.if (hasProjectPermissionV2(project.value, "bb.plans.update")) {return true;}return false;});-const startEditing = () => {- editingDescription.value = plan.value.description;- isEditing.value = true;+const handleExpand = (event: MouseEvent) => {+ if (!allowEdit.value) return;+ event.stopPropagation();+ state.shouldAutoFocus = true;+ state.isExpanded = true;+ state.justExpanded = true;+ // Add a small delay before allowing click outside to work+ setTimeout(() => {+ state.shouldAutoFocus = false;+ state.justExpanded = false;+ }, 100);};-const cancelEditing = () => {- isEditing.value = false;- editingDescription.value = "";+const handleCollapse = () => {+ state.isExpanded = false;};-const onDescriptionChange = (value: string) => {- editingDescription.value = value;-};+const handleClickOutside = (event: MouseEvent) => {+ if (!state.isExpanded) return;+ if (state.justExpanded) return; // Prevent immediate collapse after expanding+ if (!descriptionRef.value) return;-const saveChanges = async () => {- // Only update if description actually changed- if (editingDescription.value === plan.value.description) {- isEditing.value = false;- return;+ const target = event.target as Node;+ if (!descriptionRef.value.contains(target)) {+ state.isExpanded = false;}+};++onMounted(() => {+ document.addEventListener("click", handleClickOutside);+});- const request = create(UpdatePlanRequestSchema, {- plan: create(PlanSchema, {- name: plan.value.name,- description: editingDescription.value,- }),- updateMask: { paths: ["description"] },- });- await planServiceClientConnect.updatePlan(request);- refreshResources(["plan"], true /** force */);- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("common.updated"),- });- isEditing.value = false;+onUnmounted(() => {+ document.removeEventListener("click", handleClickOutside);+});++const onUpdateValue = (value: string) => {+ state.description = value;+ if (isCreating.value) {+ plan.value.description = value;+ }};++let debounceTimer: NodeJS.Timeout | null = null;++watch(+ () => state.description,+ (newValue) => {+ if (isCreating.value || !allowEdit.value) {+ return;+ }++ if (newValue === plan.value.description) {+ return;+ }++ if (debounceTimer) {+ clearTimeout(debounceTimer);+ }++ debounceTimer = setTimeout(async () => {+ try {+ state.isUpdating = true;+ const planPatch = create(PlanSchema, {+ ...plan.value,+ description: state.description,+ });+ const request = create(UpdatePlanRequestSchema, {+ plan: planPatch,+ updateMask: { paths: ["description"] },+ });+ const response = await planServiceClientConnect.updatePlan(request);+ Object.assign(plan.value, response);+ refreshResources(["plan"], true /** force */);+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.updated"),+ });+ } finally {+ state.isUpdating = false;+ }+ }, 1000);+ }+);++watch(+ () => plan.value.description,+ (newValue) => {+ if (state.description !== newValue) {+ state.description = newValue;+ }+ },+ { immediate: true }+);</script>diff --git a/frontend/src/components/Plan/components/IssueReviewView/IssueReviewView.vue b/frontend/src/components/Plan/components/IssueReviewView/IssueReviewView.vueindex fca23b75b7..956f5c4bb0 100644--- a/frontend/src/components/Plan/components/IssueReviewView/IssueReviewView.vue+++ b/frontend/src/components/Plan/components/IssueReviewView/IssueReviewView.vue@@ -2,10 +2,10 @@<div class="flex-1 flex w-full"><!-- Left Panel - Activity --><div class="flex-1 shrink px-4 py-4 space-y-4">- <OverviewSection v-if="shouldShowOverview" />-<DescriptionSection />+ <OverviewSection v-if="shouldShowOverview" />+<ActivitySection /></div>