Skip to content

Commit

Permalink
Migrate filter bar to React, EUI, and Typescript (elastic#25563)
Browse files Browse the repository at this point in the history
Rewrites the filter bar in React, EUI, and Typescript. Updates the look and feel of the filter bar and makes it consistent with the rest of K7.
  • Loading branch information
Bargs authored Jan 30, 2019
1 parent ee32e89 commit 410c094
Show file tree
Hide file tree
Showing 136 changed files with 4,131 additions and 3,428 deletions.
94 changes: 94 additions & 0 deletions packages/kbn-es-query/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# kbn-es-query

This module is responsible for generating Elasticsearch queries for Kibana. See explanations below for each of the subdirectories.

## es_query

This folder contains the code that combines Lucene/KQL queries and filters into an Elasticsearch query.

```javascript
buildEsQuery(indexPattern, queries, filters, config)
```

Generates the Elasticsearch query DSL from combining the queries and filters provided.

```javascript
buildQueryFromFilters(filters, indexPattern)
```

Generates the Elasticsearch query DSL from the given filters.

```javascript
luceneStringToDsl(query)
```

Generates the Elasticsearch query DSL from the given Lucene query.

```javascript
migrateFilter(filter, indexPattern)
```

Migrates a filter from a previous version of Elasticsearch to the current version.

```javascript
decorateQuery(query, queryStringOptions)
```

Decorates an Elasticsearch query_string query with the given options.

## filters

This folder contains the code related to Kibana Filter objects, including their definitions, and helper functions to create them. Filters in Kibana always contain a `meta` property which describes which `index` the filter corresponds to, as well as additional data about the specific filter.

The object that is created by each of the following functions corresponds to a Filter object in the `lib` directory (e.g. `PhraseFilter`, `RangeFilter`, etc.)

```javascript
buildExistsFilter(field, indexPattern)
```

Creates a filter (`ExistsFilter`) where the given field exists.

```javascript
buildPhraseFilter(field, value, indexPattern)
```

Creates an filter (`PhraseFilter`) where the given field matches the given value.

```javascript
buildPhrasesFilter(field, params, indexPattern)
```

Creates a filter (`PhrasesFilter`) where the given field matches one or more of the given values. `params` should be an array of values.

```javascript
buildQueryFilter(query, index)
```

Creates a filter (`CustomFilter`) corresponding to a raw Elasticsearch query DSL object.

```javascript
buildRangeFilter(field, params, indexPattern)
```

Creates a filter (`RangeFilter`) where the value for the given field is in the given range. `params` should contain `lt`, `lte`, `gt`, and/or `gte`.

## kuery

This folder contains the code corresponding to generating Elasticsearch queries using the Kibana query language.

It also contains code corresponding to the original implementation of Kuery (released in 6.0) which should be removed at some point (see legacy_kuery.js, legacy_kuery.peg).

In general, you will only need to worry about the following functions from the `ast` folder:

```javascript
fromExpression(expression)
```

Generates an abstract syntax tree corresponding to the raw Kibana query `expression`.

```javascript
toElasticsearchQuery(node, indexPattern)
```

Takes an abstract syntax tree (generated from the previous method) and generates the Elasticsearch query DSL using the given `indexPattern`. Note that if no `indexPattern` is provided, then an Elasticsearch query DSL will still be generated, ignoring things like the index pattern scripted fields, field types, etc.

5 changes: 3 additions & 2 deletions packages/kbn-es-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "babel src --out-dir target",
"build": "tsc && babel src --out-dir target",
"kbn:bootstrap": "yarn build --quiet",
"kbn:watch": "yarn build --watch"
},
},
"dependencies": {
"lodash": "npm:@elastic/[email protected]"
},
"devDependencies": {
"typescript": "^3.0.3",
"@kbn/babel-preset": "1.0.0",
"babel-cli": "^6.26.0",
"expect.js": "0.3.1"
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-es-query/src/filters/exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

// Creates a filter where the given field exists
export function buildExistsFilter(field, indexPattern) {
return {
meta: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,31 @@
* under the License.
*/

export function disableFilter(filter) {
return setFilterDisabled(filter, true);
}
import { Field, IndexPattern } from 'ui/index_patterns';
import { CustomFilter, ExistsFilter, PhraseFilter, PhrasesFilter, RangeFilter } from './lib';
import { RangeFilterParams } from './lib/range_filter';

export function enableFilter(filter) {
return setFilterDisabled(filter, false);
}
export * from './lib';

export function toggleFilterDisabled(filter) {
const { meta: { disabled = false } = {} } = filter;
export function buildExistsFilter(field: Field, indexPattern: IndexPattern): ExistsFilter;

return setFilterDisabled(filter, !disabled);
}
export function buildPhraseFilter(
field: Field,
value: string,
indexPattern: IndexPattern
): PhraseFilter;

function setFilterDisabled(filter, disabled) {
const { meta = {} } = filter;
export function buildPhrasesFilter(
field: Field,
values: string[],
indexPattern: IndexPattern
): PhrasesFilter;

return {
...filter,
meta: {
...meta,
disabled,
}
};
}
export function buildQueryFilter(query: any, index: string): CustomFilter;

export function buildRangeFilter(
field: Field,
params: RangeFilterParams,
indexPattern: IndexPattern,
formattedValue?: string
): RangeFilter;
1 change: 1 addition & 0 deletions packages/kbn-es-query/src/filters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './phrase';
export * from './phrases';
export * from './query';
export * from './range';
export * from './lib';
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
* under the License.
*/

import _ from 'lodash';

export function filterAppliedAndUnwrap(filters) {
return _.filter(filters, 'meta.apply');
}
import { Filter } from './meta_filter';

export type CustomFilter = Filter & {
query: any;
};
26 changes: 26 additions & 0 deletions packages/kbn-es-query/src/filters/lib/exists_filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 { Filter, FilterMeta } from './meta_filter';

export type ExistsFilterMeta = FilterMeta;

export type ExistsFilter = Filter & {
meta: ExistsFilterMeta;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@
* under the License.
*/

export { phraseFilter } from './phrase_filter';
export { scriptedPhraseFilter } from './scripted_phrase_filter';
export { phrasesFilter } from './phrases_filter';
export { rangeFilter } from './range_filter';
export { existsFilter } from './exists_filter';
import { Filter, FilterMeta, LatLon } from './meta_filter';

export type GeoBoundingBoxFilterMeta = FilterMeta & {
params: {
bottom_right: LatLon;
top_left: LatLon;
};
};

export type GeoBoundingBoxFilter = Filter & {
meta: GeoBoundingBoxFilterMeta;
};
30 changes: 30 additions & 0 deletions packages/kbn-es-query/src/filters/lib/geo_polygon_filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 { Filter, FilterMeta, LatLon } from './meta_filter';

export type GeoPolygonFilterMeta = FilterMeta & {
params: {
points: LatLon[];
};
};

export type GeoPolygonFilter = Filter & {
meta: GeoPolygonFilterMeta;
};
50 changes: 50 additions & 0 deletions packages/kbn-es-query/src/filters/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.
*/

// The interface the other filters extend
export * from './meta_filter';

// The actual filter types
import { CustomFilter } from './custom_filter';
import { ExistsFilter } from './exists_filter';
import { GeoBoundingBoxFilter } from './geo_bounding_box_filter';
import { GeoPolygonFilter } from './geo_polygon_filter';
import { PhraseFilter } from './phrase_filter';
import { PhrasesFilter } from './phrases_filter';
import { QueryStringFilter } from './query_string_filter';
import { RangeFilter } from './range_filter';
export {
CustomFilter,
ExistsFilter,
GeoBoundingBoxFilter,
GeoPolygonFilter,
PhraseFilter,
PhrasesFilter,
QueryStringFilter,
RangeFilter,
};

// Any filter associated with a field (used in the filter bar/editor)
export type FieldFilter =
| ExistsFilter
| GeoBoundingBoxFilter
| GeoPolygonFilter
| PhraseFilter
| PhrasesFilter
| RangeFilter;
Loading

0 comments on commit 410c094

Please sign in to comment.