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

[Lens][Visualize][Inspector][Reporting] Unified check for CSV cells for known formula characters (and value escaping more in general) #105221

Merged
merged 9 commits into from
Jul 16, 2021

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Jul 12, 2021

Summary

Fixes #56081

This PR unifies the escaping logic for both reporting and client side CSV export.
The escape_value module has moved to the data plugin, which now exposes a new escapeFormulaValues flag to enable the new formula check.

In addition on top of this refactor a new tableHasFormulas function has been created which is used to provide visual feedback to the user when the exported table contains formula special characters.

Tested downloads:

  • Lens
  • Visualize data table
  • Inspector download
  • Reporting (already in place prior to this PR)

Screenshot 2021-07-12 at 14 52 35

Screenshot 2021-07-12 at 15 02 08

Screenshot 2021-07-12 at 15 02 35

Screenshot 2021-07-12 at 14 58 23

Note

The download button on the Dashboard contextual menu does not have a warning tooltip: should it be added?
Is tooltip on context menu buttons a valid UI pattern?
It's already used for Visualize data table but unsure about general approach here.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@dej611 dej611 added Feature:Data Table Data table visualization feature Feature:Inspector Inspector infrastructure and implementations (Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 Feature:Lens auto-backport Deprecated: Automatically backport this PR after it's merged v7.15.0 labels Jul 12, 2021
@dej611 dej611 marked this pull request as ready for review July 13, 2021 10:52
@dej611 dej611 requested a review from a team July 13, 2021 10:52
@dej611 dej611 requested review from a team as code owners July 13, 2021 10:52
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

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

Code review only, presentation team changes LGTM!

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

So I've tested with xpack.reporting.csv.escapeFormulaValues on and found that it does correctly escape when using the CSV Reporting feature, but not when using the other CSV export options. I also saw that the tooltips are correctly warning about CSV formulas. So even if this is working as expected, I'd like a followup to see how we want to deal with formula escaping across all CSVs.

position="top"
content={i18n.translate('visTypeTable.vis.controls.exportButtonFormulasWarning', {
defaultMessage:
'Your CSV contains characters which spreadsheet application can interpret as formulas',
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the same typo in all the text you've added:

Suggested change
'Your CSV contains characters which spreadsheet application can interpret as formulas',
'Your CSV contains characters which spreadsheet applications can interpret as formulas',

formatFactory: FormatFactory;
raw?: boolean;
}

export function datatableToCSV(
{ columns, rows }: Datatable,
{ csvSeparator, quoteValues, formatFactory, raw }: CSVOptions
{ csvSeparator, quoteValues, formatFactory, raw, escapeFormulaValues = false }: CSVOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this a required argument instead? I found it hard to trace the code that is using the default value here vs actually providing a value. It looks like only the Reporting integration has a way to escape formulas, with the xpack.reporting.csv.escapeFormulaValues setting, and I was expecting that other places in the code would also use escaping.

@dej611
Copy link
Contributor Author

dej611 commented Jul 14, 2021

So I've tested with xpack.reporting.csv.escapeFormulaValues on and found that it does correctly escape when using the CSV Reporting feature, but not when using the other CSV export options. I also saw that the tooltips are correctly warning about CSV formulas. So even if this is working as expected, I'd like a followup to see how we want to deal with formula escaping across all CSVs.

You are right, the formula escape is not currently enabled outside Reporting.
Next step here is to figure out how to expose the escape option to the user and enable the feature, I'll create an issue about that.

@jloleysens
Copy link
Contributor

@elasticmachine merge upstream

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

Code changes LGTM!

Did a smoke test for reporting locally, worked as expected.

Comment on lines 106 to 108
const detectedFormulasInTables = this.props.datatables.some(({ columns, rows }) =>
tableHasFormulas(columns, rows)
);
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be useful to memoize the result of this check and only re-run it when the datatables prop has changed. WDYT?

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 did add the memoization on this specific instance. Or perhaps you meant something more generic like on the tableHasFormulas function?

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
data 588 591 +3

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
data 3259 3273 +14

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
data 164.4KB 165.1KB +718.0B
lens 1.5MB 1.5MB +479.0B
visTypeTable 102.2KB 102.7KB +492.0B
total +1.6KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
dashboard 329.2KB 329.2KB +23.0B
data 840.0KB 841.4KB +1.4KB
total +1.5KB
Unknown metric groups

API count

id before after diff
data 3825 3839 +14

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@dej611 dej611 merged commit 2e5e4ca into elastic:master Jul 16, 2021
@dej611 dej611 deleted the fix/56081 branch July 16, 2021 08:55
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Jul 16, 2021
…or known formula characters (and value escaping more in general) (elastic#105221)

* ✨ Unify escaping logic for csv export

* 📝 Update api doc

* ✅ Fix test with new escape logic

* 👌 First batch of feedback

* 💬 Fix typo

* 👌 Memoize function

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Jul 16, 2021
…or known formula characters (and value escaping more in general) (#105221) (#105925)

* ✨ Unify escaping logic for csv export

* 📝 Update api doc

* ✅ Fix test with new escape logic

* 👌 First batch of feedback

* 💬 Fix typo

* 👌 Memoize function

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated: Automatically backport this PR after it's merged (Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead Feature:Data Table Data table visualization feature Feature:Inspector Inspector infrastructure and implementations Feature:Lens release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.15.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Data Table - CSV export formulas warning
6 participants