-
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] DFA: ensure at least one field is included in analysis before job can be created #65320
[ML] DFA: ensure at least one field is included in analysis before job can be created #65320
Conversation
Pinging @elastic/ml-ui (:ml) |
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.
Code LGTM
@@ -48,6 +48,8 @@ import { | |||
} from '../../../../common/analytics'; | |||
import { shouldAddAsDepVarOption, OMIT_FIELDS } from './form_options_validation'; | |||
|
|||
const requiredFieldsErrorText = 'At least one field must be included in the analysis.'; |
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.
This needs to be internationalized.
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.
Updated in 592d87510e6ab0e58d2e72e2c1dbe30cf093bf50
@@ -565,7 +587,9 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta | |||
<Fragment> | |||
<EuiFormRow | |||
fullWidth | |||
isInvalid={maxDistinctValuesError !== undefined} | |||
isInvalid={ |
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.
I wonder if it might make more sense to show the invalid field warning below the 'Excluded fields' control, as it's most likely to appear when the user selects too many fields to exclude?
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.
🤔 Good point, @peteharverson. Updated in 592d87510e6ab0e58d2e72e2c1dbe30cf093bf50
const fieldSelection: FieldSelectionItem[] = resp.field_selection; | ||
|
||
let hasRequiredFields = false; | ||
if (fieldSelection) { |
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.
Is this if
part necessary? Asking because the assignment looks like it will always be an array. Maybe this whole part can even become something like:
const hasRequiredFields = resp.field_selection.some(field => field.is_included === true && field.is_required === false);
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.
Wrapping in an if
statement is mostly an extra safety precaution for something going wrong silently in the backend or changes to it that would make field_selection
undefined
. Looking at the docs, there doesn't seem to be a guarantee that that field will always be populated. The for loop prevents us from having to create a function on every go through. Though in this case the optimization is probably not significant. 🤔
I think for now I'd lean toward keeping it though I'm happy to update if you feel strongly (the readability is a bit better with your suggestion)
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.
Thanks for clarifying! Maybe we can then update the response type DfAnalyticsExplainResponse
to something like field_selection?: FieldSelectionItem[];
so TypeScript will force us to consider that the field could be not returned?
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.
Type updated in 4477264
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.
Tested latest edits and LGTM
55c471a
to
d4a4b2d
Compare
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.
LGTM pending the discussed TS update
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
…b can be created (elastic#65320) * ensure at least one field besides depVar included in analysis * show requiredFieldsError above excluded fields * update jest test * update fieldSelection explainResponse type
…b can be created (elastic#65320) * ensure at least one field besides depVar included in analysis * show requiredFieldsError above excluded fields * update jest test * update fieldSelection explainResponse type
…or-part-mvp-2 * 'master' of github.com:elastic/kibana: (259 commits) SavedObjects bulkCreate API should return migrationVersion and strip the type & namespace from the id (elastic#65150) Drilldown count tooltip (elastic#65105) plugins logs start with "plugins." prefix (elastic#65710) [ML] Fix pagination reset on search query update. (elastic#65668) [SIEM] Add types to the mappings objects so extra keys cannot be introduced [apm] Update machine learning flyout and service maps docs (elastic#65517) change api endpoint and throw error (elastic#65790) [Maps] remove SLA percentage metric (elastic#65718) [Reporting] APM integration for baseline performance measurements (elastic#59967) fix(NA): noParse regex for windows on kbn optimizer (elastic#65755) [ML] DFA: ensure at least one field is included in analysis before job can be created (elastic#65320) [Data plugin] cleanup - remove unused getRoutes / routes from indexPattern object (elastic#65683) Removed skip to enable test. (elastic#65575) [Lens] Type safe migrations (elastic#65576) [Canvas] Fix nav link behavior in Canvas (elastic#65590) [Event log] Fix flaky test (elastic#65658) [Alerting] changes preconfigured actions config from array to object (elastic#65397) remove immediate functions from esqueue worker cycles (elastic#65375) [Metrics UI] Fix isAbove to only display when threshold set (elastic#65540) draft search profiler accessibility tests (elastic#62357) ... # Conflicts: # x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx
Summary
Fixes #64783
Checks the
field_selection
return from the_explain
api to ensure that there is at least one other field included that is not also required.If there is not at least one field available for the analysis creation will be disabled and user will see an error message.
Checklist
Delete any items that are not applicable to this PR.