Skip to content

Commit

Permalink
Add error if filter index pattern is missing (#66979)
Browse files Browse the repository at this point in the history
* add error if filter index pattern is gone

* docs change - why?

* Fix i18n

* Added a functional test for broken filters (field + index pattern)

* Clarify readme

* Moved readme

* New warning status

* Remove getAll

* git pull upstream master

* Fix translation files

* Fix merge

* added filterbar texts

* disabled correction

* Disable check in maps test until #64861 is resolved

* Fix tests, warning state is not disabled.

* Adjust warning filter - ignore filters from "foreign" index pattern, that are still applicable

* Add an additional unrelaeted filter test

* Update src/plugins/data/public/ui/filter_bar/_global_filter_item.scss

Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>

* Update src/plugins/data/public/ui/filter_bar/_global_filter_item.scss

Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>

* Fixed test data

* Revert mapping

* Update data with missing test

* Update test to match data

* Code review

Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 3, 2020
1 parent 36c6cd9 commit fbcb74c
Show file tree
Hide file tree
Showing 15 changed files with 525 additions and 135 deletions.
4 changes: 2 additions & 2 deletions src/plugins/data/common/es_query/filters/get_display_value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Filter } from '../filters';

function getValueFormatter(indexPattern?: IIndexPattern, key?: string) {
if (!indexPattern || !key) return;

let format = get(indexPattern, ['fields', 'byName', key, 'format']);
if (!format && (indexPattern.fields as any).getByName) {
// TODO: Why is indexPatterns sometimes a map and sometimes an array?
Expand All @@ -43,9 +44,8 @@ function getValueFormatter(indexPattern?: IIndexPattern, key?: string) {
}

export function getDisplayValueFromFilter(filter: Filter, indexPatterns: IIndexPattern[]): string {
const indexPattern = getIndexPatternFromFilter(filter, indexPatterns);

if (typeof filter.meta.value === 'function') {
const indexPattern = getIndexPatternFromFilter(filter, indexPatterns);
const valueFormatter: any = getValueFormatter(indexPattern, filter.meta.key);
return filter.meta.value(valueFormatter);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,21 @@ describe('filter manager utilities', () => {

expect(compareFilters([f1], [f2], COMPARE_ALL_OPTIONS)).toBeFalsy();
});

test('should compare index with index true', () => {
const f1 = {
$state: { store: FilterStateStore.GLOBAL_STATE },
...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const f2 = {
$state: { store: FilterStateStore.GLOBAL_STATE },
...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};

f2.meta.index = 'wassup';
f2.meta.index = 'dog';

expect(compareFilters([f1], [f2], { index: true })).toBeFalsy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { defaults, isEqual, omit, map } from 'lodash';
import { FilterMeta, Filter } from '../../es_query';

export interface FilterCompareOptions {
index?: boolean;
disabled?: boolean;
negate?: boolean;
state?: boolean;
Expand All @@ -31,6 +32,7 @@ export interface FilterCompareOptions {
* Include disabled, negate and store when comparing filters
*/
export const COMPARE_ALL_OPTIONS: FilterCompareOptions = {
index: true,
disabled: true,
negate: true,
state: true,
Expand All @@ -44,6 +46,7 @@ const mapFilter = (
) => {
const cleaned: FilterMeta = omit(filter, excludedAttributes);

if (comparators.index) cleaned.index = filter.meta?.index;
if (comparators.negate) cleaned.negate = filter.meta && Boolean(filter.meta.negate);
if (comparators.disabled) cleaned.disabled = filter.meta && Boolean(filter.meta.disabled);
if (comparators.alias) cleaned.alias = filter.meta?.alias;
Expand Down Expand Up @@ -81,6 +84,7 @@ export const compareFilters = (
const excludedAttributes: string[] = ['$$hashKey', 'meta'];

comparators = defaults(comparatorOptions || {}, {
index: false,
state: false,
negate: false,
disabled: false,
Expand Down
15 changes: 13 additions & 2 deletions src/plugins/data/public/ui/filter_bar/_global_filter_item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,26 @@
font-style: italic;
}

.globalFilterItem-isInvalid {
.globalFilterItem-isError, .globalFilterItem-isWarning {
text-decoration: none;

.globalFilterLabel__value {
color: $euiColorDanger;
font-weight: $euiFontWeightBold;
}
}

.globalFilterItem-isError {
.globalFilterLabel__value {
color: makeHighContrastColor($euiColorDangerText, $euiColorLightShade);
}
}

.globalFilterItem-isWarning {
.globalFilterLabel__value {
color: makeHighContrastColor($euiColorWarningText, $euiColorLightShade);
}
}

.globalFilterItem-isPinned {
position: relative;

Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/ui/filter_bar/filter_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function FilterBarUI(props: Props) {
<EuiFlexItem key={i} grow={false} className="globalFilterBar__flexItem">
<FilterItem
id={`${i}`}
intl={props.intl}
filter={filter}
onUpdate={(newFilter) => onUpdate(i, newFilter)}
onRemove={() => onRemove(i)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,14 @@ class FilterEditorUI extends Component<Props, State> {
if (
this.props.indexPatterns.length <= 1 &&
this.props.indexPatterns.find(
(indexPattern) => indexPattern === this.state.selectedIndexPattern
(indexPattern) => indexPattern === this.getIndexPatternFromFilter()
)
) {
/**
* Don't render the index pattern selector if there's just one \ zero index patterns
* and if the index pattern the filter was LOADED with is in the indexPatterns list.
**/

return '';
}
const { selectedIndexPattern } = this.state;
Expand Down
Loading

0 comments on commit fbcb74c

Please sign in to comment.