mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 19:13:14 -04:00
## Summary Closes https://github.com/elastic/kibana/issues/167632 This PR provides a simpler api for the Lens embeddable consumers who want to provide inline editing capabilities. I added an example to help with the integration. Run kibana with ``` yarn start --run-examples ``` http://localhost:5601/app/lens_embeddable_inline_editing_example <img width="1381" alt="image" src="58e7ef2d
-2f92-4bab-9cb4-d04a90d87e15"> <img width="2498" alt="image" src="0a050e8d
-f22f-4c48-88e4-20c42683a279"> It also allows the consumers to render the inline editing component in a custom element in case you don't want to open a push flyout.  I included a readme on how to use the api. ### Note This is the first PR which uses the new Lens config builder so some of the changes are not related to the api improvements but they are fixing some bugs on the builder. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2.4 KiB
2.4 KiB
Inline editing of Lens embeddable
To run this example plugin, use the command yarn start --run-examples
.
This plugin contains examples on how to integrate the inline editing capabilities to your Lens embeddable.
Steps:
- Add UIActions on your start dependencies
- On your embeddable use the onLoad callback to store in the local state the adapters and lensEmbeddableOutput$.
// my Lens embeddable
<LensComponent {...embeddableInput} onLoad={onLoad} />
const [lensLoadEvent, setLensLoadEvent] = useState<InlineEditLensEmbeddableContext['lensEvent'] | null>(null);
// my onLoad callback
const onLoad = useCallback(
(
isLoading: boolean,
adapters: LensChartLoadEvent['adapters'] | undefined,
lensEmbeddableOutput$?: LensChartLoadEvent['embeddableOutput$']
) => {
const adapterTables = adapters?.tables?.tables;
if (adapterTables && !isLoading) {
setLensLoadEvent({
adapters,
embeddableOutput$: lensEmbeddableOutput$,
});
}
},
[]
);
- Create the triggerOptions. You will need:
- The attributes of the lens embeddable input
- The lensChartEvent that you retrieved from the onLoad callback
- An onUpdate callback to update the embeddable input with the new attributes
- An optional onApply callback if you want to add an action when the Apply button is clicked
- An optional onCancel callback if you want to add an action when the Cancel button is clicked
// my trigger options
const triggerOptions = {
attributes: embeddableInput?.attributes,
lensEvent: lensLoadEvent,
onUpdate: (newAttributes: TypedLensByValueInput['attributes']) => {
// onUpdate I need to update my embeddableInput.attributes
},
onApply: () => {
// optional callback when Apply button is clicked
},
onCancel: () => {
// optional callback when Cancel button is clicked
},
};
- Add a button which will open the editing flyout. Execute the IN_APP_EMBEDDABLE_EDIT_TRIGGER trigger onClick
uiActions.getTrigger('IN_APP_EMBEDDABLE_EDIT_TRIGGER').exec(triggerOptions);
Important note
In case you don't want to open a push flyout you can pass an html element to the triggerOptions, the container
property. This is going
to render the inline editing component to this container element. In that case you will need an extra handling on your side.
Check the 3rd example for implementation details.