import { foremanUrl } from 'foremanReact/common/helpers';
import { sprintf, translate as __ } from 'foremanReact/common/I18n';
import PropTypes from 'prop-types';
import React, { useState } from 'react';
import {
Dropdown,
DropdownItem,
BadgeToggle,
Tooltip,
} from '@patternfly/react-core';
import { Icon } from 'patternfly-react';
import { BrowserRouter, Link } from 'react-router-dom';
import './styles.scss';
const createKatelloRepoLink = (repo, sccProductId) => {
const url = foremanUrl(
`/products/${sccProductId}/repositories/${repo.katello_root_repository_id}`
);
return (
{repo.name}
);
};
const createRepoDropDownItem = (repo, sccProductId) => (
) : (
)
) : (
)
}
>
{repo.katello_root_repository_id !== null
? createKatelloRepoLink(repo, sccProductId)
: repo.name}
);
const SCCRepoView = ({ sccRepos, sccProductId }) => {
const [isOpen, setIsOpen] = useState(false);
const onToggle = (toggle) => {
setIsOpen(toggle);
};
const onFocus = () => {
const element = document.getElementById(
sprintf('scc-repo-show-toggle-id-%s', sccProductId)
);
element.focus();
};
const onSelect = (event) => {
setIsOpen(!isOpen);
onFocus();
};
const dropdownItems = sccRepos.map((repo) =>
createRepoDropDownItem(repo, sccProductId)
);
return (
{sprintf(
__('Repositories (%s/%s)'),
sccRepos.filter((r) => r.katello_root_repository_id !== null)
.length,
sccRepos.length
)}
}
isOpen={isOpen}
dropdownItems={dropdownItems}
/>
);
};
SCCRepoView.propTypes = {
sccRepos: PropTypes.array,
sccProductId: PropTypes.number,
};
SCCRepoView.defaultProps = {
sccRepos: undefined,
sccProductId: undefined,
};
export default SCCRepoView;