Skip to content

Commit

Permalink
Fix [Jobs] Delete job from the list view deletes single execution (#2151
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mariana-furyk authored Dec 22, 2023
1 parent 9c8da91 commit c17ec0c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 28 deletions.
27 changes: 26 additions & 1 deletion src/actions/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ import {
SET_NEW_JOB_VOLUMES,
SET_NEW_JOB_VOLUME_MOUNTS,
SET_TUNING_STRATEGY,
SET_URL
SET_URL,
DELETE_ALL_JOB__RUNS_BEGIN,
DELETE_ALL_JOB_RUNS_FAILURE,
DELETE_ALL_JOB_RUNS_SUCCESS
} from '../constants'
import { getNewJobErrorMsg } from '../components/JobWizard/JobWizard.util'
import { showErrorNotification } from '../utils/notifications.util'
Expand Down Expand Up @@ -100,6 +103,18 @@ const jobsActions = {
abortJobSuccess: () => ({
type: ABORT_JOB_SUCCESS
}),
deleteAllJobRuns: (project, job) => dispatch => {
dispatch(jobsActions.deleteAllJobRunsBegin())

return jobsApi
.deleteAllJobRuns(project, job.name)
.then(() => dispatch(jobsActions.deleteAllJobRunsSuccess()))
.catch(error => {
dispatch(jobsActions.deleteAllJobRunsFailure(error.message))

throw error
})
},
deleteJob: (project, job) => dispatch => {
dispatch(jobsActions.deleteJobBegin())

Expand All @@ -112,6 +127,16 @@ const jobsActions = {
throw error
})
},
deleteAllJobRunsBegin: () => ({
type: DELETE_ALL_JOB__RUNS_BEGIN
}),
deleteAllJobRunsFailure: error => ({
type: DELETE_ALL_JOB_RUNS_FAILURE,
payload: error
}),
deleteAllJobRunsSuccess: () => ({
type: DELETE_ALL_JOB_RUNS_SUCCESS
}),
deleteJobBegin: () => ({
type: DELETE_JOB_BEGIN
}),
Expand Down
3 changes: 3 additions & 0 deletions src/api/jobs-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ const jobsApi = {
{ params }
)
},
deleteAllJobRuns: (project, jobName) => {
return mainHttpClient.delete(`/projects/${project}/runs`, { params: { name: jobName } })
},
deleteJob: (project, jobUid) => {
return mainHttpClient.delete(`/projects/${project}/runs/${jobUid}`)
},
Expand Down
36 changes: 22 additions & 14 deletions src/components/Jobs/MonitorJobs/MonitorJobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { useYaml } from '../../../hooks/yaml.hook'

