Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function DataViewsList({
value: id,
checked: id === currentDataViewId && !Boolean(isTextBasedLangSelected) ? 'on' : undefined,
append: isAdhoc ? (
<EuiBadge color="hollow">
<EuiBadge color="hollow" data-test-subj={`dataViewItemTempBadge-${name}`}>
{i18n.translate('unifiedSearch.query.queryBar.indexPattern.temporaryDataviewLabel', {
defaultMessage: 'Temporary',
})}
Expand Down
7 changes: 7 additions & 0 deletions test/functional/page_objects/unified_search_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ export class UnifiedSearchPageObject extends FtrService {
await this.testSubjects.click(adHoc ? 'exploreIndexPatternButton' : 'saveIndexPatternButton');
}

public async isAdHocDataView() {
const dataViewSwitcher = await this.testSubjects.find('discover-dataView-switch-link');
const dataViewName = await dataViewSwitcher.getVisibleText();
await dataViewSwitcher.click();
return await this.testSubjects.exists(`dataViewItemTempBadge-${dataViewName}`);
}

public async selectTextBasedLanguage(language: string) {
await this.find.clickByCssSelector(
`[data-test-subj="text-based-languages-switcher"] [title="${language}"]`
Expand Down
16 changes: 9 additions & 7 deletions x-pack/plugins/lens/public/embeddable/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import type {
} from '@kbn/core/public';
import type { SpacesPluginStart } from '@kbn/spaces-plugin/public';
import { BrushTriggerEvent, ClickTriggerEvent, Warnings } from '@kbn/charts-plugin/public';
import { DataViewPersistableStateService } from '@kbn/data-views-plugin/common';
import { DataViewPersistableStateService, DataViewSpec } from '@kbn/data-views-plugin/common';
import { getExecutionContextEvents, trackUiCounterEvents } from '../lens_ui_telemetry';
import { Document } from '../persistence';
import { ExpressionWrapper, ExpressionWrapperProps } from './expression_wrapper';
Expand Down Expand Up @@ -186,7 +186,7 @@ export interface LensEmbeddableDeps {
}

export interface ViewUnderlyingDataArgs {
indexPatternId: string;
dataViewSpec: DataViewSpec;
timeRange: TimeRange;
filters: Filter[];
query: Query | AggregateQuery | undefined;
Expand Down Expand Up @@ -260,8 +260,10 @@ function getViewUnderlyingDataArgs({
esQueryConfig
);

const dataViewSpec = indexPatternsCache[meta.id]!.spec;

return {
indexPatternId: meta.id,
dataViewSpec,
timeRange,
filters: newFilters,
query: aggregateQuery.length > 0 ? aggregateQuery[0] : newQuery,
Expand Down Expand Up @@ -930,10 +932,10 @@ export class Embeddable
const adHocDataviews = await Promise.all(
Object.values(this.savedVis?.state.adHocDataViews || {})
.map((persistedSpec) => {
return DataViewPersistableStateService.inject(
persistedSpec,
this.savedVis?.references || []
);
return DataViewPersistableStateService.inject(persistedSpec, [
...(this.savedVis?.references || []),
...(this.savedVis?.state.internalReferences || []),
]);
})
.map((spec) => this.deps.dataViews.create(spec))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('open in discover action', () => {
const embeddable = { type: 'NOT_LENS' } as IEmbeddable;

const isCompatible = await createOpenInDiscoverAction(
{} as DiscoverStart,
{} as unknown as Pick<DiscoverStart, 'locator'>,
{} as DataViewsService,
true
).isCompatible({
Expand All @@ -37,7 +37,7 @@ describe('open in discover action', () => {
// make sure it would work if we had access to Discover
expect(
await createOpenInDiscoverAction(
{} as DiscoverStart,
{} as unknown as Pick<DiscoverStart, 'locator'>,
{} as DataViewsService,
hasDiscoverAccess
).isCompatible({
Expand All @@ -49,7 +49,7 @@ describe('open in discover action', () => {
hasDiscoverAccess = false;
expect(
await createOpenInDiscoverAction(
{} as DiscoverStart,
{} as unknown as Pick<DiscoverStart, 'locator'>,
{} as DataViewsService,
hasDiscoverAccess
).isCompatible({
Expand All @@ -65,7 +65,7 @@ describe('open in discover action', () => {
embeddable.canViewUnderlyingData = jest.fn(() => Promise.resolve(false));
expect(
await createOpenInDiscoverAction(
{} as DiscoverStart,
{} as unknown as Pick<DiscoverStart, 'locator'>,
{} as DataViewsService,
true
).isCompatible({
Expand All @@ -79,7 +79,7 @@ describe('open in discover action', () => {
embeddable.canViewUnderlyingData = jest.fn(() => Promise.resolve(true));
expect(
await createOpenInDiscoverAction(
{} as DiscoverStart,
{} as unknown as Pick<DiscoverStart, 'locator'>,
{} as DataViewsService,
true
).isCompatible({
Expand All @@ -93,7 +93,7 @@ describe('open in discover action', () => {

it('navigates to discover when executed', async () => {
const viewUnderlyingDataArgs = {
indexPatternId: 'index-pattern-id',
dataViewSpec: { id: 'index-pattern-id' },
timeRange: {},
filters: [],
query: undefined,
Expand All @@ -115,8 +115,13 @@ describe('open in discover action', () => {
globalThis.open = jest.fn();

await createOpenInDiscoverAction(
discover,
{ get: () => ({ isTimeBased: () => true }) } as unknown as DataViewsService,
discover as unknown as Pick<DiscoverStart, 'locator'>,
{
get: () => ({
isTimeBased: () => true,
toSpec: () => ({ id: 'index-pattern-id' }),
}),
} as unknown as DataViewsService,
true
).execute({
embeddable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function getDiscoverLocationParams({
// shouldn't be executed because of the isCompatible check
throw new Error('Underlying data is not ready');
}
const dataView = await dataViews.get(args.indexPatternId);
const dataView = await dataViews.get(args.dataViewSpec.id!);
let filtersToApply = [...(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
Expand Down
54 changes: 54 additions & 0 deletions x-pack/test/functional/apps/lens/group1/ad_hoc_data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});
}

const checkDiscoverNavigationResult = async () => {
await testSubjects.click('embeddablePanelToggleMenuIcon');
await testSubjects.click('embeddablePanelMore-mainMenu');
await testSubjects.click('embeddablePanelAction-ACTION_OPEN_IN_DISCOVER');

const [, discoverHandle] = await browser.getAllWindowHandles();
await browser.switchToWindow(discoverHandle);
await PageObjects.header.waitUntilLoadingHasFinished();

const actualIndexPattern = await (
await testSubjects.find('discover-dataView-switch-link')
).getVisibleText();
expect(actualIndexPattern).to.be('*stash*');

const actualDiscoverQueryHits = await testSubjects.getVisibleText('unifiedHistogramQueryHits');
expect(actualDiscoverQueryHits).to.be('14,005');
expect(await PageObjects.unifiedSearch.isAdHocDataView()).to.be(true);
};

describe('lens ad hoc data view tests', () => {
it('should allow building a chart based on ad hoc data view', async () => {
await setupAdHocDataView();
Expand Down Expand Up @@ -176,6 +195,41 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.discover.clickFieldListItemToggle('_bytes-runtimefield');
const newDataViewId = await PageObjects.discover.getCurrentDataViewId();
expect(newDataViewId).not.to.equal(prevDataViewId);
expect(await PageObjects.unifiedSearch.isAdHocDataView()).to.be(true);

await browser.closeCurrentWindow();
});

it('should navigate to discover from embeddable correctly', async () => {
const [lensHandle] = await browser.getAllWindowHandles();
await browser.switchToWindow(lensHandle);
await PageObjects.header.waitUntilLoadingHasFinished();

await setupAdHocDataView();
await PageObjects.lens.configureDimension({
dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension',
operation: 'average',
field: 'bytes',
});

await PageObjects.lens.save(
'embeddable-test-with-adhoc-data-view',
false,
false,
false,
'new'
);

await checkDiscoverNavigationResult();

await browser.closeCurrentWindow();
const [daashboardHandle] = await browser.getAllWindowHandles();
await browser.switchToWindow(daashboardHandle);
await PageObjects.header.waitUntilLoadingHasFinished();

// adhoc data view should be persisted after refresh
await browser.refresh();
await checkDiscoverNavigationResult();
});
});
}