Skip to content

Commit

Permalink
[TSVB] Weird state update on missing field (#115017) (#115615)
Browse files Browse the repository at this point in the history
* Remove condition for index string mode when we reset field

* Fix lint

* Fix types

* Update field_select.tsx

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
VladLasitsa and kibanamachine authored Oct 19, 2021
1 parent e6b8cd5 commit 3276fa2
Showing 1 changed file with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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>> = [];
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 3276fa2

Please sign in to comment.