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 onboarding guide checking component (#2401)
boojackcc1d86c6b9bc
diff --git a/frontend/src/App.vue b/frontend/src/App.vueindex 273cb483a8..3bc336b087 100644--- a/frontend/src/App.vue+++ b/frontend/src/App.vue@@ -21,6 +21,11 @@</BBModalStack></NDialogProvider></NConfigProvider>++ <!-- teleport onboarding guide to document.body -->+ <teleport to="body">+ <OnboardingGuide />+ </teleport></template><script lang="ts" setup>diff --git a/frontend/src/components/CreateDataSourceExample.vue b/frontend/src/components/CreateDataSourceExample.vueindex 92851ed85c..6e037a7c64 100644--- a/frontend/src/components/CreateDataSourceExample.vue+++ b/frontend/src/components/CreateDataSourceExample.vue@@ -70,11 +70,11 @@<BBAttentionclass="mb-1":style="'WARN'"- :title="$t('instance.sentence.create-user-example.postgres.warn')"+ :title="$t('instance.sentence.create-user-example.postgresql.warn')"/><i18n-ttag="p"- keypath="instance.sentence.create-user-example.postgres.template"+ keypath="instance.sentence.create-user-example.postgresql.template"><template #password><span class="text-red-600">YOUR_DB_PWD</span>diff --git a/frontend/src/components/CreateInstanceForm.vue b/frontend/src/components/CreateInstanceForm.vueindex 342ac6f8f4..44c0e968a1 100644--- a/frontend/src/components/CreateInstanceForm.vue+++ b/frontend/src/components/CreateInstanceForm.vue@@ -232,15 +232,10 @@<BBAlertv-if="state.showCreateInstanceWarningModal":style="'WARN'"- :ok-text="$t('instance.ignore-and-create')"+ :ok-text="warningModalOkText":title="$t('instance.connection-info-seems-to-be-incorrect')":description="state.createInstanceWarning"- @ok="- () => {- state.showCreateInstanceWarningModal = false;- doCreate();- }- "+ @ok="handleWarningModalOkClick"@cancel="state.showCreateInstanceWarningModal = false"></BBAlert></template>@@ -261,7 +256,12 @@ import {} from "../types";import isEmpty from "lodash-es/isEmpty";import { useI18n } from "vue-i18n";-import { pushNotification, useInstanceStore, useSQLStore } from "@/store";+import {+ pushNotification,+ useInstanceStore,+ useOnboardingGuideStore,+ useSQLStore,+} from "@/store";interface LocalState {instance: InstanceCreate;@@ -333,6 +333,19 @@ const showSSL = computed((): boolean => {return state.instance.engine === "CLICKHOUSE";});+const isInOnboaringCreateDatabaseGuide = computed(() => {+ const guideName = useOnboardingGuideStore().guideName;+ return guideName === "create-database";+});++const warningModalOkText = computed(() => {+ if (isInOnboaringCreateDatabaseGuide.value) {+ return t("instance.create-an-onboarding-postgresql-instance");+ } else {+ return t("instance.ignore-and-create");+ }+});+watch(showSSL, (ssl) => {// Clean up SSL options when they are not needed.if (!ssl) {@@ -414,6 +427,33 @@ const updateInstance = (field: string, value: string) => {(state.instance as any)[field] = str;};+const handleWarningModalOkClick = async () => {+ // When user get the warning of incorrect instance info in creating database onboarding guide,+ // we'd like to display the `create an embedded PostgreSQL database` button instead of `ignore and create`.+ if (isInOnboaringCreateDatabaseGuide.value) {+ const connectionInfo =+ await useInstanceStore().createEmbeddedPostgresInstance();+ state.instance = {+ ...state.instance,+ engine: "POSTGRES",+ host: connectionInfo.host,+ port: String(connectionInfo.port),+ username: connectionInfo.username,+ password: "",+ };+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.success"),+ description: t("instance.successfully-created-postgresql-instance"),+ });+ state.showCreateInstanceWarningModal = false;+ } else {+ state.showCreateInstanceWarningModal = false;+ doCreate();+ }+};+const cancel = () => {emit("dismiss");};diff --git a/frontend/src/components/OnboardingGuide.vue b/frontend/src/components/OnboardingGuide.vuenew file mode 100644index 0000000000..0af92fd7ee--- /dev/null+++ b/frontend/src/components/OnboardingGuide.vue@@ -0,0 +1,60 @@+<template>+ <CreateDatabaseGuide+ v-if="shouldShowCreateDatabaseGuide"+ ></CreateDatabaseGuide>+</template>++<script lang="ts" setup>+import { ref, watch } from "vue";+import {+ useCurrentUser,+ useProjectStore,+ useInstanceStore,+ useDatabaseStore,+ useOnboardingGuideStore,+} from "@/store";+import { UNKNOWN_ID } from "@/types";+import { isOwner } from "@/utils";+import CreateDatabaseGuide from "./OnboardingGuides/CreateDatabaseGuide.vue";++const currentUser = useCurrentUser();+const guideStore = useOnboardingGuideStore();++const shouldShowCreateDatabaseGuide = ref(false);++const checkShouldShowCreateDatabaseGuide = async () => {+ // Show create database guide when user is owner and no data at all.+ if (isOwner(currentUser.value.role)) {+ const instanceList = await useInstanceStore().fetchInstanceList();+ const projectList = await useProjectStore().fetchAllProjectList();+ const databaseList = await useDatabaseStore().fetchDatabaseList();++ if (+ instanceList.length === 0 &&+ projectList.length === 0 &&+ databaseList.length === 0+ ) {+ return true;+ }+ }++ return false;+};++watch(+ currentUser,+ async () => {+ // Check should show guide only when user is logged in.+ if (currentUser.value.id !== UNKNOWN_ID) {+ shouldShowCreateDatabaseGuide.value =+ await checkShouldShowCreateDatabaseGuide();+ if (shouldShowCreateDatabaseGuide.value) {+ guideStore.setGuideName("create-database");+ }+ }+ },+ {+ immediate: true,+ }+);+</script>diff --git a/frontend/src/components/OnboardingGuides/CreateDatabaseGuide.vue b/frontend/src/components/OnboardingGuides/CreateDatabaseGuide.vuenew file mode 100644index 0000000000..5d5f1f7673--- /dev/null+++ b/frontend/src/components/OnboardingGuides/CreateDatabaseGuide.vue@@ -0,0 +1,3 @@+<template>+ <!-- It's a placeholder and will be update in next PR. -->+</template>diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vueindex 67a1a3a62a..cfd832f3a6 100644--- a/frontend/src/components/QuickActionPanel.vue+++ b/frontend/src/components/QuickActionPanel.vue@@ -4,8 +4,9 @@><template v-for="(quickAction, index) in quickActionList" :key="index"><div- v-if="quickAction == 'quickaction.bb.instance.create'"+ v-if="quickAction === 'quickaction.bb.instance.create'"class="flex flex-col items-center w-28"+ data-label="bb-quick-action-add-instance"><button class="btn-icon-primary p-3" @click.prevent="createInstance"><heroicons-outline:plus-sm class="w-6 h-6" />@@ -16,7 +17,7 @@</div><div- v-if="quickAction == 'quickaction.bb.user.manage'"+ v-if="quickAction === 'quickaction.bb.user.manage'"class="flex flex-col items-center w-28"><router-link to="/setting/member" class="btn-icon-primary p-3">@@ -30,36 +31,9 @@</div><div- v-if="quickAction == 'quickaction.bb.database.query'"- class="flex flex-col items-center w-28"- >- <button class="btn-icon-primary p-3">- <heroicons-outline:search class="w-6 h-6" />- </button>- <h3- class="mt-1 text-center text-base font-normal text-main tracking-tight"- >- {{ $t("common.query") }}- </h3>- </div>-- <div- v-if="quickAction == 'quickaction.bb.database.data.edit'"- class="flex flex-col items-center w-28"- >- <button class="btn-icon-primary p-3">- <heroicons-outline:pencil-alt class="w-6 h-6" />- </button>- <h3- class="mt-1 text-center text-base font-normal text-main tracking-tight"- >- {{ $t("quick-action.edit-data") }}- </h3>- </div>-- <div- v-if="quickAction == 'quickaction.bb.database.create'"+ v-if="quickAction === 'quickaction.bb.database.create'"class="flex flex-col items-center w-28"+ data-label="bb-quick-action-new-db"><button class="btn-icon-primary p-3" @click.prevent="createDatabase"><heroicons-outline:database class="w-6 h-6" />@@ -72,7 +46,7 @@</div><div- v-if="quickAction == 'quickaction.bb.database.request'"+ v-if="quickAction === 'quickaction.bb.database.request'"class="flex flex-col items-center w-28"><button class="btn-icon-primary p-3" @click.prevent="requestDatabase">@@ -86,7 +60,7 @@</div><div- v-if="quickAction == 'quickaction.bb.database.schema.update'"+ v-if="quickAction === 'quickaction.bb.database.schema.update'"class="flex flex-col items-center w-28"><button@@ -102,7 +76,7 @@</div><div- v-if="quickAction == 'quickaction.bb.database.data.update'"+ v-if="quickAction === 'quickaction.bb.database.data.update'"class="flex flex-col items-center w-28"><button class="btn-icon-primary p-3" @click.prevent="changeData">@@ -114,7 +88,7 @@</div><div- v-if="quickAction == 'quickaction.bb.database.troubleshoot'"+ v-if="quickAction === 'quickaction.bb.database.troubleshoot'"class="flex flex-col items-center w-28"><router-link to="/issue/new" class="btn-icon-primary p-3">@@ -126,7 +100,7 @@</div><div- v-if="quickAction == 'quickaction.bb.environment.create'"+ v-if="quickAction === 'quickaction.bb.environment.create'"class="flex flex-col items-center w-36"><button class="btn-icon-primary p-3" @click.prevent="createEnvironment">@@ -138,7 +112,7 @@</div><div- v-if="quickAction == 'quickaction.bb.environment.reorder'"+ v-if="quickAction === 'quickaction.bb.environment.reorder'"class="flex flex-col items-center w-28"><button@@ -153,8 +127,9 @@</div><div- v-if="quickAction == 'quickaction.bb.project.create'"+ v-if="quickAction === 'quickaction.bb.project.create'"class="flex flex-col items-center w-28"+ data-label="bb-quick-action-new-project"><button class="btn-icon-primary p-3" @click.prevent="createProject"><heroicons-outline:template class="w-6 h-6" />@@ -165,7 +140,7 @@</div><div- v-if="quickAction == 'quickaction.bb.project.database.transfer'"+ v-if="quickAction === 'quickaction.bb.project.database.transfer'"class="flex flex-col items-center w-28"><button class="btn-icon-primary p-3" @click.prevent="transferDatabase">diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex d4ce1ed049..81a6e44fa1 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -205,7 +205,8 @@"fix": "Fix","go-now": "Go now","sync-now": "Sync Now",- "show-help": "Show help"+ "show-help": "Show help",+ "success": "Succeed"},"error-page": {"go-back-home": "Go back home"@@ -629,7 +630,7 @@"template": "Below is an example to create user 'bytebase' with password {password} and grant the user with the needed privileges. First you need to enable ClickHouse SQL-driven workflow {link} and then run the following query to create the user.","sql-driven-workflow": "SQL-driven workflow"},- "postgres": {+ "postgresql": {"warn": "If the connecting instance is managed by the cloud provider, then SUPERUSER is not available and you should create the user via that provider's admin console. The created user will have provider specific semi-SUPERUSER privileges.","template": "Below is an example to create user 'bytebase' with password {password} and grant the user with the needed privileges. If the connecting instance is self-hosted, then you can grant SUPERUSER."}@@ -639,6 +640,8 @@"password-write-only": "YOUR_DB_PWD - write only","test-connection": "Test Connection","ignore-and-create": "Ignore and create",+ "create-an-onboarding-postgresql-instance": "Create an onboarding PostgreSQL instance",+ "successfully-created-postgresql-instance": "Successfully created onboarding PostgreSQL instance and automatically filled into the form.","connection-info-seems-to-be-incorrect": "Connection info seems to be incorrect","new-instance": "New Instance","unable-to-connect": "Bytebase is unable to connect the instance. We recommend you to review the connection info again. But it's OK to ignore this warning for now. You can still fix the connection info from the instance detail page after creation.\n\nError detail: {0}",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 1cba6bde9d..421437f94f 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -205,7 +205,8 @@"fix": "修复","go-now": "立即前往","sync-now": "现在同步",- "show-help": "查看帮助"+ "show-help": "查看帮助",+ "success": "成功"},"error-page": {"go-back-home": "回到主页"@@ -630,7 +631,7 @@"sql-driven-workflow": "SQL 工作流","template": "创建用户 bytebase,密码 {password},并授予必要权限的例子如下。您需要首先启用 {link},才能执行以下创建用户的命令。"},- "postgres": {+ "postgresql": {"warn": "如果您将要连接到的实例是由云服务供应商管理的话,那么 SUPERUSER 是不可用的,您需要通过供应商的管理员控制台来创建用户。您所创建的用户会拥有供应商特定的 semi-SUPERUSER 的权限。","template": "创建用户 bytebase,密码 {password},并授予必要权限的例子如下。如果您将要连接到的实例是自己托管的,那么您可以 grant SUPERUSER。"}@@ -640,6 +641,8 @@"password-write-only": "YOUR_DB_PWD - 仅写入","test-connection": "测试连接","ignore-and-create": "忽略并创建",+ "create-an-onboarding-postgresql-instance": "创建一个临时的 PostgreSQL 数据库实例",+ "successfully-created-postgresql-instance": "成功创建临时的 PostgreSQL 数据库实例,并已经自动填充至表单。","connection-info-seems-to-be-incorrect": "连接信息似乎错误","new-instance": "新实例","unable-to-connect": "Bytebase 无法连接到实例。我们推荐您再检查一遍连接信息。但也可以暂时忽略此警告。您在创建后仍能在实例详细页里修复连接信息。\n\n错误详情:{0}",diff --git a/frontend/src/plugins/demo/guide.ts b/frontend/src/plugins/demo/guide.tsindex f063262373..b5ce956ba0 100644--- a/frontend/src/plugins/demo/guide.ts+++ b/frontend/src/plugins/demo/guide.ts@@ -42,7 +42,8 @@ export const showGuideDialog = async (return;}- const targetElement = await waitForTargetElement(guideStep.selectors);+ // NOTE: stay empty value for now.+ const targetElement = await waitForTargetElement("");if (targetElement) {// After got the targetElement, remove the guide dialog again// to ensure that only one guide dialog is shown at a time.diff --git a/frontend/src/plugins/demo/hint.ts b/frontend/src/plugins/demo/hint.tsindex 35c361e705..cc48344f62 100644--- a/frontend/src/plugins/demo/hint.ts+++ b/frontend/src/plugins/demo/hint.ts@@ -21,7 +21,7 @@ export const showHints = async (hintDataList: HintData[]) => {return;}- const targetElement = await waitForTargetElement([[hintData.selector]]);+ const targetElement = await waitForTargetElement(hintData.selector);if (targetElement) {renderHint(targetElement, hintData, index);} else {diff --git a/frontend/src/plugins/demo/utils.ts b/frontend/src/plugins/demo/utils.tsindex 6e401084ec..f49035a8d9 100644--- a/frontend/src/plugins/demo/utils.ts+++ b/frontend/src/plugins/demo/utils.ts@@ -99,30 +99,18 @@ const getTargetElementWithSelector = (selector: string) => {return targetElement;};-const getTargetElementBySelectors = (selectorsList: string[][]) => {- for (const selectors of selectorsList) {- for (const selector of selectors) {- const targetElement = getTargetElementWithSelector(selector);- if (targetElement) {- return targetElement;- }- }- }- return null;-};-// waitForTargetElement will wait for the target element to be available in the DOM.export const waitForTargetElement = (- selectors: string[][]+ selector: string): Promise<HTMLElement> => {return new Promise((resolve) => {- let targetElement = getTargetElementBySelectors(selectors);+ let targetElement = getTargetElementWithSelector(selector);if (targetElement) {return resolve(targetElement);}const observer = new MutationObserver(() => {- targetElement = getTargetElementBySelectors(selectors);+ targetElement = getTargetElementWithSelector(selector);if (targetElement) {observer.disconnect();return resolve(targetElement);diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.tsindex 023b2ad2ff..eccfe95f69 100644--- a/frontend/src/store/modules/index.ts+++ b/frontend/src/store/modules/index.ts@@ -41,3 +41,4 @@ export * from "./vcs";export * from "./view";export * from "./db_extension";export * from "./sqlReview";+export * from "./onboardingGuide";diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.tsindex 1597efc1fd..8262890297 100644--- a/frontend/src/store/modules/instance.ts+++ b/frontend/src/store/modules/instance.ts@@ -512,6 +512,17 @@ export const useInstanceStore = defineStore("instance", {return historyList;},+ async createEmbeddedPostgresInstance() {+ const data = (+ await axios.post<{+ host: string;+ port: number;+ username: string;+ }>("/api/instance/new-embedded-pg")+ ).data;++ return data;+ },},});diff --git a/frontend/src/store/modules/issue.ts b/frontend/src/store/modules/issue.tsindex 891af4b212..b97a1dd20c 100644--- a/frontend/src/store/modules/issue.ts+++ b/frontend/src/store/modules/issue.ts@@ -117,6 +117,11 @@ export const useIssueStore = defineStore("issue", {state: (): IssueState => ({issueById: new Map(),}),+ getters: {+ issueList: (state) => {+ return [...state.issueById.values()];+ },+ },actions: {getIssueById(issueId: IssueId): Issue {if (issueId == EMPTY_ID) {diff --git a/frontend/src/store/modules/onboardingGuide.ts b/frontend/src/store/modules/onboardingGuide.tsnew file mode 100644index 0000000000..b1e3fb69e7--- /dev/null+++ b/frontend/src/store/modules/onboardingGuide.ts@@ -0,0 +1,13 @@+import { defineStore } from "pinia";+import { OnboardingGuideType, OnboardingGuideState } from "@/types";++export const useOnboardingGuideStore = defineStore("onboarding_guide", {+ state: (): OnboardingGuideState => ({+ guideName: undefined,+ }),+ actions: {+ setGuideName(guideName: OnboardingGuideType) {+ this.guideName = guideName;+ },+ },+});diff --git a/frontend/src/store/modules/project.ts b/frontend/src/store/modules/project.tsindex 5161cad691..579b6deb2a 100644--- a/frontend/src/store/modules/project.ts+++ b/frontend/src/store/modules/project.ts@@ -121,7 +121,11 @@ export const useProjectStore = defineStore("project", {state: (): ProjectState => ({projectById: new Map(),}),-+ getters: {+ projectList: (state) => {+ return [...state.projectById.values()];+ },+ },actions: {convert(instance: ResourceObject, includedList: ResourceObject[]): Project {return convert(instance, includedList || []);@@ -161,7 +165,7 @@ export const useProjectStore = defineStore("project", {const data = (await axios.get(`/api/project`)).data;const projectList = data.data.map((project: ResourceObject) => {return convert(project, data.included);- });+ }) as Project[];this.upsertProjectList(projectList);return projectList;diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex 3798d1a37d..d282937556 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -44,3 +44,4 @@ export * from "./sheet";export * from "./sheetOrganizer";export * from "./sqlReview";export * from "./utils";+export * from "./onboardingGuide";diff --git a/frontend/src/types/onboardingGuide.ts b/frontend/src/types/onboardingGuide.tsnew file mode 100644index 0000000000..7c3a98617e--- /dev/null+++ b/frontend/src/types/onboardingGuide.ts@@ -0,0 +1 @@+export type OnboardingGuideType = "create-database";diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.tsindex 41543ddf23..96cc1d2f2f 100644--- a/frontend/src/types/store.ts+++ b/frontend/src/types/store.ts@@ -9,6 +9,7 @@ import {View,DBExtension,Sheet,+ OnboardingGuideType,} from ".";import { Activity } from "./activity";import { ServerInfo } from "./actuator";@@ -219,3 +220,7 @@ export interface SheetState {export interface DebugState {isDebug: boolean;}++export interface OnboardingGuideState {+ guideName?: OnboardingGuideType;+}diff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vueindex 9138461be1..5f50388a11 100644--- a/frontend/src/views/DashboardHeader.vue+++ b/frontend/src/views/DashboardHeader.vue@@ -24,6 +24,7 @@to="/project"class="bar-link px-2 py-2 rounded-md":class="getRouteLinkClass('/project')"+ data-label="bb-header-project-button">{{ $t("common.projects") }}</router-link>