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] Add doc link in help menu on more ML pages #86500

Merged
merged 9 commits into from
Jan 4, 2021
89 changes: 49 additions & 40 deletions x-pack/plugins/ml/public/application/access_denied/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,53 @@ import {
EuiTitle,
} from '@elastic/eui';
import { NavigationMenu } from '../components/navigation_menu';
import { HelpMenu } from '../components/help_menu';
import { useMlKibana } from '../contexts/kibana';

export const Page = () => (
<Fragment>
<NavigationMenu tabId="access-denied" />
<EuiPage>
<EuiPageBody>
<EuiPageContentHeader>
<EuiPageContentHeaderSection>
<EuiTitle>
<h1>
<FormattedMessage
id="xpack.ml.management.jobsList.accessDeniedTitle"
defaultMessage="Access denied"
/>
</h1>
</EuiTitle>
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
<EuiPageContentBody>
<EuiSpacer size="m" />
<EuiCallOut
title={i18n.translate('xpack.ml.accessDenied.label', {
defaultMessage: 'Insufficient permissions',
})}
color="danger"
iconType="cross"
>
<EuiText size="s">
<p>
<FormattedMessage
id="xpack.ml.accessDenied.description"
defaultMessage="You don’t have permission to access the ML plugin"
/>
</p>
</EuiText>
</EuiCallOut>
</EuiPageContentBody>
</EuiPageBody>
</EuiPage>
</Fragment>
);
export const Page = () => {
const {
services: { docLinks },
} = useMlKibana();
const helpLink = docLinks.links.ml.guide;
return (
<Fragment>
<NavigationMenu tabId="access-denied" />
<EuiPage>
<EuiPageBody>
<EuiPageContentHeader>
<EuiPageContentHeaderSection>
<EuiTitle>
<h1>
<FormattedMessage
id="xpack.ml.management.jobsList.accessDeniedTitle"
defaultMessage="Access denied"
/>
</h1>
</EuiTitle>
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
<EuiPageContentBody>
<EuiSpacer size="m" />
<EuiCallOut
title={i18n.translate('xpack.ml.accessDenied.label', {
defaultMessage: 'Insufficient permissions',
})}
color="danger"
iconType="cross"
>
<EuiText size="s">
<p>
<FormattedMessage
id="xpack.ml.accessDenied.description"
defaultMessage="You don’t have permission to access the ML plugin"
/>
</p>
</EuiText>
</EuiCallOut>
</EuiPageContentBody>
</EuiPageBody>
</EuiPage>
<HelpMenu docLink={helpLink} />
</Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,43 @@ import { ClassificationExploration } from './components/classification_explorati

import { ANALYSIS_CONFIG_TYPE } from '../../../../../common/constants/data_frame_analytics';
import { DataFrameAnalysisConfigType } from '../../../../../common/types/data_frame_analytics';
import { HelpMenu } from '../../../components/help_menu';
import { useMlKibana } from '../../../contexts/kibana';

export const Page: FC<{
jobId: string;
analysisType: DataFrameAnalysisConfigType;
}> = ({ jobId, analysisType }) => (
<>
<NavigationMenu tabId="data_frame_analytics" />
<EuiPage data-test-subj="mlPageDataFrameAnalyticsExploration">
<EuiPageBody style={{ maxWidth: 'calc(100% - 0px)' }}>
<EuiPageContentHeader>
<EuiPageContentHeaderSection>
<EuiTitle>
<h1>{jobId}</h1>
</EuiTitle>
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
<EuiPageContentBody style={{ maxWidth: 'calc(100% - 0px)' }}>
{analysisType === ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION && (
<OutlierExploration jobId={jobId} />
)}
{analysisType === ANALYSIS_CONFIG_TYPE.REGRESSION && (
<RegressionExploration jobId={jobId} />
)}
{analysisType === ANALYSIS_CONFIG_TYPE.CLASSIFICATION && (
<ClassificationExploration jobId={jobId} />
)}
</EuiPageContentBody>
</EuiPageBody>
</EuiPage>
</>
);
}> = ({ jobId, analysisType }) => {
const {
services: { docLinks },
} = useMlKibana();
const helpLink = docLinks.links.ml.dataFrameAnalytics;
return (
<>
<NavigationMenu tabId="data_frame_analytics" />
<EuiPage data-test-subj="mlPageDataFrameAnalyticsExploration">
<EuiPageBody style={{ maxWidth: 'calc(100% - 0px)' }}>
<EuiPageContentHeader>
<EuiPageContentHeaderSection>
<EuiTitle>
<h1>{jobId}</h1>
</EuiTitle>
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
<EuiPageContentBody style={{ maxWidth: 'calc(100% - 0px)' }}>
{analysisType === ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION && (
<OutlierExploration jobId={jobId} />
)}
{analysisType === ANALYSIS_CONFIG_TYPE.REGRESSION && (
<RegressionExploration jobId={jobId} />
)}
{analysisType === ANALYSIS_CONFIG_TYPE.CLASSIFICATION && (
<ClassificationExploration jobId={jobId} />
)}
</EuiPageContentBody>
</EuiPageBody>
</EuiPage>
<HelpMenu docLink={helpLink} />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import { usePageUrlState } from '../../../util/url_state';
import { ListingPageUrlState } from '../../../../../common/types/common';
import { DataFrameAnalyticsListColumn } from './components/analytics_list/common';
import { ML_PAGES } from '../../../../../common/constants/ml_url_generator';
import { HelpMenu } from '../../../components/help_menu';
import { useMlKibana } from '../../../contexts/kibana';

export const getDefaultDFAListState = (): ListingPageUrlState => ({
pageIndex: 0,
Expand All @@ -61,7 +63,10 @@ export const Page: FC = () => {
const selectedTabId = useMemo(() => location.pathname.split('/').pop(), [location]);
const mapJobId = globalState?.ml?.jobId;
const mapModelId = globalState?.ml?.modelId;

const {
services: { docLinks },
} = useMlKibana();
const helpLink = docLinks.links.ml.dataFrameAnalytics;
return (
<Fragment>
<NavigationMenu tabId="data_frame_analytics" />
Expand Down Expand Up @@ -130,6 +135,7 @@ export const Page: FC = () => {
</EuiPageContent>
</EuiPageBody>
</EuiPage>
<HelpMenu docLink={helpLink} />
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it may be better if we add the HelpMenu link into all the ML pages in one single PR. Otherwise if you switch to a page where it isn't explicitly set like this, it will remain pointing to the last configured link. For example, here on the Data Visualizer page the link will open up https://www.elastic.co/guide/en/machine-learning/master/ml-dfanalytics.html as the Data Visualizer page doesn't contain its own HelpMenu tag.

https://www.elastic.co/guide/en/machine-learning/master/ml-dfanalytics.html

From a quick look, I think you need to set it on all the pages which contain NavigationMenu, which would be:

./access_denied/page.tsx
./datavisualizer/datavisualizer_selector.tsx
./datavisualizer/file_based/file_datavisualizer.tsx
./datavisualizer/index_based/page.tsx
./data_frame_analytics/pages/analytics_exploration/page.tsx
./data_frame_analytics/pages/analytics_management/page.tsx
./explorer/explorer.js
./jobs/jobs_list/jobs.tsx
./overview/overview_page.tsx
./settings/calendars/edit/new_calendar.js
./settings/calendars/list/calendars_list.js
./settings/filter_lists/edit/edit_filter_list.js
./settings/filter_lists/list/filter_lists.js
./settings/settings.tsx
./timeseriesexplorer/timeseriesexplorer_page.tsx

</Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useTimefilter, useMlKibana, useNavigateToPath } from '../contexts/kiban

import { NavigationMenu } from '../components/navigation_menu';
import { getMaxBytesFormatted } from './file_based/components/utils';
import { HelpMenu } from '../components/help_menu';

function startTrialDescription() {
return (
Expand Down Expand Up @@ -55,8 +56,10 @@ export const DatavisualizerSelector: FC = () => {
services: {
licenseManagement,
http: { basePath },
docLinks,
},
} = useMlKibana();
const helpLink = docLinks.links.ml.guide;
const navigateToPath = useNavigateToPath();

const startTrialVisible =
Expand Down Expand Up @@ -205,6 +208,7 @@ export const DatavisualizerSelector: FC = () => {
)}
</EuiPageBody>
</EuiPage>
<HelpMenu docLink={helpLink} />
</Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { IUiSettingsClient } from 'kibana/public';
import { useTimefilter } from '../../contexts/kibana';
import { NavigationMenu } from '../../components/navigation_menu';
import { getIndexPatternsContract } from '../../util/index_utils';
import { HelpMenu } from '../../components/help_menu';
import { useMlKibana } from '../../contexts/kibana';

// @ts-ignore
import { FileDataVisualizerView } from './components/file_datavisualizer_view/index';
Expand All @@ -21,10 +23,15 @@ export interface FileDataVisualizerPageProps {
export const FileDataVisualizerPage: FC<FileDataVisualizerPageProps> = ({ kibanaConfig }) => {
useTimefilter({ timeRangeSelector: false, autoRefreshSelector: false });
const indexPatterns = getIndexPatternsContract();
const {
services: { docLinks },
} = useMlKibana();
const helpLink = docLinks.links.ml.guide;
return (
<Fragment>
<NavigationMenu tabId="datavisualizer" />
<FileDataVisualizerView indexPatterns={indexPatterns} kibanaConfig={kibanaConfig} />
<HelpMenu docLink={helpLink} />
</Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import type { FieldRequestConfig, FieldVisConfig } from './common';
import type { DataVisualizerIndexBasedAppState } from '../../../../common/types/ml_url_generator';
import type { OverallStats } from '../../../../common/types/datavisualizer';
import { MlJobFieldType } from '../../../../common/types/field_types';
import { HelpMenu } from '../../components/help_menu';
import { useMlKibana } from '../../contexts/kibana';

interface DataVisualizerPageState {
overallStats: OverallStats;
Expand Down Expand Up @@ -659,7 +661,10 @@ export const Page: FC = () => {
}
return { visibleFieldsCount: _visibleFieldsCount, totalFieldsCount: _totalFieldsCount };
}, [overallStats, showEmptyFields]);

const {
services: { docLinks },
} = useMlKibana();
const helpLink = docLinks.links.ml.guide;
return (
<Fragment>
<NavigationMenu tabId="datavisualizer" />
Expand Down Expand Up @@ -747,6 +752,7 @@ export const Page: FC = () => {
</EuiPageContentBody>
</EuiPageBody>
</EuiPage>
<HelpMenu docLink={helpLink} />
</Fragment>
);
};
8 changes: 7 additions & 1 deletion x-pack/plugins/ml/public/application/jobs/jobs_list/jobs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { JobsListView } from './components/jobs_list_view/index';
import { usePageUrlState } from '../../util/url_state';
import { ML_PAGES } from '../../../../common/constants/ml_url_generator';
import { ListingPageUrlState } from '../../../../common/types/common';
import { HelpMenu } from '../../components/help_menu';
import { useMlKibana } from '../../contexts/kibana';

interface JobsPageProps {
blockRefresh?: boolean;
Expand All @@ -31,11 +33,15 @@ export const JobsPage: FC<JobsPageProps> = (props) => {
ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE,
getDefaultAnomalyDetectionJobsListState()
);

const {
services: { docLinks },
} = useMlKibana();
const helpLink = docLinks.links.ml.anomalyDetection;
return (
<div data-test-subj="mlPageJobManagement">
<NavigationMenu tabId="anomaly_detection" />
<JobsListView {...props} jobsViewState={pageState} onJobsViewStateUpdate={setPageState} />
<HelpMenu docLink={helpLink} />
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jest.mock('../../util/url_state');

jest.mock('../../timeseriesexplorer/hooks/use_timeseriesexplorer_url_state');

jest.mock('../../components/help_menu', () => ({
HelpMenu: () => <div id="mockHelpMenu" />,
}));

jest.mock('../../contexts/kibana/kibana_context', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { of } = require('rxjs');
Expand Down Expand Up @@ -85,6 +89,11 @@ jest.mock('../../contexts/kibana/kibana_context', () => {
addDanger: () => {},
},
},
docLinks: {
links: {
ml: { anomalyDetection: jest.fn() },
},
},
},
};
},
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 @@ -21,6 +21,8 @@ import { ml } from '../../../services/ml_api_service';
import { withKibana } from '../../../../../../../../src/plugins/kibana_react/public';
import { GLOBAL_CALENDAR } from '../../../../../common/constants/calendars';
import { ML_PAGES } from '../../../../../common/constants/ml_url_generator';
import { getDocLinks } from '../../../util/dependency_cache';
import { HelpMenu } from '../../../components/help_menu';

class NewCalendarUI extends Component {
static propTypes = {
Expand Down Expand Up @@ -328,6 +330,8 @@ class NewCalendarUI extends Component {
isGlobalCalendar,
} = this.state;

const helpLink = getDocLinks().links.ml.calendars;

let modal = '';

if (isNewEventModalVisible) {
Expand Down Expand Up @@ -389,6 +393,7 @@ class NewCalendarUI extends Component {
{modal}
</EuiPageBody>
</EuiPage>
<HelpMenu docLink={helpLink} />
</Fragment>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ jest.mock('../../../contexts/kibana/use_create_url', () => ({
jest.mock('../../../components/navigation_menu', () => ({
NavigationMenu: () => <div id="mockNavigationMenu" />,
}));

jest.mock('../../../components/help_menu', () => ({
HelpMenu: () => <div id="mockHelpMenu" />,
}));

jest.mock('../../../util/dependency_cache', () => ({
getDocLinks: () => ({
links: {
ml: { calendars: jest.fn() },
},
}),
}));

jest.mock('../../../capabilities/check_capabilities', () => ({
checkPermission: () => true,
}));
Expand Down

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

Loading