@@ -68,7 +68,7 @@ export const getAllModulesInfo = async (): Promise<Record<string, ModuleInfo>> =
68
68
return Promise . resolve ( moduleStatusMap )
69
69
}
70
70
71
- export const getSecurityModulesInfoInstalledStatus = async ( ) : Promise < ModuleInfoResponse > => {
71
+ const getSecurityModulesInfoInstalledStatus = async ( ) : Promise < ModuleInfoResponse > => {
72
72
// getting Security Module Installation status
73
73
const res : ModuleInfo = {
74
74
id : null ,
@@ -100,39 +100,44 @@ export const getSecurityModulesInfoInstalledStatus = async (): Promise<ModuleInf
100
100
}
101
101
102
102
export 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 ] } )
128
107
}
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
132
111
}
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
134
140
}
135
- return Promise . resolve ( { status : '' , code : 200 , result } )
136
141
}
137
142
138
143
export const executeModuleEnableAction = ( moduleName : string , toolVersion : string ) : Promise < ModuleActionResponse > =>
@@ -181,11 +186,13 @@ export const getAllModules = (): Promise<AllModuleInfoResponse> =>
181
186
res . json ( ) ,
182
187
)
183
188
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 > => {
185
193
const url = getUrlWithSearchParams ( `${ window . _env_ . CENTRAL_API_ENDPOINT } /${ Routes . RELEASE_NOTES_API } ` , {
186
194
repo : INSTALLATION_TYPE_TO_REPO_MAP [ installationType ] ,
187
195
serverVersion,
188
-
189
196
} )
190
197
const response = await fetch ( url )
191
198
return response . json ( )
0 commit comments