Files
Joshen Lim 6779bf52e1 Joshenlim/fe 4208 explorer templates need to be properly set up (#49322)
## Context

Set up Explorer templates properly for notebooks and chat. Tried (with
the help of Claude) to come up with templates that are generic enough
for most projects to sort of pick up and use, or even pick up to study
how notebooks are meant to be used.

Feel free to play around on the preview to check out the content of each
template! 🙂

<img width="768" height="232" alt="image"
src="https://github.com/user-attachments/assets/590893c4-9772-437d-980f-05ea62ffef81"
/>

<img width="1918" height="955" alt="image"
src="https://github.com/user-attachments/assets/2114e73e-dc44-403d-a998-e87c8d328516"
/>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added ready-to-use chat templates for sample data, security policies,
and notebook creation.
* Added notebook templates for database health, user growth, and error
investigation workflows.
* Explorer cards now dynamically create chats and notebooks from
selected templates.
* Templates include guided prompts, queries, logs, charts, and relevant
notebook content.
* **Bug Fixes**
* Improved generated log cell identifiers for more reliable notebook
creation.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-21 11:06:20 +08:00

92 lines
3.6 KiB
TypeScript

import { MessageSquarePlus, NotebookText, SquareCode } from 'lucide-react'
import { useState } from 'react'
import { useCreateChat, useCreateNotebook, useCreateQuery } from './hooks'
import { CHAT_TEMPLATES, NOTEBOOK_TEMPLATES } from './templates'
import { ActionCard } from '@/components/layouts/Tabs/ActionCard'
import { AssistantChatForm } from '@/components/ui/AIAssistantPanel/AssistantChatForm'
import type { AssistantModel } from '@/state/ai-assistant-state'
export const ExplorerHomeTab = () => {
const { createNotebook } = useCreateNotebook()
const { createQuery } = useCreateQuery()
const { createChat } = useCreateChat()
const [value, setValue] = useState<string>('')
const [selectedModel, setSelectedModal] = useState<AssistantModel>('gpt-5.4-nano')
return (
<div className="bg-surface-100 h-full flex flex-col items-center justify-center">
<div className="w-full max-w-2xl">
<div className="flex items-center justify-center flex-col gap-y-1 mb-12">
<h1 className="heading-section">Explore your project</h1>
<p className="text-foreground-lighter text-sm">
Ask the Assistant about your data, or begin with a new resource.
</p>
</div>
<AssistantChatForm
loading={false}
className="bg"
placeholder="Ask anything about your project"
value={value}
onValueChange={(e) => setValue(e.target.value)}
selectedModel={selectedModel}
onSelectModel={setSelectedModal}
onSubmit={(message) => createChat({ initialMessage: message, model: selectedModel })}
/>
<section className="mt-6">
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
<ActionCard
icon={<NotebookText className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
title="Create a notebook"
description="Combine notes, queries, and results"
bgColor="bg-blue-500"
onClick={() => createNotebook()}
/>
<ActionCard
icon={<SquareCode className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
title="Run SQL"
description="Write and run an ad-hoc query"
bgColor="bg-blue-500"
onClick={createQuery}
/>
</div>
</section>
<section className="mt-8 flex flex-col gap-y-3">
<h2 className="text-sm font-medium text-foreground">Start with a template</h2>
<div className="grid grid-cols-1 gap-3 sm:grid-cols-3">
{NOTEBOOK_TEMPLATES.map((template) => (
<ActionCard
key={template.title}
icon={<NotebookText className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
title={template.title}
description={template.description}
bgColor="bg-blue-500"
onClick={() =>
createNotebook({ name: template.title, cells: template.buildCells() })
}
/>
))}
{CHAT_TEMPLATES.map((template) => (
<ActionCard
key={template.title}
icon={<MessageSquarePlus className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
title={template.title}
description={template.description}
bgColor="bg-blue-500"
onClick={() =>
createChat({ name: template.title, initialMessage: template.initialMessage })
}
/>
))}
</div>
</section>
</div>
</div>
)
}