Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] DF Analytics: Creation wizard part 1 #67564

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
661b55b
create newJob route and start of wizard
alvarezmelissa87 Apr 21, 2020
a002ba2
wip: create configStep component
alvarezmelissa87 Apr 23, 2020
c517da4
finish configStep form and details
alvarezmelissa87 Apr 24, 2020
6bb45c5
wip: create andvanced step components
alvarezmelissa87 Apr 24, 2020
bdf2906
create details step component
alvarezmelissa87 Apr 27, 2020
7226ab7
createStep component
alvarezmelissa87 Apr 27, 2020
633ccf1
ensure advanced options are correct for each job type
alvarezmelissa87 Apr 28, 2020
70185db
add validation to each step
alvarezmelissa87 Apr 29, 2020
1461140
use custom table for excludes
alvarezmelissa87 Apr 30, 2020
fdca5fd
move customSelectionTable to shared components
alvarezmelissa87 May 4, 2020
3aecbc7
form validation for advanced fields
alvarezmelissa87 May 4, 2020
11dd4e1
wip: source index selection modal
alvarezmelissa87 May 12, 2020
12cf4b4
add source index preview
alvarezmelissa87 May 13, 2020
dae899c
update details
alvarezmelissa87 May 18, 2020
a32ec5a
ensure advanced parameters added to config on creation
alvarezmelissa87 May 26, 2020
1e77fbe
can create job from savedSearch. can set source query in ui
alvarezmelissa87 May 26, 2020
29f80cb
validate source object has supported fields
alvarezmelissa87 May 26, 2020
68236b3
eslint updates
alvarezmelissa87 May 27, 2020
d7f9234
update tests. comment out clone action for now
alvarezmelissa87 May 29, 2020
0b40a5e
add create button to advanced editor
alvarezmelissa87 May 29, 2020
732b8c6
remove deprecated test helper functions
alvarezmelissa87 May 30, 2020
1d1cb3f
fix translation errors
alvarezmelissa87 May 31, 2020
5a6a567
update help text. read only once job created.
alvarezmelissa87 Jun 2, 2020
2ef783e
fix functional tests
alvarezmelissa87 Jun 3, 2020
336bad4
add nextStepNav to df service for tests
alvarezmelissa87 Jun 3, 2020
7c0a368
fix excludes table page jump and hyperParameter not showing in details
alvarezmelissa87 Jun 3, 2020
e984987
fix checkbox width for custom table
alvarezmelissa87 Jun 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { Pager } from '@elastic/eui/lib/services';
import { i18n } from '@kbn/i18n';

const JOBS_PER_PAGE = 20;
const ITEMS_PER_PAGE = 20;

