title generations

This commit is contained in:
Nate Kelley 2025-07-24 18:09:18 -06:00
parent 55679b9d19
commit 0c6271f5c9
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
7 changed files with 83 additions and 15 deletions

View File

@ -1,13 +1,4 @@
import { DashboardLayout } from '@/layouts/DashboardLayout';
import DashboardLayout, { generateMetadata } from '@dashboards/layout';
export default async function Layout({
children,
params
}: {
children: React.ReactNode;
params: Promise<{ dashboardId: string }>;
}) {
const { dashboardId } = await params;
return <DashboardLayout dashboardId={dashboardId}>{children}</DashboardLayout>;
}
export default DashboardLayout;
export { generateMetadata };

View File

@ -1,3 +1,4 @@
import MetricLayout from '@metrics/layout';
import MetricLayout, { generateMetadata } from '@metrics/layout';
export default MetricLayout;
export { generateMetadata };

View File

@ -0,0 +1,25 @@
import { getTitle_server } from '@/api/buster_rest/title';
export default function ChatLayout({ children }: { children: React.ReactNode }) {
return <>{children}</>;
}
export async function generateMetadata({ params }: { params: Promise<{ chatId: string }> }) {
const { chatId } = await params;
try {
const response = await getTitle_server({
assetId: chatId,
assetType: 'chat'
});
return {
title: response.title || 'New Chat'
};
} catch (error) {
console.error('Failed to fetch chat title:', error);
return {
title: 'New Chat'
};
}
}

View File

@ -1,3 +1,4 @@
import MetricLayout from '@metrics/layout';
import MetricLayout, { generateMetadata } from '@metrics/layout';
export default MetricLayout;
export { generateMetadata };

View File

@ -1,3 +1,4 @@
import { getTitle_server } from '@/api/buster_rest/title';
import { DashboardLayout } from '@/layouts/DashboardLayout';
export default async function Layout({
@ -11,3 +12,23 @@ export default async function Layout({
return <DashboardLayout dashboardId={dashboardId}>{children}</DashboardLayout>;
}
export async function generateMetadata({ params }: { params: Promise<{ dashboardId: string }> }) {
const { dashboardId } = await params;
try {
const response = await getTitle_server({
assetId: dashboardId,
assetType: 'dashboard'
});
return {
title: response.title || 'New Dashboard'
};
} catch (error) {
console.error('Failed to fetch dashboard title:', error);
return {
title: 'New Dashboard'
};
}
}

View File

@ -1,4 +1,6 @@
import { AppAssetCheckLayout } from '@/layouts/AppAssetCheckLayout';
import type { Metadata } from 'next';
import { getTitle_server } from '@/api/buster_rest/title';
export default async function MetricLayout({
children,
@ -15,3 +17,30 @@ export default async function MetricLayout({
</AppAssetCheckLayout>
);
}
// Generate metadata dynamically based on the metric - shared across all child pages
export async function generateMetadata({
params
}: {
params: Promise<{ metricId: string }>;
}): Promise<Metadata> {
const { metricId } = await params;
try {
// Fetch the metric title using the server-side request
const response = await getTitle_server({
assetId: metricId,
assetType: 'metric'
});
return {
title: response.title || 'New Metric'
};
} catch (error) {
// Fallback title if the request fails
console.error('Failed to fetch metric title:', error);
return {
title: 'New Metric'
};
}
}

View File

@ -13,7 +13,7 @@
"paths": {
"@/*": ["src/*"],
"@metrics/*": ["src/app/app/(primary_layout)/(chat_experience)/metrics/[metricId]/*"],
"@dashboards": ["src/app/app/(primary_layout)/(chat_experience)/dashboards/[dashboardId]/*"]
"@dashboards/*": ["src/app/app/(primary_layout)/(chat_experience)/dashboards/[dashboardId]/*"]
},
"plugins": [
{