Skip to content

Commit

Permalink
Add agent version to agent UI (#50)
Browse files Browse the repository at this point in the history
Signed-off-by: Montse Ortega <mortegag@redhat.com>
  • Loading branch information
ammont82 authored Dec 3, 2024
1 parent 41bfc75 commit 61f7a74
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
39 changes: 39 additions & 0 deletions apps/agent/src/common/AgentUIVersion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React, { useState, useEffect } from 'react';
import type { AgentApiInterface } from "@migration-planner-ui/agent-client/apis";
import { useInjection } from '@migration-planner-ui/ioc';
import { Symbols } from '#/main/Symbols';
import { StatusReply } from '@migration-planner-ui/agent-client/models';

export const AgentUIVersion: React.FC = () => {
const agentApi = useInjection<AgentApiInterface>(Symbols.AgentApi);
const [versionInfo, setVersionInfo] = useState<StatusReply | null>(null);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
const fetchVersion = async ():Promise<void> => {
try {
const statusReply = await agentApi.getAgentVersion();
setVersionInfo(statusReply);
} catch (err) {
console.error('Error fetching agent version:', err);
setError('Error fetching version');
}
};

fetchVersion();
}, [agentApi]);

if (error) {
return <div data-testid="agent-api-lib-version" hidden>Error: {error}</div>;
}

if (!versionInfo) {
return <div data-testid="agent-api-lib-version" hidden>Loading...</div>;
}

return (
<div data-testid="agent-api-lib-version" hidden>
{versionInfo.statusInfo}
</div>
);
};
2 changes: 2 additions & 0 deletions apps/agent/src/main/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "@migration-planner-ui/ioc";
import { router } from "./Router";
import { Symbols } from "./Symbols";
import { AgentUIVersion } from "#/common/AgentUIVersion";

function getConfigurationBasePath(): string {
if (import.meta.env.PROD) {
Expand Down Expand Up @@ -40,6 +41,7 @@ function main(): void {
<React.StrictMode>
<DependencyInjectionProvider container={container}>
<React.Suspense fallback={<Spinner />}>
<AgentUIVersion />
<RouterProvider router={router} />
</React.Suspense>
</DependencyInjectionProvider>
Expand Down
11 changes: 11 additions & 0 deletions packages/agent-client/src/apis/AgentApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface AgentApiInterface {
options?: RequestInit & { pathParams?: string[] }
): Promise<Either<number, CredentialsError>>;
getStatus(options?: RequestInit): Promise<StatusReply>;
getAgentVersion():Promise<StatusReply>;
}

export class AgentApi implements AgentApiInterface {
Expand Down Expand Up @@ -59,4 +60,14 @@ export class AgentApi implements AgentApiInterface {
return [null, error];
}
}

async getAgentVersion(): Promise<StatusReply> {
const request = new Request(this.configuration.basePath + "/version", {
method: "GET"
});

const response = await fetch(request);
const statusReply = (await response.json()) as StatusReply;
return statusReply;
}
}

0 comments on commit 61f7a74

Please sign in to comment.