import { DownloadOutlined } from '@ant-design/icons'; import { Button, message, Modal, Typography } from 'antd'; import React, { useEffect, useState } from 'react'; import styled from 'styled-components'; import { useGetIngestionExecutionRequestQuery } from '../../../graphql/ingestion.generated'; import { ANTD_GRAY } from '../../entity/shared/constants'; import { downloadFile } from '../../search/utils/csvUtils'; import { Message } from '../../shared/Message'; import IngestedAssets from './IngestedAssets'; import { getExecutionRequestStatusDisplayColor, getExecutionRequestStatusDisplayText, getExecutionRequestStatusIcon, SUCCESS, } from './utils'; const StyledTitle = styled(Typography.Title)` padding: 0px; margin: 0px; `; const Section = styled.div` display: flex; flex-direction: column; padding-bottom: 12px; `; const SectionHeader = styled(Typography.Title)` &&&& { padding: 0px; margin: 0px; margin-bottom: 12px; } `; const SectionSubHeader = styled.div` display: flex; justify-content: space-between; align-items: center; `; const SubHeaderParagraph = styled(Typography.Paragraph)` margin-bottom: 0px; `; const HeaderSection = styled.div``; const StatusSection = styled.div` border-bottom: 1px solid ${ANTD_GRAY[4]}; padding: 16px; padding-left: 30px; padding-right: 30px; `; const ResultText = styled.div` margin-bottom: 4px; `; const IngestedAssetsSection = styled.div` border-bottom: 1px solid ${ANTD_GRAY[4]}; padding: 16px; padding-left: 30px; padding-right: 30px; `; const LogsSection = styled.div` padding-top: 16px; padding-left: 30px; padding-right: 30px; `; const ShowMoreButton = styled(Button)` padding: 0px; `; const modalStyle = { top: 100, }; const modalBodyStyle = { padding: 0, }; type Props = { urn: string; visible: boolean; onClose: () => void; }; export const ExecutionDetailsModal = ({ urn, visible, onClose }: Props) => { const [showExpandedLogs, setShowExpandedLogs] = useState(true); const { data, loading, error } = useGetIngestionExecutionRequestQuery({ variables: { urn } }); const output = data?.executionRequest?.result?.report || 'No output found.'; useEffect(() => { if (output.length > 100) { setShowExpandedLogs(false); } }, [output, setShowExpandedLogs]); const downloadLogs = () => { downloadFile(output, `exec-${urn}.log`); }; const logs = (showExpandedLogs && output) || output.slice(0, 100); const result = data?.executionRequest?.result?.status; const ResultIcon = result && getExecutionRequestStatusIcon(result); const resultColor = result && getExecutionRequestStatusDisplayColor(result); const resultText = result && ( {ResultIcon && } {getExecutionRequestStatusDisplayText(result)} ); const resultSummaryText = (result && ( Ingestion {result === SUCCESS ? 'successfully completed' : 'completed with errors'}. )) || undefined; return ( Close} style={modalStyle} bodyStyle={modalBodyStyle} title={ Ingestion Run Details } visible={visible} onCancel={onClose} > {!data && loading && } {error && message.error('Failed to load execution details :(')}
Status {resultText} {resultSummaryText} {result === SUCCESS && ( {data?.executionRequest?.id && } )} Logs View logs that were collected during the ingestion run.
{`${logs}${!showExpandedLogs && '...'}`}
{!showExpandedLogs && ( setShowExpandedLogs(true)}> Show More )}
); };