refactor: use isActiveJobState instead of duplicated cancellableStates (#8572)

## Summary

Eliminates code duplication by replacing local `cancellableStates`
arrays with the centralized `isActiveJobState` utility function.

## Changes

- Remove duplicated `cancellableStates: JobState[] = ['pending',
'initialization', 'running']` from:
  - `src/composables/queue/useJobActions.ts`
  - `src/storybook/mocks/useJobActions.ts`
- Import and use `isActiveJobState` from `src/utils/queueUtil.ts`
instead

## Testing

- Typecheck passes
- Lint passes
- Related queue tests pass

Fixes #7947

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8572-refactor-use-isActiveJobState-instead-of-duplicated-cancellableStates-2fc6d73d365081f89decfc869fa952a0)
by [Unito](https://www.unito.io)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
  * Internal code improvements to simplify job state management logic.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Christian Byrne
2026-02-03 15:49:11 -08:00
committed by GitHub
parent 67107d6f56
commit 4b43eb5fff
2 changed files with 4 additions and 13 deletions

View File

@@ -5,7 +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 { JobState } from '@/types/queue'
import { isActiveJobState } from '@/utils/queueUtil'
export type JobAction = {
icon: string
@@ -13,8 +13,6 @@ export type JobAction = {
variant: 'destructive' | 'secondary' | 'textonly'
}
const CANCELLABLE_STATES: JobState[] = ['pending', 'initialization', 'running']
export function useJobActions(
job: MaybeRefOrGetter<JobListItem | null | undefined>
) {
@@ -36,10 +34,7 @@ export function useJobActions(
return false
}
return (
currentJob.showClear !== false &&
CANCELLABLE_STATES.includes(currentJob.state)
)
return currentJob.showClear !== false && isActiveJobState(currentJob.state)
})
const runCancelJob = wrapWithErrorHandlingAsync(async () => {

View File

@@ -3,10 +3,9 @@ import type { MaybeRefOrGetter } from 'vue'
import type { JobAction } from '../../composables/queue/useJobActions'
import type { JobListItem } from '../../composables/queue/useJobList'
import type { JobState } from '../../types/queue'
import { isActiveJobState } from '../../utils/queueUtil'
const actionsByJobId = ref<Record<string, JobAction[]>>({})
const cancellableStates: JobState[] = ['pending', 'initialization', 'running']
const cancelAction: JobAction = {
icon: 'icon-[lucide--x]',
label: 'Cancel',
@@ -33,10 +32,7 @@ export function useJobActions(
return configuredActions.length > 0
}
return (
currentJob.showClear !== false &&
cancellableStates.includes(currentJob.state)
)
return currentJob.showClear !== false && isActiveJobState(currentJob.state)
})
async function runCancelJob() {