-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
Pinging @elastic/kibana-app (Team:KibanaApp) |
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.
Code review only, presentation team changes LGTM!
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.
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', |
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.
Looks like the same typo in all the text you've added:
'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 |
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.
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.
You are right, the formula escape is not currently enabled outside Reporting. |
@elasticmachine merge upstream |
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.
Code changes LGTM!
Did a smoke test for reporting locally, worked as expected.
const detectedFormulasInTables = this.props.datatables.some(({ columns, rows }) => | ||
tableHasFormulas(columns, rows) | ||
); |
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.
It might be useful to memoize the result of this check and only re-run it when the datatables
prop has changed. WDYT?
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 did add the memoization on this specific instance. Or perhaps you meant something more generic like on the tableHasFormulas
function?
💚 Build SucceededMetrics [docs]Module Count
Public APIs missing comments
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
…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 <[email protected]>
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
…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 <[email protected]> Co-authored-by: Marco Liberati <[email protected]>
Summary
Fixes #56081
This PR unifies the escaping logic for both reporting and client side CSV export.
The
escape_value
module has moved to thedata
plugin, which now exposes a newescapeFormulaValues
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:
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