Skip to content

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

chore: update markdown editor (#6892)

ecmadaob3ea0a285765
diff --git a/frontend/src/components/Issue/IssueActivityPanel.vue b/frontend/src/components/Issue/IssueActivityPanel.vue
index e753b204d4..094ddcc957 100644
--- a/frontend/src/components/Issue/IssueActivityPanel.vue
+++ b/frontend/src/components/Issue/IssueActivityPanel.vue
@@ -37,31 +37,8 @@
</template>
<template #comment>
- <template v-if="actuatorStore.version !== 'development'">
- <div
- v-if="
- state.editCommentMode &&
- state.activeActivity?.name === item.activity.name
- "
- class="mt-2 text-sm text-control whitespace-pre-wrap"
- >
- <label for="comment" class="sr-only">
- {{ $t("issue.edit-comment") }}
- </label>
- <textarea
- ref="editCommentTextArea"
- v-model="state.editComment"
- rows="3"
- class="textarea block w-full resize-none"
- :placeholder="$t('issue.leave-a-comment')"
- @input="(e: any) => sizeToFit(e.target)"
- @focus="(e: any) => sizeToFit(e.target)"
- />
- </div>
- <ActivityComment v-else :activity="item.activity" />
- </template>
<MarkdownEditor
- v-else-if="item.activity.comment"
+ v-if="item.activity.comment"
:mode="
state.editCommentMode &&
state.activeActivity?.name === item.activity.name
@@ -120,21 +97,11 @@
{{ $t("issue.add-a-comment") }}
</label>
<MarkdownEditor
- v-if="actuatorStore.version === 'development'"
mode="editor"
:content="state.newComment"
@change="(val: string) => state.newComment = val"
@submit="doCreateComment(state.newComment)"
/>
- <textarea
- v-else
- ref="newCommentTextArea"
- v-model="state.newComment"
- rows="3"
- class="textarea block w-full resize-none whitespace-pre-wrap"
- :placeholder="$t('issue.leave-a-comment')"
- @input="(e: any) => sizeToFit(e.target)"
- ></textarea>
<div class="mt-4 flex items-center justify-between space-x-4">
<div>
<button
@@ -156,16 +123,7 @@
</template>
<script lang="ts" setup>
-import {
- computed,
- nextTick,
- ref,
- reactive,
- watch,
- watchEffect,
- Ref,
- onMounted,
-} from "vue";
+import { computed, reactive, watch, watchEffect, Ref, onMounted } from "vue";
import { useRoute } from "vue-router";
import UserAvatar from "../User/UserAvatar.vue";
import type {
@@ -174,7 +132,7 @@ import type {
IssueSubscriber,
ActivityIssueCommentCreatePayload,
} from "@/types";
-import { extractUserResourceName, sizeToFit } from "@/utils";
+import { extractUserResourceName } from "@/utils";
import { IssueBuiltinFieldId } from "@/plugins";
import {
useIssueSubscriberStore,
@@ -182,16 +140,9 @@ import {
useActivityV1Store,
useCurrentUserV1,
useCurrentUser,
- useActuatorV1Store,
} from "@/store";
-import { useEventListener } from "@vueuse/core";
import { useExtraIssueLogic, useIssueLogic } from "./logic";
-import {
- ActivityItem,
- DistinctActivity,
- Comment as ActivityComment,
- isSimilarActivity,
-} from "./activity";
+import { ActivityItem, DistinctActivity, isSimilarActivity } from "./activity";
import { LogEntity, LogEntity_Action } from "@/types/proto/v1/logging_service";
import { getLogId } from "@/store/modules/v1/common";
@@ -204,12 +155,8 @@ interface LocalState {
const reviewV1Store = useReviewV1Store();
const activityV1Store = useActivityV1Store();
-const actuatorStore = useActuatorV1Store();
const route = useRoute();
-const newCommentTextArea = ref();
-const editCommentTextArea = ref<HTMLTextAreaElement[]>();
-
const logic = useIssueLogic();
const issue = logic.issue as Ref<Issue>;
const { addSubscriberId } = useExtraIssueLogic();
@@ -220,27 +167,6 @@ const state = reactive<LocalState>({
newComment: "",
});
-const keyboardHandler = (e: KeyboardEvent) => {
- if (
- state.editCommentMode &&
- editCommentTextArea.value?.[0] === document.activeElement
- ) {
- if (e.code == "Escape") {
- cancelEditComment();
- } else if (e.code == "Enter" && e.metaKey) {
- if (allowUpdateComment.value) {
- doUpdateComment();
- }
- }
- } else if (newCommentTextArea.value === document.activeElement) {
- if (e.code == "Enter" && e.metaKey) {
- doCreateComment(state.newComment);
- }
- }
-};
-
-useEventListener("keydown", keyboardHandler);
-
const currentUser = useCurrentUser();
const currentUserV1 = useCurrentUserV1();
@@ -305,7 +231,6 @@ const doCreateComment = (comment: string) => {
})
.then(() => {
state.newComment = "";
- nextTick(() => sizeToFit(newCommentTextArea.value));
// Because the user just added a comment and we assume she is interested in this
// issue, and we add her to the subscriber list if she is not there
@@ -342,9 +267,6 @@ const onUpdateComment = (activity: LogEntity) => {
state.activeActivity = activity;
state.editCommentMode = true;
state.editComment = activity.comment;
- nextTick(() => {
- editCommentTextArea.value?.[0]?.focus();
- });
};
const doUpdateComment = () => {
diff --git a/frontend/src/components/Issue/activity/ActivityAction.vue b/frontend/src/components/Issue/activity/ActivityAction.vue
index 05b91f9e73..0914c85b3a 100644
--- a/frontend/src/components/Issue/activity/ActivityAction.vue
+++ b/frontend/src/components/Issue/activity/ActivityAction.vue
@@ -45,9 +45,7 @@
<slot name="subject-suffix"></slot>
</div>
<div class="mt-2 text-sm text-control whitespace-pre-wrap">
- <slot name="comment">
- <Comment :activity="activity" />
- </slot>
+ <slot name="comment" />
<template
v-if="
@@ -73,7 +71,6 @@ import {
ActivityTaskFileCommitPayload,
SYSTEM_BOT_EMAIL,
} from "@/types";
-import Comment from "./Comment";
import ActionCreator from "./ActionCreator.vue";
import ActionSentence from "./ActionSentence.vue";
import { LogEntity, LogEntity_Action } from "@/types/proto/v1/logging_service";
diff --git a/frontend/src/components/Issue/activity/Comment.ts b/frontend/src/components/Issue/activity/Comment.ts
deleted file mode 100644
index 7654e2f110..0000000000
--- a/frontend/src/components/Issue/activity/Comment.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import { h, defineComponent, PropType } from "vue";
-import { LogEntity } from "@/types/proto/v1/logging_service";
-
-// Render activity comments and render "#{issue_id}" patterns as issue links.
-export default defineComponent({
- name: "ActivityComment",
- props: {
- activity: {
- type: Object as PropType<LogEntity>,
- required: true,
- },
- },
- render() {
- const { comment } = this.$props.activity;
- if (!comment) return null;
-
- const pattern = /(#\d+)\b/;
- const parts = comment.split(pattern);
-
- return parts.map((part) => {
- if (part === "") return null;
-
- if (part.startsWith("#")) {
- const id = parseInt(part.slice(1), 10);
- if (!Number.isNaN(id) && id > 0) {
- // we met a valid #{issue_id} in which issue_id is an integer and >= 0
- // render a link to the issue
- return h(
- "a",
- {
- href: `/issue/${id}`,
- class: "font-medium text-main whitespace-nowrap hover:underline",
- },
- part
- );
- }
- }
-
- return h("span", {}, part);
- });
- },
-});
diff --git a/frontend/src/components/Issue/activity/index.ts b/frontend/src/components/Issue/activity/index.ts
index d57ea34140..7b5f21c5ed 100644
--- a/frontend/src/components/Issue/activity/index.ts
+++ b/frontend/src/components/Issue/activity/index.ts
@@ -1,5 +1,4 @@
import ActivityItem from "./ActivityItem.vue";
-import Comment from "./Comment";
export * from "./common";
-export { ActivityItem, Comment };
+export { ActivityItem };
diff --git a/frontend/src/components/MarkdownEditor.vue b/frontend/src/components/MarkdownEditor.vue
index acd87b1aa7..184bcb4aa3 100644
--- a/frontend/src/components/MarkdownEditor.vue
+++ b/frontend/src/components/MarkdownEditor.vue
@@ -24,21 +24,32 @@
class="flex-1 flex items-center justify-end"
>
<div v-for="(toolbar, i) in toolbarItems" :key="i">
- <button class="hover:bg-gray-100 p-2" @click="toolbar.action">
- <template v-if="toolbar.text">
- <span class="font-bold">{{ toolbar.text }}</span>
+ <NTooltip :show-arrow="true">
+ <template #trigger>
+ <button class="hover:bg-gray-100 p-2" @click="toolbar.action">
+ <template v-if="toolbar.text">
+ <span class="font-bold">{{ toolbar.text }}</span>
+ </template>
+ <template v-else-if="toolbar.icon">
+ <heroicons-outline:code
+ v-if="toolbar.icon === 'code'"
+ class="w-4 h-4"
+ />
+ <heroicons-outline:link
+ v-else-if="toolbar.icon === 'link'"
+ class="w-4 h-4"
+ />
+ <heroicons-outline:hashtag
+ v-else-if="toolbar.icon === 'hashtag'"
+ class="w-4 h-4"
+ />
+ </template>
+ </button>
</template>
- <template v-else-if="toolbar.icon">
- <heroicons-outline:code
- v-if="toolbar.icon === 'code'"
- class="w-4 h-4"
- />
- <heroicons-outline:link
- v-else-if="toolbar.icon === 'link'"
- class="w-4 h-4"
- />
- </template>
- </button>
+ <span class="w-56 text-sm">
+ {{ toolbar.tooltip }}
+ </span>
+ </NTooltip>
</div>
</div>
</div>
@@ -77,7 +88,6 @@ import MarkdownIt from "markdown-it";
import { sizeToFit } from "@/utils";
import codeStyle from "highlight.js/styles/github.css";
import markdownStyle from "../assets/css/github-markdown-style.css";
-import "../assets/css/tailwind.css";
const md = new MarkdownIt({
html: true,
@@ -103,6 +113,7 @@ interface LocalState {
interface Toolbar {
icon?: string;
text?: string;
+ tooltip: string;
action: () => void;
}
@@ -131,7 +142,26 @@ watch(
const markdownPlaceholder = t("issue.comment-editor.nothing-to-preview");
const markdownContent = computed(() => {
- return DOMPurify.sanitize(md.render(state.content || markdownPlaceholder));
+ if (!state.content) {
+ return `<span>${markdownPlaceholder}</span>`;
+ }
+
+ // we met a valid #{issue_id} in which issue_id is an integer and >= 0
+ // render a link to the issue
+ const format = state.content
+ .split(/(#\d+)\b/)
+ .map((part) => {
+ if (!part.startsWith("#")) {
+ return part;
+ }
+ const id = parseInt(part.slice(1), 10);
+ if (!Number.isNaN(id) && id > 0) {
+ return `[issue #${id}](${window.location.origin}/issue/${id})`;
+ }
+ return part;
+ })
+ .join("");
+ return DOMPurify.sanitize(md.render(format));
});
const contentTextArea = ref<HTMLTextAreaElement>();
const contentPreviewArea = ref<HTMLIFrameElement>();
@@ -175,6 +205,12 @@ const adjustIframe = () => {
cssLink.append(codeStyle, markdownStyle);
contentPreviewArea.value.contentDocument.head.append(cssLink);
contentPreviewArea.value.contentDocument.body.className = "markdown-body";
+
+ const links =
+ contentPreviewArea.value.contentDocument.querySelectorAll("a");
+ for (let i = 0; i < links.length; i++) {
+ links[i].setAttribute("target", "_blank");
+ }
}
nextTick(() => {
@@ -309,26 +345,37 @@ const getCursorPosition = (lines: string[]): number => {
const toolbarItems: Toolbar[] = [
{
text: "H",
+ tooltip: t("issue.comment-editor.toolbar.header"),
action: () => {
insertWithCursorPosition("### ", 4);
},
},
{
text: "B",
+ tooltip: t("issue.comment-editor.toolbar.bold"),
action: () => {
insertWithCursorPosition("****", 2);
},
},
{
icon: "code",
+ tooltip: t("issue.comment-editor.toolbar.code"),
action: () => {
insertWithCursorPosition("\n```sql\n\n```\n", 8);
},
},
{
icon: "link",
+ tooltip: t("issue.comment-editor.toolbar.link"),
+ action: () => {
+ insertWithCursorPosition("[](url)", 1);
+ },
+ },
+ {
+ icon: "hashtag",
+ tooltip: t("issue.comment-editor.toolbar.hashtag"),
action: () => {
- insertWithCursorPosition("[](herf)", 1);
+ insertWithCursorPosition("#", 1);
},
},
];
@@ -337,7 +384,7 @@ const toolbarItems: Toolbar[] = [
// Support templates:
// \n```\nsql{text}\n```\n
// **{text}**
-// [{text}](herf)
+// [{text}](url)
// ### {text}
const insertWithCursorPosition = (template: string, position: number) => {
if (!contentTextArea.value) {
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 6ad9f7d233..6877c49853 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -698,7 +698,14 @@
"comment-editor": {
"editor": "Editor",
"preview": "Preview",
- "nothing-to-preview": "Nothing to preview"
+ "nothing-to-preview": "Nothing to preview",
+ "toolbar": {
+ "header": "Insert heading text",
+ "bold": "Insert bold text",
+ "code": "Insert SQL code snippet",
+ "link": "Insert a link",
+ "hashtag": "Insert issue's link by id. Type the issue id after the hashtag \"#\""
+ }
},
"view-commit": "View commit",
"search-issue-name": "Search issue name",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 41fc6a2433..873881a336 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -698,7 +698,14 @@
"comment-editor": {
"editor": "Editor",
"preview": "Vista previa",
- "nothing-to-preview": "Nada para previsualizar"
+ "nothing-to-preview": "Nada para previsualizar",
+ "toolbar": {
+ "header": "Insertar texto de encabezado",
+ "bold": "Insertar texto en negrita",
+ "code": "Insertar fragmento de código SQL",
+ "link": "Insertar un enlace",
+ "hashtag": "Inserte el enlace del problema por id. Escriba la identificación del problema después del hashtag \"#\""
+ }
},
"view-commit": "Ver commit",
"search-issue-name": "Buscar nombre de la incidencia",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 37cafae374..12a4cc946e 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -695,7 +695,14 @@
"comment-editor": {
"editor": "编辑",
"preview": "预览",
- "nothing-to-preview": "暂无预览"
+ "nothing-to-preview": "暂无预览",
+ "toolbar": {
+ "header": "插入标题",
+ "bold": "插入粗体文本",
+ "code": "插入 SQL 代码片段",
+ "link": "插入链接",
+ "hashtag": "通过 id 插入工单链接。请在\"#\"后填入工单 id"
+ }
},
"view-commit": "查看提交",
"search-issue-name": "搜索工单名称",