Skip to content

Commit

Permalink
fix: failed status should show Error tab at start
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Oct 31, 2024
1 parent c47af53 commit 7cad06e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/ui/src/components/JobCard/Details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions packages/ui/src/hooks/useDetailsTabs.tsx
Original file line number Diff line number Diff line change
@@ -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<TabsType[]>([]);
const { defaultJobTab } = useSettingsStore();

Expand All @@ -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);
Expand Down

0 comments on commit 7cad06e

Please sign in to comment.