Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show failed job as "green" in active tab #296

Merged
merged 1 commit into from
Jun 12, 2021
Merged
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
3 changes: 1 addition & 2 deletions packages/ui/src/components/JobCard/Details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Button } from '../Button/Button';
import s from './Details.module.css';
import { DetailsContent } from './DetailsContent/DetailsContent';
import { AppJob, Status } from '@bull-board/api/typings/app';
import { STATUSES } from '@bull-board/api/dist/src/constants/statuses';

interface DetailsProps {
job: AppJob;
Expand All @@ -13,7 +12,7 @@ interface DetailsProps {
}

export const Details = ({ status, job, actions }: DetailsProps) => {
const { tabs, selectedTab } = useDetailsTabs(job.isFailed ? STATUSES.failed : status);
const { tabs, selectedTab } = useDetailsTabs(status, job.isFailed);

if (tabs.length === 0) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/JobCard/JobCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const JobCard = ({ job, status, actions, readOnlyMode }: JobCardProps) =>
{typeof job.progress === 'number' && (
<Progress
percentage={job.progress}
status={job.isFailed ? STATUSES.failed : status}
status={job.isFailed && status !== STATUSES.active ? STATUSES.failed : status}
className={s.progress}
/>
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/JobCard/Timeline/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const Timeline = function Timeline({ job, status }: { job: AppJob; status
includeSeconds: true,
})}
</small>
<small>{job.isFailed ? 'Failed' : 'Finished'} at</small>
<small>{job.isFailed && status !== STATUSES.active ? 'Failed' : 'Finished'} at</small>
<time>{formatDate(job.finishedOn)}</time>
</li>
)}
Expand Down
11 changes: 9 additions & 2 deletions packages/ui/src/hooks/useDetailsTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ const regularItems = ['Data', 'Options', 'Logs'] as const;

export type TabsType = typeof regularItems[number] | 'Error';

export function useDetailsTabs(currentStatus: Status) {
export function useDetailsTabs(currentStatus: Status, isJobFailed: boolean) {
const [tabs, updateTabs] = useState<TabsType[]>([]);
const [selectedTabIdx, setSelectedTabIdx] = useState(0);
const selectedTab = tabs[selectedTabIdx];

useEffect(() => {
updateTabs(currentStatus === STATUSES.failed ? ['Error', ...regularItems] : [...regularItems]);
const nextState: TabsType[] =
currentStatus === STATUSES.failed
? ['Error', ...regularItems]
: isJobFailed
? [...regularItems, 'Error']
: [...regularItems];

updateTabs(nextState);
}, [currentStatus]);

return {
Expand Down