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

Add required default markdown visState #38390

Merged
merged 5 commits into from Jun 17, 2019

Conversation

markov00
Copy link
Member

@markov00 markov00 commented Jun 7, 2019

Summary

The markdownVis expression has the markdown string property configured as required.The current implementation of the markdown vis doesn't have a default value (actually it's undefined) and this cause the error to be thrown when creating a new markdown vis.

I've fixed the issue in the following way:

  • I've applied a default value for the markdown string of the md visualization: always an empty string ''
  • I've added a check when creating the markdownVis expression to avoid throwing an error if the markdown is not a string.

fix #38127

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

The markdownVis expression has the markdown string property configured as required.The current implementation of the markdown vis doesn't have a default value (actually it's undefined) and this cause the error to be thrown when creating a new markdown vis.

fix elastic#38127
@markov00 markov00 added :AppArch bug Fixes for quality problems that affect the customer experience v7.2.0 v7.3.0 v8.0.0 labels Jun 7, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch

@markov00 markov00 added Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) Feature:Markdown Markdown visualization feature labels Jun 7, 2019
@markov00 markov00 requested a review from ppisljar June 7, 2019 10:08
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@@ -202,7 +202,7 @@ export const prepareString = (variable: string, data: string): string => {
return `${variable}='${escapeString(data)}' `;
};

export const escapeString = (data: string): string => {
export const escapeString = (data: string | string): string => {
Copy link
Member

Choose a reason for hiding this comment

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

is this added | string required, or can it be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

mmm let me remove this, sorry

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed on ddc1ecd

@@ -226,7 +226,10 @@ export const buildPipelineVisFunction: BuildPipelineVisFunction = {
},
markdown: visState => {
const { markdown, fontSize, openLinksInNewTab } = visState.params;
const escapedMarkdown = escapeString(markdown);
let escapedMarkdown = '';
if (typeof markdown === 'string' || markdown instanceof String) {
Copy link
Member

Choose a reason for hiding this comment

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

Now that the default value for markdown has been set to an empty string, is there ever a scenario where this wouldn't evaluate to true?

I understand having it as an extra precaution; mostly I'm just curious.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing prevents future changes to the markdown code to save null, undefined or numbers to the current markdown string object, so one check more is better than one more error.
There can also be the rare case where you changed manually the URL of a markdown and you created a malformed url like this:

http://localhost:5601/xhr/app/kibana#/visualize/create?type=markdown&_g=()&_a=(filters:!(),linked:!f,query:(language:kuery,query:''),uiState:(),vis:(aggs:!(),params:(fontSize:12,markdown:123,openLinksInNewTab:!f),title:'',type:markdown))

where the markdown test is a number instead of a string. Without that check, it will crash the page. In this case the markdown is also not visualized.
Similar if the url is changed with a boolean value.
As written: it's a rare case, but it's at least one more safety check for the escapeString function until we don't have a fully TS implementation of our code.

If you think it's not necessary I can remove that.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense! I don't think we need to remove it, mostly I was just curious about the cases you had in mind

@markov00 markov00 removed the v7.2.0 label Jun 10, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

@markov00
Copy link
Member Author

jenkins test this please

@elasticmachine
Copy link
Contributor

elasticmachine commented Jun 11, 2019

💔 Build Failed

[00:03:52]                       └- ✖ fail: "apis management rollup jobs actions start should throw a 400 Bad request if the job is already started"

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@markov00 markov00 merged commit 1c495ae into elastic:master Jun 17, 2019
@markov00 markov00 deleted the fix-markdown-pipeline branch June 17, 2019 13:45
markov00 added a commit to markov00/kibana that referenced this pull request Jun 17, 2019
The markdownVis expression has the markdown string property configured as required.The current implementation of the markdown vis doesn't have a default value (actually it's undefined) and this cause the error to be thrown when creating a new markdown vis.

fix elastic#38127
markov00 added a commit that referenced this pull request Jun 18, 2019
The markdownVis expression has the markdown string property configured as required.The current implementation of the markdown vis doesn't have a default value (actually it's undefined) and this cause the error to be thrown when creating a new markdown vis.

fix #38127
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) Feature:Markdown Markdown visualization feature release_note:fix v7.3.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Visualization - Cannot read property 'replace' of undefined - error seen in Markdown visualization.
3 participants