diff --git a/packages/ui/src/components/JobCard/Details/Details.tsx b/packages/ui/src/components/JobCard/Details/Details.tsx index 346ae69a..4dffcddf 100644 --- a/packages/ui/src/components/JobCard/Details/Details.tsx +++ b/packages/ui/src/components/JobCard/Details/Details.tsx @@ -13,7 +13,7 @@ interface DetailsProps { } export const Details = ({ status, job, actions }: DetailsProps) => { - const { tabs, selectedTab } = useDetailsTabs(status, job.isFailed); + const { tabs, selectedTab } = useDetailsTabs(status); const { t } = useTranslation(); if (tabs.length === 0) { diff --git a/packages/ui/src/hooks/useDetailsTabs.tsx b/packages/ui/src/hooks/useDetailsTabs.tsx index 289050c9..8c7a48aa 100644 --- a/packages/ui/src/hooks/useDetailsTabs.tsx +++ b/packages/ui/src/hooks/useDetailsTabs.tsx @@ -1,13 +1,13 @@ -import { useEffect, useState } from 'react'; -import { Status } from '@bull-board/api/typings/app'; import { STATUSES } from '@bull-board/api/src/constants/statuses'; +import { Status } from '@bull-board/api/typings/app'; +import { useEffect, useState } from 'react'; import { useSettingsStore } from './useSettings'; export const availableJobTabs = ['Data', 'Options', 'Logs', 'Error'] as const; export type TabsType = (typeof availableJobTabs)[number]; -export function useDetailsTabs(currentStatus: Status, isJobFailed: boolean) { +export function useDetailsTabs(currentStatus: Status) { const [tabs, updateTabs] = useState([]); const { defaultJobTab } = useSettingsStore(); @@ -16,18 +16,18 @@ export function useDetailsTabs(currentStatus: Status, isJobFailed: boolean) { ); useEffect(() => { - let nextState: TabsType[] = availableJobTabs.filter((tab) => tab !== 'Error'); - if (isJobFailed) { - nextState = [...nextState, 'Error']; - } else if (currentStatus === STATUSES.failed) { - nextState = ['Error', ...nextState]; + let nextTabs: TabsType[] = availableJobTabs.filter((tab) => tab !== 'Error'); + if (currentStatus === STATUSES.failed) { + nextTabs = ['Error', ...nextTabs]; + } else { + nextTabs = [...nextTabs, 'Error']; } - updateTabs(nextState); + updateTabs(nextTabs); }, [currentStatus]); useEffect(() => { - if (!tabs.includes(defaultJobTab)) { + if (!tabs.includes(defaultJobTab) || currentStatus === STATUSES.failed) { setSelectedTab(tabs[0]); } else { setSelectedTab(defaultJobTab);