Skip to content

Commit ec7df82

Browse files
committed
chore: fixup
1 parent 6c3190c commit ec7df82

File tree

3 files changed

+5
-592
lines changed

3 files changed

+5
-592
lines changed

packages/app-kit-ui/CLAUDE.md

Lines changed: 2 additions & 318 deletions
Original file line numberDiff line numberDiff line change
@@ -1,319 +1,3 @@
1-
# CLAUDE.md - @databricks/app-kit-ui
2-
3-
AI assistant guidance for the Databricks AppKit UI component library.
4-
5-
## Overview
6-
7-
`@databricks/app-kit-ui` provides React components and JavaScript utilities for building Databricks application frontends. It includes data visualization charts, data tables, and SSE utilities that integrate seamlessly with the `@databricks/app-kit` backend.
8-
9-
## Installation & Imports
10-
11-
```typescript
12-
// React components
13-
import { BarChart, LineChart, DataTable, useAnalyticsQuery } from "@databricks/app-kit-ui/react";
14-
15-
// JavaScript utilities (SSE, SQL helpers)
16-
import { connectSSE, sql } from "@databricks/app-kit-ui/js";
17-
18-
// Global styles (include in your app entry)
19-
import "@databricks/app-kit-ui/styles.css";
20-
```
21-
22-
## Chart Components
23-
24-
All charts integrate with the analytics backend via `queryKey` and support two modes:
25-
- **Opinionated mode**: Automatic field detection and rendering
26-
- **Full control mode**: Pass children for custom Recharts configuration
27-
28-
### BarChart
29-
30-
```tsx
31-
import { BarChart } from "@databricks/app-kit-ui/react";
32-
33-
// Opinionated mode - auto-detects x/y fields
34-
<BarChart
35-
queryKey="top_contributors"
36-
parameters={{ limit: 10 }}
37-
/>
38-
39-
// Horizontal orientation
40-
<BarChart
41-
queryKey="top_contributors"
42-
parameters={{ limit: 10 }}
43-
orientation="horizontal"
44-
/>
45-
46-
// With data transformation
47-
<BarChart
48-
queryKey="top_contributors"
49-
parameters={{ limit: 10 }}
50-
transformer={(data) => data.map(d => ({ name: d.user, count: d.total }))}
51-
/>
52-
53-
// Full control mode
54-
<BarChart queryKey="top_contributors" parameters={{ limit: 10 }}>
55-
<Bar dataKey="value" fill="var(--color-primary)" />
56-
<XAxis dataKey="name" />
57-
</BarChart>
58-
```
59-
60-
### LineChart
61-
62-
```tsx
63-
import { LineChart } from "@databricks/app-kit-ui/react";
64-
65-
<LineChart
66-
queryKey="daily_metrics"
67-
parameters={{ days: 30 }}
68-
height="400px"
69-
/>
70-
```
71-
72-
### AreaChart
73-
74-
```tsx
75-
import { AreaChart } from "@databricks/app-kit-ui/react";
76-
77-
<AreaChart
78-
queryKey="hourly_traffic"
79-
parameters={{ hours: 24 }}
80-
/>
81-
```
82-
83-
### PieChart
84-
85-
```tsx
86-
import { PieChart } from "@databricks/app-kit-ui/react";
87-
88-
<PieChart
89-
queryKey="category_breakdown"
90-
parameters={{ year: 2024 }}
91-
/>
92-
```
93-
94-
### RadarChart
95-
96-
```tsx
97-
import { RadarChart } from "@databricks/app-kit-ui/react";
98-
99-
<RadarChart
100-
queryKey="skill_assessment"
101-
parameters={{ userId: "123" }}
102-
/>
103-
```
104-
105-
### Common Chart Props
106-
107-
| Prop | Type | Description |
108-
|------|------|-------------|
109-
| `queryKey` | `string` | Analytics query identifier (maps to `config/queries/*.sql`) |
110-
| `parameters` | `object` | Query parameters |
111-
| `transformer` | `(data) => data` | Transform data before rendering |
112-
| `height` | `string` | Chart height (default: "300px") |
113-
| `orientation` | `"vertical" \| "horizontal"` | Bar chart orientation |
114-
| `chartConfig` | `ChartConfig` | Custom Recharts config |
115-
| `ariaLabel` | `string` | Accessibility label |
116-
| `testId` | `string` | Test ID attribute |
117-
| `className` | `string` | Additional CSS classes |
118-
119-
## DataTable Component
120-
121-
Production-ready data table with automatic data fetching, filtering, sorting, and pagination:
122-
123-
```tsx
124-
import { DataTable } from "@databricks/app-kit-ui/react";
125-
126-
// Opinionated mode
127-
<DataTable
128-
queryKey="users_list"
129-
parameters={{ status: "active" }}
130-
filterColumn="email"
131-
filterPlaceholder="Filter by email..."
132-
pageSize={25}
133-
/>
134-
135-
// With row selection
136-
<DataTable
137-
queryKey="orders_list"
138-
parameters={{}}
139-
enableRowSelection
140-
onRowSelectionChange={(selection) => console.log(selection)}
141-
/>
142-
143-
// Full control mode
144-
<DataTable queryKey="users_list" parameters={{}}>
145-
{(table) => (
146-
<div>
147-
{table.getRowModel().rows.map(row => (
148-
<div key={row.id}>{row.original.name}</div>
149-
))}
150-
</div>
151-
)}
152-
</DataTable>
153-
```
154-
155-
### DataTable Props
156-
157-
| Prop | Type | Description |
158-
|------|------|-------------|
159-
| `queryKey` | `string` | Analytics query identifier |
160-
| `parameters` | `object` | Query parameters |
161-
| `filterColumn` | `string` | Column to filter by (auto-detected if not set) |
162-
| `filterPlaceholder` | `string` | Filter input placeholder |
163-
| `transform` | `(data) => data` | Transform data before rendering |
164-
| `pageSize` | `number` | Rows per page (default: 10) |
165-
| `pageSizeOptions` | `number[]` | Page size options (default: [10, 25, 50, 100]) |
166-
| `enableRowSelection` | `boolean` | Enable row selection checkboxes |
167-
| `onRowSelectionChange` | `(selection) => void` | Row selection callback |
168-
| `labels` | `DataTableLabels` | Customize UI labels |
169-
170-
## Hooks
171-
172-
### useAnalyticsQuery
173-
174-
Subscribe to analytics queries via SSE with automatic state management:
175-
176-
```tsx
177-
import { useAnalyticsQuery } from "@databricks/app-kit-ui/react";
178-
179-
function UserList() {
180-
const { data, loading, error } = useAnalyticsQuery(
181-
"users_list", // queryKey
182-
{ status: "active" }, // parameters
183-
{ autoStart: true } // options
184-
);
185-
186-
if (loading) return <div>Loading...</div>;
187-
if (error) return <div>Error: {error}</div>;
188-
189-
return (
190-
<ul>
191-
{data?.map(user => <li key={user.id}>{user.name}</li>)}
192-
</ul>
193-
);
194-
}
195-
```
196-
197-
### useChartData
198-
199-
Lower-level hook for fetching chart data:
200-
201-
```tsx
202-
import { useChartData } from "@databricks/app-kit-ui/react";
203-
204-
const { data, loading, error } = useChartData({
205-
queryKey: "metrics",
206-
parameters: { days: 30 },
207-
transformer: (raw) => raw.filter(d => d.value > 0),
208-
});
209-
```
210-
211-
## SSE Utilities (JavaScript)
212-
213-
### connectSSE
214-
215-
Connect to SSE endpoints with automatic retries:
216-
217-
```typescript
218-
import { connectSSE } from "@databricks/app-kit-ui/js";
219-
220-
await connectSSE({
221-
url: "/api/stream/events",
222-
payload: { filter: "important" }, // Optional POST body
223-
onMessage: (message) => {
224-
console.log("Received:", JSON.parse(message.data));
225-
},
226-
onError: (error) => {
227-
console.error("SSE error:", error);
228-
},
229-
signal: abortController.signal,
230-
maxRetries: 3,
231-
retryDelay: 2000,
232-
timeout: 300000,
233-
});
234-
```
235-
236-
### SQL Type Markers
237-
238-
Type-safe SQL parameter helpers:
239-
240-
```typescript
241-
import { sql } from "@databricks/app-kit-ui/js";
242-
243-
const params = {
244-
userId: sql.string("user-123"),
245-
createdAt: sql.timestamp(new Date()),
246-
isActive: sql.boolean(true),
247-
count: sql.number(42),
248-
};
249-
```
250-
251-
## Styling
252-
253-
### CSS Variables
254-
255-
The library uses CSS variables for theming. Include the base styles:
256-
257-
```tsx
258-
// In your app entry (e.g., main.tsx)
259-
import "@databricks/app-kit-ui/styles.css";
260-
```
261-
262-
### Tailwind Integration
263-
264-
Components use Tailwind CSS classes. Extend your `tailwind.config.ts`:
265-
266-
```typescript
267-
export default {
268-
content: [
269-
"./src/**/*.{js,ts,jsx,tsx}",
270-
"./node_modules/@databricks/app-kit-ui/dist/**/*.{js,mjs}",
271-
],
272-
theme: {
273-
extend: {
274-
colors: {
275-
border: "hsl(var(--border))",
276-
background: "hsl(var(--background))",
277-
foreground: "hsl(var(--foreground))",
278-
primary: "hsl(var(--primary))",
279-
// ... other theme colors
280-
},
281-
},
282-
},
283-
};
284-
```
285-
286-
## Integration with app-kit Backend
287-
288-
Charts and tables automatically connect to `@databricks/app-kit` analytics endpoints:
289-
290-
```
291-
Frontend Backend
292-
──────── ───────
293-
<BarChart queryKey="sales" />
294-
295-
└─► POST /api/analytics/query/sales
296-
297-
└─► config/queries/sales.sql
298-
299-
└─► SQL Warehouse
300-
```
301-
302-
**Query files** are stored in `config/queries/<queryKey>.sql` on the backend.
303-
304-
## Best Practices
305-
306-
1. **Always include styles**: Import `@databricks/app-kit-ui/styles.css` in your app entry
307-
2. **Use queryKey naming**: Match `queryKey` props to SQL file names in `config/queries/`
308-
3. **Handle loading states**: All components handle loading/error states, but you can customize
309-
4. **Prefer opinionated mode**: Start with auto-detection, switch to full control when needed
310-
5. **Use transformers**: Apply data transformations via `transformer`/`transform` props, not in render
311-
312-
## Anti-Patterns
313-
314-
- Do not import from internal paths (e.g., `@databricks/app-kit-ui/dist/...`)
315-
- Do not skip the styles import (components may render incorrectly)
316-
- Do not use inline SQL in parameters (SQL lives in backend query files)
317-
- Do not call hooks conditionally (React rules apply)
318-
- Do not mutate data in transformers (return new arrays/objects)
1+
# CLAUDE.md - @databricks/appkit-ui
3192

3+
## TBD

0 commit comments

Comments
 (0)