Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Add error if filter index pattern is missing (#66979) #68050

Merged
merged 1 commit into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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