From 58f792cee3e7668ac9f24809a904a600c6c46762 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Thu, 9 Jan 2020 11:56:14 +0100 Subject: [PATCH] Remove eslint overwrite for src/legacy/core_plugins/kibana (#54222) * Cleanup code * Remove eslint overwrite --- .eslintrc.js | 7 ------- .../np_ready/components/doc/use_es_doc_search.ts | 2 +- .../field_chooser/discover_field_search.tsx | 11 ++++++----- .../field_chooser/discover_index_pattern.tsx | 14 +++++++------- ...e.ts => discover_index_pattern_directive.tsx} | 16 ++++++++++++++-- 5 files changed, 28 insertions(+), 22 deletions(-) rename src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/{discover_index_pattern_directive.ts => discover_index_pattern_directive.tsx} (65%) diff --git a/.eslintrc.js b/.eslintrc.js index c43366abf0c3..9719d1b35548 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 a40d9731a04f..d3bf3696c08a 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 d5f6b63d1219..2910ff2825fe 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 37338decce2c..a4e8ee2ca3d8 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 8bbeac086f09..d6527b0d7bee 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' }],