Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Support update comment
Tianzhou Chen4ce6f3287928
diff --git a/frontend/src/miragejs/factories/activity.js b/frontend/src/miragejs/factories/activity.jsindex 9147565df2..b7151cb12c 100644--- a/frontend/src/miragejs/factories/activity.js+++ b/frontend/src/miragejs/factories/activity.js@@ -6,7 +6,7 @@ export default {return Date.now() - (10 - i) * 1800 * 1000;},lastUpdatedTs(i) {- return Date.now() - (10 - i) * 3600 * 1000;+ return Date.now() - (10 - i) * 1800 * 1000;},actionType() {return "bytebase.task.comment.create";diff --git a/frontend/src/miragejs/factories/activityPatch.js b/frontend/src/miragejs/factories/activityPatch.jsnew file mode 100644index 0000000000..f6fd5e7c8b--- /dev/null+++ b/frontend/src/miragejs/factories/activityPatch.js@@ -0,0 +1,9 @@+import { Factory } from "miragejs";++export default {+ activityPatch: Factory.extend({+ payload() {+ return {};+ },+ }),+};diff --git a/frontend/src/miragejs/factories/index.js b/frontend/src/miragejs/factories/index.jsindex 8f01e11fc0..2896a7a778 100644--- a/frontend/src/miragejs/factories/index.js+++ b/frontend/src/miragejs/factories/index.js@@ -2,7 +2,6 @@* Mirage JS guide on Factories: https://miragejs.com/docs/data-layer/factories*/-import activity from "./activity";import user from "./user";import bookmark from "./bookmark";import project from "./project";@@ -12,6 +11,8 @@ import dataSource from "./dataSource";import repository from "./repository";import task from "./task";import taskPatch from "./taskPatch";+import activity from "./activity";+import activityPatch from "./activityPatch";import group from "./group";import workspace from "./workspace";import workspaceRole from "./workspaceRole";@@ -25,7 +26,6 @@ import loginInfo from "./loginInfo";* be done for all future factories*/export default {- ...activity,...user,...bookmark,...project,@@ -35,6 +35,8 @@ export default {...repository,...task,...taskPatch,+ ...activity,+ ...activityPatch,...group,...workspace,...workspaceRole,diff --git a/frontend/src/miragejs/models/index.js b/frontend/src/miragejs/models/index.jsindex e95c50cf41..af15ea5e7e 100644--- a/frontend/src/miragejs/models/index.js+++ b/frontend/src/miragejs/models/index.js@@ -39,6 +39,8 @@ export default {workspace: belongsTo(),}),+ activityPatch: Model,+group: Model.extend({workspace: belongsTo(),project: hasMany(),diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.jsindex 153d68482d..3bd671f991 100644--- a/frontend/src/miragejs/routes/index.js+++ b/frontend/src/miragejs/routes/index.js@@ -339,6 +339,19 @@ export default function routes() {return createdActivity;});+ this.patch("/activity/:activityId", function (schema, request) {+ const attrs = this.normalizedRequestAttrs("activity-patch");+ const activity = schema.activities.find(request.params.activityId);+ if (activity) {+ return activity.update({ ...attrs, lastUpdatedTs: Date.now() });+ }+ return new Response(+ 404,+ {},+ { errors: "Activity " + request.params.activityId + " not found" }+ );+ });+this.delete("/activity/:activityId", function (schema, request) {return schema.activities.find(request.params.activityId).destroy();});diff --git a/frontend/src/store/modules/activity.ts b/frontend/src/store/modules/activity.tsindex aeafeb1c55..3f2c3012cc 100644--- a/frontend/src/store/modules/activity.ts+++ b/frontend/src/store/modules/activity.ts@@ -2,8 +2,10 @@ import axios from "axios";import {UserId,TaskId,+ ActivityId,Activity,ActivityNew,+ ActivityPatch,ActivityState,} from "../../types";@@ -51,6 +53,34 @@ const actions = {return createdActivity;},+ async updateComment(+ { dispatch }: any,+ {+ activityId,+ updatedComment,+ }: { activityId: ActivityId; updatedComment: string }+ ) {+ const updatedActivity = (+ await axios.patch(`/api/activity/${activityId}`, {+ data: {+ type: "activitypatch",+ attributes: {+ payload: {+ content: updatedComment,+ },+ },+ },+ })+ ).data.data;++ dispatch(+ "fetchActivityListForTask",+ updatedActivity.attributes.containerId+ );++ return updatedActivity;+ },+async deleteActivity({ dispatch }: any, activity: Activity) {await axios.delete(`/api/activity/${activity.id}`);diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.tsindex ce8cf61392..2590ef4b71 100644--- a/frontend/src/types/bytebase.ts+++ b/frontend/src/types/bytebase.ts@@ -160,6 +160,10 @@ export type Activity = ResourceObject & {};export type ActivityNew = Omit<Activity, "id">;+export type ActivityPatch = {+ payload: any;+};+// Environmentexport type Environment = ResourceObject & {attributes: {diff --git a/frontend/src/views/TaskActivityPanel.vue b/frontend/src/views/TaskActivityPanel.vueindex 356c5a75dc..486ea78f9b 100644--- a/frontend/src/views/TaskActivityPanel.vue+++ b/frontend/src/views/TaskActivityPanel.vue@@ -70,36 +70,105 @@class="link whitespace-nowrap">{{ humanizeTs(activity.attributes.createdTs) }}</a>+ <template+ v-if="+ activity.attributes.createdTs !=+ activity.attributes.lastUpdatedTs &&+ activity.attributes.actionType ==+ 'bytebase.task.comment.create'+ "+ >+ (edited+ {{ humanizeTs(activity.attributes.createdTs) }})+ </template></div><divv-if="currentUser.id == activity.attributes.creator.id"class="space-x-2 text-control-light">- <!-- Delete Comment Button-->- <button- class="btn-icon"- @click.prevent="- {- state.activeComment = activity;- state.showDeleteCommentModal = true;- }+ <template+ v-if="+ state.editCommentMode &&+ state.activeComment.id == activity.id">- <svg- class="w-4 h-4"- fill="none"- stroke="currentColor"- viewBox="0 0 24 24"- xmlns="http://www.w3.org/2000/svg"+ <button+ type="button"+ class="text-control hover:bg-control-bg-hover disabled:bg-control-bg disabled:opacity-50 disabled:cursor-not-allowed px-2 text-xs leading-5 font-normal focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-2"+ @click.prevent="+ {+ editComment = '';+ state.editCommentMode = false;+ state.activeComment = null;+ }+ ">- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"- ></path>- </svg>- </button>+ Cancel+ </button>+ <button+ type="button"+ class="border border-control-border rounded-sm text-control bg-control-bg hover:bg-control-bg-hover disabled:bg-control-bg disabled:opacity-50 disabled:cursor-not-allowed px-2 text-xs leading-5 font-normal focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-2"+ @click.prevent="+ updateComment(activity.id, editComment)+ "+ >+ Save+ </button>+ </template>+ <template v-else>+ <!-- Delete Comment Button-->+ <button+ class="btn-icon"+ @click.prevent="+ {+ state.activeComment = activity;+ state.showDeleteCommentModal = true;+ }+ "+ >+ <svg+ class="w-4 h-4"+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"+ ></path>+ </svg>+ </button>+ <!-- Edit Comment Button-->+ <button+ class="btn-icon"+ @click.prevent="+ {+ editComment =+ activity.attributes.payload.content;+ state.activeComment = activity;+ state.editCommentMode = true;+ }+ "+ >+ <svg+ class="w-4 h-4"+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"+ ></path>+ </svg>+ </button>+ </template></div></div><template@@ -111,7 +180,34 @@<divclass="mt-2 text-sm text-control whitespace-pre-wrap">- {{ activity.attributes.payload.content }}+ <template+ v-if="+ state.editCommentMode &&+ state.activeComment.id == activity.id+ "+ >+ <BBAutoResize>+ <template v-slot:default="{ resize }">+ <label for="comment" class="sr-only"+ >Edit Comment</label+ >+ <textarea+ rows="3"+ class="resize-none shadow-sm block w-full focus:ring-gray-900 focus:border-gray-900 sm:text-sm border-gray-300 rounded-md"+ placeholder="Leave a comment..."+ v-model="editComment"+ @input="+ (e) => {+ resize(e);+ }+ "+ ></textarea>+ </template>+ </BBAutoResize>+ </template>+ <template v-else>+ {{ activity.attributes.payload.content }}+ </template></div></template></div>@@ -121,7 +217,7 @@</ul></div>- <div class="mt-6">+ <div v-if="!state.editCommentMode" class="mt-6"><div class="flex space-x-3"><div class="flex-shrink-0"><div class="relative">@@ -149,10 +245,8 @@<div class="min-w-0 flex-1"><BBAutoResize><template v-slot:default="{ resize }">- <label for="comment" class="sr-only">Comment</label>+ <label for="comment" class="sr-only">Create Comment</label><textarea- id="comment"- name="comment"rows="3"class="resize-none shadow-sm block w-full focus:ring-gray-900 focus:border-gray-900 sm:text-sm border-gray-300 rounded-md"placeholder="Leave a comment..."@@ -169,7 +263,6 @@<buttontype="button"class="btn-normal"- ref="commentButton":disabled="comment.length == 0"@click.prevent="createComment">@@ -204,10 +297,11 @@import { computed, inject, ref, reactive, watchEffect, PropType } from "vue";import { useStore } from "vuex";import { UserStateSymbol } from "../components/ProvideUser.vue";-import { User, Task, TaskActionType, Activity } from "../types";+import { User, Task, TaskActionType, Activity, ActivityId } from "../types";interface LocalState {showDeleteCommentModal: boolean;+ editCommentMode: boolean;activeComment?: Activity;}@@ -223,10 +317,11 @@ export default {setup(props, ctx) {const store = useStore();const comment = ref("");- const commentButton = ref();+ const editComment = ref("");const state = reactive<LocalState>({showDeleteCommentModal: false,+ editCommentMode: false,});const currentUser = inject<User>(UserStateSymbol);@@ -267,6 +362,22 @@ export default {});};+ const updateComment = (activityId: ActivityId, updatedComment: string) => {+ const activityPatch = store+ .dispatch("activity/updateComment", {+ activityId,+ updatedComment,+ })+ .then(() => {+ editComment.value = "";+ state.editCommentMode = false;+ state.activeComment = undefined;+ })+ .catch((error) => {+ console.log(error);+ });+ };+const deleteComment = (activity: Activity) => {store.dispatch("activity/deleteActivity", activity).catch((error) => {console.log(error);@@ -289,11 +400,12 @@ export default {return {state,comment,- commentButton,+ editComment,currentUser,activityList,actionSentence,createComment,+ updateComment,deleteComment,};},