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: add markdown editor to plan description section (#17267)
boojack4b548f8cdc27
diff --git a/frontend/src/components/MarkdownEditor/MarkdownEditor.vue b/frontend/src/components/MarkdownEditor/MarkdownEditor.vueindex db12f6f6bb..f6a60df982 100644--- a/frontend/src/components/MarkdownEditor/MarkdownEditor.vue+++ b/frontend/src/components/MarkdownEditor/MarkdownEditor.vue@@ -6,7 +6,7 @@><div:class="[- 'px-3 py-2 cursor-pointer font-medium transition-colors',+ 'px-3 py-2 cursor-pointer transition-colors',state.showPreview? 'text-gray-500 hover:text-gray-700': 'text-gray-900 border-b-2 border-gray-900',@@ -17,7 +17,7 @@</div><div:class="[- 'px-3 py-2 cursor-pointer font-medium transition-colors',+ 'px-3 py-2 cursor-pointer transition-colors',state.showPreview? 'text-gray-900 border-b-2 border-gray-900': 'text-gray-500 hover:text-gray-700',diff --git a/frontend/src/components/Plan/components/DescriptionSection.vue b/frontend/src/components/Plan/components/DescriptionSection.vuedeleted file mode 100644index 817e1a16d0..0000000000--- a/frontend/src/components/Plan/components/DescriptionSection.vue+++ /dev/null@@ -1,187 +0,0 @@-<template>- <div class="">- <div class="flex items-center justify-between mb-3">- <h2 class="text-lg font-semibold">{{ $t("common.description") }}</h2>-- <div v-if="!isCreating && allowEdit" class="flex items-center gap-x-2">- <NButton- v-if="!state.isEditing"- size="small"- @click.prevent="beginEdit"- >- {{ $t("common.edit") }}- </NButton>- <NButton- v-if="state.isEditing"- size="small"- :disabled="state.description === plan.description"- :loading="state.isUpdating"- @click.prevent="saveEdit"- >- {{ $t("common.save") }}- </NButton>- <NButton- v-if="state.isEditing"- size="small"- quaternary- @click.prevent="cancelEdit"- >- {{ $t("common.cancel") }}- </NButton>- </div>- </div>-- <NInput- v-if="isCreating || state.isEditing"- ref="inputRef"- v-model:value="state.description"- :placeholder="$t('issue.add-some-description')"- :autosize="{ minRows: 3, maxRows: 10 }"- :disabled="state.isUpdating"- :loading="state.isUpdating"- style="- width: 100%;- --n-placeholder-color: rgb(var(--color-control-placeholder));- "- type="textarea"- @update:value="onDescriptionChange"- />- <div- v-else- class="min-h-[6rem] max-h-[12rem] whitespace-pre-wrap px-[10px] py-[4.5px] border rounded-md"- >- <template v-if="plan.description">- <iframe- v-if="plan.description"- ref="contentPreviewArea"- :srcdoc="renderedContent"- class="w-full overflow-hidden"- />- </template>- <span v-else class="text-control-placeholder">- {{ $t("issue.add-some-description") }}- </span>- </div>- </div>-</template>--<script lang="ts" setup>-import { create } from "@bufbuild/protobuf";-import { NInput, NButton } from "naive-ui";-import { computed, nextTick, reactive, ref, watch } from "vue";-import { useI18n } from "vue-i18n";-import { useRenderMarkdown } from "@/components/MarkdownEditor";-import { planServiceClientConnect } from "@/grpcweb";-import {- pushNotification,- useCurrentUserV1,- extractUserId,- useCurrentProjectV1,-} from "@/store";-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 "../logic";--type LocalState = {- isEditing: boolean;- isUpdating: boolean;- description: string;-};--const { t } = useI18n();-const { project } = useCurrentProjectV1();-const { isCreating, plan } = usePlanContext();-const currentUser = useCurrentUserV1();-const contentPreviewArea = ref<HTMLIFrameElement>();--const state = reactive<LocalState>({- isEditing: false,- isUpdating: false,- description: plan.value.description,-});--const inputRef = ref<InstanceType<typeof NInput>>();--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 onDescriptionChange = (value: string) => {- if (!isCreating.value) {- return;- }-- plan.value.description = value;-};--const beginEdit = () => {- state.description = plan.value.description;- state.isEditing = true;- nextTick(() => {- inputRef.value?.focus();- });-};--const saveEdit = 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);- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("common.updated"),- });- state.isEditing = false;- } finally {- state.isUpdating = false;- }-};--const cancelEdit = () => {- state.description = plan.value.description;- state.isEditing = false;-};--const { renderedContent } = useRenderMarkdown(- computed(() => plan.value.description),- contentPreviewArea,- project-);--// Reset the edit state after creating the plan.-watch(isCreating, (curr, prev) => {- if (!curr && prev) {- state.isEditing = false;- }-});--watch(- () => plan.value,- (plan) => {- if (state.isEditing) return;- state.description = plan.description;- },- { immediate: true }-);-</script>diff --git a/frontend/src/components/Plan/components/IssueReviewView/DescriptionSection/DescriptionSection.vue b/frontend/src/components/Plan/components/IssueReviewView/DescriptionSection/DescriptionSection.vueindex b1b0e484b0..0d6e06ffa6 100644--- a/frontend/src/components/Plan/components/IssueReviewView/DescriptionSection/DescriptionSection.vue+++ b/frontend/src/components/Plan/components/IssueReviewView/DescriptionSection/DescriptionSection.vue@@ -4,24 +4,57 @@<h3 class="text-base font-medium">{{ $t("common.description") }}</h3>+ <NButton+ v-if="!isEditing && allowEdit"+ size="small"+ @click="startEditing"+ >+ <template #icon>+ <EditIcon class="w-4 h-4" />+ </template>+ {{ $t("common.edit") }}+ </NButton>+ <div v-if="isEditing" class="flex items-center gap-2">+ <NButton size="small" @click="cancelEditing">+ {{ $t("common.cancel") }}+ </NButton>+ <NButton size="small" type="primary" @click="saveChanges">+ {{ $t("common.save") }}+ </NButton>+ </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>+ </div>+ <div v-else>+ <MarkdownEditor+ :content="editingDescription"+ mode="editor"+ :project="project"+ :placeholder="$t('issue.add-some-description')"+ :issue-list="[]"+ @change="onDescriptionChange"+ /></div>- <NInput- v-model:value="state.description"- type="textarea"- :placeholder="$t('issue.add-some-description')"- :disabled="!allowEdit"- :autosize="false"- :resizable="false"- @blur="onPlanDescriptionUpdate"- /></div></template><script setup lang="ts">import { create } from "@bufbuild/protobuf";-import { NInput } from "naive-ui";-import { computed, reactive, watch } from "vue";+import { EditIcon } from "lucide-vue-next";+import { NButton } from "naive-ui";+import { computed, 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 {@@ -43,18 +76,8 @@ const { project } = useCurrentProjectV1();const { plan, readonly, isCreating } = usePlanContext();const { refreshResources } = useResourcePoller();-const state = reactive({- description: plan.value.description,-});--// Watch for changes in plan to update the description-watch(- () => [plan.value],- () => {- state.description = plan.value.description;- },- { immediate: true }-);+const isEditing = ref(false);+const editingDescription = ref("");const allowEdit = computed(() => {if (readonly.value) {@@ -74,16 +97,31 @@ const allowEdit = computed(() => {return false;});-const onPlanDescriptionUpdate = async () => {+const startEditing = () => {+ editingDescription.value = plan.value.description;+ isEditing.value = true;+};++const cancelEditing = () => {+ isEditing.value = false;+ editingDescription.value = "";+};++const onDescriptionChange = (value: string) => {+ editingDescription.value = value;+};++const saveChanges = async () => {// Only update if description actually changed- if (state.description === plan.value.description) {+ if (editingDescription.value === plan.value.description) {+ isEditing.value = false;return;}const request = create(UpdatePlanRequestSchema, {plan: create(PlanSchema, {name: plan.value.name,- description: state.description,+ description: editingDescription.value,}),updateMask: { paths: ["description"] },});@@ -94,5 +132,6 @@ const onPlanDescriptionUpdate = async () => {style: "SUCCESS",title: t("common.updated"),});+ isEditing.value = false;};</script>