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

[Form lib] Add validations prop to UseArray and expose "moveItem" handler #76949

Merged
merged 4 commits into from
Sep 9, 2020

Conversation

sebelga
Copy link
Contributor

@sebelga sebelga commented Sep 8, 2020

This PR enhances the <UseArray /> component and add a validations prop that can be provided to validate the array.

This enhancement is required for the ingest node pipelines "Grok" processor (#76533).

const patternsLengthValidations = [{
  validator: ({ value }) => {
    // The value are the "items" passed down in the children func
    if (value.length === 0) {
      return {
        message: 'You need to add at least one item',
      };
    }
  }
}];

export const MyComponent = () => {
  return (
    <UseArray path="patterns" validations={patternsLengthValidations}>
      {({ error, items, addItem, removeItem, form }) => {
        // error (string | null) is any validation message that came back
        // The form object is also returned so the consumer can decided _when_
        // to display the error (e.g. form.isSubmitted)
      }}
    </UseArray>
  );
};

This PR also includes a moveItem handler to reorder the array items. This was originally added by @jloleysens, I opted to not create a dependency on the @elastic/eui for the reordering.

export const MyComponent = () => {
  return (
    <UseArray path="patterns" validations={patternsLengthValidations}>
      {({ items, addItem, removeItem, moveItem }) => {
        // To reorder the item we will probably use the <EuiDragDropContext /> and <EuiDroppable />
        const onDragEnd = ({ source, destination }) => {
          if (source && destination) {
            moveItem(source.index, destination.index);
          }
        };
		
        return (
          <EuiDragDropContext onDragEnd={onDragEnd}>
            <EuiDroppable droppableId="1">
              {items.map(item => (
                ...
              ))}
            </EuiDroppable>
		  </EuiDragDropContext>
        );
      }}
    </UseArray>
  );
};

@sebelga sebelga requested a review from a team as a code owner September 8, 2020 14:32
@sebelga sebelga added enhancement New value added to drive a business result non-issue Indicates to automation that a pull request should not appear in the release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.10.0 v8.0.0 labels Sep 8, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)

@sebelga sebelga added the release_note:skip Skip the PR/issue when compiling release notes label Sep 8, 2020
@sebelga sebelga requested review from a team as code owners September 9, 2020 09:54
Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

Great work @sebelga ! We spoke offline and I am happy with these changes, also tested locally with the changes I have over here #76533.

Happy for this to be merged.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

page load bundle size

id value diff baseline
esUiShared 995.2KB +985.0B 994.2KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@sebelga sebelga merged commit 1ea58d9 into elastic:master Sep 9, 2020
@sebelga sebelga deleted the form-lib/use-array-validator branch September 9, 2020 12:40
sebelga added a commit that referenced this pull request Sep 9, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Sep 9, 2020
* master: (68 commits)
  a11y tests on spaces home page including feature control  (elastic#76515)
  [ML] Transforms list: persist pagination through refresh interval (elastic#76786)
  [ML] Replace all use of date_histogram interval with fixed_interval (elastic#76876)
  [Timelion] Update timelion deprecation links (elastic#77008)
  [Security Solution] Refactor Network Details to use Search Strategy (elastic#76928)
  Upgrade elastic charts to 21.1.2 (elastic#76939)
  [Alerting][Connectors] Refactor Jira: Generic Implementation (phase one) (elastic#73778)
  [Snapshot & Restore] fix pre existing policy with no existing repository (elastic#76861)
  Update saved object management UI text (elastic#76826)
  [Form lib] Add validations prop to UseArray and expose "moveItem" handler (elastic#76949)
  [Logs UI] Use fields api in log stream (elastic#76919)
  [UI Metrics] Support multi-colon keys (elastic#76913)
  [APM] Script for creating functional test archive (elastic#76926)
  [ENDPOINT] First version of the trusted apps list. (elastic#76304)
  Correct field for rum page url (elastic#76916)
  [Security Solution] Fix redirect properly old SIEM App routes (elastic#76868)
  Bump http-proxy from 1.17.0 to 1.18.1 (elastic#76924)
  [RUM Dashboard] Visitor breakdown usability (elastic#76834)
  [Search] Add a new advanced setting searchTimeout (elastic#75728)
  [DOCS] Adds timelion deprecation to new visualize docs structure (elastic#76959)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result non-issue Indicates to automation that a pull request should not appear in the release notes release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants