Skip to content

Commit

Permalink
fix: πŸ› don't show actions if Discover app is disabled (#73017)
Browse files Browse the repository at this point in the history
* fix: πŸ› don't show actions if Discover app is disabled

* style: collapse ifs
  • Loading branch information
streamich authored Jul 23, 2020
1 parent 49782f9 commit 304445f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ export abstract class AbstractExploreDataAction<Context extends { embeddable?: I
public async isCompatible({ embeddable }: Context): Promise<boolean> {
if (!embeddable) return false;

const { core, plugins } = this.params.start();
const { capabilities } = core.application;

if (capabilities.discover && !capabilities.discover.show) return false;
if (!plugins.discover.urlGenerator) 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;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ describe('"Explore underlying data" panel action', () => {

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

test('returns false if Discover app is disabled', async () => {
const { action, context, core } = setup();

core.application.capabilities = { ...core.application.capabilities };
(core.application.capabilities as any).discover = {
show: false,
};

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 @@ -179,6 +179,19 @@ describe('"Explore underlying data" panel action', () => {

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

test('returns false if Discover app is disabled', async () => {
const { action, context, core } = setup();

core.application.capabilities = { ...core.application.capabilities };
(core.application.capabilities as any).discover = {
show: false,
};

const isCompatible = await action.isCompatible(context);

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

describe('getHref()', () => {
Expand Down

0 comments on commit 304445f

Please sign in to comment.