-
Notifications
You must be signed in to change notification settings - Fork 364
Update UX on :style usage #1141
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,14 +75,15 @@ import { | |
| UnknownCommandError, | ||
| CouldNotFetchRemoteGuideError, | ||
| FetchURLError, | ||
| InvalidGrassError, | ||
| UnsupportedError | ||
| } from 'services/exceptions' | ||
| import { | ||
| parseHttpVerbCommand, | ||
| isValidURL | ||
| } from 'shared/modules/commands/helpers/http' | ||
| import { fetchRemoteGrass } from 'shared/modules/commands/helpers/grass' | ||
| import { parseGrass } from 'shared/services/grassUtils' | ||
| import { parseGrass, objToCss } from 'shared/services/grassUtils' | ||
| import { | ||
| shouldUseCypherThread, | ||
| getCmdChar, | ||
|
|
@@ -709,10 +710,12 @@ const availableCommands = [ | |
| name: 'style', | ||
| match: cmd => /^style(\s|$)/.test(cmd), | ||
| exec(action, cmdchar, put, store) { | ||
| const match = action.cmd.match(/:style\s*(\S.*)$/) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This regex didn't allow for style with newlines |
||
| let param = match && match[1] ? match[1] : '' | ||
| const param = action.cmd | ||
| .trim() | ||
| .split(':style')[1] | ||
| .trim() | ||
|
|
||
| if (param === '') { | ||
| function showGrass() { | ||
| const grassData = getGraphStyleData(store.getState()) | ||
| put( | ||
| frames.add({ | ||
|
|
@@ -722,41 +725,66 @@ const availableCommands = [ | |
| result: grassData | ||
| }) | ||
| ) | ||
| } else if (param === 'reset') { | ||
| put(updateGraphStyleData(null)) | ||
| } else if (isValidURL(param)) { | ||
| if (!param.startsWith('http')) { | ||
| param = `http://${param}` | ||
| } | ||
| } | ||
|
|
||
| function updateAndShowGrass(newGrass) { | ||
| put(updateGraphStyleData(newGrass)) | ||
| showGrass() | ||
| } | ||
|
|
||
| function putGrassErrorFrame(message) { | ||
| put( | ||
| frames.add({ | ||
| useDb: getUseDb(store.getState()), | ||
| ...action, | ||
| error: createErrorObject(InvalidGrassError, message), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a custom error screen for grass instead of sending "unknown error" |
||
| type: 'error' | ||
| }) | ||
| ) | ||
| } | ||
|
|
||
| if (param === '') { | ||
| showGrass() | ||
| return | ||
| } | ||
|
|
||
| if (param === 'reset') { | ||
| updateAndShowGrass(null) | ||
| return | ||
| } | ||
|
|
||
| if ( | ||
| isValidURL(param) && | ||
| param.includes('.') /* isValid url considers words like rest an url*/ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this comment suggesting
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, It would be clearer if i added quotes perhaps? Even better would be to update the isValidURL to use a better regex though. It was used in quite a lot of places so I wasn't comfortable doing the change when I wrote this. I could look into it now though |
||
| ) { | ||
| const url = param.startsWith('http') ? param : `http://${param}` | ||
| const whitelist = getRemoteContentHostnameWhitelist(store.getState()) | ||
|
|
||
| fetchRemoteGrass(param, whitelist) | ||
| .then(response => { | ||
| const parsedGrass = parseGrass(response) | ||
| if (parsedGrass) { | ||
| put(updateGraphStyleData(parsedGrass)) | ||
| updateAndShowGrass(parsedGrass) | ||
| } else { | ||
| put(showErrorMessage('Could not parse grass file')) | ||
| putGrassErrorFrame( | ||
| `Could not parse grass file containing: | ||
| ${response}` | ||
| ) | ||
| } | ||
| }) | ||
| .catch(e => { | ||
| const error = new Error(e) | ||
| put( | ||
| frames.add({ | ||
| useDb: getUseDb(store.getState()), | ||
| ...action, | ||
| error, | ||
| type: 'error' | ||
| }) | ||
| ) | ||
| }) | ||
| .catch(e => putGrassErrorFrame(e.message)) | ||
| return | ||
| } | ||
|
|
||
| // Some dummy data like 23432432 will parse as "valid grass" | ||
| // try to convert to css to see if actually valid | ||
| const parsedGrass = parseGrass(param) | ||
| const validGrass = objToCss(parsedGrass) | ||
| if (parsedGrass && validGrass) { | ||
| updateAndShowGrass(parsedGrass) | ||
| } else { | ||
| const parsedGrass = parseGrass(param) | ||
| if (parsedGrass) { | ||
| put(updateGraphStyleData(parsedGrass)) | ||
| } else { | ||
| put(showErrorMessage('Could not parse grass data')) | ||
| } | ||
| putGrassErrorFrame(`Could not parse grass data: | ||
| ${param}`) | ||
| } | ||
| } | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The best way I've found to solve the issue of
extractStatementsFromStringfrom cypher-codemirror can't parse grass is to avoid using it for style commands. We can't run style and some other command so it makes sense not to use multi-statement anyway. I'm not 100% happy with the magic string of ":style" and it's special handling to other commands though :/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not sure how 'special' situations are handled in Browser or if at all. The only comment I would have is whether a
@todocomment here makes sense too or adding:styleto some variable that holds non multi statement commands? May not be relevant, Im not sureThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the allow multi statement setting is turned on, some commands (including :style) can't be part of a multistatement but should still work on their own. The problem is that :style is parsed in such a way that browser thinks it's multiple statments, since cypher-code mirror util we have can't parse grass to split the commands properly. So i don't think the variable would be helping and I'm not sure what to even write in a todo comment.. I'll write it down and discuss with hane/emil when they get back