Skip to content

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

Update task activity description

Tianzhou Chen857259c26f24
diff --git a/frontend/src/miragejs/factories/taskPatch.js b/frontend/src/miragejs/factories/taskPatch.js
index a2909155c5..01953af150 100644
--- a/frontend/src/miragejs/factories/taskPatch.js
+++ b/frontend/src/miragejs/factories/taskPatch.js
@@ -3,6 +3,12 @@ import faker from "faker";
export default {
taskPatch: Factory.extend({
+ producer() {
+ return {
+ id: "100",
+ name: "Ed Codd",
+ };
+ },
name(i) {
return faker.fake("{{lorem.sentence}}");
},
@@ -28,11 +34,8 @@ export default {
},
payload() {
return {
- type: "bytebase.datasource.create",
- fieldList: {
- // Requested Database name
- 1: "Mydb",
- },
+ // Requested Database name
+ 1: "Mydb",
};
},
}),
diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.js
index 3bd671f991..8467aa57c1 100644
--- a/frontend/src/miragejs/routes/index.js
+++ b/frontend/src/miragejs/routes/index.js
@@ -1,8 +1,6 @@
/*
* Mirage JS guide on Routes: https://miragejs.com/docs/route-handlers/functions
*/
-
-import { create } from "lodash-es";
import { Response } from "miragejs";
const WORKSPACE_ID = 1;
@@ -117,7 +115,34 @@ export default function routes() {
return item;
});
}
- return task.update({ ...attrs, lastUpdatedTs: Date.now() });
+
+ const changeList = [];
+ for (const fieldId in attrs.payload) {
+ const oldValue = task.payload[fieldId];
+ const newValue = attrs.payload[fieldId];
+ if (oldValue != newValue) {
+ changeList.push({
+ fieldId: fieldId,
+ oldValue: task.payload[fieldId],
+ newValue: attrs.payload[fieldId],
+ });
+ }
+ }
+
+ const ts = Date.now();
+ const updatedTask = task.update({ ...attrs, lastUpdatedTs: ts });
+
+ schema.activities.create({
+ createdTs: ts,
+ lastUpdatedTs: ts,
+ actionType: "bytebase.task.field.update",
+ containerId: updatedTask.id,
+ creator: attrs.producer,
+ payload: changeList.length > 0 ? { changeList } : undefined,
+ workspaceId: WORKSPACE_ID,
+ });
+
+ return updatedTask;
}
return new Response(
404,
diff --git a/frontend/src/plugins/task/template.ts b/frontend/src/plugins/task/template.ts
index f2f8409708..8baf45ccb3 100644
--- a/frontend/src/plugins/task/template.ts
+++ b/frontend/src/plugins/task/template.ts
@@ -1,4 +1,9 @@
-import { TaskTemplate, TemplateContext } from "../types";
+import {
+ TaskField,
+ TaskFieldId,
+ TaskTemplate,
+ TemplateContext,
+} from "../types";
import { EnvironmentId, TaskType, TaskNew } from "../../types";
const allTaskTemplateList: TaskTemplate[] = [
@@ -145,3 +150,13 @@ const allTaskTemplateList: TaskTemplate[] = [
export function templateForType(type: TaskType): TaskTemplate | undefined {
return allTaskTemplateList.find((template) => template.type === type);
}
+
+export function fieldFromId(
+ template: TaskTemplate,
+ fieldId: TaskFieldId
+): TaskField | undefined {
+ if (template.fieldList) {
+ return template.fieldList.find((field) => field.id == fieldId);
+ }
+ return undefined;
+}
diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.ts
index 7bd9bdff27..a91db66e4c 100644
--- a/frontend/src/plugins/types.ts
+++ b/frontend/src/plugins/types.ts
@@ -1,6 +1,14 @@
import { Environment, TaskNew, User } from "../types";
// Task
+export type TaskFieldId = number;
+
+export enum TaskBuiltinFieldId {
+ STATUS = 10000,
+ ASSIGNEE = 10001,
+ REPORTER = 10002,
+}
+
export type TaskFieldType = "String" | "Environment";
export type TaskField = {
@@ -8,7 +16,7 @@ export type TaskField = {
// Used as the key to store the data. This must NOT be changed after
// in use, otherwise, it will cause data loss/corruption. Its design
// is very similar to the message field id in Protocol Buffers.
- id: number;
+ id: TaskFieldId;
// Used as the key to generate UI artifacts (e.g. query parameter).
// Though changing it won't have catastrophic consequence like changing
// id, we strongly recommend NOT to change it as well, otherwise, previous
@@ -34,13 +42,6 @@ export type TemplateContext = {
currentUser: User;
};
-export type TemplateOutputField = {
- // Similar to TaskField.id above
- id: number;
- name: string;
- required: boolean;
-};
-
export type TaskTemplate = {
type: string;
buildTask: (ctx: TemplateContext) => TaskNew;
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 2590ef4b71..08f6bfefc7 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -1,5 +1,6 @@
import { ResourceObject } from "./jsonapi";
import { BBNotificationStyle } from "../bbkit/types";
+import { TaskFieldId } from "../plugins";
// These ID format may change in the future, so we encapsulate with a type.
// Also good for readability.
@@ -76,6 +77,8 @@ export type TaskType = TaskTypeGeneral | TaskTypeDataSource;
export type TaskStatus = "OPEN" | "DONE" | "CANCELED";
+export type TaskPayload = { [key: string]: any };
+
export type Task = ResourceObject & {
attributes: {
name: string;
@@ -95,7 +98,7 @@ export type Task = ResourceObject & {
name: string;
};
subscriberIdList: Array<string>;
- payload: any;
+ payload: TaskPayload;
};
};
@@ -113,7 +116,7 @@ export type TaskNew = Omit<ResourceObject, "id"> & {
id: string;
name: string;
};
- payload: any;
+ payload: TaskPayload;
};
};
@@ -126,7 +129,7 @@ export type TaskPatch = {
name: string;
};
stageProgressList?: StageProgressPatch[];
- payload?: any;
+ payload?: TaskPayload;
};
// Activity
@@ -137,11 +140,21 @@ export type TaskActionType =
export type ActionType = TaskActionType;
-export type ActionCommentCreatePayload = {
+export type ActionTaskCommentCreatePayload = {
content: string;
};
-export type ActionPayloadType = ActionCommentCreatePayload;
+export type ActionTaskFieldUpdatePayload = {
+ changeList: {
+ fieldId: TaskFieldId;
+ oldValue?: string;
+ newValue?: string;
+ }[];
+};
+
+export type ActionPayloadType =
+ | ActionTaskCommentCreatePayload
+ | ActionTaskFieldUpdatePayload;
export type Activity = ResourceObject & {
attributes: {
diff --git a/frontend/src/views/TaskActivityPanel.vue b/frontend/src/views/TaskActivityPanel.vue
index f0b68f348f..202994d970 100644
--- a/frontend/src/views/TaskActivityPanel.vue
+++ b/frontend/src/views/TaskActivityPanel.vue
@@ -62,7 +62,7 @@
:href="'#activity' + (index + 1)"
class="ml-1 anchor-link whitespace-nowrap"
>
- {{ actionSentence(activity.attributes.actionType) }}
+ {{ actionSentence(activity) }}
{{ humanizeTs(activity.attributes.createdTs) }}
<template
v-if="
@@ -290,8 +290,17 @@ import {
} from "vue";
import { useStore } from "vuex";
import { UserStateSymbol } from "../components/ProvideUser.vue";
-import { User, Task, TaskActionType, Activity, ActivityId } from "../types";
+import {
+ User,
+ Task,
+ TaskActionType,
+ Activity,
+ ActionTaskCommentCreatePayload,
+ ActionTaskFieldUpdatePayload,
+ Environment,
+} from "../types";
import { sizeToFit } from "../utils";
+import { fieldFromId, TaskTemplate, TaskField } from "../plugins";
interface LocalState {
showDeleteCommentModal: boolean;
@@ -306,6 +315,10 @@ export default {
required: true,
type: Object as PropType<Task>,
},
+ taskTemplate: {
+ required: true,
+ type: Object as PropType<TaskTemplate>,
+ },
},
components: {},
setup(props, ctx) {
@@ -395,7 +408,8 @@ export default {
};
const onUpdateComment = (activity: Activity) => {
- editComment.value = activity.attributes.payload!.content;
+ editComment.value = (activity.attributes
+ .payload! as ActionTaskCommentCreatePayload).content;
state.activeComment = activity;
state.editCommentMode = true;
nextTick(() => {
@@ -423,14 +437,69 @@ export default {
});
};
- const actionSentence = (actionType: TaskActionType) => {
- switch (actionType) {
+ const actionSentence = (activity: Activity): string => {
+ switch (activity.attributes.actionType) {
case "bytebase.task.create":
return "created task";
case "bytebase.task.comment.create":
return "commented";
- case "bytebase.task.field.update":
+ case "bytebase.task.field.update": {
+ const updateInfoList: string[] = [];
+ for (const update of (activity.attributes
+ .payload as ActionTaskFieldUpdatePayload)?.changeList || []) {
+ const field = fieldFromId(props.taskTemplate, update.fieldId);
+ let name = "Unknown Field";
+ let oldValue = undefined;
+ let newValue = undefined;
+ if (field) {
+ name = field.name;
+ if (field.type === "String") {
+ oldValue = update.oldValue;
+ newValue = update.newValue;
+ } else if (field.type === "Environment") {
+ if (update.oldValue) {
+ const environment: Environment = store.getters[
+ "environment/environmentById"
+ ](update.oldValue);
+ if (environment) {
+ oldValue = environment.attributes.name;
+ } else {
+ oldValue = "Unknown Environment";
+ }
+ }
+ if (update.newValue) {
+ const environment: Environment = store.getters[
+ "environment/environmentById"
+ ](update.newValue);
+ if (environment) {
+ newValue = environment.attributes.name;
+ } else {
+ newValue = "Unknown Environment";
+ }
+ }
+ }
+ }
+ if (oldValue && newValue) {
+ updateInfoList.push(
+ "updated " +
+ name +
+ ' from "' +
+ oldValue +
+ '" to "' +
+ newValue +
+ '"'
+ );
+ } else if (oldValue) {
+ updateInfoList.push("removed " + name + ' "' + oldValue + '"');
+ } else if (newValue) {
+ updateInfoList.push("added " + name + ' "' + newValue + '"');
+ }
+ }
+ if (updateInfoList.length > 0) {
+ return updateInfoList.join("; ");
+ }
return "updated";
+ }
}
};
diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vue
index 526fe3c3d0..f9e746aa88 100644
--- a/frontend/src/views/TaskDetail.vue
+++ b/frontend/src/views/TaskDetail.vue
@@ -78,7 +78,10 @@
aria-labelledby="activity-title"
class="mt-8 lg:mt-10"
>
- <TaskActivityPanel :task="state.task" />
+ <TaskActivityPanel
+ :task="state.task"
+ :taskTemplate="taskTemplate"
+ />
</section>
</div>
<TaskSidebar
@@ -132,7 +135,7 @@ import {
TaskStatus,
StageStatus,
} from "../types";
-import { templateForType, TaskField, TaskTemplate } from "../plugins";
+import { templateForType, TaskField } from "../plugins";
type StageTransitionType = "RUN" | "RETRY" | "CANCEL" | "SKIP";
@@ -362,7 +365,13 @@ export default {
store
.dispatch("task/patchTask", {
taskId: (state.task as Task).id,
- taskPatch,
+ taskPatch: {
+ ...taskPatch,
+ producer: {
+ id: currentUser!.id,
+ name: currentUser!.attributes.name,
+ },
+ },
})
.then((updatedTask) => {
state.task = cloneDeep(updatedTask);
@@ -459,6 +468,7 @@ export default {
applicableStageTransitionList,
actionButtonClass,
currentUser,
+ taskTemplate,
outputFieldList,
inputFieldList,
showTaskFlowBar,