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

[ML] Adds capabilities and ML node check to create job button in dashboard #172022

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -28,6 +28,7 @@ import { i18n } from '@kbn/i18n';
import { useMlKibana } from '../../../contexts/kibana';
import { ML_PAGES } from '../../../../../common/constants/locator';
import { PLUGIN_ID } from '../../../../../common/constants/app';
import { MlNodeAvailableWarningShared } from '../../node_available_warning';

const JOB_FILTER_FIELDS = ['job_id', 'groups'];
const GROUP_FILTER_FIELDS = ['id'];
Expand All @@ -43,11 +44,15 @@ export function JobSelectorTable({
withTimeRangeSelector,
}) {
const [sortableProperties, setSortableProperties] = useState();
const [mlNodesAvailable, setMlNodesAvailable] = useState(true);
const [currentTab, setCurrentTab] = useState('Jobs');

const {
services: {
application: { navigateToApp },
application: {
navigateToApp,
capabilities: { ml: mlCapabilities },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, to close off #163575 we also need to add a check for ML nodes being available.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in dae614e

},
},
} = useMlKibana();

Expand Down Expand Up @@ -258,6 +263,7 @@ export function JobSelectorTable({

return (
<Fragment>
<MlNodeAvailableWarningShared nodeAvailableCallback={setMlNodesAvailable} />
{jobs.length === 0 && (
<EuiCallOut
title={
Expand All @@ -269,7 +275,11 @@ export function JobSelectorTable({
iconType="iInCircle"
>
<EuiText textAlign="center">
<EuiButton color="primary" onClick={navigateToWizard}>
<EuiButton
color="primary"
onClick={navigateToWizard}
disabled={mlCapabilities.canCreateJob === false || mlNodesAvailable === false}
>
<FormattedMessage
id="xpack.ml.jobSelector.createJobButtonLabel"
defaultMessage="Create job"
Expand Down
Expand Up @@ -11,6 +11,9 @@ import { fireEvent, render } from '@testing-library/react'; // eslint-disable-li
import { JobSelectorTable } from './job_selector_table';

jest.mock('../../../contexts/kibana');
jest.mock('../../node_available_warning', () => {
return { MlNodeAvailableWarningShared: () => <div /> };
});

const props = {
ganttBarWidth: 299,
Expand Down
Expand Up @@ -38,7 +38,15 @@ export const kibanaContextMock = {
services: {
uiSettings: { get: jest.fn() },
chrome: { recentlyAccessed: { add: jest.fn() } },
application: { navigateToApp: jest.fn(), navigateToUrl: jest.fn() },
application: {
navigateToApp: jest.fn(),
navigateToUrl: jest.fn(),
capabilities: {
ml: {
canCreateJob: true,
},
},
},
http: {
basePath: {
get: jest.fn(),
Expand Down