[Form lib] Allow new "defaultValue" to be provided when resetting the…#75302
Merged
sebelga merged 5 commits intoelastic:masterfrom Aug 19, 2020
Merged
Conversation
Contributor
|
Pinging @elastic/es-ui (Team:Elasticsearch UI) |
jloleysens
approved these changes
Aug 19, 2020
Contributor
There was a problem hiding this comment.
This is really cool @sebelga . I think this gives consumers precise control of form values given any external or internal form change.
I tested with the following ingest node pipeline form changes:
patch
diff --git i/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/common_fields/processor_type_field.tsx w/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/common_fields/processor_type_field.tsx
index e4ad90f61af..133950896cc 100644
--- i/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/common_fields/processor_type_field.tsx
+++ w/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/common_fields/processor_type_field.tsx
@@ -14,6 +14,7 @@ import {
FieldConfig,
UseField,
fieldValidators,
+ useFormContext,
} from '../../../../../../../shared_imports';
import { getProcessorDescriptor, mapProcessorTypeToDescriptor } from '../../../shared';
@@ -64,6 +65,7 @@ const typeConfig: FieldConfig<any, string> = {
};
export const ProcessorTypeField: FunctionComponent<Props> = ({ initialType }) => {
+ const form = useFormContext();
return (
<UseField<string> config={typeConfig} defaultValue={initialType} path="type">
{(typeField) => {
@@ -123,7 +125,10 @@ export const ProcessorTypeField: FunctionComponent<Props> = ({ initialType }) =>
onCreateOption={onCreateComboOption}
onChange={(options: Array<EuiComboBoxOptionOption<string>>) => {
const [selection] = options;
- typeField.setValue(selection?.value! ?? '');
+ const type = selection?.value! ?? '';
+ console.log('resetting form default value to', { type });
+ typeField.setValue(type);
+ form.reset({ defaultValue: { type } });
}}
noSuggestions={false}
singleSelection={{And was able to to get the desired behaviour of resetting the default values on type changes.
Contributor
Author
|
Thanks for the review @jloleysens ! I had to fix a few test (great that they caught the regression on the mappings editor! 😊 I haven't tested but I don't think you need to set the value if you reset right after, as resetting sets the value on the field. typeField.setValue(type); // You might not need to do that
form.reset({ defaultValue: { type } }); |
Contributor
💚 Build SucceededBuild metricsasync chunks size
page load bundle size
History
To update your PR or re-run it, just comment with: |
gmmorris
added a commit
to gmmorris/kibana
that referenced
this pull request
Aug 19, 2020
* master: (30 commits) [code coverage] always download node before team assignment (elastic#75424) [Form lib] Allow new "defaultValue" to be provided when resetting the… (elastic#75302) [Logs UI] Add "View in machine learning" links in the anomaly explorer (elastic#74555) skip flaky suite (elastic#75440) skip flaky suite (elastic#75386) [Saved objects] Add support for version on create & bulkCreate when overwriting a document (elastic#75172) [Functional]Table Vis increase sleep time in order filter to be applied (elastic#75138) MOAR RAM (elastic#75423) [Visualize] Horizontal Bar Percentiles Overlapping (elastic#75315) [ML] DF Analytics / Transforms: Fix job row actions menu invalid DOM nesting warning (elastic#74499) [ML] Inference models management (elastic#74978) [Monitoring] Migrate karma tests (elastic#75301) [Index template] Add filters to simulate preview (elastic#74497) Bump and consolidate dependencies (elastic#75360) [Ingest Manager] Fix agent config rollout rate limit to use constants (elastic#75364) Update Node.js to version 10.22.0 (elastic#75254) [ML] Anomaly Explorer / Single Metric Viewer: Fix error reporting for annotations. (elastic#74953) [Discover] Fix histogram cloud tests (elastic#75268) Uiactions to navigate to visualize or maps (elastic#74121) Use prefix search invis editor field/agg combo box (elastic#75290) ...
sebelga
added a commit
that referenced
this pull request
Aug 19, 2020
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds a new
defaultValueoption that can be passed to theform.reset()handler.This should also help in fixing the first part of this comment #72849 (comment)
@alisonelizabeth @jloleysens
Fixes #74950