Skip to content

Commit

Permalink
Moving where the privileges tooltips are specified (elastic#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobelb authored and legrego committed Jan 22, 2019
1 parent c16ba50 commit b58b799
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 50 deletions.
10 changes: 4 additions & 6 deletions x-pack/plugins/ml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ export const ml = (kibana) => {
navLinkId: 'ml',
privileges: {
all: {
metadata: {
tooltip: i18n.translate('xpack.ml.privileges.tooltip', {
defaultMessage: 'The machine_learning_user or machine_learning_admin role should also be assigned to users to grant access'
})
},
catalogue: ['ml'],
app: ['ml', 'kibana'],
savedObject: {
Expand All @@ -92,7 +87,10 @@ export const ml = (kibana) => {
},
ui: [],
},
}
},
privilegesTooltip: i18n.translate('xpack.ml.privileges.tooltip', {
defaultMessage: 'The machine_learning_user or machine_learning_admin role should also be assigned to users to grant access'
})
});

// Add server routes and initialize the plugin here
Expand Down
10 changes: 4 additions & 6 deletions x-pack/plugins/monitoring/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ export const init = (monitoringPlugin, server) => {
navLinkId: 'monitoring',
privileges: {
all: {
metadata: {
tooltip: i18n.translate('xpack.monitoring.privileges.tooltip', {
defaultMessage: 'The monitoring_user role should also be assigned to users to grant access'
})
},
catalogue: ['monitoring'],
app: ['monitoring', 'kibana'],
savedObject: {
Expand All @@ -77,7 +72,10 @@ export const init = (monitoringPlugin, server) => {
},
ui: [],
},
}
},
privilegesTooltip: i18n.translate('xpack.monitoring.privileges.tooltip', {
defaultMessage: 'The monitoring_user role should also be assigned to users to grant access'
})
});

const bulkUploader = initBulkUploader(kbnServer, server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ interface Props {
disabled?: boolean;
}

interface ToolTipDefinition {
privilegeId: string;
tooltip: string;
}

interface TableFeature extends Feature {
hasAnyPrivilegeAssigned: boolean;
}
Expand Down Expand Up @@ -109,30 +104,11 @@ export class FeatureTable extends Component<Props, {}> {
defaultMessage: 'Feature',
}),
render: (feature: TableFeature) => {
const tooltips = Object.entries(feature.privileges).reduce(
(acc: ToolTipDefinition[], [privilegeId, privilege]) => {
if (!privilege.metadata || !privilege.metadata.tooltip) {
return acc;
}

return [
...acc,
{
privilegeId,
tooltip: privilege.metadata.tooltip,
},
];
},
[] as ToolTipDefinition[]
);

let tooltipElement = null;
if (tooltips.length > 0) {
if (feature.privilegesTooltip) {
const tooltipContent = (
<EuiText>
{tooltips.map(tip => (
<p key={tip.privilegeId}>{tip.tooltip}</p>
))}
<p>{feature.privilegesTooltip}</p>
</EuiText>
);
tooltipElement = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ describe('registerFeature', () => {
validLicenses: ['standard', 'basic', 'gold', 'platinum'],
privileges: {
all: {
metadata: {
tooltip: 'some fancy tooltip',
},
app: ['app1', 'app2'],
savedObject: {
all: ['config', 'space', 'etc'],
Expand All @@ -51,6 +48,7 @@ describe('registerFeature', () => {
ui: ['allowsFoo', 'showBar', 'showBaz'],
},
},
privilegesTooltip: 'some fancy tooltip',
};

registerFeature(feature);
Expand Down Expand Up @@ -100,9 +98,6 @@ describe('registerFeature', () => {
name: 'Test Feature',
privileges: {
['some invalid key']: {
metadata: {
tooltip: 'some fancy tooltip',
},
app: ['app1', 'app2'],
savedObject: {
all: ['config', 'space', 'etc'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import _ from 'lodash';
import { UICapabilities } from 'ui/capabilities';

export interface FeaturePrivilegeDefinition {
metadata?: {
tooltip?: string;
};
management?: {
[sectionId: string]: string[];
};
Expand All @@ -36,6 +33,7 @@ export interface Feature {
privileges: {
[key: string]: FeaturePrivilegeDefinition;
};
privilegesTooltip?: string;
}

// Each feature gets its own property on the UICapabilities object,
Expand All @@ -60,9 +58,6 @@ const schema = Joi.object({
.pattern(
featurePrivilegePartRegex,
Joi.object({
metadata: Joi.object({
tooltip: Joi.string(),
}),
management: Joi.object().pattern(managementSectionIdRegex, Joi.array().items(Joi.string())),
catalogue: Joi.array().items(Joi.string()),
api: Joi.array().items(Joi.string()),
Expand All @@ -83,6 +78,7 @@ const schema = Joi.object({
})
)
.required(),
privilegesTooltip: Joi.string(),
});

const features: Record<string, Feature> = {};
Expand Down

0 comments on commit b58b799

Please sign in to comment.