@@ -9,62 +9,88 @@ import {
99 Label ,
1010 List ,
1111 ListItemCustom ,
12+ Ui5CustomEvent ,
13+ ListDomRef ,
1214} from '@ui5/webcomponents-react' ;
1315import { ResourceForm } from 'shared/ResourceForm' ;
1416import { getUserDetail } from './helpers' ;
17+ import { ResourceFormWrapperProps } from 'shared/ResourceForm/components/Wrapper' ;
18+ import { ListItemClickEventDetail } from '@ui5/webcomponents/dist/List' ;
1519
1620import './ContextChooser.scss' ;
1721
18- export function ContextChooser ( params ) {
19- const kubeconfig = params . resource ;
22+ type ContextChooserProps = {
23+ resource : Record < string , any > ;
24+ chosenContext : string ;
25+ setChosenContext : ( context : string ) => void ;
26+ } & ResourceFormWrapperProps ;
27+
28+ export function ContextChooser ( {
29+ resource,
30+ chosenContext,
31+ setChosenContext,
32+ ...props
33+ } : ContextChooserProps ) {
2034 const { t } = useTranslation ( ) ;
2135
22- if ( ! Array . isArray ( kubeconfig . contexts ) ) {
36+ if ( ! Array . isArray ( resource ? .contexts ) ) {
2337 return '' ;
2438 }
2539
2640 return (
2741 < div className = "add-cluster__content-container" >
28- < ResourceForm . Wrapper { ...params } >
42+ < ResourceForm . Wrapper resource = { resource } { ...props } >
2943 < Title className = "sap-margin-bottom-small" level = "H5" >
3044 { t ( 'clusters.wizard.provide-context' ) }
3145 </ Title >
3246 < ResourceForm . FormField
3347 required
34- value = { params . chosenContext }
48+ value = { chosenContext }
3549 propertyPath = '$["current-context"]'
3650 label = { t ( 'clusters.wizard.context' ) }
37- validate = { ( value ) => ! ! value }
51+ validate = { ( value : string ) => ! ! value }
3852 input = { ( { setValue } ) => (
3953 < ContextButtons
40- contexts = { kubeconfig . contexts }
41- users = { kubeconfig ?. users }
54+ contexts = { resource ? .contexts }
55+ users = { resource ?. users }
4256 setValue = { setValue }
43- chosenContext = { params . chosenContext }
44- setChosenContext = { params . setChosenContext }
57+ chosenContext = { chosenContext }
58+ setChosenContext = { setChosenContext }
4559 />
4660 ) }
4761 />
4862 </ ResourceForm . Wrapper >
4963 </ div >
5064 ) ;
5165}
66+
67+ type ContextButtonsProps = {
68+ users ?: Array < { name : string ; user : { exec : { args ?: string [ ] } } } > ;
69+ contexts : { name : string } [ ] ;
70+ chosenContext : string ;
71+ setValue : ( context : string ) => void ;
72+ setChosenContext ?: ( context : string ) => void ;
73+ } ;
74+
5275export function ContextButtons ( {
5376 users,
5477 contexts,
55- setValue,
5678 chosenContext,
79+ setValue,
5780 setChosenContext,
58- } ) {
81+ } : ContextButtonsProps ) {
5982 return (
6083 < List
61- onItemClick = { ( e ) => {
62- setValue ( e ?. detail ?. item ?. children [ 0 ] ?. children [ 0 ] . value ) ;
63- if ( setChosenContext )
64- setChosenContext ( e ?. detail ?. item ?. children [ 0 ] ?. children [ 0 ] . value ) ;
84+ onItemClick = { (
85+ e : Ui5CustomEvent < ListDomRef , ListItemClickEventDetail > ,
86+ ) => {
87+ const contextElement = e ?. detail ?. item ?. children ?. [ 0 ]
88+ ?. children ?. [ 0 ] as HTMLInputElement ;
89+ setValue ( contextElement ?. value ) ;
90+ if ( setChosenContext ) setChosenContext ( contextElement ?. value ) ;
6591 } }
6692 >
67- { contexts . map ( ( context ) => {
93+ { contexts ? .map ( ( context ) => {
6894 return (
6995 < ListItemCustom key = { context . name } style = { { } } >
7096 < div >
@@ -89,7 +115,21 @@ export function ContextButtons({
89115 </ List >
90116 ) ;
91117}
92- export function ContextChooserMessage ( { contextState, setValue, onCancel } ) {
118+
119+ type ContextChooserMessageProps = {
120+ contextState ?: {
121+ users ?: Array < { name : string ; user : { exec : { args ?: string [ ] } } } > ;
122+ contexts ?: { name : string } [ ] ;
123+ } ;
124+ setValue : ( context : string ) => void ;
125+ onCancel : ( ) => void ;
126+ } ;
127+
128+ export function ContextChooserMessage ( {
129+ contextState,
130+ setValue,
131+ onCancel,
132+ } : ContextChooserMessageProps ) {
93133 const { t } = useTranslation ( ) ;
94134 const [ chosenContext , setChosenContext ] = useState ( '' ) ;
95135
@@ -118,10 +158,12 @@ export function ContextChooserMessage({ contextState, setValue, onCancel }) {
118158 >
119159 < List
120160 onItemClick = { ( e ) => {
121- setChosenContext ( e ?. detail ?. item ?. children [ 0 ] ?. children [ 0 ] . value ) ;
161+ const contextElement = e ?. detail ?. item ?. children ?. [ 0 ]
162+ ?. children ?. [ 0 ] as HTMLInputElement ;
163+ setChosenContext ( contextElement ?. value ) ;
122164 } }
123165 >
124- { contextState . contexts . map ( ( context ) => (
166+ { contextState ? .contexts ? .map ( ( context ) => (
125167 < ListItemCustom key = { context . name } style = { { } } >
126168 < div >
127169 < RadioButton
@@ -135,8 +177,8 @@ export function ContextChooserMessage({ contextState, setValue, onCancel }) {
135177 />
136178 { contextState ?. users && (
137179 < AuthContextData
138- contextName = { context . name }
139- users = { contextState . users }
180+ contextName = { context ? .name }
181+ users = { contextState ? .users }
140182 />
141183 ) }
142184 </ div >
@@ -147,7 +189,12 @@ export function ContextChooserMessage({ contextState, setValue, onCancel }) {
147189 ) ;
148190}
149191
150- function AuthContextData ( { contextName, users } ) {
192+ type AuthContextDataProps = {
193+ contextName : string ;
194+ users ?: Array < { name : string ; user : { exec : { args ?: string [ ] } } } > ;
195+ } ;
196+
197+ function AuthContextData ( { contextName, users } : AuthContextDataProps ) {
151198 const { t } = useTranslation ( ) ;
152199
153200 const issuerUrl = getUserDetail ( contextName , '--oidc-issuer-url=' , users ) ;
0 commit comments