Skip to content

Commit

Permalink
improve export reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
macjuul committed Dec 20, 2024
1 parent c5bdb40 commit 7ad1b1f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/adapter/browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ export class BrowserAdapter implements SurrealistAdapter {
_title: string,
defaultPath: string,
_filters: any,
content: () => Result<string | Blob | null>,
content: () => Result<string | Blob>,
): Promise<boolean> {
const result = await content();

if (!result) {
return false;
throw new Error("File is empty");
}

const file =
Expand Down Expand Up @@ -252,7 +252,7 @@ export class BrowserAdapter implements SurrealistAdapter {
config.connectionGroups.push({
id: INSTANCE_GROUP,
name: instanceConfig.groupName,
collapsed: instanceConfig.groupCollapsed
collapsed: instanceConfig.groupCollapsed,
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/adapter/desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class DesktopAdapter implements SurrealistAdapter {
const result = await content();

if (!result) {
return false;
throw new Error("File is empty");
}

if (typeof result === "string") {
Expand Down
11 changes: 8 additions & 3 deletions src/components/App/modals/data-export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useIntent } from "~/hooks/routing";
import { useTableNames } from "~/hooks/schema";
import { useStable } from "~/hooks/stable";
import { requestDatabaseExport } from "~/screens/surrealist/connection/connection";
import { showInfo, slugify } from "~/util/helpers";
import { showError, showInfo, slugify } from "~/util/helpers";
import { iconDownload } from "~/util/icons";
import { syncConnectionSchema } from "~/util/schema";

Expand Down Expand Up @@ -60,16 +60,21 @@ export function DataExportModal() {
[SURQL_FILTER],
async () => {
setIsExporting(true);
return (await requestDatabaseExport(config)) ?? null;
return requestDatabaseExport(config);
},
);

if (success) {
showInfo({
title: "Export",
subtitle: "Database export successfully created",
subtitle: "Database successfully exported",
});
}
} catch (err: any) {
showError({
title: "Export failed",
subtitle: err.message,
});
} finally {
setIsExporting(false);
openedHandle.close();
Expand Down
6 changes: 1 addition & 5 deletions src/screens/surrealist/connection/connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,7 @@ export async function requestDatabaseExport(config?: ExportOptions) {
const useModern = compareVersions(version, "2.1.0");

if (!connection || currentState !== "connected") {
showError({
title: "Failed to export",
subtitle: "You must be connected to the remote instance",
});
return;
throw new Error("Not connected to an instance");
}

if (useModern) {
Expand Down

0 comments on commit 7ad1b1f

Please sign in to comment.