import React from 'react'; import PropTypes from 'prop-types'; import { TableComposable, Thead, Tbody, Tr, Th, Td, } from '@patternfly/react-table'; import { EmptyState, EmptyStateIcon, Spinner, Title, Grid, } from '@patternfly/react-core'; import { SearchIcon, ExclamationCircleIcon } from '@patternfly/react-icons'; import { STATUS } from 'foremanReact/constants'; import { translate as __ } from 'foremanReact/common/I18n'; import { getColumns } from './helpers'; const ReportsTable = ({ reports, status, fetchReports }) => { const columns = getColumns(fetchReports); let tableBody = null; let tableHead = null; let emptyState = null; if (status === STATUS.RESOLVED) { if (reports.length) { tableHead = ( {columns.map(({ width, title }, columnIndex) => ( {title} ))} ); tableBody = ( {reports.map((row, rowIndex) => ( {columns.map(({ title, formatter }, cellIndex) => ( {formatter(row)} ))} ))} ); } else { emptyState = ( {__('No results found')} ); } } else if (status === STATUS.FAILURE) { emptyState = ( } /> {__('Something went wrong')} ); } else if (status === STATUS.PENDING) { emptyState = ( {__('Loading')} ); } return ( {tableHead} {tableBody} {emptyState} ); }; ReportsTable.propTypes = { reports: PropTypes.array, status: PropTypes.string, fetchReports: PropTypes.func.isRequired, }; ReportsTable.defaultProps = { reports: [], status: null, }; export default ReportsTable;