Skip to content

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

feat: routing-based help (#2004)

ZhengX123e3a91c74c
diff --git a/frontend/public/help/routeMap.json b/frontend/public/help/routeMap.json
deleted file mode 100644
index 0a5bf51320..0000000000
--- a/frontend/public/help/routeMap.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "workspace.project": "help.project",
- "workspace.instance": "help.instance",
- "workspace.database": "help.database",
- "workspace.environment": "help.environment"
-}
diff --git a/frontend/public/help/routeMapList.json b/frontend/public/help/routeMapList.json
new file mode 100644
index 0000000000..b611b7aee1
--- /dev/null
+++ b/frontend/public/help/routeMapList.json
@@ -0,0 +1,206 @@
+[
+ {
+ "routeName": "auth",
+ "helpName": ""
+ },
+ {
+ "routeName": "auth.signin",
+ "helpName": ""
+ },
+ {
+ "routeName": "auth.signup",
+ "helpName": ""
+ },
+ {
+ "routeName": "auth.password.forgot",
+ "helpName": ""
+ },
+ {
+ "routeName": "oauth-callback",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.home",
+ "helpName": ""
+ },
+ {
+ "routeName": "error.403",
+ "helpName": ""
+ },
+ {
+ "routeName": "error.404",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.inbox",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.anomaly-center",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.archive",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.profile",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.profile",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.general",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.label",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.agent",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.project",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.member",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.version-control",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.version-control.create",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.version-control.detail",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.subscription",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.billing",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.integration.slack",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.sql-review",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.sql-review.create",
+ "helpName": ""
+ },
+ {
+ "routeName": "setting.workspace.sql-review.detail",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.issue",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.environment",
+ "helpName": "help.environment"
+ },
+ {
+ "routeName": "workspace.environment.detail",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.project",
+ "helpName": "help.project"
+ },
+ {
+ "routeName": "workspace.project.detail",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.project.hook.create",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.project.hook.detail",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.instance",
+ "helpName": "help.instance"
+ },
+ {
+ "routeName": "workspace.database",
+ "helpName": "help.database"
+ },
+ {
+ "routeName": "workspace.database.detail",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.database.table.detail",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.database.history.detail",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.instance.detail",
+ "helpName": ""
+ },
+ {
+ "routeName": "workspace.issue.detail",
+ "helpName": ""
+ },
+ {
+ "routeName": "sql-editor",
+ "helpName": ""
+ },
+ {
+ "routeName": "sql-editor.home",
+ "helpName": ""
+ },
+ {
+ "routeName": "sql-editor.detail",
+ "helpName": ""
+ },
+ {
+ "routeName": "sql-editor.share",
+ "helpName": ""
+ },
+ {
+ "routeName": "sheets",
+ "helpName": ""
+ },
+ {
+ "routeName": "sheets.dashboard",
+ "helpName": ""
+ },
+ {
+ "routeName": "sheets.my",
+ "helpName": ""
+ },
+ {
+ "routeName": "sheets.shared",
+ "helpName": ""
+ },
+ {
+ "routeName": "sheets.starred",
+ "helpName": ""
+ }
+]
\ No newline at end of file
diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index bf4dd676d9..2045ee1481 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -24,8 +24,8 @@
</template>
<script lang="ts" setup>
-import { reactive, watchEffect, onErrorCaptured } from "vue";
-import { useRouter } from "vue-router";
+import { reactive, watchEffect, onErrorCaptured, watch } from "vue";
+import { useRoute, useRouter } from "vue-router";
import { isDev } from "./utils";
import { BBNotificationItem } from "./bbkit/types";
@@ -36,7 +36,13 @@ import HelpDrawer from "@/components/HelpDrawer.vue";
import { NConfigProvider, NDialogProvider } from "naive-ui";
import { themeOverrides, dateLang, generalLang } from "../naive-ui.config";
import { t } from "./plugins/i18n";
-import { useAuthStore, useNotificationStore } from "./store";
+import {
+ useAuthStore,
+ useNotificationStore,
+ useUIStateStore,
+ useHelpStore,
+} from "./store";
+import { RouteMapList } from "@/types";
// Show at most 3 notifications to prevent excessive notification when shit hits the fan.
const MAX_NOTIFICATION_DISPLAY_COUNT = 3;
@@ -49,15 +55,20 @@ const CRITICAL_NOTIFICATION_DURATION = 10000;
interface LocalState {
notificationList: BBNotificationItem[];
prevLoggedIn: boolean;
+ helpTimer: number | null;
+ RouteMapList: RouteMapList | null;
}
const authStore = useAuthStore();
const notificationStore = useNotificationStore();
+const route = useRoute();
const router = useRouter();
const state = reactive<LocalState>({
notificationList: [],
prevLoggedIn: authStore.isLoggedIn(),
+ helpTimer: null,
+ RouteMapList: null,
});
setInterval(() => {
@@ -110,6 +121,40 @@ const watchNotification = () => {
}
};
+// watch route change for help
+watch(
+ () => route.name,
+ async (routeName) => {
+ const uiStateStore = useUIStateStore();
+ const helpStore = useHelpStore();
+
+ if (!state.RouteMapList) {
+ const res = await fetch("/help/routeMapList.json");
+ state.RouteMapList = await res.json();
+ }
+
+ // Clear timer after every route change.
+ if (state.helpTimer) {
+ clearTimeout(state.helpTimer);
+ state.helpTimer = null;
+ }
+
+ const helpName = state.RouteMapList?.find(
+ (pair) => pair.routeName === routeName
+ )?.helpName;
+
+ if (helpName && !uiStateStore.getIntroStateByKey(`guide.${helpName}`)) {
+ state.helpTimer = window.setTimeout(() => {
+ helpStore.showHelp(helpName, true);
+ uiStateStore.saveIntroStateByKey({
+ key: "environment.visit",
+ newState: true,
+ });
+ }, 1000);
+ }
+ }
+);
+
watchEffect(watchNotification);
onErrorCaptured((e: any /* , _, info */) => {
diff --git a/frontend/src/components/Breadcrumb.vue b/frontend/src/components/Breadcrumb.vue
index 3ae93e9515..b8162c9c29 100644
--- a/frontend/src/components/Breadcrumb.vue
+++ b/frontend/src/components/Breadcrumb.vue
@@ -51,19 +51,15 @@
</div>
</div>
- <HelpTriggerIcon
- v-if="currentRoute.name in routeHelpNameMap"
- :id="routeHelpNameMap[currentRoute.name]"
- :is-guide="true"
- />
+ <HelpTriggerIcon v-if="helpName" :id="helpName" :is-guide="true" />
</nav>
</template>
<script lang="ts">
-import { computed, ComputedRef, defineComponent } from "vue";
+import { computed, ComputedRef, defineComponent, onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
-import { Bookmark, UNKNOWN_ID, BookmarkCreate } from "../types";
+import { Bookmark, UNKNOWN_ID, BookmarkCreate, RouteMapList } from "../types";
import { idFromSlug } from "../utils";
import {
useCurrentUser,
@@ -74,7 +70,6 @@ import {
useProjectStore,
} from "@/store";
import HelpTriggerIcon from "@/components/HelpTriggerIcon.vue";
-import routeHelpNameMap from "../../public/help/routeMap.json";
interface BreadcrumbItem {
name: string;
@@ -95,6 +90,19 @@ export default defineComponent({
const currentUser = useCurrentUser();
const projectStore = useProjectStore();
+ const routeHelpNameMapList = ref<RouteMapList>([]);
+ const helpName = computed(
+ () =>
+ routeHelpNameMapList.value.find(
+ (pair) => pair.routeName === currentRoute.value.name
+ )?.helpName
+ );
+
+ onMounted(async () => {
+ const res = await fetch("/help/routeMapList.json");
+ routeHelpNameMapList.value = await res.json();
+ });
+
const bookmark: ComputedRef<Bookmark> = computed(() =>
bookmarkStore.bookmarkByUserAndLink(
currentUser.value.id,
@@ -215,7 +223,7 @@ export default defineComponent({
breadcrumbList,
toggleBookmark,
currentRoute,
- routeHelpNameMap,
+ helpName,
};
},
});
diff --git a/frontend/src/store/modules/help.ts b/frontend/src/store/modules/help.ts
index 908596d27d..2ea9b1035c 100644
--- a/frontend/src/store/modules/help.ts
+++ b/frontend/src/store/modules/help.ts
@@ -1,7 +1,10 @@
import { defineStore } from "pinia";
export const useHelpStore = defineStore("help", {
- state: () => {
+ state: (): {
+ currHelpId: string;
+ openByDefault: boolean;
+ } => {
return {
currHelpId: "",
openByDefault: false,
diff --git a/frontend/src/types/help.ts b/frontend/src/types/help.ts
new file mode 100644
index 0000000000..a54edccdde
--- /dev/null
+++ b/frontend/src/types/help.ts
@@ -0,0 +1,6 @@
+export type RouteMap = {
+ routeName: string;
+ helpName: string;
+};
+
+export type RouteMapList = RouteMap[];
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index 27d9e7a1e0..455f03cb06 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -11,6 +11,7 @@ export * from "./dataSource";
export * from "./environment";
export * from "./error";
export * from "./errorList";
+export * from "./help";
export * from "./id";
export * from "./inbox";
export * from "./instance";
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index 14336097e3..d1bea27a11 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -21,7 +21,6 @@ import {
computed,
watchEffect,
onMounted,
- onUnmounted,
reactive,
ref,
defineComponent,
@@ -38,7 +37,6 @@ import {
useEnvironmentList,
useEnvironmentStore,
useUIStateStore,
- useHelpStore,
} from "@/store";
interface LocalState {
@@ -55,10 +53,8 @@ export default defineComponent({
},
setup() {
const searchField = ref();
- const mountedTimer = ref();
const uiStateStore = useUIStateStore();
- const helpStore = useHelpStore();
const router = useRouter();
const state = reactive<LocalState>({
@@ -80,20 +76,13 @@ export default defineComponent({
searchField.value.$el.querySelector("#search").focus();
if (!uiStateStore.getIntroStateByKey("guide.help.database")) {
- mountedTimer.value = setTimeout(() => {
- helpStore.showHelp("help.database", true);
- uiStateStore.saveIntroStateByKey({
- key: "database.visit",
- newState: true,
- });
- }, 1000);
+ uiStateStore.saveIntroStateByKey({
+ key: "database.visit",
+ newState: true,
+ });
}
});
- onUnmounted(() => {
- clearTimeout(mountedTimer.value);
- });
-
const prepareDatabaseList = () => {
// It will also be called when user logout
if (currentUser.value.id != UNKNOWN_ID) {
diff --git a/frontend/src/views/EnvironmentDashboard.vue b/frontend/src/views/EnvironmentDashboard.vue
index 34c72d26d1..ff15b3afa7 100644
--- a/frontend/src/views/EnvironmentDashboard.vue
+++ b/frontend/src/views/EnvironmentDashboard.vue
@@ -60,15 +60,7 @@
</template>
<script lang="ts">
-import {
- onMounted,
- onUnmounted,
- computed,
- reactive,
- watch,
- defineComponent,
- ref,
-} from "vue";
+import { onMounted, computed, reactive, watch, defineComponent } from "vue";
import { useRouter } from "vue-router";
import { array_swap } from "../utils";
import EnvironmentDetail from "../views/EnvironmentDetail.vue";
@@ -91,7 +83,6 @@ import {
usePolicyStore,
useEnvironmentStore,
useEnvironmentList,
- useHelpStore,
} from "@/store";
const DEFAULT_NEW_ENVIRONMENT: EnvironmentCreate = {
@@ -133,9 +124,7 @@ export default defineComponent({
const environmentStore = useEnvironmentStore();
const uiStateStore = useUIStateStore();
const policyStore = usePolicyStore();
- const helpStore = useHelpStore();
const router = useRouter();
- const mountedTimer = ref();
const state = reactive<LocalState>({
reorderedEnvironmentList: [],
@@ -166,20 +155,13 @@ export default defineComponent({
selectEnvironmentOnHash();
if (!uiStateStore.getIntroStateByKey("guide.help.environment")) {
- mountedTimer.value = setTimeout(() => {
- helpStore.showHelp("help.environment", true);
- uiStateStore.saveIntroStateByKey({
- key: "environment.visit",
- newState: true,
- });
- }, 1000);
+ uiStateStore.saveIntroStateByKey({
+ key: "environment.visit",
+ newState: true,
+ });
}
});
- onUnmounted(() => {
- clearTimeout(mountedTimer.value);
- });
-
useRegisterCommand({
id: "bb.environment.create",
registerId: "environment.dashboard",
diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vue
index 94f9ae6958..9702748c11 100644
--- a/frontend/src/views/InstanceDashboard.vue
+++ b/frontend/src/views/InstanceDashboard.vue
@@ -23,14 +23,7 @@
</template>
<script lang="ts">
-import {
- computed,
- onMounted,
- onUnmounted,
- reactive,
- ref,
- defineComponent,
-} from "vue";
+import { computed, onMounted, reactive, ref, defineComponent } from "vue";
import { useRouter } from "vue-router";
import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";
import InstanceTable from "../components/InstanceTable.vue";
@@ -45,7 +38,6 @@ import {
useEnvironmentList,
useInstanceList,
useInstanceStore,
- useHelpStore,
} from "@/store";
interface LocalState {
@@ -61,12 +53,10 @@ export default defineComponent({
},
setup() {
const searchField = ref();
- const mountedTimer = ref();
const instanceStore = useInstanceStore();
const subscriptionStore = useSubscriptionStore();
const uiStateStore = useUIStateStore();
- const helpStore = useHelpStore();
const router = useRouter();
const { t } = useI18n();
@@ -86,20 +76,13 @@ export default defineComponent({
searchField.value.$el.querySelector("#search").focus();
if (!uiStateStore.getIntroStateByKey("guide.help.instance")) {
- mountedTimer.value = setTimeout(() => {
- helpStore.showHelp("help.instance", true);
- uiStateStore.saveIntroStateByKey({
- key: "instance.visit",
- newState: true,
- });
- }, 1000);
+ uiStateStore.saveIntroStateByKey({
+ key: "instance.visit",
+ newState: true,
+ });
}
});
- onUnmounted(() => {
- clearTimeout(mountedTimer.value);
- });
-
const selectEnvironment = (environment: Environment) => {
state.selectedEnvironment = environment;
if (environment) {
diff --git a/frontend/src/views/ProjectDashboard.vue b/frontend/src/views/ProjectDashboard.vue
index e9ea634f1d..cb72f85c5a 100644
--- a/frontend/src/views/ProjectDashboard.vue
+++ b/frontend/src/views/ProjectDashboard.vue
@@ -24,21 +24,9 @@
</template>
<script lang="ts">
-import {
- useCurrentUser,
- useUIStateStore,
- useProjectStore,
- useHelpStore,
-} from "@/store";
+import { useCurrentUser, useUIStateStore, useProjectStore } from "@/store";
import { useRouter } from "vue-router";
-import {
- watchEffect,
- onMounted,
- onUnmounted,
- reactive,
- ref,
- defineComponent,
-} from "vue";
+import { watchEffect, onMounted, reactive, ref, defineComponent } from "vue";
import ProjectTable from "../components/ProjectTable.vue";
import { Project, UNKNOWN_ID, DEFAULT_PROJECT_ID } from "../types";
@@ -55,12 +43,10 @@ export default defineComponent({
setup() {
const router = useRouter();
const searchField = ref();
- const mountedTimer = ref();
const uiStateStore = useUIStateStore();
const currentUser = useCurrentUser();
const projectStore = useProjectStore();
- const helpStore = useHelpStore();
const state = reactive<LocalState>({
projectList: [],
@@ -72,20 +58,13 @@ export default defineComponent({
searchField.value.$el.querySelector("#search").focus();
if (!uiStateStore.getIntroStateByKey("guide.help.project")) {
- mountedTimer.value = setTimeout(() => {
- helpStore.showHelp("help.project", true);
- uiStateStore.saveIntroStateByKey({
- key: "project.visit",
- newState: true,
- });
- }, 1000);
+ uiStateStore.saveIntroStateByKey({
+ key: "project.visit",
+ newState: true,
+ });
}
});
- onUnmounted(() => {
- clearTimeout(mountedTimer.value);
- });
-
const prepareProjectList = () => {
// It will also be called when user logout
if (currentUser.value.id != UNKNOWN_ID) {