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: add banners wrapper component (#2020)
boojack9a492b2204ca
diff --git a/frontend/src/components/BannersWrapper.vue b/frontend/src/components/BannersWrapper.vuenew file mode 100644index 0000000000..743b80ad80--- /dev/null+++ b/frontend/src/components/BannersWrapper.vue@@ -0,0 +1,64 @@+<template>+ <template v-if="shouldShowDemoBanner">+ <BannerDemo />+ </template>+ <template v-if="shouldShowDebugBanner">+ <BannerDebug />+ </template>+ <template v-if="shouldShowSubscriptionBanner">+ <BannerSubscription />+ </template>+ <template v-if="shouldShowReadonlyBanner">+ <div+ class="px-3 py-1 w-full text-lg font-medium bg-yellow-500 text-white flex justify-center items-center"+ >+ {{ $t("banner.readonly") }}+ </div>+ </template>+</template>++<script lang="ts" setup>+import { storeToRefs } from "pinia";+import { computed } from "vue";+import {+ useActuatorStore,+ useCurrentUser,+ useDebugStore,+ useSubscriptionStore,+} from "@/store/modules";+import { isDBAOrOwner } from "@/utils";++const actuatorStore = useActuatorStore();+const currentUser = useCurrentUser();+const debugStore = useDebugStore();+const subscriptionStore = useSubscriptionStore();++const { isDemo, isReadonly } = storeToRefs(actuatorStore);+const { isDebug } = storeToRefs(debugStore);+const { isExpired, isTrialing } = storeToRefs(subscriptionStore);++const shouldShowDemoBanner = computed(() => {+ // demoName is the seeding data folder name, so the `dev`/`prod` isn't a valid feature demo name+ const demoName = actuatorStore.serverInfo?.demoName;+ const invalidFeatureDemoNameList = ["dev", "prod"];+ const isFeatureDemo =+ demoName && !invalidFeatureDemoNameList.includes(demoName);++ return isDemo && !isFeatureDemo;+});++// For now, debug mode is a global setting and will affect all users.+// So we only allow DBA and Owner to toggle it and thus show a banner+// reminding them to turn off+const shouldShowDebugBanner = computed(() => {+ return isDebug.value && isDBAOrOwner(currentUser.value.role);+});++const shouldShowSubscriptionBanner = computed(() => {+ return isExpired || isTrialing;+});++const shouldShowReadonlyBanner = computed(() => {+ return !isDemo && isReadonly;+});+</script>diff --git a/frontend/src/components/ProfileDropdown.vue b/frontend/src/components/ProfileDropdown.vueindex ee8cdf78ae..df98a7e1f7 100644--- a/frontend/src/components/ProfileDropdown.vue+++ b/frontend/src/components/ProfileDropdown.vue@@ -231,7 +231,7 @@ export default defineComponent({};const ping = () => {- actuatorStore.fetchInfo().then((info: ServerInfo) => {+ actuatorStore.fetchServerInfo().then((info: ServerInfo) => {pushNotification({module: "bytebase",style: "SUCCESS",diff --git a/frontend/src/layouts/DashboardLayout.vue b/frontend/src/layouts/DashboardLayout.vueindex 1d685175a7..81ddf739c0 100644--- a/frontend/src/layouts/DashboardLayout.vue+++ b/frontend/src/layouts/DashboardLayout.vue@@ -1,21 +1,6 @@<template><div class="relative h-screen overflow-hidden flex flex-col">- <template v-if="isDemo && !isLiveDemo">- <BannerDemo />- </template>- <template v-if="showDebugBanner">- <BannerDebug />- </template>- <template v-else-if="isExpired || isTrialing">- <BannerSubscription />- </template>- <template v-else-if="isReadonly && !isLiveDemo">- <div- class="px-3 py-1 w-full text-lg font-medium bg-yellow-500 text-white flex justify-center items-center"- >- {{ $t("banner.readonly") }}- </div>- </template>+ <BannersWrapper /><navclass="bg-white border-b border-block-border"data-label="bb-dashboard-header"@@ -47,39 +32,25 @@</template><script lang="ts">-import ProvideDashboardContext from "../components/ProvideDashboardContext.vue";-import DashboardHeader from "../views/DashboardHeader.vue";-import BannerDemo from "../views/BannerDemo.vue";-import BannerSubscription from "../views/BannerSubscription.vue";-import BannerDebug from "../views/BannerDebug.vue";-import { ServerInfo } from "../types";-import { isDBAOrOwner } from "../utils";-import { computed, defineComponent } from "vue";-import {- pushNotification,- useActuatorStore,- useCurrentUser,- useDebugStore,- useSubscriptionStore,-} from "@/store";-import { storeToRefs } from "pinia";+import { defineComponent } from "vue";+import { ServerInfo } from "@/types";+import { pushNotification, useActuatorStore } from "@/store";+import DashboardHeader from "@/views/DashboardHeader.vue";+import ProvideDashboardContext from "@/components/ProvideDashboardContext.vue";+import BannersWrapper from "@/components/BannersWrapper.vue";export default defineComponent({name: "DashboardLayout",components: {- ProvideDashboardContext,DashboardHeader,- BannerDemo,- BannerSubscription,- BannerDebug,+ ProvideDashboardContext,+ BannersWrapper,},setup() {const actuatorStore = useActuatorStore();- const subscriptionStore = useSubscriptionStore();- const debugStore = useDebugStore();const ping = () => {- actuatorStore.fetchInfo().then((info: ServerInfo) => {+ actuatorStore.fetchServerInfo().then((info: ServerInfo) => {pushNotification({module: "bytebase",style: "SUCCESS",@@ -88,28 +59,8 @@ export default defineComponent({});};- const { isDemo, isReadonly, isLiveDemo } = storeToRefs(actuatorStore);- const { isExpired, isTrialing } = storeToRefs(subscriptionStore);-- const { isDebug } = storeToRefs(debugStore);-- const currentUser = useCurrentUser();-- // For now, debug mode is a global setting and will affect all users.- // So we only allow DBA and Owner to toggle it and thus show a banner- // reminding them to turn off- const showDebugBanner = computed(() => {- return isDebug.value && isDBAOrOwner(currentUser.value.role);- });-return {ping,- isDemo,- isReadonly,- isTrialing,- isExpired,- isLiveDemo,- showDebugBanner,};},});diff --git a/frontend/src/layouts/SQLEditorLayout.vue b/frontend/src/layouts/SQLEditorLayout.vueindex dbac908a78..45c50cdf69 100644--- a/frontend/src/layouts/SQLEditorLayout.vue+++ b/frontend/src/layouts/SQLEditorLayout.vue@@ -1,12 +1,6 @@<template><div class="relative h-screen overflow-hidden flex flex-col">- <template v-if="isDemo">- <BannerDemo />- </template>- <template v-else-if="isExpired || isTrialing">- <BannerSubscription />- </template>-+ <BannersWrapper /><nav class="bg-white border-b border-block-border"><div class="max-w-full mx-auto px-4"><EditorHeader />@@ -36,22 +30,15 @@<script lang="ts" setup>import ProvideSQLEditorContext from "@/components/ProvideSQLEditorContext.vue";+import { ServerInfo } from "@/types";+import { pushNotification, useActuatorStore } from "@/store";import EditorHeader from "@/views/sql-editor/EditorHeader.vue";-import BannerDemo from "@/views/BannerDemo.vue";-import BannerSubscription from "@/views/BannerSubscription.vue";-import { ServerInfo } from "../types";-import {- pushNotification,- useActuatorStore,- useSubscriptionStore,-} from "@/store";-import { storeToRefs } from "pinia";+import BannersWrapper from "@/components/BannersWrapper.vue";const actuatorStore = useActuatorStore();-const subscriptionStore = useSubscriptionStore();const ping = () => {- actuatorStore.fetchInfo().then((info: ServerInfo) => {+ actuatorStore.fetchServerInfo().then((info: ServerInfo) => {pushNotification({module: "bytebase",style: "SUCCESS",@@ -59,7 +46,4 @@ const ping = () => {});});};--const { isDemo, isReadonly } = storeToRefs(actuatorStore);-const { isExpired, isTrialing } = storeToRefs(subscriptionStore);</script>diff --git a/frontend/src/layouts/SheetDashboardLayout.vue b/frontend/src/layouts/SheetDashboardLayout.vueindex 1dab767191..7d868d2edd 100644--- a/frontend/src/layouts/SheetDashboardLayout.vue+++ b/frontend/src/layouts/SheetDashboardLayout.vue@@ -49,7 +49,7 @@ const actuatorStore = useActuatorStore();const subscriptionStore = useSubscriptionStore();const ping = () => {- actuatorStore.fetchInfo().then((info: ServerInfo) => {+ actuatorStore.fetchServerInfo().then((info: ServerInfo) => {pushNotification({module: "bytebase",style: "SUCCESS",diff --git a/frontend/src/main.ts b/frontend/src/main.tsindex 888b40ecec..4739c6637f 100644--- a/frontend/src/main.ts+++ b/frontend/src/main.ts@@ -140,7 +140,7 @@ app// We use finally because we always want to mount the app regardless of the error.const initActuator = () => {const actuatorStore = useActuatorStore();- return actuatorStore.fetchInfo();+ return actuatorStore.fetchServerInfo();};const initSubscription = () => {const subscriptionStore = useSubscriptionStore();diff --git a/frontend/src/store/modules/actuator.ts b/frontend/src/store/modules/actuator.tsindex 76365a8d81..b66dc2798c 100644--- a/frontend/src/store/modules/actuator.ts+++ b/frontend/src/store/modules/actuator.ts@@ -1,5 +1,5 @@-import { defineStore } from "pinia";import axios from "axios";+import { defineStore } from "pinia";import { ActuatorState, ServerInfo } from "@/types";export const useActuatorStore = defineStore("actuator", {@@ -25,26 +25,18 @@ export const useActuatorStore = defineStore("actuator", {needAdminSetup: (state) => {return state.serverInfo?.needAdminSetup || false;},- isLiveDemo: (state) => {- return (- state.serverInfo?.demo &&- state.serverInfo?.demoName !== "" &&- state.serverInfo?.demoName !== "dev" &&- state.serverInfo?.demoName !== "prod"- );- },},actions: {- async fetchInfo() {+ setServerInfo(serverInfo: ServerInfo) {+ this.serverInfo = serverInfo;+ },+ async fetchServerInfo() {const serverInfo = (await axios.get(`/api/actuator/info`)).data as ServerInfo;- this.setInfo(serverInfo);+ this.setServerInfo(serverInfo);return serverInfo;},- setInfo(serverInfo: ServerInfo) {- this.serverInfo = serverInfo;- },},});diff --git a/frontend/src/views/auth/Signup.vue b/frontend/src/views/auth/Signup.vueindex 45331eee4e..ee6766f353 100644--- a/frontend/src/views/auth/Signup.vue+++ b/frontend/src/views/auth/Signup.vue@@ -319,7 +319,7 @@ export default defineComponent({// we need to update the server info after setting up the first admin account so that the splash screen// won't display the UI for registering the first admin account again.if (needAdminSetup.value) {- await actuatorStore.fetchInfo();+ await actuatorStore.fetchServerInfo();}router.push("/");});