Skip to content

Commit

Permalink
Show percentage when progress is an object (#828)
Browse files Browse the repository at this point in the history
* show percentage with progress as an object

* Modified the object to {progress?: number}, removed type cast, refactored function to a calculated value.
  • Loading branch information
difagume authored Oct 9, 2024
1 parent 675cbb3 commit 352ca02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
20 changes: 9 additions & 11 deletions packages/ui/src/components/JobCard/JobCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,15 @@ export const JobCard = ({
<div className={s.content}>
<Details status={status} job={job} actions={actions} />

{typeof job.progress === 'number' && (
<Progress
percentage={job.progress}
status={
job.isFailed && !greenStatuses.includes(status as any)
? STATUSES.failed
: status
}
className={s.progress}
/>
)}
<Progress
progress={job.progress}
status={
job.isFailed && !greenStatuses.includes(status as any)
? STATUSES.failed
: status
}
className={s.progress}
/>
</div>
</div>
</div>
Expand Down
8 changes: 6 additions & 2 deletions packages/ui/src/components/JobCard/Progress/Progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ import { Status } from '@bull-board/api/typings/app';
import { STATUSES } from '@bull-board/api/src/constants/statuses';

interface ProgressProps {
percentage: number;
progress: number | { progress?: number };
strokeWidth?: number;
status: Status;
className?: string;
}

export const Progress = ({ percentage, status, className, strokeWidth = 6 }: ProgressProps) => {
export const Progress = ({ progress, status, className, strokeWidth = 6 }: ProgressProps) => {
const commonProps = {
cx: '50%',
cy: '50%',
r: `calc(50% - ${strokeWidth / 2}px)`,
strokeWidth,
['transform-origin']: 'center',
};

const percentage = typeof progress === 'number' ? progress : progress.progress ?? null;
if(!percentage) return null

return (
<svg className={cn(s.progress, className)} width="100%" height="100%">
<circle stroke="#E5E7EB" {...commonProps} />
Expand Down

0 comments on commit 352ca02

Please sign in to comment.