@@ -68,7 +68,7 @@ export const getAllModulesInfo = async (): Promise<Record<string, ModuleInfo>> =
6868 return Promise . resolve ( moduleStatusMap )
6969}
7070
71- export const getSecurityModulesInfoInstalledStatus = async ( ) : Promise < ModuleInfoResponse > => {
71+ const getSecurityModulesInfoInstalledStatus = async ( ) : Promise < ModuleInfoResponse > => {
7272 // getting Security Module Installation status
7373 const res : ModuleInfo = {
7474 id : null ,
@@ -100,39 +100,44 @@ export const getSecurityModulesInfoInstalledStatus = async (): Promise<ModuleInf
100100}
101101
102102export const getModuleInfo = async ( moduleName : string , forceReload ?: boolean ) : Promise < ModuleInfoResponse > => {
103- const _savedModuleStatusMap = getSavedModuleStatus ( )
104- if ( ! forceReload && _savedModuleStatusMap && _savedModuleStatusMap [ moduleName ] ) {
105- return Promise . resolve ( { status : '' , code : 200 , result : _savedModuleStatusMap [ moduleName ] } )
106- }
107- if ( moduleName === ModuleNameMap . SECURITY ) {
108- return getSecurityModulesInfoInstalledStatus ( )
109- }
110- const { result } = await get ( `${ Routes . MODULE_INFO_API } ?name=${ moduleName } ` )
111- if ( result && result . status === ModuleStatus . INSTALLED ) {
112- if ( moduleName === ModuleNameMap . CICD && ! isReloadToastShown ) {
113- // To show a reload tost if CICD installation complete
114- ToastManager . showToast ( {
115- variant : ToastVariantType . info ,
116- title : 'Update available' ,
117- description : 'You are viewing an outdated version of Devtron UI.' ,
118- buttonProps : {
119- text : 'Reload' ,
120- dataTestId : 'reload-button' ,
121- onClick : refresh ,
122- startIcon : < ICArrowClockwise /> ,
123- } ,
124- icon : < Icon name = "ic-sparkle-color" color = { null } /> ,
125- progressBarBg : UPDATE_AVAILABLE_TOAST_PROGRESS_BG ,
126- } )
127- isReloadToastShown = true
103+ try {
104+ const _savedModuleStatusMap = getSavedModuleStatus ( )
105+ if ( ! forceReload && _savedModuleStatusMap && _savedModuleStatusMap [ moduleName ] ) {
106+ return Promise . resolve ( { status : '' , code : 200 , result : _savedModuleStatusMap [ moduleName ] } )
128107 }
129- _savedModuleStatusMap [ moduleName ] = { ... result , moduleResourcesStatus : null }
130- if ( typeof Storage !== 'undefined' ) {
131- localStorage . moduleStatusMap = JSON . stringify ( _savedModuleStatusMap )
108+ if ( moduleName === ModuleNameMap . SECURITY ) {
109+ const moduleResponse = await getSecurityModulesInfoInstalledStatus ( )
110+ return moduleResponse
132111 }
133- moduleStatusMap = _savedModuleStatusMap
112+ const { result } = await get ( `${ Routes . MODULE_INFO_API } ?name=${ moduleName } ` )
113+ if ( result && result . status === ModuleStatus . INSTALLED ) {
114+ if ( moduleName === ModuleNameMap . CICD && ! isReloadToastShown ) {
115+ // To show a reload tost if CICD installation complete
116+ ToastManager . showToast ( {
117+ variant : ToastVariantType . info ,
118+ title : 'Update available' ,
119+ description : 'You are viewing an outdated version of Devtron UI.' ,
120+ buttonProps : {
121+ text : 'Reload' ,
122+ dataTestId : 'reload-button' ,
123+ onClick : refresh ,
124+ startIcon : < ICArrowClockwise /> ,
125+ } ,
126+ icon : < Icon name = "ic-sparkle-color" color = { null } /> ,
127+ progressBarBg : UPDATE_AVAILABLE_TOAST_PROGRESS_BG ,
128+ } )
129+ isReloadToastShown = true
130+ }
131+ _savedModuleStatusMap [ moduleName ] = { ...result , moduleResourcesStatus : null }
132+ if ( typeof Storage !== 'undefined' ) {
133+ localStorage . moduleStatusMap = JSON . stringify ( _savedModuleStatusMap )
134+ }
135+ moduleStatusMap = _savedModuleStatusMap
136+ }
137+ return Promise . resolve ( { status : '' , code : 200 , result } )
138+ } catch {
139+ return null
134140 }
135- return Promise . resolve ( { status : '' , code : 200 , result } )
136141}
137142
138143export const executeModuleEnableAction = ( moduleName : string , toolVersion : string ) : Promise < ModuleActionResponse > =>
@@ -181,11 +186,13 @@ export const getAllModules = (): Promise<AllModuleInfoResponse> =>
181186 res . json ( ) ,
182187 )
183188
184- export const getReleasesNotes = async ( installationType : InstallationType , serverVersion : string ) : Promise < ReleaseNotesResponse > => {
189+ export const getReleasesNotes = async (
190+ installationType : InstallationType ,
191+ serverVersion : string ,
192+ ) : Promise < ReleaseNotesResponse > => {
185193 const url = getUrlWithSearchParams ( `${ window . _env_ . CENTRAL_API_ENDPOINT } /${ Routes . RELEASE_NOTES_API } ` , {
186194 repo : INSTALLATION_TYPE_TO_REPO_MAP [ installationType ] ,
187195 serverVersion,
188-
189196 } )
190197 const response = await fetch ( url )
191198 return response . json ( )
0 commit comments