Skip to content

Commit a649eb0

Browse files
Return existing job when added job has same name
1 parent ec30a72 commit a649eb0

File tree

1 file changed

+29
-7
lines changed
  • plugins/jobs-management/src/JobsListWidget

1 file changed

+29
-7
lines changed

plugins/jobs-management/src/JobsListWidget/model.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ export function stateModelFactory(_pluginManager: PluginManager) {
4747
* #action
4848
*/
4949
addJob(job: NewJob) {
50-
const { cancelCallback } = job
50+
const { cancelCallback, name } = job
51+
const existing = self.jobs.find(job => job.name === name)
52+
if (existing) {
53+
return existing
54+
}
5155
const length = self.jobs.push(job)
5256
const addedJob = self.jobs[length - 1]!
5357
addedJob.setCancelCallback(cancelCallback)
@@ -66,22 +70,40 @@ export function stateModelFactory(_pluginManager: PluginManager) {
6670
* #action
6771
*/
6872
addFinishedJob(job: NewJob) {
69-
self.finished.push(job)
70-
return self.finished
73+
const existing = self.finished.find(
74+
finishedJob => finishedJob.name === job.name,
75+
)
76+
if (existing) {
77+
return existing
78+
}
79+
const length = self.finished.push(job)
80+
return self.finished[length - 1]
7181
},
7282
/**
7383
* #action
7484
*/
7585
addQueuedJob(job: NewJob) {
76-
self.queued.push(job)
77-
return self.finished
86+
const existing = self.queued.find(
87+
queuedJob => queuedJob.name === job.name,
88+
)
89+
if (existing) {
90+
return existing
91+
}
92+
const length = self.queued.push(job)
93+
return self.queued[length - 1]
7894
},
7995
/**
8096
* #action
8197
*/
8298
addAbortedJob(job: NewJob) {
83-
self.aborted.push(job)
84-
return self.aborted
99+
const existing = self.aborted.find(
100+
abortedJob => abortedJob.name === job.name,
101+
)
102+
if (existing) {
103+
return existing
104+
}
105+
const length = self.aborted.push(job)
106+
return self.aborted[length - 1]
85107
},
86108
/**
87109
* #action

0 commit comments

Comments
 (0)