Merge pull request 'feature/output-2' (#6) from feature/output-2 into develop

Reviewed-on: #6
This commit is contained in:
2025-11-27 09:45:11 +00:00
14 changed files with 570 additions and 244 deletions

View File

@@ -13,13 +13,14 @@ type SystemHealthProps = {
const SystemHealth = ({ startTime, uptime, statuses, isLoading, isError, dateUpdatedAt }: SystemHealthProps) => {
const updatedDate = dateUpdatedAt ? new Date(dateUpdatedAt).toLocaleString() : null;
// console.log(statuses);
if (isError) {
return <span className="text-red-500">Error loading system health.</span>;
}
if (isLoading) {
return <span className="text-slate-500">Loading system health</span>;
}
return (
<div className="h-100 md:h-75 overflow-y-auto flex flex-col gap-4">
<div className="p-2 border-b border-gray-600 grid grid-cols-2 justify-between">
@@ -32,7 +33,7 @@ const SystemHealth = ({ startTime, uptime, statuses, isLoading, isError, dateUpd
</div>
<div className="h-50 overflow-auto">
{statuses?.map((status: SystemHealthStatus) => (
<div className="border border-gray-700 p-4 rounded-md m-2 flex justify-between">
<div className="border border-gray-700 p-4 rounded-md m-2 flex justify-between" key={status.id}>
<span>{status.id}</span> <Badge text={status.tags[0]} />
</div>
))}

View File

@@ -14,7 +14,6 @@ const SystemOverview = () => {
const isError = query?.isError;
const dateUpdatedAt = query?.dataUpdatedAt;
console.log(query?.dataUpdatedAt);
return (
<Card className="p-4">
<CardHeader title="System Health" refetch={query?.refetch} icon={faArrowsRotate} />

View File

@@ -1,7 +1,8 @@
import { useQuery } from "@tanstack/react-query";
import { CAMBASE } from "../../../utils/config";
const fetchData = async () => {
const response = await fetch(`http://100.115.148.59/api/system-health`);
const response = await fetch(`${CAMBASE}/api/system-health`);
if (!response.ok) throw new Error("Cannot get System overview");
return response.json();
};

View File

@@ -1,6 +1,8 @@
import { Field } from "formik";
import { Field, useFormikContext } from "formik";
import type { FormTypes } from "../../../types/types";
const BearerTypeFields = () => {
useFormikContext<FormTypes>();
return (
<div className="flex flex-row justify-between">
<label htmlFor="format" className="text-xl">

View File

@@ -3,14 +3,22 @@ import Card from "../../../ui/Card";
import CardHeader from "../../../ui/CardHeader";
import ChannelFields from "./ChannelFields";
import type { FormTypes } from "../../../types/types";
import { useGetBearerConfig } from "../hooks/useBearer";
const ChannelCard = () => {
const { values, errors, touched } = useFormikContext<FormTypes>();
const { values, errors, touched, setFieldValue } = useFormikContext<FormTypes>();
const { bearerQuery } = useGetBearerConfig(values?.format?.toLowerCase() || "json");
const outputData = bearerQuery?.data;
return (
<Card className="p-4 h-150 md:h-full">
<CardHeader title={`Channel (${values?.format})`} />
<ChannelFields errors={errors} touched={touched} values={values} />
<ChannelFields
errors={errors}
touched={touched}
values={values}
outputData={outputData}
onSetFieldValue={setFieldValue}
/>
<button
type="submit"
className="w-full md:w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5"

View File

@@ -1,5 +1,7 @@
import { Field } from "formik";
import type { FormTypes, InitialValuesFormErrors } from "../../../types/types";
import type { FormTypes, InitialValuesFormErrors, OutputDataResponse } from "../../../types/types";
import { useEffect, useMemo } from "react";
import { useOptionalConstants } from "../hooks/useOptionalConstants";
type ChannelFieldsProps = {
values: FormTypes;
@@ -8,11 +10,47 @@ type ChannelFieldsProps = {
connectTimeoutSeconds?: boolean | undefined;
readTimeoutSeconds?: boolean | undefined;
};
outputData?: OutputDataResponse;
onSetFieldValue: (field: string, value: string, shouldValidate?: boolean | undefined) => void;
};
const ChannelFields = ({ errors, touched, values }: ChannelFieldsProps) => {
const ChannelFields = ({ errors, touched, values, outputData, onSetFieldValue }: ChannelFieldsProps) => {
const { optionalConstantsQuery } = useOptionalConstants(outputData?.id?.split("-")[1] || "");
const optionalConstants = optionalConstantsQuery?.data;
const channelFieldsObject = useMemo(() => {
return {
connectTimeoutSeconds: outputData?.propConnectTimeoutSeconds?.value || "5",
readTimeoutSeconds: outputData?.propReadTimeoutSeconds?.value || "15",
backOfficeURL: outputData?.propBackofficeURL?.value || "",
username: outputData?.propUsername?.value || "",
password: outputData?.propPassword?.value || "",
SCID: optionalConstants?.propSourceIdentifier?.value || "",
timestampSource: optionalConstants?.propTimeZoneType?.value || "UTC",
GPSFormat: optionalConstants?.propGpsFormat?.value || "Minutes",
FFID: optionalConstants?.propFeedIdentifier?.value || "",
};
}, [
optionalConstants?.propFeedIdentifier?.value,
optionalConstants?.propGpsFormat?.value,
optionalConstants?.propSourceIdentifier?.value,
optionalConstants?.propTimeZoneType?.value,
outputData?.propBackofficeURL?.value,
outputData?.propConnectTimeoutSeconds?.value,
outputData?.propPassword?.value,
outputData?.propReadTimeoutSeconds?.value,
outputData?.propUsername?.value,
]);
useEffect(() => {
for (const [key, value] of Object.entries(channelFieldsObject)) {
onSetFieldValue(key, value);
}
}, [channelFieldsObject, onSetFieldValue, outputData]);
return (
<div className="flex flex-col gap-4 p-4">
{values.format.toLowerCase() !== "ftp" ? (
<>
<div className="flex flex-row justify-between">
<label htmlFor="backoffice" className="block mb-2 font-medium">
Back Office URL
@@ -176,7 +214,7 @@ const ChannelFields = ({ errors, touched, values }: ChannelFieldsProps) => {
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
>
<option value={"UTC"}>UTC</option>
<option value={"local"}>Local</option>
<option value={"LOCAL"}>Local</option>
</Field>
</div>
<div className="flex flex-row justify-between">
@@ -223,6 +261,10 @@ const ChannelFields = ({ errors, touched, values }: ChannelFieldsProps) => {
</div>
</>
)}
</>
) : (
<></>
)}
</div>
);
};

View File

@@ -1,44 +0,0 @@
import { Formik, Form } from "formik";
import BearerTypeCard from "./BearerTypeCard";
import ChannelCard from "./ChannelCard";
import type { FormTypes } from "../../../types/types";
const Output = () => {
const handleSubmit = (values: FormTypes) => {
console.log(values);
};
const inititalValues: FormTypes = {
format: "JSON",
enabled: true,
backOfficeURL: "",
username: "",
password: "",
connectTimeoutSeconds: Number(5),
readTimeoutSeconds: Number(15),
overviewQuality: "HIGH",
cropSizeFactor: "3/4",
// Bof2 -optional constants
FFID: "",
SCID: "",
timestampSource: "UTC",
GPSFormat: "Minutes",
//BOF2 - optional Lane IDs
laneId: "",
LID1: "",
LID2: "",
};
return (
<Formik initialValues={inititalValues} onSubmit={handleSubmit}>
<Form className="grid grid-cols-1 md:grid-cols-2">
<BearerTypeCard />
<ChannelCard />
</Form>
</Formik>
);
};
export default Output;

View File

@@ -0,0 +1,105 @@
import { Formik, Form } from "formik";
import BearerTypeCard from "./BearerTypeCard";
import ChannelCard from "./ChannelCard";
import type { BearerTypeFields, FormTypes, OptionalBOF2Constants, OptionalUTMCConstants } from "../../../types/types";
import { usePostBearerConfig } from "../hooks/useBearer";
import { useDispatcherConfig } from "../hooks/useDispatcherConfig";
import { useOptionalConstants } from "../hooks/useOptionalConstants";
const OutputForms = () => {
const { bearerMutation } = usePostBearerConfig();
const { dispatcherQuery, dispatcherMutation } = useDispatcherConfig();
const isLoading = dispatcherQuery?.isLoading;
const format = dispatcherQuery?.data?.propFormat?.value;
const { optionalConstantsQuery, optionalConstantsMutation } = useOptionalConstants(format?.toLowerCase());
const FFID = optionalConstantsQuery?.data?.propFeedIdentifier?.value;
const SCID = optionalConstantsQuery?.data?.propSourceIdentifier?.value;
const timestampSource = optionalConstantsQuery?.data?.propTimeZoneType?.value;
const gpsFormat = optionalConstantsQuery?.data?.propGpsFormat?.value;
const inititalValues: FormTypes = {
format: format ?? "JSON",
enabled: true,
backOfficeURL: "",
username: "",
password: "",
connectTimeoutSeconds: Number(5),
readTimeoutSeconds: Number(15),
overviewQuality: "HIGH",
cropSizeFactor: "3/4",
// optional constants
FFID: FFID ?? "",
SCID: SCID ?? "",
timestampSource: timestampSource ?? "UTC",
GPSFormat: gpsFormat ?? "Minutes",
//BOF2 - optional Lane IDs
laneId: "",
LID1: "",
LID2: "",
// ftp - fields
};
const handleSubmit = async (values: FormTypes) => {
const bearerTypeFields = {
format: values.format,
enabled: values.enabled,
};
const bearerFields: BearerTypeFields = {
format: values.format,
enabled: values.enabled,
backOfficeURL: values.backOfficeURL,
username: values.username,
password: values.password,
connectTimeoutSeconds: values.connectTimeoutSeconds,
readTimeoutSeconds: values.readTimeoutSeconds,
overviewQuality: values.overviewQuality,
cropSizeFactor: values.cropSizeFactor,
};
const result = await dispatcherMutation.mutateAsync(bearerTypeFields);
if (result?.id) {
await bearerMutation.mutateAsync(bearerFields);
if (values.format === "BOF2") {
const optionalBOF2Fields: OptionalBOF2Constants = {
format: values.format,
FFID: values.FFID,
SCID: values.SCID,
timestampSource: values.timestampSource,
GPSFormat: values.GPSFormat,
};
await optionalConstantsMutation.mutateAsync(optionalBOF2Fields);
}
if (values.format === "UTMC") {
const optionalUTMCFields: OptionalUTMCConstants = {
format: values.format,
SCID: values.SCID,
timestampSource: values.timestampSource,
GPSFormat: values.GPSFormat,
};
await optionalConstantsMutation.mutateAsync(optionalUTMCFields);
}
}
};
if (isLoading) {
return <div>Loading...</div>;
}
return (
<Formik initialValues={inititalValues} onSubmit={handleSubmit} enableReinitialize>
<Form className="grid grid-cols-1 md:grid-cols-2">
<BearerTypeCard />
<ChannelCard />
</Form>
</Formik>
);
};
export default OutputForms;

View File

@@ -0,0 +1,66 @@
import { useMutation, useQuery } from "@tanstack/react-query";
import type { BearerTypeFields } from "../../../types/types";
import { CAMBASE } from "../../../utils/config";
const fetchBearerConfig = async (bearerConfig: string) => {
const response = await fetch(`${CAMBASE}/api/fetch-config?id=Dispatcher0-${bearerConfig}`, {
method: "GET",
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
const postBearerConfig = async (config: BearerTypeFields) => {
const channelConfigPayload = {
id: `Dispatcher0-${config.format.toLowerCase()}`,
fields: [
{
property: "propBackofficeURL",
value: config.backOfficeURL,
},
{
property: "propConnectTimeoutSeconds",
value: config.connectTimeoutSeconds,
},
{
property: "propPassword",
value: config.password,
},
{
property: "propReadTimeoutSeconds",
value: config.readTimeoutSeconds,
},
{
property: "propUsername",
value: config.username,
},
],
};
const response = await fetch(`${CAMBASE}/api/update-config`, {
method: "POST",
body: JSON.stringify(channelConfigPayload),
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
export const usePostBearerConfig = () => {
const bearerMutation = useMutation({
mutationFn: (query: BearerTypeFields) => postBearerConfig(query),
mutationKey: ["outputs"],
});
return { bearerMutation };
};
export const useGetBearerConfig = (bearerConfig: string) => {
const bearerQuery = useQuery({
queryKey: ["outputs", bearerConfig],
queryFn: () => fetchBearerConfig(bearerConfig),
});
return { bearerQuery };
};

View File

@@ -0,0 +1,48 @@
import { useQuery, useMutation } from "@tanstack/react-query";
import type { DispatcherConfig } from "../../../types/types";
import { CAMBASE } from "../../../utils/config";
const getDispatcherConfig = async () => {
const response = await fetch(`${CAMBASE}/api/fetch-config?id=Dispatcher0`);
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
const postDispatcherConfig = async (config: DispatcherConfig) => {
const updateConfigPayload = {
id: "Dispatcher0",
fields: [
{
property: "propEnabled",
value: config.enabled,
},
{
property: "propFormat",
value: config.format,
},
],
};
const response = await fetch(`${CAMBASE}/api/update-config`, {
method: "POST",
body: JSON.stringify(updateConfigPayload),
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
export const useDispatcherConfig = () => {
const dispatcherQuery = useQuery({
queryKey: ["dispatcherConfig"],
queryFn: () => getDispatcherConfig(),
});
const dispatcherMutation = useMutation({
mutationKey: ["postDispatcherConfig"],
mutationFn: (config: DispatcherConfig) => postDispatcherConfig(config),
});
return { dispatcherQuery, dispatcherMutation };
};

View File

@@ -0,0 +1,63 @@
import { useQuery, useMutation } from "@tanstack/react-query";
import type { OptionalBOF2Constants } from "../../../types/types";
import { CAMBASE } from "../../../utils/config";
const fetchOptionalConstants = async (format: string) => {
if (!format || format === "json") return null;
const response = await fetch(`${CAMBASE}/api/fetch-config?id=Dispatcher0-${format}-constants`);
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
const postOptionalConstants = async (config: OptionalBOF2Constants) => {
const fields = [
{
property: "propSourceIdentifier",
value: config?.SCID,
},
{
property: "propTimeZoneType",
value: config?.timestampSource,
},
{
property: "propGpsFormat",
value: config?.GPSFormat,
},
];
if (config.FFID) {
fields.push({
property: "propFeedIdentifier",
value: config.FFID,
});
}
const updateConfigPayload = {
id: `Dispatcher0-${config.format?.toLowerCase()}-constants`,
fields: fields,
};
const response = await fetch(`${CAMBASE}/api/update-config`, {
method: "POST",
body: JSON.stringify(updateConfigPayload),
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
export const useOptionalConstants = (format: string) => {
const optionalConstantsQuery = useQuery({
queryKey: ["optionalConstants", format],
queryFn: () => fetchOptionalConstants(format),
enabled: !!format && format !== "json",
});
const optionalConstantsMutation = useMutation({
mutationKey: ["postOptionalConstants"],
mutationFn: postOptionalConstants,
});
return { optionalConstantsQuery, optionalConstantsMutation };
};

View File

@@ -1,5 +1,5 @@
import { createFileRoute } from "@tanstack/react-router";
import Output from "../features/output/components/Output";
import OutputForms from "../features/output/components/OutputForms";
export const Route = createFileRoute("/output")({
component: RouteComponent,
@@ -8,7 +8,7 @@ export const Route = createFileRoute("/output")({
function RouteComponent() {
return (
<div>
<Output />
<OutputForms />
</div>
);
}

View File

@@ -57,7 +57,41 @@ export type InitialValuesFormErrors = {
};
export type FormTypes = BearerTypeFields & OptionalConstants & OptionalLaneIDs;
type FieldProperty = {
datatype: string;
value: string;
};
export type OutputDataResponse = {
id: string;
configHash: string;
} & Record<string, FieldProperty>;
export type PaintedCell = {
colour: string;
};
export type DispatcherConfig = {
format: string;
enabled: boolean;
};
export type OptionalBOF2Constants = {
format?: string;
FFID?: string;
SCID?: string;
timestampSource?: string;
GPSFormat?: string;
};
export type OptionalUTMCConstants = {
format?: string;
SCID?: string;
timestampSource?: string;
GPSFormat?: string;
};
export type OptionalBOF2LaneIDs = {
laneId?: string;
LID1?: string;
LID2?: string;
LID3?: string;
};

1
src/utils/config.ts Normal file
View File

@@ -0,0 +1 @@
export const CAMBASE = import.meta.env.VITE_BASEURL;