/* eslint-disable react/no-array-index-key */ import React from 'react'; import PropTypes from 'prop-types'; import { translate as __ } from 'foremanReact/common/I18n'; import { DataList, DataListItem, DataListItemRow, DataListItemCells, DataListCell } from '@patternfly/react-core'; import AdditionalCapsuleContent from './AdditionalCapsuleContent'; import InactiveText from '../ContentViews/components/InactiveText'; import RepoIcon from '../ContentViews/Details/Repositories/RepoIcon'; const ExpandedSmartProxyRepositories = ({ contentCounts, repositories, syncedToCapsule, envId, }) => { const filterDataByEnvId = () => { const filteredData = {}; Object.keys(contentCounts).forEach((key) => { const entry = contentCounts[key]; if (entry.metadata.env_id === envId) { filteredData[key] = entry; } }); return filteredData; }; const envContentCounts = filterDataByEnvId(); const getRepositoryNameById = id => (repositories.find(repo => Number(repo.id) === Number(id) || Number(repo.library_id) === Number(id)) || {}).name; const dataListCellLists = (repoCounts, repo) => { const cellList = []; /* eslint-disable max-len */ cellList.push({getRepositoryNameById(envContentCounts[repo].metadata.library_instance_id)}); cellList.push(); cellList.push({envContentCounts[repo].counts.rpm ? `${envContentCounts[repo].counts.rpm} Packages` : 'N/A'}); cellList.push(); /* eslint-enable max-len */ return cellList; }; const dataListCellListsNotSynced = (repo) => { const cellList = []; /* eslint-disable max-len */ cellList.push({repo.name}); cellList.push(); cellList.push(); cellList.push(); /* eslint-enable max-len */ return cellList; }; if (syncedToCapsule) { return ( {__('Repository')} , {__('Type')}, {__('Packages')}, {__('Additional content')}, ]} /> {Object.keys(envContentCounts).length ? Object.keys(envContentCounts).map((repo, index) => ( )) : ]} /> } ); } return ( {__('Repository')} , {__('Type')}, {__('Packages')}, {__('Additional content')}, ]} /> {repositories.length ? repositories.map((repo, index) => ( )) : ]} /> } ); }; ExpandedSmartProxyRepositories.propTypes = { contentCounts: PropTypes.shape({}), repositories: PropTypes.arrayOf(PropTypes.shape({})), syncedToCapsule: PropTypes.bool, envId: PropTypes.oneOfType([ PropTypes.number, PropTypes.string, // The API can sometimes return strings ]).isRequired, }; ExpandedSmartProxyRepositories.defaultProps = { contentCounts: {}, repositories: [{}], syncedToCapsule: false, }; export default ExpandedSmartProxyRepositories;