Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving where the privileges tooltips are specified #15

Merged
merged 2 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -40,11 +40,6 @@ interface Props {
disabled?: boolean;
}

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

interface TableFeature extends Feature {
hasAnyPrivilegeAssigned: boolean;
}
Expand Down Expand Up @@ -105,30 +100,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