-
Notifications
You must be signed in to change notification settings - Fork 192
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
feat: adds prism editor and implements for sdkdocs #581
Conversation
display: table-cell; | ||
` | ||
|
||
export const PrismEditor: FC<PrismEditorProps> = ({ |
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.
- Where to move this? Looking to get those components out and function to a util file. Should be accessible for RunIt as well. Would like to be able to bring into Data Dict and Lookml Diagram at some point too. What's the overhead on making a new /packages/ ?
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.
Remember that RunIt
can be used on its own so this should live in RunIt
if it's needed there as we cannot have any @looker/api-explorer
dependencies in the @looker/run-it
package.
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.
And what if it needs to be used by both ApiExplorer and RunIt? (And DD and Lookml Diagram)? Are there are docs on creating a new packages item? Would this be a good candidate for that?
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.
If it needs to be used by both ApiExplorer and RunIt, like in this case, then it should live in RunIt. I don't believe we have any documentation on how to create a new package but I'd be happy to work on that with you
{line.map((token, key) => { | ||
const tokenProps = getTokenProps({ token, key }) | ||
const text = tokenProps.children | ||
if (pattern !== '' && text.includes(pattern)) { |
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.
- Search integration feedback. This is obviously unsophisticated, should we fuzzy match? Make case insensitive? Style a smaller token? Is it annoying that the main page zoomstotop? Should I add a prop to disable when searching?
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.
I don't think it's bad as is. There are times where it highlights the whole line and is a bit confusing but it's not a big deal. I do think we should open an issue to revisit highlighting across the whole app though because some of it got broken in the latest styling round
// import { Prism } from "prism-react-renderer" | ||
import dracula from 'prism-react-renderer/themes/dracula' | ||
|
||
// (typeof global !== "undefined" ? global : window).Prism = Prism |
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.
- I'm having a hard time finding ApiExplorer's node_modules for where to import this. And TS doesn't seem to like the global addition... Any thoughts?
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.
For some reason we need to do this for kotlin, c#, swift etc support https://www.npmjs.com/package/prism-react-renderer#faq
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.
I am not very familiar with how all things works under the hood. Maybe @bryans99 could chime in on this. Could we somehow lazy load the languages based on the user's sdk language preference?
<Pre className={className} style={style}> | ||
{tokens.map((line, i) => ( | ||
<Line key={i} {...getLineProps({ line, key: i })}> | ||
<LineNo>{i + 1}</LineNo> |
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.
- Do we like the line number? Can ditch this
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.
I don't have a preference
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.
Line number can be useful for people discussing the code. Let's leave it in until we have people asking to remove it. Or we add a toggle/config setting when we start supporting APIX config settings more fully.
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.
Nice progress! A few thoughts/comments below
display: table-cell; | ||
` | ||
|
||
export const PrismEditor: FC<PrismEditorProps> = ({ |
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.
Remember that RunIt
can be used on its own so this should live in RunIt
if it's needed there as we cannot have any @looker/api-explorer
dependencies in the @looker/run-it
package.
const getPrismLanguage = (language: string) => { | ||
if (language === 'golang') { | ||
return 'go' | ||
} | ||
return language as Language | ||
} |
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.
This is ok for now, but we can change the generator language/label to Go
in @looker/sdk-codegen
. It was changed to Golang
to avoid exactly this for Ace :)
<Pre className={className} style={style}> | ||
{tokens.map((line, i) => ( | ||
<Line key={i} {...getLineProps({ line, key: i })}> | ||
<LineNo>{i + 1}</LineNo> |
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.
I don't have a preference
{line.map((token, key) => { | ||
const tokenProps = getTokenProps({ token, key }) | ||
const text = tokenProps.children | ||
if (pattern !== '' && text.includes(pattern)) { |
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.
I don't think it's bad as is. There are times where it highlights the whole line and is a bit confusing but it's not a big deal. I do think we should open an issue to revisit highlighting across the whole app though because some of it got broken in the latest styling round
@@ -77,7 +77,7 @@ export const DocSDKs: FC<LanguageSDKProps> = ({ api, method, type }) => { | |||
: gen.declareType('', item as IType) | |||
return ( | |||
<TabPanel key={language}> | |||
<DocCode language={language} code={code} /> | |||
<DocCode language={language} code={code} editor="prism" /> |
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.
Perhaps the prop should say editor="ace"
for places where we are still using ace so that it's easier to find and replace later on. This is completely fine as is though, just throwing a suggestion out there.
// import { Prism } from "prism-react-renderer" | ||
import dracula from 'prism-react-renderer/themes/dracula' | ||
|
||
// (typeof global !== "undefined" ? global : window).Prism = Prism |
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.
I am not very familiar with how all things works under the hood. Maybe @bryans99 could chime in on this. Could we somehow lazy load the languages based on the user's sdk language preference?
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.
Minor feedback
} | ||
|
||
export const DocCode: FC<DocCodeProps> = ({ | ||
code, | ||
language = 'json', | ||
fontSize = 16, | ||
width = 'auto', | ||
editor = 'ace', |
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.
Default to prism
?
Co-authored-by: John Kaster <kaster@google.com>
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.
This is a good step in the right direction
Brought in the Prism editor by following the documentation very closely: https://www.npmjs.com/package/prism-react-renderer#usage and implementing for the SdkDocs component.
Also added integration with the search functionality.
https://looker.atlassian.net/browse/EMBED-1258
https://looker.atlassian.net/browse/EMBED-1154
Looking for advice on comments
Follow up PR could replace Ace usage for RunIt response.