From 4b43eb5fffafe281a7183c348634e1583ef904c4 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 3 Feb 2026 15:49:11 -0800 Subject: [PATCH] refactor: use isActiveJobState instead of duplicated cancellableStates (#8572) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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) ## Summary by CodeRabbit * **Refactor** * Internal code improvements to simplify job state management logic. --- src/composables/queue/useJobActions.ts | 9 ++------- src/storybook/mocks/useJobActions.ts | 8 ++------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/composables/queue/useJobActions.ts b/src/composables/queue/useJobActions.ts index 4e664c4c1..65b91c88a 100644 --- a/src/composables/queue/useJobActions.ts +++ b/src/composables/queue/useJobActions.ts @@ -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 ) { @@ -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 () => { diff --git a/src/storybook/mocks/useJobActions.ts b/src/storybook/mocks/useJobActions.ts index b2b823341..7ff122d7d 100644 --- a/src/storybook/mocks/useJobActions.ts +++ b/src/storybook/mocks/useJobActions.ts @@ -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>({}) -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() {