Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more tman designer UI logic #413

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading