Skip to content

Commit

Permalink
[ML] Fix breadcrumb, permissions check, menu item.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Mar 11, 2020
1 parent 9903dd5 commit 972e455
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
*/

import { i18n } from '@kbn/i18n';
import { MANAGEMENT_BREADCRUMB } from 'ui/management/breadcrumbs';
import { JOBS_LIST_PATH } from './management_urls';

export function getJobsListBreadcrumbs() {
return [
MANAGEMENT_BREADCRUMB,
{
text: i18n.translate('xpack.ml.jobsList.breadcrumb', {
defaultMessage: 'Jobs',
Expand Down
17 changes: 12 additions & 5 deletions x-pack/legacy/plugins/ml/public/application/management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ import { i18n } from '@kbn/i18n';
import chrome from 'ui/chrome';
import { metadata } from 'ui/metadata';
import { take } from 'rxjs/operators';
import { setDependencyCache } from '../util/dependency_cache';
import { renderApp } from './jobs_list';

import { ManagementSetup } from '../../../../../../../src/plugins/management/public';

import {
LicensingPluginSetup,
LICENSE_CHECK_STATE,
} from '../../../../../../plugins/licensing/public';
import { ManagementSetup } from '../../../../../../../src/plugins/management/public';

import { PLUGIN_ID } from '../../../common/constants/app';
import { MINIMUM_FULL_LICENSE } from '../../../common/license';

import { setDependencyCache } from '../util/dependency_cache';

import { getJobsListBreadcrumbs } from './breadcrumbs';
import { renderApp } from './jobs_list';

type PluginsSetupExtended = typeof npSetup.plugins & {
// adds licensing which isn't in the PluginsSetup interface, but does exist
licensing: LicensingPluginSetup;
Expand Down Expand Up @@ -70,8 +76,9 @@ function initManagementSection(management: ManagementSetup) {
defaultMessage: 'Jobs list',
}),
order: 10,
async mount(params) {
return renderApp(params.element, {});
async mount({ element, setBreadcrumbs }) {
setBreadcrumbs(getJobsListBreadcrumbs());
return renderApp(element, {});
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { Fragment, FC, useState } from 'react';
import React, { useEffect, useState, Fragment, FC } from 'react';
import { i18n } from '@kbn/i18n';
import { I18nContext } from 'ui/i18n';
import {
Expand All @@ -18,15 +18,14 @@ import {
EuiText,
EuiTitle,
} from '@elastic/eui';
import { getDocLinks } from '../../../../util/dependency_cache';

import { checkGetManagementMlJobs } from '../../../../privilege/check_privilege';

import { getDocLinks } from '../../../../util/dependency_cache';
// @ts-ignore undeclared module
import { JobsListView } from '../../../../jobs/jobs_list/components/jobs_list_view/index';
import { DataFrameAnalyticsList } from '../../../../data_frame_analytics/pages/analytics_management/components/analytics_list';

interface Props {
isMlEnabledInSpace: boolean;
}
interface Tab {
id: string;
name: string;
Expand Down Expand Up @@ -65,11 +64,33 @@ function getTabs(isMlEnabledInSpace: boolean): Tab[] {
];
}

export const JobsListPage: FC<Props> = ({ isMlEnabledInSpace }) => {
const docLinks = getDocLinks();
const { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } = docLinks;
export const JobsListPage: FC = () => {
const [initialized, setInitialized] = useState(false);
const [isMlEnabledInSpace, setIsMlEnabledInSpace] = useState(false);
const tabs = getTabs(isMlEnabledInSpace);
const [currentTabId, setCurrentTabId] = useState(tabs[0].id);

const check = async () => {
try {
const checkPrivilege = await checkGetManagementMlJobs();
setInitialized(true);
setIsMlEnabledInSpace(checkPrivilege.mlFeatureEnabledInSpace);
} catch (e) {
// Silent fail, `checkGetManagementMlJobs()` should redirect when
// there are insufficient permissions.
}
};

useEffect(() => {
check();
}, []);

if (initialized === false) {
return null;
}

const docLinks = getDocLinks();
const { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } = docLinks;
const anomalyDetectionJobsUrl = `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-jobs.html`;
const anomalyJobsUrl = `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-dfanalytics.html`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,10 @@

import ReactDOM, { unmountComponentAtNode } from 'react-dom';
import React from 'react';
// import { canGetManagementMlJobs } from '../../privilege/check_privilege';
// import { JOBS_LIST_PATH, ACCESS_DENIED_PATH } from '../management_urls';
// import { JobsListPage, AccessDeniedPage } from './components';
import { JobsListPage } from './components';
// import { getJobsListBreadcrumbs } from '../breadcrumbs';

export const renderApp = (element: HTMLElement, appDependencies: any) => {
// const { mlFeatureEnabledInSpace } = checkPrivilege;
const mlFeatureEnabledInSpace = true;
ReactDOM.render(
React.createElement(JobsListPage, { isMlEnabledInSpace: mlFeatureEnabledInSpace }),
element
);
ReactDOM.render(React.createElement(JobsListPage), element);

return () => {
unmountComponentAtNode(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { ACCESS_DENIED_PATH } from '../management/management_urls';

let privileges: Privileges = getDefaultPrivileges();
// manage_ml requires all monitor and admin cluster privileges: https://github.com/elastic/elasticsearch/blob/664a29c8905d8ce9ba8c18aa1ed5c5de93a0eabc/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilege.java#L53
export function canGetManagementMlJobs() {
return new Promise((resolve, reject) => {
export function checkGetManagementMlJobs() {
return new Promise<{ mlFeatureEnabledInSpace: boolean }>((resolve, reject) => {
getManageMlPrivileges().then(
({ capabilities, isPlatinumOrTrialLicense, mlFeatureEnabledInSpace }) => {
privileges = capabilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ export const ml = {

checkManageMLPrivileges() {
return http({
url: `${basePath()}/ml_capabilities?ignoreSpaces=true`,
// TODO Fix http service parameters
url: `${basePath()}/ml_capabilities`, // '?ignoreSpaces=true'
method: 'GET',
});
},
Expand Down

0 comments on commit 972e455

Please sign in to comment.