-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add export for whole query result (#95)
* feat: add design for export * feat: implementing export results as file * using LF as default for vscode * feat: export row to csv --------- Co-authored-by: Ave Aristov <[email protected]>
- Loading branch information
1 parent
bf21b1b
commit ebebcf2
Showing
8 changed files
with
312 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"typescript.tsdk": "node_modules\\typescript\\lib" | ||
"typescript.tsdk": "node_modules\\typescript\\lib", | ||
"files.eol": "\n" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Button } from "../ui/button"; | ||
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue, | ||
} from "../ui/select"; | ||
import OptimizeTableState from "../table-optimized/OptimizeTableState"; | ||
import { useCallback, useState } from "react"; | ||
import { getFormatHandlers } from "@gui/lib/export-helper"; | ||
|
||
export default function ExportResultButton({ | ||
data, | ||
}: { | ||
data: OptimizeTableState; | ||
}) { | ||
const [format, setFormat] = useState<string | null>(null); | ||
|
||
const onExportClicked = useCallback(() => { | ||
if (!format) return; | ||
|
||
let content = ""; | ||
const headers = data.getHeaders().map((header) => header.name); | ||
const records = data | ||
.getAllRows() | ||
.map((row) => headers.map((header) => row.raw[header])); | ||
|
||
const tableName = "UnknownTable"; //TODO: replace with actual table name | ||
|
||
const formatHandlers = getFormatHandlers(records, headers, tableName); | ||
|
||
const handler = formatHandlers[format]; | ||
if (handler) { | ||
content = handler(); | ||
} | ||
|
||
const blob = new Blob([content], { type: "text/plain;charset=utf-8" }); | ||
const url = URL.createObjectURL(blob); | ||
const a = document.createElement("a"); | ||
a.href = url; | ||
a.download = `export.${format}`; | ||
a.click(); | ||
URL.revokeObjectURL(url); | ||
}, [format, data]); | ||
|
||
return ( | ||
<Popover> | ||
<PopoverTrigger> | ||
<Button variant="ghost" size={"sm"}> | ||
Export | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent className="p-0"> | ||
<div className="p-4"> | ||
<div className="mb-2 font-bold">Export</div> | ||
<Select onValueChange={setFormat}> | ||
<SelectTrigger> | ||
<SelectValue placeholder="Select export format" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
<SelectItem value="csv">CSV</SelectItem> | ||
<SelectItem value="json">JSON</SelectItem> | ||
<SelectItem value="sql">SQL</SelectItem> | ||
</SelectContent> | ||
</Select> | ||
</div> | ||
<div className="p-2 pt-0 px-4"> | ||
<Button size="sm" onClick={onExportClicked}> | ||
Export | ||
</Button> | ||
</div> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
} |
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
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
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,10 +1,10 @@ | ||
import "@libsqlstudio/gui/css"; | ||
import { Fragment } from "react"; | ||
|
||
export default async function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return <Fragment>{children}</Fragment>; | ||
} | ||
import "@libsqlstudio/gui/css"; | ||
import { Fragment } from "react"; | ||
|
||
export default async function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return <Fragment>{children}</Fragment>; | ||
} |
Oops, something went wrong.