import React from 'react'; import { useDispatch } from 'react-redux'; import PropTypes from 'prop-types'; import { TableComposable, Thead, Tbody, Tr, Th, Td, } from '@patternfly/react-table'; import { translate as __ } from 'foremanReact/common/I18n'; import * as diffModalActions from 'foremanReact/components/ConfigReports/DiffModal/DiffModalActions'; import DiffModal from 'foremanReact/components/ConfigReports/DiffModal'; import EmptyLogsRow from './Components/EmptyLogsRow'; import { msgLevelClasses } from './helpers'; const PuppetLogs = ({ logs, onClear }) => { const dispatch = useDispatch(); const showDiff = (e, diff, title) => { e.preventDefault(); dispatch(diffModalActions.createDiff(diff, title)); }; return ( <> {__('Level')} {__('Resource')} {__('Message')} {logs.map((log, i) => ( {log[0]} {log[1]} {log[2].startsWith('\n---') ? ( showDiff(e, log[2], /File\[(.*?)\]/.exec(log[1])[1]) } > {__('Show Diff')} ) : ( {log[2]} )} ))} {logs.length === 0 ? ( ) : null} > ); }; PuppetLogs.propTypes = { logs: PropTypes.array.isRequired, onClear: PropTypes.func.isRequired, }; export default PuppetLogs;