File tree Expand file tree Collapse file tree 4 files changed +65
-0
lines changed
Expand file tree Collapse file tree 4 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Button } from "@mui/material" ;
2+
3+ import { setWorkerState , type WorkerRequest } from "../utils/api" ;
4+
5+ const AbortButton = ( ) => {
6+ return (
7+ < Button
8+ variant = "contained"
9+ color = "error"
10+ sx = { { width : "150px" } }
11+ onClick = { async ( ) => {
12+ const workerRequest : WorkerRequest = {
13+ new_state : "ABORTING" ,
14+ defer : false ,
15+ reason : "UI Intervention" ,
16+ } ;
17+ await setWorkerState ( workerRequest ) ;
18+ } }
19+ >
20+ Abort
21+ </ Button >
22+ ) ;
23+ } ;
24+
25+ export default AbortButton ;
Original file line number Diff line number Diff line change 11import { useInstrumentSession } from "../../context/instrumentSession/useInstrumentSession" ;
22import RunPlanButton from "../RunPlanButton" ;
3+ import AbortButton from "../AbortButton" ;
34import { useState } from "react" ;
45import { NumberInput } from "../NumberInput" ;
56import { Box } from "@mui/material" ;
@@ -97,6 +98,9 @@ export function SpectroscopyForm() {
9798 instrumentSession = { instrumentSession }
9899 />
99100 </ Box >
101+ < Box sx = { { mt : 4 } } display = { "flex" } justifyContent = { "center" } >
102+ < AbortButton />
103+ </ Box >
100104 </ Box >
101105 ) ;
102106}
Original file line number Diff line number Diff line change @@ -41,6 +41,10 @@ export const handlers = [
4141 } ) ;
4242 } ) ,
4343
44+ http . put ( "/api/worker/state" , ( ) => {
45+ return HttpResponse . json ( "IDLE" ) ;
46+ } ) ,
47+
4448 http . get ( "/api/data/map" , ( { request } ) => {
4549 const url = new URL ( request . url ) ;
4650 const filepath = url . searchParams . get ( "filepath" ) ;
Original file line number Diff line number Diff line change @@ -77,3 +77,35 @@ export async function startTask(task_id: string): Promise<TaskResponse> {
7777
7878 return await response . json ( ) ;
7979}
80+
81+ export interface WorkerRequest {
82+ new_state : string ;
83+ defer : boolean ;
84+ reason : string ;
85+ }
86+
87+ export interface WorkerResponse {
88+ worker_state : string ;
89+ }
90+
91+ export async function setWorkerState (
92+ worker_request : WorkerRequest ,
93+ ) : Promise < WorkerResponse > {
94+ const url = "/api/worker/state" ;
95+
96+ const headers = new Headers ( ) ;
97+ headers . append ( "Content-Type" , "application/json" ) ;
98+ headers . append ( "X-Requested-By" , "XMLHttpRequest" ) ;
99+
100+ const response = await fetch ( url , {
101+ method : "PUT" ,
102+ headers : headers ,
103+ body : JSON . stringify ( {
104+ new_state : worker_request . new_state ,
105+ defer : worker_request . defer ,
106+ reason : worker_request . reason ,
107+ } ) ,
108+ } ) ;
109+
110+ return await response . json ( ) ;
111+ }
You can’t perform that action at this time.
0 commit comments