Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON as an export option #173

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Add JSON as an export option #173

wants to merge 5 commits into from

Conversation

seanghay
Copy link
Contributor

This will export as an unformatted JSON file using JSON.stringify(data)

image

src/libs/SaveJSONFile.ts Outdated Show resolved Hide resolved
@seanghay seanghay requested a review from invisal October 21, 2023 13:01
@seanghay
Copy link
Contributor Author

@invisal please help to review it again.

Copy link
Collaborator

@invisal invisal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for delay review. Because there are some refactoring. This need to slightly change. You can follow the sample code of Copy As JSON

Comment on lines +9 to +20
export default function saveStructuredTextFile(
fileName: string,
type: SupportedStructuredFileType,
records: object[]
) {

const serializers = {
json: jsonSerializer,
}

fs.writeFileSync(fileName, serializers[type](records))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is overkill. We only need a single function that able to write text file.

@@ -213,6 +222,18 @@ export default function ExportModal({ data, onClose }: ExportModalProps) {
console.error(e);
setStage('ERROR');
});
} else if (format === "json") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can follow this for JSON

https://github.com/querymx/querym/blob/main/src/renderer/screens/DatabaseScreen/QueryResultViewer/useDataTableContextMenu.tsx#L81

We just need to do

jsonString = // can follow the above code;
window.electron.saveTextFile(fileName, jsonString);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants