Skip to content

Commit

Permalink
Fixes #38160 - Update hosts link to new hosts URL
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanshekar committed Jan 30, 2025
1 parent c988a00 commit eb3a5f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down
14 changes: 11 additions & 3 deletions webpack/scenes/ContentViews/expansions/DetailsExpansion.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -36,7 +44,7 @@ const DetailsExpansion = ({
<div id={`cv-details-expansion-${cvId}`}>
{__('Activation keys: ')}<a aria-label={`activation_keys_link_${cvId}`} href={`/activation_keys?search=content_view_id+%3D+${cvId}`}>{activationKeyCount}</a>
<br />
{__('Hosts: ')}<a aria-label={`host_link_${cvId}`} href={`/hosts?search=content_view_id+%3D+${cvId}`}>{hostCount}</a>
{__('Hosts: ')}<a aria-label={`host_link_${cvId}`} href={hostsPageUrl}>{hostCount}</a>
<br />
{relatedContentViewModal()}
</div>
Expand Down

0 comments on commit eb3a5f9

Please sign in to comment.