@@ -24,6 +24,7 @@ import {
2424 ChangeHostnameAction ,
2525 MassChangeHostnameModal ,
2626 TableToolbar ,
27+ LoadingState ,
2728} from '../../../common' ;
2829import { ClusterDeploymentHostDiscoveryTableProps } from '../ClusterDeployment/types' ;
2930import MassApproveAgentModal from '../modals/MassApproveAgentModal' ;
@@ -34,25 +35,47 @@ import { ExpandComponent } from '../Agent/AgentsSelectionTable';
3435import { HostsTableDetailContextProvider } from '../../../common/components/hosts/HostsTableDetailContext' ;
3536import { agentStatus , bmhStatus } from '../helpers/agentStatus' ;
3637import { onAgentChangeHostname } from '../helpers' ;
38+ import {
39+ AgentClusterInstallK8sResource ,
40+ AgentK8sResource ,
41+ BareMetalHostK8sResource ,
42+ } from '../../types' ;
43+ import DeleteHostModal from '../modals/DeleteHostModal' ;
44+ import { useInfraEnvNMStates } from '../../hooks/useInfraEnvNMStates' ;
45+ import { AgentClusterInstallModel } from '../../types/models' ;
46+ import { useParams } from 'react-router-dom-v5-compat' ;
47+ import { useK8sWatchResource } from '../../hooks/useK8sWatchResource' ;
3748
3849const ClusterDeploymentHostDiscoveryTable : React . FC < ClusterDeploymentHostDiscoveryTableProps > = ( {
3950 agents,
4051 bareMetalHosts,
4152 infraEnv,
42- onApprove,
43- onChangeHostname,
44- onChangeBMHHostname,
4553 onEditRole,
4654 onSetInstallationDiskId,
4755 onEditHost,
4856 onEditBMH,
49- onDeleteHost,
5057 width,
5158} ) => {
59+ const { name = '' , namespace = '' } = useParams < { name : string ; namespace : string } > ( ) ;
60+ const [ deleteHost , setDeleteHost ] = React . useState < {
61+ agent ?: AgentK8sResource ;
62+ bmh ?: BareMetalHostK8sResource ;
63+ } > ( ) ;
5264 const [ isDiscoveryHintModalOpen , setDiscoveryHintModalOpen ] = React . useState ( false ) ;
5365 const [ isMassChangeHostOpen , setMassChangeHostOpen ] = React . useState ( false ) ;
5466 const [ isMassApproveOpen , setMassApproveOpen ] = React . useState ( false ) ;
5567 const [ selectedHostIDs , setSelectedHostIDs ] = React . useState < string [ ] > ( [ ] ) ;
68+ const [ nmStates , nmLoaded ] = useInfraEnvNMStates ( infraEnv ) ;
69+ const [ agentClusterInstall , aciLoaded ] = useK8sWatchResource < AgentClusterInstallK8sResource > ( {
70+ groupVersionKind : {
71+ kind : AgentClusterInstallModel . kind ,
72+ version : AgentClusterInstallModel . apiVersion ,
73+ group : AgentClusterInstallModel . apiGroup ,
74+ } ,
75+ name : name ,
76+ namespace : namespace ,
77+ isList : false ,
78+ } ) ;
5679
5780 const { t } = useTranslation ( ) ;
5881 const agentStatuses = agentStatus ( t ) ;
@@ -72,7 +95,7 @@ const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscove
7295 bmhs : bareMetalHosts ,
7396 infraEnv,
7497 } ,
75- { onEditHost, onEditRole, onEditBMH, onDeleteHost, onSetInstallationDiskId } ,
98+ { onEditHost, onEditRole, onEditBMH, onDeleteHost : setDeleteHost , onSetInstallationDiskId } ,
7699 ) ;
77100
78101 const addAll = width && width > 700 ;
@@ -87,7 +110,6 @@ const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscove
87110 bareMetalHosts,
88111 bmhStatuses,
89112 onEditHostname : onEditHost ,
90- onApprove,
91113 wizardStepId : 'hosts-discovery' ,
92114 t,
93115 } ) ,
@@ -107,7 +129,6 @@ const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscove
107129 agentStatuses ,
108130 bmhStatuses ,
109131 onEditHost ,
110- onApprove ,
111132 ] ,
112133 ) ;
113134
@@ -128,6 +149,10 @@ const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscove
128149 const paginationProps = usePagination ( hosts . length ) ;
129150 const itemIDs = hosts . map ( ( h ) => h . id ) ;
130151
152+ if ( ! nmLoaded || aciLoaded ) {
153+ return < LoadingState /> ;
154+ }
155+
131156 return (
132157 < >
133158 < Stack hasGutter >
@@ -171,12 +196,7 @@ const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscove
171196 isOpen = { isMassChangeHostOpen }
172197 hosts = { hosts }
173198 selectedHostIDs = { selectedHostIDs }
174- onChangeHostname = { onAgentChangeHostname (
175- agents ,
176- bareMetalHosts ,
177- onChangeHostname ,
178- onChangeBMHHostname ,
179- ) }
199+ onChangeHostname = { onAgentChangeHostname ( agents , bareMetalHosts ) }
180200 onClose = { ( ) => setMassChangeHostOpen ( false ) }
181201 canChangeHostname = { canChangeHostname ( agents , agentStatuses , bareMetalHosts , t ) }
182202 />
@@ -185,10 +205,17 @@ const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscove
185205 < MassApproveAgentModal
186206 isOpen = { isMassApproveOpen }
187207 agents = { selectedAgents }
188- onApprove = { onApprove }
189208 onClose = { ( ) => setMassApproveOpen ( false ) }
190209 />
191210 ) }
211+ { deleteHost && (
212+ < DeleteHostModal
213+ { ...deleteHost }
214+ onClose = { ( ) => setDeleteHost ( undefined ) }
215+ nmStates = { nmStates }
216+ agentClusterInstall = { agentClusterInstall }
217+ />
218+ ) }
192219 </ >
193220 ) ;
194221} ;
0 commit comments