-
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
Png #77930
Png #77930
Conversation
💔 Build Failed
Failed CI StepsBuild metrics@kbn/optimizer bundle module count
page load bundle size
To update your PR or re-run it, just comment with: |
@streamich The description still says WIP, but the PR isn't in draft mode - is this ready to review? Also, is there an issue for this feature for more context? |
@@ -207,6 +209,9 @@ export class Embeddable extends AbstractEmbeddable<LensEmbeddableInput, LensEmbe | |||
embeddable: this, | |||
}); | |||
} | |||
if (isLensControlsEvent(event)) { | |||
this.chartControls = event.data; |
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.
A bit weird seeing events pipeline used for this.
Maybe it is possible to forward a ref to controls instead ?
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.
Curious, why do you think it is weird?
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.
My take on this, not sure how much subjective is this, so curious about other's opinions:
I wouldn't expect that to get access to an api, I have to use an event system. Yes it works and can't be implemented as is, but getting it via reference to a child component seems like more common pattern to me?
I think using events for this is abusing them for things that there are not meant to handle:
- Events: notifying about changes or interactions in a system and passing meta information about the change
- Not events: exposing imperative handlers to underlying APIs.
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 agree this is weird ..... i would expect event.data
to be serializable ....
why do we need to do this, why doesn't chart handle this internally ?
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.
... getting it via reference to a child component seems like more common pattern to me?
It is effectively a function reference, like:
<input ref={ref => {}} />
Functional references are better than named or object references.
i agree this is weird ..... i would expect event.data to be serializable ....
I'm not sure why you find it weird, it is a common pattern. If event.data
had to be serializable, then we would need to use something else, but I'm not aware of this requirement.
why do we need to do this, why doesn't chart handle this internally ?
I'm not sure what you mean. We need to expose a way for embeddable to create a .png from a chart. The chart handles the part it needs to handle, the embeddable handles its part.
return toBlob(snapshot.blobOrDataUrl); | ||
}, | ||
}; | ||
onControls(controls); |
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.
just call controls.toPngBlob()
here ?
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.
You can, but that would generate a PNG of every chart on the dashboard at the moment they initially mount, not something you want.
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.
ehh ? onControls calls handlers.event() which in turn generates the png ... so instead of doing handlers.event generate the png.
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.
in my code .png is generated only when user clicks "Copy PNG" action in UI
onControls calls handlers.event() which in turn generates the png ...
hadlers.event()
does not generate anything, it just stores the controls
object in embeddable, and then embeddable can use those controls when it needs to, i.e. when user clicks "Copy PNG" in UI.
@@ -207,6 +209,9 @@ export class Embeddable extends AbstractEmbeddable<LensEmbeddableInput, LensEmbe | |||
embeddable: this, | |||
}); | |||
} | |||
if (isLensControlsEvent(event)) { | |||
this.chartControls = event.data; |
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 agree this is weird ..... i would expect event.data
to be serializable ....
why do we need to do this, why doesn't chart handle this internally ?
@@ -233,4 +238,10 @@ export class Embeddable extends AbstractEmbeddable<LensEmbeddableInput, LensEmbe | |||
} | |||
} | |||
} | |||
|
|||
async toPngBlob() { |
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.
Use something like:
getExportFunctions(): {toPngBlob?: () => Promise<Blob>; toHtml?: () => Promise<string>}
@@ -535,6 +536,10 @@ export interface LensBrushEvent { | |||
name: 'brush'; | |||
data: TriggerContext<typeof SELECT_RANGE_TRIGGER>['data']; | |||
} | |||
export interface LensControlsEvent { |
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.
Move this to expressions plugin.
export function isLensControlsEvent(event: ExpressionRendererEvent): event is LensControlsEvent { | ||
return event.name === 'controls'; | ||
} |
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.
Remove this function or move it to expressions
plugin.
Pinging @elastic/kibana-app-services (Team:AppServicesUx) |
WIP
Notes:
navigator.clipboard
available only on HTTPS or localhost. This can be detected, hide the action in that case.Summary
Summarize your PR. If it involves visual changes include a screenshot or gif.
Checklist
Delete any items that are not applicable to this PR.
For maintainers