Skip to content

Commit

Permalink
[7.x] Feature Controls - Simplify Saved Objects Management UI Capabil…
Browse files Browse the repository at this point in the history
…ities (#38461) (#38618)

* start simplifying saved objects management UI Capabilities

* update tests

* simplify UI

* address PR feedback

* remove savedObjectsManagement UI Capabilities tests
  • Loading branch information
legrego authored Jun 10, 2019
1 parent 2c1dc3b commit 2fd33c9
Show file tree
Hide file tree
Showing 20 changed files with 31 additions and 579 deletions.
17 changes: 6 additions & 11 deletions src/legacy/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ export default function (kibana) {
migrations,
},

uiCapabilities: async function (server) {
const { savedObjects } = server;

uiCapabilities: async function () {
return {
discover: {
show: true,
Expand Down Expand Up @@ -275,14 +273,11 @@ export default function (kibana) {
indexPatterns: {
save: true,
},
savedObjectsManagement: savedObjects.types.reduce((acc, type) => ({
...acc,
[type]: {
delete: true,
edit: true,
read: true,
}
}), {}),
savedObjectsManagement: {
delete: true,
edit: true,
read: true,
},
management: {
/*
* Management settings correspond to management section/link ids, and should not be changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ uiModules.get('apps/management', ['monospaced.elastic'])
}
};

const { edit: canEdit, delete: canDelete } = uiCapabilities.savedObjectsManagement[service.type];
const { edit: canEdit, delete: canDelete } = uiCapabilities.savedObjectsManagement;
$scope.canEdit = canEdit;
$scope.canDelete = canDelete;
$scope.canViewInApp = canViewInApp(uiCapabilities, service.type);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,12 @@ const defaultProps = {
services: [],
uiCapabilities: {
savedObjectsManagement: {
'index-pattern': {
read: true
},
visualization: {
read: true
},
dashboard: {
read: true
},
search: {
read: true
}
read: true,
edit: false,
delete: false,
}
},
canDeleteSavedObjectTypes: [
'index-pattern',
'visualization',
'dashboard',
'search'
]
canDelete: true,
};

beforeEach(() => {
Expand Down Expand Up @@ -272,41 +258,6 @@ describe('ObjectsTable', () => {
expect(addDangerMock).toHaveBeenCalled();
});

it('should filter find operation based on the uiCapabilities', async () => {
const uiCapabilities = {
savedObjectsManagement: {
'index-pattern': {
read: false,
},
visualization: {
read: false,
},
dashboard: {
read: false,
},
search: {
read: true,
}
}
};
const customizedProps = { ...defaultProps, uiCapabilities };
const component = shallowWithIntl(
<ObjectsTable.WrappedComponent
{...customizedProps}
perPageConfig={15}
/>
);

// Ensure all promises resolve
await new Promise(resolve => process.nextTick(resolve));
// Ensure the state changes are reflected
component.update();

expect(findObjects).toHaveBeenCalledWith(expect.objectContaining({
type: ['search']
}));
});

describe('export', () => {
it('should export selected objects', async () => {
const mockSelectedSavedObjects = [
Expand Down Expand Up @@ -452,42 +403,6 @@ describe('ObjectsTable', () => {
expect(getRelationships).toHaveBeenCalledWith('search', '1', savedObjectTypes, defaultProps.$http, defaultProps.basePath);
});

it('should fetch relationships filtered based on the uiCapabilities', async () => {
const { getRelationships } = require('../../../lib/get_relationships');

const uiCapabilities = {
savedObjectsManagement: {
'index-pattern': {
read: false,
},
visualization: {
read: false,
},
dashboard: {
read: false,
},
search: {
read: true,
}
}
};
const customizedProps = { ...defaultProps, uiCapabilities };
const component = shallowWithIntl(
<ObjectsTable.WrappedComponent
{...customizedProps}
/>
);

// Ensure all promises resolve
await new Promise(resolve => process.nextTick(resolve));
// Ensure the state changes are reflected
component.update();

await component.instance().getRelationships('search', '1');
const savedObjectTypes = ['search'];
expect(getRelationships).toHaveBeenCalledWith('search', '1', savedObjectTypes, defaultProps.$http, defaultProps.basePath);
});

it('should show the flyout', async () => {
const component = shallowWithIntl(
<ObjectsTable.WrappedComponent
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const defaultProps = {
onTableChange: () => {},
isSearching: false,
onShowRelationships: () => {},
canDeleteSavedObjectTypes: ['visualization']
canDelete: true
};

describe('Table', () => {
Expand Down Expand Up @@ -127,9 +127,9 @@ describe('Table', () => {
expect(component.state().isSearchTextValid).toBe(true);
});

it(`restricts which saved objects can be deleted based on type`, () => {
it(`prevents saved objects from being deleted`, () => {
const selectedSavedObjects = [{ type: 'visualization' }, { type: 'search' }, { type: 'index-pattern' }];
const customizedProps = { ...defaultProps, selectedSavedObjects, canDeleteSavedObjectTypes: ['visualization'] };
const customizedProps = { ...defaultProps, selectedSavedObjects, canDelete: false };
const component = shallowWithIntl(
<Table.WrappedComponent
{...customizedProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
EuiText
} from '@elastic/eui';
import { getDefaultTitle, getSavedObjectLabel } from '../../../../lib';
import { i18n } from '@kbn/i18n';
import { FormattedMessage, injectI18n } from '@kbn/i18n/react';

class TableUI extends PureComponent {
Expand All @@ -47,7 +48,7 @@ class TableUI extends PureComponent {
onSelectionChange: PropTypes.func.isRequired,
}).isRequired,
filterOptions: PropTypes.array.isRequired,
canDeleteSavedObjectTypes: PropTypes.array.isRequired,
canDelete: PropTypes.bool.isRequired,
onDelete: PropTypes.func.isRequired,
onExport: PropTypes.func.isRequired,
goInspectObject: PropTypes.func.isRequired,
Expand Down Expand Up @@ -254,10 +255,6 @@ class TableUI extends PureComponent {
);
}

const unableToDeleteSavedObjectTypes = selectedSavedObjects
.map(({ type }) => type)
.filter(type => !this.props.canDeleteSavedObjectTypes.includes(type));

const button = (
<EuiButton
iconType="arrowDown"
Expand Down Expand Up @@ -286,10 +283,15 @@ class TableUI extends PureComponent {
onClick={onDelete}
isDisabled={
selectedSavedObjects.length === 0 ||
unableToDeleteSavedObjectTypes.length > 0
!this.props.canDelete
}
title={
unableToDeleteSavedObjectTypes.length > 0 ? `Unable to delete ${unableToDeleteSavedObjectTypes.join(', ')}` : undefined
this.props.canDelete
? undefined
: i18n.translate(
'kbn.management.objects.objectsTable.table.deleteButtonTitle',
{ defaultMessage: 'Unable to delete saved objects' }
)
}
data-test-subj="savedObjectsManagementDelete"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ class ObjectsTableUI extends Component {

constructor(props) {
super(props);
this.savedObjectTypes = POSSIBLE_TYPES.filter(type => {
return this.props.uiCapabilities.savedObjectsManagement[type].read;
});
this.savedObjectTypes = POSSIBLE_TYPES;

this.state = {
totalCount: 0,
Expand Down Expand Up @@ -677,10 +675,6 @@ class ObjectsTableUI extends Component {
view: `${type} (${savedObjectCounts[type] || 0})`,
}));

const canDeleteSavedObjectTypes = POSSIBLE_TYPES.filter(type => {
return this.props.uiCapabilities.savedObjectsManagement[type].delete;
});

return (
<EuiPageContent
horizontalPosition="center"
Expand All @@ -706,7 +700,7 @@ class ObjectsTableUI extends Component {
onTableChange={this.onTableChange}
filterOptions={filterOptions}
onExport={this.onExport}
canDeleteSavedObjectTypes={canDeleteSavedObjectTypes}
canDelete={this.props.uiCapabilities.savedObjectsManagement.delete}
onDelete={this.onDelete}
goInspectObject={this.props.goInspectObject}
pageIndex={page}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { FeaturePrivilegeBuilder } from './feature_privilege_builder';
import { FeaturePrivilegeManagementBuilder } from './management';
import { FeaturePrivilegeNavlinkBuilder } from './navlink';
import { FeaturePrivilegeSavedObjectBuilder } from './saved_object';
import { FeaturePrivilegeSavedObjectsManagementBuilder } from './saved_objects_management';
import { FeaturePrivilegeUIBuilder } from './ui';
export { FeaturePrivilegeBuilder };

Expand All @@ -26,7 +25,6 @@ export const featurePrivilegeBuilderFactory = (actions: Actions): FeaturePrivile
new FeaturePrivilegeManagementBuilder(actions),
new FeaturePrivilegeNavlinkBuilder(actions),
new FeaturePrivilegeSavedObjectBuilder(actions),
new FeaturePrivilegeSavedObjectsManagementBuilder(actions),
new FeaturePrivilegeUIBuilder(actions),
];

Expand Down

This file was deleted.

Loading

0 comments on commit 2fd33c9

Please sign in to comment.