ameliorate
ameliorate copied to clipboard
Show error if user uploads topic with invalid JSON
Describe the bug Users can upload any JSON file they want, and JSON that doesn't fit the diagram store's type will not work. Not a big deal since invalid JSON results in no change, but informing the user (and explicitly causing no change) would be good.
To Reproduce Steps to reproduce the behavior:
- Click upload button
- Select a JSON file that doesn't match the standard topic format
- Observe no message is displayed, and diagram does not change
Expected behavior Inform the user (probably dialog box) if a topic upload cannot be completed because the JSON is invalid.
Screenshots
Additional context Add any other context about the problem here.
Technical ideas Code where uploading is done
With some brief investigation, it seems like there's no easy way to use typescript types at runtime for validation. zod is a very popular validation library that is probably good enough, but it seems not quite ideal - it essentially requires inferring typescript types from a zod schema, OR creating a zod schema that matches your typescript types. It also seems a little overkill because it enables validating specific requirements beyond types (e.g. number than is within X range, string that's 5+ characters long, etc).
Maybe we can just try setting the topic data, and if the data doesn't change, we assume it failed and show an error.