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: use issue comments instead of activities (#11593)
boojack5ab7892cb0af
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.goindex de821977ae..5aad643f66 100644--- a/backend/api/v1/issue_service.go+++ b/backend/api/v1/issue_service.go@@ -935,6 +935,7 @@ func (s *IssueService) ApproveIssue(ctx context.Context, request *v1pb.ApproveIsif err := func() error {p := &storepb.IssueCommentPayload{+ Comment: request.Comment,Event: &storepb.IssueCommentPayload_Approval_{Approval: &storepb.IssueCommentPayload_Approval{Status: storepb.IssueCommentPayload_Approval_APPROVED,@@ -1199,6 +1200,7 @@ func (s *IssueService) RejectIssue(ctx context.Context, request *v1pb.RejectIssuif err := func() error {p := &storepb.IssueCommentPayload{+ Comment: request.Comment,Event: &storepb.IssueCommentPayload_Approval_{Approval: &storepb.IssueCommentPayload_Approval{Status: storepb.IssueCommentPayload_Approval_REJECTED,@@ -1315,6 +1317,7 @@ func (s *IssueService) RequestIssue(ctx context.Context, request *v1pb.RequestIsif err := func() error {p := &storepb.IssueCommentPayload{+ Comment: request.Comment,Event: &storepb.IssueCommentPayload_Approval_{Approval: &storepb.IssueCommentPayload_Approval{Status: storepb.IssueCommentPayload_Approval_PENDING,@@ -1924,13 +1927,11 @@ func (s *IssueService) UpdateIssueComment(ctx context.Context, request *v1pb.Updif err != nil {return nil, err}-- activityUID, err := strconv.Atoi(request.IssueComment.Uid)+ issueCommentUID, err := strconv.Atoi(request.IssueComment.Uid)if err != nil {return nil, status.Errorf(codes.InvalidArgument, "invalid comment id %q: %v", request.IssueComment.Uid, err)}-- issueComment, err := s.store.GetActivityV2(ctx, activityUID)+ issueComment, err := s.store.GetIssueComment(ctx, &store.FindIssueCommentMessage{UID: &issueCommentUID})if err != nil {return nil, status.Errorf(codes.Internal, "failed to get issue comment: %v", err)}@@ -1944,7 +1945,7 @@ func (s *IssueService) UpdateIssueComment(ctx context.Context, request *v1pb.Upd}ok, err = func() (bool, error) {- if issueComment.CreatorUID == user.ID {+ if issueComment.Creator.ID == user.ID {return true, nil}return s.iamManager.CheckPermission(ctx, iam.PermissionIssueCommentsUpdate, user, issue.Project.ResourceID)@@ -1956,10 +1957,10 @@ func (s *IssueService) UpdateIssueComment(ctx context.Context, request *v1pb.Updreturn nil, status.Errorf(codes.PermissionDenied, "permission denied, user does not have permission %q", iam.PermissionIssueCommentsUpdate)}- update := &store.UpdateActivityMessage{- UID: activityUID,+ update := &store.UpdateIssueCommentMessage{+ UID: issueCommentUID,+ UpdaterID: user.ID,}-for _, path := range request.UpdateMask.Paths {switch path {case "comment":@@ -1969,21 +1970,18 @@ func (s *IssueService) UpdateIssueComment(ctx context.Context, request *v1pb.Upd}}- activity, err := s.store.UpdateActivityV2(ctx, update)- if err != nil {+ if err := s.store.UpdateIssueComment(ctx, update); err != nil {if common.ErrorCode(err) == common.NotFound {return nil, status.Errorf(codes.NotFound, "cannot found the issue comment %s", request.IssueComment.Uid)}return nil, status.Errorf(codes.Internal, "failed to update the issue comment with error: %v", err.Error())}+ issueComment, err = s.store.GetIssueComment(ctx, &store.FindIssueCommentMessage{UID: &issueCommentUID})+ if err != nil {+ return nil, status.Errorf(codes.Internal, "failed to get issue comment: %v", err)+ }- return &v1pb.IssueComment{- Uid: fmt.Sprintf("%d", activity.UID),- Comment: activity.Comment,- Payload: activity.Payload,- CreateTime: timestamppb.New(time.Unix(activity.CreatedTs, 0)),- UpdateTime: timestamppb.New(time.Unix(activity.UpdatedTs, 0)),- }, nil+ return convertToIssueComment(request.Parent, issueComment), nil}func (s *IssueService) getIssueMessage(ctx context.Context, name string) (*store.IssueMessage, error) {diff --git a/backend/store/issue_comment.go b/backend/store/issue_comment.goindex 4a02f8528c..01c1f420e4 100644--- a/backend/store/issue_comment.go+++ b/backend/store/issue_comment.go@@ -9,7 +9,6 @@ import ("github.com/pkg/errors""google.golang.org/protobuf/encoding/protojson"- "github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/proto/generated-go/store")@@ -26,15 +25,41 @@ type IssueCommentMessage struct {}type FindIssueCommentMessage struct {+ UID *intIssueUID *intLimit *intOffset *int}+type UpdateIssueCommentMessage struct {+ UID int+ UpdaterID int++ Comment *string+}++func (s *Store) GetIssueComment(ctx context.Context, find *FindIssueCommentMessage) (*IssueCommentMessage, error) {+ list, err := s.ListIssueComment(ctx, find)+ if err != nil {+ return nil, err+ }+ if len(list) == 0 {+ return nil, nil+ }+ if len(list) > 1 {+ return nil, errors.Errorf("found %d issue comment, expected 1", len(list))+ }+ return list[0], nil+}+func (s *Store) ListIssueComment(ctx context.Context, find *FindIssueCommentMessage) ([]*IssueCommentMessage, error) {where := []string{"TRUE"}args := []any{}+ if v := find.UID; v != nil {+ where = append(where, fmt.Sprintf("id = $%d", len(args)+1))+ args = append(args, *v)+ }if v := find.IssueUID; v != nil {where = append(where, fmt.Sprintf("issue_id = $%d", len(args)+1))args = append(args, *v)@@ -107,9 +132,6 @@ func (s *Store) ListIssueComment(ctx context.Context, find *FindIssueCommentMess}func (s *Store) CreateIssueCommentTaskUpdateStatus(ctx context.Context, issueUID int, tasks []string, status storepb.IssueCommentPayload_TaskUpdate_Status, creatorUID int) error {- if s.db.mode == common.ReleaseModeProd {- return nil- }create := &IssueCommentMessage{IssueUID: issueUID,Payload: &storepb.IssueCommentPayload{@@ -126,9 +148,6 @@ func (s *Store) CreateIssueCommentTaskUpdateStatus(ctx context.Context, issueUID}func (s *Store) CreateIssueComment(ctx context.Context, create *IssueCommentMessage, creatorUID int) error {- if s.db.mode == common.ReleaseModeProd {- return nil- }query := `INSERT INTO issue_comment (creator_id,@@ -155,19 +174,15 @@ func (s *Store) CreateIssueComment(ctx context.Context, create *IssueCommentMessreturn nil}-func (s *Store) UpdateIssueComment(ctx context.Context, comment string, uid int, updaterUID int) error {- if s.db.mode == common.ReleaseModeProd {- return nil+func (s *Store) UpdateIssueComment(ctx context.Context, patch *UpdateIssueCommentMessage) error {+ set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{patch.UpdaterID, time.Now().Unix()}++ if v := patch.Comment; v != nil {+ set, args = append(set, fmt.Sprintf("payload = payload || jsonb_build_object('comment',$%d::TEXT)", len(args)+1)), append(args, *v)}- query := `- UPDATE issue_comment- SET- updater_id = $1,- updated_ts = $2- payload = payload || jsonb_build_object('comment', $3)- WHERE id = $4- `- if _, err := s.db.db.ExecContext(ctx, query, updaterUID, time.Now().Unix(), comment, uid); err != nil {+ args = append(args, patch.UID)+ query := `UPDATE issue_comment SET ` + strings.Join(set, ", ") + fmt.Sprintf(` WHERE id = $%d`, len(args))+ if _, err := s.db.db.ExecContext(ctx, query, args...); err != nil {return errors.Wrapf(err, "failed to update issue comment")}return nildiff --git a/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue b/frontend/src/components/IssueV1/DataExportIssueDetailPage.vueindex ae89ab792a..6a5c74954a 100644--- a/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue+++ b/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue@@ -16,7 +16,7 @@<PlanCheckSection v-if="!isCreating" /><StatementSection /><DescriptionSection />- <ActivitySection v-if="!isCreating" />+ <IssueCommentSection v-if="!isCreating" /></div><div@@ -77,7 +77,7 @@ import {PlanCheckSection,StatementSection,DescriptionSection,- ActivitySection,+ IssueCommentSection,Sidebar,IssueReviewActionPanel,IssueStatusActionPanel,diff --git a/frontend/src/components/IssueV1/GrantRequestIssueDetailPage.vue b/frontend/src/components/IssueV1/GrantRequestIssueDetailPage.vueindex 775f71f325..16e8784280 100644--- a/frontend/src/components/IssueV1/GrantRequestIssueDetailPage.vue+++ b/frontend/src/components/IssueV1/GrantRequestIssueDetailPage.vue@@ -19,7 +19,7 @@<DescriptionSection />- <ActivitySection v-if="!isCreating" />+ <IssueCommentSection v-if="!isCreating" /></div><div@@ -72,7 +72,7 @@ import {BannerSection,HeaderSection,DescriptionSection,- ActivitySection,+ IssueCommentSection,IssueReviewActionPanel,IssueStatusActionPanel,GrantRequestExporterForm,diff --git a/frontend/src/components/IssueV1/IssueDetailPage.vue b/frontend/src/components/IssueV1/IssueDetailPage.vueindex aaf22cd6ec..5ca3f31e0c 100644--- a/frontend/src/components/IssueV1/IssueDetailPage.vue+++ b/frontend/src/components/IssueV1/IssueDetailPage.vue@@ -23,7 +23,7 @@<DescriptionSection />- <ActivitySection v-if="!isCreating" />+ <IssueCommentSection v-if="!isCreating" /></div><div@@ -87,12 +87,12 @@ import {PlanCheckSection,StatementSection,DescriptionSection,- ActivitySection,Sidebar,IssueReviewActionPanel,IssueStatusActionPanel,TaskRolloutActionPanel,SQLCheckSection,+ IssueCommentSection,} from "./components";import type {IssueReviewAction,diff --git a/frontend/src/components/IssueV1/components/ActivitySection/Activity/ActionIcon.vue b/frontend/src/components/IssueV1/components/ActivitySection/Activity/ActionIcon.vuedeleted file mode 100644index 250a66bdf8..0000000000--- a/frontend/src/components/IssueV1/components/ActivitySection/Activity/ActionIcon.vue+++ /dev/null@@ -1,263 +0,0 @@-<template>- <div class="relative">- <div v-if="icon == 'system'" class="relative pl-0.5">- <div- class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"- >- <img class="mt-1" src="@/assets/logo-icon.svg" alt="Bytebase" />- </div>- </div>- <div v-else-if="icon == 'avatar'" class="relative pl-0.5">- <div- class="w-7 h-7 bg-white rounded-full ring-4 ring-white flex items-center justify-center"- >- <PrincipalAvatar- :user="user"- override-class="w-7 h-7 font-medium"- override-text-size="0.8rem"- />- </div>- </div>- <div v-else-if="icon == 'create'" class="relative pl-0.5">- <div- class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"- >- <heroicons-solid:plus-sm class="w-5 h-5 text-control" />- </div>- </div>- <div v-else-if="icon == 'update'" class="relative pl-0.5">- <div- class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"- >- <heroicons-solid:pencil class="w-4 h-4 text-control" />- </div>- </div>- <div v-else-if="icon == 'run' || icon == 'rollout'" class="relative pl-0.5">- <div- class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"- >- <heroicons-outline:play class="w-6 h-6 text-control" />- </div>- </div>- <div v-else-if="icon == 'approve-review'" class="relative pl-0.5">- <div- class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"- >- <heroicons-outline:thumb-up class="w-5 h-5 text-control" />- </div>- </div>- <div v-else-if="icon == 'reject-review'" class="relative pl-0.5">- <div- class="w-7 h-7 bg-warning rounded-full ring-4 ring-white flex items-center justify-center"- >- <heroicons:pause-solid class="w-5 h-5 text-white" />- </div>- </div>- <div v-else-if="icon == 're-request-review'" class="relative pl-0.5">- <div- class="w-7 h-7 bg-success rounded-full ring-4 ring-white flex items-center justify-center icon-re-request-review"- >- <heroicons:play class="w-4 h-4 text-white ml-px" />- </div>- </div>- <div v-else-if="icon == 'cancel'" class="relative pl-0.5">- <div- class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"- >- <heroicons-outline:minus class="w-5 h-5 text-control" />- </div>- </div>- <div v-else-if="icon == 'fail'" class="relative pl-0.5">- <div- class="w-7 h-7 bg-white rounded-full ring-4 ring-white flex items-center justify-center"- >- <heroicons-outline:exclamation-circle class="w-6 h-6 text-error" />- </div>- </div>- <div v-else-if="icon == 'complete'" class="relative pl-0.5">- <div- class="w-7 h-7 bg-white rounded-full ring-4 ring-white flex items-center justify-center"- >- <heroicons-outline:check-circle class="w-6 h-6 text-success" />- </div>- </div>- <div v-else-if="icon == 'skip'" class="relative pl-1">- <div- class="w-6 h-6 bg-gray-200 rounded-full ring-4 ring-white flex items-center justify-center"- >- <SkipIcon class="w-5 h-5 text-gray-500" />- </div>- </div>- <div v-else-if="icon == 'commit'" class="relative pl-0.5">- <div- class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"- >- <heroicons-outline:code class="w-5 h-5 text-control" />- </div>- </div>- </div>-</template>--<script lang="ts" setup>-import { computed } from "vue";-import { SkipIcon } from "@/components/Icon";-import PrincipalAvatar from "@/components/PrincipalAvatar.vue";-import { useUserStore } from "@/store";-import type {- ActivityIssueCommentCreatePayload,- ActivityPipelineTaskRunStatusUpdatePayload,- ActivityStageStatusUpdatePayload,- ActivityTaskStatusUpdatePayload,-} from "@/types";-import { SYSTEM_BOT_EMAIL } from "@/types";-import type { LogEntity } from "@/types/proto/v1/logging_service";-import { LogEntity_Action } from "@/types/proto/v1/logging_service";-import { extractUserResourceName } from "@/utils";--type ActionIconType =- | "avatar"- | "system"- | "create"- | "update"- | "run"- | "approve-review"- | "reject-review"- | "re-request-review"- | "rollout"- | "cancel"- | "fail"- | "complete"- | "skip"- | "commit";--const props = defineProps<{- activity: LogEntity;-}>();--const user = computed(() => {- const email = extractUserResourceName(props.activity.creator);- return useUserStore().getUserByEmail(email);-});--const icon = computed((): ActionIconType => {- const { activity } = props;- if (activity.action == LogEntity_Action.ACTION_ISSUE_CREATE) {- return "create";- } else if (activity.action == LogEntity_Action.ACTION_ISSUE_FIELD_UPDATE) {- return "update";- } else if (- activity.action == LogEntity_Action.ACTION_PIPELINE_TASK_STATUS_UPDATE- ) {- const payload = JSON.parse(- activity.payload- ) as ActivityTaskStatusUpdatePayload;- switch (payload.newStatus) {- case "PENDING": {- if (payload.oldStatus == "RUNNING") {- return "cancel";- } else if (payload.oldStatus == "PENDING_APPROVAL") {- return "rollout";- }- break;- }- case "CANCELED": {- return "cancel";- }- case "RUNNING": {- return "run";- }- case "DONE": {- if (payload.oldStatus === "RUNNING") {- return "complete";- } else {- return "skip";- }- }- case "FAILED": {- return "fail";- }- case "SKIPPED": {- return "skip";- }- case "PENDING_APPROVAL": {- return "avatar"; // stale approval dismissed.- }- }- } else if (- activity.action === LogEntity_Action.ACTION_PIPELINE_TASK_RUN_STATUS_UPDATE- ) {- const payload = JSON.parse(- activity.payload- ) as ActivityPipelineTaskRunStatusUpdatePayload;-- switch (payload.newStatus) {- case "PENDING": {- return "rollout";- }- case "CANCELED": {- return "cancel";- }- case "RUNNING": {- return "run";- }- case "DONE": {- return "complete";- }- case "SKIPPED": {- return "skip";- }- case "FAILED": {- return "fail";- }- }- } else if (- activity.action == LogEntity_Action.ACTION_PIPELINE_STAGE_STATUS_UPDATE- ) {- const payload = JSON.parse(- activity.payload- ) as ActivityStageStatusUpdatePayload;- switch (payload.stageStatusUpdateType) {- case "BEGIN": {- return "run";- }- case "END": {- return "complete";- }- }- } else if (- activity.action == LogEntity_Action.ACTION_PIPELINE_TASK_STATEMENT_UPDATE- ) {- return "update";- } else if (- activity.action ==- LogEntity_Action.ACTION_PIPELINE_TASK_EARLIEST_ALLOWED_TIME_UPDATE- ) {- return "update";- } else if (activity.action === LogEntity_Action.ACTION_ISSUE_COMMENT_CREATE) {- const payload = JSON.parse(- activity.payload- ) as ActivityIssueCommentCreatePayload;- if (payload.approvalEvent) {- const { status } = payload.approvalEvent;- switch (status) {- case "APPROVED":- return "approve-review";- case "REJECTED":- return "reject-review";- case "PENDING":- return "re-request-review";- }- }- }-- return extractUserResourceName(activity.creator) == SYSTEM_BOT_EMAIL- ? "system"- : "avatar";-});-</script>--<style scoped>-.icon-re-request-review :deep(path) {- stroke-width: 3 !important;-}-</style>diff --git a/frontend/src/components/IssueV1/components/ActivitySection/Activity/ActionSentence.vue b/frontend/src/components/IssueV1/components/ActivitySection/Activity/ActionSentence.vuedeleted file mode 100644index b08d5c68ad..0000000000--- a/frontend/src/components/IssueV1/components/ActivitySection/Activity/ActionSentence.vue+++ /dev/null@@ -1,340 +0,0 @@-<template>- <Renderer />-</template>--<script lang="ts" setup>-import dayjs from "dayjs";-import { defineComponent, h } from "vue";-import { Translation, useI18n } from "vue-i18n";-import type {- ActivityIssueCommentCreatePayload,- ActivityPipelineTaskRunStatusUpdatePayload,- ActivityStageStatusUpdatePayload,- ActivityTaskEarliestAllowedTimeUpdatePayload,- ActivityTaskStatementUpdatePayload,- ActivityTaskStatusUpdatePayload,- ActivityTaskPriorBackup,- ComposedIssue,-} from "@/types";-import { SYSTEM_BOT_EMAIL, UNKNOWN_ID } from "@/types";-import type { LogEntity } from "@/types/proto/v1/logging_service";-import { LogEntity_Action } from "@/types/proto/v1/logging_service";-import {- findStageByUID,- findTaskByUID,- issueActivityActionSentence,-} from "@/utils";-import { extractUserResourceName } from "@/utils";-import StageName from "./StageName.vue";-import StatementUpdate from "./StatementUpdate.vue";-import TaskName from "./TaskName.vue";--type RenderedContent = string | ReturnType<typeof h>;--const props = defineProps<{- activity: LogEntity;- issue: ComposedIssue;-}>();--const { t } = useI18n();--const renderActionSentence = () => {- const renderSpan = (content: string, props?: object) => {- return h("span", props, content);- };-- const { activity, issue } = props;- if (activity.resource.startsWith("issues")) {- if (activity.action === LogEntity_Action.ACTION_ISSUE_COMMENT_CREATE) {- const payload = JSON.parse(- activity.payload- ) as ActivityIssueCommentCreatePayload;- if (payload.externalApprovalEvent) {- if (payload.externalApprovalEvent.action == "REJECT") {- let imName = "";- switch (payload.externalApprovalEvent.type) {- case "bb.plugin.app.feishu":- imName = t("common.feishu");- break;- }- return renderSpan(- t("activity.sentence.external-approval-rejected", {- stageName: payload.externalApprovalEvent.stageName,- imName: imName,- })- );- }- }- if (payload.approvalEvent) {- if (payload.approvalEvent) {- const { status } = payload.approvalEvent;- const dict: Record<typeof status, string> = {- APPROVED: t("custom-approval.issue-review.approved-issue"),- REJECTED: t("custom-approval.issue-review.sent-back-issue"),- PENDING: t("custom-approval.issue-review.re-requested-review"),- };- const verb = dict[status];- if (verb) {- return renderSpan(maybeAutomaticallyVerb(activity, verb));- }- }- }- }-- const [tid, params] = issueActivityActionSentence(activity);- return renderSpan(t(tid, params));- }- switch (activity.action) {- case LogEntity_Action.ACTION_PIPELINE_TASK_STATUS_UPDATE: {- const payload = JSON.parse(- activity.payload- ) as ActivityTaskStatusUpdatePayload;- if (payload.newStatus === "PENDING_APPROVAL") {- // stale approval dismissed.-- const task = findTaskByUID(issue.rolloutEntity, String(payload.taskId));- const taskName = t("activity.sentence.task-name", {- name: task.title,- });- return t("activity.sentence.dismissed-stale-approval", {- task: taskName,- });- }- const params: VerbTypeTarget = {- activity,- verb: "",- type: t("common.task"),- target: "",- };- switch (payload.newStatus) {- case "PENDING": {- if (payload.oldStatus == "RUNNING") {- params.verb = t("activity.sentence.canceled");- } else if (payload.oldStatus == "PENDING_APPROVAL") {- params.verb = maybeAutomaticallyVerb(- activity,- t("activity.sentence.rolled-out")- );- }- break;- }- case "RUNNING": {- params.verb = t("activity.sentence.started");- break;- }- case "DONE": {- if (payload.oldStatus === "RUNNING") {- params.verb = t("activity.sentence.completed");- } else {- params.verb = t("activity.sentence.skipped");- }- break;- }- case "FAILED": {- params.verb = t("activity.sentence.failed");- break;- }- case "CANCELED": {- params.verb = t("activity.sentence.canceled");- break;- }- case "SKIPPED": {- params.verb = t("activity.sentence.skipped");- break;- }- default:- params.verb = t("activity.sentence.changed");- }- const task = findTaskByUID(issue.rolloutEntity, String(payload.taskId));- if (task) {- params.target = h(TaskName, { issue, task });- }- return renderVerbTypeTarget(params, {- tag: "span",- });- }- case LogEntity_Action.ACTION_PIPELINE_TASK_RUN_STATUS_UPDATE: {- const payload = JSON.parse(- activity.payload- ) as ActivityPipelineTaskRunStatusUpdatePayload;- const params: VerbTypeTarget = {- activity,- verb: "",- type: t("common.task"),- target: "",- };- switch (payload.newStatus) {- case "PENDING": {- params.verb = maybeAutomaticallyVerb(- activity,- t("activity.sentence.rolled-out")- );- break;- }- case "RUNNING": {- params.verb = t("activity.sentence.started");- break;- }- case "DONE": {- params.verb = t("activity.sentence.completed");- break;- }- case "FAILED": {- params.verb = t("activity.sentence.failed");- break;- }- case "CANCELED": {- params.verb = t("activity.sentence.canceled");- break;- }- case "SKIPPED": {- params.verb = t("activity.sentence.skipped");- break;- }- default:- params.verb = t("activity.sentence.changed");- }- const task = findTaskByUID(issue.rolloutEntity, String(payload.taskId));- if (task) {- params.target = h(TaskName, { issue, task });- }- return renderVerbTypeTarget(params, {- tag: "span",- });- }- case LogEntity_Action.ACTION_PIPELINE_TASK_PRIOR_BACKUP: {- const payload = JSON.parse(activity.payload) as ActivityTaskPriorBackup;- const tables = payload.schemaMetadata.map((sc) => sc.table).join(", ");- const params: VerbTypeTarget = {- activity,- verb: t("activity.sentence.prior-back-table", {- database: "bbdataarchive",- tables: tables,- }),- type: t("common.task"),- target: "",- };- const task = findTaskByUID(issue.rolloutEntity, String(payload.taskId));- if (task) {- params.target = h(TaskName, { issue, task });- }- return renderVerbTypeTarget(params, {- tag: "span",- });- }- case LogEntity_Action.ACTION_PIPELINE_STAGE_STATUS_UPDATE: {- const payload = JSON.parse(- activity.payload- ) as ActivityStageStatusUpdatePayload;- const stage = findStageByUID(- issue.rolloutEntity,- String(payload.stageId)- );- const params: VerbTypeTarget = {- activity,- verb: "",- type: t("common.stage"),- target: h(StageName, { stage, issue }),- };- switch (payload.stageStatusUpdateType) {- case "BEGIN":- params.verb = maybeAutomaticallyVerb(- activity,- t("activity.sentence.started")- );- break;- case "END":- params.verb = t("activity.sentence.completed");- break;- default:- params.verb = t("activity.sentence.changed");- break;- }- return renderVerbTypeTarget(params, {- tag: "span",- });- }- case LogEntity_Action.ACTION_PIPELINE_TASK_STATEMENT_UPDATE: {- const payload = JSON.parse(- activity.payload- ) as ActivityTaskStatementUpdatePayload;- return h(- "span",- {},- h(- Translation,- {- keypath: "activity.sentence.changed-x-link",- },- {- name: () => "SQL",- link: () =>- h(StatementUpdate, {- oldSheetId: String(payload.oldSheetId || UNKNOWN_ID),- newSheetId: String(payload.newSheetId || UNKNOWN_ID),- }),- }- )- );- }- case LogEntity_Action.ACTION_PIPELINE_TASK_EARLIEST_ALLOWED_TIME_UPDATE: {- const payload = JSON.parse(- activity.payload- ) as ActivityTaskEarliestAllowedTimeUpdatePayload;- const newVal = payload.newEarliestAllowedTs;- const oldVal = payload.oldEarliestAllowedTs;- const timeFormat = "YYYY-MM-DD HH:mm:ss UTCZZ";- return h(- "span",- {},- t("activity.sentence.changed-from-to", {- name: t("task.rollout-time"),- oldValue: oldVal ? dayjs(oldVal * 1000).format(timeFormat) : "Unset",- newValue: newVal ? dayjs(newVal * 1000).format(timeFormat) : "Unset",- })- );- }- }- return "";-};--const maybeAutomaticallyVerb = (activity: LogEntity, verb: string): string => {- if (extractUserResourceName(activity.creator) !== SYSTEM_BOT_EMAIL) {- return verb;- }- return t("activity.sentence.xxx-automatically", {- verb,- });-};--type VerbTypeTarget = {- activity: LogEntity;- verb: RenderedContent;- type: RenderedContent;- target?: RenderedContent;-};--const renderVerbTypeTarget = (params: VerbTypeTarget, props: object = {}) => {- const keypath =- extractUserResourceName(params.activity.creator) === SYSTEM_BOT_EMAIL- ? "activity.sentence.verb-type-target-by-system-bot"- : "activity.sentence.verb-type-target-by-people";- return h(- Translation,- {- ...props,- keypath,- },- {- verb: () => params.verb,- type: () => params.type,- target: () => params.target,- }- );-};--const Renderer = defineComponent({- name: "ActionSentenceRenderer",- render: renderActionSentence,-});-</script>diff --git a/frontend/src/components/IssueV1/components/ActivitySection/Activity/common.ts b/frontend/src/components/IssueV1/components/ActivitySection/Activity/common.tsdeleted file mode 100644index 62fd233ea8..0000000000--- a/frontend/src/components/IssueV1/components/ActivitySection/Activity/common.ts+++ /dev/null@@ -1,67 +0,0 @@-import type {- ActivityIssueCommentCreatePayload,- ActivityTaskStatementUpdatePayload,- ActivityTaskStatusUpdatePayload,-} from "@/types";-import type { LogEntity } from "@/types/proto/v1/logging_service";-import { LogEntity_Action } from "@/types/proto/v1/logging_service";--export type DistinctActivity = {- activity: LogEntity;- similar: LogEntity[];-};--export const isSimilarActivity = (a: LogEntity, b: LogEntity): boolean => {- // Now, we recognize two "Change SQL from .... to ...." activities are similar- // when they have the same "from" and "to" values.- if (- a.action === LogEntity_Action.ACTION_PIPELINE_TASK_STATEMENT_UPDATE &&- a.action === b.action &&- a.resource === b.resource- ) {- const payloadA = JSON.parse(- a.payload- ) as ActivityTaskStatementUpdatePayload;- const payloadB = JSON.parse(- b.payload- ) as ActivityTaskStatementUpdatePayload;- if (payloadA.newSheetId === payloadB.newSheetId) {- // If two "Update statement" activities come from one "Apply to stage"- // or "Apply to all tasks" operation, they will share the same newSheetId.- // So that we can define they are "similar".- return true;- }- }-- if (- a.action === LogEntity_Action.ACTION_PIPELINE_TASK_STATUS_UPDATE &&- a.action === b.action &&- a.resource === b.resource &&- a.creator === b.creator- ) {- const payloadA = JSON.parse(a.payload) as ActivityTaskStatusUpdatePayload;- const payloadB = JSON.parse(b.payload) as ActivityTaskStatusUpdatePayload;- if (- payloadA.oldStatus === payloadB.oldStatus &&- payloadB.newStatus === payloadB.newStatus- ) {- return true;- }- }-- return false;-};--export const isUserEditableActivity = (activity: LogEntity) => {- if (activity.action !== LogEntity_Action.ACTION_ISSUE_COMMENT_CREATE) {- return false;- }- const payload = JSON.parse(- activity.payload- ) as ActivityIssueCommentCreatePayload;- if (payload && payload.externalApprovalEvent) {- return false;- }-- return true;-};diff --git a/frontend/src/components/IssueV1/components/ActivitySection/Activity/index.ts b/frontend/src/components/IssueV1/components/ActivitySection/Activity/index.tsdeleted file mode 100644index 7b5f21c5ed..0000000000--- a/frontend/src/components/IssueV1/components/ActivitySection/Activity/index.ts+++ /dev/null@@ -1,4 +0,0 @@-import ActivityItem from "./ActivityItem.vue";--export * from "./common";-export { ActivityItem };diff --git a/frontend/src/components/IssueV1/components/ActivitySection/index.ts b/frontend/src/components/IssueV1/components/ActivitySection/index.tsdeleted file mode 100644index 0fddb8247e..0000000000--- a/frontend/src/components/IssueV1/components/ActivitySection/index.ts+++ /dev/null@@ -1,3 +0,0 @@-import ActivitySection from "./ActivitySection.vue";--export default ActivitySection;diff --git a/frontend/src/components/IssueV1/components/ActivitySection/ActivityList.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentList.vuesimilarity index 63%rename from frontend/src/components/IssueV1/components/ActivitySection/ActivityList.vuerename to frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentList.vueindex 7b4de605e3..d5c6ba7725 100644--- a/frontend/src/components/IssueV1/components/ActivitySection/ActivityList.vue+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentList.vue@@ -1,16 +1,17 @@<template><div class="flex flex-col gap-y-4"><ul>- <ActivityItem- v-for="(item, index) in activityList"- :key="item.activity.name"- :activity-list="activityList"+ <IssueCreatedComment :issue-comments="issueComments" :issue="issue" />+ <IssueCommentView+ v-for="(item, index) in issueComments"+ :key="item.comment.name"+ :issue-comments="issueComments":issue="issue":index="index"- :activity="item.activity"+ :issue-comment="item.comment":similar="item.similar">- <template v-if="allowEditActivity(item.activity)" #subject-suffix>+ <template v-if="allowEditIssueComment(item.comment)" #subject-suffix><div class="space-x-2 flex items-center text-control-light"><!-- mr-2 is to vertical align with the text description edit button--><div@@ -21,7 +22,7 @@<NButtonquaternarysize="tiny"- @click.prevent="onUpdateComment(item.activity)"+ @click.prevent="onUpdateComment(item.comment)"><heroicons-outline:pencil class="w-4 h-4" /></NButton>@@ -31,14 +32,14 @@<template #comment><MarkdownEditor- v-if="item.activity.comment"+ v-if="item.comment.comment":mode="state.editCommentMode &&- state.activeActivity?.name === item.activity.name+ state.activeComment?.name === item.comment.name? 'editor': 'preview'"- :content="item.activity.comment"+ :content="item.comment.comment":issue-list="issueList":project="issue.projectEntity"@change="(val: string) => (state.editComment = val)"@@ -48,7 +49,7 @@<divv-if="state.editCommentMode &&- state.activeActivity?.name === item.activity.name+ state.activeComment?.name === item.comment.name"class="flex space-x-2 mt-4 items-center justify-end">@@ -63,7 +64,7 @@</NButton></div></template>- </ActivityItem>+ </IssueCommentView></ul><div v-if="!state.editCommentMode && allowCreateComment">@@ -110,30 +111,33 @@import { computed, onMounted, reactive, ref, watch, watchEffect } from "vue";import { useRoute } from "vue-router";import MarkdownEditor from "@/components/MarkdownEditor";-import { IssueBuiltinFieldId } from "@/plugins";-import { useActivityV1Store, useCurrentUserV1, useIssueV1Store } from "@/store";-import { getLogId } from "@/store/modules/v1/common";+import {+ useCurrentUserV1,+ useIssueCommentStore,+ useIssueV1Store,+ type ComposedIssueComment,+} from "@/store";+import { getIssueCommentId } from "@/store/modules/v1/common";import { UNKNOWN_PROJECT_NAME } from "@/types";-import type { ComposedIssue, ActivityIssueFieldUpdatePayload } from "@/types";-import type { LogEntity } from "@/types/proto/v1/logging_service";-import { LogEntity_Action } from "@/types/proto/v1/logging_service";+import type { ComposedIssue } from "@/types";+import { ListIssueCommentsRequest } from "@/types/proto/v1/issue_service";import { extractUserResourceName, hasProjectPermissionV2 } from "@/utils";import { doSubscribeIssue, useIssueContext } from "../../logic";-import type { DistinctActivity } from "./Activity";import {- ActivityItem,- isSimilarActivity,- isUserEditableActivity,-} from "./Activity";+ IssueCommentView,+ isSimilarIssueComment,+ isUserEditableComment,+ type DistinctIssueComment,+} from "./IssueCommentView";+import IssueCreatedComment from "./IssueCommentView/IssueCreatedComment.vue";interface LocalState {editCommentMode: boolean;- activeActivity?: LogEntity;+ activeComment?: ComposedIssueComment;editComment: string;newComment: string;}-const activityV1Store = useActivityV1Store();const route = useRoute();const { issue } = useIssueContext();@@ -147,6 +151,7 @@ const state = reactive<LocalState>({const currentUser = useCurrentUserV1();const issueV1Store = useIssueV1Store();+const issueCommentStore = useIssueCommentStore();const prepareIssueListForMarkdownEditor = async () => {const project = issue.value.project;@@ -162,47 +167,36 @@ const prepareIssueListForMarkdownEditor = async () => {issueList.value = list.issues;};-const prepareActivityList = () => {- activityV1Store.fetchActivityListForIssueV1(issue.value);+const prepareIssueComments = async () => {+ await issueCommentStore.listIssueComments(+ ListIssueCommentsRequest.fromPartial({+ parent: issue.value.name,+ // Try to get all comments at once with max page size.+ pageSize: 1000,+ })+ );};-watchEffect(prepareActivityList);--// Need to use computed to make list reactive to activity list changes.-const activityList = computed((): DistinctActivity[] => {- const list = activityV1Store- .getActivityListByIssueV1(issue.value.uid)- .filter((activity) => {- if (activity.action === LogEntity_Action.ACTION_ISSUE_APPROVAL_NOTIFY) {- return false;- }-- if (activity.action === LogEntity_Action.ACTION_ISSUE_FIELD_UPDATE) {- const containUserVisibleChange =- (JSON.parse(activity.payload) as ActivityIssueFieldUpdatePayload)- .fieldId !== IssueBuiltinFieldId.SUBSCRIBER_LIST;- return containUserVisibleChange;- }- return true;- });+watchEffect(prepareIssueComments);- const distinctActivityList: DistinctActivity[] = [];+const issueComments = computed((): DistinctIssueComment[] => {+ const list = issueCommentStore.getIssueComments(issue.value.name);+ const distinctIssueComments: DistinctIssueComment[] = [];for (let i = 0; i < list.length; i++) {- const activity = list[i];- if (distinctActivityList.length === 0) {- distinctActivityList.push({ activity, similar: [] });+ const comment = list[i];+ if (distinctIssueComments.length === 0) {+ distinctIssueComments.push({ comment, similar: [] });continue;}- const prev = distinctActivityList[distinctActivityList.length - 1];- if (isSimilarActivity(prev.activity, activity)) {- prev.similar.push(activity);+ const prev = distinctIssueComments[distinctIssueComments.length - 1];+ if (isSimilarIssueComment(prev.comment, comment)) {+ prev.similar.push(comment);} else {- distinctActivityList.push({ activity, similar: [] });+ distinctIssueComments.push({ comment, similar: [] });}}-- return distinctActivityList;+ return distinctIssueComments;});const allowCreateComment = computed(() => {@@ -214,20 +208,18 @@ const allowCreateComment = computed(() => {});const cancelEditComment = () => {- state.activeActivity = undefined;+ state.activeComment = undefined;state.editCommentMode = false;state.editComment = "";};const doCreateComment = async (comment: string) => {- await issueV1Store.createIssueComment({+ await issueCommentStore.createIssueComment({issueName: issue.value.name,comment,});state.newComment = "";-- await prepareActivityList();-+ await prepareIssueComments();// // 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 theretry {@@ -237,11 +229,11 @@ const doCreateComment = async (comment: string) => {}};-const allowEditActivity = (activity: LogEntity) => {- if (!isUserEditableActivity(activity)) {+const allowEditIssueComment = (comment: ComposedIssueComment) => {+ if (!isUserEditableComment(comment)) {return false;}- if (currentUser.value.email === extractUserResourceName(activity.creator)) {+ if (currentUser.value.email === extractUserResourceName(comment.creator)) {return true;}return hasProjectPermissionV2(@@ -251,35 +243,31 @@ const allowEditActivity = (activity: LogEntity) => {);};-const onUpdateComment = (activity: LogEntity) => {- state.activeActivity = activity;+const onUpdateComment = (issueComment: ComposedIssueComment) => {+ state.activeComment = issueComment;state.editCommentMode = true;- state.editComment = activity.comment;+ state.editComment = issueComment.comment;};-const doUpdateComment = () => {- if (!state.activeActivity) {+const doUpdateComment = async () => {+ if (!state.activeComment) {return;}if (!state.editComment) {return;}- const activityId = getLogId(state.activeActivity.name);- issueV1Store- .updateIssueComment({- issueName: issue.value.name,- commentId: `${activityId}`,- comment: state.editComment,- })- .then(() => {- cancelEditComment();- });++ const commentId = getIssueCommentId(state.activeComment.name);+ await issueCommentStore.updateIssueComment({+ issueName: issue.value.name,+ commentId: `${commentId}`,+ comment: state.editComment,+ });+ cancelEditComment();};const allowUpdateComment = computed(() => {- return (- state.editComment && state.editComment != state.activeActivity!.comment- );+ return state.editComment && state.editComment != state.activeComment!.comment;});onMounted(() => {diff --git a/frontend/src/components/IssueV1/components/ActivitySection/ActivitySection.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentSection.vuesimilarity index 82%rename from frontend/src/components/IssueV1/components/ActivitySection/ActivitySection.vuerename to frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentSection.vueindex 6c0475e929..21adc60006 100644--- a/frontend/src/components/IssueV1/components/ActivitySection/ActivitySection.vue+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentSection.vue@@ -10,11 +10,11 @@</HideInStandaloneMode></div>- <ActivityList />+ <IssueCommentList /></div></template><script lang="ts" setup>-import ActivityList from "./ActivityList.vue";+import IssueCommentList from "./IssueCommentList.vue";import Subscribers from "./Subscribers";</script>diff --git a/frontend/src/components/IssueV1/components/ActivitySection/Activity/ActionCreator.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionCreator.vuesimilarity index 89%rename from frontend/src/components/IssueV1/components/ActivitySection/Activity/ActionCreator.vuerename to frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionCreator.vueindex 9019795fbb..a2952f7965 100644--- a/frontend/src/components/IssueV1/components/ActivitySection/Activity/ActionCreator.vue+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionCreator.vue@@ -21,17 +21,17 @@ import { computed } from "vue";import SystemBotTag from "@/components/misc/SystemBotTag.vue";import { usePageMode, useUserStore } from "@/store";import { SYSTEM_BOT_EMAIL } from "@/types";-import type { LogEntity } from "@/types/proto/v1/logging_service";import { extractUserResourceName } from "@/utils";const props = defineProps<{- activity: LogEntity;+ // Format: users/{email}+ creator: string;}>();const pageMode = usePageMode();const userEmail = computed(() => {- return extractUserResourceName(props.activity.creator);+ return extractUserResourceName(props.creator);});const user = computed(() => {diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionIcon.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionIcon.vuenew file mode 100644index 0000000000..74adbfb919--- /dev/null+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionIcon.vue@@ -0,0 +1,221 @@+<template>+ <div class="relative">+ <div v-if="icon === 'system'" class="relative pl-0.5">+ <div+ class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <img class="mt-1" src="@/assets/logo-icon.svg" alt="Bytebase" />+ </div>+ </div>+ <div v-else-if="icon === 'avatar'" class="relative pl-0.5">+ <div+ class="w-7 h-7 bg-white rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <PrincipalAvatar+ :user="user"+ override-class="w-7 h-7 font-medium"+ override-text-size="0.8rem"+ />+ </div>+ </div>+ <div v-else-if="icon === 'create'" class="relative pl-0.5">+ <div+ class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <heroicons-solid:plus-sm class="w-5 h-5 text-control" />+ </div>+ </div>+ <div v-else-if="icon === 'update'" class="relative pl-0.5">+ <div+ class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <heroicons-solid:pencil class="w-4 h-4 text-control" />+ </div>+ </div>+ <div+ v-else-if="icon === 'run' || icon === 'rollout'"+ class="relative pl-0.5"+ >+ <div+ class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <heroicons-outline:play class="w-6 h-6 text-control" />+ </div>+ </div>+ <div v-else-if="icon === 'approve-review'" class="relative pl-0.5">+ <div+ class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <heroicons-outline:thumb-up class="w-5 h-5 text-control" />+ </div>+ </div>+ <div v-else-if="icon === 'reject-review'" class="relative pl-0.5">+ <div+ class="w-7 h-7 bg-warning rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <heroicons:pause-solid class="w-5 h-5 text-white" />+ </div>+ </div>+ <div v-else-if="icon === 're-request-review'" class="relative pl-0.5">+ <div+ class="w-7 h-7 bg-success rounded-full ring-4 ring-white flex items-center justify-center icon-re-request-review"+ >+ <heroicons:play class="w-4 h-4 text-white ml-px" />+ </div>+ </div>+ <div v-else-if="icon === 'cancel'" class="relative pl-0.5">+ <div+ class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <heroicons-outline:minus class="w-5 h-5 text-control" />+ </div>+ </div>+ <div v-else-if="icon === 'fail'" class="relative pl-0.5">+ <div+ class="w-7 h-7 bg-white rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <heroicons-outline:exclamation-circle class="w-6 h-6 text-error" />+ </div>+ </div>+ <div v-else-if="icon === 'complete'" class="relative pl-0.5">+ <div+ class="w-7 h-7 bg-white rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <heroicons-outline:check-circle class="w-6 h-6 text-success" />+ </div>+ </div>+ <div v-else-if="icon === 'skip'" class="relative pl-1">+ <div+ class="w-6 h-6 bg-gray-200 rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <SkipIcon class="w-5 h-5 text-gray-500" />+ </div>+ </div>+ <div v-else-if="icon === 'commit'" class="relative pl-0.5">+ <div+ class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <heroicons-outline:code class="w-5 h-5 text-control" />+ </div>+ </div>+ </div>+</template>++<script lang="ts" setup>+import { computed } from "vue";+import { SkipIcon } from "@/components/Icon";+import PrincipalAvatar from "@/components/PrincipalAvatar.vue";+import {+ IssueCommentType,+ useUserStore,+ type ComposedIssueComment,+} from "@/store";+import { SYSTEM_BOT_EMAIL } from "@/types";+import {+ IssueComment_Approval,+ IssueComment_Approval_Status,+ IssueComment_IssueUpdate,+ IssueComment_TaskUpdate,+ IssueComment_TaskUpdate_Status,+} from "@/types/proto/v1/issue_service";+import { extractUserResourceName } from "@/utils";++type ActionIconType =+ | "avatar"+ | "system"+ | "create"+ | "update"+ | "run"+ | "approve-review"+ | "reject-review"+ | "re-request-review"+ | "rollout"+ | "cancel"+ | "fail"+ | "complete"+ | "skip"+ | "commit";++const props = defineProps<{+ issueComment: ComposedIssueComment;+}>();++const user = computed(() => {+ const email = extractUserResourceName(props.issueComment.creator);+ return useUserStore().getUserByEmail(email);+});++const icon = computed((): ActionIconType => {+ const { issueComment } = props;+ if (issueComment.type === IssueCommentType.APPROVAL) {+ const { status } = IssueComment_Approval.fromPartial(+ issueComment.approval || {}+ );+ switch (status) {+ case IssueComment_Approval_Status.APPROVED:+ return "approve-review";+ case IssueComment_Approval_Status.REJECTED:+ return "reject-review";+ case IssueComment_Approval_Status.PENDING:+ return "re-request-review";+ }+ } else if (issueComment.type === IssueCommentType.STAGE_END) {+ return "complete";+ } else if (issueComment.type === IssueCommentType.TASK_UPDATE) {+ const { toStatus } = IssueComment_TaskUpdate.fromPartial(+ issueComment.taskUpdate || {}+ );+ let action: ActionIconType = "update";+ if (toStatus !== undefined) {+ switch (toStatus) {+ case IssueComment_TaskUpdate_Status.PENDING: {+ action = "rollout";+ break;+ }+ case IssueComment_TaskUpdate_Status.RUNNING: {+ action = "run";+ break;+ }+ case IssueComment_TaskUpdate_Status.DONE: {+ action = "complete";+ break;+ }+ case IssueComment_TaskUpdate_Status.FAILED: {+ action = "fail";+ break;+ }+ case IssueComment_TaskUpdate_Status.SKIPPED: {+ action = "skip";+ break;+ }+ case IssueComment_TaskUpdate_Status.CANCELED: {+ action = "cancel";+ break;+ }+ }+ }+ return action;+ } else if (issueComment.type === IssueCommentType.ISSUE_UPDATE) {+ const { toTitle, toDescription, toAssignee } =+ IssueComment_IssueUpdate.fromPartial(issueComment.issueUpdate || {});+ if (+ toAssignee !== undefined ||+ toTitle !== undefined ||+ toDescription !== undefined+ ) {+ return "update";+ }+ // Otherwise, show avatar icon based on the creator.+ }++ return extractUserResourceName(issueComment.creator) == SYSTEM_BOT_EMAIL+ ? "system"+ : "avatar";+});+</script>++<style scoped>+.icon-re-request-review :deep(path) {+ stroke-width: 3 !important;+}+</style>diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionSentence.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionSentence.vuenew file mode 100644index 0000000000..187f4f2d54--- /dev/null+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionSentence.vue@@ -0,0 +1,286 @@+<template>+ <Renderer />+</template>++<script lang="tsx" setup>+import dayjs from "dayjs";+import type { h } from "vue";+import { defineComponent } from "vue";+import { Translation, useI18n } from "vue-i18n";+import {+ IssueCommentType,+ useUserStore,+ type ComposedIssueComment,+} from "@/store";+import type { ComposedIssue } from "@/types";+import { SYSTEM_BOT_EMAIL } from "@/types";+import { unknownUser } from "@/types";+import {+ IssueComment_Approval,+ IssueComment_Approval_Status,+ IssueComment_IssueUpdate,+ IssueComment_StageEnd,+ IssueComment_TaskPriorBackup,+ IssueComment_TaskUpdate,+ IssueComment_TaskUpdate_Status,+ IssueStatus,+} from "@/types/proto/v1/issue_service";+import {+ extractTaskUID,+ findStageByUID,+ findTaskByUID,+ extractStageUID,+ extractSheetUID,+} from "@/utils";+import { extractUserResourceName } from "@/utils";+import StageName from "./StageName.vue";+import StatementUpdate from "./StatementUpdate.vue";+import TaskName from "./TaskName.vue";++type RenderedContent = string | ReturnType<typeof h>;++const props = defineProps<{+ issue: ComposedIssue;+ issueComment: ComposedIssueComment;+}>();++const { t } = useI18n();+const userStore = useUserStore();++const renderActionSentence = () => {+ const { issueComment, issue } = props;+ if (issueComment.type === IssueCommentType.APPROVAL) {+ const { status } = IssueComment_Approval.fromPartial(+ issueComment.approval || {}+ );+ let verb = "";+ if (status === IssueComment_Approval_Status.APPROVED) {+ verb = t("custom-approval.issue-review.approved-issue");+ } else if (status === IssueComment_Approval_Status.REJECTED) {+ verb = t("custom-approval.issue-review.sent-back-issue");+ } else if (status === IssueComment_Approval_Status.PENDING) {+ verb = t("custom-approval.issue-review.re-requested-review");+ }+ if (verb) {+ return maybeAutomaticallyVerb(issueComment, verb);+ }+ } else if (issueComment.type === IssueCommentType.ISSUE_UPDATE) {+ const {+ fromTitle,+ toTitle,+ fromDescription,+ toDescription,+ fromStatus,+ toStatus,+ fromAssignee,+ toAssignee,+ } = IssueComment_IssueUpdate.fromPartial(issueComment.issueUpdate || {});+ if (fromTitle !== undefined && toTitle !== undefined) {+ return t("activity.sentence.changed-from-to", {+ name: t("issue.issue-name").toLowerCase(),+ oldValue: fromTitle,+ newValue: toTitle,+ });+ } else if (fromDescription !== undefined && toDescription !== undefined) {+ // Description could be very long, so we don't display it.+ return t("activity.sentence.changed-description");+ } else if (fromStatus !== undefined && toStatus !== undefined) {+ if (toStatus === IssueStatus.DONE) {+ return t("activity.sentence.resolved-issue");+ } else if (toStatus === IssueStatus.CANCELED) {+ return t("activity.sentence.canceled-issue");+ } else if (toStatus === IssueStatus.OPEN) {+ return t("activity.sentence.reopened-issue");+ }+ } else if (fromAssignee !== undefined || toAssignee !== undefined) {+ if (fromAssignee && toAssignee) {+ const oldName = (+ userStore.getUserByIdentifier(fromAssignee) ?? unknownUser()+ ).title;+ const newName = (+ userStore.getUserByIdentifier(toAssignee) ?? unknownUser()+ ).title;+ return t("activity.sentence.reassigned-issue", {+ oldName,+ newName,+ });+ } else if (!fromAssignee && toAssignee) {+ const newName = (+ userStore.getUserByIdentifier(toAssignee) ?? unknownUser()+ ).title;+ return t("activity.sentence.assigned-issue", { newName });+ } else if (fromAssignee && !toAssignee) {+ const oldName = (+ userStore.getUserByIdentifier(fromAssignee) ?? unknownUser()+ ).title;+ return t("activity.sentence.unassigned-issue", {+ oldName,+ });+ } else {+ return t("activity.sentence.invalid-assignee-update");+ }+ }+ } else if (issueComment.type === IssueCommentType.STAGE_END) {+ const { stage } = IssueComment_StageEnd.fromPartial(+ issueComment.stageEnd || {}+ );+ const stageEntity = findStageByUID(+ issue.rolloutEntity,+ extractStageUID(stage)+ );+ const params: VerbTypeTarget = {+ issueComment,+ type: t("common.stage"),+ target: <StageName stage={stageEntity} issue={issue} />,+ verb: t("activity.sentence.completed"),+ };+ return renderVerbTypeTarget(params);+ } else if (issueComment.type === IssueCommentType.TASK_UPDATE) {+ const {+ tasks,+ fromSheet,+ toSheet,+ fromEarliestAllowedTime,+ toEarliestAllowedTime,+ toStatus,+ } = IssueComment_TaskUpdate.fromPartial(issueComment.taskUpdate || {});++ if (toStatus !== undefined) {+ const params: VerbTypeTarget = {+ issueComment,+ verb: "",+ type: t("common.task"),+ target: "",+ };+ switch (toStatus) {+ case IssueComment_TaskUpdate_Status.PENDING: {+ params.verb = maybeAutomaticallyVerb(+ issueComment,+ t("activity.sentence.rolled-out")+ );+ break;+ }+ case IssueComment_TaskUpdate_Status.RUNNING: {+ params.verb = t("activity.sentence.started");+ break;+ }+ case IssueComment_TaskUpdate_Status.DONE: {+ params.verb = t("activity.sentence.completed");+ break;+ }+ case IssueComment_TaskUpdate_Status.FAILED: {+ params.verb = t("activity.sentence.failed");+ break;+ }+ case IssueComment_TaskUpdate_Status.CANCELED: {+ params.verb = t("activity.sentence.canceled");+ break;+ }+ case IssueComment_TaskUpdate_Status.SKIPPED: {+ params.verb = t("activity.sentence.skipped");+ break;+ }+ default:+ params.verb = t("activity.sentence.changed");+ }+ const taskEntities = tasks.map((task) =>+ findTaskByUID(issue.rolloutEntity, extractTaskUID(task))+ );+ if (taskEntities.length > 0) {+ params.target = <TaskName issue={issue} task={taskEntities[0]} />;+ }+ return renderVerbTypeTarget(params);+ } else if (fromSheet !== undefined && toSheet !== undefined) {+ return (+ <Translation keypath="activity.sentence.changed-x-link">+ {{+ name: () => "SQL",+ link: () => (+ <StatementUpdate+ oldSheetId={extractSheetUID(fromSheet)}+ newSheetId={extractSheetUID(toSheet)}+ />+ ),+ }}+ </Translation>+ );+ } else if (+ fromEarliestAllowedTime !== undefined ||+ toEarliestAllowedTime !== undefined+ ) {+ const oldVal = fromEarliestAllowedTime;+ const newVal = toEarliestAllowedTime;+ const timeFormat = "YYYY-MM-DD HH:mm:ss UTCZZ";+ return t("activity.sentence.changed-from-to", {+ name: t("task.rollout-time"),+ oldValue: oldVal ? dayjs(oldVal).format(timeFormat) : "Unset",+ newValue: newVal ? dayjs(newVal).format(timeFormat) : "Unset",+ });+ }+ } else if (issueComment.type === IssueCommentType.TASK_PRIOR_BACKUP) {+ const { task, tables } = IssueComment_TaskPriorBackup.fromPartial(+ issueComment.taskPriorBackup || {}+ );+ const taskEntity = findTaskByUID(issue.rolloutEntity, extractTaskUID(task));+ const params: VerbTypeTarget = {+ issueComment,+ verb: t("activity.sentence.prior-back-table", {+ database: "bbdataarchive",+ tables: tables+ .map((table) =>+ table.schema ? `${table.schema}.${table.table}` : table.table+ )+ .join(", "),+ }),+ type: t("common.task"),+ target: "",+ };+ if (task) {+ params.target = <TaskName issue={issue} task={taskEntity} />;+ }+ return renderVerbTypeTarget(params);+ }+ return t("activity.sentence.empty");+};++const maybeAutomaticallyVerb = (+ issueComment: ComposedIssueComment,+ verb: string+): string => {+ if (extractUserResourceName(issueComment.creator) !== SYSTEM_BOT_EMAIL) {+ return verb;+ }+ return t("activity.sentence.xxx-automatically", {+ verb,+ });+};++type VerbTypeTarget = {+ issueComment: ComposedIssueComment;+ verb: RenderedContent;+ type: RenderedContent;+ target?: RenderedContent;+};++const renderVerbTypeTarget = (params: VerbTypeTarget, props: object = {}) => {+ const keypath =+ extractUserResourceName(params.issueComment.creator) === SYSTEM_BOT_EMAIL+ ? "activity.sentence.verb-type-target-by-system-bot"+ : "activity.sentence.verb-type-target-by-people";++ return (+ <Translation {...props} keypath={keypath}>+ {{+ verb: () => params.verb,+ type: () => params.type,+ target: () => params.target,+ }}+ </Translation>+ );+};++const Renderer = defineComponent({+ name: "ActionSentenceRenderer",+ render: () => <span>{renderActionSentence()}</span>,+});+</script>diff --git a/frontend/src/components/IssueV1/components/ActivitySection/Activity/ActivityAction.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCommentAction.vuesimilarity index 63%rename from frontend/src/components/IssueV1/components/ActivitySection/Activity/ActivityAction.vuerename to frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCommentAction.vueindex 3fc3fec2bb..70b3927bb9 100644--- a/frontend/src/components/IssueV1/components/ActivitySection/Activity/ActivityAction.vue+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCommentAction.vue@@ -4,28 +4,30 @@<div class="text-sm text-control-light space-x-1"><ActionCreatorv-if="- extractUserResourceName(activity.creator) !== SYSTEM_BOT_EMAIL ||- activity.action === LogEntity_Action.ACTION_ISSUE_COMMENT_CREATE+ extractUserResourceName(issueComment.creator) !==+ SYSTEM_BOT_EMAIL ||+ issueComment.type === IssueCommentType.USER_COMMENT"- :activity="activity"+ :creator="issueComment.creator"/>- <ActionSentence :issue="issue" :activity="activity" />+ <ActionSentence :issue="issue" :issue-comment="issueComment" /><HumanizeTs- :ts="(activity.createTime?.getTime() ?? 0) / 1000"+ :ts="(issueComment.createTime?.getTime() ?? 0) / 1000"class="ml-1"/><spanv-if="- activity.createTime?.getTime() !== activity.updateTime?.getTime() &&- activity.action == LogEntity_Action.ACTION_ISSUE_COMMENT_CREATE+ issueComment.createTime?.getTime() !==+ issueComment.updateTime?.getTime() &&+ issueComment.type === IssueCommentType.USER_COMMENT"><span>({{ $t("common.edited") }}</span><HumanizeTs- :ts="(activity.updateTime?.getTime() ?? 0) / 1000"+ :ts="(issueComment.updateTime?.getTime() ?? 0) / 1000"class="ml-1"/>)</span>@@ -51,10 +53,9 @@</template><script lang="ts" setup>+import { IssueCommentType, type ComposedIssueComment } from "@/store";import type { ComposedIssue } from "@/types";import { SYSTEM_BOT_EMAIL } from "@/types";-import type { LogEntity } from "@/types/proto/v1/logging_service";-import { LogEntity_Action } from "@/types/proto/v1/logging_service";import { extractUserResourceName } from "@/utils";import ActionCreator from "./ActionCreator.vue";import ActionSentence from "./ActionSentence.vue";@@ -62,7 +63,7 @@ import ActionSentence from "./ActionSentence.vue";defineProps<{issue: ComposedIssue;index: number;- activity: LogEntity;- similar: LogEntity[];+ issueComment: ComposedIssueComment;+ similar: ComposedIssueComment[];}>();</script>diff --git a/frontend/src/components/IssueV1/components/ActivitySection/Activity/ActivityItem.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCommentView.vuesimilarity index 55%rename from frontend/src/components/IssueV1/components/ActivitySection/Activity/ActivityItem.vuerename to frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCommentView.vueindex 43ac8cde9e..94c280e81d 100644--- a/frontend/src/components/IssueV1/components/ActivitySection/Activity/ActivityItem.vue+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCommentView.vue@@ -1,21 +1,18 @@<template>- <li class="issue-debug">- {{ LogEntity.toJSON(activity) }}- </li><li>- <div :id="`#${activity.name}`" class="relative pb-4">+ <div :id="`#${issueComment.name}`" class="relative pb-4"><span- v-if="index !== activityList.length - 1"+ v-if="index !== issueComments.length - 1"class="absolute left-4 -ml-px h-full w-0.5 bg-block-border"aria-hidden="true"></span><div class="relative flex items-start">- <ActionIcon :activity="activity" />+ <ActionIcon :issue-comment="issueComment" />- <ActivityAction+ <IssueCommentAction:issue="issue":index="index"- :activity="activity"+ :issue-comment="issueComment":similar="similar"><template #subject-suffix>@@ -25,24 +22,24 @@<template #comment><slot name="comment" /></template>- </ActivityAction>+ </IssueCommentAction></div></div></li></template><script lang="ts" setup>+import type { ComposedIssueComment } from "@/store";import type { ComposedIssue } from "@/types";-import { LogEntity } from "@/types/proto/v1/logging_service";import ActionIcon from "./ActionIcon.vue";-import ActivityAction from "./ActivityAction.vue";-import type { DistinctActivity } from "./common";+import IssueCommentAction from "./IssueCommentAction.vue";+import type { DistinctIssueComment } from "./common";defineProps<{issue: ComposedIssue;- activityList: DistinctActivity[];+ issueComments: DistinctIssueComment[];index: number;- activity: LogEntity;- similar: LogEntity[];+ issueComment: ComposedIssueComment;+ similar: ComposedIssueComment[];}>();</script>diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCreatedComment.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCreatedComment.vuenew file mode 100644index 0000000000..d24cd9eb73--- /dev/null+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCreatedComment.vue@@ -0,0 +1,46 @@+<template>+ <li>+ <div class="relative pb-4">+ <span+ v-if="issueComments.length > 0"+ class="absolute left-4 -ml-px h-full w-0.5 bg-block-border"+ aria-hidden="true"+ ></span>+ <div class="relative flex items-start">+ <div>+ <div class="relative pl-0.5">+ <div+ class="w-7 h-7 bg-control-bg rounded-full ring-4 ring-white flex items-center justify-center"+ >+ <heroicons-solid:plus-sm class="w-5 h-5 text-control" />+ </div>+ </div>+ </div>++ <div class="ml-3 min-w-0 flex-1">+ <div class="min-w-0 flex-1 pt-1 flex justify-between">+ <div class="text-sm text-control-light space-x-1">+ <ActionCreator :creator="issue.creator" />+ <span>{{ $t("activity.sentence.created-issue") }}</span>+ <HumanizeTs+ :ts="(issue.createTime?.getTime() ?? 0) / 1000"+ class="ml-1"+ />+ </div>+ </div>+ </div>+ </div>+ </div>+ </li>+</template>++<script lang="ts" setup>+import type { ComposedIssue } from "@/types";+import ActionCreator from "./ActionCreator.vue";+import type { DistinctIssueComment } from "./common";++defineProps<{+ issue: ComposedIssue;+ issueComments: DistinctIssueComment[];+}>();+</script>diff --git a/frontend/src/components/IssueV1/components/ActivitySection/Activity/StageName.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/StageName.vuesimilarity index 100%rename from frontend/src/components/IssueV1/components/ActivitySection/Activity/StageName.vuerename to frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/StageName.vuediff --git a/frontend/src/components/IssueV1/components/ActivitySection/Activity/StatementUpdate.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/StatementUpdate.vuesimilarity index 100%rename from frontend/src/components/IssueV1/components/ActivitySection/Activity/StatementUpdate.vuerename to frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/StatementUpdate.vuediff --git a/frontend/src/components/IssueV1/components/ActivitySection/Activity/TaskName.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/TaskName.vuesimilarity index 100%rename from frontend/src/components/IssueV1/components/ActivitySection/Activity/TaskName.vuerename to frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/TaskName.vuediff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/common.ts b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/common.tsnew file mode 100644index 0000000000..275fac3aac--- /dev/null+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/common.ts@@ -0,0 +1,50 @@+import { IssueCommentType, type ComposedIssueComment } from "@/store";++export type DistinctIssueComment = {+ comment: ComposedIssueComment;+ similar: ComposedIssueComment[];+};++export const isSimilarIssueComment = (+ a: ComposedIssueComment,+ b: ComposedIssueComment+): boolean => {+ if (a.type !== b.type || a.creator !== b.creator) {+ return false;+ }++ if (a.type === IssueCommentType.TASK_UPDATE) {+ const fromTaskUpdate = a.taskUpdate;+ const toTaskUpdate = b.taskUpdate;+ if (!fromTaskUpdate || !toTaskUpdate) {+ return false;+ }++ if (+ fromTaskUpdate.toSheet &&+ fromTaskUpdate.toSheet === toTaskUpdate.toSheet+ ) {+ return true;+ }+ if (+ fromTaskUpdate.toStatus &&+ fromTaskUpdate.toStatus === toTaskUpdate.toStatus+ ) {+ return true;+ }+ }++ return false;+};++export const isUserEditableComment = (comment: ComposedIssueComment) => {+ if (comment.type === IssueCommentType.USER_COMMENT) {+ return true;+ }+ if (comment.type === IssueCommentType.APPROVAL) {+ if (comment.comment !== "") {+ return true;+ }+ }+ return false;+};diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/index.ts b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/index.tsnew file mode 100644index 0000000000..b66be42005--- /dev/null+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/index.ts@@ -0,0 +1,4 @@+import IssueCommentView from "./IssueCommentView.vue";++export * from "./common";+export { IssueCommentView };diff --git a/frontend/src/components/IssueV1/components/ActivitySection/Subscribers/SubscribeButton.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscribeButton.vuesimilarity index 100%rename from frontend/src/components/IssueV1/components/ActivitySection/Subscribers/SubscribeButton.vuerename to frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscribeButton.vuediff --git a/frontend/src/components/IssueV1/components/ActivitySection/Subscribers/SubscriberList.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberList.vuesimilarity index 100%rename from frontend/src/components/IssueV1/components/ActivitySection/Subscribers/SubscriberList.vuerename to frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberList.vuediff --git a/frontend/src/components/IssueV1/components/ActivitySection/Subscribers/SubscriberListItem.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberListItem.vuesimilarity index 100%rename from frontend/src/components/IssueV1/components/ActivitySection/Subscribers/SubscriberListItem.vuerename to frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberListItem.vuediff --git a/frontend/src/components/IssueV1/components/ActivitySection/Subscribers/Subscribers.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/Subscribers.vuesimilarity index 100%rename from frontend/src/components/IssueV1/components/ActivitySection/Subscribers/Subscribers.vuerename to frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/Subscribers.vuediff --git a/frontend/src/components/IssueV1/components/ActivitySection/Subscribers/index.ts b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/index.tssimilarity index 100%rename from frontend/src/components/IssueV1/components/ActivitySection/Subscribers/index.tsrename to frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/index.tsdiff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/index.ts b/frontend/src/components/IssueV1/components/IssueCommentSection/index.tsnew file mode 100644index 0000000000..078c74bb18--- /dev/null+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/index.ts@@ -0,0 +1,3 @@+import IssueCommentSection from "./IssueCommentSection.vue";++export default IssueCommentSection;diff --git a/frontend/src/components/IssueV1/components/Sidebar/RollbackSection/common.ts b/frontend/src/components/IssueV1/components/Sidebar/RollbackSection/common.tsindex 4c9326030c..960196943d 100644--- a/frontend/src/components/IssueV1/components/Sidebar/RollbackSection/common.ts+++ b/frontend/src/components/IssueV1/components/Sidebar/RollbackSection/common.ts@@ -11,8 +11,8 @@ import { rolloutServiceClient } from "@/grpcweb";import {useCurrentUserV1,experimentalFetchIssueByName,- useIssueV1Store,pushNotification,+ useIssueCommentStore,} from "@/store";import type { ComposedIssue } from "@/types";import { UNKNOWN_ID } from "@/types";@@ -155,7 +155,7 @@ export const useRollbackContext = () => {});try {- await useIssueV1Store().createIssueComment({+ await useIssueCommentStore().createIssueComment({issueName: issue.value.name,comment: `${action} SQL rollback log for task [${issue.value.title}].`,payload: {@@ -203,11 +203,8 @@ export const maybeCreateBackTraceComments = async (newIssue: ComposedIssue) => {if (rollbackList.length === 0) return;for (let i = 0; i < rollbackList.length; i++) {- const {- // byTask,- fromIssue: fromIssueName,- fromTask: fromTaskName,- } = rollbackList[i];+ const { fromIssue: fromIssueName, fromTask: fromTaskName } =+ rollbackList[i];const fromIssue = await experimentalFetchIssueByName(fromIssueName);if (fromIssue.uid === String(UNKNOWN_ID)) continue;@@ -215,30 +212,5 @@ export const maybeCreateBackTraceComments = async (newIssue: ComposedIssue) => {(task) => task.name === fromTaskName);if (!fromTask || fromTask.uid === String(UNKNOWN_ID)) continue;-- // const comment = [- // `Create issue #${newIssue.uid}`,- // "to rollback task",- // `[${fromTask.title}]`,- // ].join(" ");- try {- // TODO: create comment- // await useIssueV1Store().createIssueComment({- // issueId: fromIssue.uid,- // comment,- // payload: {- // issueName: fromIssue.name,- // taskRollbackBy: {- // issueId: fromIssue.id,- // taskId: fromTask.id,- // rollbackByIssueId: newIssue.id,- // rollbackByTaskId: byTask.id,- // },- // },- // });- } catch {- // do nothing- // failing to comment to won't be too bad- }}};diff --git a/frontend/src/components/IssueV1/components/index.ts b/frontend/src/components/IssueV1/components/index.tsindex 3295cd7692..ad79525dc0 100644--- a/frontend/src/components/IssueV1/components/index.ts+++ b/frontend/src/components/IssueV1/components/index.ts@@ -1,8 +1,8 @@-import ActivitySection from "./ActivitySection";import BannerSection from "./BannerSection.vue";import DataExportSection from "./DataExportSection";import DescriptionSection from "./DescriptionSection";import HeaderSection from "./HeaderSection";+import IssueCommentSection from "./IssueCommentSection";import IssueSearch from "./IssueSearch";import PlanCheckSection from "./PlanCheckSection";import SQLCheckSection from "./SQLCheckSection";@@ -23,9 +23,9 @@ export {PlanCheckSection,StatementSection,DescriptionSection,- ActivitySection,IssueSearch,Sidebar,SQLCheckSection,DataExportSection,+ IssueCommentSection,};diff --git a/frontend/src/store/modules/v1/common.ts b/frontend/src/store/modules/v1/common.tsindex d0685f9c90..b8fe06dece 100644--- a/frontend/src/store/modules/v1/common.ts+++ b/frontend/src/store/modules/v1/common.ts@@ -20,8 +20,8 @@ export const issueNamePrefix = "issues/";export const secretNamePrefix = "secrets/";export const branchNamePrefix = "branches/";export const ssoNamePrefix = "idps/";-export const protectionRulesSuffix = "/protectionRules";+export const issueCommentNamePrefix = "issueComments/";export const getNameParentTokens = (name: string,@@ -178,3 +178,15 @@ export const getSSOId = (name: string) => {const tokens = getNameParentTokens(name, [ssoNamePrefix]);return tokens[0];};++export const getIssueCommentId = (name: string) => {+ const tokens = getNameParentTokens(name, [+ projectNamePrefix,+ issueNamePrefix,+ issueCommentNamePrefix,+ ]);+ if (tokens.length !== 3) {+ return "";+ }+ return tokens[2];+};diff --git a/frontend/src/store/modules/v1/index.ts b/frontend/src/store/modules/v1/index.tsindex c397bb8b1c..f51b153457 100644--- a/frontend/src/store/modules/v1/index.ts+++ b/frontend/src/store/modules/v1/index.ts@@ -24,3 +24,4 @@ export * from "./activity";export * from "./anomaly";export * from "./schemaEditor";export * from "./changelist";+export * from "./issueComment";diff --git a/frontend/src/store/modules/v1/issue.ts b/frontend/src/store/modules/v1/issue.tsindex df9e17ebfe..561f8642a2 100644--- a/frontend/src/store/modules/v1/issue.ts+++ b/frontend/src/store/modules/v1/issue.ts@@ -4,11 +4,7 @@ import { defineStore } from "pinia";import type { WatchCallback } from "vue";import { ref, watch } from "vue";import { issueServiceClient } from "@/grpcweb";-import type {- ActivityIssueCommentCreatePayload,- ComposedIssue,- IssueFilter,-} from "@/types";+import type { ComposedIssue, IssueFilter } from "@/types";import { PresetRoleType, UNKNOWN_PROJECT_NAME } from "@/types";import { UserType } from "@/types/proto/v1/auth_service";import type { ApprovalStep } from "@/types/proto/v1/issue_service";@@ -19,9 +15,7 @@ import {} from "@/types/proto/v1/issue_service";import { extractProjectResourceName, memberListInProjectV1 } from "@/utils";import { useUserStore } from "../user";-import { useActivityV1Store } from "./activity";import {- experimentalFetchIssueByName,shallowComposeIssue,type ComposeIssueConfig,} from "./experimental-issue";@@ -87,47 +81,6 @@ export const useIssueV1Store = defineStore("issue_v1", () => {});};- const createIssueComment = async ({- issueName,- comment,- payload,- }: {- issueName: string;- comment: string;- payload?: ActivityIssueCommentCreatePayload;- }) => {- await issueServiceClient.createIssueComment({- parent: issueName,- issueComment: {- comment,- payload: JSON.stringify(payload ?? {}),- },- });- const issue = await experimentalFetchIssueByName(issueName);- await useActivityV1Store().fetchActivityListForIssueV1(issue);- };-- const updateIssueComment = async ({- issueName,- commentId,- comment,- }: {- issueName: string;- commentId: string;- comment: string;- }) => {- await issueServiceClient.updateIssueComment({- parent: issueName,- issueComment: {- uid: commentId,- comment,- },- updateMask: ["comment"],- });- const issue = await experimentalFetchIssueByName(issueName);- await useActivityV1Store().fetchActivityListForIssueV1(issue);- };-const listIssues = async ({ find, pageSize, pageToken }: ListIssueParams,composeIssueConfig?: ComposeIssueConfig@@ -161,8 +114,6 @@ export const useIssueV1Store = defineStore("issue_v1", () => {return {listIssues,regenerateReviewV1,- createIssueComment,- updateIssueComment,};});diff --git a/frontend/src/store/modules/v1/issueComment.ts b/frontend/src/store/modules/v1/issueComment.tsnew file mode 100644index 0000000000..ea2e85c2bd--- /dev/null+++ b/frontend/src/store/modules/v1/issueComment.ts@@ -0,0 +1,124 @@+import { defineStore } from "pinia";+import { reactive } from "vue";+import { issueServiceClient } from "@/grpcweb";+import type { ActivityIssueCommentCreatePayload } from "@/types";+import type {+ IssueComment,+ ListIssueCommentsRequest,+} from "@/types/proto/v1/issue_service";++export enum IssueCommentType {+ USER_COMMENT = "USER_COMMENT",+ APPROVAL = "APPROVAL",+ ISSUE_UPDATE = "ISSUE_UPDATE",+ STAGE_END = "STAGE_END",+ TASK_UPDATE = "TASK_UPDATE",+ TASK_PRIOR_BACKUP = "TASK_PRIOR_BACKUP",+}++export interface ComposedIssueComment extends IssueComment {+ type: IssueCommentType;+}++const composeIssueComment = (+ issueComment: IssueComment+): ComposedIssueComment => {+ let type = IssueCommentType.USER_COMMENT;+ if (issueComment.approval !== undefined) {+ type = IssueCommentType.APPROVAL;+ } else if (issueComment.issueUpdate !== undefined) {+ type = IssueCommentType.ISSUE_UPDATE;+ } else if (issueComment.stageEnd !== undefined) {+ type = IssueCommentType.STAGE_END;+ } else if (issueComment.taskUpdate !== undefined) {+ type = IssueCommentType.TASK_UPDATE;+ } else if (issueComment.taskPriorBackup !== undefined) {+ type = IssueCommentType.TASK_PRIOR_BACKUP;+ }+ return {+ ...issueComment,+ type,+ };+};++export const useIssueCommentStore = defineStore("issue_comment", () => {+ // issueCommentMap is a map of issueName to ComposedIssueComment[].+ const issueCommentMap = reactive(new Map<string, ComposedIssueComment[]>());++ const listIssueComments = async (request: ListIssueCommentsRequest) => {+ const resp = await issueServiceClient.listIssueComments(request);+ issueCommentMap.set(+ request.parent,+ resp.issueComments.map(composeIssueComment)+ );++ return {+ nextPageToken: resp.nextPageToken,+ issueComments: resp.issueComments,+ };+ };++ const createIssueComment = async ({+ issueName,+ comment,+ payload,+ }: {+ issueName: string;+ comment: string;+ payload?: ActivityIssueCommentCreatePayload;+ }) => {+ const issueComment = await issueServiceClient.createIssueComment({+ parent: issueName,+ issueComment: {+ comment,+ payload: JSON.stringify(payload ?? {}),+ },+ });+ issueCommentMap.set(issueName, [+ ...(issueCommentMap.get(issueName) ?? []),+ composeIssueComment(issueComment),+ ]);+ };++ const updateIssueComment = async ({+ issueName,+ commentId,+ comment,+ }: {+ issueName: string;+ commentId: string;+ comment: string;+ }) => {+ await issueServiceClient.updateIssueComment({+ parent: issueName,+ issueComment: {+ uid: commentId,+ comment,+ },+ updateMask: ["comment"],+ });+ issueCommentMap.set(+ issueName,+ (issueCommentMap.get(issueName) ?? []).map((issueComment) => {+ if (issueComment.uid === commentId) {+ return {+ ...issueComment,+ comment,+ };+ }+ return issueComment;+ })+ );+ };++ const getIssueComments = (issueName: string): ComposedIssueComment[] => {+ return issueCommentMap.get(issueName) ?? [];+ };++ return {+ listIssueComments,+ createIssueComment,+ updateIssueComment,+ getIssueComments,+ };+});diff --git a/frontend/src/utils/v1/issue/rollout.ts b/frontend/src/utils/v1/issue/rollout.tsindex ab7fc6d85f..3378ea3c74 100644--- a/frontend/src/utils/v1/issue/rollout.ts+++ b/frontend/src/utils/v1/issue/rollout.ts@@ -20,6 +20,12 @@ export const extractRolloutUID = (name: string) => {return matches?.[1] ?? "";};+export const extractStageUID = (name: string) => {+ const pattern = /(?:^|\/)stages\/([^/]+)(?:$|\/)/;+ const matches = name.match(pattern);+ return matches?.[1] ?? "";+};+export const extractTaskUID = (name: string) => {const pattern = /(?:^|\/)tasks\/([^/]+)(?:$|\/)/;const matches = name.match(pattern);