-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Form lib] Allow new "defaultValue" to be provided when resetting the… #75302
[Form lib] Allow new "defaultValue" to be provided when resetting the… #75302
Conversation
Pinging @elastic/es-ui (Team:Elasticsearch UI) |
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 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.
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 } }); |
💚 Build SucceededBuild metricsasync chunks size
page load bundle size
History
To update your PR or re-run it, just comment with: |
* 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) ...
This PR adds a new
defaultValue
option 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