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 more configurable fields to guide (#1680)
boojackea232523f0cc
diff --git a/frontend/src/plugins/demo/guide.ts b/frontend/src/plugins/demo/guide.tsindex f95ab30f27..29dc9fab89 100644--- a/frontend/src/plugins/demo/guide.ts+++ b/frontend/src/plugins/demo/guide.ts@@ -1,26 +1,8 @@import { merge } from "lodash-es";-import { getElementBounding } from "./utils";+import { getElementBounding, waitForTargetElement } from "./utils";import * as storage from "./storage";import { GuidePosition, StepData } from "./types";-const getTargetElementBySelectors = (selectors: string[][]) => {- let targetElement = document.body;- for (const selector of selectors) {- try {- targetElement = document.body.querySelector(- selector.join(" ")- ) as HTMLElement;- } catch (error) {- // do nth- }-- if (targetElement) {- break;- }- }- return targetElement;-};-export const showGuideDialog = async (guideStep: StepData) => {removeGuideDialog();const targetElement = await waitForTargetElement(guideStep.selectors);@@ -28,13 +10,23 @@ export const showGuideDialog = async (guideStep: StepData) => {// After got the targetElement, remove the guide dialog again// to ensure that only one guide dialog is shown at a time.removeGuideDialog();- renderHighlightWrapper(targetElement);+ if (guideStep.cover) {+ renderCover();+ targetElement.classList.add("bb-guide-target-element");+ }+ renderHighlight(targetElement);renderGuideDialog(targetElement, guideStep);requestAnimationFrame(() => updateGuidePosition(targetElement, guideStep));}};-const renderHighlightWrapper = (targetElement: HTMLElement) => {+const renderCover = () => {+ const coverElement = document.createElement("div");+ coverElement.className = "bb-guide-cover-wrapper";+ document.body.appendChild(coverElement);+};++const renderHighlight = (targetElement: HTMLElement) => {const highlightWrapper = document.createElement("div");highlightWrapper.className = "bb-guide-highlight-wrapper";document.body.appendChild(highlightWrapper);@@ -51,6 +43,12 @@ const renderGuideDialog = (targetElement: HTMLElement, guideStep: StepData) => {guideDialogDiv.className = "bb-guide-dialog";adjustGuideDialogPosition(targetElement, guideDialogDiv, guideStep.position);+ const closeButton = document.createElement("button");+ closeButton.className = "bb-guide-close-button";+ closeButton.innerHTML = "×";+ closeButton.addEventListener("click", () => removeGuideDialog());+ guideDialogDiv.appendChild(closeButton);+const titleElement = document.createElement("p");titleElement.className = "bb-guide-title-text";titleElement.innerText = title;@@ -159,28 +157,6 @@ const updateGuidePosition = (requestAnimationFrame(() => updateGuidePosition(targetElement, guideStep));};-const waitForTargetElement = (selectors: string[][]): Promise<HTMLElement> => {- return new Promise((resolve) => {- let targetElement = getTargetElementBySelectors(selectors);- if (targetElement) {- return resolve(targetElement);- }-- const observer = new MutationObserver(() => {- targetElement = getTargetElementBySelectors(selectors);- if (targetElement) {- observer.disconnect();- return resolve(targetElement);- }- });-- observer.observe(document.body, {- childList: true,- subtree: true,- });- });-};-export const removeGuideDialog = () => {document.body.querySelectorAll(".bb-guide-dialog")?.forEach((element) => {element.remove();@@ -190,4 +166,14 @@ export const removeGuideDialog = () => {?.forEach((element) => {element.remove();});+ document.body+ .querySelectorAll(".bb-guide-cover-wrapper")+ ?.forEach((element) => {+ element.remove();+ });+ document.body+ .querySelectorAll(".bb-guide-target-element")+ ?.forEach((element) => {+ element.classList.remove("bb-guide-target-element");+ });};diff --git a/frontend/src/plugins/demo/style.css b/frontend/src/plugins/demo/style.cssindex a620bf75bc..c5dc921a6b 100644--- a/frontend/src/plugins/demo/style.css+++ b/frontend/src/plugins/demo/style.css@@ -1,13 +1,28 @@+.bb-guide-cover-wrapper {+ @apply fixed inset-0;+ background-color: rgb(33 33 33 / 30%);+ z-index: 999998;+}++.bb-guide-target-element {+ z-index: 999999;+}+.bb-guide-highlight-wrapper {@apply absolute rounded pointer-events-none;box-shadow: rgb(33 33 33 / 80%) 0px 0px 1px 2px;- z-index: 9999999;+ z-index: 999999;}.bb-guide-dialog {@apply absolute bg-white w-72 m-1 text-black p-2 px-3 rounded-lg text-left;box-shadow: 0 3px 30px rgb(33 33 33 / 30%);- z-index: 10000000;+ z-index: 1000000;+}++.bb-guide-close-button {+ @apply absolute top-0 right-1 px-1 text-xl rounded opacity-80 hover:opacity-60;+ cursor: pointer;}.bb-guide-title-text {diff --git a/frontend/src/plugins/demo/types.ts b/frontend/src/plugins/demo/types.tsindex 7d1f428258..a67b5ff7fc 100644--- a/frontend/src/plugins/demo/types.ts+++ b/frontend/src/plugins/demo/types.ts@@ -13,11 +13,11 @@ export interface StepData {value?: string;// position is the position of the guide dialog, default is bottomposition?: GuidePosition;+ // cover is the flag that should be shown for the guide dialog+ cover?: boolean;}export interface GuideData {name: string;steps: StepData[];- // cover is the flag that should be shown for the guide dialog- cover?: boolean;}diff --git a/frontend/src/plugins/demo/utils.ts b/frontend/src/plugins/demo/utils.tsindex ce65533f08..eec5749ae1 100644--- a/frontend/src/plugins/demo/utils.ts+++ b/frontend/src/plugins/demo/utils.ts@@ -71,3 +71,45 @@ export const getElementBounding = (left: elementRect.left + scrollLeft,});};++const getTargetElementBySelectors = (selectors: string[][]) => {+ let targetElement = document.body;+ for (const selector of selectors) {+ try {+ targetElement = document.body.querySelector(+ selector.join(" ")+ ) as HTMLElement;+ } catch (error) {+ // do nth+ }++ if (targetElement) {+ break;+ }+ }+ return targetElement;+};++export const waitForTargetElement = (+ selectors: string[][]+): Promise<HTMLElement> => {+ return new Promise((resolve) => {+ let targetElement = getTargetElementBySelectors(selectors);+ if (targetElement) {+ return resolve(targetElement);+ }++ const observer = new MutationObserver(() => {+ targetElement = getTargetElementBySelectors(selectors);+ if (targetElement) {+ observer.disconnect();+ return resolve(targetElement);+ }+ });++ observer.observe(document.body, {+ childList: true,+ subtree: true,+ });+ });+};diff --git a/frontend/static/demo/schema-migration/guide.json b/frontend/static/demo/schema-migration/guide.jsonindex 8e14dfcae8..abc3010b37 100644--- a/frontend/static/demo/schema-migration/guide.json+++ b/frontend/static/demo/schema-migration/guide.json@@ -6,7 +6,8 @@"title": "Click the Alter Schema button","description": "Alter schema is a main feature of Bytebase","selectors": [["[data-label='bb-alter-schema-button']"]],- "url": "http://localhost:3000"+ "url": "http://localhost:3000",+ "cover": true},{"title": "Select the database",