Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Use a new Activity type which is decoupled from the underlying API model
Tianzhou Chen45c5e256fef9
diff --git a/frontend/src/plugins/task/template.ts b/frontend/src/plugins/task/template.tsindex 1e02b5bb66..329fb34830 100644--- a/frontend/src/plugins/task/template.ts+++ b/frontend/src/plugins/task/template.ts@@ -11,25 +11,23 @@ const allTaskTemplateList: TaskTemplate[] = [type: "bytebase.general",buildTask: (ctx: TemplateContext): TaskNew => {return {- type: "task",- attributes: {- name: "New General Task",- type: "bytebase.general",- description: "",- stageProgressList: [- {- id: "1",- name: "Request",- type: "SIMPLE",- status: "PENDING",- },- ],- creator: {- id: ctx.currentUser.id,- name: ctx.currentUser.attributes.name,+ name: "New General Task",+ type: "bytebase.general",+ description: "",+ stageProgressList: [+ {+ id: "1",+ name: "Request",+ type: "SIMPLE",+ status: "PENDING",},- payload: {},+ ],+ creatorId: ctx.currentUser.id,+ creator: {+ id: ctx.currentUser.id,+ name: ctx.currentUser.attributes.name,},+ payload: {},};},},@@ -37,25 +35,23 @@ const allTaskTemplateList: TaskTemplate[] = [type: "bytebase.datasource.create",buildTask: (ctx: TemplateContext): TaskNew => {return {- type: "task",- attributes: {- name: "New Data Source",- type: "bytebase.datasource.create",- description: "Estimated QPS: 10",- stageProgressList: [- {- id: "1",- name: "Request Data Source",- type: "SIMPLE",- status: "PENDING",- },- ],- creator: {- id: ctx.currentUser.id,- name: ctx.currentUser.attributes.name,+ name: "New Data Source",+ type: "bytebase.datasource.create",+ description: "Estimated QPS: 10",+ stageProgressList: [+ {+ id: "1",+ name: "Request Data Source",+ type: "SIMPLE",+ status: "PENDING",},- payload: {},+ ],+ creatorId: ctx.currentUser.id,+ creator: {+ id: ctx.currentUser.id,+ name: ctx.currentUser.attributes.name,},+ payload: {},};},fieldList: [@@ -101,31 +97,29 @@ const allTaskTemplateList: TaskTemplate[] = [type: "bytebase.datasource.schema.update",buildTask: (ctx: TemplateContext): TaskNew => {return {- type: "task",- attributes: {- name: "Update Schema",- type: "bytebase.datasource.schema.update",- description: "DDL: ",- stageProgressList: ctx.environmentList.map((env) => {- return {- id: env.id,- name: env.attributes.name,- type: "ENVIRONMENT",- status: "PENDING",- runnable: {- auto: true,- run: () => {- console.log("Start", env.attributes.name);- },+ name: "Update Schema",+ type: "bytebase.datasource.schema.update",+ description: "DDL: ",+ stageProgressList: ctx.environmentList.map((env) => {+ return {+ id: env.id,+ name: env.name,+ type: "ENVIRONMENT",+ status: "PENDING",+ runnable: {+ auto: true,+ run: () => {+ console.log("Start", env.name);},- };- }),- creator: {- id: ctx.currentUser.id,- name: ctx.currentUser.attributes.name,- },- payload: {},+ },+ };+ }),+ creatorId: ctx.currentUser.id,+ creator: {+ id: ctx.currentUser.id,+ name: ctx.currentUser.attributes.name,},+ payload: {},};},fieldList: [diff --git a/frontend/src/store/modules/activity.ts b/frontend/src/store/modules/activity.tsindex fa5e812fc0..e5bff97779 100644--- a/frontend/src/store/modules/activity.ts+++ b/frontend/src/store/modules/activity.ts@@ -7,8 +7,16 @@ import {ActivityNew,ActivityPatch,ActivityState,+ ResourceObject,} from "../../types";+function convert(activity: ResourceObject): Activity {+ return {+ id: activity.id,+ ...(activity.attributes as Omit<Activity, "id">),+ };+}+const state: () => ActivityState = () => ({activityListByUser: new Map(),activityListByTask: new Map(),@@ -25,7 +33,12 @@ const getters = {const actions = {async fetchActivityListForUser({ commit }: any, userId: UserId) {- const activityList = (await axios.get(`/api/activity`)).data.data;+ const activityList = (await axios.get(`/api/activity`)).data.data.map(+ (activity: ResourceObject) => {+ return convert(activity);+ }+ );+commit("setActivityListForUser", { userId, activityList });return activityList;},@@ -33,21 +46,29 @@ const actions = {async fetchActivityListForTask({ commit }: any, taskId: TaskId) {const activityList = (await axios.get(`/api/activity?containerid=${taskId}&type=bytebase.task.`)- ).data.data;+ ).data.data.map((activity: ResourceObject) => {+ return convert(activity);+ });+commit("setActivityListForTask", { taskId, activityList });return activityList;},async createActivity({ dispatch }: any, newActivity: ActivityNew) {- const createdActivity: Activity = (- await axios.post(`/api/activity`, {- data: newActivity,- })- ).data.data;+ const createdActivity: Activity = convert(+ (+ await axios.post(`/api/activity`, {+ data: {+ type: "activity",+ attributes: 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);+ if (newActivity.actionType.startsWith("bytebase.task.")) {+ dispatch("fetchActivityListForTask", newActivity.containerId);}return createdActivity;@@ -60,32 +81,31 @@ const actions = {updatedComment,}: { activityId: ActivityId; updatedComment: string }) {- const updatedActivity = (- await axios.patch(`/api/activity/${activityId}`, {- data: {- type: "activitypatch",- attributes: {- payload: {- comment: updatedComment,+ const updatedActivity = convert(+ (+ await axios.patch(`/api/activity/${activityId}`, {+ data: {+ type: "activitypatch",+ attributes: {+ payload: {+ comment: updatedComment,+ },},},- },- })- ).data.data;-- dispatch(- "fetchActivityListForTask",- updatedActivity.attributes.containerId+ })+ ).data.data);+ dispatch("fetchActivityListForTask", updatedActivity.containerId);+return updatedActivity;},async deleteActivity({ dispatch }: any, activity: Activity) {await axios.delete(`/api/activity/${activity.id}`);- if (activity.attributes.actionType.startsWith("bytebase.task.")) {- dispatch("fetchActivityListForTask", activity.attributes.containerId);+ if (activity.actionType.startsWith("bytebase.task.")) {+ dispatch("fetchActivityListForTask", activity.containerId);}},};diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.tsindex c4494628d2..f05e8ff46c 100644--- a/frontend/src/store/modules/task.ts+++ b/frontend/src/store/modules/task.ts@@ -55,7 +55,12 @@ const actions = {const createdTask = convert((await axios.post(`/api/task`, {- data: newTask,+ data: {+ type: "task",+ attributes: {+ ...newTask,+ },+ },})).data.data);diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.tsindex 3783a40c4d..bf501a7528 100644--- a/frontend/src/types/bytebase.ts+++ b/frontend/src/types/bytebase.ts@@ -134,7 +134,7 @@ export type TaskNew = {description: string;stageProgressList: StageProgress[];creatorId: PrincipalId;- assigneeId: PrincipalId;+ assigneeId?: PrincipalId;creator: UserDisplay;assignee?: UserDisplay;payload: TaskPayload;@@ -174,18 +174,17 @@ export type ActionPayloadType =| ActionTaskCommentCreatePayload| ActionTaskFieldUpdatePayload;-export type Activity = ResourceObject & {- attributes: {- createdTs: number;- lastUpdatedTs: number;- actionType: ActionType;- // The object where this activity belongs- // e.g if actionType is "bytebase.task.xxx", then this field refers to the corresponding task's id.- containerId: TaskId;- creatorId: PrincipalId;- creator: UserDisplay;- payload?: ActionPayloadType;- };+export type Activity = {+ id: ActivityId;+ createdTs: number;+ lastUpdatedTs: number;+ actionType: ActionType;+ // The object where this activity belongs+ // e.g if actionType is "bytebase.task.xxx", then this field refers to the corresponding task's id.+ containerId: TaskId;+ creatorId: PrincipalId;+ creator: UserDisplay;+ payload?: ActionPayloadType;};export type ActivityNew = Omit<Activity, "id">;diff --git a/frontend/src/views/TaskActivityPanel.vue b/frontend/src/views/TaskActivityPanel.vueindex 98677d0716..830043fe19 100644--- a/frontend/src/views/TaskActivityPanel.vue+++ b/frontend/src/views/TaskActivityPanel.vue@@ -17,11 +17,7 @@aria-hidden="true"></span><div class="relative flex items-start">- <template- v-if="- activity.attributes.actionType == 'bytebase.task.create'- "- >+ <template v-if="activity.actionType == 'bytebase.task.create'"><div class="relative pl-0.5"><divclass="w-7 h-7 bg-control-bg rounded-full ring-8 ring-white flex items-center justify-center"@@ -43,8 +39,7 @@</template><templatev-else-if="- activity.attributes.actionType ==- 'bytebase.task.field.update'+ activity.actionType == 'bytebase.task.field.update'"><div class="relative pl-0.5">@@ -73,7 +68,7 @@<div class="relative"><BBAvatarclass="rounded-full ring-8 ring-white"- :username="activity.attributes.creator.name"+ :username="activity.creator.name"></BBAvatar></div>@@ -82,32 +77,30 @@<div class="min-w-0 flex-1 pt-1 flex justify-between"><div class="text-sm text-control-light"><span class="font-medium text-main whitespace-nowrap">{{- activity.attributes.creator.name+ activity.creator.name}}</span><a:href="'#activity' + (index + 1)"class="ml-1 anchor-link whitespace-normal">{{ actionSentence(activity) }}- {{ humanizeTs(activity.attributes.createdTs) }}+ {{ humanizeTs(activity.createdTs) }}<templatev-if="- activity.attributes.createdTs !=- activity.attributes.lastUpdatedTs &&- activity.attributes.actionType ==+ activity.createdTs != activity.lastUpdatedTs &&+ activity.actionType =='bytebase.task.comment.create'">(edited- {{ humanizeTs(activity.attributes.createdTs) }})+ {{ humanizeTs(activity.createdTs) }})</template></a></div><divv-if="- currentUser.id == activity.attributes.creatorId &&- activity.attributes.actionType ==- 'bytebase.task.comment.create'+ currentUser.id == activity.creatorId &&+ activity.actionType == 'bytebase.task.comment.create'"class="space-x-2 text-control-light">@@ -129,7 +122,7 @@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":disabled="editComment.length == 0 ||- editComment == activity.attributes.payload.comment+ editComment == activity.payload.comment"@click.prevent="doUpdateComment">@@ -187,10 +180,7 @@</div></div><template- v-if="- activity.attributes.actionType ==- 'bytebase.task.comment.create'- "+ v-if="activity.actionType == 'bytebase.task.comment.create'"><div class="mt-2 text-sm text-control whitespace-pre-wrap"><template@@ -221,7 +211,7 @@></textarea></template><template v-else>- {{ activity.attributes.payload.comment }}+ {{ activity.payload.comment }}</template></div></template>@@ -419,17 +409,14 @@ export default {const doCreateComment = () => {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: {- comment: newComment.value,- },+ actionType: "bytebase.task.comment.create",+ containerId: props.task.id,+ creator: {+ id: currentUser.id,+ name: currentUser.attributes.name,+ },+ payload: {+ comment: newComment.value,},}).then(() => {@@ -442,8 +429,7 @@ export default {};const onUpdateComment = (activity: Activity) => {- editComment.value = (activity.attributes- .payload! as ActionTaskCommentCreatePayload).comment;+ editComment.value = (activity.payload! as ActionTaskCommentCreatePayload).comment;state.activeComment = activity;state.editCommentMode = true;nextTick(() => {@@ -472,15 +458,15 @@ export default {};const actionSentence = (activity: Activity): string => {- switch (activity.attributes.actionType) {+ switch (activity.actionType) {case "bytebase.task.create":return "created task";case "bytebase.task.comment.create":return "commented";case "bytebase.task.field.update": {const updateInfoList: string[] = [];- for (const update of (activity.attributes- .payload as ActionTaskFieldUpdatePayload)?.changeList || []) {+ for (const update of (activity.payload as ActionTaskFieldUpdatePayload)+ ?.changeList || []) {let name = "Unknown Field";let oldValue = undefined;let newValue = undefined;diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vueindex 11d151dabf..e45100d3e6 100644--- a/frontend/src/views/TaskDetail.vue+++ b/frontend/src/views/TaskDetail.vue@@ -397,7 +397,7 @@ export default {...taskPatch,producer: {id: currentUser.id,- name: currentUser.name,+ name: currentUser.attributes.name,},},})