function getError(error) {
if (error !== null) {
Expand All @@ -43,23 +43,26 @@ function getError(error) {
}

export function CustomSelectionTable({
checkboxDisabledCheck,
columns,
filterDefaultFields,
filters,
items,
itemsPerPage = ITEMS_PER_PAGE,
onTableChange,
radioDisabledCheck,
selectedIds,
singleSelection,
sortableProperties,
timeseriesOnly,
tableItemId = 'id',
}) {
const [itemIdToSelectedMap, setItemIdToSelectedMap] = useState(getCurrentlySelectedItemIdsMap());
const [currentItems, setCurrentItems] = useState(items);
const [lastSelected, setLastSelected] = useState(selectedIds);
const [sortedColumn, setSortedColumn] = useState('');
const [pager, setPager] = useState();
const [pagerSettings, setPagerSettings] = useState({
itemsPerPage: JOBS_PER_PAGE,
itemsPerPage: itemsPerPage,
firstItemIndex: 0,
lastItemIndex: 1,
});
Expand All @@ -77,9 +80,9 @@ export function CustomSelectionTable({
}, [selectedIds]); // eslint-disable-line

useEffect(() => {
const tablePager = new Pager(currentItems.length, JOBS_PER_PAGE);
const tablePager = new Pager(currentItems.length, itemsPerPage);
setPagerSettings({
itemsPerPage: JOBS_PER_PAGE,
itemsPerPage: itemsPerPage,
firstItemIndex: tablePager.getFirstItemIndex(),
lastItemIndex: tablePager.getLastItemIndex(),
});
Expand All @@ -100,7 +103,7 @@ export function CustomSelectionTable({

function handleTableChange({ isSelected, itemId }) {
const selectedMapIds = Object.getOwnPropertyNames(itemIdToSelectedMap);
const currentItemIds = currentItems.map((item) => item.id);
const currentItemIds = currentItems.map((item) => item[tableItemId]);

let currentSelected = selectedMapIds.filter(
(id) => itemIdToSelectedMap[id] === true && id !== itemId
Expand All @@ -124,11 +127,11 @@ export function CustomSelectionTable({
onTableChange(currentSelected);
}

function handleChangeItemsPerPage(itemsPerPage) {
pager.setItemsPerPage(itemsPerPage);
function handleChangeItemsPerPage(numItemsPerPage) {
pager.setItemsPerPage(numItemsPerPage);
setPagerSettings({
...pagerSettings,
itemsPerPage,
itemsPerPage: numItemsPerPage,
firstItemIndex: pager.getFirstItemIndex(),
lastItemIndex: pager.getLastItemIndex(),
});
Expand Down Expand Up @@ -161,7 +164,9 @@ export function CustomSelectionTable({
}

function areAllItemsSelected() {
const indexOfUnselectedItem = currentItems.findIndex((item) => !isItemSelected(item.id));
const indexOfUnselectedItem = currentItems.findIndex(
(item) => !isItemSelected(item[tableItemId])
);
return indexOfUnselectedItem === -1;
}

Expand Down Expand Up @@ -199,7 +204,7 @@ export function CustomSelectionTable({
function toggleAll() {
const allSelected = areAllItemsSelected() || itemIdToSelectedMap.all === true;
const newItemIdToSelectedMap = {};
currentItems.forEach((item) => (newItemIdToSelectedMap[item.id] = !allSelected));
currentItems.forEach((item) => (newItemIdToSelectedMap[item[tableItemId]] = !allSelected));
setItemIdToSelectedMap(newItemIdToSelectedMap);
handleTableChange({ isSelected: !allSelected, itemId: 'all' });
}
Expand Down Expand Up @@ -255,20 +260,23 @@ export function CustomSelectionTable({
<EuiTableRowCellCheckbox key={column.id}>
{!singleSelection && (
<EuiCheckbox
id={`${item.id}-checkbox`}
data-test-subj={`${item.id}-checkbox`}
checked={isItemSelected(item.id)}
onChange={() => toggleItem(item.id)}
disabled={
checkboxDisabledCheck !== undefined ? checkboxDisabledCheck(item) : undefined
}
id={`${item[tableItemId]}-checkbox`}
data-test-subj={`${item[tableItemId]}-checkbox`}
checked={isItemSelected(item[tableItemId])}
onChange={() => toggleItem(item[tableItemId])}
type="inList"
/>
)}
{singleSelection && (
<EuiRadio
id={item.id}
data-test-subj={`${item.id}-radio-button`}
checked={isItemSelected(item.id)}
onChange={() => toggleItem(item.id)}
disabled={timeseriesOnly && item.isSingleMetricViewerJob === false}
id={item[tableItemId]}
data-test-subj={`${item[tableItemId]}-radio-button`}
checked={isItemSelected(item[tableItemId])}
onChange={() => toggleItem(item[tableItemId])}
disabled={radioDisabledCheck !== undefined ? radioDisabledCheck(item) : undefined}
/>
)}
</EuiTableRowCellCheckbox>
Expand Down Expand Up @@ -299,11 +307,11 @@ export function CustomSelectionTable({

return (
<EuiTableRow
key={item.id}
isSelected={isItemSelected(item.id)}
key={item[tableItemId]}
isSelected={isItemSelected(item[tableItemId])}
isSelectable={true}
hasActions={true}
data-test-subj="mlFlyoutJobSelectorTableRow"
data-test-subj="mlCustomSelectionTableRow"
>
{cells}
</EuiTableRow>
Expand Down Expand Up @@ -331,7 +339,7 @@ export function CustomSelectionTable({
<Fragment>
<EuiSpacer size="s" />
<EuiFlexGroup direction="column">
<EuiFlexItem grow={false} data-test-subj="mlFlyoutJobSelectorSearchBar">
<EuiFlexItem grow={false} data-test-subj="mlCustomSelectionTableSearchBar">
<EuiSearchBar
defaultQuery={query}
box={{
Expand Down Expand Up @@ -359,7 +367,7 @@ export function CustomSelectionTable({
<EuiFlexItem grow={false}>{renderSelectAll(true)}</EuiFlexItem>
</EuiFlexGroup>
</EuiTableHeaderMobile>
<EuiTable data-test-subj="mlFlyoutJobSelectorTable">
<EuiTable data-test-subj="mlCustomSelectionTable">
<EuiTableHeader>{renderHeaderCells()}</EuiTableHeader>
<EuiTableBody>{renderRows()}</EuiTableBody>
</EuiTable>
Expand All @@ -368,7 +376,7 @@ export function CustomSelectionTable({
<EuiTablePagination
activePage={pager.getCurrentPageIndex()}
itemsPerPage={pagerSettings.itemsPerPage}
itemsPerPageOptions={[10, JOBS_PER_PAGE, 50]}
itemsPerPageOptions={[5, 10, 20, 50]}
pageCount={pager.getTotalPages()}
onChangeItemsPerPage={handleChangeItemsPerPage}
onChangePage={(pageIndex) => handlePageChange(pageIndex)}
Expand All @@ -379,13 +387,16 @@ export function CustomSelectionTable({
}

CustomSelectionTable.propTypes = {
checkboxDisabledCheck: PropTypes.func,
columns: PropTypes.array.isRequired,
filterDefaultFields: PropTypes.array,
filters: PropTypes.array,
items: PropTypes.array.isRequired,
itemsPerPage: PropTypes.number,
onTableChange: PropTypes.func.isRequired,
radioDisabledCheck: PropTypes.func,
selectedId: PropTypes.array,
singleSelection: PropTypes.bool,
sortableProperties: PropTypes.object,
timeseriesOnly: PropTypes.bool,
tableItemId: PropTypes.string,
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React, { Fragment, useState, useEffect } from 'react';
import { PropTypes } from 'prop-types';
import { CustomSelectionTable } from '../custom_selection_table';
import { CustomSelectionTable } from '../../custom_selection_table';
import { JobSelectorBadge } from '../job_selector_badge';
import { TimeRangeBar } from '../timerange_bar';

Expand Down Expand Up @@ -107,7 +107,7 @@ export function JobSelectorTable({
id: 'checkbox',
isCheckbox: true,
textOnly: false,
width: '24px',
width: '32px',
},
{
label: 'job ID',
Expand Down Expand Up @@ -157,6 +157,9 @@ export function JobSelectorTable({
filterDefaultFields={!singleSelection ? JOB_FILTER_FIELDS : undefined}
items={jobs}
onTableChange={(selectionFromTable) => onSelection({ selectionFromTable })}
radioDisabledCheck={(item) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, but as this file is being touched by this PR, could you set the width of the first checkbox column to 32px to stop the selection border being cropped. It is used twice - once for the jobs table, and once for the groups table. It needs to match the width of the euiTableRowCellCheckbox.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to 32px in fdf122f9dce26a106075d73672c0510fa95dd2f8

return timeseriesOnly && item.isSingleMetricViewerJob === false;
}}
selectedIds={selectedIds}
singleSelection={singleSelection}
sortableProperties={sortableProperties}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
@import 'pages/analytics_management/components/analytics_list/index';
@import 'pages/analytics_management/components/create_analytics_form/index';
@import 'pages/analytics_management/components/create_analytics_flyout/index';
@import 'pages/analytics_management/components/create_analytics_button/index';
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ export enum ANALYSIS_CONFIG_TYPE {
CLASSIFICATION = 'classification',
}

export enum ANALYSIS_ADVANCED_FIELDS {
FEATURE_INFLUENCE_THRESHOLD = 'feature_influence_threshold',
GAMMA = 'gamma',
LAMBDA = 'lambda',
MAX_TREES = 'max_trees',
NUM_TOP_FEATURE_IMPORTANCE_VALUES = 'num_top_feature_importance_values',
}

export enum OUTLIER_ANALYSIS_METHOD {
LOF = 'lof',
LDOF = 'ldof',
DISTANCE_KTH_NN = 'distance_kth_nn',
DISTANCE_KNN = 'distance_knn',
}

interface OutlierAnalysis {
[key: string]: {};
outlier_detection: {};
Expand Down Expand Up @@ -263,11 +278,13 @@ export const isClassificationAnalysis = (arg: any): arg is ClassificationAnalysi
};

export const isResultsSearchBoolQuery = (arg: any): arg is ResultsSearchBoolQuery => {
if (arg === undefined) return false;
const keys = Object.keys(arg);
return keys.length === 1 && keys[0] === 'bool';
};

export const isQueryStringQuery = (arg: any): arg is QueryStringQuery => {
if (arg === undefined) return false;
const keys = Object.keys(arg);
return keys.length === 1 && keys[0] === 'query_string';
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export {
IndexPattern,
REFRESH_ANALYTICS_LIST_STATE,
ANALYSIS_CONFIG_TYPE,
OUTLIER_ANALYSIS_METHOD,
RegressionEvaluateResponse,
getValuesFromResponse,
loadEvalData,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FC } from 'react';
import { EuiForm } from '@elastic/eui';

import { CreateAnalyticsStepProps } from '../../../analytics_management/hooks/use_create_analytics_form';
import { AdvancedStepForm } from './advanced_step_form';
import { AdvancedStepDetails } from './advanced_step_details';
import { ANALYTICS_STEPS } from '../../page';

export const AdvancedStep: FC<CreateAnalyticsStepProps> = ({
actions,
state,
step,
setCurrentStep,
stepActivated,
}) => {
return (
<EuiForm>
{step === ANALYTICS_STEPS.ADVANCED && (
<AdvancedStepForm actions={actions} state={state} setCurrentStep={setCurrentStep} />
)}
{step !== ANALYTICS_STEPS.ADVANCED && stepActivated === true && (
<AdvancedStepDetails setCurrentStep={setCurrentStep} state={state} />
)}
</EuiForm>
);
};
Loading