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 8307210
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 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
6 changes: 5 additions & 1 deletion webpack/scenes/ContentViews/expansions/DetailsExpansion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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';

Expand All @@ -10,6 +11,9 @@ const DetailsExpansion = ({
const activationKeyCount = activationKeys.length;
const hostCount = hosts.length;

const baseHostsPageUrl = useForemanHostsPageUrl();
const hostsPageUrl = `${baseHostsPageUrl}?search=${encodeURIComponent(`content_view_id=${cvId}`)}`;

const relatedContentViewModal = () => {
if (cvComposite) {
return (
Expand All @@ -36,7 +40,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 8307210

Please sign in to comment.