import React, { useState, useCallback } from 'react'; import { useSelector } from 'react-redux'; import { TableVariant, Thead, Tbody, Tr, Th, Td } from '@patternfly/react-table'; import { translate as __ } from 'foremanReact/common/I18n'; import PropTypes from 'prop-types'; import { selectRepositoryContentDetails, selectRepositoryContentDetailsError, selectRepositoryContentDetailsStatus, } from '../ContentSelectors'; import contentConfig from '../ContentConfig'; import { getRepositoryContentDetails } from '../ContentActions'; import TableWrapper from '../../../components/Table/TableWrapper'; /* eslint-disable react/no-array-index-key */ const ContentRepositories = ({ contentType, id, tabKey }) => { const status = useSelector(selectRepositoryContentDetailsStatus); const response = useSelector(selectRepositoryContentDetails); const error = useSelector(selectRepositoryContentDetailsError); const [searchQuery, updateSearchQuery] = useState(''); const { results, ...metadata } = response; const config = contentConfig.find(type => type.names.pluralLabel === contentType); const typeSingularLabel = config.names.singularLabel; const { columnHeaders } = config.tabs.find(header => header.tabKey === tabKey); const emptyContentTitle = __("You currently don't have any repositories associated with this content."); const emptyContentBody = __('Please add some repositories.'); const emptySearchTitle = __('No matching repositories found'); const emptySearchBody = __('Try changing your search settings.'); return ( getRepositoryContentDetails(typeSingularLabel, id, params), [typeSingularLabel, id], )} > {columnHeaders.map(col => {col.title})} {results?.map((details, idx) => ( {columnHeaders.map((col, index) => {col.getProperty(details, typeSingularLabel)}) } )) } ); }; export default ContentRepositories; ContentRepositories.propTypes = { contentType: PropTypes.string.isRequired, id: PropTypes.number.isRequired, tabKey: PropTypes.string.isRequired, };