Skip to content

Commit

Permalink
fix: 🐛 don't show action in dashboard_only mode (#73010)
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich authored Jul 23, 2020
1 parent cf3aa2c commit 8f8cba5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/discover_enhanced/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"server": true,
"ui": true,
"requiredPlugins": ["uiActions", "embeddable", "discover"],
"optionalPlugins": ["share"],
"optionalPlugins": ["share", "kibanaLegacy"],
"configPath": ["xpack", "discoverEnhanced"],
"requiredBundles": ["kibanaUtils", "data"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DiscoverStart } from '../../../../../../src/plugins/discover/public';
import { EmbeddableStart } from '../../../../../../src/plugins/embeddable/public';
import { ViewMode, IEmbeddable } from '../../../../../../src/plugins/embeddable/public';
import { StartServicesGetter } from '../../../../../../src/plugins/kibana_utils/public';
import { KibanaLegacyStart } from '../../../../../../src/plugins/kibana_legacy/public';
import { CoreStart } from '../../../../../../src/core/public';
import { KibanaURL } from './kibana_url';
import * as shared from './shared';
Expand All @@ -18,6 +19,11 @@ export const ACTION_EXPLORE_DATA = 'ACTION_EXPLORE_DATA';
export interface PluginDeps {
discover: Pick<DiscoverStart, 'urlGenerator'>;
embeddable: Pick<EmbeddableStart, 'filtersAndTimeRangeFromContext'>;
kibanaLegacy?: {
dashboardConfig: {
getHideWriteControls: KibanaLegacyStart['dashboardConfig']['getHideWriteControls'];
};
};
}

export interface CoreDeps {
Expand All @@ -42,6 +48,12 @@ export abstract class AbstractExploreDataAction<Context extends { embeddable?: I

public async isCompatible({ embeddable }: Context): Promise<boolean> {
if (!embeddable) return false;

const isDashboardOnlyMode = !!this.params
.start()
.plugins.kibanaLegacy?.dashboardConfig.getHideWriteControls();
if (isDashboardOnlyMode) return false;

if (!this.params.start().plugins.discover.urlGenerator) return false;
if (!shared.hasExactlyOneIndexPattern(embeddable)) return false;
if (embeddable.getInput().viewMode !== ViewMode.VIEW) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ afterEach(() => {
i18nTranslateSpy.mockClear();
});

const setup = ({ useRangeEvent = false }: { useRangeEvent?: boolean } = {}) => {
const setup = ({
useRangeEvent = false,
dashboardOnlyMode = false,
}: { useRangeEvent?: boolean; dashboardOnlyMode?: boolean } = {}) => {
type UrlGenerator = UrlGeneratorContract<'DISCOVER_APP_URL_GENERATOR'>;

const core = coreMock.createStart();
Expand All @@ -54,6 +57,11 @@ const setup = ({ useRangeEvent = false }: { useRangeEvent?: boolean } = {}) => {
embeddable: {
filtersAndTimeRangeFromContext,
},
kibanaLegacy: {
dashboardConfig: {
getHideWriteControls: () => dashboardOnlyMode,
},
},
};

const params: Params = {
Expand Down Expand Up @@ -181,6 +189,13 @@ describe('"Explore underlying data" panel action', () => {

expect(isCompatible).toBe(false);
});

test('return false for dashboard_only mode', async () => {
const { action, context } = setup({ dashboardOnlyMode: true });
const isCompatible = await action.isCompatible(context);

expect(isCompatible).toBe(false);
});
});

describe('getHref()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ afterEach(() => {
i18nTranslateSpy.mockClear();
});

const setup = () => {
const setup = ({ dashboardOnlyMode = false }: { dashboardOnlyMode?: boolean } = {}) => {
type UrlGenerator = UrlGeneratorContract<'DISCOVER_APP_URL_GENERATOR'>;

const core = coreMock.createStart();
Expand All @@ -48,6 +48,11 @@ const setup = () => {
embeddable: {
filtersAndTimeRangeFromContext,
},
kibanaLegacy: {
dashboardConfig: {
getHideWriteControls: () => dashboardOnlyMode,
},
},
};

const params: Params = {
Expand Down Expand Up @@ -167,6 +172,13 @@ describe('"Explore underlying data" panel action', () => {

expect(isCompatible).toBe(false);
});

test('return false for dashboard_only mode', async () => {
const { action, context } = setup({ dashboardOnlyMode: true });
const isCompatible = await action.isCompatible(context);

expect(isCompatible).toBe(false);
});
});

describe('getHref()', () => {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/discover_enhanced/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { createStartServicesGetter } from '../../../../src/plugins/kibana_utils/public';
import { DiscoverSetup, DiscoverStart } from '../../../../src/plugins/discover/public';
import { SharePluginSetup, SharePluginStart } from '../../../../src/plugins/share/public';
import { KibanaLegacySetup, KibanaLegacyStart } from '../../../../src/plugins/kibana_legacy/public';
import {
EmbeddableSetup,
EmbeddableStart,
Expand All @@ -39,13 +40,15 @@ declare module '../../../../src/plugins/ui_actions/public' {
export interface DiscoverEnhancedSetupDependencies {
discover: DiscoverSetup;
embeddable: EmbeddableSetup;
kibanaLegacy?: KibanaLegacySetup;
share?: SharePluginSetup;
uiActions: UiActionsSetup;
}

export interface DiscoverEnhancedStartDependencies {
discover: DiscoverStart;
embeddable: EmbeddableStart;
kibanaLegacy?: KibanaLegacyStart;
share?: SharePluginStart;
uiActions: UiActionsStart;
}
Expand Down

0 comments on commit 8f8cba5

Please sign in to comment.