@@ -4,6 +4,16 @@ import React, { useEffect, useState } from 'react';
44import { useFetch } from 'shared/hooks/BackendAPI/useFetch' ;
55import { ColumnLayoutState } from 'state/columnLayoutAtom' ;
66
7+ export const enum ModuleTemplateStatus {
8+ Ready = 'Ready' ,
9+ Processing = 'Processing' ,
10+ Deleting = 'Deleting' ,
11+ Unknown = 'Unknown' ,
12+ Unmanaged = 'Unmanaged' ,
13+ Warning = 'Warning' ,
14+ Error = 'Error' ,
15+ }
16+
717export type KymaResourceSpecModuleType = {
818 name : string ;
919 channel ?: string ;
@@ -105,7 +115,7 @@ export function useGetAllModulesStatuses(modules: any[]) {
105115 const status = ( await response . json ( ) ) ?. status ;
106116 return {
107117 key : resource ?. metadata ?. name ?? resource ?. name ,
108- status : status ?. state || ' Unknown' ,
118+ status : status ?. state || ModuleTemplateStatus . Unknown ,
109119 } ;
110120 } catch ( e ) {
111121 return {
@@ -152,6 +162,14 @@ export const findModuleSpec = (
152162 ) ;
153163} ;
154164
165+ type ModuleManagerType = {
166+ name : string ;
167+ namespace : string ;
168+ group : string ;
169+ version : string ;
170+ kind : string ;
171+ } ;
172+
155173export type ModuleTemplateType = {
156174 metadata : {
157175 name : string ;
@@ -167,6 +185,7 @@ export type ModuleTemplateType = {
167185 info ?: {
168186 documentation ?: string ;
169187 } ;
188+ manager : ModuleManagerType ;
170189 } ;
171190} ;
172191
@@ -244,3 +263,57 @@ export const checkSelectedModule = (
244263 }
245264 return false ;
246265} ;
266+
267+ export function useGetManagerStatus ( manager ?: ModuleManagerType ) {
268+ const fetch = useFetch ( ) ;
269+ const [ data , setData ] = useState < any > ( ModuleTemplateStatus . Unknown ) ;
270+ const [ error , setError ] = useState < Error | null > ( null ) ;
271+
272+ useEffect ( ( ) => {
273+ if ( manager ) {
274+ const path = getResourcePath ( {
275+ apiVersion : `${ manager ?. group } /${ manager ?. version } ` ,
276+ kind : manager ?. kind ,
277+ metadata : {
278+ name : manager ?. name ,
279+ namespace : manager ?. namespace ,
280+ } ,
281+ } as KymaResourceType ) ;
282+ async function fetchModule ( ) {
283+ try {
284+ const response = await fetch ( { relativeUrl : path } ) ;
285+ const status = ( await response . json ( ) ) ?. status ;
286+ setData ( status ?. conditions ?. [ 0 ] ?. type ) ;
287+ } catch ( error ) {
288+ if ( error instanceof Error ) {
289+ setError ( error ) ;
290+ }
291+ }
292+ }
293+
294+ fetchModule ( ) ;
295+ }
296+ // eslint-disable-next-line react-hooks/exhaustive-deps
297+ } , [ manager ] ) ;
298+
299+ return { data, error } ;
300+ }
301+
302+ export const resolveInstallationStateName = (
303+ state ?: string ,
304+ managerExists ?: boolean ,
305+ managerResourceState ?: string ,
306+ ) => {
307+ if ( state === ModuleTemplateStatus . Unmanaged && ! managerExists ) {
308+ return 'Not installed' ;
309+ }
310+
311+ if ( state === ModuleTemplateStatus . Unmanaged && managerExists ) {
312+ if ( state !== managerResourceState ) {
313+ return ModuleTemplateStatus . Processing ;
314+ }
315+ return managerResourceState || ModuleTemplateStatus . Unknown ;
316+ }
317+
318+ return state || ModuleTemplateStatus . Unknown ;
319+ } ;
0 commit comments