Skip to content

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

feat(demo): initial guide data (#1611)

Stevenc84ed9a5a6f8
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 32a2616c49..8deefff1af 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -2,17 +2,11 @@ import axios from "axios";
import isEmpty from "lodash-es/isEmpty";
import { createApp } from "vue";
-import App from "./App.vue";
import i18n from "./plugins/i18n";
import NaiveUI from "./plugins/naive-ui";
import dayjs from "./plugins/dayjs";
import highlight from "./plugins/highlight";
-import "./assets/css/inter.css";
-import "./assets/css/tailwind.css";
-
-import dataSourceType from "./directives/data-source-type";
-// eslint-disable-next-line @typescript-eslint/ban-ts-comment
-// @ts-ignore
+import "./plugins/guide";
import { router } from "./router";
import {
pinia,
@@ -37,6 +31,10 @@ import {
sizeToFit,
urlfy,
} from "./utils";
+import dataSourceType from "./directives/data-source-type";
+import App from "./App.vue";
+import "./assets/css/inter.css";
+import "./assets/css/tailwind.css";
console.debug("dev:", isDev());
console.debug("release:", isRelease());
diff --git a/frontend/src/plugins/guide/data.ts b/frontend/src/plugins/guide/data.ts
new file mode 100644
index 0000000000..637a024221
--- /dev/null
+++ b/frontend/src/plugins/guide/data.ts
@@ -0,0 +1,14 @@
+import { merge } from "lodash-es";
+
+export const fetchGuideDataWithName = async (guideName: string) => {
+ const recorderData = await fetchJSONData(`/recorder/${guideName}.json`);
+ const guideData = await fetchJSONData(`/${guideName}.json`);
+
+ return merge(recorderData, guideData);
+};
+
+const fetchJSONData = async (path: string) => {
+ const res = await fetch("/static/guide" + path);
+ const data = await res.json();
+ return data;
+};
diff --git a/frontend/src/plugins/guide/index.ts b/frontend/src/plugins/guide/index.ts
new file mode 100644
index 0000000000..30c2305c47
--- /dev/null
+++ b/frontend/src/plugins/guide/index.ts
@@ -0,0 +1,14 @@
+import initGuideListeners from "./listener";
+
+// initial guide listeners when window loaded
+window.addEventListener(
+ "load",
+ () => {
+ initGuideListeners();
+ },
+ {
+ once: true,
+ }
+);
+
+export default null;
diff --git a/frontend/src/plugins/guide/listener.ts b/frontend/src/plugins/guide/listener.ts
new file mode 100644
index 0000000000..c8f2789f52
--- /dev/null
+++ b/frontend/src/plugins/guide/listener.ts
@@ -0,0 +1,63 @@
+import { isEqual } from "lodash-es";
+import { fetchGuideDataWithName } from "./data";
+import * as storage from "./storage";
+
+// initLocationListener using mutation observer to detect DOM changes for mocking location changed.
+const initLocationListener = () => {
+ let prevLocationString = "";
+
+ const observer = new MutationObserver(async () => {
+ const locationString = window.location.toString();
+
+ if (!isEqual(prevLocationString, locationString)) {
+ prevLocationString = locationString;
+ let { guide } = storage.get(["guide"]);
+
+ const params = new URLSearchParams(window.location.search);
+ const guideName = params.get("guide");
+
+ if (guideName && guideName !== guide?.name) {
+ const guideData = await fetchGuideDataWithName(guideName);
+
+ if (guideData) {
+ const tempGuide = {
+ name: guideName,
+ startRoute: "",
+ stepIndex: 0,
+ };
+
+ guide = tempGuide;
+ storage.set({
+ guide: tempGuide,
+ });
+ }
+ }
+
+ if (guide) {
+ const guideData = await fetchGuideDataWithName(guide.name);
+ console.log("guideData", guideData);
+ // ...do something with the guide and guideData
+ }
+ }
+ });
+
+ observer.observe(document.querySelector("body") as HTMLBodyElement, {
+ childList: true,
+ subtree: true,
+ });
+};
+
+// initStorageListener detecting storage changes
+const initStorageListener = () => {
+ window.addEventListener("storage", () => {
+ console.log("storage changed");
+ });
+};
+
+const initGuideListeners = () => {
+ console.log("init listeners");
+ initLocationListener();
+ initStorageListener();
+};
+
+export default initGuideListeners;
diff --git a/frontend/src/plugins/guide/storage.ts b/frontend/src/plugins/guide/storage.ts
new file mode 100644
index 0000000000..cefb36f860
--- /dev/null
+++ b/frontend/src/plugins/guide/storage.ts
@@ -0,0 +1,51 @@
+import { GuideState } from "./types";
+
+/**
+ * Define storage data type for guide
+ */
+interface StorageData {
+ guide: GuideState;
+}
+
+type StorageKey = keyof StorageData;
+
+export function get(keys: StorageKey[]): Partial<StorageData> {
+ const data: Partial<StorageData> = {};
+
+ for (const key of keys) {
+ try {
+ const stringifyValue = localStorage.getItem(key);
+
+ if (stringifyValue !== null) {
+ const val = JSON.parse(stringifyValue);
+ data[key] = val;
+ }
+ } catch (error: any) {
+ console.error("Get storage failed in ", key, error);
+ }
+ }
+
+ return data;
+}
+
+export function set(data: Partial<StorageData>) {
+ for (const key in data) {
+ try {
+ const stringifyValue = JSON.stringify(data[key as StorageKey]);
+
+ localStorage.setItem(key, stringifyValue);
+ } catch (error: any) {
+ console.error("Save storage failed in ", key, error);
+ }
+ }
+}
+
+export function remove(keys: StorageKey[]) {
+ for (const key of keys) {
+ try {
+ localStorage.removeItem(key);
+ } catch (error: any) {
+ console.error("Remove storage failed in ", key, error);
+ }
+ }
+}
diff --git a/frontend/src/plugins/guide/types.ts b/frontend/src/plugins/guide/types.ts
new file mode 100644
index 0000000000..5f793674c1
--- /dev/null
+++ b/frontend/src/plugins/guide/types.ts
@@ -0,0 +1,5 @@
+// GuideState data type in storage
+export interface GuideState {
+ name: string;
+ stepIndex: number;
+}
diff --git a/frontend/static/guide/recorder/schema-migration.json b/frontend/static/guide/recorder/schema-migration.json
new file mode 100644
index 0000000000..ba19059333
--- /dev/null
+++ b/frontend/static/guide/recorder/schema-migration.json
@@ -0,0 +1,101 @@
+{
+ "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/static/guide/schema-migration.json b/frontend/static/guide/schema-migration.json
new file mode 100644
index 0000000000..779208d7f2
--- /dev/null
+++ b/frontend/static/guide/schema-migration.json
@@ -0,0 +1,33 @@
+{
+ "steps": [
+ {},
+ {},
+ {
+ "title": "Click the Alter Schema button",
+ "description": "",
+ "url": "http://localhost:3000/"
+ },
+ {
+ "title": "Select one of your database",
+ "description": ""
+ },
+ {
+ "title": "Select Normal migration and click Next"
+ },
+ {
+ "title": "Input the `DROP COLUMN` SQL string in the editor",
+ "description": ""
+ },
+ {
+ "title": "Let's choose a member as the Assignee"
+ },
+ {
+ "title": "That's him, Demo Owner!",
+ "description": ""
+ },
+ {
+ "title": "Click Create button",
+ "description": ""
+ }
+ ]
+}
diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json
index 9e56870198..beaea19eff 100644
--- a/frontend/tsconfig.json
+++ b/frontend/tsconfig.json
@@ -54,6 +54,7 @@
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
+ "resolveJsonModule": true /* Allows importing modules with a ‘.json’ extension. */,
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index ebfe70c9d5..a8e1f84169 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -8,7 +8,6 @@ import Components from "unplugin-vue-components/vite";
const SERVER_PORT = parseInt(process.env.PORT ?? "", 10) ?? 3000;
const HTTPS_PORT = 443;
-const r = (...args: string[]) => resolve(__dirname, ...args);
export default defineConfig(() => {
// NOTE: the following lines is to solve https://github.com/gitpod-io/gitpod/issues/6719
@@ -24,7 +23,7 @@ export default defineConfig(() => {
include: [resolve(__dirname, "src/locales/**")],
}),
Components({
- dirs: [r("src/components"), r("src/bbkit")],
+ dirs: [resolve("src/components"), resolve("src/bbkit")],
// auto import icons
resolvers: [
IconsResolver({