Skip to content
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

Merged
merged 5 commits into from
Apr 13, 2021

Conversation

noahamac
Copy link
Contributor

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

  1. 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.
  2. 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?
  3. 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?

Follow up PR could replace Ace usage for RunIt response.

@google-cla google-cla bot added the cla: yes label Apr 13, 2021
@noahamac noahamac changed the title adds prism editor and implements for sdkdocs feat: adds prism editor and implements for sdkdocs Apr 13, 2021
display: table-cell;
`

export const PrismEditor: FC<PrismEditorProps> = ({
Copy link
Contributor Author

@noahamac noahamac Apr 13, 2021

Choose a reason for hiding this comment

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

  1. 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/ ?

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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)) {
Copy link
Contributor Author

@noahamac noahamac Apr 13, 2021

Choose a reason for hiding this comment

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

  1. 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?

Copy link
Contributor

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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. 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?

Copy link
Contributor Author

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

Copy link
Contributor

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?

@noahamac noahamac requested review from josephaxisa and jkaster and removed request for jkaster April 13, 2021 05:50
<Pre className={className} style={style}>
{tokens.map((line, i) => (
<Line key={i} {...getLineProps({ line, key: i })}>
<LineNo>{i + 1}</LineNo>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Do we like the line number? Can ditch this

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

@josephaxisa josephaxisa left a 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> = ({
Copy link
Contributor

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.

Comment on lines 70 to 75
const getPrismLanguage = (language: string) => {
if (language === 'golang') {
return 'go'
}
return language as Language
}
Copy link
Contributor

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>
Copy link
Contributor

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)) {
Copy link
Contributor

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" />
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor

@jkaster jkaster left a 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',
Copy link
Contributor

Choose a reason for hiding this comment

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

Default to prism?

Copy link
Contributor

@jkaster jkaster left a 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

@jkaster jkaster merged commit aea0424 into main Apr 13, 2021
@jkaster jkaster deleted the noahamac/introduces-prism-editor branch April 13, 2021 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants