Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/composables/queue/useJobActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useI18n } from 'vue-i18n'
import { useErrorHandling } from '@/composables/useErrorHandling'
import type { JobListItem } from '@/composables/queue/useJobList'
import { useJobMenu } from '@/composables/queue/useJobMenu'
import type { TaskItemImpl } from '@/stores/queueStore'
import type { JobState } from '@/types/queue'

export type JobAction = {
Expand All @@ -18,14 +19,20 @@ export function useJobActions(
) {
const { t } = useI18n()
const { wrapWithErrorHandlingAsync } = useErrorHandling()
const { cancelJob } = useJobMenu()
const { cancelJob, removeFailedJob } = useJobMenu()

const cancelAction: JobAction = {
icon: 'icon-[lucide--x]',
label: t('sideToolbar.queueProgressOverlay.cancelJobTooltip'),
variant: 'destructive'
}

const deleteAction: JobAction = {
icon: 'icon-[lucide--circle-minus]',
label: t('queue.jobMenu.removeJob'),
variant: 'destructive'
}

const cancellableStates: JobState[] = ['pending', 'initialization', 'running']

const jobRef = computed(() => toValue(job) ?? null)
Expand All @@ -42,6 +49,15 @@ export function useJobActions(
)
})

const canDeleteJob = computed(() => {
const currentJob = jobRef.value
if (!currentJob) {
return false
}

return currentJob.state === 'failed'
})

const runCancelJob = wrapWithErrorHandlingAsync(async () => {
const currentJob = jobRef.value
if (!currentJob) {
Expand All @@ -51,9 +67,22 @@ export function useJobActions(
await cancelJob(currentJob)
})

const runDeleteJob = wrapWithErrorHandlingAsync(async () => {
const currentJob = jobRef.value
const task = currentJob?.taskRef as TaskItemImpl | undefined
if (!task) {
return
}

await removeFailedJob(task)
})

return {
cancelAction,
canCancelJob,
runCancelJob
runCancelJob,
deleteAction,
canDeleteJob,
runDeleteJob
}
}
12 changes: 7 additions & 5 deletions src/composables/queue/useJobMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ export function useJobMenu(
}
}

const removeFailedJob = async () => {
const task = currentMenuItem()?.taskRef as TaskItemImpl | undefined
if (!task) return
await queueStore.delete(task)
const removeFailedJob = async (task?: TaskItemImpl | null) => {
const target =
task ?? (currentMenuItem()?.taskRef as TaskItemImpl | undefined)
if (!target) return
await queueStore.delete(target)
}

const jobMenuOpenWorkflowLabel = computed(() =>
Expand Down Expand Up @@ -365,6 +366,7 @@ export function useJobMenu(
jobMenuEntries,
openJobWorkflow,
copyJobId,
cancelJob
cancelJob,
removeFailedJob
}
}
33 changes: 27 additions & 6 deletions src/platform/assets/components/ActiveMediaAssetCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@
class="icon-[lucide--loader-circle] size-8 animate-spin text-muted-foreground"
/>
</div>
<!-- Cancel button overlay -->
<!-- Cancel/Delete button overlay -->
<Button
v-if="hovered && canCancelJob"
v-if="hovered && showActionButton"
variant="destructive"
size="icon"
:aria-label="cancelAction.label"
:aria-label="activeAction.label"
class="absolute top-2 right-2"
@click.stop="runCancelJob()"
@click.stop="runActiveAction()"
>
<i :class="cancelAction.icon" />
<i :class="activeAction.icon" />
</Button>
</div>

Expand Down Expand Up @@ -90,7 +90,28 @@ const { job } = defineProps<{ job: JobListItem }>()
const { t } = useI18n()
const hovered = ref(false)

const { cancelAction, canCancelJob, runCancelJob } = useJobActions(() => job)
const {
cancelAction,
canCancelJob,
runCancelJob,
deleteAction,
canDeleteJob,
runDeleteJob
} = useJobActions(() => job)

const showActionButton = computed(
() => canCancelJob.value || canDeleteJob.value
)
const activeAction = computed(() =>
canCancelJob.value ? cancelAction : deleteAction
)
const runActiveAction = () => {
if (canCancelJob.value) {
runCancelJob()
} else if (canDeleteJob.value) {
runDeleteJob()
}
}

const { progressBarPrimaryClass, hasProgressPercent, progressPercentStyle } =
useProgressBarBackground()
Expand Down