mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
fix: 🐛 don't show action in dashboard_only mode (#73010)
This commit is contained in:
parent
cf3aa2c641
commit
8f8cba5013
5 changed files with 45 additions and 3 deletions
|
@ -5,7 +5,7 @@
|
|||
"server": true,
|
||||
"ui": true,
|
||||
"requiredPlugins": ["uiActions", "embeddable", "discover"],
|
||||
"optionalPlugins": ["share"],
|
||||
"optionalPlugins": ["share", "kibanaLegacy"],
|
||||
"configPath": ["xpack", "discoverEnhanced"],
|
||||
"requiredBundles": ["kibanaUtils", "data"]
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
@ -54,6 +57,11 @@ const setup = ({ useRangeEvent = false }: { useRangeEvent?: boolean } = {}) => {
|
|||
embeddable: {
|
||||
filtersAndTimeRangeFromContext,
|
||||
},
|
||||
kibanaLegacy: {
|
||||
dashboardConfig: {
|
||||
getHideWriteControls: () => dashboardOnlyMode,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const params: Params = {
|
||||
|
@ -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()', () => {
|
||||
|
|
|
@ -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();
|
||||
|
@ -48,6 +48,11 @@ const setup = () => {
|
|||
embeddable: {
|
||||
filtersAndTimeRangeFromContext,
|
||||
},
|
||||
kibanaLegacy: {
|
||||
dashboardConfig: {
|
||||
getHideWriteControls: () => dashboardOnlyMode,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const params: Params = {
|
||||
|
@ -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()', () => {
|
||||
|
|
|
@ -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,
|
||||
|
@ -39,6 +40,7 @@ declare module '../../../../src/plugins/ui_actions/public' {
|
|||
export interface DiscoverEnhancedSetupDependencies {
|
||||
discover: DiscoverSetup;
|
||||
embeddable: EmbeddableSetup;
|
||||
kibanaLegacy?: KibanaLegacySetup;
|
||||
share?: SharePluginSetup;
|
||||
uiActions: UiActionsSetup;
|
||||
}
|
||||
|
@ -46,6 +48,7 @@ export interface DiscoverEnhancedSetupDependencies {
|
|||
export interface DiscoverEnhancedStartDependencies {
|
||||
discover: DiscoverStart;
|
||||
embeddable: EmbeddableStart;
|
||||
kibanaLegacy?: KibanaLegacyStart;
|
||||
share?: SharePluginStart;
|
||||
uiActions: UiActionsStart;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue