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: update guide position config (#1667)
boojackd6f8c2369f17
diff --git a/frontend/src/components/MonacoEditor/MonacoEditor.vue b/frontend/src/components/MonacoEditor/MonacoEditor.vueindex a61b390157..b52c56977b 100644--- a/frontend/src/components/MonacoEditor/MonacoEditor.vue+++ b/frontend/src/components/MonacoEditor/MonacoEditor.vue@@ -1,5 +1,5 @@<template>- <div ref="editorContainerRef"></div>+ <div ref="editorContainerRef" v-bind="$attrs"></div><BBSpinv-if="!isEditorLoaded"class="h-full w-full flex items-center justify-center"diff --git a/frontend/src/plugins/guide/data.ts b/frontend/src/plugins/guide/data.tsindex 6fe71994cc..ece6f12c7c 100644--- a/frontend/src/plugins/guide/data.ts+++ b/frontend/src/plugins/guide/data.ts@@ -1,4 +1,5 @@import { merge } from "lodash-es";+import { GuideData } from "./types";const fetchJSONData = async (path: string) => {const res = await fetch("/static/guide" + path);@@ -8,7 +9,10 @@ const fetchJSONData = async (path: string) => {export const fetchGuideDataWithName = async (guideName: string) => {const recorderData = await fetchJSONData(`/recorder/${guideName}.json`);- const guideData = await fetchJSONData(`/${guideName}.json`);-- return merge(recorderData, guideData);+ const guideTempData = await fetchJSONData(`/${guideName}.json`);+ const guideData = merge(recorderData, guideTempData) as GuideData;+ guideData.steps = guideData.steps.filter(+ (s) => s.type === "click" || s.type === "change"+ );+ return guideData;};diff --git a/frontend/src/plugins/guide/dialog.ts b/frontend/src/plugins/guide/dialog.tsindex dc9620ea48..f95ab30f27 100644--- a/frontend/src/plugins/guide/dialog.ts+++ b/frontend/src/plugins/guide/dialog.ts@@ -1,6 +1,7 @@+import { merge } from "lodash-es";import { getElementBounding } from "./utils";import * as storage from "./storage";-import { merge } from "lodash-es";+import { GuidePosition, StepData } from "./types";const getTargetElementBySelectors = (selectors: string[][]) => {let targetElement = document.body;@@ -20,12 +21,16 @@ const getTargetElementBySelectors = (selectors: string[][]) => {return targetElement;};-export const showGuideDialog = async (guideStep: any) => {+export const showGuideDialog = async (guideStep: StepData) => {removeGuideDialog();const targetElement = await waitForTargetElement(guideStep.selectors);if (targetElement) {+ // After got the targetElement, remove the guide dialog again+ // to ensure that only one guide dialog is shown at a time.+ removeGuideDialog();renderHighlightWrapper(targetElement);renderGuideDialog(targetElement, guideStep);+ requestAnimationFrame(() => updateGuidePosition(targetElement, guideStep));}};@@ -40,13 +45,12 @@ const renderHighlightWrapper = (targetElement: HTMLElement) => {highlightWrapper.style.height = `${bounding.height}px`;};-const renderGuideDialog = (targetElement: HTMLElement, guideStep: any) => {+const renderGuideDialog = (targetElement: HTMLElement, guideStep: StepData) => {const { description, title, type } = guideStep;const guideDialogDiv = document.createElement("div");guideDialogDiv.className = "bb-guide-dialog";- const bounding = getElementBounding(targetElement);- guideDialogDiv.style.top = `${bounding.top + bounding.height}px`;- guideDialogDiv.style.left = `${bounding.left}px`;+ adjustGuideDialogPosition(targetElement, guideDialogDiv, guideStep.position);+const titleElement = document.createElement("p");titleElement.className = "bb-guide-title-text";titleElement.innerText = title;@@ -75,7 +79,6 @@ const renderGuideDialog = (targetElement: HTMLElement, guideStep: any) => {});storage.emitStorageChangedEvent();});-nextButton.onclick = () => {targetElement.click();};@@ -86,7 +89,7 @@ const renderGuideDialog = (targetElement: HTMLElement, guideStep: any) => {targetElement.nodeValue ||(targetElement as HTMLInputElement).value ||"";- if (RegExp(guideStep.value).test(value)) {+ if (guideStep.value && RegExp(guideStep.value).test(value)) {const { guide } = storage.get(["guide"]);storage.set({guide: merge(guide, {@@ -103,6 +106,59 @@ const renderGuideDialog = (targetElement: HTMLElement, guideStep: any) => {document.body.appendChild(guideDialogDiv);};+const adjustGuideDialogPosition = (+ targetElement: HTMLElement,+ guideDialogDiv: HTMLElement,+ position: GuidePosition = "bottom"+) => {+ const bounding = getElementBounding(targetElement);+ const guideDialogBounding = getElementBounding(guideDialogDiv);+ if (position === "bottom") {+ guideDialogDiv.style.top = `${bounding.top + bounding.height}px`;+ guideDialogDiv.style.left = `${bounding.left - 4}px`;+ } else if (position === "top") {+ guideDialogDiv.style.top = `${+ bounding.top - guideDialogBounding.height - 8+ }px`;+ guideDialogDiv.style.left = `${bounding.left - 4}px`;+ } else if (position === "left") {+ guideDialogDiv.style.top = `${bounding.top - 4}px`;+ guideDialogDiv.style.left = `${+ bounding.left - guideDialogBounding.width - 8+ }px`;+ } else if (position === "right") {+ guideDialogDiv.style.top = `${bounding.top - 4}px`;+ guideDialogDiv.style.left = `${bounding.left + bounding.width}px`;+ }+};++const updateGuidePosition = (+ targetElement: HTMLElement,+ guideStep: StepData+) => {+ const highlightWrapper = document.body.querySelector(+ ".bb-guide-highlight-wrapper"+ ) as HTMLElement;+ const guideDialogDiv = document.body.querySelector(+ ".bb-guide-dialog"+ ) as HTMLElement;++ if (!targetElement || !highlightWrapper || !guideDialogDiv) {+ return;+ }++ const bounding = getElementBounding(targetElement);++ highlightWrapper.style.top = `${bounding.top}px`;+ highlightWrapper.style.left = `${bounding.left}px`;+ highlightWrapper.style.width = `${bounding.width}px`;+ highlightWrapper.style.height = `${bounding.height}px`;++ adjustGuideDialogPosition(targetElement, guideDialogDiv, guideStep.position);++ requestAnimationFrame(() => updateGuidePosition(targetElement, guideStep));+};+const waitForTargetElement = (selectors: string[][]): Promise<HTMLElement> => {return new Promise((resolve) => {let targetElement = getTargetElementBySelectors(selectors);diff --git a/frontend/src/plugins/guide/listener.ts b/frontend/src/plugins/guide/listener.tsindex 7e62e4cdfe..72512afdbf 100644--- a/frontend/src/plugins/guide/listener.ts+++ b/frontend/src/plugins/guide/listener.ts@@ -27,13 +27,10 @@ const tryToShowGuideDialog = async () => {if (guide) {const guideData = await fetchGuideDataWithName(guide.name);-- // remove useless type guideData- guideData.steps = guideData.steps.filter(- (s: any) => s.type !== "setViewport" && s.type !== "navigate"- );-- showGuideDialog(guideData.steps[guide.stepIndex]);+ const stepData = guideData.steps[guide.stepIndex];+ if (stepData) {+ showGuideDialog(stepData);+ }} else {removeGuideDialog();}@@ -62,13 +59,11 @@ const initLocationListener = () => {// initStorageListener detecting storage changesconst initStorageListener = () => {window.addEventListener("storage", async () => {- console.log("storage changed");tryToShowGuideDialog();});};const initGuideListeners = () => {- console.log("init listeners");initLocationListener();initStorageListener();};diff --git a/frontend/src/plugins/guide/storage.ts b/frontend/src/plugins/guide/storage.tsindex e80101c922..14cb2b5331 100644--- a/frontend/src/plugins/guide/storage.ts+++ b/frontend/src/plugins/guide/storage.ts@@ -1,10 +1,11 @@-import { GuideState } from "./types";-/*** Define storage data type for guide*/interface StorageData {- guide: GuideState;+ guide: {+ name: string;+ stepIndex: number;+ };}type StorageKey = keyof StorageData;diff --git a/frontend/src/plugins/guide/style.css b/frontend/src/plugins/guide/style.cssindex 2edda9b772..a620bf75bc 100644--- a/frontend/src/plugins/guide/style.css+++ b/frontend/src/plugins/guide/style.css@@ -5,7 +5,7 @@}.bb-guide-dialog {- @apply absolute bg-white w-72 mt-1 text-black p-2 px-3 rounded-lg text-left;+ @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;}diff --git a/frontend/src/plugins/guide/types.ts b/frontend/src/plugins/guide/types.tsindex 5f793674c1..7d1f428258 100644--- a/frontend/src/plugins/guide/types.ts+++ b/frontend/src/plugins/guide/types.ts@@ -1,5 +1,23 @@-// GuideState data type in storage-export interface GuideState {+type StepType = "click" | "change";++export type GuidePosition = "bottom" | "top" | "left" | "right";++export interface StepData {+ type: StepType;+ title: string;+ description: string;+ selectors: string[][];+ // url is using for validate url in change step+ url?: string;+ // value is the regex-like string using for check the target content value+ value?: string;+ // position is the position of the guide dialog, default is bottom+ position?: GuidePosition;+}++export interface GuideData {name: string;- stepIndex: number;+ steps: StepData[];+ // cover is the flag that should be shown for the guide dialog+ cover?: boolean;}diff --git a/frontend/static/guide/schema-migration.json b/frontend/static/guide/schema-migration.jsonindex aaa7f1433a..8e14dfcae8 100644--- a/frontend/static/guide/schema-migration.json+++ b/frontend/static/guide/schema-migration.json@@ -5,8 +5,8 @@{"title": "Click the Alter Schema button","description": "Alter schema is a main feature of Bytebase",- "url": "http://localhost:3000",- "selectors": [["[data-label='bb-alter-schema-button']"]]+ "selectors": [["[data-label='bb-alter-schema-button']"]],+ "url": "http://localhost:3000"},{"title": "Select the database",@@ -29,34 +29,32 @@{"title": "Input the `DROP COLUMN` SQL string in the editor","description": "",- "url": "http://localhost:3000/issue/new",- "value": ".+","selectors": [[- "[data-label='bb-issue-sql-editor'] >.monaco-editor .editor-scrollable"+ "[data-label='bb-issue-sql-editor'] > .monaco-editor .editor-scrollable"]- ]+ ],+ "url": "http://localhost:3000/issue/new",+ "value": ".+"},{"title": "Let's choose a member as the Assignee",- "url": "http://localhost:3000/issue/new",- "selectors": [["[data-label='bb-assignee-select-container']"]]+ "description": "",+ "selectors": [["[data-label='bb-assignee-select-container']"]],+ "url": "http://localhost:3000/issue/new"},{"title": "That's him, Demo Owner!","description": "",- "url": "http://localhost:3000/issue/new",- "selectors": [- [- "[data-label='bb-assignee-select-container'] [data-label='bb-assignee-select-item'] ul li"- ]- ]+ "selectors": [["[data-label='bb-assignee-select-item'] ul li"]],+ "url": "http://localhost:3000/issue/new"},{"title": "Click Create button","description": "",+ "selectors": [["[data-label='bb-issue-create-button']"]],"url": "http://localhost:3000/issue/new",- "selectors": [["[data-label='bb-issue-create-button']"]]+ "position": "left"}]}