这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions src/components/project/InsightsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ const lock = ref<boolean>(false);
/** Store the insights data */
const insightsData = ref<Record<string, InsightResponse> | null>(null);

/** Track whether insights are enabled for this service */
const isInsightsEnabled = ref<boolean | null>(null);

/** Chart configurations for each insight metric */
const charts = ref<Map<string, ChartConfig>>(new Map());

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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();
}
}
</script>

<template>
<Card>
<Card v-if="isInsightsEnabled === true">
<template #title>
<div class="flex items-center justify-between w-full">
<span>Insights</span>
Expand Down
11 changes: 11 additions & 0 deletions src/components/project/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,15 @@ export default class ProjectAPIService extends APIService {
throw error;
}
}

async checkInsightsEnabled(): Promise<boolean> {
try {
const response = await this.wsClient.get(`enabled-products/v1/log_explorer_insights/services/${this.service_id}`);
return response.status === 200 && response.data?.product?.id === 'log_explorer_insights';
} catch (error) {
// If we get a 404 or any error, insights are not enabled
console.error('Insights not enabled for this service:', error);
return false;
}
}
}