Skip to content

Commit

Permalink
[Visualizations][Lens] Hide incompatible actions from the panels (#15…
Browse files Browse the repository at this point in the history
…6667)

## Summary

Closes #156119
Closes #156114

This PR

1. Removes the convert to Lens action if visualize permissions are set
to None
<img width="467" alt="image"
src="https://user-images.githubusercontent.com/17003240/236183482-b6e3cfe9-a77b-44d5-9909-1580c0796db2.png">

2. Removes the edit actions if visualize permisions are set to None
<img width="938" alt="image"
src="https://user-images.githubusercontent.com/17003240/236183601-9a715339-2ab7-47d8-8b89-c10bdb03938e.png">


### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
stratoula authored May 5, 2023
1 parent bc159fd commit ac18e8a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import { IEmbeddable, ViewMode } from '@kbn/embeddable-plugin/public';
import { Action } from '@kbn/ui-actions-plugin/public';
import { VisualizeEmbeddable } from '../embeddable';
import { DASHBOARD_VISUALIZATION_PANEL_TRIGGER } from '../triggers';
import { getUiActions, getApplication, getEmbeddable, getUsageCollection } from '../services';
import {
getUiActions,
getApplication,
getEmbeddable,
getUsageCollection,
getCapabilities,
} from '../services';

export const ACTION_EDIT_IN_LENS = 'ACTION_EDIT_IN_LENS';

Expand Down Expand Up @@ -116,7 +122,8 @@ export class EditInLensAction implements Action<EditInLensContext> {

async isCompatible(context: ActionExecutionContext<EditInLensContext>) {
const { embeddable } = context;
if (!isVisualizeEmbeddable(embeddable)) {
const { visualize } = getCapabilities();
if (!isVisualizeEmbeddable(embeddable) || !visualize.show) {
return false;
}
const vis = embeddable.getVis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const createVisEmbeddableFromObject =
const capabilities = {
visualizeSave: Boolean(getCapabilities().visualize.save),
dashboardSave: Boolean(getCapabilities().dashboard?.showWriteControls),
visualizeOpen: Boolean(getCapabilities().visualize?.show),
};

return createVisualizeEmbeddableAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface VisualizeEmbeddableConfiguration {
indexPatterns?: DataView[];
editPath: string;
editUrl: string;
capabilities: { visualizeSave: boolean; dashboardSave: boolean };
capabilities: { visualizeSave: boolean; dashboardSave: boolean; visualizeOpen: boolean };
deps: VisualizeEmbeddableFactoryDeps;
}

Expand Down Expand Up @@ -171,7 +171,9 @@ export class VisualizeEmbeddable

if (this.attributeService) {
const isByValue = !this.inputIsRefType(initialInput);
const editable = capabilities.visualizeSave || (isByValue && capabilities.dashboardSave);
const editable =
capabilities.visualizeSave ||
(isByValue && capabilities.dashboardSave && capabilities.visualizeOpen);
this.updateOutput({ ...this.getOutput(), editable });
}

Expand Down
27 changes: 27 additions & 0 deletions x-pack/plugins/lens/public/embeddable/embeddable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ describe('embeddable', () => {
capabilities: {
canSaveDashboards: true,
canSaveVisualizations: true,
canOpenVisualizations: true,
discover: {},
navLinks: {},
},
Expand Down Expand Up @@ -361,6 +362,7 @@ describe('embeddable', () => {
capabilities: {
canSaveDashboards: true,
canSaveVisualizations: true,
canOpenVisualizations: true,
discover: {},
navLinks: {},
},
Expand Down Expand Up @@ -413,6 +415,7 @@ describe('embeddable', () => {
capabilities: {
canSaveDashboards: true,
canSaveVisualizations: true,
canOpenVisualizations: true,
discover: {},
navLinks: {},
},
Expand Down Expand Up @@ -940,6 +943,7 @@ describe('embeddable', () => {
capabilities: {
canSaveDashboards: true,
canSaveVisualizations: true,
canOpenVisualizations: true,
discover: {},
navLinks: {},
},
Expand Down Expand Up @@ -1039,6 +1043,7 @@ describe('embeddable', () => {
capabilities: {
canSaveDashboards: true,
canSaveVisualizations: true,
canOpenVisualizations: true,
discover: {},
navLinks: {},
},
Expand Down Expand Up @@ -1135,6 +1140,7 @@ describe('embeddable', () => {
capabilities: {
canSaveDashboards: true,
canSaveVisualizations: true,
canOpenVisualizations: true,
discover: {},
navLinks: {},
},
Expand Down Expand Up @@ -1186,4 +1192,25 @@ describe('embeddable', () => {
})
);
});

it('should not be editable for no visualize library privileges', async () => {
const embeddable = new Embeddable(
getEmbeddableProps({
capabilities: {
canSaveDashboards: false,
canSaveVisualizations: true,
canOpenVisualizations: false,
discover: {},
navLinks: {},
},
}),
{
timeRange: {
from: 'now-15m',
to: 'now',
},
} as LensEmbeddableInput
);
expect(embeddable.getOutput().editable).toBeUndefined();
});
});
5 changes: 4 additions & 1 deletion x-pack/plugins/lens/public/embeddable/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export interface LensEmbeddableDeps {
getTriggerCompatibleActions?: UiActionsStart['getTriggerCompatibleActions'];
capabilities: {
canSaveVisualizations: boolean;
canOpenVisualizations: boolean;
canSaveDashboards: boolean;
navLinks: Capabilities['navLinks'];
discover: Capabilities['discover'];
Expand Down Expand Up @@ -1353,7 +1354,9 @@ export class Embeddable
private getIsEditable() {
return (
this.deps.capabilities.canSaveVisualizations ||
(!this.inputIsRefType(this.getInput()) && this.deps.capabilities.canSaveDashboards)
(!this.inputIsRefType(this.getInput()) &&
this.deps.capabilities.canSaveDashboards &&
this.deps.capabilities.canOpenVisualizations)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class EmbeddableFactory implements EmbeddableFactoryDefinition {
capabilities: {
canSaveDashboards: Boolean(capabilities.dashboard?.showWriteControls),
canSaveVisualizations: Boolean(capabilities.visualize.save),
canOpenVisualizations: Boolean(capabilities.visualize.show),
navLinks: capabilities.navLinks,
discover: capabilities.discover,
},
Expand Down

0 comments on commit ac18e8a

Please sign in to comment.