diff --git a/libs/ui-lib/lib/common/components/clusterConfiguration/DownloadIso.tsx b/libs/ui-lib/lib/common/components/clusterConfiguration/DownloadIso.tsx index ad65381cf7..ec366b2338 100644 --- a/libs/ui-lib/lib/common/components/clusterConfiguration/DownloadIso.tsx +++ b/libs/ui-lib/lib/common/components/clusterConfiguration/DownloadIso.tsx @@ -26,6 +26,7 @@ export type DownloadISOProps = { onClose: () => void; onReset?: () => void; docVersion?: string; + updateTagsForCiscoIntersight?: () => void; }; const DownloadIso = ({ @@ -36,9 +37,16 @@ const DownloadIso = ({ hasDHCP, isSNO = false, docVersion, + updateTagsForCiscoIntersight, }: DownloadISOProps) => { const wgetCommand = `wget -O ${fileName} '${downloadUrl || ''}'`; const { t } = useTranslation(); + + const openCiscoIntersightHostsLink = (downloadUrl: string) => { + updateTagsForCiscoIntersight ? updateTagsForCiscoIntersight() : ''; + window.open(getCiscoIntersightLink(downloadUrl), '_blank', 'noopener'); + }; + return ( <> @@ -66,7 +74,7 @@ const DownloadIso = ({ icon={} iconPosition="right" isInline - onClick={() => window.open(getCiscoIntersightLink(downloadUrl), '_blank', 'noopener')} + onClick={() => openCiscoIntersightHostsLink(downloadUrl)} > {t('ai:Add hosts from Cisco Intersight')} diff --git a/libs/ui-lib/lib/common/config/constants.ts b/libs/ui-lib/lib/common/config/constants.ts index cf8e39a406..ef744fed5b 100644 --- a/libs/ui-lib/lib/common/config/constants.ts +++ b/libs/ui-lib/lib/common/config/constants.ts @@ -377,3 +377,5 @@ export const operatorLabels = ( export const AI_UI_TAG = 'ui_ocm'; export const AI_ASSISTED_MIGRATION_TAG = 'assisted_migration'; + +export const AI_CISCO_INTERSIGHT_TAG = 'cisco_intersight_ui'; diff --git a/libs/ui-lib/lib/ocm/components/clusterConfiguration/DiscoveryImageModal.tsx b/libs/ui-lib/lib/ocm/components/clusterConfiguration/DiscoveryImageModal.tsx index 58afd3285e..cb037f9583 100644 --- a/libs/ui-lib/lib/ocm/components/clusterConfiguration/DiscoveryImageModal.tsx +++ b/libs/ui-lib/lib/ocm/components/clusterConfiguration/DiscoveryImageModal.tsx @@ -1,7 +1,14 @@ import React from 'react'; import { Button, ButtonVariant, Modal, ModalVariant } from '@patternfly/react-core'; import { pluralize } from 'humanize-plus'; -import { CpuArchitecture, DownloadIso, ErrorState, isSNO, ToolbarButton } from '../../../common'; +import { + AI_CISCO_INTERSIGHT_TAG, + CpuArchitecture, + DownloadIso, + ErrorState, + isSNO, + ToolbarButton, +} from '../../../common'; import DiscoveryImageForm from './DiscoveryImageForm'; import { useModalDialogsContext } from '../hosts/ModalDialogsContext'; import useInfraEnvImageUrl from '../../hooks/useInfraEnvImageUrl'; @@ -9,6 +16,9 @@ import useInfraEnvIpxeImageUrl from '../../hooks/useInfraEnvIpxeImageUrl'; import DownloadIpxeScript from '../../../common/components/clusterConfiguration/DownloadIpxeScript'; import './DiscoveryImageModal.css'; import { Cluster } from '@openshift-assisted/types/assisted-installer-service'; +import { ClustersService } from '../../services'; +import { useDispatch } from 'react-redux'; +import { updateCluster } from '../../store/slices/current-cluster/slice'; type DiscoveryImageModalButtonProps = { ButtonComponent?: typeof Button | typeof ToolbarButton; @@ -49,6 +59,8 @@ export const DiscoveryImageModal = () => { const { getIsoImageUrl } = useInfraEnvImageUrl(); const { getIpxeImageUrl } = useInfraEnvIpxeImageUrl(); + const dispatch = useDispatch(); + const onImageReady = React.useCallback(async () => { // We need to retrieve the Iso for the only infraEnv on Day1, hence we don't specify the architecture const { url, error } = await getIsoImageUrl(cluster.id, CpuArchitecture.USE_DAY1_ARCHITECTURE); @@ -73,6 +85,16 @@ export const DiscoveryImageModal = () => { setIpxeSelected(true); }, []); + const updateTagsForCiscoIntersight = async (cluster: Cluster) => { + try { + const { data: updatedCluster } = await ClustersService.update(cluster.id, cluster.tags, { + tags: AI_CISCO_INTERSIGHT_TAG, + }); + + dispatch(updateCluster(updatedCluster)); + } catch (e) {} + }; + if (!cluster) { return null; } @@ -98,6 +120,7 @@ export const DiscoveryImageModal = () => { isSNO={isSNOCluster} onReset={onReset} onClose={close} + updateTagsForCiscoIntersight={() => updateTagsForCiscoIntersight(cluster)} /> ) : ipxeDownloadUrl ? ( []; if (tags.includes(AI_UI_TAG)) { - delete params.tags; + if (params.tags && params.tags.includes(AI_CISCO_INTERSIGHT_TAG)) { + tags?.push(AI_CISCO_INTERSIGHT_TAG); + params.tags = tags?.join(','); + } else { + delete params.tags; + } } else { tags?.push(AI_UI_TAG); params.tags = tags?.join(',');