|
| 1 | +import { ButtonPrimary, Icon } from '@terra-ui-packages/components'; |
| 2 | +import { TooltipTrigger } from '@terra-ui-packages/components'; |
| 3 | +import React from 'react'; |
| 4 | +import { PipelineRunResponse } from 'src/libs/ajax/teaspoons/teaspoons-models'; |
| 5 | +import colors from 'src/libs/colors'; |
| 6 | +import { usePipelineDetails } from 'src/pages/scientificServices/pipelines/hooks/usePipelineDetails'; |
| 7 | +import { PipelineWidgetContainer } from 'src/pages/scientificServices/pipelines/tabs/run/widgets/PipelineWidgetContainer'; |
| 8 | + |
| 9 | +interface JobMetricsProps { |
| 10 | + pipelineRunResult: PipelineRunResponse; |
| 11 | +} |
| 12 | + |
| 13 | +// Mock file sizes for demonstration |
| 14 | +const MOCK_METRICS: Record<string, string> = { |
| 15 | + 'Total number of contigs processed': '2', |
| 16 | + 'Total number of variants in raw input': '65234', |
| 17 | + 'Total number of variants in filtered input': '64295', |
| 18 | + 'Percent input variants passing filtering': '98.6%', |
| 19 | + 'Total number of filtered variants matching reference panel': '63696', |
| 20 | + 'Percent filtered variants matching reference panel': '99.1%', |
| 21 | +}; |
| 22 | + |
| 23 | +const InfoItem = ({ label, value }: { label: string; value: React.ReactNode }) => ( |
| 24 | + <div> |
| 25 | + <div style={{ marginBottom: '0.5rem', fontWeight: 500 }}> |
| 26 | + <TooltipTrigger content='Here is a full description for the input'> |
| 27 | + <span>{label}</span> |
| 28 | + </TooltipTrigger> |
| 29 | + </div> |
| 30 | + <div style={{ color: colors.dark(), wordBreak: 'break-all' }}>{value}</div> |
| 31 | + </div> |
| 32 | +); |
| 33 | + |
| 34 | +const OutputItem = ({ label, url, fileSize }: { label: string; url: string; fileSize: string }) => { |
| 35 | + return ( |
| 36 | + <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}> |
| 37 | + <div style={{ flex: 1 }}> |
| 38 | + <div style={{ marginBottom: '0.5rem', fontWeight: 500 }}>{label}</div> |
| 39 | + <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}> |
| 40 | + <span>{fileSize}</span> |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + <ButtonPrimary |
| 44 | + onClick={() => { |
| 45 | + console.log(url); |
| 46 | + }} |
| 47 | + style={{ |
| 48 | + display: 'flex', |
| 49 | + alignItems: 'center', |
| 50 | + padding: '0.75rem', |
| 51 | + gap: '0.25rem', |
| 52 | + borderRadius: '4px', |
| 53 | + cursor: 'pointer', |
| 54 | + marginLeft: '1rem', |
| 55 | + }} |
| 56 | + > |
| 57 | + <Icon icon='download' size={16} /> |
| 58 | + </ButtonPrimary> |
| 59 | + </div> |
| 60 | + ); |
| 61 | +}; |
| 62 | + |
| 63 | +export const JobMetrics = ({ pipelineRunResult }: JobMetricsProps) => { |
| 64 | + const { pipelineDetails, isLoading } = usePipelineDetails( |
| 65 | + pipelineRunResult.pipelineRunReport.pipelineName, |
| 66 | + pipelineRunResult.pipelineRunReport.pipelineVersion |
| 67 | + ); |
| 68 | + |
| 69 | + const hasOutputs = |
| 70 | + pipelineRunResult.pipelineRunReport.outputs && Object.keys(pipelineRunResult.pipelineRunReport.outputs).length > 0; |
| 71 | + |
| 72 | + return ( |
| 73 | + <PipelineWidgetContainer title='Metrics' border='1px solid #d7d9dc' showIcon={false}> |
| 74 | + {isLoading ? ( |
| 75 | + <div style={{ color: colors.dark(0.6) }}>Loading...</div> |
| 76 | + ) : ( |
| 77 | + <div style={{ display: 'flex', gap: '2rem', alignItems: 'center' }}> |
| 78 | + {/* Metrics Column */} |
| 79 | + <div style={{ flex: 1 }}> |
| 80 | + <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: '1.5rem' }}> |
| 81 | + {Object.entries(MOCK_METRICS).map(([label, value]) => ( |
| 82 | + <InfoItem key={label} label={label} value={value} /> |
| 83 | + ))} |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + )} |
| 88 | + </PipelineWidgetContainer> |
| 89 | + ); |
| 90 | +}; |
0 commit comments