const MonitorJobs = ({
abortJob,
deleteAllJobRuns,
deleteJob,
fetchAllJobRuns,
fetchJob,
Expand Down Expand Up @@ -212,22 +213,29 @@ const MonitorJobs = ({

const onDeleteJob = useCallback(
job => {
handleDeleteJob(deleteJob, job, params.projectName, refreshJobs, filtersStore, dispatch).then(
() => {
if (params.jobName)
navigate(
location.pathname
.split('/')
.splice(0, location.pathname.split('/').indexOf(params.jobName) + 1)
.join('/')
)
}
)
handleDeleteJob(
params.jobName || !isEmpty(selectedJob) ? deleteJob : deleteAllJobRuns,
job,
params.projectName,
refreshJobs,
filtersStore,
dispatch
).then(() => {
if (params.jobName)
navigate(
location.pathname
.split('/')
.splice(0, location.pathname.split('/').indexOf(params.jobName) + 1)
.join('/')
)
})
},
[
deleteJob,
params.projectName,
params.jobName,
params.projectName,
selectedJob,
deleteJob,
deleteAllJobRuns,
refreshJobs,
filtersStore,
dispatch,
Expand All @@ -241,7 +249,7 @@ const MonitorJobs = ({
setConfirmData({
item: job,
header: 'Delete job?',
message: `You try to delete job "${job.name}".`,
message: `Do you want to delete the job "${job.name}"? Deleted jobs can not be restored.`,
btnConfirmLabel: 'Delete',
btnConfirmType: DANGER_BUTTON,
rejectHandler: () => {
Expand Down
13 changes: 7 additions & 6 deletions src/components/Jobs/MonitorJobs/monitorJobs.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ export const generateActionsMenu = (
hidden: !functionRunKinds.includes(job?.ui?.originalContent.metadata.labels?.kind),
onClick: handleRerunJob
},
{
label: 'Delete',
icon: <Delete />,
className: 'danger',
onClick: handleConfirmDeleteJob
},
{
label: 'Monitoring',
icon: <MonitorIcon />,
Expand All @@ -132,6 +126,12 @@ export const generateActionsMenu = (
label: 'View YAML',
icon: <Yaml />,
onClick: toggleConvertedYaml
},
{
label: 'Delete',
icon: <Delete />,
className: 'danger',
onClick: handleConfirmDeleteJob
}
]
]
Expand All @@ -148,6 +148,7 @@ export const generateActionsMenu = (

export const monitorJobsActionCreator = {
abortJob: jobsActions.abortJob,
deleteAllJobRuns: jobsActions.deleteAllJobRuns,
deleteJob: jobsActions.deleteJob,
fetchAllJobRuns: jobsActions.fetchAllJobRuns,
fetchJob: jobsActions.fetchJob,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Jobs/MonitorWorkflows/MonitorWorkflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ const MonitorWorkflows = ({
setConfirmData({
item: job,
header: 'Delete job?',
message: `You try to delete job "${job.name}".`,
message: `Do you want to delete the job "${job.name}"? Deleted jobs can not be restored.`,
btnConfirmLabel: 'Delete',
btnConfirmType: DANGER_BUTTON,
rejectHandler: () => {
Expand Down
12 changes: 6 additions & 6 deletions src/components/Jobs/MonitorWorkflows/monitorWorkflows.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ export const generateActionsMenu = (
hidden: [JOB_KIND_LOCAL, ''].includes(job?.ui?.originalContent.metadata.labels.kind),
onClick: handleRerunJob
},
{
label: 'Delete',
icon: <Delete />,
className: 'danger',
onClick: handleConfirmDeleteJob
},
{
label: 'Monitoring',
icon: <MonitorIcon />,
Expand All @@ -139,6 +133,12 @@ export const generateActionsMenu = (
label: 'View YAML',
icon: <Yaml />,
onClick: toggleConvertedYaml
},
{
label: 'Delete',
icon: <Delete />,
className: 'danger',
onClick: handleConfirmDeleteJob
}
]
]
Expand Down
3 changes: 3 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ export const DATASETS_FILTERS = 'DATASETS_FILTERS'
export const ABORT_JOB_BEGIN = 'ABORT_JOB_BEGIN'
export const ABORT_JOB_FAILURE = 'ABORT_JOB_FAILURE'
export const ABORT_JOB_SUCCESS = 'ABORT_JOB_SUCCESS'
export const DELETE_ALL_JOB__RUNS_BEGIN = 'DELETE_ALL_JOB__RUNS_BEGIN'
export const DELETE_ALL_JOB_RUNS_FAILURE = 'DELETE_ALL_JOB_RUNS_FAILURE'
export const DELETE_ALL_JOB_RUNS_SUCCESS = 'DELETE_ALL_JOB_RUNS_SUCCESS'
export const DELETE_JOB_BEGIN = 'DELETE_JOB_BEGIN'
export const DELETE_JOB_FAILURE = 'DELETE_JOB_FAILURE'
export const DELETE_JOB_SUCCESS = 'DELETE_JOB_SUCCESS'
Expand Down

0 comments on commit c17ec0c

Please sign in to comment.