Skip to content

Commit 7db4cdf

Browse files
committed
fix: sql accordion theme for csv import/export messages
1 parent f3eef14 commit 7db4cdf

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

apps/postgres-new/components/tools/csv-export.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { m } from 'framer-motion'
22
import { Download } from 'lucide-react'
3+
import { useMemo } from 'react'
4+
import { format } from 'sql-formatter'
35
import { loadFile } from '~/lib/files'
46
import { ToolInvocation } from '~/lib/tools'
57
import { downloadFile } from '~/lib/util'
@@ -10,19 +12,40 @@ export type CsvExportProps = {
1012
}
1113

1214
export default function CsvExport({ toolInvocation }: CsvExportProps) {
15+
const { sql } = toolInvocation.args
16+
17+
const formattedSql = useMemo(
18+
() =>
19+
format(sql, {
20+
language: 'postgresql',
21+
keywordCase: 'lower',
22+
identifierCase: 'lower',
23+
dataTypeCase: 'lower',
24+
functionCase: 'lower',
25+
}),
26+
[sql]
27+
)
28+
1329
if (!('result' in toolInvocation)) {
1430
return null
1531
}
1632

1733
const { result } = toolInvocation
1834

1935
if (!result.success) {
20-
return <div className="bg-destructive-300 px-6 py-4 rounded-md">Error executing SQL</div>
36+
return (
37+
<CodeAccordion
38+
title="Error executing SQL"
39+
language="sql"
40+
code={formattedSql}
41+
error={result.error}
42+
/>
43+
)
2144
}
2245

2346
return (
2447
<>
25-
<CodeAccordion title="Executed SQL" language="sql" code={toolInvocation.args.sql} />
48+
<CodeAccordion title="Executed SQL" language="sql" code={formattedSql} />
2649
<m.div
2750
layoutId={toolInvocation.toolCallId}
2851
className="self-start px-5 py-2.5 text-base rounded-full bg-border flex gap-2 items-center text-lighter italic"
Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
11
import { ToolInvocation } from '~/lib/tools'
22
import CodeAccordion from '../code-accordion'
3+
import { useMemo } from 'react'
4+
import { format } from 'sql-formatter'
35

46
export type CsvExportProps = {
57
toolInvocation: ToolInvocation<'importCsv'>
68
}
79

810
export default function CsvImport({ toolInvocation }: CsvExportProps) {
11+
const { sql } = toolInvocation.args
12+
13+
const formattedSql = useMemo(
14+
() =>
15+
format(sql, {
16+
language: 'postgresql',
17+
keywordCase: 'lower',
18+
identifierCase: 'lower',
19+
dataTypeCase: 'lower',
20+
functionCase: 'lower',
21+
}),
22+
[sql]
23+
)
24+
925
if (!('result' in toolInvocation)) {
1026
return null
1127
}
1228

1329
const { result } = toolInvocation
1430

1531
if (!result.success) {
16-
return <div className="bg-destructive-300 px-6 py-4 rounded-md">Error executing SQL</div>
32+
return (
33+
<CodeAccordion
34+
title="Error executing SQL"
35+
language="sql"
36+
code={formattedSql}
37+
error={result.error}
38+
/>
39+
)
1740
}
1841

19-
return <CodeAccordion title="Executed SQL" language="sql" code={toolInvocation.args.sql} />
42+
return <CodeAccordion title="Executed SQL" language="sql" code={formattedSql} />
2043
}

apps/postgres-new/components/tools/executed-sql.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ export default function ExecutedSql({ toolInvocation }: ExecutedSqlProps) {
2626
return null
2727
}
2828

29-
if (!toolInvocation.result.success) {
29+
const { result } = toolInvocation
30+
31+
if (!result.success) {
3032
return (
3133
<CodeAccordion
3234
title="Error executing SQL"
3335
language="sql"
3436
code={formattedSql}
35-
error={toolInvocation.result.error}
37+
error={result.error}
3638
/>
3739
)
3840
}

0 commit comments

Comments
 (0)