Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: cache last viewed page & show activity notification (#9099)
ecmadaoccc22fb26e57
diff --git a/frontend/src/App.vue b/frontend/src/App.vueindex 6dda862da2..24dc314121 100644--- a/frontend/src/App.vue+++ b/frontend/src/App.vue@@ -84,6 +84,7 @@ setInterval(() => {const removeNotification = (item: BBNotificationItem | undefined) => {if (!item) return;+ item.onClose();const index = state.notificationList.indexOf(item);if (index >= 0) {state.notificationList.splice(index, 1);@@ -105,6 +106,7 @@ const watchNotification = () => {description: notification.description || "",link: notification.link || "",linkTitle: notification.linkTitle || "",+ onClose: notification.onClose || (() => {}),};state.notificationList.unshift(item);if (!notification.manualHide) {diff --git a/frontend/src/bbkit/BBNotification.vue b/frontend/src/bbkit/BBNotification.vueindex b74266fc33..95abb6487d 100644--- a/frontend/src/bbkit/BBNotification.vue+++ b/frontend/src/bbkit/BBNotification.vue@@ -61,10 +61,13 @@<p class="mt-1 text-sm text-gray-500 whitespace-pre-wrap">{{ notification.description }}</p>- <div v-if="notification.link" class="mt-2">+ <div+ v-if="notification.link && notification.linkTitle"+ class="mt-2"+ ><buttonclass="bg-white rounded-md text-sm font-medium text-accent hover:text-accent-hover focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-accent"- @click.prevent="viewLink(notification.link)"+ @click.prevent="viewLink(notification)">{{ notification.linkTitle }}</button>@@ -135,9 +138,9 @@ const emit = defineEmits<{const router = useRouter();-const viewLink = (link: string) => {- router.push(link);- emit("close");+const viewLink = (notification: BBNotificationItem) => {+ router.push(notification.link);+ emit("close", notification);};const placementClass = computed(() => placementClassMap.get(props.placement));</script>diff --git a/frontend/src/bbkit/types.ts b/frontend/src/bbkit/types.tsindex 57f1db225c..9b2796575a 100644--- a/frontend/src/bbkit/types.ts+++ b/frontend/src/bbkit/types.ts@@ -97,6 +97,7 @@ export type BBNotificationItem = {description: string;link: string;linkTitle: string;+ onClose: () => void;};export type BBAlertStyle = "INFO" | "SUCCESS" | "WARN" | "CRITICAL";diff --git a/frontend/src/components/ActivityTable/ActivityTypeLink.vue b/frontend/src/components/ActivityTable/ActivityTypeLink.vueindex b925459bc4..46a4a9bfcb 100644--- a/frontend/src/components/ActivityTable/ActivityTypeLink.vue+++ b/frontend/src/components/ActivityTable/ActivityTypeLink.vue@@ -16,14 +16,9 @@</template><script lang="ts" setup>-import { head } from "lodash-es";import { computed, PropType } from "vue";-import { LogEntity, LogEntity_Action } from "@/types/proto/v1/logging_service";-import {- ActivityProjectRepositoryPushPayload,- ActivityProjectDatabaseTransferPayload,-} from "../../types";-import { Link } from "./types";+import { LogEntity } from "@/types/proto/v1/logging_service";+import { getLinkFromActivity } from "./utils";const props = defineProps({activity: {@@ -32,36 +27,5 @@ const props = defineProps({},});-const link = computed((): Link | undefined => {- const { activity } = props;- switch (activity.action) {- case LogEntity_Action.ACTION_PROJECT_REPOSITORY_PUSH: {- const payload = JSON.parse(- activity.payload- ) as ActivityProjectRepositoryPushPayload;- const commit =- head(payload.pushEvent.commits) ?? payload.pushEvent.fileCommit;- if (commit && commit.id && commit.url) {- return {- title: commit.id.substring(0, 7),- path: commit.url,- external: true,- };- }- // Downgrade for legacy data.- return undefined;- }- case LogEntity_Action.ACTION_PROJECT_DATABASE_TRANSFER: {- const payload = JSON.parse(- activity.payload- ) as ActivityProjectDatabaseTransferPayload;- return {- title: payload.databaseName,- path: `/db/${payload.databaseId}`,- external: false,- };- }- }- return undefined;-});+const link = computed(() => getLinkFromActivity(props.activity));</script>diff --git a/frontend/src/components/ActivityTable/utils.ts b/frontend/src/components/ActivityTable/utils.tsnew file mode 100644index 0000000000..f60b5714e0--- /dev/null+++ b/frontend/src/components/ActivityTable/utils.ts@@ -0,0 +1,61 @@+import { head } from "lodash-es";+import { getIssueId } from "@/store/modules/v1/common";+import {+ ActivityIssueCreatePayload,+ ActivityProjectRepositoryPushPayload,+ ActivityProjectDatabaseTransferPayload,+ UNKNOWN_ID,+ EMPTY_ID,+} from "@/types";+import { LogEntity, LogEntity_Action } from "@/types/proto/v1/logging_service";+import { Link } from "./types";++export const getLinkFromActivity = (activity: LogEntity): Link | undefined => {+ switch (activity.action) {+ case LogEntity_Action.ACTION_PROJECT_REPOSITORY_PUSH: {+ const payload = JSON.parse(+ activity.payload+ ) as ActivityProjectRepositoryPushPayload;+ const commit =+ head(payload.pushEvent.commits) ?? payload.pushEvent.fileCommit;+ if (commit && commit.id && commit.url) {+ return {+ title: commit.id.substring(0, 7),+ path: commit.url,+ external: true,+ };+ }+ // Downgrade for legacy data.+ return undefined;+ }+ case LogEntity_Action.ACTION_PROJECT_DATABASE_TRANSFER: {+ const payload = JSON.parse(+ activity.payload+ ) as ActivityProjectDatabaseTransferPayload;+ return {+ title: payload.databaseName,+ path: `/db/${payload.databaseId}`,+ external: false,+ };+ }+ case LogEntity_Action.ACTION_PIPELINE_TASK_STATUS_UPDATE:+ case LogEntity_Action.ACTION_PIPELINE_STAGE_STATUS_UPDATE:+ case LogEntity_Action.ACTION_PIPELINE_TASK_RUN_STATUS_UPDATE:+ case LogEntity_Action.ACTION_ISSUE_STATUS_UPDATE:+ case LogEntity_Action.ACTION_ISSUE_CREATE: {+ const payload = JSON.parse(+ activity.payload+ ) as ActivityIssueCreatePayload;+ const issueId = getIssueId(activity.resource);+ if (issueId === UNKNOWN_ID || issueId === EMPTY_ID) {+ return undefined;+ }+ return {+ title: payload.issueName,+ path: `/issue/${issueId}`,+ external: false,+ };+ }+ }+ return undefined;+};diff --git a/frontend/src/components/AuditLog/AuditLogTable.vue b/frontend/src/components/AuditLog/AuditLogTable.vueindex d44123533a..34a3366ad3 100644--- a/frontend/src/components/AuditLog/AuditLogTable.vue+++ b/frontend/src/components/AuditLog/AuditLogTable.vue@@ -77,7 +77,7 @@ defineProps({});defineEmits<{- (event: "view-detail", log: LogEntity, e: MouseEvent): void;+ (event: "view-detail", log: LogEntity): void;}>();const { t } = useI18n();diff --git a/frontend/src/components/Project/ProjectSidebar.vue b/frontend/src/components/Project/ProjectSidebar.vueindex eeae30ff4d..c0afe5d7f1 100644--- a/frontend/src/components/Project/ProjectSidebar.vue+++ b/frontend/src/components/Project/ProjectSidebar.vue@@ -8,6 +8,7 @@</template><script setup lang="ts">+import { useLocalStorage } from "@vueuse/core";import { startCase } from "lodash-es";import {Database,@@ -59,7 +60,14 @@ interface ProjectSidebarItem {}[];}-const defaultHash: ProjectHash = "databases";+const cachedLastPage = useLocalStorage<ProjectHash>(+ "bb.project.page",+ "databases"+);++const defaultHash = computed((): ProjectHash => {+ return cachedLastPage.value;+});interface LocalState {selectedHash: ProjectHash;@@ -71,9 +79,14 @@ const router = useRouter();const projectV1Store = useProjectV1Store();const state = reactive<LocalState>({- selectedHash: defaultHash,+ selectedHash: defaultHash.value,});+watch(+ () => state.selectedHash,+ (hash) => (cachedLastPage.value = hash)+);+const projectSlug = computed(() => route.params.projectSlug as string);const project = computed(() => {return projectV1Store.getProjectByUID(String(idFromSlug(projectSlug.value)));@@ -244,7 +257,7 @@ const selectProjectTabOnHash = () => {if (name == "workspace.project.detail") {let targetHash = hash.replace(/^#?/g, "");if (!isProjectHash(targetHash)) {- targetHash = defaultHash;+ targetHash = defaultHash.value;}onSelect(targetHash as ProjectHash);} else if (diff --git a/frontend/src/store/modules/v1/common.ts b/frontend/src/store/modules/v1/common.tsindex 75e2fceb08..6c129da0ef 100644--- a/frontend/src/store/modules/v1/common.ts+++ b/frontend/src/store/modules/v1/common.ts@@ -56,6 +56,10 @@ export const getLogId = (name: string): number => {return getNumberId(name, logNamePrefix);};+export const getIssueId = (name: string): number => {+ return getNumberId(name, issueNamePrefix);+};+export const getProjectName = (name: string): string => {const tokens = getNameParentTokens(name, [projectNamePrefix]);const projectId = tokens[0];diff --git a/frontend/src/types/activity.ts b/frontend/src/types/activity.tsindex 2feaf70c27..a09b896364 100644--- a/frontend/src/types/activity.ts+++ b/frontend/src/types/activity.ts@@ -36,7 +36,7 @@ export function activityName(action: LogEntity_Action): string {case LogEntity_Action.ACTION_PIPELINE_TASK_STATUS_UPDATE:return t("activity.type.pipeline-task-status-update");case LogEntity_Action.ACTION_PIPELINE_TASK_RUN_STATUS_UPDATE:- return t("activity.type.pipeline-task-run-status-update");+ return t("activity.type.pipeline-task-status-update");case LogEntity_Action.ACTION_PIPELINE_TASK_FILE_COMMIT:return t("activity.type.pipeline-task-file-commit");case LogEntity_Action.ACTION_PIPELINE_TASK_STATEMENT_UPDATE:diff --git a/frontend/src/types/notification.ts b/frontend/src/types/notification.tsindex 3a4f316b75..baf06c79e7 100644--- a/frontend/src/types/notification.ts+++ b/frontend/src/types/notification.ts@@ -10,6 +10,7 @@ export type Notification = {link?: string;linkTitle?: string;manualHide?: boolean;+ onClose?: () => void;};// "id" and "createdTs" is auto generated upon the notification storediff --git a/frontend/src/views/ProjectDetail.vue b/frontend/src/views/ProjectDetail.vueindex aeb48047ae..58ace82acf 100644--- a/frontend/src/views/ProjectDetail.vue+++ b/frontend/src/views/ProjectDetail.vue@@ -66,9 +66,12 @@</template><script lang="ts" setup>+import { useLocalStorage } from "@vueuse/core";import { pull } from "lodash-es";-import { computed } from "vue";+import { computed, onMounted } from "vue";+import { useI18n } from "vue-i18n";import { useRoute } from "vue-router";+import { getLinkFromActivity } from "@/components/ActivityTable/utils";import AnomalyCenterDashboard from "@/components/AnomalyCenter/AnomalyCenterDashboard.vue";import ChangelistDashboard from "@/components/Changelist/ChangelistDashboard";import ProjectDatabaseGroupPanel from "@/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue";@@ -89,9 +92,16 @@ import {useDatabaseV1Store,useProjectV1Store,useCurrentUserV1,+ useActivityV1Store,hasFeature,+ pushNotification,} from "@/store";-import { QuickActionType, DEFAULT_PROJECT_V1_NAME, RoleType } from "@/types";+import {+ QuickActionType,+ DEFAULT_PROJECT_V1_NAME,+ RoleType,+ activityName,+} from "@/types";import { State } from "@/types/proto/v1/common";import {idFromSlug,@@ -118,6 +128,8 @@ const props = defineProps({const route = useRoute();const projectV1Store = useProjectV1Store();+const activityV1Store = useActivityV1Store();+const { t } = useI18n();const hash = computed(() => route.hash.replace(/^#?/, "") as ProjectHash);@@ -141,6 +153,41 @@ const databaseV1List = computed(() => {return sortDatabaseV1List(list);});+const cachedNotifiedActivities = useLocalStorage<string[]>(+ "bb.project.activities",+ []+);++const maximumCachedActivities = 5;++onMounted(() => {+ activityV1Store+ .fetchActivityList({+ pageSize: 1,+ order: "desc",+ resource: project.value.name,+ })+ .then((resp) => {+ for (const activity of resp.logEntities) {+ if (cachedNotifiedActivities.value.includes(activity.name)) {+ continue;+ }+ cachedNotifiedActivities.value.push(activity.name);+ if (cachedNotifiedActivities.value.length > maximumCachedActivities) {+ cachedNotifiedActivities.value.shift();+ }+ pushNotification({+ module: "bytebase",+ style: "INFO",+ title: activityName(activity.action),+ manualHide: true,+ link: getLinkFromActivity(activity)?.path,+ linkTitle: t("common.view"),+ });+ }+ });+});+const quickActionMapByRole = computed(() => {if (project.value.state === State.ACTIVE) {const DBA_AND_OWNER_QUICK_ACTION_LIST: QuickActionType[] = [