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(ui): Adding templating to code snippets #15671

Merged
merged 7 commits into from
Oct 31, 2019
Merged

Conversation

drdelambre
Copy link
Contributor

This is a prereq for #14924 and wanted to make sure that it was applied separately, as it is its own chunk of functionality.

Basically it wraps a CodeSnippet with a small templating language based on a crowd favorite: https://johnresig.com/blog/javascript-micro-templating/

so anytime you submit a string of Hello <%= planet %>, it will go off and look up the property planet from the value prop passed into the component. if that's not defined, it'll look up the property in the defaults prop. if THAT is not defined, it just writes undefined.

<TemplatedCodeSnippet
    template={ "Hello <%= planet %>" }
    values={{ planet: 'Mars' }}
    defaults={{ planet: 'World' }} />

^--- opens a CodeSnippet element with the text Hello Mars

@drdelambre drdelambre requested review from russorat and a team October 30, 2019 22:30
Copy link
Contributor

@hoorayimhelping hoorayimhelping left a comment

Choose a reason for hiding this comment

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

Feels like there is enough logic in this component to have tests for it. What do you think?

Edit: forgot to add: this is super clean!

template={executeQueryCodeSnippet}
label="Java Code"
defaults={{
bucket: 'my_bucket',
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be bucketID and orgID for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was going to start standardizing those, but at the same time have a plan to connect them all to redux state in a little bit to give them MORE consistency. like site wide, frontend <=> backend consistency. so.... yes, but meh?

Copy link
Contributor

Choose a reason for hiding this comment

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

so.... yes, but meh

pretty much perfectly sums up software engineering, circa 2019.

👍

@ErrorHandling
class TemplatedCodeSnippet extends PureComponent<Props> {
// NOTE: this is just a simplified form of the resig classic:
// https://johnresig.com/blog/javascript-micro-templating/
Copy link
Contributor

Choose a reason for hiding this comment

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

🤙 dig this comment

@drdelambre
Copy link
Contributor Author

yeah, you're probably right. at least the templating function + object.assigns. ON IT

Alex Boatwright added 5 commits October 30, 2019 20:22
Merge branch 'master' of github.com:influxdata/influxdb into alex_templated_snippets
Merge branch 'master' of github.com:influxdata/influxdb into alex_templated_snippets
Copy link
Contributor

@hoorayimhelping hoorayimhelping left a comment

Choose a reason for hiding this comment

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

hot diggity daffodil, good stuff!

template={executeQueryCodeSnippet}
label="Java Code"
defaults={{
bucket: 'my_bucket',
Copy link
Contributor

Choose a reason for hiding this comment

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

so.... yes, but meh

pretty much perfectly sums up software engineering, circa 2019.

👍

})

const template = 'this is only a <%= word %>'
const response = 'this is only a sentance'
Copy link
Contributor

Choose a reason for hiding this comment

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

defanately keep this in.

@drdelambre drdelambre merged commit e9e0dfc into master Oct 31, 2019
@drdelambre drdelambre deleted the alex_templated_snippets branch November 8, 2019 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants