Skip to content

Commit

Permalink
changes based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Dec 9, 2019
1 parent d5c373f commit f29478c
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 51 deletions.
13 changes: 7 additions & 6 deletions x-pack/legacy/plugins/ml/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,28 @@ import ReactDOM from 'react-dom';
import 'uiExports/savedObjectTypes';

import 'ui/autoload/all';
import { IndexPatterns } from 'ui/index_patterns';

// needed to make syntax highlighting work in ace editors
import 'ace';

import { AppMountContext, AppMountParameters } from 'kibana/public';
import { DataStart } from 'src/legacy/core_plugins/data/public';
import {
IndexPatternsContract,
Plugin as DataPlugin,
} from '../../../../../../src/plugins/data/public';

import { Plugin as DataPlugin } from '../../../../../../src/plugins/data/public';
import { KibanaConfigTypeFix } from './contexts/kibana';

import { MlRouter } from './routing';

export interface MlDependencies extends AppMountParameters {
npData: ReturnType<DataPlugin['start']>;
indexPatterns: DataStart['indexPatterns']['indexPatterns'];
indexPatterns: IndexPatternsContract;
}

interface AppProps {
context: AppMountContext;
indexPatterns: IndexPatterns;
indexPatterns: IndexPatternsContract;
}

const App: FC<AppProps> = ({ context, indexPatterns }) => {
Expand All @@ -39,7 +40,7 @@ const App: FC<AppProps> = ({ context, indexPatterns }) => {
return (
<MlRouter
config={config}
setBreadCrumbs={context.core.chrome.setBreadcrumbs}
setBreadcrumbs={context.core.chrome.setBreadcrumbs}
indexPatterns={indexPatterns}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import React from 'react';

import { KibanaConfig } from 'src/legacy/server/kbn_server';
import { IndexPattern, IndexPatterns } from 'ui/index_patterns';
import {
IndexPattern,
IndexPatternsContract,
} from '../../../../../../../../src/plugins/data/public';
import { SavedSearchSavedObject } from '../../../../common/types/kibana';

// set() method is missing in original d.ts
Expand All @@ -17,9 +20,9 @@ export interface KibanaConfigTypeFix extends KibanaConfig {

export interface KibanaContextValue {
combinedQuery: any;
currentIndexPattern: IndexPattern; // TODO this should be or null
currentIndexPattern: IndexPattern; // TODO this should be IndexPattern or null
currentSavedSearch: SavedSearchSavedObject | null;
indexPatterns: IndexPatterns;
indexPatterns: IndexPatternsContract;
kibanaConfig: KibanaConfigTypeFix;
}

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

import React, { FC, Fragment } from 'react';
import { timefilter } from 'ui/timefilter';
import { IndexPatternsContract } from '../../../../../../../../src/plugins/data/public';

import { KibanaConfigTypeFix } from '../../contexts/kibana';
import { NavigationMenu } from '../../components/navigation_menu';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
*/

import { idx } from '@kbn/elastic-idx';
import { IndexPatterns } from 'ui/index_patterns';
import { IndexPatternsContract } from '../../../../../../../../../../src/plugins/data/public';
import { mlJobService } from '../../../../services/job_service';
import { loadIndexPatterns, getIndexPatternIdFromName } from '../../../../util/index_utils';
import { CombinedJob } from '../../common/job_creator/configs';
import { CREATED_BY_LABEL, JOB_TYPE } from '../../common/job_creator/util/constants';

export async function preConfiguredJobRedirect(indexPatterns: IndexPatterns) {
export async function preConfiguredJobRedirect(indexPatterns: IndexPatternsContract) {
const { job } = mlJobService.tempJobCloningObjects;
if (job) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { loadIndexPatterns, loadSavedSearches } from '../util/index_utils';
import { checkFullLicense } from '../license/check_license';
import { checkGetJobsPrivilege } from '../privilege/check_privilege';
import { getMlNodeCount } from '../ml_nodes_check/check_ml_nodes';
// import { getJobManagementBreadcrumbs } from './jobs/breadcrumbs';
import { loadMlServerInfo } from '../services/ml_server_info';
import { PageDependencies } from './router';

Expand All @@ -25,5 +24,4 @@ export const basicResolvers = (deps: PageDependencies): Resolvers => ({
loadIndexPatterns: () => loadIndexPatterns(deps.indexPatterns),
checkGetJobsPrivilege,
loadSavedSearches,
// getJobManagementBreadcrumbs(),
});
12 changes: 6 additions & 6 deletions x-pack/legacy/plugins/ml/public/application/routing/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { HashRouter, Route, RouteProps } from 'react-router-dom';
import { Location } from 'history';
import { I18nContext } from 'ui/i18n';

import { IndexPatterns } from 'ui/index_patterns';
import { IndexPatternsContract } from '../../../../../../../src/plugins/data/public';
import { KibanaContext, KibanaConfigTypeFix, KibanaContextValue } from '../contexts/kibana';
import { ChromeBreadcrumb } from '../../../../../../../src/core/public';

Expand All @@ -33,7 +33,7 @@ export interface PageProps {
}

export interface PageDependencies {
indexPatterns: IndexPatterns;
indexPatterns: IndexPatternsContract;
}

export const PageLoader: FC<{ context: KibanaContextValue }> = ({ context, children }) => {
Expand All @@ -46,9 +46,9 @@ export const PageLoader: FC<{ context: KibanaContextValue }> = ({ context, child

export const MlRouter: FC<{
config: KibanaConfigTypeFix;
setBreadCrumbs: any;
indexPatterns: IndexPatterns;
}> = ({ config, setBreadCrumbs, indexPatterns }) => {
setBreadcrumbs: (breadcrumbs: ChromeBreadcrumb[]) => void;
indexPatterns: IndexPatternsContract;
}> = ({ config, setBreadcrumbs, indexPatterns }) => {
return (
<HashRouter>
<div>
Expand All @@ -59,7 +59,7 @@ export const MlRouter: FC<{
exact
render={props => {
window.setTimeout(() => {
setBreadCrumbs(route.breadcrumbs);
setBreadcrumbs(route.breadcrumbs);
});
return route.render(props, config, { indexPatterns });
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

import React, { FC } from 'react';

// @ts-ignore
import queryString from 'query-string';
import { MlRoute, PageLoader, PageProps } from '../../router';
import { useResolver } from '../../use_resolver';
import { DatavisualizerSelector } from '../../../datavisualizer';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import React, { FC } from 'react';
import { i18n } from '@kbn/i18n';

// @ts-ignore
import queryString from 'query-string';
import { MlRoute, PageLoader, PageProps } from '../../router';
import { useResolver } from '../../use_resolver';
import { FileDataVisualizerPage } from '../../../datavisualizer/file_based';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ const PageWrapper: FC<PageProps> = ({ location, config, deps }) => {
globalState = decode(_g);
} catch (error) {
// eslint-disable-next-line no-console
// console.error('Could not parse global state');
// window.location.href = '#data_frame_analytics';
// globalState = {};
// appState = {};
console.error('Could not parse global or app state');
}
appState.mlTimeSeriesExplorer = {};
appState.fetch = () => {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface WizardPageProps extends PageProps {
jobType: JOB_TYPE;
}

const singleMetricBreadCrumbs = [
const singleMetricBreadcrumbs = [
...baseBreadcrumbs,
{
text: i18n.translate('xpack.ml.jobsBreadcrumbs.singleMetricLabel', {
Expand All @@ -35,7 +35,7 @@ const singleMetricBreadCrumbs = [
},
];

const multiMetricBreadCrumbs = [
const multiMetricBreadcrumbs = [
...baseBreadcrumbs,
{
text: i18n.translate('xpack.ml.jobsBreadcrumbs.multiMetricLabel', {
Expand All @@ -45,7 +45,7 @@ const multiMetricBreadCrumbs = [
},
];

const populationBreadCrumbs = [
const populationBreadcrumbs = [
...baseBreadcrumbs,
{
text: i18n.translate('xpack.ml.jobsBreadcrumbs.populationLabel', {
Expand All @@ -55,7 +55,7 @@ const populationBreadCrumbs = [
},
];

const advancedBreadCrumbs = [
const advancedBreadcrumbs = [
...baseBreadcrumbs,
{
text: i18n.translate('xpack.ml.jobsBreadcrumbs.advancedConfigurationLabel', {
Expand All @@ -70,31 +70,31 @@ export const singleMetricRoute: MlRoute = {
render: (props, config, deps) => (
<PageWrapper config={config} {...props} jobType={JOB_TYPE.SINGLE_METRIC} deps={deps} />
),
breadcrumbs: singleMetricBreadCrumbs,
breadcrumbs: singleMetricBreadcrumbs,
};

export const multiMetricRoute: MlRoute = {
path: '/jobs/new_job/multi_metric',
render: (props, config, deps) => (
<PageWrapper config={config} {...props} jobType={JOB_TYPE.MULTI_METRIC} deps={deps} />
),
breadcrumbs: multiMetricBreadCrumbs,
breadcrumbs: multiMetricBreadcrumbs,
};

export const populationRoute: MlRoute = {
path: '/jobs/new_job/population',
render: (props, config, deps) => (
<PageWrapper config={config} {...props} jobType={JOB_TYPE.POPULATION} deps={deps} />
),
breadcrumbs: populationBreadCrumbs,
breadcrumbs: populationBreadcrumbs,
};

export const advancedRoute: MlRoute = {
path: '/jobs/new_job/advanced',
render: (props, config, deps) => (
<PageWrapper config={config} {...props} jobType={JOB_TYPE.ADVANCED} deps={deps} />
),
breadcrumbs: advancedBreadCrumbs,
breadcrumbs: advancedBreadcrumbs,
};

const PageWrapper: FC<WizardPageProps> = ({ location, config, jobType, deps }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

import React, { FC } from 'react';
import { i18n } from '@kbn/i18n';
// @ts-ignore
import queryString from 'query-string';

import { MlRoute, PageLoader, PageProps } from '../../router';
import { useResolver } from '../../use_resolver';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

import React, { FC } from 'react';
import { i18n } from '@kbn/i18n';
// @ts-ignore
import queryString from 'query-string';

import { MlRoute, PageLoader, PageProps } from '../../router';
import { useResolver } from '../../use_resolver';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ const PageWrapper: FC<PageProps> = ({ location, config, deps }) => {
globalState = decode(_g);
} catch (error) {
// eslint-disable-next-line no-console
// console.error('Could not parse global state');
// window.location.href = '#data_frame_analytics';
// globalState = {};
// appState = {};
console.error('Could not parse global or app state');
}
appState.mlTimeSeriesExplorer = {};
globalState.fetch = () => {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IndexPattern, IndexPatterns } from 'ui/index_patterns';

import {
Field,
Aggregation,
Expand All @@ -27,7 +25,7 @@ import { getIndexPatternAndSavedSearch } from '../util/index_utils';
export function loadNewJobCapabilities(
indexPatternId: string,
savedSearchId: string,
indexPatterns: IndexPatterns
indexPatterns: IndexPatternsContract
) {
return new Promise(async (resolve, reject) => {
if (indexPatternId !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

import { toastNotifications } from 'ui/notify';
import { i18n } from '@kbn/i18n';
import { IndexPattern, IndexPatterns } from 'ui/index_patterns';
import chrome from 'ui/chrome';
import { Query } from 'src/plugins/data/public';
import { IndexPattern, IndexPatternsContract } from '../../../../../../../src/plugins/data/public';
import { IndexPatternSavedObject, SavedSearchSavedObject } from '../../../common/types/kibana';

let indexPatternCache: IndexPatternSavedObject[] = [];
let savedSearchesCache: SavedSearchSavedObject[] = [];
let indexPatternsContract: IndexPatterns | null = null;
let indexPatternsContract: IndexPatternsContract | null = null;

export function loadIndexPatterns(indexPatterns: IndexPatterns) {
export function loadIndexPatterns(indexPatterns: IndexPatternsContract) {
indexPatternsContract = indexPatterns;
const savedObjectsClient = chrome.getSavedObjectsClient();
return savedObjectsClient
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/ml/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
const { renderApp } = await import('./application/app');
return renderApp(context, {
...params,
indexPatterns: npData.indexPatterns.indexPatterns,
indexPatterns: npData.indexPatterns,
npData,
});
},
Expand Down

0 comments on commit f29478c

Please sign in to comment.