import React, { useState } from 'react'; import { useSelector, } from 'react-redux'; import PropTypes from 'prop-types'; import { translate as __ } from 'foremanReact/common/I18n'; import { TableVariant, Tr, Th, Tbody, Td, Thead } from '@patternfly/react-table'; import { TableType } from './CVVersionCompareConfig'; import TableWrapper from '../../../../../components/Table/TableWrapper'; import { useTableSort } from '../../../../../components/Table/TableHooks'; const CVVersionCompareTable = ({ tableConfig: { name, responseSelector, statusSelector, autocompleteEndpoint, fetchItems: fetchItemsSorted, columnHeaders, hideSearch, sortConfig, }, versionOne, versionTwo, currentActiveKey, selectedViewBy, }) => { const [searchQuery, updateSearchQuery] = useState(''); const { pfSortParams, apiSortParams, activeSortColumn, activeSortDirection, } = useTableSort({ allColumns: columnHeaders.map(header => header?.title), columnsToSortParams: sortConfig, initialSortColumnName: Object.keys(sortConfig)[0], }); const response = useSelector(responseSelector); const { results, ...metadata } = response; const status = useSelector(statusSelector); const fetchItems = params => fetchItemsSorted({ ...apiSortParams, ...params, }); return ( {columnHeaders.map(({ title }) => ( {title} ))} {results?.map(result => ( {columnHeaders.map(({ getProperty }, colIndex) => // eslint-disable-next-line react/no-array-index-key {getProperty(result)} )} ))} ); }; CVVersionCompareTable.propTypes = { tableConfig: TableType.isRequired, versionOne: PropTypes.string.isRequired, versionTwo: PropTypes.string.isRequired, currentActiveKey: PropTypes.string.isRequired, selectedViewBy: PropTypes.string.isRequired, }; export default CVVersionCompareTable;