|
3 | 3 | * Requests response generated by a tool run |
4 | 4 | */ |
5 | 5 |
|
6 | | -import axios from "axios"; |
7 | 6 | import { defineStore } from "pinia"; |
8 | | -import Vue from "vue"; |
| 7 | +import { ref } from "vue"; |
9 | 8 |
|
10 | | -import { getAppRoot } from "@/onload/loadConfig"; |
| 9 | +import { GalaxyApi } from "@/api"; |
| 10 | +import type { ResponseVal, ShowFullJobResponse } from "@/api/jobs"; |
| 11 | +import { type FetchParams, useKeyedCache } from "@/composables/keyedCache"; |
| 12 | +import { rethrowSimple } from "@/utils/simple-error"; |
11 | 13 |
|
12 | | -/* interfaces */ |
13 | | -interface Job { |
14 | | - id: string; |
15 | | - tool_id: string; |
16 | | - tool_version: string; |
17 | | - tool_stdout: string; |
18 | | - tool_stderr: string; |
19 | | -} |
20 | | -interface JobDef { |
21 | | - tool_id: string; |
22 | | -} |
23 | | -interface JobResponse { |
24 | | - produces_entry_points: boolean; |
25 | | - jobs: Array<Job>; |
26 | | -} |
27 | | -interface ResponseVal { |
28 | | - jobDef: JobDef; |
29 | | - jobResponse: JobResponse; |
30 | | - toolName: string; |
31 | | -} |
| 14 | +export const useJobStore = defineStore("jobStore", () => { |
| 15 | + const latestResponse = ref<ResponseVal | null>(null); |
32 | 16 |
|
33 | | -export const useJobStore = defineStore("jobStore", { |
34 | | - state: () => ({ |
35 | | - jobs: {} as { [index: string]: Job }, |
36 | | - response: {} as ResponseVal, |
37 | | - }), |
38 | | - getters: { |
39 | | - getJob: (state) => { |
40 | | - return (jobId: string) => state.jobs[jobId]; |
41 | | - }, |
42 | | - getLatestResponse: (state) => { |
43 | | - return state.response; |
44 | | - }, |
45 | | - }, |
46 | | - actions: { |
47 | | - async fetchJob(jobId: string) { |
48 | | - const { data } = await axios.get(`${getAppRoot()}api/jobs/${jobId}?full=true`); |
49 | | - this.saveJobForJobId(jobId, data); |
50 | | - }, |
51 | | - // Setters |
52 | | - saveJobForJobId(jobId: string, job: Job) { |
53 | | - Vue.set(this.jobs, jobId, job); |
54 | | - }, |
55 | | - saveLatestResponse(response: ResponseVal) { |
56 | | - this.response = response; |
57 | | - }, |
58 | | - }, |
| 17 | + async function fetchJobById(params: FetchParams): Promise<ShowFullJobResponse> { |
| 18 | + const { data, error } = await GalaxyApi().GET("/api/jobs/{job_id}", { |
| 19 | + params: { path: { job_id: params.id } }, |
| 20 | + query: { full: true }, |
| 21 | + }); |
| 22 | + if (error) { |
| 23 | + rethrowSimple(error); |
| 24 | + } |
| 25 | + return data; |
| 26 | + } |
| 27 | + |
| 28 | + function saveLatestResponse(newResponse: ResponseVal) { |
| 29 | + latestResponse.value = newResponse; |
| 30 | + } |
| 31 | + |
| 32 | + const { |
| 33 | + fetchItemById: fetchJob, |
| 34 | + getItemById: getJob, |
| 35 | + getItemLoadError: getJobLoadError, |
| 36 | + isLoadingItem: isLoadingJob, |
| 37 | + } = useKeyedCache<ShowFullJobResponse>(fetchJobById); |
| 38 | + |
| 39 | + return { |
| 40 | + fetchJob, |
| 41 | + saveLatestResponse, |
| 42 | + getJob, |
| 43 | + getJobLoadError, |
| 44 | + isLoadingJob, |
| 45 | + latestResponse, |
| 46 | + }; |
59 | 47 | }); |
0 commit comments