vogievetsky commented on a change in pull request #10256:
URL: https://github.com/apache/druid/pull/10256#discussion_r467314056
##########
File path: web-console/src/components/json-input/json-input.tsx
##########
@@ -24,7 +24,9 @@ import AceEditor from 'react-ace';
import './json-input.scss';
function parseHjson(str: string) {
- return str === '' ? null : Hjson.parse(str);
+ // Throwing on empty input is more consistent with how JSON.parse works
Review comment:
When it can not parse the editor itself would keep the partial string
value inside of it - so nothing interesting would happen. The issue is when it
does parse... in simple terms this was the old problem:
Let say you were deleting text and you have `{` entered. Then you press
backspace.
The simplified logic flow would go like this:
- AceEditor: user has changed input to `''`
- JsonInput: `''` is valid JSON it parses to `null`, notify the parent
- DataLoader: user changed the spec to `null` that is not workable as a
spec, adjust it to `{}`
- JsonInput: adjusting the input to `"{}"`
- AceEditor: shows `{}` after you pressed backspace on `{`
Now it would go like this:
- AceEditor: user has changed input to `''`
- JsonInput: `''` is not valid JSON because it throws, keep waiting
- AceEditor: shows nothing
Note that `Hjson.parse({})` is `{}` so that is why we need to special case
white space only strings. If we were not being that fancy and using boring old
`JSON.parse` this would not be an issue as `JSON.parse` does not recognize `''`
as valid json.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]