feat: send http

This commit is contained in:
Carlos Valente
2025-01-11 14:39:58 +01:00
committed by Carlos Valente
parent 8b84963e17
commit ab4dd300ca
8 changed files with 138 additions and 52 deletions
+2 -2
View File
@@ -80,6 +80,6 @@ export function deleteBlueprint(id: string): Promise<void> {
* HTTP request to test automation output
* The return is irrelevant as we care for the resolution of the promise
*/
export async function testOutput(output: AutomationOutput): Promise<void> {
return axios.post(automationsPath, output);
export function testOutput(output: AutomationOutput): Promise<void> {
return axios.post(`${automationsPath}/test`, output);
}
@@ -6,13 +6,14 @@ import { IoTrash } from '@react-icons/all-files/io5/IoTrash';
import {
AutomationBlueprint,
AutomationBlueprintDTO,
CustomFields,
HTTPOutput,
isHTTPOutput,
isOSCOutput,
OSCOutput,
OntimeEvent,
} from 'ontime-types';
import { addBlueprint, editBlueprint } from '../../../../common/api/automation';
import { addBlueprint, editBlueprint, testOutput } from '../../../../common/api/automation';
import { maybeAxiosError } from '../../../../common/api/utils';
import Tag from '../../../../common/components/tag/Tag';
import useAutomationSettings from '../../../../common/hooks-query/useAutomationSettings';
@@ -40,6 +41,7 @@ export default function BlueprintForm(props: BlueprintFormProps) {
const {
control,
handleSubmit,
getValues,
register,
setError,
setFocus,
@@ -364,7 +366,6 @@ export default function BlueprintForm(props: BlueprintFormProps) {
url?: { message?: string };
}
| undefined;
const canTest = output.url;
return (
<div key={output.id} className={style.outputCard}>
<Tag>HTTP</Tag>
@@ -387,7 +388,7 @@ export default function BlueprintForm(props: BlueprintFormProps) {
<Panel.Error>{rowErrors?.url?.message}</Panel.Error>
</label>
<Panel.InlineElements relation='inner'>
<Button size='sm' variant='ontime-ghosted' isDisabled={!canTest} onClick={handleTestHTTPOutput}>
<Button size='sm' variant='ontime-ghosted' onClick={() => handleTestHTTPOutput(index)}>
Test
</Button>
<IconButton
@@ -444,3 +445,38 @@ export default function BlueprintForm(props: BlueprintFormProps) {
</Panel.Indent>
);
}
/**
* We use this guard to find out if the form is receiving an existing blueprint or creating a DTO
* We do this by checking whether an ID has been generated
*/
function isBlueprint(blueprint: AutomationBlueprintDTO | AutomationBlueprint): blueprint is AutomationBlueprint {
return Object.hasOwn(blueprint, 'id');
}
export const staticSelectProperties = [
{ value: 'id', label: 'ID' },
{ value: 'title', label: 'Title' },
{ value: 'cue', label: 'Cue' },
{ value: 'countToEnd', label: 'Count to end' },
{ value: 'isPublic', label: 'Is public' },
{ value: 'skip', label: 'Skip' },
{ value: 'note', label: 'Note' },
{ value: 'colour', label: 'Colour' },
{ value: 'endAction', label: 'End action' },
{ value: 'timerType', label: 'Timer type' },
{ value: 'timeWarning', label: 'Time warning' },
{ value: 'timeDanger', label: 'Time danger' },
];
type SelectableField = {
value: keyof OntimeEvent | string; // string for custom fields
label: string;
};
function makeFieldList(customFields: CustomFields): SelectableField[] {
return [
...staticSelectProperties,
...Object.entries(customFields).map(([key, { label }]) => ({ value: key, label: `Custom: ${label}` })),
];
}