diff --git a/src/components/Charts.tsx b/src/components/Charts.tsx index 601450f..9554811 100644 --- a/src/components/Charts.tsx +++ b/src/components/Charts.tsx @@ -128,10 +128,20 @@ const defaultMetrics: DoraState = { }; export const Charts = (props: ChartProps) => { - // Always call useEntity unconditionally - const entityContext = useEntity(); - // Then conditionally use the result - const entity = props.showServiceSelection ? null : entityContext; + // Use try/catch to handle the case when entity context is not available + let entity = null; + try { + // Only call useEntity when we're not in standalone mode + if (!props.showServiceSelection) { + const { entity: contextEntity } = useEntity(); + entity = contextEntity; + } + } catch (error) { + // Entity context not available, which is fine in standalone mode + if (!props.showServiceSelection) { + throw error; // Re-throw if we're not in service selection mode + } + } const configApi = useApi(configApiRef); const backendUrl = configApi.getString('backend.baseUrl'); const dataEndpoint = configApi.getString('dora.dataEndpoint'); @@ -255,20 +265,50 @@ export const Charts = (props: ChartProps) => { onError: (error: any) => void, ) => { try { + console.log('Fetching services from URL:', url); const authHeader = await Promise.resolve(getAuthHeader()); + console.log('Auth header available:', !!authHeader); + const response = await fetch(url, { headers: { Authorization: authHeader || '', }, }); + console.log('Service list response status:', response.status, response.statusText); + if (!response.ok) { + // If proxy fails, try direct connection as fallback + if (response.status === 504) { + console.log('Proxy timeout, trying direct connection to API'); + try { + const directResponse = await fetch('http://localhost:8080/v1/services', { + headers: { + 'Accept': 'application/json', + }, + }); + + console.log('Direct API response:', directResponse.status, directResponse.statusText); + + if (directResponse.ok) { + const directData = await directResponse.json(); + console.log('Direct API data:', directData); + onSuccess(directData); + return; + } + } catch (directError) { + console.error('Direct API connection failed:', directError); + // Continue with the original error + } + } throw new Error(`Error fetching services: ${response.statusText}`); } const responseData = await response.json(); + console.log('Service list data received:', responseData); onSuccess(responseData); } catch (error) { + console.error('Error fetching services:', error); onError(error); } }; @@ -346,7 +386,13 @@ export const Charts = (props: ChartProps) => { const fetch = props.showServiceSelection ? async () => { + // http://localhost:7007/api/proxy/dora/api/services + console.log('Service selection mode active'); + console.log('Config servicesList:', servicesList); + console.log('Service list URL:', serviceListUrl); + if (servicesList && servicesList.length > 0) { + console.log('Using services from config:', servicesList); const serviceEntries = [ { value: '', @@ -364,26 +410,36 @@ export const Charts = (props: ChartProps) => { setMessage('Please select a Service'); setLoading(false); setServices(serviceEntries); + console.log('Services set from config:', serviceEntries); } else { + console.log('Fetching services from API'); fetchServicesData( serviceListUrl, getAuthHeaderValue, (services_data: any) => { + console.log('Services data received:', services_data); const newList: any[] = [{ label: 'Please Select', value: '' }]; - for (const entry of services_data.services) { - const newEntry = { - label: entry, - value: entry, - }; - - newList.push(newEntry); + if (services_data.services && services_data.services.length > 0) { + console.log('Processing services:', services_data.services); + for (const entry of services_data.services) { + const newEntry = { + label: entry, + value: entry, + }; + + newList.push(newEntry); + } + } else { + console.warn('No services found in response'); } + console.log('Setting services:', newList); setServices(newList); setLoading(false); }, - _ => { + error => { + console.error('Error in service list callback:', error); setLoading(false); }, ); diff --git a/yarn.lock b/yarn.lock index 616af3f..9db9df1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2299,10 +2299,10 @@ resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.5.tgz#4fc56c15c580b9adb7dc3c333a134e540b44bfb1" integrity sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw== -"@liatrio/react-dora-charts@^1.1.8": - version "1.1.10" - resolved "https://registry.yarnpkg.com/@liatrio/react-dora-charts/-/react-dora-charts-1.1.10.tgz#001e615b83c3abe17204e869ceadcdf2a77a60c6" - integrity sha512-CUK8JD5jGqifu3Ykx7WgXzPoR6Hulg48f5ZuizS08LG9VggRR+gAz9GNhl2co5Dg4Cyik1KGqNCHqaNVM6vBNw== +"@liatrio/react-dora-charts@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@liatrio/react-dora-charts/-/react-dora-charts-2.0.0.tgz#3421560ff01dfe9fa83d4c93d3d348ef0cea2d49" + integrity sha512-Mr8pna9m/emGlc1g/JYxPeZ8VJMixqjnI4ZxRBfx/rUNjLyhDaR66/dxIoK3oDf9X0eT080jeN1KB9h3BVEfqg== dependencies: js-yaml "^4.1.0" react-tooltip "^5.28.0"