Skip to content

Commit

Permalink
feat: add more tman designer UI logic (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn authored Dec 17, 2024
1 parent ce8be39 commit 027a7c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
29 changes: 5 additions & 24 deletions core/src/ten_manager/designer_frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@ import SettingsPopup from "./components/SettingsPopup/SettingsPopup";
import { useTheme } from "./hooks/useTheme";

import "./theme/index.scss";

interface ApiResponse<T> {
status: string;
data: T;
meta?: any;
}

interface DesignerVersion {
version: string;
}
import { fetchDesignerVersion } from "./api/api";

const App: React.FC = () => {
const [version, setVersion] = useState<string>("");
Expand All @@ -33,22 +24,12 @@ const App: React.FC = () => {

// Get the version of tman.
useEffect(() => {
fetch("/api/designer/v1/version")
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then((payload: ApiResponse<DesignerVersion>) => {
if (payload.status === "ok" && payload.data.version) {
setVersion(payload.data.version);
} else {
throw new Error("Failed to fetch version information.");
}
fetchDesignerVersion()
.then((version) => {
setVersion(version);
})
.catch((err) => {
console.error("Error fetching API:", err);
console.error("Failed to fetch version:", err);
setError("Failed to fetch version.");
});
}, []);
Expand Down
15 changes: 15 additions & 0 deletions core/src/ten_manager/designer_frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ export const isSuccessResponse = <T>(
return response.status === "ok";
};

export const fetchDesignerVersion = async (): Promise<string> => {
const response = await fetch("/api/designer/v1/version");
if (!response.ok) {
throw new Error(`Failed to fetch version: ${response.status}`);
}

const data: ApiResponse<{ version: string }> = await response.json();

if (isSuccessResponse(data) && data.data.version) {
return data.data.version;
} else {
throw new Error("Failed to fetch version information.");
}
};

export const fetchNodes = async (): Promise<BackendNode[]> => {
const response = await fetch(`/api/designer/v1/graphs/default/nodes`);
if (!response.ok) {
Expand Down

0 comments on commit 027a7c1

Please sign in to comment.