Skip to content

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

Notification show/hide logic

Tianzhou Chen9f1de73fa683
diff --git a/frontend/src/layouts/DashboardLayout.vue b/frontend/src/layouts/DashboardLayout.vue
index b9818f6595..b1be6c6d6f 100644
--- a/frontend/src/layouts/DashboardLayout.vue
+++ b/frontend/src/layouts/DashboardLayout.vue
@@ -13,13 +13,6 @@
</nav>
<router-view name="body" />
</div>
- <BBNotification
- :placement="'BOTTOM_RIGHT'"
- :showing="state.notification != null"
- :style="state.notification?.style || 'INFO'"
- :title="state.notification?.title || ''"
- :description="state.notification?.description || ''"
- />
</ProvideContext>
</div>
</template>
@@ -27,6 +20,15 @@
<span>Loading...</span>
</template>
</Suspense>
+ <BBNotification
+ :placement="'BOTTOM_RIGHT'"
+ :showing="state.notification != null"
+ :style="state.notification?.style || 'INFO'"
+ :title="state.notification?.title || ''"
+ :description="state.notification?.description || ''"
+ :payload="state.notification?.id"
+ @close="removeNotification"
+ />
</template>
<script lang="ts">
@@ -38,10 +40,10 @@ import BannerDemo from "../views/BannerDemo.vue";
import { Notification } from "../types";
import { isDemo } from "../utils";
-const NOTIFICAITON_DURATION = 4000;
+const NOTIFICAITON_DURATION = 8000;
interface LocalState {
- notification?: Notification | null;
+ notification?: Notification | undefined;
}
export default {
@@ -51,25 +53,32 @@ export default {
const store = useStore();
const state = reactive<LocalState>({
- notification: null,
+ notification: undefined,
});
+ const removeNotification = (id: string) => {
+ store
+ .dispatch("notification/removeNotification", {
+ module: "bytebase",
+ id,
+ })
+ .then(() => {
+ state.notification = undefined;
+ });
+ };
+
const watchNotification = () => {
store
.dispatch("notification/peekNotification", {
module: "bytebase",
})
- .then((notification) => {
- if (notification) {
- state.notification = notification;
+ .then((notification: Notification) => {
+ state.notification = notification;
+ // We don't want user to miss "CRITICAL" notification and
+ // thus don't automatically dismiss it.
+ if (notification && notification.style != "CRITICAL") {
setTimeout(() => {
- store
- .dispatch("notification/popNotification", {
- module: "bytebase",
- })
- .then(() => {
- state.notification = null;
- });
+ removeNotification(notification.id);
}, NOTIFICAITON_DURATION);
}
});
@@ -80,6 +89,7 @@ export default {
return {
state,
isDemo,
+ removeNotification,
};
},
};
diff --git a/frontend/src/store/modules/notification.ts b/frontend/src/store/modules/notification.ts
index 888c3a71bc..bc5ac59f3c 100644
--- a/frontend/src/store/modules/notification.ts
+++ b/frontend/src/store/modules/notification.ts
@@ -13,12 +13,15 @@ const state: () => NotificationState = () => ({
function findNotification(
state: NotificationState,
filter: NotificationFilter
-): Notification | null {
+): Notification | undefined {
const list = state.notificationByModule.get(filter.module);
if (list && list.length > 0) {
+ if (filter.id) {
+ return list.find((item) => item.id == filter.id);
+ }
return list[0];
}
- return null;
+ return undefined;
}
const getters = {};
@@ -37,7 +40,7 @@ const actions = {
return findNotification(state, filter);
},
- popNotification({ state, commit }: any, filter: NotificationFilter) {
+ removeNotification({ state, commit }: any, filter: NotificationFilter) {
const notification = findNotification(state, filter);
commit("removeNotification", notification);
return notification;
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 25569c2249..1bc52c10a6 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -251,6 +251,7 @@ export type NewNotification = Omit<Notification, "id" | "createdTs">;
export type NotificationFilter = {
module: string;
+ id?: string;
};
// Store