@@ -36,7 +36,7 @@ import {
3636 useModulesReleaseQuery ,
3737 useModuleTemplatesQuery ,
3838} from './kymaModulesQueries' ;
39- import { findSpec , findStatus } from './support' ;
39+ import { findSpec , findStatus , setChannel } from './support' ;
4040
4141export default function KymaModulesCreate ( { resource, ...props } ) {
4242 const { t } = useTranslation ( ) ;
@@ -67,10 +67,12 @@ export default function KymaModulesCreate({ resource, ...props }) {
6767
6868 const getRequest = useSingleGet ( ) ;
6969 const patchRequest = useUpdate ( ) ;
70- const [ selectedModules ] = useState (
70+ const [ selectedModules , setSelectedModules ] = useState (
7171 cloneDeep ( initialResource ?. spec ?. modules ) ?? [ ] ,
7272 ) ;
73- const [ isEdited , setIsEdited ] = useState ( false ) ;
73+ const [ showChannelChangeWarning , setShowChannelChangeWarning ] = useState (
74+ false ,
75+ ) ;
7476 const [ isManagedChanged , setIsManagedChanged ] = useState ( false ) ;
7577 const [ showMessageBox , setShowMessageBox ] = useState ( {
7678 isOpen : false ,
@@ -88,33 +90,6 @@ export default function KymaModulesCreate({ resource, ...props }) {
8890 ) ;
8991 }
9092
91- const setChannel = ( module , channel , index ) => {
92- if (
93- selectedModules . find (
94- selectedModule => selectedModule . name === module . name ,
95- )
96- ) {
97- if ( channel === 'predefined' ) {
98- delete selectedModules [ index ] . channel ;
99- } else selectedModules [ index ] . channel = channel ;
100- } else {
101- selectedModules . push ( {
102- name : module . name ,
103- } ) ;
104- if ( channel !== 'predefined' )
105- selectedModules [ selectedModules . length - 1 ] . channel = channel ;
106- }
107-
108- setKymaResource ( {
109- ...kymaResource ,
110- spec : {
111- ...kymaResource . spec ,
112- modules : selectedModules ,
113- } ,
114- } ) ;
115- setIsEdited ( true ) ;
116- } ;
117-
11893 const setManaged = ( managed , index ) => {
11994 selectedModules [ index ] . managed = managed ;
12095
@@ -238,7 +213,21 @@ export default function KymaModulesCreate({ resource, ...props }) {
238213 < Select
239214 accessibleName = { `channel-select-${ module . name } ` }
240215 onChange = { event => {
241- setChannel ( module , event . detail . selectedOption . value , index ) ;
216+ setChannel (
217+ module ,
218+ event . detail . selectedOption . value ,
219+ index ,
220+ selectedModules ,
221+ setSelectedModules ,
222+ ) ;
223+ setKymaResource ( {
224+ ...kymaResource ,
225+ spec : {
226+ ...kymaResource . spec ,
227+ modules : selectedModules ,
228+ } ,
229+ } ) ;
230+ setShowChannelChangeWarning ( true ) ;
242231 } }
243232 value = {
244233 findSpec ( kymaResource , module . name ) ?. channel ||
@@ -401,7 +390,7 @@ export default function KymaModulesCreate({ resource, ...props }) {
401390
402391 const skipModuleFn = ( ) => {
403392 const shouldShowManagedWarning = isManagedChanged ;
404- const shouldShowChannelWarning = isEdited ;
393+ const shouldShowChannelWarning = showChannelChangeWarning ;
405394
406395 if ( shouldShowManagedWarning ) {
407396 setShowManagedBox ( {
@@ -434,7 +423,7 @@ export default function KymaModulesCreate({ resource, ...props }) {
434423 showManagedBox = { showManagedBox }
435424 setShowManagedBox = { setShowManagedBox }
436425 handleCreate = { handleCreate }
437- isEdited = { isEdited }
426+ showChannelChangeWarning = { showChannelChangeWarning }
438427 setShowMessageBox = { setShowMessageBox }
439428 /> ,
440429 document . body ,
0 commit comments