Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor(frontend): IssueDetail part.4 (#1284)
Liu Ji75474b8f379b
diff --git a/frontend/src/components/Issue/IssueActivityPanel.vue b/frontend/src/components/Issue/IssueActivityPanel.vueindex ea8cfa4316..eb7418d827 100644--- a/frontend/src/components/Issue/IssueActivityPanel.vue+++ b/frontend/src/components/Issue/IssueActivityPanel.vue@@ -156,7 +156,7 @@<templatev-if="state.editCommentMode &&- state.activeActivity.id == activity.id+ state.activeActivity?.id === activity.id"><button@@ -204,7 +204,7 @@<templatev-if="state.editCommentMode &&- state.activeActivity.id == activity.id+ state.activeActivity?.id === activity.id"><label for="comment" class="sr-only">@@ -217,12 +217,12 @@class="textarea block w-full resize-none":placeholder="$t('issue.leave-a-comment')"@input="- (e) => {+ (e: any) => {sizeToFit(e.target);}"@focus="- (e) => {+ (e: any) => {sizeToFit(e.target);}"@@ -235,7 +235,7 @@v-if="activity.type == 'bb.pipeline.task.file.commit'"><a- :href="`${activity.payload.vcsInstanceUrl}/${activity.payload.repositoryFullPath}/-/commit/${activity.payload.commitId}`"+ :href="fileCommitActivityUrl(activity)"target="__blank"class="normal-link flex flex-row items-center">@@ -276,7 +276,7 @@class="textarea block w-full resize-none whitespace-pre-wrap":placeholder="$t('issue.leave-a-comment')"@input="- (e) => {+ (e: any) => {sizeToFit(e.target);}"@@ -305,9 +305,9 @@:description="'You cannot undo this action.'"@ok="() => {- doDeleteComment(state.activeActivity);+ doDeleteComment(state.activeActivity!);state.showDeleteCommentModal = false;- state.activeActivity = null;+ state.activeActivity = undefined;}"@cancel="state.showDeleteCommentModal = false"@@ -315,42 +315,30 @@</BBAlert></template>-<script lang="ts">-import {- onMounted,- onUnmounted,- computed,- nextTick,- ref,- reactive,- watchEffect,- PropType,- defineComponent,-} from "vue";+<script lang="ts" setup>+import { computed, nextTick, ref, reactive, watchEffect, Ref } from "vue";import { useRouter } from "vue-router";import PrincipalAvatar from "../PrincipalAvatar.vue";-import {+import type {Issue,Activity,ActivityIssueFieldUpdatePayload,ActivityTaskStatusUpdatePayload,ActivityTaskStatementUpdatePayload,ActivityTaskEarliestAllowedTimeUpdatePayload,- UNKNOWN_ID,- EMPTY_ID,- SYSTEM_BOT_ID,ActivityCreate,IssueSubscriber,ActivityTaskFileCommitPayload,-} from "../../types";+} from "@/types";+import { UNKNOWN_ID, EMPTY_ID, SYSTEM_BOT_ID } from "@/types";import {findTaskById,issueActivityActionSentence,issueSlug,sizeToFit,taskSlug,-} from "../../utils";-import { IssueTemplate, IssueBuiltinFieldId } from "../../plugins";+} from "@/utils";+import { IssueBuiltinFieldId } from "@/plugins";import { useI18n } from "vue-i18n";import dayjs from "dayjs";import {@@ -359,6 +347,8 @@ import {useIssueSubscriberStore,useActivityStore,} from "@/store";+import { useEventListener } from "@vueuse/core";+import { useExtraIssueLogic, useIssueLogic } from "./logic";interface LocalState {showDeleteCommentModal: boolean;@@ -383,330 +373,292 @@ type ActionIconType =| "complete"| "commit";-export default defineComponent({- name: "IssueActivityPanel",- components: { PrincipalAvatar },- props: {- issue: {- required: true,- type: Object as PropType<Issue>,- },- issueTemplate: {- required: true,- type: Object as PropType<IssueTemplate>,- },- },- emits: ["add-subscriber-id"],- setup(props, { emit }) {- const { t } = useI18n();- const activityStore = useActivityStore();- const router = useRouter();+const { t } = useI18n();+const activityStore = useActivityStore();+const router = useRouter();- const newComment = ref("");- const newCommentTextArea = ref();- const editComment = ref("");- const editCommentTextArea = ref();+const newComment = ref("");+const newCommentTextArea = ref();+const editComment = ref("");+const editCommentTextArea = ref();- const state = reactive<LocalState>({- showDeleteCommentModal: false,- editCommentMode: false,- });+const logic = useIssueLogic();+const issue = logic.issue as Ref<Issue>;+const { addSubscriberId } = useExtraIssueLogic();- const keyboardHandler = (e: KeyboardEvent) => {- if (- state.editCommentMode &&- editCommentTextArea.value === 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();- }- }- };+const state = reactive<LocalState>({+ showDeleteCommentModal: false,+ editCommentMode: false,+});- onMounted(() => {- document.addEventListener("keydown", keyboardHandler);- });+const keyboardHandler = (e: KeyboardEvent) => {+ if (+ state.editCommentMode &&+ editCommentTextArea.value === 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();+ }+ }+};- onUnmounted(() => {- document.removeEventListener("keydown", keyboardHandler);- });+useEventListener("keydown", keyboardHandler);- const currentUser = useCurrentUser();+const currentUser = useCurrentUser();- const prepareActivityList = () => {- activityStore.fetchActivityListForIssue(props.issue.id);- };+const prepareActivityList = () => {+ activityStore.fetchActivityListForIssue(issue.value.id);+};- watchEffect(prepareActivityList);+watchEffect(prepareActivityList);- // The activity list and its anchor is not immediately available when the issue shows up.- // Thus the scrollBehavior set in the vue router won't work (also tried promise to resolve async with no luck either)- // So we manually use scrollIntoView after rendering the activity list.- nextTick(() => {- if (router.currentRoute.value.hash) {- const el = document.getElementById(- router.currentRoute.value.hash.slice(1)- );- el?.scrollIntoView();- }- });+// The activity list and its anchor is not immediately available when the issue shows up.+// Thus the scrollBehavior set in the vue router won't work (also tried promise to resolve async with no luck either)+// So we manually use scrollIntoView after rendering the activity list.+nextTick(() => {+ if (router.currentRoute.value.hash) {+ const el = document.getElementById(router.currentRoute.value.hash.slice(1));+ el?.scrollIntoView();+ }+});- // Need to use computed to make list reactive to activity list changes.- const activityList = computed((): Activity[] => {- const list = activityStore.getActivityListByIssue(props.issue.id);- return list.filter((activity: Activity) => {- if (activity.type == "bb.issue.field.update") {- let containUserVisibleChange =- (activity.payload as ActivityIssueFieldUpdatePayload).fieldId !=- IssueBuiltinFieldId.SUBSCRIBER_LIST;- return containUserVisibleChange;- }- return true;- });- });+// Need to use computed to make list reactive to activity list changes.+const activityList = computed((): Activity[] => {+ const list = activityStore.getActivityListByIssue(issue.value.id);+ return list.filter((activity: Activity) => {+ if (activity.type == "bb.issue.field.update") {+ let containUserVisibleChange =+ (activity.payload as ActivityIssueFieldUpdatePayload).fieldId !=+ IssueBuiltinFieldId.SUBSCRIBER_LIST;+ return containUserVisibleChange;+ }+ return true;+ });+});- const subscriberList = computed((): IssueSubscriber[] => {- return useIssueSubscriberStore().subscriberListByIssue(props.issue.id);- });+const subscriberList = computed((): IssueSubscriber[] => {+ return useIssueSubscriberStore().subscriberListByIssue(issue.value.id);+});- const cancelEditComment = () => {- editComment.value = "";- state.activeActivity = undefined;- state.editCommentMode = false;- };+const cancelEditComment = () => {+ editComment.value = "";+ state.activeActivity = undefined;+ state.editCommentMode = false;+};- const doCreateComment = () => {- const createActivity: ActivityCreate = {- type: "bb.issue.comment.create",- containerId: props.issue.id,- comment: newComment.value,- };- activityStore.createActivity(createActivity).then(() => {- useUIStateStore().saveIntroStateByKey({- key: "comment.create",- newState: true,- });+const doCreateComment = () => {+ const createActivity: ActivityCreate = {+ type: "bb.issue.comment.create",+ containerId: issue.value.id,+ comment: newComment.value,+ };+ activityStore.createActivity(createActivity).then(() => {+ useUIStateStore().saveIntroStateByKey({+ key: "comment.create",+ newState: true,+ });- newComment.value = "";- nextTick(() => sizeToFit(newCommentTextArea.value));+ newComment.value = "";+ 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- let isSubscribed = false;- for (const subscriber of subscriberList.value) {- if (subscriber.subscriber.id == currentUser.value.id) {- isSubscribed = true;- break;- }- }- if (!isSubscribed) {- emit("add-subscriber-id", currentUser.value.id);- }- });- };-- const onUpdateComment = (activity: Activity) => {- editComment.value = activity.comment;- state.activeActivity = activity;- state.editCommentMode = true;- nextTick(() => {- editCommentTextArea.value.focus();- });- };+ // 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+ let isSubscribed = false;+ for (const subscriber of subscriberList.value) {+ if (subscriber.subscriber.id == currentUser.value.id) {+ isSubscribed = true;+ break;+ }+ }+ if (!isSubscribed) {+ addSubscriberId(currentUser.value.id);+ }+ });+};- const doUpdateComment = () => {- activityStore- .updateComment({- activityId: state.activeActivity!.id,- updatedComment: editComment.value,- })- .then(() => {- cancelEditComment();- });- };+const onUpdateComment = (activity: Activity) => {+ editComment.value = activity.comment;+ state.activeActivity = activity;+ state.editCommentMode = true;+ nextTick(() => {+ editCommentTextArea.value?.focus();+ });+};- const allowUpdateComment = computed(() => {- return editComment.value != state.activeActivity!.comment;+const doUpdateComment = () => {+ activityStore+ .updateComment({+ activityId: state.activeActivity!.id,+ updatedComment: editComment.value,+ })+ .then(() => {+ cancelEditComment();});+};- const doDeleteComment = (activity: Activity) => {- activityStore.deleteActivity(activity);- };+const allowUpdateComment = computed(() => {+ return editComment.value != state.activeActivity!.comment;+});- const actionIcon = (activity: Activity): ActionIconType => {- if (activity.type == "bb.issue.create") {- return "create";- } else if (activity.type == "bb.issue.field.update") {- return "update";- } else if (activity.type == "bb.pipeline.task.status.update") {- const payload = activity.payload as ActivityTaskStatusUpdatePayload;- switch (payload.newStatus) {- case "PENDING": {- if (payload.oldStatus == "RUNNING") {- return "cancel";- } else if (payload.oldStatus == "PENDING_APPROVAL") {- return "approve";- }- break;- }- case "RUNNING": {- return "run";- }- case "DONE": {- return "complete";- }- case "FAILED": {- return "fail";- }+const doDeleteComment = (activity: Activity) => {+ activityStore.deleteActivity(activity);+};++const actionIcon = (activity: Activity): ActionIconType => {+ if (activity.type == "bb.issue.create") {+ return "create";+ } else if (activity.type == "bb.issue.field.update") {+ return "update";+ } else if (activity.type == "bb.pipeline.task.status.update") {+ const payload = activity.payload as ActivityTaskStatusUpdatePayload;+ switch (payload.newStatus) {+ case "PENDING": {+ if (payload.oldStatus == "RUNNING") {+ return "cancel";+ } else if (payload.oldStatus == "PENDING_APPROVAL") {+ return "approve";}- } else if (activity.type == "bb.pipeline.task.file.commit") {- return "commit";- } else if (activity.type == "bb.pipeline.task.statement.update") {- return "update";- } else if (- activity.type == "bb.pipeline.task.general.earliest-allowed-time.update"- ) {- return "update";+ break;+ }+ case "RUNNING": {+ return "run";+ }+ case "DONE": {+ return "complete";}+ case "FAILED": {+ return "fail";+ }+ }+ } else if (activity.type == "bb.pipeline.task.file.commit") {+ return "commit";+ } else if (activity.type == "bb.pipeline.task.statement.update") {+ return "update";+ } else if (+ activity.type == "bb.pipeline.task.general.earliest-allowed-time.update"+ ) {+ return "update";+ }- return activity.creator.id == SYSTEM_BOT_ID ? "system" : "avatar";- };+ return activity.creator.id == SYSTEM_BOT_ID ? "system" : "avatar";+};- const actionSubjectPrefix = (activity: Activity): string => {- if (activity.creator.id == SYSTEM_BOT_ID) {- if (activity.type == "bb.pipeline.task.status.update") {- return `${t("activity.subject-prefix.task")} `;- }- }- return "";- };+const actionSubjectPrefix = (activity: Activity): string => {+ if (activity.creator.id == SYSTEM_BOT_ID) {+ if (activity.type == "bb.pipeline.task.status.update") {+ return `${t("activity.subject-prefix.task")} `;+ }+ }+ return "";+};- const actionSubject = (activity: Activity): ActionSubject => {- if (activity.creator.id == SYSTEM_BOT_ID) {- if (activity.type == "bb.pipeline.task.status.update") {- if (props.issue.pipeline.id != EMPTY_ID) {- const payload = activity.payload as ActivityTaskStatusUpdatePayload;- const task = findTaskById(props.issue.pipeline, payload.taskId);- var link = "";- if (task.id != UNKNOWN_ID) {- link = `/issue/${issueSlug(- props.issue.name,- props.issue.id- )}?task=${taskSlug(task.name, task.id)}`;- }- return {- name: `${task.name} (${task.stage.name})`,- link,- };- }+const actionSubject = (activity: Activity): ActionSubject => {+ if (activity.creator.id == SYSTEM_BOT_ID) {+ if (activity.type == "bb.pipeline.task.status.update") {+ if (issue.value.pipeline.id != EMPTY_ID) {+ const payload = activity.payload as ActivityTaskStatusUpdatePayload;+ const task = findTaskById(issue.value.pipeline, payload.taskId);+ var link = "";+ if (task.id != UNKNOWN_ID) {+ link = `/issue/${issueSlug(+ issue.value.name,+ issue.value.id+ )}?task=${taskSlug(task.name, task.id)}`;}+ return {+ name: `${task.name} (${task.stage.name})`,+ link,+ };}- return {- name: activity.creator.name,- link: `/u/${activity.creator.id}`,- };- };+ }+ }+ return {+ name: activity.creator.name,+ link: `/u/${activity.creator.id}`,+ };+};- const actionSentence = (activity: Activity): string => {- if (activity.type.startsWith("bb.issue.")) {- const [tid, params] = issueActivityActionSentence(activity);- return t(tid, params);- }- switch (activity.type) {- case "bb.pipeline.task.status.update": {- const payload = activity.payload as ActivityTaskStatusUpdatePayload;- let str = t("activity.sentence.changed");- switch (payload.newStatus) {- case "PENDING": {- if (payload.oldStatus == "RUNNING") {- str = t("activity.sentence.canceled");- } else if (payload.oldStatus == "PENDING_APPROVAL") {- str = t("activity.sentence.approved");- }- break;- }- case "RUNNING": {- str = t("activity.sentence.started");- break;- }- case "DONE": {- str = t("activity.sentence.completed");- break;- }- case "FAILED": {- str = t("activity.sentence.failed");- break;- }+const actionSentence = (activity: Activity): string => {+ if (activity.type.startsWith("bb.issue.")) {+ const [tid, params] = issueActivityActionSentence(activity);+ return t(tid, params);+ }+ switch (activity.type) {+ case "bb.pipeline.task.status.update": {+ const payload = activity.payload as ActivityTaskStatusUpdatePayload;+ let str = t("activity.sentence.changed");+ switch (payload.newStatus) {+ case "PENDING": {+ if (payload.oldStatus == "RUNNING") {+ str = t("activity.sentence.canceled");+ } else if (payload.oldStatus == "PENDING_APPROVAL") {+ str = t("activity.sentence.approved");}- if (activity.creator.id != SYSTEM_BOT_ID) {- // If creator is not the robot (which means we do NOT use task name in the subject),- // then we append the task name here.- const task = findTaskById(props.issue.pipeline, payload.taskId);- str += t("activity.sentence.task-name", { name: task.name });- }- return str;+ break;}- case "bb.pipeline.task.file.commit": {- const payload = activity.payload as ActivityTaskFileCommitPayload;- // return `committed ${payload.filePath} to ${payload.branch}@${payload.repositoryFullPath}`;- return t("activity.sentence.committed-to-at", {- file: payload.filePath,- branch: payload.branch,- repo: payload.repositoryFullPath,- });+ case "RUNNING": {+ str = t("activity.sentence.started");+ break;}- case "bb.pipeline.task.statement.update": {- const payload =- activity.payload as ActivityTaskStatementUpdatePayload;- return t("activity.sentence.changed-from-to", {- name: "SQL",- oldValue: payload.oldStatement,- newValue: payload.newStatement,- });+ case "DONE": {+ str = t("activity.sentence.completed");+ break;}- case "bb.pipeline.task.general.earliest-allowed-time.update": {- const payload =- activity.payload as ActivityTaskEarliestAllowedTimeUpdatePayload;- const newVal = payload.newEarliestAllowedTs;- const oldVal = payload.oldEarliestAllowedTs;- return t("activity.sentence.changed-from-to", {- name: "earliest allowed time",- oldValue: oldVal ? dayjs(oldVal * 1000) : "Unset",- newValue: newVal ? dayjs(newVal * 1000) : "Unset",- });+ case "FAILED": {+ str = t("activity.sentence.failed");+ break;}}- return "";- };+ if (activity.creator.id != SYSTEM_BOT_ID) {+ // If creator is not the robot (which means we do NOT use task name in the subject),+ // then we append the task name here.+ const task = findTaskById(issue.value.pipeline, payload.taskId);+ str += t("activity.sentence.task-name", { name: task.name });+ }+ return str;+ }+ case "bb.pipeline.task.file.commit": {+ const payload = activity.payload as ActivityTaskFileCommitPayload;+ // return `committed ${payload.filePath} to ${payload.branch}@${payload.repositoryFullPath}`;+ return t("activity.sentence.committed-to-at", {+ file: payload.filePath,+ branch: payload.branch,+ repo: payload.repositoryFullPath,+ });+ }+ case "bb.pipeline.task.statement.update": {+ const payload = activity.payload as ActivityTaskStatementUpdatePayload;+ return t("activity.sentence.changed-from-to", {+ name: "SQL",+ oldValue: payload.oldStatement,+ newValue: payload.newStatement,+ });+ }+ case "bb.pipeline.task.general.earliest-allowed-time.update": {+ const payload =+ activity.payload as ActivityTaskEarliestAllowedTimeUpdatePayload;+ const newVal = payload.newEarliestAllowedTs;+ const oldVal = payload.oldEarliestAllowedTs;+ return t("activity.sentence.changed-from-to", {+ name: "earliest allowed time",+ oldValue: oldVal ? dayjs(oldVal * 1000) : "Unset",+ newValue: newVal ? dayjs(newVal * 1000) : "Unset",+ });+ }+ }+ return "";+};- return {- SYSTEM_BOT_ID,- state,- activityList,- newComment,- newCommentTextArea,- editComment,- editCommentTextArea,- currentUser,- actionIcon,- actionSubjectPrefix,- actionSubject,- actionSentence,- doCreateComment,- cancelEditComment,- onUpdateComment,- doUpdateComment,- allowUpdateComment,- doDeleteComment,- };- },-});+const fileCommitActivityUrl = (activity: Activity) => {+ const payload = activity.payload as ActivityTaskFileCommitPayload;+ return `${payload.vcsInstanceUrl}/${payload.repositoryFullPath}/-/commit/${payload.commitId}`;+};</script>diff --git a/frontend/src/components/Issue/IssueBanner.vue b/frontend/src/components/Issue/IssueBanner.vueindex fbf09aaa4a..a178148aae 100644--- a/frontend/src/components/Issue/IssueBanner.vue+++ b/frontend/src/components/Issue/IssueBanner.vue@@ -20,24 +20,23 @@</template><script lang="ts" setup>-import { computed } from "vue";-import { Issue } from "../../types";-import { activeTask } from "../../utils";+import { computed, Ref } from "vue";+import { Issue } from "@/types";+import { activeTask } from "@/utils";+import { useIssueLogic } from "./logic";-const props = defineProps<{- issue: Issue;-}>();+const issue = useIssueLogic().issue as Ref<Issue>;const showCancelBanner = computed(() => {- return props.issue.status == "CANCELED";+ return issue.value.status == "CANCELED";});const showSuccessBanner = computed(() => {- return props.issue.status == "DONE";+ return issue.value.status == "DONE";});const showPendingApproval = computed(() => {- const task = activeTask(props.issue.pipeline);+ const task = activeTask(issue.value.pipeline);return task.status == "PENDING_APPROVAL";});</script>diff --git a/frontend/src/components/Issue/IssueDescriptionPanel.vue b/frontend/src/components/Issue/IssueDescriptionPanel.vueindex 57a0898136..24396a5e7a 100644--- a/frontend/src/components/Issue/IssueDescriptionPanel.vue+++ b/frontend/src/components/Issue/IssueDescriptionPanel.vue@@ -4,7 +4,7 @@<div class="textlabel">{{ $t("common.description") }}</div><div v-if="!create" class="space-x-2"><button- v-if="allowEdit && !state.editing"+ v-if="allowEditNameAndDescription && !state.editing"type="button"class="btn-icon"@click.prevent="beginEdit"@@ -57,7 +57,7 @@sizeToFit(e.target as HTMLTextAreaElement);// When creating the issue, we will emit the event on keystroke to update the in-memory state.if (create) {- $emit('update-description', state.editDescription);+ updateDescription(state.editDescription);}}"@@ -69,140 +69,100 @@></textarea></template>-<script lang="ts">-import {- nextTick,- onMounted,- onUnmounted,- PropType,- ref,- reactive,- watch,- defineComponent,-} from "vue";-import type { Issue, IssueCreate } from "@/types";+<script lang="ts" setup>+import { nextTick, onMounted, onUnmounted, ref, reactive, watch } from "vue";+import type { Issue } from "@/types";import { sizeToFit } from "@/utils";+import { useExtraIssueLogic, useIssueLogic } from "./logic";interface LocalState {editing: boolean;editDescription: string;}-export default defineComponent({- name: "IssueDescriptionPanel",- props: {- issue: {- required: true,- type: Object as PropType<Issue | IssueCreate>,- },- create: {- required: true,- type: Boolean,- },- allowEdit: {- required: true,- type: Boolean,- },- },- emits: ["update-description"],- setup(props, { emit }) {- const editDescriptionTextArea = ref();+const { issue, create } = useIssueLogic();+const { allowEditNameAndDescription, updateDescription } = useExtraIssueLogic();- const state = reactive<LocalState>({- editing: false,- editDescription: props.issue.description,- });-- const keyboardHandler = (e: KeyboardEvent) => {- if (- state.editing &&- editDescriptionTextArea.value === document.activeElement- ) {- if (e.code == "Escape") {- cancelEdit();- } else if (e.code == "Enter" && e.metaKey) {- if (state.editDescription != props.issue.description) {- saveEdit();- }- }- }- };+const editDescriptionTextArea = ref();- const resizeTextAreaHandler = () => {- sizeToFit(editDescriptionTextArea.value);- };+const state = reactive<LocalState>({+ editing: false,+ editDescription: issue.value.description,+});- onMounted(() => {- document.addEventListener("keydown", keyboardHandler);- window.addEventListener("resize", resizeTextAreaHandler);- if (props.create) {- state.editing = true;- sizeToFit(editDescriptionTextArea.value);+const keyboardHandler = (e: KeyboardEvent) => {+ if (+ state.editing &&+ editDescriptionTextArea.value === document.activeElement+ ) {+ if (e.code == "Escape") {+ cancelEdit();+ } else if (e.code == "Enter" && e.metaKey) {+ if (state.editDescription != issue.value.description) {+ saveEdit();}- });+ }+ }+};- onUnmounted(() => {- document.removeEventListener("keydown", keyboardHandler);- window.removeEventListener("resize", resizeTextAreaHandler);- });+const resizeTextAreaHandler = () => {+ sizeToFit(editDescriptionTextArea.value);+};- // Reset the edit state after creating the issue.- watch(- () => props.create,- (curNew, prevNew) => {- if (!curNew && prevNew) {- state.editing = false;- }- }- );+onMounted(() => {+ document.addEventListener("keydown", keyboardHandler);+ window.addEventListener("resize", resizeTextAreaHandler);+ if (create.value) {+ state.editing = true;+ sizeToFit(editDescriptionTextArea.value);+ }+});- watch(- () => props.issue,- (curIssue) => {- state.editDescription = curIssue.description;- nextTick(() => {- sizeToFit(editDescriptionTextArea.value);- });- }- );+onUnmounted(() => {+ document.removeEventListener("keydown", keyboardHandler);+ window.removeEventListener("resize", resizeTextAreaHandler);+});- const beginEdit = () => {- state.editDescription = props.issue.description;- state.editing = true;- nextTick(() => {- editDescriptionTextArea.value.focus();- });- };+// Reset the edit state after creating the issue.+watch(create, (curNew, prevNew) => {+ if (!curNew && prevNew) {+ state.editing = false;+ }+});- const saveEdit = () => {- emit(- "update-description",- state.editDescription,- (updatedIssue: Issue) => {- state.editDescription = updatedIssue.description;- state.editing = false;- nextTick(() => {- sizeToFit(editDescriptionTextArea.value);- });- }- );- };+watch(+ () => issue.value,+ (curIssue) => {+ state.editDescription = curIssue.description;+ nextTick(() => {+ sizeToFit(editDescriptionTextArea.value);+ });+ }+);- const cancelEdit = () => {- state.editDescription = props.issue.description;- state.editing = false;- nextTick(() => {- sizeToFit(editDescriptionTextArea.value);- });- };+const beginEdit = () => {+ state.editDescription = issue.value.description;+ state.editing = true;+ nextTick(() => {+ editDescriptionTextArea.value.focus();+ });+};- return {- state,- editDescriptionTextArea,- beginEdit,- saveEdit,- cancelEdit,- };- },-});+const saveEdit = () => {+ updateDescription(state.editDescription, (updatedIssue: Issue) => {+ state.editDescription = updatedIssue.description;+ state.editing = false;+ nextTick(() => {+ sizeToFit(editDescriptionTextArea.value);+ });+ });+};++const cancelEdit = () => {+ state.editDescription = issue.value.description;+ state.editing = false;+ nextTick(() => {+ sizeToFit(editDescriptionTextArea.value);+ });+};</script>diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vueindex 4709b2567d..b376f22ca7 100644--- a/frontend/src/components/Issue/IssueDetailLayout.vue+++ b/frontend/src/components/Issue/IssueDetailLayout.vue@@ -1,24 +1,16 @@<template>- <div- id="issue-detail-top"- class="flex-1 overflow-auto focus:outline-none"- tabindex="0"- >- <component :is="logicProviderType" ref="issueLogic">- <IssueBanner v-if="!create" :issue="(issue as Issue)" />+ <component :is="logicProviderType" ref="issueLogic">+ <div+ id="issue-detail-top"+ class="flex-1 overflow-auto focus:outline-none"+ tabindex="0"+ >+ <IssueBanner v-if="!create" /><!-- Highlight Panel --><div class="bg-white px-4 pb-4">- <IssueHighlightPanel- :issue="(issue as Issue)"- :create="create"- :allow-edit="allowEditNameAndDescription"- @update-name="updateName"- >- <IssueStatusTransitionButtonGroup- @change-issue-status="changeIssueStatus"- @change-task-status="changeTaskStatus"- />+ <IssueHighlightPanel>+ <IssueStatusTransitionButtonGroup /></IssueHighlightPanel></div>@@ -48,12 +40,7 @@</template><div v-if="!create" class="px-4 py-4 md:flex md:flex-col border-b">- <IssueStagePanel- :stage="(selectedStage as Stage)"- :selected-task="(selectedTask as Task)"- :is-tenant-mode="isTenantMode"- :is-ghost-mode="isGhostMode"- />+ <IssueStagePanel /></div></template>@@ -64,12 +51,7 @@class="px-2 py-4 md:flex md:flex-col":class="showPipelineFlowBar ? '' : 'lg:border-t'">- <IssueOutputPanel- :issue="(issue as Issue)"- :output-field-list="issueTemplate.outputFieldList"- :allow-edit="allowEditOutput"- @update-custom-field="updateCustomField"- />+ <IssueOutputPanel /></div><!-- Main Content -->@@ -87,24 +69,7 @@<divclass="py-6 lg:pl-4 lg:w-96 xl:w-112 lg:border-l lg:border-block-border overflow-hidden">- <IssueSidebar- :issue="issue"- :database="database"- :instance="instance"- :create="create"- :selected-stage="selectedStage"- :task="selectedTask"- :input-field-list="issueTemplate.inputFieldList"- :allow-edit="allowEditSidebar"- :is-tenant-deploy-mode="isTenantMode"- @update-assignee-id="updateAssigneeId"- @update-earliest-allowed-time="updateEarliestAllowedTime"- @add-subscriber-id="addSubscriberId"- @remove-subscriber-id="removeSubscriberId"- @update-custom-field="updateCustomField"- @select-stage-id="selectStageOrTask"- @select-task-id="selectTaskId"- />+ <IssueSidebar :database="database" :instance="instance" /></div><div class="lg:hidden border-t border-block-border" /><div class="w-full py-4 pr-4">@@ -118,57 +83,32 @@<IssueTaskStatementPanel :sql-hint="sqlHint()" /></section>- <IssueDescriptionPanel- :issue="issue"- :create="create"- :allow-edit="allowEditNameAndDescription"- @update-description="updateDescription"- />+ <IssueDescriptionPanel />+<sectionv-if="!create"aria-labelledby="activity-title"class="mt-4">- <IssueActivityPanel- :issue="(issue as Issue)"- :issue-template="issueTemplate"- @add-subscriber-id="addSubscriberId"- />+ <IssueActivityPanel /></section></div></div></div></main>- </component>- </div>+ </div>+ </component></template><script lang="ts" setup>-/* eslint-disable vue/no-mutating-props */-+import { computed, onMounted, PropType, ref, watch, watchEffect } from "vue";+import { useRoute } from "vue-router";import {- computed,- nextTick,- onMounted,- PropType,- ref,- watch,- watchEffect,-} from "vue";-import { useRoute, useRouter } from "vue-router";-import { cloneDeep, isEmpty, isEqual } from "lodash-es";-import {- idFromSlug,pipelineType,PipelineType,- indexFromSlug,activeStage,- stageSlug,- taskSlug,- isDev,activeTaskInStage,activeTask,- issueSlug,} from "@/utils";import IssueBanner from "./IssueBanner.vue";import IssueHighlightPanel from "./IssueHighlightPanel.vue";@@ -186,38 +126,18 @@ import TaskCheckBar from "./TaskCheckBar.vue";import type {Issue,IssueCreate,- IssuePatch,- PrincipalId,Database,Instance,- Stage,- StageId,- IssueStatus,- TaskId,- TaskStatusPatch,- TaskStatus,- IssueStatusPatch,Task,TaskDatabaseSchemaUpdatePayload,- StageCreate,TaskCreate,- Project,MigrationType,- TaskPatch,} from "@/types";-import {- defaultTemplate,- templateForType,- InputField,- OutputField,-} from "@/plugins";+import { defaultTemplate, templateForType } from "@/plugins";import {featureToRef,- useCurrentUser,useDatabaseStore,useInstanceStore,- useIssueStore,- useIssueSubscriberStore,useProjectStore,useTaskStore,} from "@/store";@@ -228,6 +148,7 @@ import {StandardModeProvider,TaskTypeWithStatement,IssueLogic,+ useBaseIssueLogic,} from "./logic";const props = defineProps({@@ -245,12 +166,8 @@ const emit = defineEmits<{(e: "status-changed", eager: boolean): void;}>();-const router = useRouter();const route = useRoute();-const currentUser = useCurrentUser();-const issueStore = useIssueStore();-const issueSubscriberStore = useIssueSubscriberStore();const taskStore = useTaskStore();const projectStore = useProjectStore();const databaseStore = useDatabaseStore();@@ -258,9 +175,29 @@ const databaseStore = useDatabaseStore();const create = computed(() => props.create);const issue = computed(() => props.issue);+const {+ project,+ isTenantMode,+ isGhostMode,+ createIssue,+ selectedStage,+ selectedTask,+ selectStageOrTask,+ selectTask,+ taskStatusOfStage,+ isValidStage,+} = useBaseIssueLogic({ issue, create });+const issueLogic = ref<IssueLogic>();-watchEffect(function prepare() {+// Determine which type of IssueLogicProvider should be used+const logicProviderType = computed(() => {+ if (isTenantMode.value) return TenantModeProvider;+ if (isGhostMode.value) return GhostModeProvider;+ return StandardModeProvider;+});++watchEffect(() => {if (props.create) {projectStore.fetchProjectById((props.issue as IssueCreate).projectId);}@@ -270,148 +207,6 @@ const issueTemplate = computed(() => templateForType(props.issue.type) || defaultTemplate());-const project = computed((): Project => {- if (props.create) {- return projectStore.getProjectById((props.issue as IssueCreate).projectId);- }- return (props.issue as Issue).project;-});--const updateName = (- newName: string,- postUpdated: (updatedIssue: Issue) => void-) => {- if (props.create) {- props.issue.name = newName;- } else {- patchIssue(- {- name: newName,- },- postUpdated- );- }-};--const updateDescription = (- newDescription: string,- postUpdated: (updatedIssue: Issue) => void-) => {- if (props.create) {- props.issue.description = newDescription;- } else {- patchIssue(- {- description: newDescription,- },- postUpdated- );- }-};--const updateAssigneeId = (newAssigneeId: PrincipalId) => {- if (props.create) {- (props.issue as IssueCreate).assigneeId = newAssigneeId;- } else {- patchIssue({- assigneeId: newAssigneeId,- });- }-};--const updateEarliestAllowedTime = (newEarliestAllowedTsMs: number) => {- if (props.create) {- if (isGhostMode.value) {- // In gh-ost mode, when creating an issue, all sub-tasks in a stage- // share the same earliestAllowedTs.- // So updates on any one of them will be applied to others.- // (They can be updated independently after creation)- const taskList = selectedStage.value.taskList as TaskCreate[];- taskList.forEach((task) => {- task.earliestAllowedTs = newEarliestAllowedTsMs;- });- } else {- selectedTask.value.earliestAllowedTs = newEarliestAllowedTsMs;- }- } else {- const taskPatch: TaskPatch = {- earliestAllowedTs: newEarliestAllowedTsMs,- };- patchTask((selectedTask.value as Task).id, taskPatch);- }-};--const addSubscriberId = (subscriberId: PrincipalId) => {- issueSubscriberStore.createSubscriber({- issueId: (props.issue as Issue).id,- subscriberId,- });-};--const removeSubscriberId = (subscriberId: PrincipalId) => {- issueSubscriberStore.deleteSubscriber({- issueId: (props.issue as Issue).id,- subscriberId,- });-};--const updateCustomField = (field: InputField | OutputField, value: any) => {- if (!isEqual(props.issue.payload[field.id], value)) {- if (props.create) {- props.issue.payload[field.id] = value;- } else {- const newPayload = cloneDeep(props.issue.payload);- newPayload[field.id] = value;- patchIssue({- payload: newPayload,- });- }- }-};--const changeIssueStatus = (newStatus: IssueStatus, comment: string) => {- const issueStatusPatch: IssueStatusPatch = {- status: newStatus,- comment: comment,- };- issueStore- .updateIssueStatus({- issueId: (props.issue as Issue).id,- issueStatusPatch,- })- .then(() => {- // pollIssue(POST_CHANGE_POLL_INTERVAL);- });-};--const changeTaskStatus = (- task: Task,- newStatus: TaskStatus,- comment: string-) => {- // Switch to the stage view containing this task- selectStageOrTask(task.stage.id);- nextTick().then(() => {- selectTaskId(task.id);- });-- const taskStatusPatch: TaskStatusPatch = {- status: newStatus,- comment: comment,- };- taskStore- .updateStatus({- issueId: (props.issue as Issue).id,- pipelineId: (props.issue as Issue).pipeline.id,- taskId: task.id,- taskStatusPatch,- })- .then(() => {- // pollIssue(POST_CHANGE_POLL_INTERVAL);- emit("status-changed", true);- });-};-const runTaskChecks = (task: Task) => {taskStore.runChecks({@@ -425,163 +220,10 @@ const runTaskChecks = (task: Task) => {});};-const patchIssue = (- issuePatch: IssuePatch,- postUpdated?: (updatedIssue: Issue) => void-) => {- issueStore- .patchIssue({- issueId: (props.issue as Issue).id,- issuePatch,- })- .then((updatedIssue) => {- // issue/patchIssue already fetches the new issue, so we schedule- // the next poll in NORMAL_POLL_INTERVAL- // pollIssue(NORMAL_POLL_INTERVAL);- emit("status-changed", false);- if (postUpdated) {- postUpdated(updatedIssue);- }- });-};--const patchTask = (- taskId: TaskId,- taskPatch: TaskPatch,- postUpdated?: (updatedTask: Task) => void-) => {- taskStore- .patchTask({- issueId: (props.issue as Issue).id,- pipelineId: (props.issue as Issue).pipeline.id,- taskId,- taskPatch,- })- .then((updatedTask) => {- // For now, the only task/patchTask is to change statement, which will trigger async task check.- // Thus we use the short poll interval- emit("status-changed", true);- if (postUpdated) {- postUpdated(updatedTask);- }- });-};--const createIssue = (issue: IssueCreate) => {- // Set issue.pipeline and issue.payload to empty- // because we are no longer passing parameters via issue.pipeline- // we are using issue.createContext instead- delete issue.pipeline;- issue.payload = {};-- issueStore.createIssue(issue).then((createdIssue) => {- // Use replace to omit the new issue url in the navigation history.- router.replace(`/issue/${issueSlug(createdIssue.name, createdIssue.id)}`);- });-};-const currentPipelineType = computed((): PipelineType => {return pipelineType(props.issue.pipeline!);});-const selectedStage = computed((): Stage | StageCreate => {- const stageSlug = router.currentRoute.value.query.stage as string;- const taskSlug = router.currentRoute.value.query.task as string;- // For stage slug, we support both index based and id based.- // Index based is used when creating the new task and is the one used when clicking the UI.- // Id based is used when the context only has access to the stage id (e.g. Task only contains StageId)- if (stageSlug) {- const index = indexFromSlug(stageSlug);- if (index < props.issue.pipeline!.stageList.length) {- return props.issue.pipeline!.stageList[index];- }- const stageId = idFromSlug(stageSlug);- const stageList = (props.issue as Issue).pipeline.stageList;- for (const stage of stageList) {- if (stage.id == stageId) {- return stage;- }- }- } else if (!props.create && taskSlug) {- const taskId = idFromSlug(taskSlug);- const stageList = (props.issue as Issue).pipeline.stageList;- for (const stage of stageList) {- for (const task of stage.taskList) {- if (task.id == taskId) {- return stage;- }- }- }- }- if (props.create) {- return props.issue.pipeline!.stageList[0];- }- return activeStage((props.issue as Issue).pipeline);-});--const selectStageOrTask = (- stageId: StageId,- taskSlug: string | undefined = undefined-) => {- const stageList = props.issue.pipeline!.stageList;- const index = stageList.findIndex((item, index) => {- if (props.create) {- return index === stageId;- }- return (item as Stage).id == stageId;- });- router.replace({- name: "workspace.issue.detail",- query: {- ...router.currentRoute.value.query,- stage: stageSlug(stageList[index].name, index),- task: taskSlug,- },- });-};--const selectTaskId = (taskId: TaskId) => {- const taskList = selectedStage.value.taskList as Task[];- const task = taskList.find((t) => t.id === taskId);- if (!task) return;- const slug = taskSlug(task.name, task.id);- const stage = selectedStage.value as Stage;- selectStageOrTask(stage.id, slug);-};--const selectedTask = computed((): Task | TaskCreate => {- const taskSlug = route.query.task as string;- const { taskList } = selectedStage.value;- if (taskSlug) {- const index = indexFromSlug(taskSlug);- if (index < taskList.length) {- return taskList[index];- }- const id = idFromSlug(taskSlug);- for (let i = 0; i < taskList.length; i++) {- const task = taskList[i] as Task;- if (task.id === id) {- return task;- }- }- }- return taskList[0];-});--const isTenantMode = computed((): boolean => {- if (project.value.tenantMode !== "TENANT") return false;- return (- props.issue.type === "bb.issue.database.schema.update" ||- props.issue.type === "bb.issue.database.data.update"- );-});--const isGhostMode = computed((): boolean => {- if (!isDev()) return false;-- return props.issue.type === "bb.issue.database.schema.update.ghost";-});-const selectedMigrateType = computed((): MigrationType => {if (!props.create &&@@ -594,37 +236,6 @@ const selectedMigrateType = computed((): MigrationType => {return "MIGRATE";});-const allowEditSidebar = computed(() => {- // For now, we only allow assignee to update the field when the issue- // is 'OPEN'. This reduces flexibility as creator must ask assignee to- // change any fields if there is typo. On the other hand, this avoids- // the trouble that the creator changes field value when the creator- // is performing the issue based on the old value.- // For now, we choose to be on the safe side at the cost of flexibility.- return (- props.create ||- ((props.issue as Issue).status == "OPEN" &&- (props.issue as Issue).assignee?.id == currentUser.value.id)- );-});--const allowEditOutput = computed(() => {- return (- props.create ||- ((props.issue as Issue).status == "OPEN" &&- (props.issue as Issue).assignee?.id == currentUser.value.id)- );-});--const allowEditNameAndDescription = computed(() => {- return (- props.create ||- ((props.issue as Issue).status == "OPEN" &&- ((props.issue as Issue).assignee?.id == currentUser.value.id ||- (props.issue as Issue).creator.id == currentUser.value.id))- );-});-const showPipelineFlowBar = computed(() => {return currentPipelineType.value != "NO_PIPELINE";});@@ -689,36 +300,6 @@ const supportBackwardCompatibilityFeature = computed((): boolean => {return engine === "MYSQL" || engine === "TIDB";});-const taskStatusOfStage = (stage: Stage | StageCreate) => {- if (props.create) {- return stage.taskList[0].status;- }- const activeTask = activeTaskInStage(stage as Stage);- return activeTask.status;-};--const isValidStage = (stage: Stage | StageCreate) => {- if (!props.create) {- return true;- }-- for (const task of stage.taskList) {- if (TaskTypeWithStatement.includes(task.type)) {- if (isEmpty((task as TaskCreate).statement)) {- return false;- }- }- }- return true;-};--// Determine which type of IssueLogicProvider should be used-const logicProviderType = computed(() => {- if (isTenantMode.value) return TenantModeProvider;- if (isGhostMode.value) return GhostModeProvider;- return StandardModeProvider;-});-watch([create, issue, () => route.query.sql as string, issueLogic],([create, issue, sql, provider]) => {@@ -731,11 +312,13 @@ watch(});+const onStatusChanged = (eager: boolean) => emit("status-changed", eager);+provideIssueLogic({create,issue,- project: project,+ project,template: issueTemplate,selectedStage,selectedTask,@@ -746,9 +329,9 @@ provideIssueLogic(activeStageOfPipeline: activeStage,activeTaskOfPipeline: activeTask,activeTaskOfStage: activeTaskInStage,- selectStageOrTask: selectStageOrTask,- patchTask,- patchIssue,+ selectStageOrTask,+ selectTask,+ onStatusChanged,createIssue,},truediff --git a/frontend/src/components/Issue/IssueHighlightPanel.vue b/frontend/src/components/Issue/IssueHighlightPanel.vueindex b55bf5ac63..932fcd81be 100644--- a/frontend/src/components/Issue/IssueHighlightPanel.vue+++ b/frontend/src/components/Issue/IssueHighlightPanel.vue@@ -12,7 +12,7 @@</div><BBTextFieldclass="ml-2 my-0.5 w-full text-lg font-bold"- :disabled="!allowEdit"+ :disabled="!allowEditNameAndDescription":required="true":focus-on-mount="create":bordered="false"@@ -76,107 +76,82 @@</div></template>-<script lang="ts">-import { reactive, watch, PropType, computed, defineComponent } from "vue";+<script lang="ts" setup>+import { reactive, watch, computed, Ref } from "vue";import IssueStatusIcon from "./IssueStatusIcon.vue";-import { activeTask } from "../../utils";+import { activeTask } from "@/utils";import {TaskDatabaseSchemaUpdatePayload,TaskDatabaseDataUpdatePayload,Issue,VCSPushEvent,-} from "../../types";+} from "@/types";+import { useExtraIssueLogic, useIssueLogic } from "./logic";interface LocalState {editing: boolean;name: string;}-export default defineComponent({- name: "IssueHighlightPanel",- components: { IssueStatusIcon },- props: {- issue: {- required: true,- type: Object as PropType<Issue>,- },- create: {- required: true,- type: Boolean,- },- allowEdit: {- required: true,- type: Boolean,- },- },- emits: ["update-name"],- setup(props, { emit }) {- const state = reactive<LocalState>({- editing: false,- name: props.issue.name,- });+const logic = useIssueLogic();+const create = logic.create;+const issue = logic.issue as Ref<Issue>;+const { allowEditNameAndDescription, updateName } = useExtraIssueLogic();- watch(- () => props.issue,- (curIssue) => {- state.name = curIssue.name;- }- );-- const pushEvent = computed((): VCSPushEvent | undefined => {- if (props.issue.type == "bb.issue.database.schema.update") {- const payload = activeTask(props.issue.pipeline)- .payload as TaskDatabaseSchemaUpdatePayload;- return payload?.pushEvent;- } else if (props.issue.type == "bb.issue.database.data.update") {- const payload = activeTask(props.issue.pipeline)- .payload as TaskDatabaseDataUpdatePayload;- return payload?.pushEvent;- }- return undefined;- });+const state = reactive<LocalState>({+ editing: false,+ name: issue.value.name,+});- const vcsType = computed((): string => {- if (pushEvent.value) {- if (pushEvent.value.vcsType.startsWith("GITLAB")) {- return "GitLab";- }- }- return "";- });+watch(+ () => issue.value,+ (curIssue) => {+ state.name = curIssue.name;+ }+);- const vcsBranch = computed((): string => {- if (pushEvent.value) {- return pushEvent.value.ref.replace(/^refs\/heads\//g, "");- }- return "";- });+const pushEvent = computed((): VCSPushEvent | undefined => {+ if (issue.value.type == "bb.issue.database.schema.update") {+ const payload = activeTask(issue.value.pipeline)+ .payload as TaskDatabaseSchemaUpdatePayload;+ return payload?.pushEvent;+ } else if (issue.value.type == "bb.issue.database.data.update") {+ const payload = activeTask(issue.value.pipeline)+ .payload as TaskDatabaseDataUpdatePayload;+ return payload?.pushEvent;+ }+ return undefined;+});- const vcsBranchUrl = computed((): string => {- if (pushEvent.value) {- if (pushEvent.value.vcsType == "GITLAB_SELF_HOST") {- return `${pushEvent.value.repositoryUrl}/-/tree/${vcsBranch.value}`;- }- }- return "";- });+const vcsType = computed((): string => {+ if (pushEvent.value) {+ if (pushEvent.value.vcsType.startsWith("GITLAB")) {+ return "GitLab";+ }+ }+ return "";+});- const trySaveName = (text: string) => {- state.name = text;- if (text != props.issue.name) {- emit("update-name", state.name);- }- };+const vcsBranch = computed((): string => {+ if (pushEvent.value) {+ return pushEvent.value.ref.replace(/^refs\/heads\//g, "");+ }+ return "";+});- return {- state,- activeTask,- pushEvent,- vcsType,- vcsBranch,- vcsBranchUrl,- trySaveName,- };- },+const vcsBranchUrl = computed((): string => {+ if (pushEvent.value) {+ if (pushEvent.value.vcsType == "GITLAB_SELF_HOST") {+ return `${pushEvent.value.repositoryUrl}/-/tree/${vcsBranch.value}`;+ }+ }+ return "";});++const trySaveName = (text: string) => {+ state.name = text;+ if (text != issue.value.name) {+ updateName(state.name);+ }+};</script>diff --git a/frontend/src/components/Issue/IssueOutputPanel.vue b/frontend/src/components/Issue/IssueOutputPanel.vueindex 908c012634..3331aa1f04 100644--- a/frontend/src/components/Issue/IssueOutputPanel.vue+++ b/frontend/src/components/Issue/IssueOutputPanel.vue@@ -7,7 +7,7 @@</h2><div class="my-2 mx-4 space-y-2">- <template v-for="(field, index) in outputFieldList" :key="index">+ <template v-for="(field, index) in template.outputFieldList" :key="index"><div class="flex flex-col space-y-1"><div class="textlabel">{{ field.name }}@@ -26,11 +26,11 @@<inputtype="text"class="flex-1 min-w-0 block w-full px-3 py-2 rounded-l-md border border-r border-control-border focus:mr-0.5 focus:ring-control focus:border-control sm:text-sm disabled:bg-gray-50"- :disabled="!allowEdit"+ :disabled="!allowEditOutput":name="field.id":value="fieldValue(field)"autocomplete="off"- @blur="(e: any) => $emit('update-custom-field', field, e.target.value)"+ @blur="(e: any) => updateCustomField(field, e.target.value)"/><!-- Disallow tabbing since the focus ring is partially covered by the text field due to overlaying --><button@@ -61,7 +61,7 @@:disabled="!allowEditDatabase":mode="'ENVIRONMENT'":environmentId="environmentId"- :selectedId="fieldValue(field) || UNKNOWN_ID"+ :selectedId="parseInt(fieldValue(field), 10) || UNKNOWN_ID"@select-database-id="(databaseId: number) => {trySaveCustomField(field, databaseId);@@ -88,120 +88,83 @@</div></template>-<script lang="ts">-import { PropType, computed, reactive, defineComponent } from "vue";+<script lang="ts" setup>+import { computed, Ref } from "vue";import { useRouter } from "vue-router";-import isEqual from "lodash-es/isEqual";+import { isEqual } from "lodash-es";import { toClipboard } from "@soerenmartius/vue3-clipboard";import DatabaseSelect from "../DatabaseSelect.vue";-import { activeEnvironment } from "../../utils";-import { OutputField, IssueContext } from "../../plugins";-import { DatabaseId, EnvironmentId, Issue, UNKNOWN_ID } from "../../types";+import { activeEnvironment } from "@/utils";+import { OutputField, IssueContext } from "@/plugins";+import { DatabaseId, EnvironmentId, Issue, UNKNOWN_ID } from "@/types";import { pushNotification, useCurrentUser } from "@/store";+import { useExtraIssueLogic, useIssueLogic } from "./logic";-// eslint-disable-next-line @typescript-eslint/no-empty-interface-interface LocalState {}+const router = useRouter();+const logic = useIssueLogic();+const issue = logic.issue as Ref<Issue>;+const template = logic.template;+const { allowEditOutput, updateCustomField } = useExtraIssueLogic();-export default defineComponent({- name: "IssueOutputPanel",- components: { DatabaseSelect },- props: {- issue: {- required: true,- type: Object as PropType<Issue>,- },- outputFieldList: {- required: true,- type: Object as PropType<OutputField[]>,- },- allowEdit: {- required: true,- type: Boolean,- },- },- emits: ["update-custom-field"],- setup(props, { emit }) {- const router = useRouter();+const currentUser = useCurrentUser();- const state = reactive<LocalState>({});+const environmentId = computed((): EnvironmentId => {+ return activeEnvironment(issue.value.pipeline).id;+});- const currentUser = useCurrentUser();+const fieldValue = (field: OutputField): string => {+ return issue.value.payload[field.id];+};- const environmentId = computed((): EnvironmentId => {- return activeEnvironment(props.issue.pipeline).id;- });+const issueContext = computed((): IssueContext => {+ return {+ currentUser: currentUser.value,+ create: false,+ issue: issue.value,+ };+});- const fieldValue = (field: OutputField): string => {- return props.issue.payload[field.id];- };+const allowEditDatabase = computed((): boolean => {+ if (!allowEditOutput.value) {+ return false;+ }+ return (+ issue.value.type == "bb.issue.database.create" ||+ issue.value.type == "bb.issue.database.grant"+ );+});- const issueContext = computed((): IssueContext => {- return {- currentUser: currentUser.value,- create: false,- issue: props.issue,- };- });+const isValidLink = (link: string): boolean => {+ return link?.trim().length > 0;+};- const allowEditDatabase = computed((): boolean => {- if (!props.allowEdit) {- return false;- }- return (- props.issue.type == "bb.issue.database.create" ||- props.issue.type == "bb.issue.database.grant"- );+const copyText = (field: OutputField) => {+ toClipboard(issue.value.payload[field.id]).then(() => {+ pushNotification({+ module: "bytebase",+ style: "INFO",+ title: `${field.name} copied to clipboard.`,});+ });+};- const isValidLink = (link: string): boolean => {- return link?.trim().length > 0;- };+const goToLink = (link: string) => {+ const myLink = link.trim();+ const parts = myLink.split("://");+ if (parts.length > 1) {+ window.open(myLink, "_blank");+ } else {+ if (!myLink.startsWith("/")) {+ router.push("/" + myLink);+ } else {+ router.push(myLink);+ }+ }+};- const copyText = (field: OutputField) => {- toClipboard(props.issue.payload[field.id]).then(() => {- pushNotification({- module: "bytebase",- style: "INFO",- title: `${field.name} copied to clipboard.`,- });- });- };-- const goToLink = (link: string) => {- const myLink = link.trim();- const parts = myLink.split("://");- if (parts.length > 1) {- window.open(myLink, "_blank");- } else {- if (!myLink.startsWith("/")) {- router.push("/" + myLink);- } else {- router.push(myLink);- }- }- };-- const trySaveCustomField = (- field: OutputField,- value: string | DatabaseId- ) => {- if (!isEqual(value, fieldValue(field))) {- emit("update-custom-field", field, value);- }- };-- return {- UNKNOWN_ID,- state,- environmentId,- fieldValue,- issueContext,- allowEditDatabase,- isValidLink,- copyText,- goToLink,- trySaveCustomField,- };- },-});+const trySaveCustomField = (field: OutputField, value: string | DatabaseId) => {+ if (!isEqual(value, fieldValue(field))) {+ updateCustomField(field, value);+ }+};</script>diff --git a/frontend/src/components/Issue/IssueSidebar.vue b/frontend/src/components/Issue/IssueSidebar.vueindex 0bef002c4c..dc6aa15caa 100644--- a/frontend/src/components/Issue/IssueSidebar.vue+++ b/frontend/src/components/Issue/IssueSidebar.vue@@ -33,13 +33,13 @@:allowed-role-list="['OWNER', 'DBA']"@select-principal-id="(principalId: number) => {- $emit('update-assignee-id', principalId);+ updateAssigneeId(principalId)}"/></div>- <template v-for="(field, index) in inputFieldList" :key="index">+ <template v-for="(field, index) in template.inputFieldList" :key="index"><h2 class="textlabel flex items-center col-span-1 col-start-1">{{ field.name }}<span v-if="field.required" class="text-red-600">*</span>@@ -78,9 +78,9 @@</h2><div class="col-span-2"><StageSelect- :pipeline="(issue.pipeline as Pipeline)"+ :pipeline="(issue as Issue).pipeline":selected-id="(selectedStage as Stage).id"- @select-stage-id="(stageId) => $emit('select-stage-id', stageId)"+ @select-stage-id="(stageId) => selectStageOrTask(stageId)"/></div></template>@@ -91,15 +91,15 @@</h2><div class="col-span-2"><TaskSelect- :pipeline="(issue.pipeline as Pipeline)"+ :pipeline="(issue as Issue).pipeline":stage="(selectedStage as Stage)"- :selected-id="(task as Task).id"- @select-task-id="(taskId) => $emit('select-task-id', taskId)"+ :selected-id="(selectedTask as Task).id"+ @select-task-id="(taskId) => selectTaskId(taskId)"/></div></template>- <template v-if="!isTenantDeployMode">+ <template v-if="!isTenantMode"><!--earliest-allowed-time is disabled in tenant mode for nowwe will provide more powerful deployment schedule in deployment config@@ -140,9 +140,9 @@}}</span><span class="textfield col-span-2 text-sm font-medium text-main">{{- task.earliestAllowedTs === 0+ selectedTask.earliestAllowedTs === 0? $t("task.earliest-allowed-time-unset")- : dayjs(task.earliestAllowedTs * 1000).format("LLL")+ : dayjs(selectedTask.earliestAllowedTs * 1000).format("LLL")}}</span></div>@@ -257,12 +257,8 @@<IssueSubscriberPanelv-if="!create":issue="(issue as Issue)"- @add-subscriber-id="- (subscriberId) => $emit('add-subscriber-id', subscriberId)- "- @remove-subscriber-id="- (subscriberId) => $emit('remove-subscriber-id', subscriberId)- "+ @add-subscriber-id="(subscriberId) => addSubscriberId(subscriberId)"+ @remove-subscriber-id="(subscriberId) => removeSubscriberId(subscriberId)"/><FeatureModalv-if="state.showFeatureModal"@@ -294,17 +290,13 @@ import type {Project,Issue,IssueCreate,- Pipeline,Task,- TaskCreate,TaskId,Stage,StageCreate,- StageId,Instance,TaskDatabaseCreatePayload,DatabaseLabel,- PrincipalId,} from "@/types";import { ONBOARDING_ISSUE_ID } from "@/types";import {@@ -313,6 +305,7 @@ import {isDBAOrOwner,isReservedDatabaseLabel,hidePrefix,+ taskSlug,} from "@/utils";import {hasFeature,@@ -322,6 +315,7 @@ import {useLabelList,useProjectStore,} from "@/store";+import { useExtraIssueLogic, useIssueLogic } from "./logic";dayjs.extend(isSameOrAfter);@@ -331,37 +325,9 @@ interface LocalState {}const props = defineProps({- issue: {- required: true,- type: Object as PropType<Issue | IssueCreate>,- },- task: {- required: true,- type: Object as PropType<Task | TaskCreate>,- },- create: {- required: true,- type: Boolean,- },- selectedStage: {- required: true,- type: Object as PropType<Stage | StageCreate>,- },- inputFieldList: {- required: true,- type: Object as PropType<InputField[]>,- },- allowEdit: {- required: true,- type: Boolean,- },- isTenantDeployMode: {- type: Boolean,- default: false,- },database: {- required: true,type: Object as PropType<Database | undefined>,+ default: undefined,},instance: {required: true,@@ -369,37 +335,58 @@ const props = defineProps({},});-const emit = defineEmits<{- (e: "update-assignee-id", assigneeId: PrincipalId): void;- (e: "update-earliest-allowed-time", newTs: number): void;- (e: "add-subscriber-id", subscriberId: PrincipalId): void;- (e: "remove-subscriber-id", subscriberId: PrincipalId): void;- (e: "update-custom-field", field: InputField, value: any): void;- (e: "select-stage-id", stageId: StageId): void;- (e: "select-task-id", taskId: TaskId): void;-}>();-const router = useRouter();const projectStore = useProjectStore();+const {+ create,+ issue,+ template,+ isTenantMode,+ selectedStage,+ selectedTask,+ selectStageOrTask,+} = useIssueLogic();+const {+ updateEarliestAllowedTime,+ updateAssigneeId,+ updateCustomField,+ addSubscriberId,+ removeSubscriberId,+} = useExtraIssueLogic();++const allowEdit = computed(() => {+ if (create.value) {+ return true;+ }+ // For now, we only allow assignee to update the field when the issue+ // is 'OPEN'. This reduces flexibility as creator must ask assignee to+ // change any fields if there is typo. On the other hand, this avoids+ // the trouble that the creator changes field value when the creator+ // is performing the issue based on the old value.+ // For now, we choose to be on the safe side at the cost of flexibility.+ const issueEntity = issue.value as Issue;+ return (+ issueEntity.status == "OPEN" &&+ issueEntity.assignee?.id == currentUser.value.id+ );+});+const now = new Date();const state = reactive<LocalState>({- earliestAllowedTs: props.task.earliestAllowedTs,+ earliestAllowedTs: selectedTask.value.earliestAllowedTs,showFeatureModal: false,});-watch(- () => props.task,- (cur) => {- // we show user local time- state.earliestAllowedTs = cur.earliestAllowedTs;- }-);+watch(selectedTask, (cur) => {+ // we show user local time+ state.earliestAllowedTs = cur.earliestAllowedTs;+});const currentUser = useCurrentUser();const fieldValue = <T = string>(field: InputField): T => {- return props.issue.payload[field.id] as T;+ return issue.value.payload[field.id] as T;};const databaseName = computed((): string | undefined => {@@ -407,13 +394,13 @@ const databaseName = computed((): string | undefined => {return props.database.name;}- const stage = props.selectedStage as Stage;+ const stage = selectedStage.value as Stage;if (stage.taskList[0].type == "bb.task.database.create" ||stage.taskList[0].type == "bb.task.database.restore") {- if (props.create) {- const stage = props.selectedStage as StageCreate;+ if (create.value) {+ const stage = selectedStage.value as StageCreate;return stage.taskList[0].databaseName;}return ((stage.taskList[0] as Task).payload as TaskDatabaseCreatePayload)@@ -423,19 +410,19 @@ const databaseName = computed((): string | undefined => {});const environment = computed((): Environment => {- if (props.create) {- const stage = props.selectedStage as StageCreate;+ if (create.value) {+ const stage = selectedStage.value as StageCreate;return useEnvironmentStore().getEnvironmentById(stage.environmentId);}- const stage = props.selectedStage as Stage;+ const stage = selectedStage.value as Stage;return stage.environment;});const project = computed((): Project => {- if (props.create) {- return projectStore.getProjectById((props.issue as IssueCreate).projectId);+ if (create.value) {+ return projectStore.getProjectById((issue.value as IssueCreate).projectId);}- return (props.issue as Issue).project;+ return (issue.value as Issue).project;});const labelList = useLabelList();@@ -452,13 +439,15 @@ const visibleLabelList = computed((): DatabaseLabel[] => {const showStageSelect = computed((): boolean => {return (- !props.create && allTaskList((props.issue as Issue).pipeline).length > 1+ !create.value && allTaskList((issue.value as Issue).pipeline).length > 1);});const showTaskSelect = computed((): boolean => {- if (props.create) return false;- const { taskList } = props.selectedStage;+ if (create.value) {+ return false;+ }+ const { taskList } = selectedStage.value;return taskList.length > 1;});@@ -467,47 +456,51 @@ const showInstance = computed((): boolean => {});const allowEditAssignee = computed(() => {- const issue = props.issue as Issue;+ if (create.value) {+ return true;+ }// We allow the current assignee or DBA to re-assign the issue.// Though only DBA can be assigned to the issue, the current// assignee might not have DBA role in case its role is revoked after// being assigned to the issue.+ const issueEntity = issue.value as Issue;return (- props.create ||- (issue.id != ONBOARDING_ISSUE_ID &&- issue.status == "OPEN" &&- (currentUser.value.id == issue.assignee?.id ||- isDBAOrOwner(currentUser.value.role)))+ issueEntity.id !== ONBOARDING_ISSUE_ID &&+ issueEntity.status == "OPEN" &&+ (currentUser.value.id == issueEntity.assignee.id ||+ isDBAOrOwner(currentUser.value.role)));});const allowEditEarliestAllowedTime = computed(() => {- const issue = props.issue as Issue;- const task = props.task as Task;+ if (create.value) {+ return true;+ }// only the assignee is allowed to modify EarliestAllowedTime+ const issueEntity = issue.value as Issue;+ const task = selectedTask.value as Task;return (- props.create ||- (issue.id != ONBOARDING_ISSUE_ID &&- issue.status == "OPEN" &&- (task.status == "PENDING" || task.status == "PENDING_APPROVAL") &&- currentUser.value.id == issue.assignee?.id)+ issueEntity.id != ONBOARDING_ISSUE_ID &&+ issueEntity.status == "OPEN" &&+ (task.status == "PENDING" || task.status == "PENDING_APPROVAL") &&+ currentUser.value.id == issueEntity.assignee.id);});const allowEditCustomField = (field: InputField) => {- return props.allowEdit && (props.create || field.allowEditAfterCreation);+ return allowEdit.value && (create.value || field.allowEditAfterCreation);};const trySaveCustomField = (field: InputField, value: string | boolean) => {if (!isEqual(value, fieldValue(field))) {- emit("update-custom-field", field, value);+ updateCustomField(field, value);}};const isDatabaseCreated = computed(() => {- const stage = props.selectedStage as Stage;+ const stage = selectedStage.value as Stage;if (stage.taskList[0].type == "bb.task.database.create") {- if (props.create) {+ if (create.value) {return false;}return stage.taskList[0].status == "DONE";@@ -517,8 +510,8 @@ const isDatabaseCreated = computed(() => {// We only show creation label for database create taskconst showDatabaseCreationLabel = computed(() => {- const stage = props.selectedStage as Stage;- if (stage.taskList[0].type != "bb.task.database.create") {+ const stage = selectedStage.value as Stage;+ if (stage.taskList[0].type !== "bb.task.database.create") {return "";}return isDatabaseCreated.value ? "(created)" : "(pending create)";@@ -562,6 +555,15 @@ const updateEarliestAllowedTs = (newTimestampMS: number) => {// We divide it by 1000 to get timestamp in secondconst newTs = newTimestampMS / 1000;state.earliestAllowedTs = newTs;- emit("update-earliest-allowed-time", newTs);+ updateEarliestAllowedTime(newTs);+};++const selectTaskId = (taskId: TaskId) => {+ const taskList = (selectedStage.value as Stage).taskList;+ const task = taskList.find((t) => t.id === taskId);+ if (!task) return;+ const slug = taskSlug(task.name, task.id);+ const stage = selectedStage.value as Stage;+ selectStageOrTask(stage.id, slug);};</script>diff --git a/frontend/src/components/Issue/IssueStagePanel.vue b/frontend/src/components/Issue/IssueStagePanel.vueindex 4aee55f880..25fa50102d 100644--- a/frontend/src/components/Issue/IssueStagePanel.vue+++ b/frontend/src/components/Issue/IssueStagePanel.vue@@ -1,7 +1,7 @@<template><div class="space-y-4"><template v-if="mode === 'single'">- <TaskRunTable :task-list="[selectedTask || stage.taskList[0]]" />+ <TaskRunTable :task-list="[task || stage.taskList[0]]" /></template><template v-else-if="mode === 'merged'"><TaskRunTable :task-list="stage.taskList" />@@ -26,55 +26,36 @@</div></template>-<script lang="ts">-import { PropType, computed, defineComponent } from "vue";+<script lang="ts" setup>+import { computed, Ref } from "vue";import TaskRunTable from "./TaskRunTable.vue";-import { Stage, Task } from "../../types";-import { activeTaskInStage } from "../../utils";+import { Stage, Task } from "@/types";+import { useIssueLogic } from "./logic";type Mode = "normal" | "single" | "merged";-export default defineComponent({- name: "IssueStagePanel",- components: { TaskRunTable },- props: {- stage: {- required: true,- type: Object as PropType<Stage>,- },- selectedTask: {- type: Object as PropType<Task>,- default: undefined,- },- isTenantMode: {- type: Boolean,- default: false,- },- isGhostMode: {- type: Boolean,- default: false,- },- },- setup(props) {- const activeTask = computed((): Task => {- return activeTaskInStage(props.stage);- });+const {+ selectedStage,+ selectedTask,+ isGhostMode,+ isTenantMode,+ activeTaskOfStage,+} = useIssueLogic();+const stage = selectedStage as Ref<Stage>;+const task = selectedTask as Ref<Task>;- /**- * normal mode: display multiple tables for each task in stage.taskList- * merged mode: merge all tasks' activities into one table- * single mode: show only selected task's activities- */- const mode = computed((): Mode => {- if (props.isGhostMode) return "merged";- if (props.isTenantMode) return "single";- return "normal";- });+const activeTask = computed((): Task => {+ return activeTaskOfStage(stage.value);+});- return {- activeTask,- mode,- };- },+/**+ * normal mode: display multiple tables for each task in stage.taskList+ * merged mode: merge all tasks' activities into one table+ * single mode: show only selected task's activities+ */+const mode = computed((): Mode => {+ if (isGhostMode.value) return "merged";+ if (isTenantMode.value) return "single";+ return "normal";});</script>diff --git a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vueindex 49bbcb5b9f..44ce2c435c 100644--- a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue+++ b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue@@ -140,6 +140,7 @@ import {flattenTaskList,IssueTypeWithStatement,TaskTypeWithStatement,+ useExtraIssueLogic,useIssueLogic,} from "./logic";@@ -159,8 +160,6 @@ interface UpdateStatusModalState {payload?: Task;}-const emit = defineEmits(["change-issue-status", "change-task-status"]);-const { t } = useI18n();const menu = ref<InstanceType<typeof BBContextMenu>>();@@ -171,6 +170,7 @@ const {activeTaskOfPipeline,doCreate,} = useIssueLogic();+const { changeIssueStatus, changeTaskStatus } = useExtraIssueLogic();const updateStatusModalState = reactive<UpdateStatusModalState>({mode: "ISSUE",@@ -255,7 +255,7 @@ const doTaskStatusTransition = (task: Task,comment: string) => {- emit("change-task-status", task, transition.to, comment);+ changeTaskStatus(task, transition.to, comment);};const applicableIssueStatusTransitionList = computed(@@ -358,7 +358,7 @@ const doIssueStatusTransition = (transition: IssueStatusTransition,comment: string) => {- emit("change-issue-status", transition.to, comment);+ changeIssueStatus(transition.to, comment);};const allowCreate = computed(() => {diff --git a/frontend/src/components/Issue/logic/IssueLogic.ts b/frontend/src/components/Issue/logic/IssueLogic.tsindex 4a3c136e15..e87be09685 100644--- a/frontend/src/components/Issue/logic/IssueLogic.ts+++ b/frontend/src/components/Issue/logic/IssueLogic.ts@@ -59,10 +59,12 @@ type IssueLogic = {doCreate(): any;// events+ onStatusChanged: (eager: boolean) => void;selectStageOrTask: (stageIdOrIndex: number,taskSlug?: string | undefined) => void;+ selectTask: (task: Task) => void;};export default IssueLogic;diff --git a/frontend/src/components/Issue/logic/base.ts b/frontend/src/components/Issue/logic/base.tsnew file mode 100644index 0000000000..2e61df478e--- /dev/null+++ b/frontend/src/components/Issue/logic/base.ts@@ -0,0 +1,196 @@+import { computed, Ref } from "vue";+import { isEmpty } from "lodash-es";+import {+ Issue,+ IssueCreate,+ Project,+ Stage,+ StageCreate,+ StageId,+ Task,+ TaskCreate,+} from "@/types";+import { useRoute, useRouter } from "vue-router";+import {+ activeStage,+ activeTaskInStage,+ idFromSlug,+ indexFromSlug,+ isDev,+ issueSlug,+ stageSlug,+ taskSlug,+} from "@/utils";+import { useIssueStore, useProjectStore } from "@/store";+import { TaskTypeWithStatement } from "./common";++export const useBaseIssueLogic = (params: {+ create: Ref<boolean>;+ issue: Ref<Issue | IssueCreate>;+}) => {+ const { create, issue } = params;+ const route = useRoute();+ const router = useRouter();+ const issueStore = useIssueStore();+ const projectStore = useProjectStore();++ const project = computed((): Project => {+ if (create.value) {+ return projectStore.getProjectById(+ (issue.value as IssueCreate).projectId+ );+ }+ return (issue.value as Issue).project;+ });++ const createIssue = (issue: IssueCreate) => {+ // Set issue.pipeline and issue.payload to empty+ // because we are no longer passing parameters via issue.pipeline+ // we are using issue.createContext instead+ delete issue.pipeline;+ issue.payload = {};++ issueStore.createIssue(issue).then((createdIssue) => {+ // Use replace to omit the new issue url in the navigation history.+ router.replace(`/issue/${issueSlug(createdIssue.name, createdIssue.id)}`);+ });+ };++ const selectedStage = computed((): Stage | StageCreate => {+ const stageSlug = router.currentRoute.value.query.stage as string;+ const taskSlug = router.currentRoute.value.query.task as string;+ // For stage slug, we support both index based and id based.+ // Index based is used when creating the new task and is the one used when clicking the UI.+ // Id based is used when the context only has access to the stage id (e.g. Task only contains StageId)+ if (stageSlug) {+ const index = indexFromSlug(stageSlug);+ if (index < issue.value.pipeline!.stageList.length) {+ return issue.value.pipeline!.stageList[index];+ }+ const stageId = idFromSlug(stageSlug);+ const stageList = (issue.value as Issue).pipeline.stageList;+ for (const stage of stageList) {+ if (stage.id == stageId) {+ return stage;+ }+ }+ } else if (!create.value && taskSlug) {+ const taskId = idFromSlug(taskSlug);+ const stageList = (issue.value as Issue).pipeline.stageList;+ for (const stage of stageList) {+ for (const task of stage.taskList) {+ if (task.id == taskId) {+ return stage;+ }+ }+ }+ }+ if (create.value) {+ return issue.value.pipeline!.stageList[0];+ }+ return activeStage((issue.value as Issue).pipeline);+ });++ const selectStageOrTask = (+ stageId: StageId,+ taskSlug: string | undefined = undefined+ ) => {+ const stageList = issue.value.pipeline!.stageList;+ const index = stageList.findIndex((item, index) => {+ if (create.value) {+ return index === stageId;+ }+ return (item as Stage).id == stageId;+ });+ router.replace({+ name: "workspace.issue.detail",+ query: {+ ...router.currentRoute.value.query,+ stage: stageSlug(stageList[index].name, index),+ task: taskSlug,+ },+ });+ };++ const selectTask = (task: Task) => {+ if (!create.value) return;++ const stage = (issue.value as Issue).pipeline?.stageList.find(+ (t) => t.id === task.id+ );+ if (!stage) {+ return;+ }+ const slug = taskSlug(task.name, task.id);+ selectStageOrTask(stage.id, slug);+ };++ const selectedTask = computed((): Task | TaskCreate => {+ const taskSlug = route.query.task as string;+ const { taskList } = selectedStage.value;+ if (taskSlug) {+ const index = indexFromSlug(taskSlug);+ if (index < taskList.length) {+ return taskList[index];+ }+ const id = idFromSlug(taskSlug);+ for (let i = 0; i < taskList.length; i++) {+ const task = taskList[i] as Task;+ if (task.id === id) {+ return task;+ }+ }+ }+ return taskList[0];+ });++ const isTenantMode = computed((): boolean => {+ if (project.value.tenantMode !== "TENANT") return false;+ return (+ issue.value.type === "bb.issue.database.schema.update" ||+ issue.value.type === "bb.issue.database.data.update"+ );+ });++ const isGhostMode = computed((): boolean => {+ if (!isDev()) return false;++ return issue.value.type === "bb.issue.database.schema.update.ghost";+ });++ const taskStatusOfStage = (stage: Stage | StageCreate) => {+ if (create.value) {+ return stage.taskList[0].status;+ }+ const activeTask = activeTaskInStage(stage as Stage);+ return activeTask.status;+ };++ const isValidStage = (stage: Stage | StageCreate) => {+ if (!create.value) {+ return true;+ }++ for (const task of stage.taskList) {+ if (TaskTypeWithStatement.includes(task.type)) {+ if (isEmpty((task as TaskCreate).statement)) {+ return false;+ }+ }+ }+ return true;+ };++ return {+ project,+ isTenantMode,+ isGhostMode,+ createIssue,+ selectedStage,+ selectedTask,+ selectStageOrTask,+ selectTask,+ taskStatusOfStage,+ isValidStage,+ };+};diff --git a/frontend/src/components/Issue/logic/common.ts b/frontend/src/components/Issue/logic/common.tsindex b25e9e8928..d2ccd235d6 100644--- a/frontend/src/components/Issue/logic/common.ts+++ b/frontend/src/components/Issue/logic/common.ts@@ -1,11 +1,18 @@import { computed } from "vue";import { cloneDeep } from "lodash-es";import formatSQL from "@/components/MonacoEditor/sqlFormatter";-import { useCurrentUser, useDatabaseStore, useUIStateStore } from "@/store";+import {+ useCurrentUser,+ useDatabaseStore,+ useIssueStore,+ useTaskStore,+ useUIStateStore,+} from "@/store";import {Database,Issue,IssueCreate,+ IssuePatch,IssueType,SQLDialect,Task,@@ -14,6 +21,8 @@ import {TaskDatabaseDataUpdatePayload,TaskDatabaseSchemaUpdatePayload,TaskGeneralPayload,+ TaskId,+ TaskPatch,TaskType,UpdateSchemaDetail,} from "@/types";@@ -21,10 +30,53 @@ import { useIssueLogic } from "./index";import { isDev } from "@/utils";export const useCommonLogic = () => {- const { create, issue, selectedTask, patchTask, createIssue } =+ const { create, issue, selectedTask, createIssue, onStatusChanged } =useIssueLogic();const currentUser = useCurrentUser();const databaseStore = useDatabaseStore();+ const issueStore = useIssueStore();+ const taskStore = useTaskStore();++ const patchIssue = (+ issuePatch: IssuePatch,+ postUpdated?: (updatedIssue: Issue) => void+ ) => {+ issueStore+ .patchIssue({+ issueId: (issue.value as Issue).id,+ issuePatch,+ })+ .then((updatedIssue) => {+ // issue/patchIssue already fetches the new issue, so we schedule+ // the next poll in NORMAL_POLL_INTERVAL+ onStatusChanged(false);+ if (postUpdated) {+ postUpdated(updatedIssue);+ }+ });+ };++ const patchTask = (+ taskId: TaskId,+ taskPatch: TaskPatch,+ postUpdated?: (updatedTask: Task) => void+ ) => {+ taskStore+ .patchTask({+ issueId: (issue.value as Issue).id,+ pipelineId: (issue.value as Issue).pipeline.id,+ taskId,+ taskPatch,+ })+ .then((updatedTask) => {+ // For now, the only task/patchTask is to change statement, which will trigger async task check.+ // Thus we use the short poll interval+ onStatusChanged(true);+ if (postUpdated) {+ postUpdated(updatedTask);+ }+ });+ };const allowEditStatement = computed(() => {// if creating an issue, it's editable@@ -148,6 +200,7 @@ export const useCommonLogic = () => {};return {+ patchIssue,patchTask,allowEditStatement,selectedStatement,diff --git a/frontend/src/components/Issue/logic/extra.ts b/frontend/src/components/Issue/logic/extra.tsnew file mode 100644index 0000000000..c72ae5a84d--- /dev/null+++ b/frontend/src/components/Issue/logic/extra.ts@@ -0,0 +1,227 @@+import { cloneDeep, isEqual } from "lodash-es";+import { InputField, OutputField } from "@/plugins";+import {+ useCurrentUser,+ useIssueStore,+ useIssueSubscriberStore,+ useTaskStore,+} from "@/store";+import {+ Issue,+ IssueCreate,+ IssueStatus,+ IssueStatusPatch,+ PrincipalId,+ Task,+ TaskCreate,+ TaskPatch,+ TaskStatus,+ TaskStatusPatch,+} from "@/types";+import { useIssueLogic } from "./index";+import { computed, nextTick } from "vue";++export const useExtraIssueLogic = () => {+ const {+ create,+ issue,+ isGhostMode,+ selectedStage,+ selectedTask,+ selectStageOrTask,+ selectTask,+ onStatusChanged,+ patchIssue,+ patchTask,+ } = useIssueLogic();+ const issueStore = useIssueStore();+ const issueSubscriberStore = useIssueSubscriberStore();+ const taskStore = useTaskStore();+ const currentUser = useCurrentUser();++ const allowEditOutput = computed(() => {+ if (create.value) {+ return true;+ }++ const issueEntity = issue.value as Issue;+ return (+ issueEntity.status == "OPEN" &&+ issueEntity.assignee?.id == currentUser.value.id+ );+ });++ const allowEditNameAndDescription = computed(() => {+ if (create.value) {+ return true;+ }++ const issueEntity = issue.value as Issue;+ return (+ issueEntity.status == "OPEN" &&+ (issueEntity.assignee.id == currentUser.value.id ||+ issueEntity.creator.id == currentUser.value.id)+ );+ });++ const updateName = (+ newName: string,+ postUpdated?: (updatedIssue: Issue) => void+ ) => {+ if (create.value) {+ issue.value.name = newName;+ } else {+ patchIssue(+ {+ name: newName,+ },+ postUpdated+ );+ }+ };++ const updateDescription = (+ newDescription: string,+ postUpdated?: (updatedIssue: Issue) => void+ ) => {+ if (create.value) {+ issue.value.description = newDescription;+ } else {+ patchIssue(+ {+ description: newDescription,+ },+ postUpdated+ );+ }+ };++ const updateAssigneeId = (newAssigneeId: PrincipalId) => {+ if (create.value) {+ (issue.value as IssueCreate).assigneeId = newAssigneeId;+ } else {+ patchIssue({+ assigneeId: newAssigneeId,+ });+ }+ };++ const updateEarliestAllowedTime = (newEarliestAllowedTsMs: number) => {+ if (create.value) {+ if (isGhostMode.value) {+ // In gh-ost mode, when creating an issue, all sub-tasks in a stage+ // share the same earliestAllowedTs.+ // So updates on any one of them will be applied to others.+ // (They can be updated independently after creation)+ const taskList = selectedStage.value.taskList as TaskCreate[];+ taskList.forEach((task) => {+ task.earliestAllowedTs = newEarliestAllowedTsMs;+ });+ } else {+ selectedTask.value.earliestAllowedTs = newEarliestAllowedTsMs;+ }+ } else {+ const taskPatch: TaskPatch = {+ earliestAllowedTs: newEarliestAllowedTsMs,+ };+ patchTask((selectedTask.value as Task).id, taskPatch);+ }+ };++ const addSubscriberId = (subscriberId: PrincipalId) => {+ issueSubscriberStore.createSubscriber({+ issueId: (issue.value as Issue).id,+ subscriberId,+ });+ };++ const removeSubscriberId = (subscriberId: PrincipalId) => {+ issueSubscriberStore.deleteSubscriber({+ issueId: (issue.value as Issue).id,+ subscriberId,+ });+ };++ const updateCustomField = (field: InputField | OutputField, value: any) => {+ if (!isEqual(issue.value.payload[field.id], value)) {+ if (create.value) {+ issue.value.payload[field.id] = value;+ } else {+ const newPayload = cloneDeep(issue.value.payload);+ newPayload[field.id] = value;+ patchIssue({+ payload: newPayload,+ });+ }+ }+ };++ const changeIssueStatus = (newStatus: IssueStatus, comment: string) => {+ const issueStatusPatch: IssueStatusPatch = {+ status: newStatus,+ comment: comment,+ };+ issueStore+ .updateIssueStatus({+ issueId: (issue.value as Issue).id,+ issueStatusPatch,+ })+ .then(() => {+ // pollIssue(POST_CHANGE_POLL_INTERVAL);+ });+ };++ const changeTaskStatus = (+ task: Task,+ newStatus: TaskStatus,+ comment: string+ ) => {+ // Switch to the stage view containing this task+ selectStageOrTask(task.stage.id);+ nextTick().then(() => {+ selectTask(task);+ });++ const taskStatusPatch: TaskStatusPatch = {+ status: newStatus,+ comment: comment,+ };+ taskStore+ .updateStatus({+ issueId: (issue.value as Issue).id,+ pipelineId: (issue.value as Issue).pipeline.id,+ taskId: task.id,+ taskStatusPatch,+ })+ .then(() => {+ onStatusChanged(true);+ });+ };++ const runTaskChecks = (task: Task) => {+ taskStore+ .runChecks({+ issueId: (issue.value as Issue).id,+ pipelineId: (issue.value as Issue).pipeline.id,+ taskId: task.id,+ })+ .then(() => {+ onStatusChanged(true);+ });+ };++ return {+ allowEditOutput,+ allowEditNameAndDescription,+ updateName,+ updateDescription,+ updateAssigneeId,+ updateEarliestAllowedTime,+ addSubscriberId,+ removeSubscriberId,+ updateCustomField,+ changeIssueStatus,+ changeTaskStatus,+ runTaskChecks,+ };+};diff --git a/frontend/src/components/Issue/logic/index.ts b/frontend/src/components/Issue/logic/index.tsindex d6a503e340..86512b1507 100644--- a/frontend/src/components/Issue/logic/index.ts+++ b/frontend/src/components/Issue/logic/index.ts@@ -4,7 +4,9 @@ import TenantModeProvider from "./TenantModeProvider";import GhostModeProvider from "./GhostModeProvider";import StandardModeProvider from "./StandardModeProvider";+export * from "./base";export * from "./common";+export * from "./extra";export {IssueLogic,