feat(export): add HTML export for query result grids
This commit is contained in:
1 parent
254b9baaff
commit
dc4764e930
21 files changed
+442
-5
No files matched your search
@@ -48,6 +48,7 @@ const FORMAT_META: Record<string, { ext: string; label: string }> = {
|
||||
xlsx: { ext: "xlsx", label: "Excel" },
|
||||
json: { ext: "json", label: "JSON" },
|
||||
markdown: { ext: "md", label: "Markdown" },
|
||||
html: { ext: "html", label: "HTML" },
|
||||
sql: { ext: "sql", label: "SQL" },
|
||||
txt: { ext: "txt", label: "Text" },
|
||||
};
|
||||
@@ -453,6 +454,10 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
return currentResultLabel?.value || tableMeta.value?.tableName || "Export";
|
||||
}
|
||||
|
||||
function currentExportTitle(): string {
|
||||
return tableMeta.value?.tableName || currentResultLabel?.value || "Query Result";
|
||||
}
|
||||
|
||||
function currentExportSql(): string | undefined {
|
||||
return resultExportSql?.value || sql.value;
|
||||
}
|
||||
@@ -985,6 +990,50 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
});
|
||||
}
|
||||
|
||||
async function exportHtml(rowIds?: number[]) {
|
||||
await runExclusiveExport(async () => {
|
||||
try {
|
||||
let outputPath = exportFileName("export", "html");
|
||||
if (isTauriRuntime()) {
|
||||
const { save } = await import("@tauri-apps/plugin-dialog");
|
||||
const path = await save({
|
||||
defaultPath: outputPath,
|
||||
filters: [{ name: "HTML", extensions: ["html"] }],
|
||||
});
|
||||
if (!path) return;
|
||||
outputPath = path as string;
|
||||
}
|
||||
const result = await resultToExport(rowIds);
|
||||
await api.exportQueryResultHtml(outputPath, currentExportTitle(), result.columns, result.rows);
|
||||
toast(t("grid.exported"));
|
||||
} catch (e: any) {
|
||||
toast(t("grid.exportFailed", { message: translateBackendError(t, e) }), 5000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function exportCurrentPageHtml() {
|
||||
await runExclusiveExport(async () => {
|
||||
try {
|
||||
let outputPath = exportFileName("export-page", "html", { page: true });
|
||||
if (isTauriRuntime()) {
|
||||
const { save } = await import("@tauri-apps/plugin-dialog");
|
||||
const path = await save({
|
||||
defaultPath: outputPath,
|
||||
filters: [{ name: "HTML", extensions: ["html"] }],
|
||||
});
|
||||
if (!path) return;
|
||||
outputPath = path as string;
|
||||
}
|
||||
const result = await resultToExport(undefined, undefined, false);
|
||||
await api.exportQueryResultHtml(outputPath, currentExportTitle(), result.columns, result.rows);
|
||||
toast(t("grid.exported"));
|
||||
} catch (e: any) {
|
||||
toast(t("grid.exportFailed", { message: translateBackendError(t, e) }), 5000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function exportCurrentPageTxt() {
|
||||
await runExclusiveExport(async () => {
|
||||
try {
|
||||
@@ -1599,6 +1648,8 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
exportCurrentPageJson,
|
||||
exportMarkdown,
|
||||
exportCurrentPageMarkdown,
|
||||
exportHtml,
|
||||
exportCurrentPageHtml,
|
||||
exportTxt,
|
||||
exportCurrentPageTxt,
|
||||
exportXlsx,
|
||||
|
||||
Reference in new issue
Block a user