Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(sql-editor): The sheet "Sample Sheet" should come open by default when a user enters SQL Editor for the first time (#4478)
Liu Ji1eae832af946
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex 0a0bfcfd24..6becd4e83a 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -47,6 +47,8 @@ import {useRouterStore,useDBSchemaStore,useConnectionTreeStore,+ useOnboardingStateStore,+ useTabStore,} from "@/store";const HOME_MODULE = "workspace.home";@@ -56,6 +58,7 @@ const SIGNUP_MODULE = "auth.signup";const ACTIVATE_MODULE = "auth.activate";const PASSWORD_RESET_MODULE = "auth.password.reset";const PASSWORD_FORGOT_MODULE = "auth.password.forgot";+const SQL_EDITOR_HOME_MODULE = "sql-editor.home";const routes: Array<RouteRecordRaw> = [{@@ -861,7 +864,7 @@ const routes: Array<RouteRecordRaw> = [children: [{path: "",- name: "sql-editor.home",+ name: SQL_EDITOR_HOME_MODULE,meta: { title: () => "SQL Editor" },component: () => import("../views/sql-editor/SQLEditorPage.vue"),props: true,@@ -974,6 +977,7 @@ router.beforeEach((to, from, next) => {to.name === PASSWORD_RESET_MODULE ||to.name === PASSWORD_FORGOT_MODULE) {+ useTabStore().reset();if (isLoggedIn) {if (typeof to.query.redirect === "string") {location.replace(to.query.redirect);@@ -1020,6 +1024,19 @@ router.beforeEach((to, from, next) => {return;}+ if (to.name === SQL_EDITOR_HOME_MODULE) {+ const onboardingStateStore = useOnboardingStateStore();+ if (onboardingStateStore.getStateByKey("sql-editor")) {+ // Open the "Sample Sheet" when the first time onboarding SQL Editor+ onboardingStateStore.consume("sql-editor");+ next({+ path: `/sql-editor/sheet/sample-sheet-101`,+ replace: true,+ });+ return;+ }+ }+const currentUser = authStore.currentUser;if (to.name?.toString().startsWith("setting.workspace.version-control")) {diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.tsindex e39765f99b..f9015971ef 100644--- a/frontend/src/store/modules/index.ts+++ b/frontend/src/store/modules/index.ts@@ -40,6 +40,7 @@ export * from "./task";export * from "./uistate";export * from "./vcs";export * from "./sqlReview";+export * from "./onboardingState";export * from "./onboardingGuide";export * from "./schemaEditor";export * from "./dbSchema";diff --git a/frontend/src/store/modules/onboardingState.ts b/frontend/src/store/modules/onboardingState.tsnew file mode 100644index 0000000000..b7afc3720e--- /dev/null+++ b/frontend/src/store/modules/onboardingState.ts@@ -0,0 +1,52 @@+import { defineStore } from "pinia";+import { useLocalStorage } from "@vueuse/core";++type OnboardingState = {+ isOnboarding: boolean;+ consumed: string[];+};+/**+ * OnboardingState will tell if we are onboarding the workspace, so we can do+ * some welcomes, tutorials, demonstrations if needed.+ *+ * example:+ * - { isOnboarding: false }+ * (the default and fallback value) means we are not onboarding the workspace+ * - { isOnboarding: true, consumed: ["a", "b"] }+ * means we are onboarding the workspace, and module "a" and "b" already+ * consumed the onboarding state.+ *+ * If the value in localStorage is gone (e.g., the user cleared the browser+ * data), the onboarding state will also be cleared. This is to ensure that the+ * onboarding actions will never fire more than once.+ */++export const useOnboardingStateStore = defineStore("onboardingState", () => {+ // states+ const state = useLocalStorage<OnboardingState>("bb.onboarding-state", {+ isOnboarding: false,+ consumed: [],+ });++ // actions+ const initialize = () => {+ state.value = {+ isOnboarding: true,+ consumed: [],+ };+ };+ const getStateByKey = (key: string) => {+ if (!state.value.isOnboarding) return false;+ return !state.value.consumed.includes(key);+ };+ const consume = (key: string) => {+ state.value.consumed.push(key);+ };++ // exposure+ return {+ initialize,+ getStateByKey,+ consume,+ };+});diff --git a/frontend/src/views/auth/Signup.vue b/frontend/src/views/auth/Signup.vueindex ff57de7799..3fc589bd92 100644--- a/frontend/src/views/auth/Signup.vue+++ b/frontend/src/views/auth/Signup.vue@@ -227,7 +227,11 @@ import {} from "vue";import { useRouter } from "vue-router";import { storeToRefs } from "pinia";-import { useActuatorStore, useAuthStore } from "@/store";+import {+ useActuatorStore,+ useAuthStore,+ useOnboardingStateStore,+} from "@/store";import { SignupInfo, TEXT_VALIDATION_DELAY } from "@/types";import { isValidEmail } from "@/utils";import AuthFooter from "./AuthFooter.vue";@@ -355,6 +359,11 @@ export default defineComponent({await useAuthStore().signup(signupInfo);if (needAdminSetup.value) {await actuatorStore.fetchServerInfo();+ // When the first time we created an end user, the server-side will+ // generate onboarding data.+ // We write a flag here to indicate that the workspace is just created+ // and we can consume this flag somewhere else if needed.+ useOnboardingStateStore().initialize();}router.replace("/");}diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vueindex ea08ecc617..32954d198a 100644--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue@@ -328,13 +328,17 @@ watch(isLoggedIn,() => tabStore.currentTab.connection.instanceId,() => tabStore.currentTab.connection.databaseId,+ () => connectionTreeStore.tree.state,],- ([isLoggedIn, instanceId, databaseId]) => {+ ([isLoggedIn, instanceId, databaseId, treeState]) => {if (!isLoggedIn) {// Don't go further and cleanup the state if we signed out.connectionTreeStore.expandedTreeNodeKeys = [];return;}+ if (treeState !== ConnectionTreeState.LOADED) {+ return;+ }if (instanceId !== UNKNOWN_ID) {maybeExpandKey(`instance-${instanceId}`);@@ -342,13 +346,14 @@ watch(if (databaseId !== UNKNOWN_ID) {maybeExpandKey(`database-${databaseId}`);const db = databaseStore.getDatabaseById(databaseId);+ console.log(db);const projectId = db.project.id;maybeExpandKey(`project-${projectId}`);}scrollToConnectedNode(instanceId, databaseId);},- { immediate: true, flush: "pre" }+ { immediate: true });</script>