Skip to content

Commit

Permalink
update types
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Jan 6, 2020
1 parent c7f86dc commit 5fb02c5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ export enum INDEX_STATUS {
ERROR,
}

export interface FieldSelectionItem {
name: string;
mappings_types: string[];
is_included: boolean;
is_required: boolean;
feature_type?: string;
reason?: string;
}

export interface DfAnalyticsExplainResponse {
field_selection: FieldSelectionItem[];
memory_estimation: {
expected_memory_without_disk: string;
expected_memory_with_disk: string;
};
}

export interface Eval {
meanSquaredError: number | string;
rSquared: number | string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Data Frame Analytics: <CreateAnalyticsForm />', () => {
);

const euiFormRows = wrapper.find('EuiFormRow');
expect(euiFormRows.length).toBe(8);
expect(euiFormRows.length).toBe(9);

const row1 = euiFormRows.at(0);
expect(row1.find('label').text()).toBe('Job type');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, { Fragment, FC, useEffect } from 'react';

import {
EuiComboBox,
EuiComboBoxOptionProps,
EuiForm,
EuiFieldText,
EuiFormRow,
Expand All @@ -32,7 +33,6 @@ import {
JOB_TYPES,
DEFAULT_MODEL_MEMORY_LIMIT,
getJobConfigFromFormState,
Option,
} from '../../hooks/use_create_analytics_form/state';
import { JOB_ID_MAX_LENGTH } from '../../../../../../../common/constants/validation';
import { Messages } from './messages';
Expand All @@ -43,6 +43,12 @@ import {
IndexPattern,
indexPatterns,
} from '../../../../../../../../../../../src/plugins/data/public';
import { DfAnalyticsExplainResponse, FieldSelectionItem } from '../../../../common/analytics';

// based on code used by `ui/index_patterns` internally
// remove the space character from the list of illegal characters
INDEX_PATTERN_ILLEGAL_CHARACTERS.pop();
const characterList = INDEX_PATTERN_ILLEGAL_CHARACTERS.join(', ');

const BASIC_NUMERICAL_TYPES = new Set([
ES_FIELD_TYPES.LONG,
Expand Down Expand Up @@ -146,7 +152,7 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
if (jobType === JOB_TYPES.CLASSIFICATION) return isSupportedByClassification;
};

const onCreateOption = (searchValue: string, flattenedOptions: Option[]) => {
const onCreateOption = (searchValue: string, flattenedOptions: EuiComboBoxOptionProps[]) => {
const normalizedSearchValue = searchValue.trim().toLowerCase();

if (!normalizedSearchValue) {
Expand All @@ -159,9 +165,9 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta

// Create the option if it doesn't exist.
if (
flattenedOptions.findIndex(
flattenedOptions.some(
(option: { label: string }) => option.label.trim().toLowerCase() === normalizedSearchValue
) === -1
)
) {
excludesOptions.push(newOption);
setFormState({ excludes: [...excludes, newOption.label] });
Expand All @@ -182,15 +188,16 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
delete jobConfig.dest;
delete jobConfig.model_memory_limit;
delete jobConfig.analyzed_fields;
const resp = await ml.dataFrameAnalytics.explainDataFrameAnalytics(jobConfig);
const resp: DfAnalyticsExplainResponse = await ml.dataFrameAnalytics.explainDataFrameAnalytics(
jobConfig
);

// If sourceIndex has changed load analysis field options again
if (previousSourceIndex !== sourceIndex || previousJobType !== jobType) {
const analyzedFieldsOptions: Array<{ label: string }> = [];

if (resp.field_selection) {
resp.field_selection.forEach((selectedField: any) => {
// TODO: update type
resp.field_selection.forEach((selectedField: FieldSelectionItem) => {
if (selectedField.is_included === true && selectedField.name !== dependentVariable) {
analyzedFieldsOptions.push({ label: selectedField.name });
}
Expand Down Expand Up @@ -297,6 +304,15 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
return errors;
};

const onSourceIndexChange = (selectedOptions: EuiComboBoxOptionProps[]) => {
setFormState({
excludes: [],
excludesOptions: [],
previousSourceIndex: sourceIndex,
sourceIndex: selectedOptions[0].label || '',
});
};

useEffect(() => {
if (isJobTypeWithDepVar && sourceIndexNameEmpty === false) {
loadDepVarOptions();
Expand Down Expand Up @@ -438,14 +454,7 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
selectedOptions={
indexPatternsMap[sourceIndex] !== undefined ? [{ label: sourceIndex }] : []
}
onChange={selectedOptions => {
setFormState({
excludes: [],
excludesOptions: [],
previousSourceIndex: sourceIndex,
sourceIndex: selectedOptions[0].label || '',
});
}}
onChange={onSourceIndexChange}
isClearable={false}
data-test-subj="mlAnalyticsCreateJobFlyoutSourceIndexSelect"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiComboBoxOptionProps } from '@elastic/eui';
import { DeepPartial } from '../../../../../../../common/types/common';
import { checkPermission } from '../../../../../privilege/check_privilege';
import { mlNodesAvailable } from '../../../../../ml_nodes_check/check_ml_nodes';
Expand Down Expand Up @@ -38,26 +39,22 @@ export enum JOB_TYPES {
CLASSIFICATION = 'classification',
}

export interface Option {
label: string;
}

export interface State {
advancedEditorMessages: FormMessage[];
advancedEditorRawString: string;
form: {
createIndexPattern: boolean;
dependentVariable: DependentVariable;
dependentVariableFetchFail: boolean;
dependentVariableOptions: Option[] | [];
dependentVariableOptions: EuiComboBoxOptionProps[] | [];
description: string;
destinationIndex: EsIndexName;
destinationIndexNameExists: boolean;
destinationIndexNameEmpty: boolean;
destinationIndexNameValid: boolean;
destinationIndexPatternTitleExists: boolean;
excludes: string[];
excludesOptions: Option[];
excludesOptions: EuiComboBoxOptionProps[];
fieldOptionsFetchFail: boolean;
jobId: DataFrameAnalyticsId;
jobIdExists: boolean;
Expand Down

0 comments on commit 5fb02c5

Please sign in to comment.