-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from supabase-community/fix/csv-import-export-…
…theme fix: sql accordion theme for csv import/export messages
- Loading branch information
Showing
3 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,43 @@ | ||
import { ToolInvocation } from '~/lib/tools' | ||
import CodeAccordion from '../code-accordion' | ||
import { useMemo } from 'react' | ||
import { format } from 'sql-formatter' | ||
|
||
export type CsvExportProps = { | ||
toolInvocation: ToolInvocation<'importCsv'> | ||
} | ||
|
||
export default function CsvImport({ toolInvocation }: CsvExportProps) { | ||
const { sql } = toolInvocation.args | ||
|
||
const formattedSql = useMemo( | ||
() => | ||
format(sql, { | ||
language: 'postgresql', | ||
keywordCase: 'lower', | ||
identifierCase: 'lower', | ||
dataTypeCase: 'lower', | ||
functionCase: 'lower', | ||
}), | ||
[sql] | ||
) | ||
|
||
if (!('result' in toolInvocation)) { | ||
return null | ||
} | ||
|
||
const { result } = toolInvocation | ||
|
||
if (!result.success) { | ||
return <div className="bg-destructive-300 px-6 py-4 rounded-md">Error executing SQL</div> | ||
return ( | ||
<CodeAccordion | ||
title="Error executing SQL" | ||
language="sql" | ||
code={formattedSql} | ||
error={result.error} | ||
/> | ||
) | ||
} | ||
|
||
return <CodeAccordion title="Executed SQL" language="sql" code={toolInvocation.args.sql} /> | ||
return <CodeAccordion title="Executed SQL" language="sql" code={formattedSql} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters