diff --git a/.eslintrc.js b/.eslintrc.js index c43366abf0c3d..9719d1b35548e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -82,13 +82,6 @@ module.exports = { 'react-hooks/exhaustive-deps': 'off', }, }, - { - files: ['src/legacy/core_plugins/kibana/**/*.{js,ts,tsx}'], - rules: { - 'react-hooks/rules-of-hooks': 'off', - 'react-hooks/exhaustive-deps': 'off', - }, - }, { files: ['src/legacy/core_plugins/tile_map/**/*.{js,ts,tsx}'], rules: { diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/use_es_doc_search.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/use_es_doc_search.ts index a40d9731a04f5..d3bf3696c08a5 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/use_es_doc_search.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/use_es_doc_search.ts @@ -91,7 +91,7 @@ export function useEsDocSearch({ useEffect(() => { requestData(); - }, []); + }); return [status, hit, indexPattern]; } diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field_search.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field_search.tsx index d5f6b63d12199..2910ff2825fe7 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field_search.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field_search.tsx @@ -67,11 +67,6 @@ export interface Props { * Additionally there's a button displayed that allows the user to show/hide more filter fields */ export function DiscoverFieldSearch({ onChange, value, types }: Props) { - if (typeof value !== 'string') { - // at initial rendering value is undefined (angular related), this catches the warning - // should be removed once all is react - return null; - } const searchPlaceholder = i18n.translate('kbn.discover.fieldChooser.searchPlaceHolder', { defaultMessage: 'Search field names', }); @@ -99,6 +94,12 @@ export function DiscoverFieldSearch({ onChange, value, types }: Props) { missing: true, }); + if (typeof value !== 'string') { + // at initial rendering value is undefined (angular related), this catches the warning + // should be removed once all is react + return null; + } + const filterBtnAriaLabel = isPopoverOpen ? i18n.translate('kbn.discover.fieldChooser.toggleFieldFilterButtonHideAriaLabel', { defaultMessage: 'Hide field filter settings', diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.tsx index 37338decce2c2..a4e8ee2ca3d8a 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.tsx @@ -45,19 +45,19 @@ export function DiscoverIndexPattern({ selectedIndexPattern, setIndexPattern, }: DiscoverIndexPatternProps) { - if (!indexPatternList || indexPatternList.length === 0 || !selectedIndexPattern) { - // just in case, shouldn't happen - return null; - } - const options: IndexPatternRef[] = indexPatternList.map(entity => ({ + const options: IndexPatternRef[] = (indexPatternList || []).map(entity => ({ id: entity.id, title: entity.attributes!.title, })); + const { id: selectedId, attributes } = selectedIndexPattern || {}; const [selected, setSelected] = useState({ - id: selectedIndexPattern.id, - title: selectedIndexPattern.attributes!.title, + id: selectedId, + title: attributes?.title || '', }); + if (!selectedId) { + return null; + } return (
diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern_directive.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern_directive.tsx similarity index 65% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern_directive.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern_directive.tsx index 8bbeac086f093..d6527b0d7beed 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern_directive.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern_directive.tsx @@ -16,11 +16,23 @@ * specific language governing permissions and limitations * under the License. */ +import React from 'react'; import { wrapInI18nContext } from '../../../kibana_services'; -import { DiscoverIndexPattern } from './discover_index_pattern'; +import { DiscoverIndexPattern, DiscoverIndexPatternProps } from './discover_index_pattern'; + +/** + * At initial rendering the angular directive the selectedIndexPattern prop is undefined + * This wrapper catches this, had to be introduced to satisfy eslint + */ +export function DiscoverIndexPatternWrapper(props: DiscoverIndexPatternProps) { + if (!props.selectedIndexPattern || !Array.isArray(props.indexPatternList)) { + return null; + } + return ; +} export function createIndexPatternSelectDirective(reactDirective: any) { - return reactDirective(wrapInI18nContext(DiscoverIndexPattern), [ + return reactDirective(wrapInI18nContext(DiscoverIndexPatternWrapper), [ ['indexPatternList', { watchDepth: 'reference' }], ['selectedIndexPattern', { watchDepth: 'reference' }], ['setIndexPattern', { watchDepth: 'reference' }],