@@ -3,12 +3,16 @@ import {
33 FlexBox ,
44 Input ,
55 Label ,
6- MessageBox ,
76 MessageStrip ,
87 OptionCustom ,
98 Text ,
109 Select ,
1110 Icon ,
11+ Dialog ,
12+ Bar ,
13+ ButtonDomRef ,
14+ Ui5CustomEvent ,
15+ DialogDomRef ,
1216} from '@ui5/webcomponents-react' ;
1317import { Trans , useTranslation } from 'react-i18next' ;
1418import { createPortal } from 'react-dom' ;
@@ -35,6 +39,8 @@ import {
3539 OPERATION_STATE_SOME_FAILED ,
3640 OPERATION_STATE_SUCCEEDED ,
3741} from 'resources/Namespaces/YamlUpload/YamlUploadDialog' ;
42+ import { ButtonClickEventDetail } from '@ui5/webcomponents/dist/Button' ;
43+ import { PopupBeforeCloseEventDetail } from '@ui5/webcomponents/dist/Popup' ;
3844
3945const DEFAULT_SOURCE_URL =
4046 'https://kyma-project.github.io/community-modules/all-modules.yaml' ;
@@ -173,21 +179,23 @@ export const AddSourceYamls = () => {
173179 navigate ( link ) ;
174180 } ;
175181
176- const handleClose = ( action ?: string ) => {
177- /* It fires on every action, but we want to show the loader when adding.
178- `1: custom action` - Add
179- `2: custom action` - Cancel
180- undefined - ESC
181- */
182- if ( action === '1: custom action' ) {
183- return ;
182+ const handleClose = (
183+ e :
184+ | Ui5CustomEvent < ButtonDomRef , ButtonClickEventDetail >
185+ | Ui5CustomEvent < DialogDomRef , PopupBeforeCloseEventDetail > ,
186+ isCancel ?: boolean ,
187+ ) => {
188+ const isEscape = 'escPressed' in e . detail ? e . detail . escPressed : false ;
189+
190+ if ( isEscape || isCancel ) {
191+ setSourceURL ( DEFAULT_SOURCE_URL ) ;
192+ setResourcesToApply ( [ ] ) ;
193+ setShowDescription ( false ) ;
194+ setShowAddSource ( false ) ;
195+ setAddYamlsLoader ( false ) ;
184196 }
185- setSourceURL ( DEFAULT_SOURCE_URL ) ;
186- setResourcesToApply ( [ ] ) ;
187- setShowDescription ( false ) ;
188- setShowAddSource ( false ) ;
189- setAddYamlsLoader ( false ) ;
190197 } ;
198+
191199 const displayExistingModulesList = ( moduleList : any ) => (
192200 < ul className = "unordered-list-disc" >
193201 { moduleList ?. map ( ( mt : any ) => {
@@ -264,38 +272,48 @@ export const AddSourceYamls = () => {
264272
265273 { showAddSource &&
266274 createPortal (
267- < MessageBox
275+ < Dialog
268276 open = { showAddSource }
269277 className = "sourceurl-messagebox"
270- titleText = { t ( 'modules.community.source-yaml.add-source-yaml' ) }
271- onClose = { handleClose }
272- actions = { [
273- addYamlsLoader ? < Spinner key = "add-yamls-loader" /> : null ,
274- < Button
275- accessibleName = "add-yamls"
276- design = "Emphasized"
277- key = "add-yamls"
278- disabled = {
279- ! ! error || resourcesToApply . length === 0 || addYamlsLoader
278+ headerText = { t ( 'modules.community.source-yaml.add-source-yaml' ) }
279+ onBeforeClose = { handleClose }
280+ footer = {
281+ < Bar
282+ design = "Footer"
283+ endContent = {
284+ < >
285+ { addYamlsLoader ? < Spinner key = "add-yamls-loader" /> : null }
286+ < Button
287+ accessibleName = "add-yamls"
288+ design = "Emphasized"
289+ key = "add-yamls"
290+ disabled = {
291+ ! ! error ||
292+ resourcesToApply . length === 0 ||
293+ addYamlsLoader
294+ }
295+ onClick = { async ( ) => {
296+ setAddYamlsLoader ( true ) ;
297+ await handleApplySourceYAMLs ( ) ;
298+ } }
299+ >
300+ { t ( 'common.buttons.add' ) }
301+ </ Button >
302+ < Button
303+ accessibleName = "cancel-add-yamls"
304+ design = "Transparent"
305+ key = "cancel-add-yamls"
306+ onClick = { ( e ) => {
307+ handleClose ( e , true ) ;
308+ setShowAddSource ( false ) ;
309+ } }
310+ >
311+ { t ( 'common.buttons.cancel' ) }
312+ </ Button >
313+ </ >
280314 }
281- onClick = { async ( ) => {
282- setAddYamlsLoader ( true ) ;
283- await handleApplySourceYAMLs ( ) ;
284- } }
285- >
286- { t ( 'common.buttons.add' ) }
287- </ Button > ,
288- < Button
289- accessibleName = "cancel-add-yamls"
290- design = "Transparent"
291- key = "cancel-add-yamls"
292- onClick = { ( ) => {
293- setShowAddSource ( false ) ;
294- } }
295- >
296- { t ( 'common.buttons.cancel' ) }
297- </ Button > ,
298- ] }
315+ > </ Bar >
316+ }
299317 >
300318 < div className = "sourceurl-content" >
301319 < FlexBox direction = { FlexBoxDirection . Column } gap = { '0.5rem' } >
@@ -409,7 +427,7 @@ export const AddSourceYamls = () => {
409427 )
410428 ) }
411429 </ div >
412- </ MessageBox > ,
430+ </ Dialog > ,
413431 document . body ,
414432 ) }
415433 </ >
0 commit comments