Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #38160 - Update hosts link to new hosts URL #11296

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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