Skip to content

Commit

Permalink
[ML] Use getAnalysisType, reorder import Link, rename AdJobLink
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Sep 16, 2020
1 parent 0d83eac commit cc8f5dd
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
TrainedModelStat,
} from '../../../../../../../common/types/inference';
import {
getAnalysisType,
REFRESH_ANALYTICS_LIST_STATE,
refreshAnalyticsList$,
useRefreshAnalyticsList,
Expand Down Expand Up @@ -286,9 +287,9 @@ export const ModelsList: FC = () => {
page: ML_PAGES.DATA_FRAME_ANALYTICS_EXPLORATION,
pageState: {
jobId: item.metadata?.analytics_config.id as string,
analysisType: Object.keys(
item.metadata?.analytics_config.analysis
)[0] as DataFrameAnalysisConfigType,
analysisType: getAnalysisType(
item.metadata?.analytics_config
) as DataFrameAnalysisConfigType,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DeepPartial, DeepReadonly } from '../../../../../../../common/types/com
import { checkPermission } from '../../../../../capabilities/check_capabilities';
import { mlNodesAvailable } from '../../../../../ml_nodes_check';

import { defaultSearchQuery } from '../../../../common/analytics';
import { defaultSearchQuery, getAnalysisType } from '../../../../common/analytics';
import { CloneDataFrameAnalyticsConfig } from '../../components/action_clone';
import {
DataFrameAnalyticsConfig,
Expand Down Expand Up @@ -291,7 +291,7 @@ export function getFormStateFromJobConfig(
analyticsJobConfig: Readonly<CloneDataFrameAnalyticsConfig>,
isClone: boolean = true
): Partial<State['form']> {
const jobType = Object.keys(analyticsJobConfig.analysis)[0] as DataFrameAnalysisConfigType;
const jobType = getAnalysisType(analyticsJobConfig.analysis) as DataFrameAnalysisConfigType;

const resultState: Partial<State['form']> = {
jobType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
GetDataFrameAnalyticsStatsResponseError,
GetDataFrameAnalyticsStatsResponseOk,
} from '../../../../../services/ml_api_service/data_frame_analytics';
import { REFRESH_ANALYTICS_LIST_STATE, refreshAnalyticsList$ } from '../../../../common';
import {
getAnalysisType,
REFRESH_ANALYTICS_LIST_STATE,
refreshAnalyticsList$,
} from '../../../../common';

import {
DATA_FRAME_MODE,
Expand Down Expand Up @@ -140,7 +144,7 @@ export const getAnalyticsFactory = (
checkpointing: {},
config,
id: config.id,
job_type: Object.keys(config.analysis)[0] as DataFrameAnalysisConfigType,
job_type: getAnalysisType(config.analysis) as DataFrameAnalysisConfigType,
mode: DATA_FRAME_MODE.BATCH,
state: stats.state,
stats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const ResultsLinks: FC<Props> = ({
} = useMlKibana();

useEffect(() => {
let unamounted = false;
let unmounted = false;

const getDiscoverUrl = async (): Promise<void> => {
const state: DiscoverUrlGeneratorState = {
Expand All @@ -72,7 +72,7 @@ export const ResultsLinks: FC<Props> = ({
if (globalState?.time) {
state.timeRange = globalState.time;
}
if (!unamounted) {
if (!unmounted) {
const discoverUrlGenerator = getUrlGenerator(DISCOVER_APP_URL_GENERATOR);
const discoverUrl = await discoverUrlGenerator.createUrl(state);
setDiscoverLink(discoverUrl);
Expand All @@ -81,7 +81,7 @@ export const ResultsLinks: FC<Props> = ({
getDiscoverUrl();

return () => {
unamounted = true;
unmounted = true;
};
}, [indexPatternId, getUrlGenerator]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
/*
* React component for rendering EuiEmptyPrompt when no jobs were found.
*/

import { Link } from 'react-router-dom';
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';

import { EuiEmptyPrompt, EuiButton } from '@elastic/eui';
import { ML_PAGES } from '../../../../../common/constants/ml_url_generator';
import { Link } from 'react-router-dom';
import { useMlLink } from '../../../contexts/kibana/use_create_url';

export const ExplorerNoJobsFound = () => {
const ADJobsManagementUrl = useMlLink({
page: ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
import React from 'react';

import { JobGroup } from '../job_group';
import { ADJobIdLink } from './job_id_link';
import { AnomalyDetectionJobIdLink } from './job_id_link';

export function JobDescription({ job, isManagementTable }) {
return (
Expand All @@ -17,7 +17,7 @@ export function JobDescription({ job, isManagementTable }) {
{job.description} &nbsp;
{job.groups.map((group) => {
if (isManagementTable === true) {
return <ADJobIdLink key={group} groupId={group} />;
return <AnomalyDetectionJobIdLink key={group} groupId={group} />;
}
return <JobGroup key={group} name={group} />;
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ interface GroupIdLink {
children: string;
}

type ADJobIdLinkProps = JobIdLink | GroupIdLink;
type AnomalyDetectionJobIdLinkProps = JobIdLink | GroupIdLink;

function isGroupIdLink(props: JobIdLink | GroupIdLink): props is GroupIdLink {
return (props as GroupIdLink).groupId !== undefined;
}
export const ADJobIdLink = (props: ADJobIdLinkProps) => {
export const AnomalyDetectionJobIdLink = (props: AnomalyDetectionJobIdLinkProps) => {
const mlUrlGenerator = useMlUrlGenerator();
const {
services: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { TIME_FORMAT } from '../../../../../../common/constants/time_format';
import { EuiBadge, EuiBasicTable, EuiButtonIcon, EuiScreenReaderOnly } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { ADJobIdLink } from './job_id_link';
import { AnomalyDetectionJobIdLink } from './job_id_link';

const PAGE_SIZE = 10;
const PAGE_SIZE_OPTIONS = [10, 25, 50];
Expand Down Expand Up @@ -71,7 +71,7 @@ export class JobsList extends Component {
return id;
}

return <ADJobIdLink key={id} id={id} />;
return <AnomalyDetectionJobIdLink key={id} id={id} />;
}