Skip to content

Commit

Permalink
Replace fetchJobDestinationParams
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Jul 17, 2024
1 parent 3dcada2 commit 4ff8248
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 0 additions & 2 deletions client/src/api/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export const getJobDetails = fetcher.path("/api/jobs/{job_id}").method("get").cr
export const jobLockStatus = fetcher.path("/api/job_lock").method("get").create();
export const jobLockUpdate = fetcher.path("/api/job_lock").method("put").create();

export const fetchJobDestinationParams = fetcher.path("/api/jobs/{job_id}/destination_params").method("get").create();

export type ShowFullJobResponse = components["schemas"]["ShowFullJobResponse"];
export type JobDetails = components["schemas"]["ShowFullJobResponse"] | components["schemas"]["EncodedJobDetails"];
export const fetchJobDetails = fetcher.path("/api/jobs/{job_id}").method("get").create();
Expand Down
22 changes: 17 additions & 5 deletions client/src/stores/jobDestinationParametersStore.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import { defineStore } from "pinia";

import { fetchJobDestinationParams, type JobDestinationParams } from "@/api/jobs";
import { useKeyedCache } from "@/composables/keyedCache";
import { client } from "@/api";
import { type JobDestinationParams } from "@/api/jobs";
import { type FetchParams, useKeyedCache } from "@/composables/keyedCache";
import { rethrowSimple } from "@/utils/simple-error";

export const useJobDestinationParametersStore = defineStore("jobDestinationParametersStore", () => {
const { storedItems, getItemById, isLoadingItem } = useKeyedCache<JobDestinationParams>((params) =>
fetchJobDestinationParams({ job_id: params.id })
);
async function fetchJobDestinationParams(params: FetchParams): Promise<JobDestinationParams> {
const { data, error } = await client.GET("/api/jobs/{job_id}/destination_params", {
params: {
path: { job_id: params.id },
},
});
if (error) {
rethrowSimple(error);
}
return data;
}

const { storedItems, getItemById, isLoadingItem } = useKeyedCache<JobDestinationParams>(fetchJobDestinationParams);

return {
storedJobDestinationParameters: storedItems,
Expand Down

0 comments on commit 4ff8248

Please sign in to comment.