import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { Alert, AlertActionCloseButton, Button } from '@patternfly/react-core'; import { TableComposable, Thead, Tbody, Tr, Th, Td, } from '@patternfly/react-table'; import { translate as __ } from 'foremanReact/common/I18n'; import { useForemanModal } from 'foremanReact/components/ForemanModal/ForemanModalHooks'; import RawMsgModal from './Components/RawMsgModal'; import EmptyLogsRow from './Components/EmptyLogsRow'; import { msgLevelClasses } from './helpers'; import { RAW_MSG_MODAL_ID } from '../../../constants'; const AnsibleLogs = ({ logs, checkMode, onClear }) => { const [alertVisibility, setAlertVisibility] = useState(true); const [selectedMsg, setSelectedMsg] = useState(0); const { setModalOpen: setRawModalOpen } = useForemanModal({ id: RAW_MSG_MODAL_ID, }); const rawMsg = idx => { const onClick = () => { setSelectedMsg(idx); setRawModalOpen(); }; return ( ); }; return ( <> {checkMode && alertVisibility ? ( setAlertVisibility(false)} /> } > {__('Notice that ansible roles run in check mode.')} ) : null} {__('Level')} {__('Task')} {__('Message')} {__('Raw data')} {logs.map((log, idx) => ( {log.level} {log.task.name} {Array.isArray(log.friendlyMessage) ? ( ) : ( {log.friendlyMessage} )} {rawMsg(idx)} ))} {logs.length === 0 ? ( ) : null} ); }; AnsibleLogs.propTypes = { logs: PropTypes.array.isRequired, onClear: PropTypes.func.isRequired, checkMode: PropTypes.bool, }; AnsibleLogs.defaultProps = { checkMode: false, }; export default AnsibleLogs;