Skip to content

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

chore: set should show demo from server (#1846)

boojack5cfb9e47147a
diff --git a/api/actuator.go b/api/actuator.go
index 6edec76732..a45e64ced7 100644
--- a/api/actuator.go
+++ b/api/actuator.go
@@ -7,6 +7,7 @@ type ServerInfo struct {
GitCommit string `json:"gitCommit"`
Readonly bool `json:"readonly"`
Demo bool `json:"demo"`
+ DemoName string `json:"demoName"`
Host string `json:"host"`
Port string `json:"port"`
NeedAdminSetup bool `json:"needAdminSetup"`
diff --git a/frontend/src/plugins/demo/index.ts b/frontend/src/plugins/demo/index.ts
index c4f0dc8022..fddead031f 100644
--- a/frontend/src/plugins/demo/index.ts
+++ b/frontend/src/plugins/demo/index.ts
@@ -1,7 +1,10 @@
+import axios from "axios";
import { isNull } from "lodash-es";
import { initGuideListeners, initHintListeners } from "./listener";
import * as storage from "./storage";
+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 = () => {
@@ -21,30 +24,55 @@ const hideConsoleGuides = () => {
// initial guide listeners when window loaded
window.addEventListener(
"load",
- () => {
- const { guide: storageGuide, hint: storageHint } = storage.get([
- "guide",
- "hint",
- ]);
- const params = new URLSearchParams(window.location.search);
+ async () => {
+ const serverInfo = (
+ await axios.get<{
+ demo: boolean;
+ demoName: string;
+ }>(`/api/actuator/info`)
+ ).data;
+
+ // In online demo, we only show the hints.
+ if (
+ serverInfo.demo &&
+ serverInfo.demoName &&
+ !invalidDemoNameList.includes(serverInfo.demoName)
+ ) {
+ const demoName = serverInfo.demoName;
+ if (demoName) {
+ storage.set({
+ hint: {
+ name: 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");
+
+ if (paramGuide || storageGuide) {
+ hideConsoleGuides();
+ initGuideListeners();
+ }
+ if (paramHint || storageHint) {
+ hideConsoleGuides();
+ initHintListeners();
+ }
+ }
- // If there is a cleardemo flag in the url, then clear the demo storage and return
+ // If there is a `cleardemo` flag in the url, then clear the demo storage.
+ const params = new URLSearchParams(window.location.search);
const clearDemo = params.get("cleardemo");
if (!isNull(clearDemo)) {
storage.remove(["guide", "hint"]);
- return;
- }
-
- const paramGuide = params.get("guide");
- const paramHint = params.get("hint");
-
- if (paramGuide || storageGuide) {
- initGuideListeners();
- hideConsoleGuides();
- }
- if (paramHint || storageHint) {
- initHintListeners();
- hideConsoleGuides();
}
},
{
diff --git a/server/actuator.go b/server/actuator.go
index f7be3baeea..03a3cb9eab 100644
--- a/server/actuator.go
+++ b/server/actuator.go
@@ -11,11 +11,13 @@ import (
func (s *Server) registerActuatorRoutes(g *echo.Group) {
g.GET("/actuator/info", func(c echo.Context) error {
ctx := c.Request().Context()
+ demoName := s.profile.DemoDataDir[len("demo/"):len(s.profile.DemoDataDir)]
serverInfo := api.ServerInfo{
Version: s.profile.Version,
GitCommit: s.profile.GitCommit,
Readonly: s.profile.Readonly,
Demo: s.profile.Demo,
+ DemoName: demoName,
Host: s.profile.BackendHost,
Port: strconv.Itoa(s.profile.BackendPort),
}