diff --git a/src/components/project/InsightsCard.vue b/src/components/project/InsightsCard.vue index d915aaa..93230b9 100644 --- a/src/components/project/InsightsCard.vue +++ b/src/components/project/InsightsCard.vue @@ -65,6 +65,9 @@ const lock = ref(false); /** Store the insights data */ const insightsData = ref | null>(null); +/** Track whether insights are enabled for this service */ +const isInsightsEnabled = ref(null); + /** Chart configurations for each insight metric */ const charts = ref>(new Map()); @@ -98,12 +101,28 @@ const visualizations = [ ]; /** - * Component lifecycle hook - fetches initial data when component is mounted + * Component lifecycle hook - checks insights enablement and fetches initial data when component is mounted */ -onMounted(() => { - fetchInsights(); +onMounted(async () => { + await checkInsightsEnabledStatus(); + if (isInsightsEnabled.value) { + fetchInsights(); + } }); +/** + * Checks if insights are enabled for this service + */ +async function checkInsightsEnabledStatus() { + try { + const projectService = new ProjectAPIService(credentialsStore.getServiceId(), credentialsStore.getServiceToken()); + isInsightsEnabled.value = await projectService.checkInsightsEnabled(); + } catch (error) { + console.error('Error checking insights enabled status:', error); + isInsightsEnabled.value = false; + } +} + /** * Calculates start and end times based on selected time range */ @@ -866,19 +885,23 @@ function getColorForIndex(index: number, alpha: number = 1): string { * Manual refresh handler */ function handleRefresh() { - fetchInsights(); + if (isInsightsEnabled.value) { + fetchInsights(); + } } /** * Handle time range change */ function handleTimeRangeChange() { - fetchInsights(); + if (isInsightsEnabled.value) { + fetchInsights(); + } }