Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

feat: added json validation and import error modal #25

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

Conversation

vinhvn
Copy link
Contributor

@vinhvn vinhvn commented Sep 9, 2021

Closes #15

Preview:
BldMd1RL7R

I redid the file imports to map a filename to its FeatureCollection so we always have a reference to the file path, which is then passed onto the App. Here, files are filtered into a valid and invalid group using a rigorous and terrible method (very open to suggestions). All valid geo json are passed in as usual. If any invalid files are found, a modal is opened that lists their corresponding file paths. To close the modal, users can click the "x" icon or click outside of the modal.

Tested on an empty directory, a directory containing a half-empty json and a working geo json, and a directory containing working geo json files.

@vinhvn vinhvn self-assigned this Sep 9, 2021
@vinhvn vinhvn added the enhancement New feature or request label Sep 9, 2021
@vinhvn vinhvn marked this pull request as ready for review September 9, 2021 18:45
src/App.tsx Outdated Show resolved Hide resolved
src/util/validateJson.ts Show resolved Hide resolved
src/util/validateJson.ts Outdated Show resolved Hide resolved
src/util/validateJson.ts Outdated Show resolved Hide resolved
src/util/validateJson.ts Outdated Show resolved Hide resolved
@dellisd
Copy link
Member

dellisd commented Sep 10, 2021

In general, this looks great. I'm a fan of listing the files that weren't able to load, and loading the ones that can 👍

@dellisd
Copy link
Member

dellisd commented Sep 10, 2021

We could consider using a JSON Schema validator. There are pre-written schemas for GeoJSON out there, and lots of libraries that can validate JSON files (plus they can provide detailed parsing error messages!)

electron/main.ts Outdated Show resolved Hide resolved
src/Modal.tsx Outdated Show resolved Hide resolved
Comment on lines +85 to +90
{errorFiles.length > 0 ? (
<FileErrorModal
onClose={() => setErrorFiles([])}
files={errorFiles}
/>
) : null}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{errorFiles.length > 0 ? (
<FileErrorModal
onClose={() => setErrorFiles([])}
files={errorFiles}
/>
) : null}
{errorFiles.length > 0 && (
<FileErrorModal
onClose={() => setErrorFiles([])}
files={errorFiles}
/>
)}

Comment on lines +16 to +17
<ErrorHeader>There was an error importing some files.</ErrorHeader>
<ErrorText>Files that could not be imported:</ErrorText>
Copy link
Member

Choose a reason for hiding this comment

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

We should add a header and description value to FileErrorModalProps to make it easier to reuse in the future.

Comment on lines +18 to +22
<ErrorList>
{files.map((file, i) => (
<ErrorItem key={`${file}-${i}`}>{file}</ErrorItem>
))}
</ErrorList>
Copy link
Member

Choose a reason for hiding this comment

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

Likewise for the error content, the list could be specified via a prop.

@@ -0,0 +1,455 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

Just for naming, could we move this file to FeatureCollection.schema.json?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add data validation
3 participants