Skip to content

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

Bring inbox route back and rename message to inbox

天舟c14c99ee825f
diff --git a/frontend/src/components/IssueActivityPanel.vue b/frontend/src/components/IssueActivityPanel.vue
index e5c51e55bb..a35fcca6f5 100644
--- a/frontend/src/components/IssueActivityPanel.vue
+++ b/frontend/src/components/IssueActivityPanel.vue
@@ -562,7 +562,13 @@ import {
ActivityCreate,
IssueSubscriber,
} from "../types";
-import { findTaskById, issueActivityActionSentence, issueSlug, sizeToFit, stageSlug } from "../utils";
+import {
+ findTaskById,
+ issueActivityActionSentence,
+ issueSlug,
+ sizeToFit,
+ stageSlug,
+} from "../utils";
import { IssueTemplate, IssueBuiltinFieldId } from "../plugins";
interface LocalState {
@@ -818,8 +824,8 @@ export default {
};
const actionSentence = (activity: Activity): string => {
- if (activity.actionType.startsWith("bb.issue")) {
- return issueActivityActionSentence(activity)
+ if (activity.actionType.startsWith("bb.issue.")) {
+ return issueActivityActionSentence(activity);
}
switch (activity.actionType) {
case "bb.pipeline.task.status.update": {
@@ -856,6 +862,7 @@ export default {
return str;
}
}
+ return "";
};
return {
diff --git a/frontend/src/components/ProvideDashboardContext.vue b/frontend/src/components/ProvideDashboardContext.vue
index ec74986b15..14c3db7469 100644
--- a/frontend/src/components/ProvideDashboardContext.vue
+++ b/frontend/src/components/ProvideDashboardContext.vue
@@ -27,7 +27,6 @@ export default {
store.dispatch("environment/fetchEnvironmentList"),
// The default project hosts databases not explicitly assigned to other users project.
store.dispatch("project/fetchProjectById", DEFAULT_PROJECT_ID),
- store.dispatch("message/fetchMessageListByUser", currentUser.value.id),
store.dispatch("uistate/restoreState"),
]);
},
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index ad844af053..2fa4a250fd 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -45,12 +45,14 @@ import {
isRelease,
projectName,
projectSlug,
+ registerStoreWithActivityUtil,
registerStoreWithRoleUtil,
sizeToFit,
urlfy,
} from "./utils";
registerStoreWithRoleUtil(store);
+registerStoreWithActivityUtil(store);
console.debug("dev:", isDev());
console.debug("release:", isRelease());
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 242390454e..f61bed5e6d 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -178,19 +178,19 @@ const routes: Array<RouteRecordRaw> = [
leftSidebar: true,
},
},
- // {
- // path: "inbox",
- // name: "workspace.inbox",
- // meta: { title: () => "Inbox" },
- // components: {
- // content: () => import("../views/Inbox.vue"),
- // leftSidebar: DashboardSidebar,
- // },
- // props: {
- // content: true,
- // leftSidebar: true,
- // },
- // },
+ {
+ path: "inbox",
+ name: "workspace.inbox",
+ meta: { title: () => "Inbox" },
+ components: {
+ content: () => import("../views/Inbox.vue"),
+ leftSidebar: DashboardSidebar,
+ },
+ props: {
+ content: true,
+ leftSidebar: true,
+ },
+ },
{
path: "archive",
name: "workspace.archive",
@@ -768,7 +768,7 @@ router.beforeEach((to, from, next) => {
to.name === "error.500" ||
to.name === "oauth-callback" ||
to.name === "workspace.home" ||
- // to.name === "workspace.inbox" ||
+ to.name === "workspace.inbox" ||
to.name === "workspace.project" ||
to.name === "workspace.database" ||
to.name === "workspace.archive" ||
diff --git a/frontend/src/store/index.ts b/frontend/src/store/index.ts
index 8c7a478c09..70a6596fa5 100644
--- a/frontend/src/store/index.ts
+++ b/frontend/src/store/index.ts
@@ -10,11 +10,11 @@ import database from "./modules/database";
import dataSource from "./modules/dataSource";
import environment from "./modules/environment";
import gitlab from "./modules/gitlab";
+import inbox from "./modules/inbox";
import instance from "./modules/instance";
import issue from "./modules/issue";
import issueSubscriber from "./modules/issueSubscriber";
import member from "./modules/member";
-import message from "./modules/message";
import notification from "./modules/notification";
import pipeline from "./modules/pipeline";
import plan from "./modules/plan";
@@ -50,7 +50,7 @@ export const store: Store<any> = createStore({
issue,
issueSubscriber,
member,
- message,
+ inbox,
notification,
pipeline,
plan,
diff --git a/frontend/src/store/modules/activity.ts b/frontend/src/store/modules/activity.ts
index 218c649649..fe323af660 100644
--- a/frontend/src/store/modules/activity.ts
+++ b/frontend/src/store/modules/activity.ts
@@ -1,13 +1,13 @@
import axios from "axios";
import {
- PrincipalId,
- IssueId,
- ActivityId,
Activity,
ActivityCreate,
+ ActivityId,
+ ActivityPatch,
ActivityState,
+ IssueId,
+ PrincipalId,
ResourceObject,
- ActivityPatch,
} from "../../types";
function convert(
@@ -32,6 +32,12 @@ const state: () => ActivityState = () => ({
});
const getters = {
+ convert:
+ (state: ActivityState, getters: any, rootState: any, rootGetters: any) =>
+ (activity: ResourceObject, includedList: ResourceObject[]): Activity => {
+ return convert(activity, includedList || [], rootGetters);
+ },
+
activityListByUser:
(state: ActivityState) =>
(userId: PrincipalId): Activity[] => {
diff --git a/frontend/src/store/modules/inbox.ts b/frontend/src/store/modules/inbox.ts
new file mode 100644
index 0000000000..20d0c3ca72
--- /dev/null
+++ b/frontend/src/store/modules/inbox.ts
@@ -0,0 +1,122 @@
+import axios from "axios";
+import {
+ Activity,
+ Inbox,
+ InboxId,
+ InboxPatch,
+ InboxState,
+ PrincipalId,
+ ResourceIdentifier,
+ ResourceObject,
+ unknown,
+} from "../../types";
+
+function convert(
+ inbox: ResourceObject,
+ includedList: ResourceObject[],
+ rootGetters: any
+): Inbox {
+ const activityId = (inbox.relationships!.activity.data as ResourceIdentifier)
+ .id;
+ let activity: Activity = unknown("ACTIVITY") as Activity;
+ activity.id = parseInt(activityId);
+
+ for (const item of includedList || []) {
+ if (item.type == "activity" && item.id == activityId) {
+ activity = rootGetters["activity/convert"](item, includedList);
+ }
+ }
+
+ return {
+ ...(inbox.attributes as Omit<Inbox, "id">),
+ id: parseInt(inbox.id),
+ activity,
+ };
+}
+
+const state: () => InboxState = () => ({
+ inboxListByUser: new Map(),
+});
+
+const getters = {
+ inboxListByUser:
+ (state: InboxState) =>
+ (userId: PrincipalId): Inbox[] => {
+ return state.inboxListByUser.get(userId) || [];
+ },
+};
+
+const actions = {
+ async fetchInboxListByUser(
+ { commit, rootGetters }: any,
+ userId: PrincipalId
+ ) {
+ const data = (await axios.get(`/api/inbox?user=${userId}`)).data;
+ const inboxList = data.data.map((inbox: ResourceObject) => {
+ return convert(inbox, data.included, rootGetters);
+ });
+
+ commit("setInboxListByUser", { userId, inboxList });
+ return inboxList;
+ },
+
+ async patchInbox(
+ { commit, rootGetters }: any,
+ { inboxId, inboxPatch }: { inboxId: InboxId; inboxPatch: InboxPatch }
+ ) {
+ const data = (
+ await axios.patch(`/api/inbox/${inboxId}`, {
+ data: {
+ type: "inboxPatch",
+ attributes: inboxPatch,
+ },
+ })
+ ).data;
+ const updatedInbox = convert(data.data, data.included, rootGetters);
+
+ commit("updateInboxById", { inboxId, inbox: updatedInbox });
+
+ return updatedInbox;
+ },
+};
+
+const mutations = {
+ setInboxListByUser(
+ state: InboxState,
+ {
+ userId,
+ inboxList,
+ }: {
+ userId: PrincipalId;
+ inboxList: Inbox[];
+ }
+ ) {
+ state.inboxListByUser.set(userId, inboxList);
+ },
+
+ updateInboxById(
+ state: InboxState,
+ {
+ inboxId,
+ inbox,
+ }: {
+ inboxId: InboxId;
+ inbox: Inbox;
+ }
+ ) {
+ for (let [_, inboxList] of state.inboxListByUser) {
+ const i = inboxList.findIndex((item: Inbox) => item.id == inboxId);
+ if (i >= 0) {
+ inboxList[i] = inbox;
+ }
+ }
+ },
+};
+
+export default {
+ namespaced: true,
+ state,
+ getters,
+ actions,
+ mutations,
+};
diff --git a/frontend/src/store/modules/message.ts b/frontend/src/store/modules/message.ts
deleted file mode 100644
index 0428d3bec7..0000000000
--- a/frontend/src/store/modules/message.ts
+++ /dev/null
@@ -1,125 +0,0 @@
-import axios from "axios";
-import {
- PrincipalId,
- MessageId,
- Message,
- MessageState,
- ResourceObject,
- MessagePatch,
-} from "../../types";
-
-function convert(message: ResourceObject, rootGetters: any): Message {
- const creator = rootGetters["principal/principalById"](
- message.attributes.creatorId
- );
- const updater = rootGetters["principal/principalById"](
- message.attributes.updaterId
- );
- const receiver = rootGetters["principal/principalById"](
- message.attributes.receiverId
- );
-
- return {
- ...(message.attributes as Omit<
- Message,
- "id" | "creator" | "updater" | "receiver"
- >),
- id: parseInt(message.id),
- creator,
- updater,
- receiver,
- };
-}
-
-const state: () => MessageState = () => ({
- messageListByUser: new Map(),
-});
-
-const getters = {
- messageListByUser:
- (state: MessageState) =>
- (userId: PrincipalId): Message[] => {
- return state.messageListByUser.get(userId) || [];
- },
-};
-
-const actions = {
- async fetchMessageListByUser(
- { commit, rootGetters }: any,
- userId: PrincipalId
- ) {
- // const messageList = (
- // await axios.get(`/api/message?user=${userId}`)
- // ).data.data.map((message: ResourceObject) => {
- // return convert(message, rootGetters);
- // });
-
- // commit("setMessageListByUser", { userId, messageList });
- return [];
- },
-
- async patchMessage(
- { commit, rootGetters }: any,
- {
- messageId,
- messagePatch,
- }: { messageId: MessageId; messagePatch: MessagePatch }
- ) {
- const updatedMessage = convert(
- (
- await axios.patch(`/api/message/${messageId}`, {
- data: {
- type: "messagePatch",
- attributes: messagePatch,
- },
- })
- ).data.data,
- rootGetters
- );
-
- commit("updateMessageById", { messageId, message: updatedMessage });
-
- return updatedMessage;
- },
-};
-
-const mutations = {
- setMessageListByUser(
- state: MessageState,
- {
- userId,
- messageList,
- }: {
- userId: PrincipalId;
- messageList: Message[];
- }
- ) {
- state.messageListByUser.set(userId, messageList);
- },
-
- updateMessageById(
- state: MessageState,
- {
- messageId,
- message,
- }: {
- messageId: MessageId;
- message: Message;
- }
- ) {
- for (let [_, messageList] of state.messageListByUser) {
- const i = messageList.findIndex((item: Message) => item.id == messageId);
- if (i >= 0) {
- messageList[i] = message;
- }
- }
- },
-};
-
-export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations,
-};
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index eacb1db1a8..91a23f08ff 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -4,10 +4,10 @@ import { Database } from "./database";
import { DataSource } from "./dataSource";
import { Environment } from "./environment";
import { CommandId, CommandRegisterId, PrincipalId } from "./id";
+import { Message } from "./inbox";
import { Instance } from "./instance";
import { Issue } from "./issue";
import { Member } from "./member";
-import { Message } from "./message";
import { Pipeline, Stage, Task } from "./pipeline";
import { Principal } from "./principal";
import { Project, ProjectMember } from "./project";
diff --git a/frontend/src/types/id.ts b/frontend/src/types/id.ts
index f19310ecf0..86276efce9 100644
--- a/frontend/src/types/id.ts
+++ b/frontend/src/types/id.ts
@@ -27,7 +27,7 @@ export type TaskRunId = IdType;
export type ActivityId = IdType;
-export type MessageId = IdType;
+export type InboxId = IdType;
export type EnvironmentId = IdType;
diff --git a/frontend/src/types/inbox.ts b/frontend/src/types/inbox.ts
new file mode 100644
index 0000000000..39e5eb1ab0
--- /dev/null
+++ b/frontend/src/types/inbox.ts
@@ -0,0 +1,17 @@
+import { Activity } from "./activity";
+import { InboxId, PrincipalId } from "./id";
+
+export type InboxStatus = "UNREAD" | "READ" | "PINNED";
+
+export type Inbox = {
+ id: InboxId;
+
+ // Domain specific fields
+ receiver_id: PrincipalId;
+ activity: Activity;
+ status: InboxStatus;
+};
+
+export type InboxPatch = {
+ status: InboxStatus;
+};
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index e9888d9645..abd99cbbbe 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -1,6 +1,7 @@
export * from "./activity";
export * from "./actuator";
export * from "./auth";
+export * from "./backup";
export * from "./bookmark";
export * from "./column";
export * from "./common";
@@ -8,12 +9,12 @@ export * from "./database";
export * from "./dataSource";
export * from "./environment";
export * from "./id";
+export * from "./inbox";
export * from "./instance";
export * from "./issue";
export * from "./issueSubscriber";
export * from "./jsonapi";
export * from "./member";
-export * from "./message";
export * from "./notification";
export * from "./oauth";
export * from "./pipeline";
@@ -26,4 +27,3 @@ export * from "./store";
export * from "./table";
export * from "./tableIndex";
export * from "./vcs";
-export * from "./backup";
diff --git a/frontend/src/types/message.ts b/frontend/src/types/message.ts
deleted file mode 100644
index dffafeaf81..0000000000
--- a/frontend/src/types/message.ts
+++ /dev/null
@@ -1,141 +0,0 @@
-import { ActivityId, ContainerId, MessageId, PrincipalId } from "./id";
-import { IssueStatus } from "./issue";
-import { RoleType } from "./member";
-import { Principal } from "./principal";
-import { ProjectRoleType } from "./project";
-
-export type MemberMessageType =
- | "bb.message.member.create"
- | "bb.message.member.add"
- | "bb.message.member.join"
- | "bb.message.member.revoke"
- | "bb.message.member.updaterole";
-
-export type ProjectMemberMessageType =
- | "bb.message.project.member.create"
- | "bb.message.project.member.revoke"
- | "bb.message.project.member.updaterole";
-
-export type EnvironmentMessageType =
- | "bb.message.environment.create"
- | "bb.message.environment.update"
- | "bb.message.environment.delete"
- | "bb.message.environment.archive"
- | "bb.message.environment.restore"
- | "bb.message.environment.reorder";
-
-export type InstanceMessageType =
- | "bb.message.instance.create"
- | "bb.message.instance.update"
- | "bb.message.instance.archive"
- | "bb.message.instance.restore";
-
-export type IssueMessageType =
- | "bb.message.issue.assign"
- | "bb.message.issue.status.update"
- | "bb.message.issue.comment";
-
-export type MessageType =
- | MemberMessageType
- | EnvironmentMessageType
- | InstanceMessageType
- | IssueMessageType;
-
-export type MemberMessagePayload = {
- principalId: PrincipalId;
- oldRole?: RoleType;
- newRole?: RoleType;
-};
-
-export type ProjectMemberMessagePayload = {
- principalId: PrincipalId;
- oldRole?: ProjectRoleType;
- newRole?: ProjectRoleType;
-};
-
-export type EnvironmentUpdateMessagePayload = {
- environmentName: string;
-};
-
-export enum EnvironmentBuiltinFieldId {
- ROW_STATUS = "1",
- NAME = "2",
-}
-
-export type EnvironmentMessagePayload = {
- environmentName: string;
- changeList: {
- fieldId: EnvironmentBuiltinFieldId;
- oldValue?: any;
- newValue?: any;
- }[];
-};
-
-export enum InstanceBuiltinFieldId {
- ROW_STATUS = "1",
- NAME = "2",
- ENVIRONMENT = "3",
- EXTERNAL_LINK = "4",
- HOST = "5",
- PORT = "6",
- username = "7",
- password = "8",
-}
-
-export type InstanceMessagePaylaod = {
- instanceName: string;
-};
-
-export type IssueAssignMessagePayload = {
- issueName: string;
- oldAssigneeId: PrincipalId;
- newAssigneeId: PrincipalId;
-};
-
-export type IssueUpdateStatusMessagePayload = {
- issueName: string;
- oldStatus: IssueStatus;
- newStatus: IssueStatus;
-};
-
-export type IssueCommentMessagePayload = {
- issueName: string;
- commentId: ActivityId;
-};
-
-export type MessagePayload =
- | MemberMessagePayload
- | EnvironmentMessagePayload
- | EnvironmentUpdateMessagePayload
- | InstanceMessagePaylaod
- | IssueAssignMessagePayload
- | IssueUpdateStatusMessagePayload
- | IssueCommentMessagePayload;
-
-export type MessageStatus = "DELIVERED" | "CONSUMED";
-
-export type Message = {
- id: MessageId;
-
- // Related fields
- // The object where this message originates, simliar to containerId in Activity
- containerId: ContainerId;
-
- // Standard fields
- creator: Principal;
- createdTs: number;
- updater: Principal;
- updatedTs: number;
-
- // Domain specific fields
- type: MessageType;
- status: MessageStatus;
- description: string;
- receiver: Principal;
- payload?: MessagePayload;
-};
-export type MessageCreate = Omit<Message, "id" | "createdTs" | "updatedTs">;
-
-export type MessagePatch = {
- status: MessageStatus;
-};
diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.ts
index 51e9512dbe..647e1c7033 100644
--- a/frontend/src/types/store.ts
+++ b/frontend/src/types/store.ts
@@ -15,11 +15,11 @@ import {
ProjectId,
VCSId,
} from "./id";
+import { Inbox } from "./inbox";
import { Instance, MigrationHistory } from "./instance";
import { Issue } from "./issue";
import { IssueSubscriber } from "./issueSubscriber";
import { Member } from "./member";
-import { Message } from "./message";
import { Notification } from "./notification";
import { PlanType } from "./plan";
import { Principal } from "./principal";
@@ -63,8 +63,8 @@ export interface ActivityState {
activityListByIssue: Map<IssueId, Activity[]>;
}
-export interface MessageState {
- messageListByUser: Map<PrincipalId, Message[]>;
+export interface InboxState {
+ inboxListByUser: Map<PrincipalId, Inbox[]>;
}
export interface IssueState {
diff --git a/frontend/src/views/DashboardSidebar.vue b/frontend/src/views/DashboardSidebar.vue
index 2e66f91ddd..eeb304f5c3 100644
--- a/frontend/src/views/DashboardSidebar.vue
+++ b/frontend/src/views/DashboardSidebar.vue
@@ -14,7 +14,7 @@
</svg>
Home
</router-link>
- <!-- <router-link
+ <router-link
to="/inbox"
class="outline-item group flex items-center px-2 py-2"
>
@@ -24,23 +24,15 @@
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
- <template v-if="hasUnreadMessage">
- <path
- d="M8.707 7.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l2-2a1 1 0 00-1.414-1.414L11 7.586V3a1 1 0 10-2 0v4.586l-.293-.293z"
- ></path>
- <path
- d="M3 5a2 2 0 012-2h1a1 1 0 010 2H5v7h2l1 2h4l1-2h2V5h-1a1 1 0 110-2h1a2 2 0 012 2v10a2 2 0 01-2 2H5a2 2 0 01-2-2V5z"
- ></path>
- </template>
<path
- v-else
- fill-rule="evenodd"
- d="M5 3a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2V5a2 2 0 00-2-2H5zm0 2h10v7h-2l-1 2H8l-1-2H5V5z"
- clip-rule="evenodd"
+ d="M8.707 7.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l2-2a1 1 0 00-1.414-1.414L11 7.586V3a1 1 0 10-2 0v4.586l-.293-.293z"
+ ></path>
+ <path
+ d="M3 5a2 2 0 012-2h1a1 1 0 010 2H5v7h2l1 2h4l1-2h2V5h-1a1 1 0 110-2h1a2 2 0 012 2v10a2 2 0 01-2 2H5a2 2 0 01-2-2V5z"
></path>
</svg>
Inbox
- </router-link> -->
+ </router-link>
<div>
<BookmarkListSidePanel />
</div>
@@ -54,16 +46,9 @@
</template>
<script lang="ts">
-import { computed } from "vue";
-import { useStore } from "vuex";
import BookmarkListSidePanel from "../components/BookmarkListSidePanel.vue";
import ProjectListSidePanel from "../components/ProjectListSidePanel.vue";
import DatabaseListSidePanel from "../components/DatabaseListSidePanel.vue";
-import { Message } from "../types";
-
-interface LocalState {
- hasUnreadMessage: boolean;
-}
export default {
name: "DashboardSidebar",
@@ -74,22 +59,7 @@ export default {
DatabaseListSidePanel,
},
setup(props, ctx) {
- const store = useStore();
-
- const currentUser = computed(() => store.getters["auth/currentUser"]());
-
- const hasUnreadMessage = computed(() => {
- const list = store.getters["message/messageListByUser"](
- currentUser.value.id
- );
- return list.find((item: Message) => {
- return item.status == "DELIVERED";
- });
- });
-
- return {
- hasUnreadMessage,
- };
+ return {};
},
};
</script>
diff --git a/frontend/src/views/Inbox.vue b/frontend/src/views/Inbox.vue
index 79ee59bdf3..b740f76f7d 100644
--- a/frontend/src/views/Inbox.vue
+++ b/frontend/src/views/Inbox.vue
@@ -15,7 +15,7 @@
<div>
<div class="px-4 py-2 flex justify-between">
<BBSwitch
- :label="'Display all messages'"
+ :label="'Display all inboxs'"
:value="state.showAll"
@toggle="
(on) => {
@@ -24,7 +24,6 @@
"
/>
<button type="button" class="btn-normal" @click.prevent="markAllAsRead">
- <!-- Heroicon name: solid/pencil -->
<svg
class="-ml-1 mr-2 h-5 w-5 text-control-light"
fill="currentColor"
@@ -40,13 +39,16 @@
</div>
<ul class="divide-y divide-block-border">
<li
- v-for="(message, index) in effectiveMessageList"
+ v-for="(inbox, index) in effectiveInboxList"
:key="index"
class="p-3 hover:bg-control-bg-hover cursor-default"
- @click.prevent="clickMessage(message)"
+ @click.prevent="clickInbox(inbox)"
>
<div class="flex space-x-3">
- <PrincipalAvatar :principal="message.creator" :size="'SMALL'" />
+ <PrincipalAvatar
+ :principal="inbox.activity.creator"
+ :size="'SMALL'"
+ />
<div class="flex-1 space-y-1">
<div class="flex w-full items-center justify-between space-x-2">
<h3
@@ -59,99 +61,95 @@
"
>
<router-link
- :to="`/u/${message.creator.id}`"
+ :to="`/u/${inbox.activity.creator.id}`"
class="font-medium text-main hover:underline"
- >{{ message.creator.name }}</router-link
+ >{{ inbox.activity.creator.name }}</router-link
>
- <span class="ml-1"> {{ actionSentence(message) }}</span>
- <template
+ <span class="ml-1"> {{ actionSentence(inbox) }}</span>
+ <!-- <template
v-if="
- message.type == 'bb.message.member.create' ||
- message.type == 'bb.message.member.add' ||
- message.type == 'bb.message.member.join' ||
- message.type == 'bb.message.member.revoke' ||
- message.type == 'bb.message.member.updaterole'
+ inbox.type == 'bb.inbox.member.create' ||
+ inbox.type == 'bb.inbox.member.add' ||
+ inbox.type == 'bb.inbox.member.join' ||
+ inbox.type == 'bb.inbox.member.revoke' ||
+ inbox.type == 'bb.inbox.member.updaterole'
"
>
</template>
<template
v-else-if="
- message.type == 'bb.message.environment.create' ||
- message.type == 'bb.message.environment.update' ||
- message.type == 'bb.message.environment.archive' ||
- message.type == 'bb.message.environment.restore'
+ inbox.type == 'bb.inbox.environment.create' ||
+ inbox.type == 'bb.inbox.environment.update' ||
+ inbox.type == 'bb.inbox.environment.archive' ||
+ inbox.type == 'bb.inbox.environment.restore'
"
>
<router-link
- :to="`/environment#${message.containerId}`"
+ :to="`/environment#${inbox.containerId}`"
class="normal-link ml-1"
>
- {{ message.payload.environmentName }}
+ {{ inbox.payload.environmentName }}
</router-link>
</template>
<template
- v-else-if="message.type == 'bb.message.environment.delete'"
+ v-else-if="inbox.type == 'bb.inbox.environment.delete'"
>
<span class="font-medium text-main ml-1">
- {{ message.payload.environmentName }}
+ {{ inbox.payload.environmentName }}
</span>
</template>
<template
v-else-if="
- message.type == 'bb.message.instance.create' ||
- message.type == 'bb.message.instance.update' ||
- message.type == 'bb.message.instance.archive' ||
- message.type == 'bb.message.instance.restore'
+ inbox.type == 'bb.inbox.instance.create' ||
+ inbox.type == 'bb.inbox.instance.update' ||
+ inbox.type == 'bb.inbox.instance.archive' ||
+ inbox.type == 'bb.inbox.instance.restore'
"
>
<router-link
- :to="`/instance/${message.containerId}`"
+ :to="`/instance/${inbox.containerId}`"
class="normal-link ml-1"
>
- {{ message.payload.instanceName }}
+ {{ inbox.payload.instanceName }}
</router-link>
- </template>
- <template
- v-else-if="message.type == 'bb.message.issue.assign'"
- >
+ </template> -->
+ <!-- <template v-if="inbox.activity.type.startsWith('bb.issue.')">
<router-link
- :to="`/issue/${message.containerId}`"
+ :to="`/issue/${inbox.containerId}`"
class="normal-link ml-1"
>
- {{ message.payload.issueName }}
+ {{ inbox.activity.issueName }}
</router-link>
</template>
<template
- v-else-if="message.type == 'bb.message.issue.status.update'"
+ v-else-if="inbox.type == 'bb.inbox.issue.status.update'"
>
<router-link
- :to="`/issue/${message.containerId}`"
+ :to="`/issue/${inbox.containerId}`"
class="normal-link ml-1"
>
- {{ message.payload.issueName }}
+ {{ inbox.payload.issueName }}
</router-link>
</template>
- <template
- v-else-if="message.type == 'bb.message.issue.comment'"
- >
+ <template v-else-if="inbox.type == 'bb.inbox.issue.comment'">
<router-link
- :to="`/issue/${message.containerId}#activity${message.payload.commentId}`"
+ :to="`/issue/${inbox.containerId}#activity${inbox.payload.commentId}`"
class="normal-link ml-1"
>
- {{ message.payload.issueName }}
+ {{ inbox.payload.issueName }}
</router-link>
- </template>
+ </template> -->
<span
- v-if="message.status == 'DELIVERED'"
+ v-if="inbox.status == 'UNREAD'"
class="ml-2 mt-1 h-3 w-3 rounded-full bg-accent"
></span>
</h3>
<p class="text-sm text-control">
- {{ humanizeTs(message.createdTs) }}
+ {{ humanizeTs(inbox.activity.createdTs) }}
</p>
</div>
- <div v-if="message.description" class="text-sm text-control">
- {{ message.description }}
+ <div v-if="inbox.activity.comment" class="text-sm text-control">
+ {{ inbox.activity.comment }}
</div>
</div>
</div>
@@ -166,16 +164,8 @@
import { computed, onMounted, reactive, watchEffect } from "vue";
import { useStore } from "vuex";
import PrincipalAvatar from "../components/PrincipalAvatar.vue";
-import {
- MemberMessagePayload,
- Message,
- Principal,
- PrincipalId,
- IssueAssignMessagePayload,
- IssueUpdateStatusMessagePayload,
- UNKNOWN_ID,
-} from "../types";
-import { isDBAOrOwner, roleName } from "../utils";
+import { Inbox, UNKNOWN_ID } from "../types";
+import { isDBAOrOwner, issueActivityActionSentence } from "../utils";
const GENERAL_TAB = 0;
const MEMBERSHIP_TAB = 1;
@@ -183,12 +173,12 @@ const MEMBERSHIP_TAB = 1;
interface LocalState {
selectedIndex: number;
showAll: boolean;
- messageList: Message[];
+ inboxList: Inbox[];
// To maintain a stable view when user clicks an item.
// When user clicks an item, we will set the item as "CONSUMED".
// Without this logic, if the user stays on the display unread item view,
// that item will suddenly be removed from the list, which is not ideal for UX.
- whitelist: Message[];
+ whitelist: Inbox[];
}
export default {
@@ -200,24 +190,24 @@ export default {
const state = reactive<LocalState>({
selectedIndex: 0,
showAll: false,
- messageList: [],
+ inboxList: [],
whitelist: [],
});
const currentUser = computed(() => store.getters["auth/currentUser"]());
- const prepareMessageList = () => {
+ const prepareInboxList = () => {
// It will also be called when user logout
if (currentUser.value.id != UNKNOWN_ID) {
store
- .dispatch("message/fetchMessageListByUser", currentUser.value.id)
- .then((list: Message[]) => {
- state.messageList = list;
+ .dispatch("inbox/fetchInboxListByUser", currentUser.value.id)
+ .then((list: Inbox[]) => {
+ state.inboxList = list;
});
}
};
- watchEffect(prepareMessageList);
+ watchEffect(prepareInboxList);
onMounted(() => {
state.whitelist = [];
@@ -227,139 +217,38 @@ export default {
return isDBAOrOwner(currentUser.value.role);
});
- const effectiveMessageList = computed(() => {
- return state.messageList.filter((message: Message) => {
+ const effectiveInboxList = computed(() => {
+ return state.inboxList.filter((inbox: Inbox) => {
if (
(state.selectedIndex == GENERAL_TAB &&
- message.type.startsWith("bb.message.member.")) ||
+ inbox.activity.actionType.startsWith("bb.inbox.member.")) ||
(state.selectedIndex == MEMBERSHIP_TAB &&
- !message.type.startsWith("bb.message.member."))
+ !inbox.activity.actionType.startsWith("bb.inbox.member."))
) {
return false;
}
return (
state.showAll ||
- message.status == "DELIVERED" ||
- state.whitelist.find((item: Message) => {
- return item.id == message.id;
+ inbox.status == "UNREAD" ||
+ state.whitelist.find((item: Inbox) => {
+ return item.id == inbox.id;
})
);
});
});
- const principalFromId = (principalId: PrincipalId): Principal => {
- return store.getters["principal/principalById"](principalId);
- };
-
- const actionSentence = (message: Message): string => {
- switch (message.type) {
- case "bb.message.member.create": {
- const payload = message.payload as MemberMessagePayload;
- return `added ${
- principalFromId(payload.principalId).email
- } as ${roleName(payload.newRole!)}`;
- }
- case "bb.message.member.add": {
- const payload = message.payload as MemberMessagePayload;
- return `invited ${
- principalFromId(payload.principalId).email
- } as ${roleName(payload.newRole!)}`;
- }
- case "bb.message.member.join": {
- const payload = message.payload as MemberMessagePayload;
- return `joined as ${roleName(payload.newRole!)}`;
- }
- case "bb.message.member.revoke": {
- const payload = message.payload as MemberMessagePayload;
- return `revoked ${roleName(payload.oldRole!)} from ${
- principalFromId(payload.principalId).name
- }`;
- }
- case "bb.message.member.updaterole":
- const payload = message.payload as MemberMessagePayload;
- return `changed ${
- principalFromId(payload.principalId).name
- } role from ${roleName(payload.oldRole!)} to ${roleName(
- payload.newRole!
- )}`;
- case "bb.message.environment.create":
- return "created environment";
- case "bb.message.environment.update":
- return "updated environment";
- case "bb.message.environment.delete":
- return "deleted environment";
- case "bb.message.environment.archive":
- return "archived environment";
- case "bb.message.environment.restore":
- return "restored environment";
- case "bb.message.environment.reorder":
- return "reordered environment";
- case "bb.message.instance.create":
- return "created instance";
- case "bb.message.instance.update":
- return "updated instance";
- case "bb.message.instance.archive":
- return "archived instance";
- case "bb.message.instance.restore":
- return "restored instance";
- case "bb.message.issue.assign": {
- const payload = message.payload as IssueAssignMessagePayload;
- if (
- payload.oldAssigneeId == UNKNOWN_ID &&
- payload.newAssigneeId != UNKNOWN_ID
- ) {
- const newName =
- currentUser.value.id == payload.newAssigneeId
- ? "you"
- : principalFromId(payload.newAssigneeId).name;
- return `assigned issue to ${newName}`;
- } else if (
- payload.oldAssigneeId != UNKNOWN_ID &&
- payload.newAssigneeId == UNKNOWN_ID
- ) {
- const oldName =
- currentUser.value.id == payload.oldAssigneeId
- ? "you"
- : principalFromId(payload.oldAssigneeId).name;
- return `un-assigned issue from ${oldName}`;
- } else if (
- payload.oldAssigneeId != UNKNOWN_ID &&
- payload.newAssigneeId != UNKNOWN_ID
- ) {
- const oldName =
- currentUser.value.id == payload.oldAssigneeId
- ? "you"
- : principalFromId(payload.oldAssigneeId).name;
- const newName =
- currentUser.value.id == payload.newAssigneeId
- ? "you"
- : principalFromId(payload.newAssigneeId).name;
- return `re-assigned from ${oldName} to ${newName}`;
- }
- return "assigned issue";
- }
- case "bb.message.issue.status.update": {
- const payload = message.payload as IssueUpdateStatusMessagePayload;
- return (
- "changed issue status from " +
- payload.oldStatus +
- " to " +
- payload.newStatus
- );
- }
- case "bb.message.issue.comment":
- return "commented issue";
- }
+ const actionSentence = (inbox: Inbox): string => {
+ return issueActivityActionSentence(inbox.activity);
};
- const clickMessage = (message: Message) => {
- if (message.status == "DELIVERED") {
- state.whitelist.push(message);
- store.dispatch("message/patchMessage", {
- messageId: message.id,
- messagePatch: {
- status: "CONSUMED",
+ const clickInbox = (inbox: Inbox) => {
+ if (inbox.status == "UNREAD") {
+ state.whitelist.push(inbox);
+ store.dispatch("inbox/patchInbox", {
+ inboxId: inbox.id,
+ inboxPatch: {
+ status: "READ",
},
});
}
@@ -371,13 +260,13 @@ export default {
};
const markAllAsRead = () => {
- state.messageList.forEach((item: Message) => {
- if (item.status == "DELIVERED") {
+ state.inboxList.forEach((item: Inbox) => {
+ if (item.status == "UNREAD") {
state.whitelist.push(item);
- store.dispatch("message/patchMessage", {
- messageId: item.id,
- messagePatch: {
- status: "CONSUMED",
+ store.dispatch("inbox/patchInbox", {
+ inboxId: item.id,
+ inboxPatch: {
+ status: "READ",
},
});
}
@@ -387,11 +276,10 @@ export default {
return {
state,
currentUser,
- principalFromId,
isCurrentUserDBAOrOwner,
- effectiveMessageList,
+ effectiveInboxList,
actionSentence,
- clickMessage,
+ clickInbox,
showAll,
markAllAsRead,
};