[TSVB] Weird state update on missing field (#115017)

* Remove condition for index string mode when we reset field

* Fix lint

* Fix types

* Update field_select.tsx

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Uladzislau Lasitsa 2021-10-19 20:40:22 +03:00 committed by GitHub
parent 9ee377979c
commit d5b214a340
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import { i18n } from '@kbn/i18n';
import React, { ReactNode, useContext } from 'react';
import React, { ReactNode } from 'react';
import {
EuiComboBox,
EuiComboBoxProps,
@ -20,8 +20,6 @@ import type { TimeseriesUIRestrictions } from '../../../../common/ui_restriction
// @ts-ignore
import { isFieldEnabled } from '../../lib/check_ui_restrictions';
import { PanelModelContext } from '../../contexts/panel_model_context';
import { USE_KIBANA_INDEXES_KEY } from '../../../../common/constants';
interface FieldSelectProps {
label: string | ReactNode;
@ -64,7 +62,6 @@ export function FieldSelect({
uiRestrictions,
'data-test-subj': dataTestSubj = 'metricsIndexPatternFieldsSelect',
}: FieldSelectProps) {
const panelModel = useContext(PanelModelContext);
const htmlId = htmlIdGenerator();
let selectedOptions: Array<EuiComboBoxOptionOption<string>> = [];
@ -119,18 +116,10 @@ export function FieldSelect({
}
});
let isInvalid;
const isInvalid = Boolean(value && fields[fieldsSelector] && !selectedOptions.length);
if (Boolean(panelModel?.[USE_KIBANA_INDEXES_KEY])) {
isInvalid = Boolean(value && fields[fieldsSelector] && !selectedOptions.length);
if (value && !selectedOptions.length) {
selectedOptions = [{ label: value!, id: 'INVALID_FIELD' }];
}
} else {
if (value && fields[fieldsSelector] && !selectedOptions.length) {
onChange([]);
}
if (value && !selectedOptions.length) {
selectedOptions = [{ label: value, id: 'INVALID_FIELD' }];
}
return (