Skip to content

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

chore: update some details for guide (#1681)

boojack6417cfe0f286
diff --git a/frontend/src/plugins/demo/guide.ts b/frontend/src/plugins/demo/guide.ts
index 29dc9fab89..1468a5187c 100644
--- a/frontend/src/plugins/demo/guide.ts
+++ b/frontend/src/plugins/demo/guide.ts
@@ -1,32 +1,39 @@
import { merge } from "lodash-es";
-import { getElementBounding, waitForTargetElement } from "./utils";
+import {
+ checkUrlPathnameMatched,
+ getElementBounding,
+ getElementMaxZIndex,
+ waitForTargetElement,
+} from "./utils";
import * as storage from "./storage";
-import { GuidePosition, StepData } from "./types";
+import { GuideData, GuidePosition, StepData } from "./types";
-export const showGuideDialog = async (guideStep: StepData) => {
+export const showGuideDialog = async (
+ guideData: GuideData,
+ stepIndex: number
+) => {
removeGuideDialog();
+ const guideStep = guideData.steps[stepIndex];
+ if (!guideStep) {
+ return;
+ }
+
+ if (guideStep.url && !checkUrlPathnameMatched(guideStep.url)) {
+ return;
+ }
+
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();
- if (guideStep.cover) {
- renderCover();
- targetElement.classList.add("bb-guide-target-element");
- }
- renderHighlight(targetElement);
- renderGuideDialog(targetElement, guideStep);
+ renderHighlight(targetElement, guideStep);
+ renderGuideDialog(targetElement, guideData, stepIndex);
requestAnimationFrame(() => updateGuidePosition(targetElement, guideStep));
}
};
-const renderCover = () => {
- const coverElement = document.createElement("div");
- coverElement.className = "bb-guide-cover-wrapper";
- document.body.appendChild(coverElement);
-};
-
-const renderHighlight = (targetElement: HTMLElement) => {
+const renderHighlight = (targetElement: HTMLElement, guideStep: StepData) => {
const highlightWrapper = document.createElement("div");
highlightWrapper.className = "bb-guide-highlight-wrapper";
document.body.appendChild(highlightWrapper);
@@ -35,9 +42,24 @@ const renderHighlight = (targetElement: HTMLElement) => {
highlightWrapper.style.left = `${bounding.left}px`;
highlightWrapper.style.width = `${bounding.width}px`;
highlightWrapper.style.height = `${bounding.height}px`;
+
+ if (guideStep.cover) {
+ const maxZIndex = getElementMaxZIndex(targetElement);
+ highlightWrapper.classList.add("covered");
+ const coverElement = document.createElement("div");
+ coverElement.className = "bb-guide-cover-wrapper";
+ coverElement.style.zIndex = `${maxZIndex - 1}`;
+ document.body.appendChild(coverElement);
+ targetElement.classList.add("bb-guide-target-element");
+ }
};
-const renderGuideDialog = (targetElement: HTMLElement, guideStep: StepData) => {
+const renderGuideDialog = (
+ targetElement: HTMLElement,
+ guideData: GuideData,
+ stepIndex: number
+) => {
+ const guideStep = guideData.steps[stepIndex];
const { description, title, type } = guideStep;
const guideDialogDiv = document.createElement("div");
guideDialogDiv.className = "bb-guide-dialog";
@@ -58,47 +80,60 @@ const renderGuideDialog = (targetElement: HTMLElement, guideStep: StepData) => {
descriptionElement.innerText = description;
guideDialogDiv.appendChild(descriptionElement);
- const buttonsContainer = document.createElement("div");
- buttonsContainer.className = "bb-guide-btns-container";
-
- const nextButton = document.createElement("button");
- nextButton.className = "button";
- nextButton.innerText = "Next";
- buttonsContainer.appendChild(nextButton);
- guideDialogDiv.appendChild(buttonsContainer);
+ if (!guideStep.hideNextButton) {
+ const buttonsContainer = document.createElement("div");
+ buttonsContainer.className = "bb-guide-btns-container";
+ const nextButton = document.createElement("button");
+ nextButton.className = "button";
+ if (stepIndex === guideData.steps.length - 1) {
+ nextButton.innerText = "Done";
+ } else {
+ nextButton.innerText = "Next";
+ }
+ buttonsContainer.appendChild(nextButton);
+ guideDialogDiv.appendChild(buttonsContainer);
+
+ if (type === "click") {
+ nextButton.onclick = () => {
+ targetElement.click();
+ };
+ } else if (type === "change") {
+ nextButton.onclick = () => {
+ const value =
+ targetElement.textContent ||
+ targetElement.nodeValue ||
+ (targetElement as HTMLInputElement).value ||
+ "";
+
+ if (guideStep.value && RegExp(guideStep.value).test(value)) {
+ const { guide } = storage.get(["guide"]);
+ storage.set({
+ guide: merge(guide, {
+ stepIndex: stepIndex + 1,
+ }),
+ });
+ storage.emitStorageChangedEvent();
+ } else {
+ // show invalid value message by alert
+ alert(`invalid content value, should be like \`${guideStep.value}\``);
+ }
+ };
+ }
+ }
if (type === "click") {
targetElement.addEventListener("click", () => {
const { guide } = storage.get(["guide"]);
storage.set({
guide: merge(guide, {
- stepIndex: (guide?.stepIndex ?? 0) + 1,
+ stepIndex: stepIndex + 1,
}),
});
+ if (stepIndex + 1 >= guideData.steps.length) {
+ storage.remove(["guide"]);
+ }
storage.emitStorageChangedEvent();
});
- nextButton.onclick = () => {
- targetElement.click();
- };
- } else if (type === "change") {
- nextButton.onclick = () => {
- const value =
- targetElement.textContent ||
- targetElement.nodeValue ||
- (targetElement as HTMLInputElement).value ||
- "";
- if (guideStep.value && RegExp(guideStep.value).test(value)) {
- const { guide } = storage.get(["guide"]);
- storage.set({
- guide: merge(guide, {
- stepIndex: (guide?.stepIndex ?? 0) + 1,
- }),
- });
- storage.emitStorageChangedEvent();
- } else {
- // ...show invalid value message
- }
- };
}
document.body.appendChild(guideDialogDiv);
@@ -111,6 +146,7 @@ const adjustGuideDialogPosition = (
) => {
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`;
diff --git a/frontend/src/plugins/demo/listener.ts b/frontend/src/plugins/demo/listener.ts
index 2bc2a2340e..56c07ed24f 100644
--- a/frontend/src/plugins/demo/listener.ts
+++ b/frontend/src/plugins/demo/listener.ts
@@ -27,10 +27,7 @@ const tryToShowGuideDialog = async () => {
if (guide) {
const guideData = await fetchGuideDataWithName(guide.name);
- const stepData = guideData.steps[guide.stepIndex];
- if (stepData) {
- showGuideDialog(stepData);
- }
+ showGuideDialog(guideData, guide.stepIndex);
} else {
removeGuideDialog();
}
diff --git a/frontend/src/plugins/demo/style.css b/frontend/src/plugins/demo/style.css
index c5dc921a6b..f0d721a0b0 100644
--- a/frontend/src/plugins/demo/style.css
+++ b/frontend/src/plugins/demo/style.css
@@ -1,6 +1,5 @@
.bb-guide-cover-wrapper {
@apply fixed inset-0;
- background-color: rgb(33 33 33 / 30%);
z-index: 999998;
}
@@ -14,19 +13,24 @@
z-index: 999999;
}
+.bb-guide-highlight-wrapper.covered {
+ box-shadow: rgb(33 33 33 / 80%) 0px 0px 1px 2px,
+ rgb(33 33 33 / 50%) 0px 0px 0px 5000px;
+}
+
.bb-guide-dialog {
- @apply absolute bg-white w-72 m-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 -top-full -left-full;
box-shadow: 0 3px 30px rgb(33 33 33 / 30%);
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;
+ @apply absolute top-0 right-1 px-1 rounded cursor-pointer opacity-60 hover:opacity-50;
+ font-size: 24px;
}
.bb-guide-title-text {
- @apply text-lg text-black leading-6 py-1 mb-1;
+ @apply text-lg text-black leading-6 py-1 my-1 pr-3;
}
.bb-guide-description-text {
diff --git a/frontend/src/plugins/demo/types.ts b/frontend/src/plugins/demo/types.ts
index a67b5ff7fc..2afd7604b0 100644
--- a/frontend/src/plugins/demo/types.ts
+++ b/frontend/src/plugins/demo/types.ts
@@ -11,10 +11,12 @@ export interface StepData {
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 is the position of the guide dialog (default is bottom)
position?: GuidePosition;
- // cover is the flag that should be shown for the guide dialog
+ // cover is the flag that cover should be shown
cover?: boolean;
+ // hideNextButton is the flag that next button should be hidden
+ hideNextButton?: boolean;
}
export interface GuideData {
diff --git a/frontend/src/plugins/demo/utils.ts b/frontend/src/plugins/demo/utils.ts
index eec5749ae1..28fbbd7f45 100644
--- a/frontend/src/plugins/demo/utils.ts
+++ b/frontend/src/plugins/demo/utils.ts
@@ -1,5 +1,6 @@
-import { assign } from "lodash-es";
+import { assign, isNumber, isNaN } from "lodash-es";
+// getStylePropertyValue returns the value of the given style property of the given element.
export const getStylePropertyValue = (
element: HTMLElement,
propertyName: string
@@ -11,6 +12,7 @@ export const getStylePropertyValue = (
return propertyValue;
};
+// isElementFixed returns true if the element is fixed.
export const isElementFixed = (element: HTMLElement): boolean => {
const parentNode = element.parentNode;
@@ -25,6 +27,7 @@ export const isElementFixed = (element: HTMLElement): boolean => {
return isElementFixed(parentNode as HTMLElement);
};
+// getElementBounding returns the bounding rectangle and position of the element.
export const getElementBounding = (
element: HTMLElement,
relativeEl?: HTMLElement
@@ -72,6 +75,20 @@ export const getElementBounding = (
});
};
+// getElementMaxZIndex returns the max z-index of the element and its parents.
+export const getElementMaxZIndex = (element: HTMLElement): number => {
+ const zIndex = Number(getStylePropertyValue(element, "z-index"));
+
+ if (element.parentElement && element.parentElement !== document.body) {
+ if (isNumber(zIndex) && !isNaN(zIndex)) {
+ return Math.max(zIndex, getElementMaxZIndex(element.parentElement));
+ }
+ return getElementMaxZIndex(element.parentElement);
+ }
+
+ return 0;
+};
+
const getTargetElementBySelectors = (selectors: string[][]) => {
let targetElement = document.body;
for (const selector of selectors) {
@@ -90,6 +107,7 @@ const getTargetElementBySelectors = (selectors: string[][]) => {
return targetElement;
};
+// waitForTargetElement will wait for the target element to be available in the DOM.
export const waitForTargetElement = (
selectors: string[][]
): Promise<HTMLElement> => {
@@ -113,3 +131,9 @@ export const waitForTargetElement = (
});
});
};
+
+// checkUrlMatched is used to check if the given url's pathname is matched with the location pathname.
+export const checkUrlPathnameMatched = (url: string) => {
+ const urlObject = new URL(url);
+ return urlObject.pathname === window.location.pathname;
+};
diff --git a/frontend/static/demo/schema-migration/guide.json b/frontend/static/demo/schema-migration/guide.json
index abc3010b37..9dd70102ed 100644
--- a/frontend/static/demo/schema-migration/guide.json
+++ b/frontend/static/demo/schema-migration/guide.json
@@ -6,8 +6,7 @@
"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",
- "cover": true
+ "url": "http://localhost:3000"
},
{
"title": "Select the database",
@@ -16,7 +15,9 @@
[
"[data-label='bb-alter-schema-modal'] [data-label='bb-database-table'] tbody tr"
]
- ]
+ ],
+ "url": "http://localhost:3000",
+ "cover": true
},
{
"title": "Choose Normal migration and click Next",
@@ -25,7 +26,8 @@
[
"[data-label='bb-migration-mode-dialog'] [data-label='bb-modal-confirm-button']"
]
- ]
+ ],
+ "url": "http://localhost:3000"
},
{
"title": "Input the `DROP COLUMN` SQL string in the editor",
@@ -42,13 +44,16 @@
"title": "Let's choose a member as the Assignee",
"description": "",
"selectors": [["[data-label='bb-assignee-select-container']"]],
- "url": "http://localhost:3000/issue/new"
+ "url": "http://localhost:3000/issue/new",
+ "hideNextButton": true,
+ "position": "left"
},
{
"title": "That's him, Demo Owner!",
"description": "",
"selectors": [["[data-label='bb-assignee-select-item'] ul li"]],
- "url": "http://localhost:3000/issue/new"
+ "url": "http://localhost:3000/issue/new",
+ "position": "left"
},
{
"title": "Click Create button",