Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed May 3, 2022
1 parent 4be7a1b commit 718d779
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { DiscoverSetup } from '@kbn/discover-plugin/public';
import { DiscoverStart } from '@kbn/discover-plugin/public';
import type { IEmbeddable } from '@kbn/embeddable-plugin/public';
import { ActionExecutionContext } from '@kbn/ui-actions-plugin/public';
import { DOC_TYPE } from '../../common';
Expand All @@ -17,7 +17,7 @@ describe('open in discover action', () => {
it('is incompatible with non-lens embeddables', async () => {
const embeddable = { type: 'NOT_LENS' } as IEmbeddable;

const isCompatible = await createOpenInDiscoverAction({} as DiscoverSetup, true).isCompatible(
const isCompatible = await createOpenInDiscoverAction({} as DiscoverStart, true).isCompatible(
{
embeddable,
} as ActionExecutionContext<{ embeddable: IEmbeddable }>
Expand All @@ -33,15 +33,15 @@ describe('open in discover action', () => {
let hasDiscoverAccess = true;
// make sure it would work if we had access to Discover
expect(
await createOpenInDiscoverAction({} as DiscoverSetup, hasDiscoverAccess).isCompatible({
await createOpenInDiscoverAction({} as DiscoverStart, hasDiscoverAccess).isCompatible({
embeddable,
} as unknown as ActionExecutionContext<{ embeddable: IEmbeddable }>)
).toBeTruthy();

// make sure no Discover access makes the action incompatible
hasDiscoverAccess = false;
expect(
await createOpenInDiscoverAction({} as DiscoverSetup, hasDiscoverAccess).isCompatible({
await createOpenInDiscoverAction({} as DiscoverStart, hasDiscoverAccess).isCompatible({
embeddable,
} as unknown as ActionExecutionContext<{ embeddable: IEmbeddable }>)
).toBeFalsy();
Expand All @@ -53,7 +53,7 @@ describe('open in discover action', () => {
// test false
embeddable.canViewUnderlyingData = jest.fn(() => Promise.resolve(false));
expect(
await createOpenInDiscoverAction({} as DiscoverSetup, true).isCompatible({
await createOpenInDiscoverAction({} as DiscoverStart, true).isCompatible({
embeddable,
} as unknown as ActionExecutionContext<{ embeddable: IEmbeddable }>)
).toBeFalsy();
Expand All @@ -63,7 +63,7 @@ describe('open in discover action', () => {
// test true
embeddable.canViewUnderlyingData = jest.fn(() => Promise.resolve(true));
expect(
await createOpenInDiscoverAction({} as DiscoverSetup, true).isCompatible({
await createOpenInDiscoverAction({} as DiscoverStart, true).isCompatible({
embeddable,
} as unknown as ActionExecutionContext<{ embeddable: IEmbeddable }>)
).toBeTruthy();
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('open in discover action', () => {
locator: {
getRedirectUrl: jest.fn(() => discoverUrl),
},
} as unknown as DiscoverSetup;
} as unknown as DiscoverStart;

globalThis.open = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { i18n } from '@kbn/i18n';
import { createAction } from '@kbn/ui-actions-plugin/public';
import type { DiscoverSetup } from '@kbn/discover-plugin/public';
import type { DiscoverStart } from '@kbn/discover-plugin/public';
import { IEmbeddable } from '@kbn/embeddable-plugin/public';
import { execute, isCompatible } from './open_in_discover_helpers';

Expand All @@ -18,7 +18,7 @@ interface Context {
}

export const createOpenInDiscoverAction = (
discover: Pick<DiscoverSetup, 'locator'>,
discover: Pick<DiscoverStart, 'locator'>,
hasDiscoverAccess: boolean
) =>
createAction<Context>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export function execute({ embeddable, discover, timeRange, filters, openInSameTa
// shouldn't be executed because of the isCompatible check
throw new Error('Can only be executed in the context of Lens visualization');
}
const args = embeddable.getViewUnderlyingDataArgs()!;
const args = embeddable.getViewUnderlyingDataArgs();
if (!args) {
// shouldn't be executed because of the isCompatible check
throw new Error('Underlying data is not ready');
}
const discoverUrl = discover.locator?.getRedirectUrl({
...args,
timeRange: timeRange || args.timeRange,
Expand Down

0 comments on commit 718d779

Please sign in to comment.