-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Refactored `ESFieldSelect`. Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Yaroslav Kuznietsov <[email protected]>
- Loading branch information
1 parent
2339c8e
commit 10ea4ce
Showing
3 changed files
with
47 additions
and
51 deletions.
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
33 changes: 0 additions & 33 deletions
33
x-pack/plugins/canvas/public/components/es_field_select/index.js
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
x-pack/plugins/canvas/public/components/es_field_select/index.tsx
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useState, useEffect } from 'react'; | ||
import { getFields } from '../../lib/es_service'; | ||
import { ESFieldSelect as Component, ESFieldSelectProps as Props } from './es_field_select'; | ||
|
||
type ESFieldSelectProps = Omit<Props, 'fields'>; | ||
|
||
export const ESFieldSelect: React.FunctionComponent<ESFieldSelectProps> = (props) => { | ||
const { index, value, onChange } = props; | ||
const [fields, setFields] = useState<string[]>([]); | ||
|
||
useEffect(() => { | ||
getFields(index).then((newFields) => setFields(newFields || [])); | ||
}, [index]); | ||
|
||
useEffect(() => { | ||
if (value && !fields.includes(value)) { | ||
onChange(null); | ||
} | ||
}, [value, fields, onChange]); | ||
|
||
return <Component {...props} fields={fields} />; | ||
}; |