Skip to content

Commit 5fb02c5

Browse files
update types
1 parent c7f86dc commit 5fb02c5

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

x-pack/legacy/plugins/ml/public/application/data_frame_analytics/common/analytics.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ export enum INDEX_STATUS {
5858
ERROR,
5959
}
6060

61+
export interface FieldSelectionItem {
62+
name: string;
63+
mappings_types: string[];
64+
is_included: boolean;
65+
is_required: boolean;
66+
feature_type?: string;
67+
reason?: string;
68+
}
69+
70+
export interface DfAnalyticsExplainResponse {
71+
field_selection: FieldSelectionItem[];
72+
memory_estimation: {
73+
expected_memory_without_disk: string;
74+
expected_memory_with_disk: string;
75+
};
76+
}
77+
6178
export interface Eval {
6279
meanSquaredError: number | string;
6380
rSquared: number | string;

x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('Data Frame Analytics: <CreateAnalyticsForm />', () => {
4040
);
4141

4242
const euiFormRows = wrapper.find('EuiFormRow');
43-
expect(euiFormRows.length).toBe(8);
43+
expect(euiFormRows.length).toBe(9);
4444

4545
const row1 = euiFormRows.at(0);
4646
expect(row1.find('label').text()).toBe('Job type');

x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React, { Fragment, FC, useEffect } from 'react';
88

99
import {
1010
EuiComboBox,
11+
EuiComboBoxOptionProps,
1112
EuiForm,
1213
EuiFieldText,
1314
EuiFormRow,
@@ -32,7 +33,6 @@ import {
3233
JOB_TYPES,
3334
DEFAULT_MODEL_MEMORY_LIMIT,
3435
getJobConfigFromFormState,
35-
Option,
3636
} from '../../hooks/use_create_analytics_form/state';
3737
import { JOB_ID_MAX_LENGTH } from '../../../../../../../common/constants/validation';
3838
import { Messages } from './messages';
@@ -43,6 +43,12 @@ import {
4343
IndexPattern,
4444
indexPatterns,
4545
} from '../../../../../../../../../../../src/plugins/data/public';
46+
import { DfAnalyticsExplainResponse, FieldSelectionItem } from '../../../../common/analytics';
47+
48+
// based on code used by `ui/index_patterns` internally
49+
// remove the space character from the list of illegal characters
50+
INDEX_PATTERN_ILLEGAL_CHARACTERS.pop();
51+
const characterList = INDEX_PATTERN_ILLEGAL_CHARACTERS.join(', ');
4652

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

149-
const onCreateOption = (searchValue: string, flattenedOptions: Option[]) => {
155+
const onCreateOption = (searchValue: string, flattenedOptions: EuiComboBoxOptionProps[]) => {
150156
const normalizedSearchValue = searchValue.trim().toLowerCase();
151157

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

160166
// Create the option if it doesn't exist.
161167
if (
162-
flattenedOptions.findIndex(
168+
flattenedOptions.some(
163169
(option: { label: string }) => option.label.trim().toLowerCase() === normalizedSearchValue
164-
) === -1
170+
)
165171
) {
166172
excludesOptions.push(newOption);
167173
setFormState({ excludes: [...excludes, newOption.label] });
@@ -182,15 +188,16 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
182188
delete jobConfig.dest;
183189
delete jobConfig.model_memory_limit;
184190
delete jobConfig.analyzed_fields;
185-
const resp = await ml.dataFrameAnalytics.explainDataFrameAnalytics(jobConfig);
191+
const resp: DfAnalyticsExplainResponse = await ml.dataFrameAnalytics.explainDataFrameAnalytics(
192+
jobConfig
193+
);
186194

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

191199
if (resp.field_selection) {
192-
resp.field_selection.forEach((selectedField: any) => {
193-
// TODO: update type
200+
resp.field_selection.forEach((selectedField: FieldSelectionItem) => {
194201
if (selectedField.is_included === true && selectedField.name !== dependentVariable) {
195202
analyzedFieldsOptions.push({ label: selectedField.name });
196203
}
@@ -297,6 +304,15 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
297304
return errors;
298305
};
299306

307+
const onSourceIndexChange = (selectedOptions: EuiComboBoxOptionProps[]) => {
308+
setFormState({
309+
excludes: [],
310+
excludesOptions: [],
311+
previousSourceIndex: sourceIndex,
312+
sourceIndex: selectedOptions[0].label || '',
313+
});
314+
};
315+
300316
useEffect(() => {
301317
if (isJobTypeWithDepVar && sourceIndexNameEmpty === false) {
302318
loadDepVarOptions();
@@ -438,14 +454,7 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
438454
selectedOptions={
439455
indexPatternsMap[sourceIndex] !== undefined ? [{ label: sourceIndex }] : []
440456
}
441-
onChange={selectedOptions => {
442-
setFormState({
443-
excludes: [],
444-
excludesOptions: [],
445-
previousSourceIndex: sourceIndex,
446-
sourceIndex: selectedOptions[0].label || '',
447-
});
448-
}}
457+
onChange={onSourceIndexChange}
449458
isClearable={false}
450459
data-test-subj="mlAnalyticsCreateJobFlyoutSourceIndexSelect"
451460
/>

x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/state.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import { EuiComboBoxOptionProps } from '@elastic/eui';
78
import { DeepPartial } from '../../../../../../../common/types/common';
89
import { checkPermission } from '../../../../../privilege/check_privilege';
910
import { mlNodesAvailable } from '../../../../../ml_nodes_check/check_ml_nodes';
@@ -38,26 +39,22 @@ export enum JOB_TYPES {
3839
CLASSIFICATION = 'classification',
3940
}
4041

41-
export interface Option {
42-
label: string;
43-
}
44-
4542
export interface State {
4643
advancedEditorMessages: FormMessage[];
4744
advancedEditorRawString: string;
4845
form: {
4946
createIndexPattern: boolean;
5047
dependentVariable: DependentVariable;
5148
dependentVariableFetchFail: boolean;
52-
dependentVariableOptions: Option[] | [];
49+
dependentVariableOptions: EuiComboBoxOptionProps[] | [];
5350
description: string;
5451
destinationIndex: EsIndexName;
5552
destinationIndexNameExists: boolean;
5653
destinationIndexNameEmpty: boolean;
5754
destinationIndexNameValid: boolean;
5855
destinationIndexPatternTitleExists: boolean;
5956
excludes: string[];
60-
excludesOptions: Option[];
57+
excludesOptions: EuiComboBoxOptionProps[];
6158
fieldOptionsFetchFail: boolean;
6259
jobId: DataFrameAnalyticsId;
6360
jobIdExists: boolean;

0 commit comments

Comments
 (0)