mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 11:05:39 -04:00
Fix warning text doesn't get displayed on filters with custom filter name (#78617)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
2904fe01b5
commit
1eb229be2e
6 changed files with 177 additions and 71 deletions
|
@ -1,18 +0,0 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`alias 1`] = `
|
|
||||||
<Fragment>
|
|
||||||
geo.coordinates in US
|
|
||||||
</Fragment>
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`negated alias 1`] = `
|
|
||||||
<Fragment>
|
|
||||||
<EuiTextColor
|
|
||||||
color="danger"
|
|
||||||
>
|
|
||||||
NOT
|
|
||||||
</EuiTextColor>
|
|
||||||
geo.coordinates in US
|
|
||||||
</Fragment>
|
|
||||||
`;
|
|
|
@ -1,48 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
|
||||||
* license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright
|
|
||||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
|
||||||
* the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
* not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import React from 'react';
|
|
||||||
import { FilterLabel } from './filter_label';
|
|
||||||
import { shallow } from 'enzyme';
|
|
||||||
import { phraseFilter } from '../../../../stubs';
|
|
||||||
|
|
||||||
test('alias', () => {
|
|
||||||
const filter = {
|
|
||||||
...phraseFilter,
|
|
||||||
meta: {
|
|
||||||
...phraseFilter.meta,
|
|
||||||
alias: 'geo.coordinates in US',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const component = shallow(<FilterLabel filter={filter} />);
|
|
||||||
expect(component).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('negated alias', () => {
|
|
||||||
const filter = {
|
|
||||||
...phraseFilter,
|
|
||||||
meta: {
|
|
||||||
...phraseFilter.meta,
|
|
||||||
alias: 'geo.coordinates in US',
|
|
||||||
negate: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const component = shallow(<FilterLabel filter={filter} />);
|
|
||||||
expect(component).toMatchSnapshot();
|
|
||||||
});
|
|
|
@ -0,0 +1,156 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import { FilterLabel } from './filter_label';
|
||||||
|
import { render, cleanup } from '@testing-library/react/pure';
|
||||||
|
import { phraseFilter } from '../../../../stubs';
|
||||||
|
|
||||||
|
afterEach(cleanup);
|
||||||
|
|
||||||
|
test('alias', () => {
|
||||||
|
const filter = {
|
||||||
|
...phraseFilter,
|
||||||
|
meta: {
|
||||||
|
...phraseFilter.meta,
|
||||||
|
alias: 'geo.coordinates in US',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const { container } = render(<FilterLabel filter={filter} />);
|
||||||
|
expect(container).toMatchInlineSnapshot(`
|
||||||
|
<div>
|
||||||
|
|
||||||
|
geo.coordinates in US
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('negated alias', () => {
|
||||||
|
const filter = {
|
||||||
|
...phraseFilter,
|
||||||
|
meta: {
|
||||||
|
...phraseFilter.meta,
|
||||||
|
alias: 'geo.coordinates in US',
|
||||||
|
negate: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const { container } = render(<FilterLabel filter={filter} />);
|
||||||
|
expect(container).toMatchInlineSnapshot(`
|
||||||
|
<div>
|
||||||
|
<span
|
||||||
|
class="euiTextColor euiTextColor--danger"
|
||||||
|
>
|
||||||
|
NOT
|
||||||
|
</span>
|
||||||
|
geo.coordinates in US
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('alias with warning status', () => {
|
||||||
|
const filter = {
|
||||||
|
...phraseFilter,
|
||||||
|
meta: {
|
||||||
|
...phraseFilter.meta,
|
||||||
|
alias: 'geo.coordinates in US',
|
||||||
|
negate: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const { container } = render(
|
||||||
|
<FilterLabel filter={filter} valueLabel={'Warning'} filterLabelStatus={'warn'} />
|
||||||
|
);
|
||||||
|
expect(container).toMatchInlineSnapshot(`
|
||||||
|
<div>
|
||||||
|
<span
|
||||||
|
class="euiTextColor euiTextColor--danger"
|
||||||
|
>
|
||||||
|
NOT
|
||||||
|
</span>
|
||||||
|
geo.coordinates in US
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="globalFilterLabel__value"
|
||||||
|
>
|
||||||
|
Warning
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('alias with error status', () => {
|
||||||
|
const filter = {
|
||||||
|
...phraseFilter,
|
||||||
|
meta: {
|
||||||
|
...phraseFilter.meta,
|
||||||
|
alias: 'geo.coordinates in US',
|
||||||
|
negate: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const { container } = render(
|
||||||
|
<FilterLabel filter={filter} valueLabel={'Error'} filterLabelStatus={'error'} />
|
||||||
|
);
|
||||||
|
expect(container).toMatchInlineSnapshot(`
|
||||||
|
<div>
|
||||||
|
<span
|
||||||
|
class="euiTextColor euiTextColor--danger"
|
||||||
|
>
|
||||||
|
NOT
|
||||||
|
</span>
|
||||||
|
geo.coordinates in US
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="globalFilterLabel__value"
|
||||||
|
>
|
||||||
|
Error
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('warning', () => {
|
||||||
|
const { container } = render(<FilterLabel filter={phraseFilter} valueLabel={'Warning'} />);
|
||||||
|
expect(container).toMatchInlineSnapshot(`
|
||||||
|
<div>
|
||||||
|
|
||||||
|
machine.os
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="globalFilterLabel__value"
|
||||||
|
>
|
||||||
|
Warning
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('error', () => {
|
||||||
|
const { container } = render(<FilterLabel filter={phraseFilter} valueLabel={'Error'} />);
|
||||||
|
expect(container).toMatchInlineSnapshot(`
|
||||||
|
<div>
|
||||||
|
|
||||||
|
machine.os
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="globalFilterLabel__value"
|
||||||
|
>
|
||||||
|
Error
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
});
|
|
@ -22,13 +22,15 @@ import { EuiTextColor } from '@elastic/eui';
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
import { existsOperator, isOneOfOperator } from './filter_operators';
|
import { existsOperator, isOneOfOperator } from './filter_operators';
|
||||||
import { Filter, FILTERS } from '../../../../../common';
|
import { Filter, FILTERS } from '../../../../../common';
|
||||||
|
import type { FilterLabelStatus } from '../../filter_item';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
filter: Filter;
|
filter: Filter;
|
||||||
valueLabel?: string;
|
valueLabel?: string;
|
||||||
|
filterLabelStatus?: FilterLabelStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function FilterLabel({ filter, valueLabel }: Props) {
|
export function FilterLabel({ filter, valueLabel, filterLabelStatus }: Props) {
|
||||||
const prefixText = filter.meta.negate
|
const prefixText = filter.meta.negate
|
||||||
? ` ${i18n.translate('data.filter.filterBar.negatedFilterPrefix', {
|
? ` ${i18n.translate('data.filter.filterBar.negatedFilterPrefix', {
|
||||||
defaultMessage: 'NOT ',
|
defaultMessage: 'NOT ',
|
||||||
|
@ -50,6 +52,7 @@ export function FilterLabel({ filter, valueLabel }: Props) {
|
||||||
<Fragment>
|
<Fragment>
|
||||||
{prefix}
|
{prefix}
|
||||||
{filter.meta.alias}
|
{filter.meta.alias}
|
||||||
|
{filterLabelStatus && <>: {getValue(valueLabel)}</>}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ interface Props {
|
||||||
|
|
||||||
interface LabelOptions {
|
interface LabelOptions {
|
||||||
title: string;
|
title: string;
|
||||||
status: string;
|
status: FilterLabelStatus;
|
||||||
message?: string;
|
message?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,11 @@ const FILTER_ITEM_OK = '';
|
||||||
const FILTER_ITEM_WARNING = 'warn';
|
const FILTER_ITEM_WARNING = 'warn';
|
||||||
const FILTER_ITEM_ERROR = 'error';
|
const FILTER_ITEM_ERROR = 'error';
|
||||||
|
|
||||||
|
export type FilterLabelStatus =
|
||||||
|
| typeof FILTER_ITEM_OK
|
||||||
|
| typeof FILTER_ITEM_WARNING
|
||||||
|
| typeof FILTER_ITEM_ERROR;
|
||||||
|
|
||||||
export function FilterItem(props: Props) {
|
export function FilterItem(props: Props) {
|
||||||
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false);
|
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false);
|
||||||
const [indexPatternExists, setIndexPatternExists] = useState<boolean | undefined>(undefined);
|
const [indexPatternExists, setIndexPatternExists] = useState<boolean | undefined>(undefined);
|
||||||
|
@ -260,7 +265,7 @@ export function FilterItem(props: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getValueLabel(): LabelOptions {
|
function getValueLabel(): LabelOptions {
|
||||||
const label = {
|
const label: LabelOptions = {
|
||||||
title: '',
|
title: '',
|
||||||
message: '',
|
message: '',
|
||||||
status: FILTER_ITEM_OK,
|
status: FILTER_ITEM_OK,
|
||||||
|
@ -326,6 +331,7 @@ export function FilterItem(props: Props) {
|
||||||
<FilterView
|
<FilterView
|
||||||
filter={filter}
|
filter={filter}
|
||||||
valueLabel={valueLabelConfig.title}
|
valueLabel={valueLabelConfig.title}
|
||||||
|
filterLabelStatus={valueLabelConfig.status}
|
||||||
errorMessage={valueLabelConfig.message}
|
errorMessage={valueLabelConfig.message}
|
||||||
className={getClasses(filter.meta.negate, valueLabelConfig)}
|
className={getClasses(filter.meta.negate, valueLabelConfig)}
|
||||||
iconOnClick={() => props.onRemove()}
|
iconOnClick={() => props.onRemove()}
|
||||||
|
|
|
@ -22,10 +22,12 @@ import { i18n } from '@kbn/i18n';
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import { FilterLabel } from '../filter_editor/lib/filter_label';
|
import { FilterLabel } from '../filter_editor/lib/filter_label';
|
||||||
import { Filter, isFilterPinned } from '../../../../common';
|
import { Filter, isFilterPinned } from '../../../../common';
|
||||||
|
import type { FilterLabelStatus } from '../filter_item';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
filter: Filter;
|
filter: Filter;
|
||||||
valueLabel: string;
|
valueLabel: string;
|
||||||
|
filterLabelStatus: FilterLabelStatus;
|
||||||
errorMessage?: string;
|
errorMessage?: string;
|
||||||
[propName: string]: any;
|
[propName: string]: any;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +38,7 @@ export const FilterView: FC<Props> = ({
|
||||||
onClick,
|
onClick,
|
||||||
valueLabel,
|
valueLabel,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
|
filterLabelStatus,
|
||||||
...rest
|
...rest
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const [ref, innerText] = useInnerText();
|
const [ref, innerText] = useInnerText();
|
||||||
|
@ -65,7 +68,7 @@ export const FilterView: FC<Props> = ({
|
||||||
iconType="cross"
|
iconType="cross"
|
||||||
iconSide="right"
|
iconSide="right"
|
||||||
closeButtonProps={{
|
closeButtonProps={{
|
||||||
// Removing tab focus on close button because the same option can be optained through the context menu
|
// Removing tab focus on close button because the same option can be obtained through the context menu
|
||||||
// Also, we may want to add a `DEL` keyboard press functionality
|
// Also, we may want to add a `DEL` keyboard press functionality
|
||||||
tabIndex: -1,
|
tabIndex: -1,
|
||||||
}}
|
}}
|
||||||
|
@ -80,7 +83,11 @@ export const FilterView: FC<Props> = ({
|
||||||
{...rest}
|
{...rest}
|
||||||
>
|
>
|
||||||
<span ref={ref}>
|
<span ref={ref}>
|
||||||
<FilterLabel filter={filter} valueLabel={valueLabel} />
|
<FilterLabel
|
||||||
|
filter={filter}
|
||||||
|
valueLabel={valueLabel}
|
||||||
|
filterLabelStatus={filterLabelStatus}
|
||||||
|
/>
|
||||||
</span>
|
</span>
|
||||||
</EuiBadge>
|
</EuiBadge>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue