[Lens][Embeddable] Fix unnecessary rerender on view mode change (#213902)

## Summary

Fixes #203020 

Improve drill down check before triggering a rerender.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
This commit is contained in:
Marco Liberati 2025-03-12 10:09:33 +01:00 committed by GitHub
parent 382630ecd1
commit 14b0c611b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

View file

@ -240,7 +240,14 @@ describe('Data Loader', () => {
attributes: getLensAttributesMock(),
enhancements: {
dynamicActions: {
events: [],
events: [
// make sure there's at least one event
{
eventId: 'test',
triggers: [],
action: { factoryId: 'test', name: 'testAction', config: {} },
},
],
},
},
});
@ -252,6 +259,24 @@ describe('Data Loader', () => {
});
it('should not re-render when dashboard view/edit mode changes if dynamic actions are not set', async () => {
await expectRerenderOnDataLoader(async ({ api, getState }) => {
getState.mockReturnValue({
attributes: getLensAttributesMock(),
enhancements: {
dynamicActions: {
// empty list should not trigger
events: [],
},
},
});
// trigger a change by changing the title in the attributes
(api.viewMode$ as BehaviorSubject<ViewMode | undefined>).next('view');
return false;
});
});
it('should not re-render when dashboard view/edit mode changes if dynamic actions are not available', async () => {
await expectRerenderOnDataLoader(async ({ api }) => {
// the default get state does not have dynamic actions
// trigger a change by changing the title in the attributes

View file

@ -304,7 +304,7 @@ export function loadEmbeddableData(
// make sure to reload on viewMode change
api.viewMode$.subscribe(() => {
// only reload if drilldowns are set
if (getState().enhancements?.dynamicActions) {
if (getState().enhancements?.dynamicActions?.events.length) {
reload('viewMode');
}
}),