-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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: ensure user can switch back to form from JSON editor #73752
Merged
alvarezmelissa87
merged 8 commits into
elastic:master
from
alvarezmelissa87:ml-dfanalytics-switch-back-to-form
Jul 31, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
44390dd
wip: add reducer action to switch to form
alvarezmelissa87 b84b287
rename getFormStateFromJobConfig
alvarezmelissa87 8c1ad24
wip: types fix
alvarezmelissa87 9900223
show destIndex input when switching back from editor
alvarezmelissa87 9f14ab8
ensure validation up to date when switching to form
alvarezmelissa87 23b3c2e
cannot switch back to form if advanced config
alvarezmelissa87 369ad8e
update types
alvarezmelissa87 715d0d4
localization fix
alvarezmelissa87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,17 @@ import { i18n } from '@kbn/i18n'; | |
import { memoize } from 'lodash'; | ||
// @ts-ignore | ||
import numeral from '@elastic/numeral'; | ||
import { isEmpty } from 'lodash'; | ||
import { isValidIndexName } from '../../../../../../../common/util/es_utils'; | ||
|
||
import { collapseLiteralStrings } from '../../../../../../../../../../src/plugins/es_ui_shared/public'; | ||
|
||
import { Action, ACTION } from './actions'; | ||
import { getInitialState, getJobConfigFromFormState, State } from './state'; | ||
import { | ||
getInitialState, | ||
getFormStateFromJobConfig, | ||
getJobConfigFromFormState, | ||
State, | ||
} from './state'; | ||
import { | ||
isJobIdValid, | ||
validateModelMemoryLimitUnits, | ||
|
@@ -41,6 +45,7 @@ import { | |
TRAINING_PERCENT_MAX, | ||
} from '../../../../common/analytics'; | ||
import { indexPatterns } from '../../../../../../../../../../src/plugins/data/public'; | ||
import { isAdvancedConfig } from '../../components/action_clone/clone_button'; | ||
|
||
const mmlAllowedUnitsStr = `${ALLOWED_DATA_UNITS.slice(0, ALLOWED_DATA_UNITS.length - 1).join( | ||
', ' | ||
|
@@ -458,13 +463,16 @@ export function reducer(state: State, action: Action): State { | |
|
||
case ACTION.SET_ADVANCED_EDITOR_RAW_STRING: | ||
let resultJobConfig; | ||
let disableSwitchToForm = false; | ||
try { | ||
resultJobConfig = JSON.parse(collapseLiteralStrings(action.advancedEditorRawString)); | ||
disableSwitchToForm = isAdvancedConfig(resultJobConfig); | ||
} catch (e) { | ||
return { | ||
...state, | ||
advancedEditorRawString: action.advancedEditorRawString, | ||
isAdvancedEditorValidJson: false, | ||
disableSwitchToForm: true, | ||
advancedEditorMessages: [], | ||
}; | ||
} | ||
|
@@ -473,6 +481,7 @@ export function reducer(state: State, action: Action): State { | |
...validateAdvancedEditor({ ...state, jobConfig: resultJobConfig }), | ||
advancedEditorRawString: action.advancedEditorRawString, | ||
isAdvancedEditorValidJson: true, | ||
disableSwitchToForm, | ||
}; | ||
|
||
case ACTION.SET_FORM_STATE: | ||
|
@@ -538,17 +547,53 @@ export function reducer(state: State, action: Action): State { | |
|
||
case ACTION.SWITCH_TO_ADVANCED_EDITOR: | ||
let { jobConfig } = state; | ||
const isJobConfigEmpty = isEmpty(state.jobConfig); | ||
if (isJobConfigEmpty) { | ||
jobConfig = getJobConfigFromFormState(state.form); | ||
} | ||
jobConfig = getJobConfigFromFormState(state.form); | ||
const shouldDisableSwitchToForm = isAdvancedConfig(jobConfig); | ||
|
||
return validateAdvancedEditor({ | ||
...state, | ||
advancedEditorRawString: JSON.stringify(jobConfig, null, 2), | ||
isAdvancedEditorEnabled: true, | ||
disableSwitchToForm: shouldDisableSwitchToForm, | ||
hasSwitchedToEditor: true, | ||
jobConfig, | ||
}); | ||
|
||
case ACTION.SWITCH_TO_FORM: | ||
const { jobConfig: config, jobIds } = state; | ||
const { jobId } = state.form; | ||
// @ts-ignore | ||
const formState = getFormStateFromJobConfig(config, false); | ||
|
||
if (typeof jobId === 'string' && jobId.trim() !== '') { | ||
formState.jobId = jobId; | ||
} | ||
|
||
formState.jobIdExists = jobIds.some((id) => formState.jobId === id); | ||
formState.jobIdEmpty = jobId === ''; | ||
formState.jobIdValid = isJobIdValid(jobId); | ||
formState.jobIdInvalidMaxLength = !!maxLengthValidator(JOB_ID_MAX_LENGTH)(jobId); | ||
|
||
formState.destinationIndexNameEmpty = formState.destinationIndex === ''; | ||
formState.destinationIndexNameValid = isValidIndexName(formState.destinationIndex || ''); | ||
formState.destinationIndexPatternTitleExists = | ||
state.indexPatternsMap[formState.destinationIndex || ''] !== undefined; | ||
|
||
if (formState.numTopFeatureImportanceValues !== undefined) { | ||
formState.numTopFeatureImportanceValuesValid = validateNumTopFeatureImportanceValues( | ||
formState.numTopFeatureImportanceValues | ||
); | ||
} | ||
|
||
return validateForm({ | ||
...state, | ||
// @ts-ignore | ||
form: formState, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain and add a comment why the ignore is necessary? Do you plan to solve it in a follow up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
isAdvancedEditorEnabled: false, | ||
advancedEditorRawString: JSON.stringify(config, null, 2), | ||
jobConfig: config, | ||
}); | ||
|
||
case ACTION.SET_ESTIMATED_MODEL_MEMORY_LIMIT: | ||
return { | ||
...state, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain and add a comment why the ignore is necessary? Do you plan to solve it in a follow up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ignore is necessary because of the differences in
CloneDataFrameAnalyticsConfig
vsDataFrameAnalyticsConfig
- particularly the allowance of some of those values being undefined when just switching back from the JSON editor (as when it's a cloned job, all the values must be defined). I plan to solve it in a follow-up.