diff --git a/src/components/misc/ProgressBar.tsx b/src/components/misc/ProgressBar.tsx index b6d2c16..51578bd 100644 --- a/src/components/misc/ProgressBar.tsx +++ b/src/components/misc/ProgressBar.tsx @@ -224,6 +224,52 @@ const jobNames = [ 'carbon', ] as const; +interface JobListItemProps { + job: LoadingJob; + showJobDocs: (name: string) => void; + showErrorModal: (name: string, state: LoadingState, timeTaken: number | undefined, error: string, isInfo?: boolean) => void; + barColors: Record; +} + +const getStatusEmoji = (state: LoadingState): string => { + switch (state) { + case 'success': + return 'βœ…'; + case 'loading': + return 'πŸ”„'; + case 'error': + return '❌'; + case 'timed-out': + return '⏸️'; + case 'skipped': + return '⏭️'; + default: + return '❓'; + } +}; + +const JobListItem: React.FC = ({ job, showJobDocs, showErrorModal, barColors }) => { + const { name, state, timeTaken, retry, error } = job; + const actionButton = retry && state !== 'success' && state !== 'loading' ? + ↻ Retry : null; + + const showModalButton = error && ['error', 'timed-out', 'skipped'].includes(state) && + showErrorModal(name, state, timeTaken, error, state === 'skipped')}> + {state === 'timed-out' ? 'β–  Show Timeout Reason' : 'β–  Show Error'} + ; + + return ( +
  • + showJobDocs(name)}>{getStatusEmoji(state)} {name} + ({state}). + {timeTaken && state !== 'loading' ? ` Took ${timeTaken} ms` : ''} + {actionButton} + {showModalButton} +
  • + ); +}; + + export const initialJobs = jobNames.map((job: string) => { return { name: job, @@ -239,9 +285,9 @@ export const calculateLoadingStatePercentages = (loadingJobs: LoadingJob[]): Rec const stateCount: Record = { 'success': 0, 'loading': 0, - 'skipped': 0, - 'error': 0, 'timed-out': 0, + 'error': 0, + 'skipped': 0, }; // Count the number of each state @@ -253,9 +299,9 @@ export const calculateLoadingStatePercentages = (loadingJobs: LoadingJob[]): Rec const statePercentage: Record = { 'success': (stateCount['success'] / totalJobs) * 100, 'loading': (stateCount['loading'] / totalJobs) * 100, - 'skipped': (stateCount['skipped'] / totalJobs) * 100, - 'error': (stateCount['error'] / totalJobs) * 100, 'timed-out': (stateCount['timed-out'] / totalJobs) * 100, + 'error': (stateCount['error'] / totalJobs) * 100, + 'skipped': (stateCount['skipped'] / totalJobs) * 100, }; return statePercentage; @@ -353,26 +399,9 @@ const ProgressLoader = (props: { loadStatus: LoadingJob[], showModal: (err: Reac const barColors: Record = { 'success': isDone ? makeBarColor(colors.primary) : makeBarColor(colors.success), 'loading': makeBarColor(colors.info), - 'skipped': makeBarColor(colors.warning), 'error': makeBarColor(colors.danger), - 'timed-out': makeBarColor(colors.neutral), - }; - - const getStatusEmoji = (state: LoadingState): string => { - switch (state) { - case 'success': - return 'βœ…'; - case 'loading': - return 'πŸ”„'; - case 'skipped': - return '⏭️'; - case 'error': - return '❌'; - case 'timed-out': - return '⏸️'; - default: - return '❓'; - } + 'timed-out': makeBarColor(colors.warning), + 'skipped': makeBarColor(colors.neutral), }; const showErrorModal = (name: string, state: LoadingState, timeTaken: number | undefined, error: string, isInfo?: boolean) => { @@ -416,20 +445,9 @@ const ProgressLoader = (props: { loadStatus: LoadingJob[], showModal: (err: Reac
    Show Details
      - { - loadStatus.map(({ name, state, timeTaken, retry, error }: LoadingJob) => { - return ( -
    • - props.showJobDocs(name)}>{getStatusEmoji(state)} {name} - ({state}). - {(timeTaken && state !== 'loading') ? ` Took ${timeTaken} ms` : '' } - { (retry && state !== 'success' && state !== 'loading') && ↻ Retry } - { (error && state === 'error') && showErrorModal(name, state, timeTaken, error)}>β–  Show Error } - { (error && state === 'skipped') && showErrorModal(name, state, timeTaken, error, true)}>β–  Show Reason } -
    • - ); - }) - } + {loadStatus.map((job: LoadingJob) => ( + + ))}
    { loadStatus.filter((val: LoadingJob) => val.state === 'error').length > 0 &&