@@ -26,52 +26,45 @@ const ImportPage: FC<ImportPageType> = ({ projectId, projectName }) => {
2626 const history = useHistory ( )
2727 const [ LDKey , setLDKey ] = useState < string > ( '' )
2828 const [ importId , setImportId ] = useState < number > ( )
29+ const [ importSource , setImportSource ] = useState < string > ( '' )
2930 const [ isLoading , setIsLoading ] = useState < boolean > ( false )
30- const [ isAppLoading , setAppIsLoading ] = useState < boolean > ( false )
3131 const [ projects , setProjects ] = useState < { key : string ; name : string } [ ] > ( [ ] )
3232 const [ createLaunchDarklyProjectImport , { data, isSuccess } ] =
3333 useCreateLaunchDarklyProjectImportMutation ( )
3434
35- const {
36- data : status ,
37- isSuccess : statusLoaded ,
38- isUninitialized,
39- refetch,
40- } = useGetLaunchDarklyProjectImportQuery (
35+ const { data : status } = useGetLaunchDarklyProjectImportQuery (
4136 {
4237 import_id : `${ importId } ` ,
4338 project_id : projectId ,
4439 } ,
45- { skip : ! importId } ,
40+ {
41+ pollingInterval : importId ? 1000 : 0 ,
42+ skip : ! importId ,
43+ } ,
4644 )
4745
46+ // Set importId when mutation succeeds
4847 useEffect ( ( ) => {
49- const checkImportStatus = async ( ) => {
50- setAppIsLoading ( true )
51- const intervalId = setInterval ( async ( ) => {
52- await refetch ( )
53-
54- if ( statusLoaded && status && status . status . result === 'success' ) {
55- clearInterval ( intervalId )
56- setAppIsLoading ( false )
57- window . location . reload ( )
58- }
59- } , 1000 )
60- }
61-
62- if ( statusLoaded ) {
63- checkImportStatus ( )
48+ if ( isSuccess && data ?. id ) {
49+ setImportId ( data . id )
50+ setImportSource ( 'LaunchDarkly' )
6451 }
65- } , [ statusLoaded , status , refetch ] )
52+ } , [ isSuccess , data ] )
6653
54+ // Navigate away on import success
6755 useEffect ( ( ) => {
68- if ( isSuccess && data ?. id ) {
69- setImportId ( data . id )
70- if ( ! isUninitialized ) {
71- refetch ( )
72- }
56+ if ( status ?. status ?. result === 'success' ) {
57+ const params = new URLSearchParams ( )
58+ params . set ( 'import_success' , '1' )
59+ params . set ( 'import_source' , importSource )
60+ params . set ( 'import_count' , String ( status . status . requested_flag_count ) )
61+ params . set (
62+ 'import_deprecated' ,
63+ String ( status . status . deprecated_flag_count ?? 0 ) ,
64+ )
65+ history . push ( `/project/${ projectId } ?${ params . toString ( ) } ` )
7366 }
74- } , [ isSuccess , data , refetch , isUninitialized ] )
67+ } , [ status , projectId , history , importSource ] )
7568
7669 const getProjectList = ( LDKey : string ) => {
7770 setIsLoading ( true )
@@ -210,11 +203,13 @@ const ImportPage: FC<ImportPageType> = ({ projectId, projectName }) => {
210203 </ >
211204 )
212205
206+ const isImporting = ! ! importId && status ?. status ?. result !== 'success'
207+
213208 return (
214209 < >
215- { isAppLoading && (
210+ { isImporting && (
216211 < div className = 'overlay' >
217- < div className = 'title' > Importing Project </ div >
212+ < div className = 'title' > Importing from { importSource } ... </ div >
218213 < AppLoader />
219214 </ div >
220215 ) }
0 commit comments