Conversation
|
Made the |
|
Pinging @elastic/kibana-app (Team:KibanaApp) |
|
@elasticmachine merge upstream |
| * | ||
| * @returns undefined (download) - Record\<string, string\> (only for testing) | ||
| */ | ||
| export function exportAsCSVs( |
There was a problem hiding this comment.
lets change this function so it doesn't download the file but just returns csv as a string, this way we can move the function to common and make it usable from server.
the download aspect of it should be moved to some other place (possibly share plugin) so that can be used for other things as well, as that download function would now just take filename and filecontent in.
There was a problem hiding this comment.
You proposing splitting this into two exportCSVs + download plugins?
There was a problem hiding this comment.
yes, two functions as converting to csv can be common and downloading can be used for other things beside csv as well.
|
@elasticmachine merge upstream |
| raw?: boolean; | ||
| } | ||
|
|
||
| function buildCSV( |
There was a problem hiding this comment.
lets rename this one to datatableToCSV and export it
| * | ||
| * @returns A dictionary of files to download: the key is the filename and the value the CSV string | ||
| */ | ||
| export function exportAsCSVs( |
There was a problem hiding this comment.
i am wondering if this function should be kept inside lens for now. how often will we want to convert multiple datatables at once ? also i am wondering if the reference to filename here should be omited but rather just use the datatable name ? @lukeelmers whats your opinion ?
There was a problem hiding this comment.
Mind that the DataTable type has no name property. The key:string passed for the record may be just internal ids (for instance in Lens it represents the layer id).
There was a problem hiding this comment.
As we move down the path of creating these various utility functions for datatables, I think it's important to have some consistency in how you interact with them. For any datatable utility function, I'd expect an interface similar to the following:
type SomeFn = (table: Datatable, options?: Record<string, whatever>) => Promise<Something> | Something;how often will we want to convert multiple datatables at once ?
For the sake of consistency, I would vote to make this function operate on a single table just like our other datatable helpers.
i am wondering if the reference to filename here should be omited but rather just use the datatable name
I think the concept of a filename is only here because the file download functionality was extracted from this function originally. IMHO it would make more sense to remove it and handle it when calling the download helper from the share plugin.
This would make the interface something like:
exportAsCsv(table: Datatable, options: CSVOptions) => string;Then Lens would handle calling it multiple times (for multiple tables), assigning a filename, and passing the output to the download helper.
To me this feels like the best way to make these utilities as decoupled as possible, and keeps the lens-specific stuff in lens. (And of course we can always revisit down the road if some of the lens logic is needed for a bunch of other apps)
flash1293
left a comment
There was a problem hiding this comment.
Tested in Firefox and works well for me. It would be super cool to have a functional test for that but I'm not sure whether that's possible with our current setup.
| state?: unknown; | ||
| }; | ||
| filters: PersistableFilter[]; | ||
| activeData?: TableInspectorAdapter; |
There was a problem hiding this comment.
Seems like this is a leftover
src/plugins/share/public/index.ts
Outdated
| import { SharePlugin } from './plugin'; | ||
|
|
||
| export { KibanaURL } from './kibana_url'; | ||
| export * from './lib/download_as'; |
There was a problem hiding this comment.
nit: We prefer to explicitly export named items from the top-level public/index.ts (instead of using export *)... that way we avoid accidentally leaking internal items into the public contract later.
| * | ||
| * @returns A dictionary of files to download: the key is the filename and the value the CSV string | ||
| */ | ||
| export function exportAsCSVs( |
There was a problem hiding this comment.
As we move down the path of creating these various utility functions for datatables, I think it's important to have some consistency in how you interact with them. For any datatable utility function, I'd expect an interface similar to the following:
type SomeFn = (table: Datatable, options?: Record<string, whatever>) => Promise<Something> | Something;how often will we want to convert multiple datatables at once ?
For the sake of consistency, I would vote to make this function operate on a single table just like our other datatable helpers.
i am wondering if the reference to filename here should be omited but rather just use the datatable name
I think the concept of a filename is only here because the file download functionality was extracted from this function originally. IMHO it would make more sense to remove it and handle it when calling the download helper from the share plugin.
This would make the interface something like:
exportAsCsv(table: Datatable, options: CSVOptions) => string;Then Lens would handle calling it multiple times (for multiple tables), assigning a filename, and passing the output to the download helper.
To me this feels like the best way to make these utilities as decoupled as possible, and keeps the lens-specific stuff in lens. (And of course we can always revisit down the road if some of the lens logic is needed for a bunch of other apps)
| * under the License. | ||
| */ | ||
|
|
||
| export * from './export_csv'; |
There was a problem hiding this comment.
If we make my proposed changes to exportAsCsv, then we could move this all to the common directory. (Maybe common/utils?) and export it from both public/index.ts and server/index.ts
src/plugins/data/public/index.ts
Outdated
| * Exporters (CSV) | ||
| */ | ||
|
|
||
| export * from './exports'; |
There was a problem hiding this comment.
Same comment re: using named exports from top-level public/index.ts and server/index.ts
@flash1293 added basic functional test :) |
💚 Build SucceededMetrics [docs]Module Count
Async chunks
Distributable file count
Page load bundle
History
To update your PR or re-run it, just comment with: |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
1 similar comment
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> # Conflicts: # src/plugins/data/server/server.api.md
Summary
First implementation of the CSV export feature for Lens.
datatableToCsvfunctiondataplugin +downloadshare pluginonData$callback and pass theactiveDatato the app, which in turns shows the buttonNote: the embeddable action will be implemented in a subsequent PR.
Fixes part of #74509
Open questions:
filename-N.csv). In [Lens] CSV export #74509 the suggestion was to use the postfix-Layer N(=>filename-Layer N.csv), which is a valid option. Is the- Layer Npostfix the final decision on that? ( Change in later on will be easy )Possible enhancement discussion (out of scope for this PR, but worth discussing):
Checklist
Delete any items that are not applicable to this PR.