66import { Close } from '@mui/icons-material' ;
77import InstallDesktopIcon from '@mui/icons-material/InstallDesktop' ;
88import LoadingButton from '@mui/lab/LoadingButton' ;
9- import { Alert , FormControl , FormHelperText , IconButton , InputLabel , MenuItem , Paper , Select , Stack , TextField , useMediaQuery } from '@mui/material' ;
9+ import { Alert , Box , FormControl , FormHelperText , IconButton , InputLabel , LinearProgress , MenuItem , Paper , Select , Stack , TextField , Theme , Typography , useMediaQuery } from '@mui/material' ;
1010import React from 'react' ;
1111import { Chart , ChartResponse } from '../../../helm/helmChartType' ;
1212import { VSCodeMessage } from '../vsCodeMessage' ;
1313import { HelmListItem } from './helmListItem' ;
14+ import CodeMirror from '@uiw/react-codemirror' ;
15+ import { yaml } from '@codemirror/lang-yaml' ;
16+ import { githubLight , githubDark } from '@uiw/codemirror-theme-github' ;
17+ import jsyaml from 'js-yaml' ;
1418
1519type Message = {
1620 action : string ;
@@ -22,6 +26,7 @@ export const HelmModal = React.forwardRef(
2226 props : {
2327 helmChart : ChartResponse ;
2428 closeModal : ( ) => void ;
29+ theme : Theme ;
2530 } ,
2631 ref ,
2732 ) => {
@@ -31,14 +36,15 @@ export const HelmModal = React.forwardRef(
3136 const [ installNameErrorMessage , setInstallNameErrorMessage ] = React . useState (
3237 'Please enter a name.' ,
3338 ) ;
34-
3539 const [ showStatus , setStatus ] = React . useState < boolean > ( false ) ;
3640 const [ installError , setInstallError ] = React . useState < boolean > ( false ) ;
3741 const [ installMsg , setInstallMsg ] = React . useState < string > ( '' ) ;
3842 const [ installLoading , setInstallLoading ] = React . useState < boolean > ( false ) ;
3943
4044 const [ selectedVersion , setSelectedVersion ] = React . useState < Chart > ( props . helmChart . chartVersions [ 0 ] ) ;
4145 const [ isInteracted , setInteracted ] = React . useState ( false ) ;
46+ const [ yamlValues , setYAMLValues ] = React . useState < string > ( '' ) ;
47+ const [ yamlError , setYAMLError ] = React . useState < string > ( undefined ) ;
4248
4349 function respondToMessage ( messageEvent : MessageEvent ) {
4450 const message = messageEvent . data as Message ;
@@ -63,6 +69,10 @@ export const HelmModal = React.forwardRef(
6369 }
6470 break ;
6571 }
72+ case 'getYAMLValues' : {
73+ setYAMLValues ( message . data . yamlValues )
74+ break ;
75+ }
6676 default :
6777 break ;
6878 }
@@ -75,6 +85,10 @@ export const HelmModal = React.forwardRef(
7585 } ;
7686 } , [ ] ) ;
7787
88+ React . useEffect ( ( ) => {
89+ VSCodeMessage . postMessage ( { action : 'getYAMLValues' , data : props . helmChart } ) ;
90+ } , [ ] ) ;
91+
7892 const isWideEnough = useMediaQuery ( '(min-width: 900px)' ) ;
7993
8094 React . useEffect ( ( ) => {
@@ -101,6 +115,16 @@ export const HelmModal = React.forwardRef(
101115
102116 const isError = ! versions . length || ! selectedVersion ;
103117
118+ const handleChange = ( newValue : string ) => {
119+ setYAMLError ( undefined ) ;
120+ try {
121+ jsyaml . load ( newValue ) ;
122+ setYAMLValues ( newValue ) ;
123+ } catch ( e ) {
124+ setYAMLError ( e . message ) ;
125+ }
126+ } ;
127+
104128 return (
105129 < Paper
106130 elevation = { 24 }
@@ -109,12 +133,12 @@ export const HelmModal = React.forwardRef(
109133 top : '50%' ,
110134 left : '50%' ,
111135 width : isWideEnough ? '900px' : 'calc(100vw - 48px)' ,
112- maxHeight : 'calc(100vh - 48px) ' ,
136+ height : 'auto ' ,
113137 transform : 'translate(-50%, -50%)' ,
114138 padding : 2 ,
115139 } }
116140 >
117- < Stack direction = 'column' spacing = { 2 } >
141+ < Stack direction = 'column' spacing = { 1 } justifyContent = 'space-between' >
118142 < Stack
119143 direction = 'row'
120144 justifyContent = 'space-between'
@@ -170,33 +194,66 @@ export const HelmModal = React.forwardRef(
170194 ) ;
171195 } ) }
172196 </ Select >
173- < Stack direction = 'row' justifyContent = 'space-between' >
174- < FormHelperText error = { isError } > { helperText } </ FormHelperText >
175- < Stack direction = 'row' marginTop = { 1 } spacing = { 2 } >
176- < LoadingButton
177- variant = 'contained'
178- onClick = { ( ) => {
179- setInstallLoading ( true ) ;
180- VSCodeMessage . postMessage ( {
181- action : 'install' ,
182- data : {
183- name : installName ,
184- repoName : props . helmChart . repoName ,
185- chartName : props . helmChart . chartName ,
186- version : selectedVersion . version
187- }
188- } )
189- } }
190- disabled = { ! isInstallNameFieldValid || installName . length === 0 }
191- loading = { installLoading }
192- loadingPosition = 'start'
193- startIcon = { < InstallDesktopIcon /> }
194- >
195- < span > Install</ span >
196- </ LoadingButton >
197- </ Stack >
198- </ Stack >
197+ < FormHelperText error = { isError } > { helperText } </ FormHelperText >
199198 </ FormControl >
199+ {
200+ yamlValues . length <= 0 ?
201+ < >
202+ < Box sx = { { color : '#EE0000' } } >
203+ < LinearProgress color = 'inherit' sx = { { height : '1rem' } } />
204+ </ Box >
205+ < Typography
206+ variant = 'caption'
207+ component = 'div'
208+ color = 'inherit'
209+ style = { { marginTop : '3px' , marginLeft : '5px' , fontSize : '1em' } }
210+ > Retrieving helm values</ Typography >
211+ </ >
212+ :
213+ < >
214+ {
215+ yamlValues !== 'noVal' &&
216+ < Stack direction = 'column' spacing = { 1 } justifyContent = 'space-between' >
217+ < InputLabel id = 'values' > Values:</ InputLabel >
218+ < CodeMirror
219+ value = { yamlValues }
220+ height = '300px'
221+ extensions = { [ yaml ( ) ] }
222+ theme = { props . theme ?. palette . mode === 'light' ? githubLight : githubDark }
223+ onChange = { handleChange }
224+ basicSetup = { {
225+ lineNumbers : true ,
226+ highlightActiveLine : true
227+ } } />
228+ { yamlError && < div style = { { color : '#EE0000' } } > Error: { yamlError } </ div > }
229+ </ Stack >
230+ }
231+ </ >
232+ }
233+ < Stack direction = 'row' marginTop = { 1 } spacing = { 2 } >
234+ < LoadingButton
235+ variant = 'contained'
236+ onClick = { ( ) => {
237+ setInstallLoading ( true ) ;
238+ VSCodeMessage . postMessage ( {
239+ action : 'install' ,
240+ data : {
241+ name : installName ,
242+ repoName : props . helmChart . repoName ,
243+ chartName : props . helmChart . chartName ,
244+ version : selectedVersion . version ,
245+ yamlValues
246+ }
247+ } ) ;
248+ } }
249+ disabled = { ! isInstallNameFieldValid || installName . length === 0 }
250+ loading = { installLoading }
251+ loadingPosition = 'start'
252+ startIcon = { < InstallDesktopIcon /> }
253+ >
254+ < span > Install</ span >
255+ </ LoadingButton >
256+ </ Stack >
200257 { showStatus && (
201258 ! installError ? < Alert severity = 'info' >
202259 { installMsg } `{ installName } `
0 commit comments