Skip to content

Commit cb2e6af

Browse files
fix(menu): consistency bugs in menu
Wording consistency regarding cancelling/closing/editing jobs, especially as it relates to batch jobs; and the status of edited jobs is now reset to null.
1 parent 386acbc commit cb2e6af

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

src/main/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ import {
4444
selectPipeline,
4545
selectNextJob,
4646
selectPrevJob,
47-
removeBatchJob
47+
removeBatchJob,
48+
cancelBatchJob
4849
} from 'shared/data/slices/pipeline'
4950
import { setupClipboardEvents } from './ipcs/clipboard'
5051
import { checkForUpdate } from 'shared/data/slices/update'
@@ -218,6 +219,9 @@ function buildMenu() {
218219
// Open the settings window
219220
ipcMain.emit(IPC.WINDOWS.ABOUT.CREATE)
220221
},
222+
onCancelBatchJob: async (jobsInBatch) => {
223+
store.dispatch(cancelBatchJob(jobsInBatch))
224+
},
221225
})
222226
// @ts-ignore
223227
const menu = Menu.buildFromTemplate(template)

src/main/menu.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import { store } from './data/store'
77
import { closeApplication } from './windows'
88
import { selectEditOnNewTab } from 'shared/data/slices/settings'
99
import { selectDownloadPath } from 'shared/data/slices/settings'
10-
import { areAllJobsInBatchDone, getCompletedCountInBatch } from 'shared/utils'
10+
import {
11+
areAllJobsInBatchDone,
12+
getCompletedCountInBatch,
13+
getIdleCountInBatch,
14+
} from 'shared/utils'
1115

1216
export function buildMenuTemplate({
1317
appName,
@@ -23,6 +27,7 @@ export function buildMenuTemplate({
2327
onRemoveJob,
2428
onEditJob,
2529
onShowAbout,
30+
onCancelBatchJob,
2631
}) {
2732
let pipelineStatus = PipelineStatus.UNKNOWN
2833
const instance = getPipelineInstance(store.getState())
@@ -58,7 +63,7 @@ export function buildMenuTemplate({
5863
canDelete =
5964
pipelineStatus == PipelineStatus.RUNNING &&
6065
currentJob &&
61-
currentJob.state == JobState.SUBMITTED &&
66+
(currentJob.state == JobState.SUBMITTED || currentJob.state == JobState.ENDED) &&
6267
currentJob.jobData &&
6368
currentJob.jobData.status != JobStatus.RUNNING &&
6469
currentJob.jobData.status != JobStatus.IDLE
@@ -78,7 +83,10 @@ export function buildMenuTemplate({
7883
if (currentJob?.isPrimaryForBatch) {
7984
canCloseJob = areAllJobsInBatchDone(currentJob, jobsInBatch)
8085
} else {
81-
canCloseJob = currentJob && currentJob.state == JobState.SUBMITTED
86+
canCloseJob =
87+
currentJob &&
88+
(currentJob.state == JobState.SUBMITTED ||
89+
currentJob.state == JobState.ENDED)
8290
}
8391

8492
let canCreateJob = pipelineStatus == PipelineStatus.RUNNING
@@ -187,11 +195,28 @@ export function buildMenuTemplate({
187195
]
188196
: [
189197
{
190-
label: 'Cancel job',
198+
label: currentJob?.jobRequest?.batchId
199+
? 'Cancel scheduled jobs'
200+
: 'Cancel job',
191201
click: () => {
192-
onRemoveJob(currentJob)
202+
if (currentJob?.jobRequest?.batchId) {
203+
if (
204+
getIdleCountInBatch(
205+
currentJob,
206+
jobsInBatch
207+
) > 0
208+
) {
209+
onCancelBatchJob(jobsInBatch)
210+
}
211+
} else {
212+
onRemoveJob(currentJob)
213+
}
193214
},
194215
accelerator: 'CommandOrControl+D',
216+
enabled:
217+
!currentJob?.jobRequest?.batchId ||
218+
getIdleCountInBatch(currentJob, jobsInBatch) >
219+
0,
195220
},
196221
]),
197222
{ type: 'separator' },
@@ -232,7 +257,7 @@ export function buildMenuTemplate({
232257
onEditJob(currentJob)
233258
},
234259
accelerator: 'CommandOrControl+E',
235-
enabled: canDelete,
260+
enabled: canDelete && !currentJob?.jobRequest?.batchId,
236261
},
237262
{ type: 'separator' },
238263
{ role: 'copy' },

src/shared/data/slices/pipeline.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export const pipeline = createSlice({
180180
job.state = JobState.NEW
181181
if (job.jobData && job.jobData.results) {
182182
job.jobData.results = undefined
183+
job.jobData.status = null
183184
}
184185
if (job.jobRequestError) {
185186
job.jobRequestError = undefined

0 commit comments

Comments
 (0)