[Lens][ES|QL] Going to Discover without carrying the dashboard filters (#208041)

This commit is contained in:
Stratoula Kalafateli 2025-01-29 08:00:22 +01:00 committed by GitHub
parent 8b7b36a692
commit d97b6fa7a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 1 deletions

View file

@ -135,4 +135,48 @@ describe('open in discover action', () => {
expect(locator.getRedirectUrl).toHaveBeenCalledWith(viewUnderlyingDataArgs);
expect(globalThis.open).toHaveBeenCalledWith(discoverUrl, '_blank');
});
it('navigates to discover for an ES|QL chart but without the filters', async () => {
const viewUnderlyingDataArgs = {
dataViewSpec: { id: 'index-pattern-id' },
timeRange: {},
filters: [{ meta: { type: 'range' } }],
query: undefined,
columns: [],
};
const embeddable = {
...compatibleEmbeddableApi,
getViewUnderlyingDataArgs: jest.fn(() => viewUnderlyingDataArgs),
isTextBasedLanguage: jest.fn(() => true),
};
const discoverUrl = 'https://discover-redirect-url';
const locator = {
getRedirectUrl: jest.fn(() => discoverUrl),
} as unknown as DiscoverAppLocator;
globalThis.open = jest.fn();
await createOpenInDiscoverAction(
locator,
{
get: () => ({
isTimeBased: () => true,
toSpec: () => ({ id: 'index-pattern-id' }),
}),
} as unknown as DataViewsService,
true
).execute({
embeddable,
} as ActionExecutionContext<EmbeddableApiContext>);
expect(embeddable.getViewUnderlyingDataArgs).toHaveBeenCalled();
const viewUnderlyingDataArgsWithoutFilters = {
...viewUnderlyingDataArgs,
filters: [],
};
expect(locator.getRedirectUrl).toHaveBeenCalledWith(viewUnderlyingDataArgsWithoutFilters);
expect(globalThis.open).toHaveBeenCalledWith(discoverUrl, '_blank');
});
});

View file

@ -59,7 +59,10 @@ async function getDiscoverLocationParams({
throw new Error('Underlying data is not ready');
}
const dataView = await dataViews.get(args.dataViewSpec.id!);
let filtersToApply = [...(filters || []), ...args.filters];
// we don't want to pass the DSL filters when navigating from an ES|SQL embeddable
let filtersToApply = embeddable.isTextBasedLanguage()
? []
: [...(filters || []), ...args.filters];
let timeRangeToApply = args.timeRange;
// if the target data view is time based, attempt to split out a time range from the provided filters
if (dataView.isTimeBased() && dataView.timeFieldName === timeFieldName) {