fix underlying data drilldown for Lens (#82737)

This commit is contained in:
Joe Reuter 2020-11-06 12:18:54 +01:00 committed by GitHub
parent b0eb277983
commit d83167629c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 4 deletions

View file

@ -139,6 +139,44 @@ describe('embeddable', () => {
| expression`);
});
it('should initialize output with deduped list of index patterns', async () => {
attributeService = attributeServiceMockFromSavedVis({
...savedVis,
references: [
{ type: 'index-pattern', id: '123', name: 'abc' },
{ type: 'index-pattern', id: '123', name: 'def' },
{ type: 'index-pattern', id: '456', name: 'ghi' },
],
});
const embeddable = new Embeddable(
{
timefilter: dataPluginMock.createSetupContract().query.timefilter.timefilter,
attributeService,
expressionRenderer,
basePath,
indexPatternService: ({
get: (id: string) => Promise.resolve({ id }),
} as unknown) as IndexPatternsContract,
editable: true,
getTrigger,
documentToExpression: () =>
Promise.resolve({
type: 'expression',
chain: [
{ type: 'function', function: 'my', arguments: {} },
{ type: 'function', function: 'expression', arguments: {} },
],
}),
},
{} as LensEmbeddableInput
);
await embeddable.initializeSavedVis({} as LensEmbeddableInput);
const outputIndexPatterns = embeddable.getOutput().indexPatterns!;
expect(outputIndexPatterns.length).toEqual(2);
expect(outputIndexPatterns[0].id).toEqual('123');
expect(outputIndexPatterns[1].id).toEqual('456');
});
it('should re-render if new input is pushed', async () => {
const timeRange: TimeRange = { from: 'now-15d', to: 'now' };
const query: Query = { language: 'kquery', query: '' };

View file

@ -259,8 +259,10 @@ export class Embeddable
if (!this.savedVis) {
return;
}
const promises = this.savedVis.references
.filter(({ type }) => type === 'index-pattern')
const promises = _.uniqBy(
this.savedVis.references.filter(({ type }) => type === 'index-pattern'),
'id'
)
.map(async ({ id }) => {
try {
return await this.deps.indexPatternService.get(id);

View file

@ -8,7 +8,14 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['header', 'common', 'dashboard', 'timePicker', 'lens']);
const PageObjects = getPageObjects([
'header',
'common',
'dashboard',
'timePicker',
'lens',
'discover',
]);
const find = getService('find');
const dashboardAddPanel = getService('dashboardAddPanel');
@ -18,6 +25,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const filterBar = getService('filterBar');
const security = getService('security');
const panelActions = getService('dashboardPanelActions');
async function clickInChart(x: number, y: number) {
const el = await elasticChart.getCanvas();
@ -27,7 +35,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe('lens dashboard tests', () => {
before(async () => {
await PageObjects.common.navigateToApp('dashboard');
await security.testUser.setRoles(['global_dashboard_all', 'test_logstash_reader'], false);
await security.testUser.setRoles(
['global_dashboard_all', 'global_discover_all', 'test_logstash_reader'],
false
);
});
after(async () => {
await security.testUser.restoreDefaults();
@ -68,6 +79,26 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const hasIpFilter = await filterBar.hasFilter('ip', '97.220.3.248');
expect(hasIpFilter).to.be(true);
});
it('should be able to drill down to discover', async () => {
await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.clickNewDashboard();
await dashboardAddPanel.clickOpenAddPanel();
await dashboardAddPanel.filterEmbeddableNames('lnsXYvis');
await find.clickByButtonText('lnsXYvis');
await dashboardAddPanel.closeAddPanel();
await PageObjects.lens.goToTimeRange();
await PageObjects.dashboard.saveDashboard('lnsDrilldown');
await panelActions.openContextMenu();
await testSubjects.clickWhenNotDisabled('embeddablePanelAction-ACTION_EXPLORE_DATA');
await PageObjects.discover.waitForDiscoverAppOnScreen();
const el = await testSubjects.find('indexPattern-switch-link');
const text = await el.getVisibleText();
expect(text).to.be('logstash-*');
});
it('should be able to add filters by clicking in pie chart', async () => {
await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.clickNewDashboard();