From 020244e1c0b86b5636c90df47f4db20e68ba7f53 Mon Sep 17 00:00:00 2001 From: Dennis Oelkers Date: Thu, 12 Mar 2026 16:43:12 +0100 Subject: [PATCH] Fixing up types. --- .../src/stores/systemjobs/SystemJobsStore.ts | 103 +++++++++--------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/graylog2-web-interface/src/stores/systemjobs/SystemJobsStore.ts b/graylog2-web-interface/src/stores/systemjobs/SystemJobsStore.ts index 0667bd15fd..e94b7995ad 100644 --- a/graylog2-web-interface/src/stores/systemjobs/SystemJobsStore.ts +++ b/graylog2-web-interface/src/stores/systemjobs/SystemJobsStore.ts @@ -52,64 +52,65 @@ export const SystemJobsActions = singletonActions('core.SystemJobs', () => }), ); -export const SystemJobsStore: Store<{ jobs: unknown; jobsById: Record }> = singletonStore( - 'core.SystemJobs', - () => - Reflux.createStore({ - listenables: [SystemJobsActions], +export const SystemJobsStore: Store<{ + jobs: Record; + jobsById: Record; +}> = singletonStore('core.SystemJobs', () => + Reflux.createStore({ + listenables: [SystemJobsActions], - jobsById: {} as Record, + jobsById: {} as Record, - getInitialState() { - return { jobs: this.jobs, jobsById: this.jobsById }; - }, - list() { - const url = URLUtils.qualifyUrl(ApiRoutes.SystemJobsApiController.list().url); - const promise = fetchPeriodically('GET', url).then((response) => { - this.jobs = response; - this.trigger({ jobs: response }); + getInitialState() { + return { jobs: this.jobs, jobsById: this.jobsById }; + }, + list() { + const url = URLUtils.qualifyUrl(ApiRoutes.SystemJobsApiController.list().url); + const promise = fetchPeriodically('GET', url).then((response) => { + this.jobs = response; + this.trigger({ jobs: response }); + + return response; + }); + + SystemJobsActions.list.promise(promise); + }, + getJob(jobId: string) { + const url = URLUtils.qualifyUrl(ApiRoutes.SystemJobsApiController.getJob(jobId).url); + const promise = fetch<{ id: string }>('GET', url).then( + (response) => { + this.jobsById = { ...this.jobsById, [response.id]: response }; + this.trigger({ jobsById: this.jobsById }); return response; - }); + }, + () => { + // If we get an error (probably 404 because the job is gone), remove the job from the cache and trigger an update. - SystemJobsActions.list.promise(promise); - }, - getJob(jobId: string) { - const url = URLUtils.qualifyUrl(ApiRoutes.SystemJobsApiController.getJob(jobId).url); - const promise = fetch<{ id: string }>('GET', url).then( - (response) => { - this.jobsById = { ...this.jobsById, [response.id]: response }; - this.trigger({ jobsById: this.jobsById }); + const { [jobId]: _, ...rest } = this.jobsById; - return response; - }, - () => { - // If we get an error (probably 404 because the job is gone), remove the job from the cache and trigger an update. + this.jobsById = rest; + this.trigger({ jobsById: this.jobsById }); + }, + ); - const { [jobId]: _, ...rest } = this.jobsById; + SystemJobsActions.getJob.promise(promise); + }, + acknowledgeJob(jobId: string) { + const url = URLUtils.qualifyUrl(ApiRoutes.SystemJobsApiController.acknowledgeJob(jobId).url); + const promise = fetch('DELETE', url).then(() => { + delete this.jobsById[jobId]; + }); - this.jobsById = rest; - this.trigger({ jobsById: this.jobsById }); - }, - ); + SystemJobsActions.acknowledgeJob.promise(promise); + }, + cancelJob(jobId: string) { + const url = URLUtils.qualifyUrl(ApiRoutes.SystemJobsApiController.cancelJob(jobId).url); + const promise = fetch<{ id: string }>('DELETE', url).then((response) => { + delete this.jobsById[response.id]; + }); - SystemJobsActions.getJob.promise(promise); - }, - acknowledgeJob(jobId: string) { - const url = URLUtils.qualifyUrl(ApiRoutes.SystemJobsApiController.acknowledgeJob(jobId).url); - const promise = fetch('DELETE', url).then(() => { - delete this.jobsById[jobId]; - }); - - SystemJobsActions.acknowledgeJob.promise(promise); - }, - cancelJob(jobId: string) { - const url = URLUtils.qualifyUrl(ApiRoutes.SystemJobsApiController.cancelJob(jobId).url); - const promise = fetch<{ id: string }>('DELETE', url).then((response) => { - delete this.jobsById[response.id]; - }); - - SystemJobsActions.cancelJob.promise(promise); - }, - }), + SystemJobsActions.cancelJob.promise(promise); + }, + }), );