diff --git a/webpack/__mocks__/foremanReact/Root/Context/ForemanContext.js b/webpack/__mocks__/foremanReact/Root/Context/ForemanContext.js index 3ad644d7f80..bff3666e3dd 100644 --- a/webpack/__mocks__/foremanReact/Root/Context/ForemanContext.js +++ b/webpack/__mocks__/foremanReact/Root/Context/ForemanContext.js @@ -1,3 +1,4 @@ // eslint-disable-next-line import/prefer-default-export export const useForemanSettings = () => ({ perPage: 20 }); export const useForemanVersion = () => 'nightly'; +export const useForemanHostsPageUrl = () => '/new/hosts'; diff --git a/webpack/scenes/ContentViews/__tests__/contentViewPage.test.js b/webpack/scenes/ContentViews/__tests__/contentViewPage.test.js index cc6acf9df04..d7c83bd9bca 100644 --- a/webpack/scenes/ContentViews/__tests__/contentViewPage.test.js +++ b/webpack/scenes/ContentViews/__tests__/contentViewPage.test.js @@ -132,7 +132,7 @@ test('Can expand cv and show activation keys and hosts', async (done) => { expect(queryByLabelText('activation_keys_link_2').textContent).toEqual('1'); // Displays hosts link with count - expect(queryByLabelText('host_link_2')).toHaveAttribute('href', '/hosts?search=content_view_id+%3D+2'); + expect(queryByLabelText('host_link_2')).toHaveAttribute('href', '/new/hosts?search=content_view_id%3D2'); expect(queryByLabelText('host_link_2').textContent).toEqual('1'); }); diff --git a/webpack/scenes/ContentViews/expansions/DetailsExpansion.js b/webpack/scenes/ContentViews/expansions/DetailsExpansion.js index 060bdddb944..2e3ef759930 100644 --- a/webpack/scenes/ContentViews/expansions/DetailsExpansion.js +++ b/webpack/scenes/ContentViews/expansions/DetailsExpansion.js @@ -1,14 +1,22 @@ import React from 'react'; import PropTypes from 'prop-types'; import { translate as __ } from 'foremanReact/common/I18n'; +import { useForemanHostsPageUrl } from 'foremanReact/Root/Context/ForemanContext'; import RelatedCompositeContentViewsModal from './RelatedCompositeContentViewsModal'; import RelatedContentViewComponentsModal from './RelatedContentViewComponentsModal'; const DetailsExpansion = ({ cvId, cvName, cvComposite, activationKeys, hosts, relatedCVCount, relatedCompositeCVs, }) => { - const activationKeyCount = activationKeys.length; - const hostCount = hosts.length; + const uniqueActivationKeys = Array.from(new Map(activationKeys.map(activationKey => + [activationKey.id, activationKey])).values()); + const uniqueHosts = Array.from(new Map(hosts.map(host => [host.id, host])).values()); + + const activationKeyCount = uniqueActivationKeys.length; + const hostCount = uniqueHosts.length; + + const baseHostsPageUrl = useForemanHostsPageUrl(); + const hostsPageUrl = `${baseHostsPageUrl}?search=${encodeURIComponent(`content_view_id=${cvId}`)}`; const relatedContentViewModal = () => { if (cvComposite) { @@ -36,7 +44,7 @@ const DetailsExpansion = ({