@@ -18,7 +18,7 @@ import { getAllStacksInOrg } from '../../services/api/stacks.service';
1818import { CS_ENTRIES } from '../../utilities/constants' ;
1919
2020// Interface
21- import { MigrationType } from './testMigration.interface' ;
21+ import { MigrationType , TestMigrationValues } from './testMigration.interface' ;
2222import { INewMigration } from '../../context/app/app.interface' ;
2323
2424
@@ -28,21 +28,36 @@ import TestMigrationLogViewer from '../LogScreen';
2828// CSS
2929import './index.scss' ;
3030
31+ // utility function to save state to sessionStorage
32+ export const saveStateToLocalStorage = ( state :TestMigrationValues , projectId : string ) => {
33+ sessionStorage . setItem ( `testmigration_${ projectId } ` , JSON . stringify ( state ) ) ;
34+ } ;
35+
36+ // utitlity function to retrieve state from sessionStorage
37+ const getStateFromLocalStorage = ( projectId : string ) => {
38+ const state = sessionStorage . getItem ( `testmigration_${ projectId } ` ) ;
39+ return state ? JSON . parse ( state ) : null ;
40+ } ;
41+
3142const TestMigration = ( ) => {
43+
44+ // Access Redux state for migration data and selected organization
3245 const newMigrationData = useSelector ( ( state : RootState ) => state ?. migration ?. newMigrationData ) ;
3346 const selectedOrganisation = useSelector ( ( state : RootState ) => state ?. authentication ?. selectedOrganisation ) ;
3447
3548 const [ data , setData ] = useState < MigrationType > ( { } ) ;
3649 const [ isLoading , setIsLoading ] = useState ( newMigrationData ?. isprojectMapped ) ;
3750 const [ isStackLoading , setIsStackLoading ] = useState < boolean > ( false ) ;
38- const [ disableTestMigration , setdisableTestMigration ] = useState < boolean > ( false ) ;
51+ const [ disableTestMigration , setdisableTestMigration ] = useState < boolean > ( newMigrationData ?. test_migration ?. isMigrationStarted ) ;
3952
40- const [ disableCreateStack , setDisableCreateStack ] = useState < boolean > ( false ) ;
53+ const [ disableCreateStack , setDisableCreateStack ] = useState < boolean > ( newMigrationData ?. test_migration ?. isMigrationStarted ) ;
4154 const [ stackLimitReached , setStackLimitReached ] = useState < boolean > ( false ) ;
4255
56+ // Extract project ID from URL parameters
4357 const { projectId = '' } = useParams ( ) ;
4458 const dispatch = useDispatch ( ) ;
4559
60+ // Destructure CMS data for button labels and subtitles
4661 const { create_stack_cta : createStackCta , subtitle, start_migration_cta : startMigrationCta } = data
4762
4863 /********** ALL USEEFFECT HERE *************/
@@ -63,7 +78,8 @@ const TestMigration = () => {
6378 * to disable Create Test Stack and Start Test Migration buttons as per isMigrated state
6479 */
6580 useEffect ( ( ) => {
66- if ( ! newMigrationData ?. testStacks ?. find ( ( stack ) => stack ?. stackUid === newMigrationData ?. test_migration ?. stack_api_key ) ?. isMigrated ) {
81+ if ( ! newMigrationData ?. testStacks ?. find ( ( stack ) => stack ?. stackUid === newMigrationData ?. test_migration ?. stack_api_key ) ?. isMigrated && ! disableTestMigration ) {
82+
6783 setDisableCreateStack ( false ) ;
6884 }
6985
@@ -72,6 +88,18 @@ const TestMigration = () => {
7288 }
7389 } , [ newMigrationData ?. testStacks ] ) ;
7490
91+ useEffect ( ( ) => {
92+
93+ // Retrieve and apply saved state from sessionStorage
94+ const savedState = getStateFromLocalStorage ( projectId ) ;
95+ if ( savedState ) {
96+ setdisableTestMigration ( savedState ?. isTestMigrationStarted ) ;
97+ setDisableCreateStack ( savedState ?. isTestMigrationStarted ) ;
98+ }
99+
100+ } , [ ] ) ;
101+
102+
75103
76104 /**
77105 * Handles create test stack function
@@ -81,15 +109,19 @@ const TestMigration = () => {
81109
82110 //get org plan details
83111 try {
112+
113+ // Fetch organization details to determine stack limit
84114 const orgDetails = await getOrgDetails ( selectedOrganisation ?. value ) ;
85115 const stacks_details_key = Object . keys ( orgDetails ?. data ?. organization ?. plan ?. features ) ?. find ( key => orgDetails ?. data ?. organization ?. plan ?. features [ key ] . uid === 'stacks' ) ?? '' ;
86116
87117 const max_stack_limit = orgDetails ?. data ?. organization ?. plan ?. features [ stacks_details_key ] ?. max_limit ;
88118
119+ // Check the current stack count
89120 const stackData = await getAllStacksInOrg ( selectedOrganisation ?. value , '' ) ; // org id will always be there
90121
91122 const stack_count = stackData ?. data ?. stacks ?. length ;
92123
124+ // Handle stack limit reached
93125 if ( stack_count >= max_stack_limit ) {
94126 setIsLoading ( false ) ;
95127 setDisableCreateStack ( true ) ;
@@ -104,6 +136,7 @@ const TestMigration = () => {
104136 console . log ( error ) ;
105137 }
106138
139+ // Prepare data for stack creation
107140 const data = {
108141 name : newMigrationData ?. destination_stack ?. selectedStack ?. label ,
109142 description : 'test migration stack' ,
@@ -130,7 +163,7 @@ const TestMigration = () => {
130163 type : 'success'
131164 } ) ;
132165
133-
166+ // Update migration data in Redux
134167 const newMigrationDataObj : INewMigration = {
135168 ...newMigrationData ,
136169 test_migration : { ...newMigrationData ?. test_migration , stack_link : res ?. data ?. data ?. url , stack_api_key : res ?. data ?. data ?. data ?. stack ?. api_key , stack_name : res ?. data ?. data ?. data ?. stack ?. name }
@@ -154,7 +187,26 @@ const TestMigration = () => {
154187
155188 if ( testRes ?. status === 200 ) {
156189 setdisableTestMigration ( true ) ;
190+
191+ //dispatch test migration started flag in redux
192+ const newMigrationDataObj : INewMigration = {
193+ ...newMigrationData ,
194+ test_migration :{
195+ ...newMigrationData ?. test_migration ,
196+ isMigrationStarted :true ,
197+ }
198+ }
199+ dispatch ( updateNewMigrationData ( newMigrationDataObj ) ) ;
200+
201+ //update test migration started flag in localstorage
202+ saveStateToLocalStorage ( {
203+ isTestMigrationCompleted : false ,
204+ isTestMigrationStarted : true ,
205+ } , projectId ) ;
206+
157207 handleMigrationState ( true ) ;
208+
209+
158210 Notification ( {
159211 notificationContent : { text : 'Test Migration started' } ,
160212 notificationProps : {
@@ -250,7 +302,7 @@ const TestMigration = () => {
250302 < div className = 'content-block' >
251303 < div className = 'content-header' > Execution Logs</ div >
252304 < div >
253- < TestMigrationLogViewer serverPath = { process . env . REACT_APP_BASE_API_URL ?? '' } sendDataToParent = { handleMigrationState } />
305+ < TestMigrationLogViewer serverPath = { process . env . REACT_APP_BASE_API_URL ?? '' } sendDataToParent = { handleMigrationState } projectId = { projectId } />
254306 </ div >
255307 </ div >
256308 </ div >
0 commit comments