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 some vue components for demo (#2079)
boojack5bf1db5d88f4
diff --git a/frontend/public/demo/schema-migration-history/demo.json b/frontend/public/demo/schema-migration-history/demo.jsonnew file mode 100644index 0000000000..ae17ba4cd8--- /dev/null+++ b/frontend/public/demo/schema-migration-history/demo.json@@ -0,0 +1,19 @@+{+ "process": [+ {+ "url": "/db/employee-103/history/20220708094434-3",+ "title": "schema drift",+ "description": "This is schema drift page"+ },+ {+ "url": "/db/employee-103#migration-history",+ "title": "migration history",+ "description": "This is migration history page"+ },+ {+ "url": "/issue/104?stage=test-employee-1&task=update-employee-schema-105",+ "title": "issue detail",+ "description": "This is another issue detail page"+ }+ ]+}diff --git a/frontend/public/demo/schema-migration-history/guide.json b/frontend/public/demo/schema-migration-history/guide.jsondeleted file mode 100644index a526437b79..0000000000--- a/frontend/public/demo/schema-migration-history/guide.json+++ /dev/null@@ -1,72 +0,0 @@-{- "steps": [- {},- {},- {- "title": {- "en-US": "Click the Alter Schema button",- "zh-CN": "点击修改模式按钮"- },- "description": {- "en-US": "Alter schema is a main feature of Bytebase",- "zh-CN": "修改数据库 Schema 是 Bytebase 的核心功能之一"- },- "selectors": [["[data-label='bb-alter-schema-button']"]],- "url": "http://localhost:3000"- },- {- "title": "Select the database",- "description": "",- "selectors": [- [- "[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",- "description": "",- "selectors": [- [- "[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",- "description": "",- "selectors": [- [- "[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",- "description": "",- "selectors": [["[data-label='bb-assignee-select-container']"]],- "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",- "position": "left"- },- {- "title": "Click Create button",- "description": "",- "selectors": [["[data-label='bb-issue-create-button']"]],- "url": "http://localhost:3000/issue/new",- "position": "left"- }- ]-}diff --git a/frontend/public/demo/schema-migration-history/hint.json b/frontend/public/demo/schema-migration-history/hint.jsonindex 9597ec5aef..cffcca9252 100644--- a/frontend/public/demo/schema-migration-history/hint.json+++ b/frontend/public/demo/schema-migration-history/hint.json@@ -9,70 +9,37 @@}},{- "selector": "[data-label='bb-migration-history-establish-baseline-alert'] [data-label='bb-alert-ok-button']",+ "selector": "[data-label='bb-dashboard-header']",+ "url": ".*","type": "shield",- "url": ".+?/db/.+?#migration-history$",- "dialog": {- "title": "",- "description": {- "en-US": "Since this is a read-only DEMO, you can contact [email protected] to request a full DEMO.",- "zh-CN": "但由于这是个只读 DEMO,您可以联系 [email protected] 来申请完整的 DEMO 进行尝试"- },- "alwaysShow": true- },"additionStyle": {- "backdropFilter": "unset"- }- },- {- "selector": "[data-label='bb-dashboard-header-database-entry']",- "url": "^(?!.+/(db|issue/))",- "cover": true,- "dialog": {- "title": "",- "description": {- "en-US": "Click here. Let's enter the DEMO",- "zh-CN": "点击这里,让我们进入 DEMO"- },- "alwaysShow": true+ "backdropFilter": "unset",+ "background": "transparent"}},{- "selector": "[data-label='bb-database-table']",- "url": ".+?/db",- "cover": true,- "dialog": {- "title": "",- "description": {- "en-US": "Selecting the target database",- "zh-CN": "选择目标数据库"- },- "alwaysShow": true,- "position": "bottom"+ "selector": "[data-label='bb-dashboard-static-sidebar']",+ "url": ".*",+ "type": "shield",+ "additionStyle": {+ "backdropFilter": "unset",+ "background": "transparent"}},{- "selector": "[data-label='bb-main-body-wrapper']",- "url": ".+?/(db|issue)/.+",- "cover": true- },- {- "selector": "[data-label='bb-database-detail-tab'] button:nth-child(2)",- "url": ".+?/db/.+?#overview$",- "type": "tooltip",- "position": "center",+ "selector": "[data-label='bb-migration-history-establish-baseline-alert'] [data-label='bb-alert-ok-button']",+ "type": "shield",+ "url": ".+?/db/.+?#migration-history$","dialog": {"title": "","description": {- "en-US": "All migration records are here.",- "zh-CN": "所有的变更记录都在这里"+ "en-US": "Since this is a read-only DEMO, you can contact [email protected] to request a full DEMO.",+ "zh-CN": "但由于这是个只读 DEMO,您可以联系 [email protected] 来申请完整的 DEMO 进行尝试"},- "alwaysShow": true,- "position": "right"+ "alwaysShow": true},"additionStyle": {- "marginLeft": "7px",- "marginTop": "10px"+ "backdropFilter": "unset"}},{@@ -85,21 +52,18 @@}},{- "selector": "[data-label='bb-migration-history-table'] tr:nth-child(2) > td:nth-child(2)",+ "selector": "[data-label='bb-migration-history-table'] tr:nth-child(2) > td:nth-child(4) > a","url": ".+?/db/.+?#migration-history$","type": "tooltip",- "position": "leftcenter",+ "position": "center","dialog": {"title": "","description": {- "en-US": "In this migration, drift is detected. Click for more.",- "zh-CN": "一次常规的变更,其中检测到了偏差。点击查看详情"+ "en-US": "Let's take a closer look at the issue it generates.",+ "zh-CN": "让我们来详细看看它产生的工单"},"alwaysShow": true,"position": "right"- },- "additionStyle": {- "marginLeft": "-16px"}},{@@ -120,19 +84,5 @@"marginLeft": "2px","marginTop": "10px"}- },- {- "selector": "a.bb-comment-link",- "url": ".+?/issue/.+",- "type": "tooltip",- "dialog": {- "title": "",- "description": {- "en-US": "Let's go back to Migration History.",- "zh-CN": "让我们回到 Migration History"- },- "alwaysShow": true,- "position": "right"- }}]diff --git a/frontend/public/demo/schema-migration-history/recorder.json b/frontend/public/demo/schema-migration-history/recorder.jsondeleted file mode 100644index ba19059333..0000000000--- a/frontend/public/demo/schema-migration-history/recorder.json+++ /dev/null@@ -1,101 +0,0 @@-{- "title": "schema-migration",- "steps": [- {- "type": "setViewport",- "width": 935,- "height": 833,- "deviceScaleFactor": 1,- "isMobile": false,- "hasTouch": false,- "isLandscape": false- },- {- "type": "navigate",- "url": "http://localhost:3000/",- "assertedEvents": [- {- "type": "navigation",- "url": "http://localhost:3000/",- "title": "Bytebase"- }- ]- },- {- "type": "click",- "selectors": [- ["#app > div > div > div > div > div.w-full.mx-auto.md\\:flex > div > div > div > div:nth-child(1) > button > svg > g > path"]- ],- "target": "main",- "offsetX": 6,- "offsetY": 2.0245590209960938- },- {- "type": "click",- "selectors": [- [- "#bb-modal-stack > div.relative.overflow-hidden.bb-modal > div.modal-container > div > div.overflow-x-auto > div > div > div.n-tab-pane > table > tbody > tr:nth-child(1) > td.table-cell.text-sm.leading-5.max-w-prose.pl-4.pr-2.py-2.w-16"- ]- ],- "target": "main",- "offsetX": 176,- "offsetY": 33.5- },- {- "type": "click",- "selectors": [- ["aria/Next"],- [- "#bb-modal-stack > div:nth-child(4) > div.modal-container > div.pt-4.border-t.border-block-border.flex.justify-end.space-x-3 > button.btn-primary.py-2.px-4"- ]- ],- "target": "main",- "offsetX": 15.25,- "offsetY": 10.5- },- {- "type": "change",- "value": "ALTER TABLE Customers DROP COLUMN name;",- "selectors": [- ["aria/Editor content;Press Alt+F1 for Accessibility Options."],- [- "#issue-detail-top > main > div > div > div.w-full.lg\\:w-auto.lg\\:flex-1.py-4.pr-4.overflow-x-hidden > section > div.whitespace-pre-wrap.mt-2.w-full.overflow-hidden.border-t.border-x > div > div > div.overflow-guard > textarea"- ]- ],- "target": "main"- },- {- "type": "click",- "selectors": [- [- "#issue-detail-top > main > div > div > div.py-6.lg\\:pl-4.lg\\:w-72.xl\\:w-96.lg\\:border-l.lg\\:border-block-border.overflow-hidden > aside > div:nth-child(2) > div > div > div > input"- ]- ],- "target": "main",- "offsetX": 114.3359375,- "offsetY": 17- },- {- "type": "click",- "selectors": [- ["aria/DO Demo Owner"],- [- "body > div.v-binder-follower-container > div > div > ul > li.text-main.cursor-default.select-none.relative.py-2.pl-3.pr-9.text-main-text.bg-main-hover"- ]- ],- "target": "main",- "offsetX": 151,- "offsetY": 33- },- {- "type": "click",- "selectors": [- ["aria/Create"],- ["#issue-detail-top > div.bg-white.px-4.pb-4 > div > div.mt-4.flex.space-x-3.md\\:mt-0.md\\:ml-4 > button"]- ],- "target": "main",- "offsetX": 26.140625,- "offsetY": 13- }- ]-}diff --git a/frontend/src/plugins/demo/components/DemoDrawer.vue b/frontend/src/plugins/demo/components/DemoDrawer.vuenew file mode 100644index 0000000000..df3653a85c--- /dev/null+++ b/frontend/src/plugins/demo/components/DemoDrawer.vue@@ -0,0 +1,42 @@+<template>+ <div+ class="demo-drawer-container px-6 py-6 fixed right-0 top-0 w-96 h-screen flex flex-col justify-start items-start shadow-xl bg-white"+ >+ <div+ class="absolute top-4 right-4 w-6 h-6 flex flex-row justify-center items-center rounded cursor-pointer hover:bg-gray-100"+ @click="handleCloseButtonClick"+ >+ <span class="text-2xl -mt-1">×</span>+ </div>+ <p class="text-4xl my-2">🎉</p>+ <p class="text-xl font-medium">Demo Completed</p>+ <div class="text-base leading-6 mt-4">+ <p>If you have a question about site</p>+ <p>If you have a question about site</p>+ <p>If you have a question about site</p>+ </div>+ <div class="w-full text-base leading-6 mt-4">+ <p>And here are the other demos:</p>+ <ul class="list-disc ml-6 leading-7 my-1">+ <li>demo1</li>+ <li>demo2</li>+ <li>demo3</li>+ <li>demo4</li>+ </ul>+ </div>+ </div>+</template>++<script lang="ts" setup>+const emits = defineEmits(["close"]);++const handleCloseButtonClick = () => {+ emits("close");+};+</script>++<style scoped>+.demo-drawer-container {+ z-index: 10001;+}+</style>diff --git a/frontend/src/plugins/demo/components/DemoWrapper.vue b/frontend/src/plugins/demo/components/DemoWrapper.vuenew file mode 100644index 0000000000..7d190965af--- /dev/null+++ b/frontend/src/plugins/demo/components/DemoWrapper.vue@@ -0,0 +1,80 @@+<template>+ <Transition name="drawer">+ <DemoDrawer v-if="state.showDemoDrawer" @close="handleDemoDrawerClose" />+ </Transition>+ <Transition name="process-bar">+ <ProcessBar+ v-if="state.showProcessBar"+ @finish.once="handleProcessFinished"+ />+ </Transition>+</template>++<script lang="ts" setup>+import { onMounted, reactive } from "vue";+import { fetchDemoDataWithName } from "../data";+import useAppStore from "../store";+import DemoDrawer from "./DemoDrawer.vue";+import ProcessBar from "./ProcessBar.vue";++interface LocalState {+ showDemoDrawer: boolean;+ showProcessBar: boolean;+}++const props = defineProps<{+ demoName: string;+}>();++const state = reactive<LocalState>({+ showDemoDrawer: false,+ showProcessBar: false,+});++const store = useAppStore();++onMounted(async () => {+ try {+ const demoData = await fetchDemoDataWithName(props.demoName);+ if (demoData) {+ store.setState({+ demoName: props.demoName,+ processDataList: demoData.process,+ });++ if (demoData.process.length > 0) {+ state.showProcessBar = true;+ }+ }+ } catch (error) {+ // do nth+ }+});++const handleDemoDrawerClose = () => {+ state.showDemoDrawer = false;+};++const handleProcessFinished = () => {+ state.showDemoDrawer = true;+};+</script>++<style scoped>+.drawer-enter-active,+.drawer-leave-active,+.process-bar-leave-active,+.process-bar-leave-active {+ @apply transition-all duration-300;+}++.drawer-enter-from,+.drawer-leave-to {+ @apply translate-x-full;+}++.process-bar-enter-from,+.process-bar-leave-to {+ @apply translate-y-full;+}+</style>diff --git a/frontend/src/plugins/demo/components/ProcessBar.vue b/frontend/src/plugins/demo/components/ProcessBar.vuenew file mode 100644index 0000000000..e5e2d37d4f--- /dev/null+++ b/frontend/src/plugins/demo/components/ProcessBar.vue@@ -0,0 +1,171 @@+<template>+ <div class="process-bar-container">+ <div+ v-if="currentProcessData"+ class="w-full flex flex-col justify-start items-start"+ >+ <p class="text-gray-800 w-full leading-7">+ {{ currentProcessData.description }}+ </p>+ </div>+ <div v-else class="w-full flex flex-col justify-start items-start">+ <p class="text-gray-800 w-full leading-7">+ Looks like you've got out of the demo process 🙁+ </p>+ <span+ class="border px-3 py-1 mt-2 rounded-lg text-indigo-600 bg-indigo-50 cursor-pointer hover:opacity-80"+ @click="handleBackToDemoButtonClick"+ >👉 Get back to Demo</span+ >+ </div>+ <div+ class="my-4 bg-gray-200 w-full flex flex-row justify-start items-center rounded-full overflow-hidden"+ >+ <div+ class="h-2 bg-indigo-600 rounded-full transition-all"+ :style="{+ width: processBarWidth,+ }"+ ></div>+ </div>+ <div+ class="w-full grid text-base text-gray-400"+ :class="`grid-cols-${processDataList.length}`"+ >+ <div+ v-for="(processData, index) in processDataList"+ :key="index"+ class="select-none text-center first:text-left last:text-right"+ :class="`${+ index <= currentProcessIndex+ ? 'text-indigo-600 cursor-pointer hover:opacity-80'+ : ''+ } ${+ index <= currentProcessIndex + 1+ ? 'cursor-pointer hover:opacity-80'+ : ''+ }`"+ @click="handleProcessItemClick(processData)"+ >+ {{ processData.title }}+ </div>+ </div>+ <div+ v-show="+ currentProcessIndex >= 0 && currentProcessIndex < processDataList.length+ "+ class="w-full flex flex-row justify-between items-center mt-2"+ >+ <span+ class="border px-3 py-1 mt-2 rounded-lg text-indigo-600 bg-indigo-50 cursor-pointer hover:opacity-80"+ :class="+ currentProcessIndex === 0 ? '!opacity-40 !cursor-not-allowed' : ''+ "+ @click="handlePrevButtonClick"+ >👈 Prev</span+ >+ <span+ class="border px-3 py-1 mt-2 rounded-lg text-indigo-600 bg-indigo-50 cursor-pointer hover:opacity-80"+ :class="+ currentProcessIndex === processDataList.length - 1+ ? '!opacity-40 !cursor-not-allowed'+ : ''+ "+ @click="handleNextButtonClick"+ >Next 👉</span+ >+ </div>+ </div>+</template>++<script lang="ts" setup>+import { computed, ref, watch } from "vue";+import { useRoute, useRouter } from "vue-router";+import { first, indexOf } from "lodash-es";+import { ProcessData } from "../types";+import useAppStore from "../store";++const emit = defineEmits(["finish"]);++const route = useRoute();+const router = useRouter();++const store = useAppStore();+const processDataList = computed(() => store.processDataList);++const currentProcessIndex = ref<number>(-1);+const currentProcessData = computed(() => {+ return currentProcessIndex.value >= 0+ ? processDataList.value[currentProcessIndex.value]+ : undefined;+});+const processBarWidth = computed(() => {+ return (+ Math.max(+ (currentProcessIndex.value / (processDataList.value.length - 1)) * 100,+ 2+ ) + "%"+ );+});++watch(+ route,+ () => {+ let matchedProcessDataIndex = -1;+ for (let i = 0; i < processDataList.value.length; i++) {+ const processData = processDataList.value[i];+ if (window.location.href.includes(processData.url)) {+ matchedProcessDataIndex = i;+ break;+ }+ }+ currentProcessIndex.value = matchedProcessDataIndex;+ if (+ matchedProcessDataIndex >= 0 &&+ matchedProcessDataIndex === processDataList.value.length - 1+ ) {+ emit("finish");+ }+ },+ {+ immediate: true,+ }+);++const handleProcessItemClick = (processData: ProcessData) => {+ const index = indexOf(processDataList.value, processData);+ if (currentProcessIndex.value + 1 >= index) {+ router.push(processData.url);+ }+};++const handlePrevButtonClick = () => {+ const process = processDataList.value[currentProcessIndex.value - 1];+ if (process) {+ router.push(process.url);+ }+};++const handleNextButtonClick = () => {+ const process = processDataList.value[currentProcessIndex.value + 1];+ if (process) {+ router.push(process.url);+ }+};++const handleBackToDemoButtonClick = () => {+ const process = first(processDataList.value);+ if (process) {+ router.push(process.url);+ }+};+</script>++<style scoped>+.process-bar-container {+ @apply max-w-full fixed bottom-6 left-1/2 -translate-x-1/2 translate-y-0 transition-transform duration-500 flex flex-col justify-start items-center bg-white px-8 py-6 rounded-lg;+ min-width: 600px;+ z-index: 10001;+ box-shadow: 0 0 24px 8px rgb(0 0 0 / 20%);+}+</style>diff --git a/frontend/src/plugins/demo/data.ts b/frontend/src/plugins/demo/data.tsindex bc44fe3c5c..426a68bbef 100644--- a/frontend/src/plugins/demo/data.ts+++ b/frontend/src/plugins/demo/data.ts@@ -1,6 +1,6 @@import { merge } from "lodash-es";+import { DemoData, GuideData, HintData } from "./types";import { validateStepData } from "./guide";-import { GuideData, HintData } from "./types";const hintCache = new Map<string, HintData[]>();@@ -30,3 +30,8 @@ export const fetchHintDataWithName = async (hintName: string) => {return hintData;};++export const fetchDemoDataWithName = async (demoName: string) => {+ const demoData = (await fetchJSONData(`/${demoName}/demo.json`)) as DemoData;+ return demoData;+};diff --git a/frontend/src/plugins/demo/guide.ts b/frontend/src/plugins/demo/guide.tsindex aed9b87479..f063262373 100644--- a/frontend/src/plugins/demo/guide.ts+++ b/frontend/src/plugins/demo/guide.ts@@ -7,7 +7,7 @@ import {waitForTargetElement,} from "./utils";import * as storage from "./storage";-import { DialogPosition, GuideData, StepData } from "./types";+import { Position, GuideData, StepData } from "./types";import { getStringFromI18NText, nextI18NText } from "./i18n";// validateStepData will check if the step data is valid@@ -55,7 +55,7 @@ export const showGuideDialog = async (const renderHighlight = (targetElement: HTMLElement, guideStep: StepData) => {const highlightWrapper = document.createElement("div");- highlightWrapper.className = "bb-guide-highlight-wrapper";+ highlightWrapper.className = "bb-demo-element bb-guide-highlight-wrapper";document.body.appendChild(highlightWrapper);const bounding = getElementBounding(targetElement);highlightWrapper.style.top = `${bounding.top}px`;@@ -67,7 +67,7 @@ const renderHighlight = (targetElement: HTMLElement, guideStep: StepData) => {const maxZIndex = getElementMaxZIndex(targetElement);highlightWrapper.classList.add("covered");const coverElement = document.createElement("div");- coverElement.className = "bb-guide-cover-wrapper";+ coverElement.className = "bb-demo-element bb-guide-cover-wrapper";coverElement.style.zIndex = `${maxZIndex - 1}`;document.body.appendChild(coverElement);targetElement.classList.add("bb-guide-target-element");@@ -82,29 +82,29 @@ const renderGuideDialog = (const guideStep = guideData.steps[stepIndex];const { description, title, type } = guideStep;const guideDialogDiv = document.createElement("div");- guideDialogDiv.className = "bb-guide-dialog";+ guideDialogDiv.className = "bb-demo-element bb-guide-dialog";adjustGuideDialogPosition(targetElement, guideDialogDiv, guideStep.position);const closeButton = document.createElement("button");- closeButton.className = "bb-guide-close-button";+ closeButton.className = "bb-demo-element 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.className = "bb-demo-element bb-guide-title-text";titleElement.innerText = getStringFromI18NText(title);guideDialogDiv.appendChild(titleElement);const descriptionElement = document.createElement("p");- descriptionElement.className = "bb-guide-description-text";+ descriptionElement.className = "bb-demo-element bb-guide-description-text";descriptionElement.innerText = getStringFromI18NText(description);guideDialogDiv.appendChild(descriptionElement);if (!guideStep.hideNextButton) {const buttonsContainer = document.createElement("div");- buttonsContainer.className = "bb-guide-btns-container";+ buttonsContainer.className = "bb-demo-element bb-guide-btns-container";const nextButton = document.createElement("button");- nextButton.className = "button";+ nextButton.className = "bb-demo-element button";if (stepIndex === guideData.steps.length - 1) {nextButton.innerText = "Done";} else {@@ -162,7 +162,7 @@ const renderGuideDialog = (const adjustGuideDialogPosition = (targetElement: HTMLElement,guideDialogDiv: HTMLElement,- position: DialogPosition = "bottom"+ position: Position = "bottom") => {const bounding = getElementBounding(targetElement);const guideDialogBounding = getElementBounding(guideDialogDiv);diff --git a/frontend/src/plugins/demo/hint.ts b/frontend/src/plugins/demo/hint.tsindex 84134e9c00..35c361e705 100644--- a/frontend/src/plugins/demo/hint.ts+++ b/frontend/src/plugins/demo/hint.ts@@ -10,34 +10,26 @@ import {waitForTargetElement,} from "./utils";-const shownHintIndexSet = new Set<number>();const closedHintIndexSet = new Set<number>();export const showHints = async (hintDataList: HintData[]) => {- removeHint();- shownHintIndexSet.clear();-const findTargetPromiseList = hintDataList.map(async (hintData) => {const index = indexOf(hintDataList, hintData);- if (- shownHintIndexSet.has(index) ||- closedHintIndexSet.has(index) ||- !checkUrlMatched(hintData.url)- ) {++ if (closedHintIndexSet.has(index) || !checkUrlMatched(hintData.url)) {+ removeHint(index);return;}const targetElement = await waitForTargetElement([[hintData.selector]]);if (targetElement) {renderHint(targetElement, hintData, index);- shownHintIndexSet.add(index);} else {removeHint(index);- shownHintIndexSet.delete(index);}});- Promise.all(findTargetPromiseList);+ await Promise.all(findTargetPromiseList);};const renderHint = (@@ -51,7 +43,7 @@ const renderHint = (}const hintWrapper = document.createElement("div");- hintWrapper.className = `bb-hint-wrapper bb-hint-${hintIndex}`;+ hintWrapper.className = `bb-demo-element bb-hint-wrapper bb-hint-${hintIndex}`;if (hintData.type === "shield") {hintWrapper.classList.add("shield");}@@ -105,6 +97,47 @@ const renderHint = (updateHintPosition(targetElement, hintData, hintIndex);};+const renderCover = (targetElement: HTMLElement, hintIndex: number) => {+ const coverElement = document.createElement("div");+ coverElement.className = `bb-demo-element bb-hint-cover-wrapper bb-hint-${hintIndex}`;+ const maxZIndex = getElementMaxZIndex(targetElement);+ coverElement.style.zIndex = `${Math.max(maxZIndex - 1, 0)}`;+ removeElementBySelector(`.bb-hint-cover-wrapper.bb-hint-${hintIndex}`);+ document.body.appendChild(coverElement);+ targetElement.classList.add("bb-hint-target-element");+};++const updateHintPosition = (+ targetElement: HTMLElement,+ hintData: HintData,+ hintIndex: number+) => {+ const hintWrapper = document.body.querySelector(+ `.bb-hint-wrapper.bb-hint-${hintIndex}`+ ) as HTMLElement;++ if (!targetElement || !hintWrapper) {+ removeHint(hintIndex);+ return;+ }++ const bounding = getElementBounding(targetElement);++ if (bounding.width === 0 && bounding.height === 0) {+ removeHint(hintIndex);+ return;+ }++ hintWrapper.style.top = `${bounding.top}px`;+ hintWrapper.style.left = `${bounding.left}px`;+ hintWrapper.style.width = `${bounding.width}px`;+ hintWrapper.style.height = `${bounding.height}px`;++ requestAnimationFrame(() =>+ updateHintPosition(targetElement, hintData, hintIndex)+ );+};+const renderHintDialog = (targetElement: HTMLElement,hintData: HintData,@@ -118,7 +151,7 @@ const renderHintDialog = (dialog: { title, description, position, alwaysShow },} = hintData;const hintDialogDiv = document.createElement("div");- hintDialogDiv.className = `bb-hint-dialog bb-hint-${hintIndex} ${+ hintDialogDiv.className = `bb-demo-element bb-hint-dialog bb-hint-${hintIndex} ${position ?? "bottom"}`;@@ -126,12 +159,12 @@ const renderHintDialog = (hintDialogDiv.classList.add("tooltip-dialog");}- const maxZIndex = getComputedStyle(targetElement, "z-index");+ const maxZIndex = getStylePropertyValue(targetElement, "z-index");hintDialogDiv.style.zIndex = `${maxZIndex}`;if (!alwaysShow) {const closeButton = document.createElement("button");- closeButton.className = "bb-hint-close-button";+ closeButton.className = "bb-demo-element bb-hint-close-button";closeButton.innerHTML = "×";closeButton.addEventListener("click", () => {removeHint(hintIndex);@@ -142,13 +175,13 @@ const renderHintDialog = (if (getStringFromI18NText(title)) {const titleElement = document.createElement("p");- titleElement.className = "bb-hint-title-text";+ titleElement.className = "bb-demo-element bb-hint-title-text";titleElement.innerText = getStringFromI18NText(title);hintDialogDiv.appendChild(titleElement);}if (getStringFromI18NText(description)) {const descriptionElement = document.createElement("p");- descriptionElement.className = "bb-hint-description-text";+ descriptionElement.className = "bb-demo-element bb-hint-description-text";descriptionElement.innerText = getStringFromI18NText(description);hintDialogDiv.appendChild(descriptionElement);}@@ -203,44 +236,18 @@ const adjustHintDialogPosition = ();};-const updateHintPosition = (- targetElement: HTMLElement,- hintData: HintData,- hintIndex: number-) => {- const hintWrapper = document.body.querySelector(- `.bb-hint-wrapper.bb-hint-${hintIndex}`- ) as HTMLElement;-- if (!targetElement || !hintWrapper) {- removeHint(hintIndex);- return;- }-- const bounding = getElementBounding(targetElement);-- hintWrapper.style.top = `${bounding.top}px`;- hintWrapper.style.left = `${bounding.left}px`;- hintWrapper.style.width = `${bounding.width}px`;- hintWrapper.style.height = `${bounding.height}px`;-- requestAnimationFrame(() =>- updateHintPosition(targetElement, hintData, hintIndex)- );-};-const renderTooltip = (targetElement: HTMLElement,hintData: HintData,hintIndex: number) => {const tooltipWrapper = document.createElement("div");- tooltipWrapper.className = `bb-hint-tooltip-wrapper bb-hint-${hintIndex}`;+ tooltipWrapper.className = `bb-demo-element bb-hint-tooltip-wrapper bb-hint-${hintIndex}`;const pingElement = document.createElement("span");- pingElement.className = "bb-hint-tooltip-ping";+ pingElement.className = "bb-demo-element bb-hint-tooltip-ping";tooltipWrapper.appendChild(pingElement);const blockElement = document.createElement("span");- blockElement.className = "bb-hint-tooltip-block";+ blockElement.className = "bb-demo-element bb-hint-tooltip-block";tooltipWrapper.appendChild(blockElement);tooltipWrapper.style.zIndex = `${getElementMaxZIndex(targetElement)}`;@@ -251,23 +258,10 @@ const renderTooltip = (}removeElementBySelector(`.bb-hint-tooltip-wrapper.bb-hint-${hintIndex}`);document.body.appendChild(tooltipWrapper);-- tooltipWrapper.addEventListener("mouseenter", () => {- const dialogElement = renderHintDialog(tooltipWrapper, hintData, hintIndex);- tooltipWrapper.addEventListener(- "mouseleave",- () => {- dialogElement?.remove();- },- {- once: true,- }- );- });+ renderHintDialog(tooltipWrapper, hintData, hintIndex);tooltipWrapper.addEventListener("click", () => {targetElement.click();- closedHintIndexSet.add(hintIndex);removeHint(hintIndex);});@@ -317,16 +311,6 @@ const updateTooltipPosition = ();};-const renderCover = (targetElement: HTMLElement, hintIndex: number) => {- const coverElement = document.createElement("div");- coverElement.className = `bb-hint-cover-wrapper bb-hint-${hintIndex}`;- const maxZIndex = getElementMaxZIndex(targetElement);- coverElement.style.zIndex = `${Math.max(maxZIndex - 1, 0)}`;- removeElementBySelector(`.bb-hint-cover-wrapper.bb-hint-${hintIndex}`);- document.body.appendChild(coverElement);- targetElement.classList.add("bb-hint-target-element");-};-export const removeHint = (hintIndex?: number) => {if (isUndefined(hintIndex)) {const hintWrappers = document.querySelectorAll(".bb-hint-wrapper");diff --git a/frontend/src/plugins/demo/index.ts b/frontend/src/plugins/demo/index.tsindex fddead031f..f3d037d1fa 100644--- a/frontend/src/plugins/demo/index.ts+++ b/frontend/src/plugins/demo/index.ts@@ -1,26 +1,14 @@import axios from "axios";import { isNull } from "lodash-es";-import { initGuideListeners, initHintListeners } from "./listener";+import { createApp } from "vue";+import { router } from "@/router";import * as storage from "./storage";+import { piniaInstance } from "./store";+import { initLocationListenerForDemo } from "./listener";+import DemoWrapper from "./components/DemoWrapper.vue";const invalidDemoNameList = ["dev", "prod"];-// TODO(steven): after we using help to replace the guide, we should remove this.-// In live demo mode, we should not show the guide dialog.-const hideConsoleGuides = () => {- const tempData = {- "database.visit": true,- "instance.visit": true,- "project.visit": true,- "environment.visit": true,- "guide.database": true,- "guide.instance": true,- "guide.project": true,- "guide.environment": true,- };- window.localStorage.setItem("ui.intro", JSON.stringify(tempData));-};-// initial guide listeners when window loadedwindow.addEventListener("load",@@ -32,7 +20,7 @@ window.addEventListener(}>(`/api/actuator/info`)).data;- // In online demo, we only show the hints.+ // only show demo in feature demo mode.if (serverInfo.demo &&serverInfo.demoName &&@@ -40,31 +28,16 @@ window.addEventListener() {const demoName = serverInfo.demoName;if (demoName) {- storage.set({- hint: {- name: demoName,- },+ // mount the demo vue app+ const demoDrawerContainer = document.createElement("div");+ document.body.appendChild(demoDrawerContainer);+ const app = createApp(DemoWrapper, {+ demoName,});- hideConsoleGuides();- initHintListeners();- }- } else {- // This is using for dev mainly.- const { guide: storageGuide, hint: storageHint } = storage.get([- "guide",- "hint",- ]);- const params = new URLSearchParams(window.location.search);- const paramGuide = params.get("guide");- const paramHint = params.get("hint");+ app.use(router).use(piniaInstance).mount(demoDrawerContainer);- if (paramGuide || storageGuide) {- hideConsoleGuides();- initGuideListeners();- }- if (paramHint || storageHint) {- hideConsoleGuides();- initHintListeners();+ // TODO(steven): refactor the pure js element into vue+ await initLocationListenerForDemo();}}@@ -72,7 +45,7 @@ window.addEventListener(const params = new URLSearchParams(window.location.search);const clearDemo = params.get("cleardemo");if (!isNull(clearDemo)) {- storage.remove(["guide", "hint"]);+ storage.remove(["demo", "guide"]);}},{diff --git a/frontend/src/plugins/demo/listener.ts b/frontend/src/plugins/demo/listener.tsindex 1e2d3c63dd..bec7feee39 100644--- a/frontend/src/plugins/demo/listener.ts+++ b/frontend/src/plugins/demo/listener.ts@@ -1,46 +1,14 @@import { isEqual } from "lodash-es";-import { fetchGuideDataWithName, fetchHintDataWithName } from "./data";+import {+ fetchDemoDataWithName,+ fetchGuideDataWithName,+ fetchHintDataWithName,+} from "./data";import { removeGuideDialog, showGuideDialog } from "./guide";import { removeHint, showHints } from "./hint";import * as storage from "./storage";-const refreshLocalStorageGuideData = async () => {- const params = new URLSearchParams(window.location.search);- const guideName = params.get("guide");- const { guide } = storage.get(["guide"]);-- if (guideName && guideName !== guide?.name) {- const guideData = await fetchGuideDataWithName(guideName);-- if (guideData) {- storage.set({- guide: {- name: guideName,- stepIndex: 0,- },- });- }- }-};--const refreshLocalStorageHintData = async () => {- const params = new URLSearchParams(window.location.search);- const hintName = params.get("hint");-- if (hintName) {- const hintData = await fetchHintDataWithName(hintName);-- if (hintData) {- storage.set({- hint: {- name: hintName,- },- });- }- }-};--const tryToShowGuideDialog = async () => {+const tryToShowGuides = async () => {const { guide } = storage.get(["guide"]);if (guide) {@@ -52,10 +20,10 @@ const tryToShowGuideDialog = async () => {};const tryToShowHints = async () => {- const { hint } = storage.get(["hint"]);+ const { demo } = storage.get(["demo"]);- if (hint) {- const hintData = await fetchHintDataWithName(hint.name);+ if (demo) {+ const hintData = await fetchHintDataWithName(demo.name);showHints(hintData);} else {removeHint();@@ -67,12 +35,11 @@ const initLocationListenerForGuide = () => {let prevLocationString = "";const observer = new MutationObserver(async () => {- await refreshLocalStorageGuideData();const locationString = window.location.toString();if (!isEqual(prevLocationString, locationString)) {prevLocationString = locationString;- tryToShowGuideDialog();+ tryToShowGuides();}});@@ -84,19 +51,16 @@ const initLocationListenerForGuide = () => {// initMutationListenerForHint using mutation observer to detect DOM changes.const initMutationListenerForHint = () => {- const observer = new MutationObserver(async (mutations: MutationRecord[]) => {- setTimeout(() => {+ const observer = new MutationObserver((mutations: MutationRecord[]) => {+ setTimeout(async () => {for (const mutation of mutations) {const changedNodes = [...mutation.addedNodes, ...mutation.removedNodes];for (const changedNode of changedNodes) {if (changedNode instanceof HTMLElement &&- !changedNode.matches(".bb-hint-wrapper") &&- !changedNode.matches(".bb-hint-cover-wrapper") &&- !changedNode.matches(".bb-hint-dialog") &&- !changedNode.matches(".bb-hint-tooltip-wrapper")+ !changedNode.matches(".bb-demo-element")) {- tryToShowHints();+ await tryToShowHints();return;}}@@ -110,17 +74,75 @@ const initMutationListenerForHint = () => {});};-export const initGuideListeners = () => {+const initGuideListeners = () => {initLocationListenerForGuide();window.addEventListener("storage", async () => {- tryToShowGuideDialog();+ tryToShowGuides();});};-export const initHintListeners = async () => {- await refreshLocalStorageHintData();+const initHintListeners = () => {initMutationListenerForHint();window.addEventListener("storage", async () => {tryToShowHints();});};++const initDemoListeners = async () => {+ const { demo } = storage.get(["demo"]);+ if (demo && demo.name) {+ const demoData = await fetchDemoDataWithName(demo.name);+ if (demoData) {+ try {+ const guideData = await fetchGuideDataWithName(demo.name);+ if (guideData) {+ await tryToShowGuides();+ initGuideListeners();+ }+ } catch (error) {+ // do nth+ }++ try {+ const hintData = await fetchHintDataWithName(demo.name);+ if (hintData) {+ await tryToShowHints();+ initHintListeners();+ }+ } catch (error) {+ // do nth+ }+ }+ }+};++export const initLocationListenerForDemo = async () => {+ const { demo } = storage.get(["demo"]);++ if (demo && demo.name) {+ const demoData = await fetchDemoDataWithName(demo.name);+ if (demoData) {+ let prevLocationString = "";++ const observer = new MutationObserver(async () => {+ const locationString = window.location.toString();++ if (!isEqual(prevLocationString, locationString)) {+ prevLocationString = locationString;+ // Do not show demo element in /auth pages.+ if (window.location.pathname.startsWith("/auth")) {+ return;+ }++ initDemoListeners();+ observer.disconnect();+ }+ });++ observer.observe(document.body, {+ childList: true,+ subtree: true,+ });+ }+ }+};diff --git a/frontend/src/plugins/demo/storage.ts b/frontend/src/plugins/demo/storage.tsindex b684784abd..7b9086de54 100644--- a/frontend/src/plugins/demo/storage.ts+++ b/frontend/src/plugins/demo/storage.ts@@ -2,12 +2,12 @@* Define storage data type for guide*/interface StorageData {- guide: {+ demo: {name: string;- stepIndex: number;};- hint: {+ guide: {name: string;+ stepIndex: number;};bytebase_options: {appearance: {diff --git a/frontend/src/plugins/demo/store/index.ts b/frontend/src/plugins/demo/store/index.tsnew file mode 100644index 0000000000..e5e1906e11--- /dev/null+++ b/frontend/src/plugins/demo/store/index.ts@@ -0,0 +1,26 @@+import { createPinia, defineStore } from "pinia";+import { ProcessData } from "../types";++export const piniaInstance = createPinia();++interface State {+ demoName: string;+ processDataList: ProcessData[];+}++const useAppStore = defineStore("appStore", {+ state: (): State => {+ return {+ demoName: "",+ processDataList: [],+ };+ },+ actions: {+ setState(state: State) {+ this.demoName = state.demoName;+ this.processDataList = state.processDataList;+ },+ },+});++export default useAppStore;diff --git a/frontend/src/plugins/demo/style.css b/frontend/src/plugins/demo/style.cssindex 6c52145f15..dcfda2ad57 100644--- a/frontend/src/plugins/demo/style.css+++ b/frontend/src/plugins/demo/style.css@@ -13,7 +13,7 @@.bb-guide-highlight-wrapper {@apply absolute rounded pointer-events-none;box-shadow: rgb(33 33 33 / 80%) 0px 0px 1px 2px;- z-index: 999999;+ z-index: 9999;}.bb-guide-highlight-wrapper.covered {@@ -24,7 +24,7 @@.bb-guide-dialog,.bb-hint-dialog {@apply fixed bg-white w-auto m-1 my-2 p-3 px-5 text-slate-900 rounded-lg text-left -top-full -left-full;- z-index: 1000000;+ z-index: 10000;max-width: 300px;box-shadow: 0 4px 36px rgb(33 33 33 / 40%);font-size: 15px;@@ -123,11 +123,11 @@.bb-hint-wrapper {@apply fixed rounded cursor-pointer overflow-hidden;- z-index: 999999;+ z-index: 9999;}.bb-hint-wrapper.covered {- box-shadow: 0 3px 30px rgb(33 33 33 / 30%), rgb(0 0 0 / 30%) 0px 0px 0px 100vw !important;+ box-shadow: 0 3px 30px rgb(33 33 33 / 30%), rgb(0 0 0 / 30%) 0px 0px 0px 100vw;}.bb-hint-wrapper.shield {diff --git a/frontend/src/plugins/demo/types.ts b/frontend/src/plugins/demo/types.tsindex d59d05988f..bf0c32c998 100644--- a/frontend/src/plugins/demo/types.ts+++ b/frontend/src/plugins/demo/types.ts@@ -1,3 +1,13 @@+export interface ProcessData {+ url: string;+ title: string | I18NText;+ description: string | I18NText;+}++export interface DemoData {+ process: ProcessData[];+}+type StepType = "click" | "change";export type Position =