Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
* upstream/master:
  [ML] Single Metric Viewer: Fix job check. (elastic#55191)
  • Loading branch information
gmmorris committed Jan 20, 2020
2 parents 946183c + bd7f7ab commit e50378d
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import { APP_STATE_ACTION } from '../../timeseriesexplorer/timeseriesexplorer_co
import {
createTimeSeriesJobData,
getAutoZoomDuration,
validateJobSelection,
} from '../../timeseriesexplorer/timeseriesexplorer_utils';
import { TimeSeriesExplorerPage } from '../../timeseriesexplorer/timeseriesexplorer_page';
import { TimeseriesexplorerNoJobsFound } from '../../timeseriesexplorer/components/timeseriesexplorer_no_jobs_found';
import { useUrlState } from '../../util/url_state';
import { useTableInterval } from '../../components/controls/select_interval';
import { useTableSeverity } from '../../components/controls/select_severity';
Expand Down Expand Up @@ -81,6 +84,7 @@ export const TimeSeriesExplorerUrlStateManager: FC<TimeSeriesExplorerUrlStateMan
const [appState, setAppState] = useUrlState('_a');
const [globalState, setGlobalState] = useUrlState('_g');
const [lastRefresh, setLastRefresh] = useState(0);
const [selectedJobId, setSelectedJobId] = useState<string>();

const refresh = useRefresh();
useEffect(() => {
Expand Down Expand Up @@ -141,6 +145,10 @@ export const TimeSeriesExplorerUrlStateManager: FC<TimeSeriesExplorerUrlStateMan
setLastRefresh(Date.now());
appStateHandler(APP_STATE_ACTION.CLEAR);
}
const validatedJobId = validateJobSelection(jobsWithTimeRange, selectedJobIds, setGlobalState);
if (typeof validatedJobId === 'string') {
setSelectedJobId(validatedJobId);
}
}, [JSON.stringify(selectedJobIds)]);

// Next we get globalState and appState information to pass it on as props later.
Expand All @@ -156,14 +164,12 @@ export const TimeSeriesExplorerUrlStateManager: FC<TimeSeriesExplorerUrlStateMan
to: string;
} = isJobChange ? undefined : appState?.mlTimeSeriesExplorer?.zoom;

const selectedJob = selectedJobIds && mlJobService.getJob(selectedJobIds[0]);
const selectedJob = selectedJobId !== undefined ? mlJobService.getJob(selectedJobId) : undefined;
const timeSeriesJobs = createTimeSeriesJobData(mlJobService.jobs);

let autoZoomDuration: number | undefined;
if (selectedJobIds !== undefined && selectedJobIds.length === 1 && selectedJob !== undefined) {
autoZoomDuration = getAutoZoomDuration(
createTimeSeriesJobData(mlJobService.jobs),
mlJobService.getJob(selectedJobIds[0])
);
if (selectedJobId !== undefined && selectedJob !== undefined) {
autoZoomDuration = getAutoZoomDuration(timeSeriesJobs, selectedJob);
}

const appStateHandler = useCallback(
Expand Down Expand Up @@ -264,16 +270,27 @@ export const TimeSeriesExplorerUrlStateManager: FC<TimeSeriesExplorerUrlStateMan
const tzConfig = config.get('dateFormat:tz');
const dateFormatTz = tzConfig !== 'Browser' ? tzConfig : moment.tz.guess();

if (timeSeriesJobs.length === 0) {
return (
<TimeSeriesExplorerPage dateFormatTz={dateFormatTz}>
<TimeseriesexplorerNoJobsFound />
</TimeSeriesExplorerPage>
);
}

if (selectedJobId === undefined || autoZoomDuration === undefined || bounds === undefined) {
return null;
}

return (
<TimeSeriesExplorer
{...{
appStateHandler,
autoZoomDuration,
bounds,
dateFormatTz,
jobsWithTimeRange,
lastRefresh,
selectedJobIds,
selectedJobId,
selectedDetectorIndex,
selectedEntities,
selectedForecastId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import { getDateFormatTz, TimeRangeBounds } from '../explorer/explorer_utils';

declare const TimeSeriesExplorer: FC<{
appStateHandler: (action: string, payload: any) => void;
autoZoomDuration?: number;
bounds?: TimeRangeBounds;
autoZoomDuration: number;
bounds: TimeRangeBounds;
dateFormatTz: string;
jobsWithTimeRange: any[];
lastRefresh: number;
selectedJobIds: string[];
selectedJobId: string;
selectedDetectorIndex: number;
selectedEntities: any[];
selectedForecastId: string;
Expand Down
Loading

0 comments on commit e50378d

Please sign in to comment.