Skip to content

Commit ab49f26

Browse files
Fix warning text doesn't get displayed on filters with custom filter name (#78617)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 56cb430 commit ab49f26

File tree

6 files changed

+177
-71
lines changed

6 files changed

+177
-71
lines changed

src/plugins/data/public/ui/filter_bar/filter_editor/lib/__snapshots__/filter_label.test.js.snap

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_label.test.js

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import React from 'react';
21+
import { FilterLabel } from './filter_label';
22+
import { render, cleanup } from '@testing-library/react/pure';
23+
import { phraseFilter } from '../../../../stubs';
24+
25+
afterEach(cleanup);
26+
27+
test('alias', () => {
28+
const filter = {
29+
...phraseFilter,
30+
meta: {
31+
...phraseFilter.meta,
32+
alias: 'geo.coordinates in US',
33+
},
34+
};
35+
const { container } = render(<FilterLabel filter={filter} />);
36+
expect(container).toMatchInlineSnapshot(`
37+
<div>
38+
39+
geo.coordinates in US
40+
</div>
41+
`);
42+
});
43+
44+
test('negated alias', () => {
45+
const filter = {
46+
...phraseFilter,
47+
meta: {
48+
...phraseFilter.meta,
49+
alias: 'geo.coordinates in US',
50+
negate: true,
51+
},
52+
};
53+
const { container } = render(<FilterLabel filter={filter} />);
54+
expect(container).toMatchInlineSnapshot(`
55+
<div>
56+
<span
57+
class="euiTextColor euiTextColor--danger"
58+
>
59+
NOT
60+
</span>
61+
geo.coordinates in US
62+
</div>
63+
`);
64+
});
65+
66+
test('alias with warning status', () => {
67+
const filter = {
68+
...phraseFilter,
69+
meta: {
70+
...phraseFilter.meta,
71+
alias: 'geo.coordinates in US',
72+
negate: true,
73+
},
74+
};
75+
const { container } = render(
76+
<FilterLabel filter={filter} valueLabel={'Warning'} filterLabelStatus={'warn'} />
77+
);
78+
expect(container).toMatchInlineSnapshot(`
79+
<div>
80+
<span
81+
class="euiTextColor euiTextColor--danger"
82+
>
83+
NOT
84+
</span>
85+
geo.coordinates in US
86+
:
87+
<span
88+
class="globalFilterLabel__value"
89+
>
90+
Warning
91+
</span>
92+
</div>
93+
`);
94+
});
95+
96+
test('alias with error status', () => {
97+
const filter = {
98+
...phraseFilter,
99+
meta: {
100+
...phraseFilter.meta,
101+
alias: 'geo.coordinates in US',
102+
negate: true,
103+
},
104+
};
105+
const { container } = render(
106+
<FilterLabel filter={filter} valueLabel={'Error'} filterLabelStatus={'error'} />
107+
);
108+
expect(container).toMatchInlineSnapshot(`
109+
<div>
110+
<span
111+
class="euiTextColor euiTextColor--danger"
112+
>
113+
NOT
114+
</span>
115+
geo.coordinates in US
116+
:
117+
<span
118+
class="globalFilterLabel__value"
119+
>
120+
Error
121+
</span>
122+
</div>
123+
`);
124+
});
125+
126+
test('warning', () => {
127+
const { container } = render(<FilterLabel filter={phraseFilter} valueLabel={'Warning'} />);
128+
expect(container).toMatchInlineSnapshot(`
129+
<div>
130+
131+
machine.os
132+
:
133+
<span
134+
class="globalFilterLabel__value"
135+
>
136+
Warning
137+
</span>
138+
</div>
139+
`);
140+
});
141+
142+
test('error', () => {
143+
const { container } = render(<FilterLabel filter={phraseFilter} valueLabel={'Error'} />);
144+
expect(container).toMatchInlineSnapshot(`
145+
<div>
146+
147+
machine.os
148+
:
149+
<span
150+
class="globalFilterLabel__value"
151+
>
152+
Error
153+
</span>
154+
</div>
155+
`);
156+
});

src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_label.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import { EuiTextColor } from '@elastic/eui';
2222
import { i18n } from '@kbn/i18n';
2323
import { existsOperator, isOneOfOperator } from './filter_operators';
2424
import { Filter, FILTERS } from '../../../../../common';
25+
import type { FilterLabelStatus } from '../../filter_item';
2526

