Skip to content

Commit

Permalink
fix: version endpoint (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-mcgovern authored Jan 20, 2025
1 parent faa17e8 commit eada275
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LoaderCircle, CheckCircle2, XCircle } from "lucide-react";
import { HealthStatus } from "../lib/get-codegate-health";
import { HealthStatus } from "../types";

export const CodegateStatusHealth = ({
data: data,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LoaderCircle, CheckCircle2, CircleAlert, XCircle } from "lucide-react";
import { VersionResponse } from "../lib/get-version-status";
import { Link, Tooltip, TooltipTrigger } from "@stacklok/ui-kit";
import { VersionResponse } from "../types";

export const CodegateStatusVersion = ({
data,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
import { queryOptions, useQuery } from "@tanstack/react-query";

import { getCodeGateHealth } from "../lib/get-codegate-health";
import { getVersionStatus } from "../lib/get-version-status";
import {
PollingInterval,
POLLING_INTERVAl,
} from "../components/codegate-status-polling-control";
import { healthCheckHealthGet, v1VersionCheck } from "@/api/generated";
import { HealthStatus, VersionResponse } from "../types";

type HealthResponse = { status: "healthy" | unknown } | null;

const getCodeGateHealth = async (): Promise<HealthStatus | null> => {
const data = (await healthCheckHealthGet()).data;

if ((data as HealthResponse)?.status === "healthy")
return HealthStatus.HEALTHY;
if ((data as HealthResponse)?.status !== "healthy")
return HealthStatus.UNHEALTHY;

return null;
};

const getVersion = async (): Promise<VersionResponse | null> => {
return ((await v1VersionCheck()).data as VersionResponse) ?? null;
};

export function getQueryOptionsCodeGateStatus(
pollingInterval: PollingInterval,
) {
return queryOptions({
queryFn: async () => {
const health = await getCodeGateHealth();
const version = await getVersionStatus();
const version = await getVersion();

return {
health,
version,
version: version as VersionResponse | null,
};
},
queryKey: ["useHealthCheck", { pollingInterval }],
Expand Down
18 changes: 0 additions & 18 deletions src/features/dashboard-codegate-status/lib/get-codegate-health.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/features/dashboard-codegate-status/lib/get-version-status.ts

This file was deleted.

11 changes: 11 additions & 0 deletions src/features/dashboard-codegate-status/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum HealthStatus {
HEALTHY = "Healthy",
UNHEALTHY = "Unhealthy",
}

export type VersionResponse = {
current_version: string;
latest_version: string;
is_latest: boolean | null;
error: string | null;
} | null;

0 comments on commit eada275

Please sign in to comment.