Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Add Subscriber list UI to the task sidebar
天舟c95321fd8e4d
diff --git a/frontend/src/bbkit/BBAvatar.vue b/frontend/src/bbkit/BBAvatar.vueindex afd1ac8620..bfae180470 100644--- a/frontend/src/bbkit/BBAvatar.vue+++ b/frontend/src/bbkit/BBAvatar.vue@@ -2,7 +2,7 @@<!-- This div is used to insulate it from outside element to prevent resizing the BBAvatar --><div><div- class="flex tracking-wide justify-center items-center select-none"+ class="flex justify-center items-center select-none":class="textClass":style="[style]">diff --git a/frontend/src/miragejs/routes/task.js b/frontend/src/miragejs/routes/task.jsindex 884cf728d3..4c2fc490e2 100644--- a/frontend/src/miragejs/routes/task.js+++ b/frontend/src/miragejs/routes/task.js@@ -118,6 +118,16 @@ export default function configureTask(route) {}}+ if (attrs.subscriberIdList !== undefined) {+ if (task.subscriberIdList != attrs.subscriberIdList) {+ changeList.push({+ fieldId: TaskBuiltinFieldId.SUBSCRIBER_LIST,+ oldValue: task.subscriberIdList,+ newValue: attrs.subscriberIdList,+ });+ }+ }+if (attrs.sql !== undefined) {if (task.sql != attrs.sql) {changeList.push({diff --git a/frontend/src/miragejs/seeds/index.ts b/frontend/src/miragejs/seeds/index.tsindex 9a01f5d5aa..3c46f11efe 100644--- a/frontend/src/miragejs/seeds/index.ts+++ b/frontend/src/miragejs/seeds/index.ts@@ -116,7 +116,7 @@ const workspacesSeeder = (server: any) => {"SELECT 'Welcome'\nFROM engineering\nWHERE role IN ('DBA', 'Developer') AND taste = 'Good';",creatorId: ws1Dev1.id,assigneeId: ws1Owner.id,- subscriberIdList: [ws1DBA.id, ws1Dev2.id],+ subscriberIdList: [ws1DBA.id, ws1Dev2.id, ws1Dev1.id, ws1Owner.id],stageList: [{id: "1",diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.tsindex 740d2463ca..a79dd8e504 100644--- a/frontend/src/plugins/types.ts+++ b/frontend/src/plugins/types.ts@@ -24,6 +24,7 @@ export enum TaskBuiltinFieldId {STAGE = "9", // The full id is concatenated with the actual stage id e.g. "8".<<stage id>>SQL = "10",ROLLBACK_SQL = "11",+ SUBSCRIBER_LIST = "12",}export const INPUT_CUSTOM_FIELD_ID_BEGIN = "100";diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.tsindex 0549c86877..7f51db6c5f 100644--- a/frontend/src/types/bytebase.ts+++ b/frontend/src/types/bytebase.ts@@ -344,6 +344,7 @@ export type TaskPatch = {name?: string;status?: TaskStatus;description?: string;+ subscriberIdList?: PrincipalId[];sql?: string;rollbackSql?: string;assigneeId?: PrincipalId;diff --git a/frontend/src/views/TaskActivityPanel.vue b/frontend/src/views/TaskActivityPanel.vueindex b3c24eb183..e1f9f2a960 100644--- a/frontend/src/views/TaskActivityPanel.vue+++ b/frontend/src/views/TaskActivityPanel.vue@@ -374,8 +374,24 @@ export default {watchEffect(prepareActivityList);+ // Filter out the subscriber changeconst activityList = computed(() =>- store.getters["activity/activityListByTask"](props.task.id)+ store.getters["activity/activityListByTask"](props.task.id).filter(+ (activity: Activity) => {+ if (activity.actionType == "bytebase.task.field.update") {+ let containUserVisibleChange = false;+ for (const update of (activity.payload as ActionTaskFieldUpdatePayload)+ ?.changeList || []) {+ if (update.fieldId != TaskBuiltinFieldId.SUBSCRIBER_LIST) {+ containUserVisibleChange = true;+ break;+ }+ }+ return containUserVisibleChange;+ }+ return true;+ }+ ));const cancelEditComment = () => {@@ -489,6 +505,8 @@ export default {name = "Rollback SQL";oldValue = update.oldValue;newValue = update.newValue;+ } else if (update.fieldId == TaskBuiltinFieldId.SUBSCRIBER_LIST) {+ continue;} else {const field = fieldFromId(props.taskTemplate, update.fieldId);name = field.name;diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vueindex 0a6882d49f..645fde074e 100644--- a/frontend/src/views/TaskDetail.vue+++ b/frontend/src/views/TaskDetail.vue@@ -95,6 +95,7 @@:fieldList="inputFieldList":allowEdit="allowEditSidebar"@update-assignee-id="updateAssigneeId"+ @update-subscriber-list="updateSubscriberIdList"@update-custom-field="updateCustomField"/></div>@@ -573,6 +574,12 @@ export default {}};+ const updateSubscriberIdList = (newSubscriberIdList: PrincipalId[]) => {+ patchTask({+ subscriberIdList: newSubscriberIdList,+ });+ };+const updateCustomField = (field: TaskField, value: any) => {console.log("updateCustomField", field.name, value);if (!isEqual(state.task.payload[field.id], value)) {@@ -750,6 +757,7 @@ export default {tryStartTaskStatusTransition,doTaskStatusTransition,updateAssigneeId,+ updateSubscriberIdList,updateCustomField,doCreate,changeStageStatus,diff --git a/frontend/src/views/TaskSidebar.vue b/frontend/src/views/TaskSidebar.vueindex af52043a4b..82d6c74f12 100644--- a/frontend/src/views/TaskSidebar.vue+++ b/frontend/src/views/TaskSidebar.vue@@ -136,6 +136,53 @@{{ moment(task.createdTs).format("LLL") }}</span></div>+ <div+ v-if="!$props.new"+ class="mt-6 border-t border-block-border pt-6 grid gap-y-4 gap-x-6 grid-cols-3"+ >+ <h2+ class="textlabel flex items-center col-span-1 col-start-1 whitespace-nowrap"+ >+ {{+ task.subscriberList.length ++ (task.subscriberList.length > 1 ? " subscribers" : " subscriber")+ }}+ </h2>+ <div v-if="subscriberList.length > 0" class="col-span-3 col-start-1">+ <div class="flex space-x-1">+ <template v-for="(subscriber, index) in subscriberList" :key="index">+ <router-link :to="`/u/${subscriber.id}`" class="hover:opacity-75">+ <BBAvatar :size="'small'" :username="subscriber.name" />+ </router-link>+ </template>+ </div>+ </div>+ <button+ type="button"+ class="btn-normal items-center col-span-3 col-start-1"+ @click.prevent="toggleSubscription"+ >+ <span class="w-full">+ <svg+ class="h-5 w-5 text-control inline -mt-0.5 mr-1"+ fill="currentColor"+ viewBox="0 0 20 20"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ v-if="isCurrentUserSubscribed"+ fill-rule="evenodd"+ d="M13.477 14.89A6 6 0 015.11 6.524l8.367 8.368zm1.414-1.414L6.524 5.11a6 6 0 018.367 8.367zM18 10a8 8 0 11-16 0 8 8 0 0116 0z"+ clip-rule="evenodd"+ ></path>+ <path+ v-else+ d="M10 2a6 6 0 00-6 6v3.586l-.707.707A1 1 0 004 14h12a1 1 0 00.707-1.707L16 11.586V8a6 6 0 00-6-6zM10 18a3 3 0 01-3-3h6a3 3 0 01-3 3z"+ ></path></svg+ >{{ isCurrentUserSubscribed ? "Unsubscribe" : "Subscribe" }}</span+ >+ </button>+ </div></aside></template>@@ -153,14 +200,24 @@ import {TaskBuiltinFieldId,DatabaseFieldPayload,} from "../plugins";-import { DatabaseId, EnvironmentId, Task } from "../types";+import {+ DatabaseId,+ EnvironmentId,+ Principal,+ PrincipalId,+ Task,+} from "../types";import { isDBA } from "../utils";interface LocalState {}export default {name: "TaskSidebar",- emits: ["update-assignee-id", "update-custom-field"],+ emits: [+ "update-assignee-id",+ "update-subscriber-list",+ "update-custom-field",+ ],props: {task: {required: true,@@ -199,6 +256,28 @@ export default {return props.task.payload[TaskBuiltinFieldId.ENVIRONMENT];});+ const isCurrentUserSubscribed = computed((): boolean => {+ for (const principal of props.task.subscriberList) {+ if (currentUser.value.id == principal.id) {+ return true;+ }+ }+ return false;+ });++ const subscriberList = computed((): Principal[] => {+ const list: Principal[] = [];+ props.task.subscriberList.forEach((principal: Principal) => {+ // Put the current user at the front if in the list.+ if (currentUser.value.id == principal.id) {+ list.unshift(principal);+ } else {+ list.push(principal);+ }+ });+ return list;+ });+const allowEditAssignee = computed(() => {// We allow the current assignee or DBA to re-assign the task.// Though only DBA can be assigned to the task, the current@@ -257,16 +336,39 @@ export default {trySaveCustomField(field, payload);};+ const toggleSubscription = () => {+ const list = cloneDeep(props.task.subscriberList);+ if (isCurrentUserSubscribed.value) {+ const index = props.task.subscriberList.findIndex((item: Principal) => {+ return item.id == currentUser.value.id;+ });+ if (index >= 0) {+ list.splice(index, 1);+ }+ } else {+ list.push(currentUser.value);+ }+ emit(+ "update-subscriber-list",+ list.map((item: Principal) => {+ return item.id;+ })+ );+ };+return {state,allowEditAssignee,fieldValue,environmentId,+ isCurrentUserSubscribed,+ subscriberList,trySaveCustomField,trySaveDatabaseNew,trySaveDatabaseName,trySaveDatabaseId,trySaveDatabaseReadOnly,+ toggleSubscription,};},};