2627
interface Props {
2728
filter: Filter;
2829
valueLabel?: string;
30+
filterLabelStatus?: FilterLabelStatus;
2931
}
3032

31-
export function FilterLabel({ filter, valueLabel }: Props) {
33+
export function FilterLabel({ filter, valueLabel, filterLabelStatus }: Props) {
3234
const prefixText = filter.meta.negate
3335
? ` ${i18n.translate('data.filter.filterBar.negatedFilterPrefix', {
3436
defaultMessage: 'NOT ',
@@ -50,6 +52,7 @@ export function FilterLabel({ filter, valueLabel }: Props) {
5052
<Fragment>
5153
{prefix}
5254
{filter.meta.alias}
55+
{filterLabelStatus && <>: {getValue(valueLabel)}</>}
5356
</Fragment>
5457
);
5558
}

src/plugins/data/public/ui/filter_bar/filter_item.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,19 @@ interface Props {
4949

5050
interface LabelOptions {
5151
title: string;
52-
status: string;
52+
status: FilterLabelStatus;
5353
message?: string;
5454
}
5555

5656
const FILTER_ITEM_OK = '';
5757
const FILTER_ITEM_WARNING = 'warn';
5858
const FILTER_ITEM_ERROR = 'error';
5959

60+
export type FilterLabelStatus =
61+
| typeof FILTER_ITEM_OK
62+
| typeof FILTER_ITEM_WARNING
63+
| typeof FILTER_ITEM_ERROR;
64+
6065
export function FilterItem(props: Props) {
6166
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false);
6267
const [indexPatternExists, setIndexPatternExists] = useState<boolean | undefined>(undefined);
@@ -260,7 +265,7 @@ export function FilterItem(props: Props) {
260265
}
261266

262267
function getValueLabel(): LabelOptions {
263-
const label = {
268+
const label: LabelOptions = {
264269
title: '',
265270
message: '',
266271
status: FILTER_ITEM_OK,
@@ -326,6 +331,7 @@ export function FilterItem(props: Props) {
326331
<FilterView
327332
filter={filter}
328333
valueLabel={valueLabelConfig.title}
334+
filterLabelStatus={valueLabelConfig.status}
329335
errorMessage={valueLabelConfig.message}
330336
className={getClasses(filter.meta.negate, valueLabelConfig)}
331337
iconOnClick={() => props.onRemove()}

src/plugins/data/public/ui/filter_bar/filter_view/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import { i18n } from '@kbn/i18n';
2222
import React, { FC } from 'react';
2323
import { FilterLabel } from '../filter_editor/lib/filter_label';
2424
import { Filter, isFilterPinned } from '../../../../common';
25+
import type { FilterLabelStatus } from '../filter_item';
2526

2627
interface Props {
2728
filter: Filter;
2829
valueLabel: string;
30+
filterLabelStatus: FilterLabelStatus;
2931
errorMessage?: string;
3032
[propName: string]: any;
3133
}
@@ -36,6 +38,7 @@ export const FilterView: FC<Props> = ({
3638
onClick,
3739
valueLabel,
3840
errorMessage,
41+
filterLabelStatus,
3942
...rest
4043
}: Props) => {
4144
const [ref, innerText] = useInnerText();
@@ -65,7 +68,7 @@ export const FilterView: FC<Props> = ({
6568
iconType="cross"
6669
iconSide="right"
6770
closeButtonProps={{
68-
// Removing tab focus on close button because the same option can be optained through the context menu
71+
// Removing tab focus on close button because the same option can be obtained through the context menu
6972
// Also, we may want to add a `DEL` keyboard press functionality
7073
tabIndex: -1,
7174
}}
@@ -80,7 +83,11 @@ export const FilterView: FC<Props> = ({
8083
{...rest}
8184
>
8285
<span ref={ref}>
83-
<FilterLabel filter={filter} valueLabel={valueLabel} />
86+
<FilterLabel
87+
filter={filter}
88+
valueLabel={valueLabel}
89+
filterLabelStatus={filterLabelStatus}
90+
/>
8491
</span>
8592
</EuiBadge>
8693
);

0 commit comments

Comments
 (0)