Skip to content

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

Support add comment

Tianzhou Chen2da55618629d
diff --git a/frontend/src/miragejs/models/index.js b/frontend/src/miragejs/models/index.js
index e722eebfc1..e95c50cf41 100644
--- a/frontend/src/miragejs/models/index.js
+++ b/frontend/src/miragejs/models/index.js
@@ -20,6 +20,7 @@ export default {
group: hasMany(),
project: hasMany(),
workspaceRole: hasMany(),
+ activity: hasMany(),
task: hasMany(),
environment: hasMany(),
instance: hasMany(),
diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.js
index bd7270d30e..4b672a8267 100644
--- a/frontend/src/miragejs/routes/index.js
+++ b/frontend/src/miragejs/routes/index.js
@@ -326,6 +326,19 @@ export default function routes() {
});
});
+ this.post("/activity", function (schema, request) {
+ const ts = Date.now();
+ const attrs = this.normalizedRequestAttrs("activity");
+ const newActivity = {
+ ...attrs,
+ createdTs: ts,
+ lastUpdatedTs: ts,
+ workspaceId: WORKSPACE_ID,
+ };
+ const createdActivity = schema.activities.create(newActivity);
+ return createdActivity;
+ });
+
// Group
this.get("/group", function (schema, request) {
const {
diff --git a/frontend/src/store/modules/activity.ts b/frontend/src/store/modules/activity.ts
index b8d7ce38f7..9459641753 100644
--- a/frontend/src/store/modules/activity.ts
+++ b/frontend/src/store/modules/activity.ts
@@ -1,5 +1,11 @@
import axios from "axios";
-import { UserId, TaskId, Activity, ActivityState } from "../../types";
+import {
+ UserId,
+ TaskId,
+ Activity,
+ ActivityNew,
+ ActivityState,
+} from "../../types";
const state: () => ActivityState = () => ({
activityListByUser: new Map(),
@@ -29,6 +35,21 @@ const actions = {
commit("setActivityListForTask", { taskId, activityList });
return activityList;
},
+
+ async createActivity({ dispatch }: any, newActivity: ActivityNew) {
+ const createdActivity: Activity = (
+ await axios.post(`/api/activity`, {
+ data: newActivity,
+ })
+ ).data.data;
+
+ // There might exist other activities happened since the last fetch, so we do a full refetch.
+ if (newActivity.attributes.actionType.startsWith("bytebase.task.")) {
+ dispatch("fetchActivityListForTask", newActivity.attributes.containerId);
+ }
+
+ return createdActivity;
+ },
};
const mutations = {
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 7bd9786a66..f28d0cf010 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -156,7 +156,7 @@ export type Activity = ResourceObject & {
payload?: ActionPayloadType;
};
};
-export type ActivityNew = Omit<Environment, "id">;
+export type ActivityNew = Omit<Activity, "id">;
// Environment
export type Environment = ResourceObject & {
diff --git a/frontend/src/views/TaskActivityPanel.vue b/frontend/src/views/TaskActivityPanel.vue
index 97c876cd3a..75c11e9a93 100644
--- a/frontend/src/views/TaskActivityPanel.vue
+++ b/frontend/src/views/TaskActivityPanel.vue
@@ -189,7 +189,27 @@ export default {
);
const createComment = () => {
- console.log(comment.value);
+ store
+ .dispatch("activity/createActivity", {
+ type: "activity",
+ attributes: {
+ actionType: "bytebase.task.comment.create",
+ containerId: props.task.id,
+ creator: {
+ id: currentUser!.id,
+ name: currentUser!.attributes.name,
+ },
+ payload: {
+ content: comment.value,
+ },
+ },
+ })
+ .then(() => {
+ comment.value = "";
+ })
+ .catch((error) => {
+ console.log(error);
+ });
};
watchEffect(prepareActivityList);