Skip to content

Commit dd68452

Browse files
tea-artistteable-bot
andauthored
feat(api-dialog): improve API panel for AI and developers (T1480) (#943) (#2363)
Synced from teableio/teable-ee@44c8c3c Co-authored-by: teable-bot <[email protected]>
1 parent a466a71 commit dd68452

File tree

4 files changed

+42
-40
lines changed

4 files changed

+42
-40
lines changed

apps/nestjs-backend/src/types/i18n.generated.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2928,8 +2928,9 @@ export type I18nTranslations = {
29282928
"confirmExpiry": string;
29292929
"confirmButton": string;
29302930
"tokenInfo": string;
2931+
"tokenCreatedSuccess": string;
29312932
"copied": string;
2932-
"copyToClipboard": string;
2933+
"copy": string;
29332934
"advancedDesc": string;
29342935
"openAdvanced": string;
29352936
};

apps/nextjs-app/src/features/app/blocks/view/tool-bar/APIDialog.tsx

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getTableById,
88
type CreateAccessTokenVo,
99
} from '@teable/openapi';
10+
import { MarkdownPreview } from '@teable/sdk';
1011
import { useBaseId, useTableId } from '@teable/sdk/hooks';
1112
import {
1213
Button,
@@ -123,23 +124,6 @@ const generateAIContext = (
123124

124125
return `# Table: ${tableName}
125126
${tableDescription ? `\nDescription: ${tableDescription}\n` : ''}
126-
## Fields
127-
${fieldDescriptions}
128-
129-
## API Configuration
130-
- **Base URL**: ${baseUrl}
131-
- **Table ID**: ${tableId}
132-
- **API Token**: ${displayToken}
133-
- **Endpoint**: \`${baseUrl}/api/table/${tableId}/record\`
134-
135-
## Authentication
136-
All requests require the \`Authorization\` header:
137-
\`\`\`
138-
Authorization: Bearer ${displayToken}
139-
\`\`\`
140-
141-
---
142-
143127
## API Operations
144128
145129
### 1. Read Records (GET)
@@ -244,6 +228,25 @@ curl -X DELETE "${baseUrl}/api/table/${tableId}/record/{recordId}" \\
244228
245229
---
246230
231+
## API Configuration
232+
- **Base URL**: ${baseUrl}
233+
- **Table ID**: ${tableId}
234+
- **API Token**: ${displayToken}
235+
- **Endpoint**: \`${baseUrl}/api/table/${tableId}/record\`
236+
237+
## Authentication
238+
All requests require the \`Authorization\` header:
239+
\`\`\`
240+
Authorization: Bearer ${displayToken}
241+
\`\`\`
242+
243+
---
244+
245+
## Fields
246+
${fieldDescriptions}
247+
248+
---
249+
247250
## Notes for AI
248251
- Fields marked [PRIMARY] are the main identifier field
249252
- Fields marked [READ-ONLY] are computed and cannot be directly modified
@@ -351,17 +354,8 @@ export const APIDialog = ({ children }: APIDialogProps) => {
351354
);
352355
}, [tableInfo, fields, currentUrl, tableId, generatedToken]);
353356

354-
const handleCopy = useCallback(() => {
355-
const textArea = document.createElement('textarea');
356-
textArea.value = aiContext;
357-
textArea.style.position = 'fixed';
358-
textArea.style.left = '-999999px';
359-
textArea.style.top = '-999999px';
360-
document.body.appendChild(textArea);
361-
textArea.focus();
362-
textArea.select();
363-
document.execCommand('copy');
364-
document.body.removeChild(textArea);
357+
const handleCopy = useCallback(async () => {
358+
await navigator.clipboard.writeText(aiContext);
365359
setCopied(true);
366360
setTimeout(() => setCopied(false), 2000);
367361
}, [aiContext]);
@@ -372,7 +366,7 @@ export const APIDialog = ({ children }: APIDialogProps) => {
372366
return (
373367
<Dialog open={open} onOpenChange={setOpen}>
374368
<DialogTrigger asChild>{children}</DialogTrigger>
375-
<DialogContent className="max-h-[90vh] max-w-4xl">
369+
<DialogContent className="flex max-h-[90vh] max-w-4xl flex-col overflow-hidden">
376370
<DialogHeader>
377371
<DialogTitle className="flex items-center gap-2">
378372
<Code2 className="size-5" />
@@ -392,7 +386,7 @@ export const APIDialog = ({ children }: APIDialogProps) => {
392386
</TabsTrigger>
393387
</TabsList>
394388

395-
<TabsContent value="ai-context">
389+
<TabsContent value="ai-context" className="w-full overflow-hidden">
396390
{isDataLoading ? (
397391
<div className="flex h-64 items-center justify-center">
398392
<Loader2 className="size-8 animate-spin text-muted-foreground" />
@@ -413,11 +407,16 @@ export const APIDialog = ({ children }: APIDialogProps) => {
413407

414408
<div className="flex items-center justify-between gap-4">
415409
{generatedToken ? (
416-
<div className="flex items-center gap-2 text-sm text-green-600 dark:text-green-400">
417-
<Check className="size-4" />
418-
{t('table:toolbar.others.api.tokenInfo', {
419-
expiry: new Date(generatedToken.expiredTime).toLocaleDateString(),
420-
})}
410+
<div className="flex flex-col gap-1">
411+
<div className="flex items-center gap-2 text-sm text-green-600 dark:text-green-400">
412+
<Check className="size-4" />
413+
{t('table:toolbar.others.api.tokenCreatedSuccess')}
414+
</div>
415+
<div className="text-xs text-muted-foreground">
416+
{t('table:toolbar.others.api.tokenInfo', {
417+
expiry: new Date(generatedToken.expiredTime).toLocaleDateString(),
418+
})}
419+
</div>
421420
</div>
422421
) : (
423422
<Button
@@ -448,14 +447,14 @@ export const APIDialog = ({ children }: APIDialogProps) => {
448447
) : (
449448
<>
450449
<Copy className="size-4" />
451-
{t('table:toolbar.others.api.copyToClipboard')}
450+
{t('table:toolbar.others.api.copy')}
452451
</>
453452
)}
454453
</Button>
455454
</div>
456455

457456
<ScrollArea className="h-[400px] rounded-lg border bg-muted/20 p-4">
458-
<pre className="whitespace-pre-wrap text-sm">{aiContext}</pre>
457+
<MarkdownPreview>{aiContext}</MarkdownPreview>
459458
</ScrollArea>
460459
</div>
461460
)}

packages/common-i18n/src/locales/en/table.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
"confirmExpiry": "The token will be valid for 1 year.",
5454
"confirmButton": "Confirm & Create",
5555
"tokenInfo": "Token expires: {{expiry}}",
56+
"tokenCreatedSuccess": "Token created successfully! Click copy to use it with your AI assistant.",
5657
"copied": "Copied!",
57-
"copyToClipboard": "Copy to Clipboard",
58+
"copy": "Copy",
5859
"advancedDesc": "Open the advanced API query builder for more customization options.",
5960
"openAdvanced": "Open Query Builder"
6061
},

packages/common-i18n/src/locales/zh/table.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
"confirmExpiry": "Token 有效期为 1 年。",
5454
"confirmButton": "确认创建",
5555
"tokenInfo": "Token 过期时间:{{expiry}}",
56+
"tokenCreatedSuccess": "Token 创建成功!点击复制即可使用。",
5657
"copied": "已复制!",
57-
"copyToClipboard": "复制到剪贴板",
58+
"copy": "复制",
5859
"advancedDesc": "打开高级 API 查询构建器,获取更多自定义选项。",
5960
"openAdvanced": "打开查询构建器"
6061
},

0 commit comments

Comments
 (0)