Skip to content

Commit

Permalink
[Data][Filters] Move more filter utils to package and cleanup API (el…
Browse files Browse the repository at this point in the history
…astic#106566)

* Move more utils to package and cleanup API

* docs and imports

* better imports

* change comment

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
2 people authored and vadimkibana committed Aug 8, 2021
1 parent 51f420c commit e894c41
Show file tree
Hide file tree
Showing 65 changed files with 925 additions and 466 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

## esFilters variable

> Warning: This API is now obsolete.
>
> Please import helpers from the package kbn/es-query directly. This import will be deprecated in v8.0.0.
>
Filter helpers namespace:

<b>Signature:</b>

```typescript
Expand All @@ -16,15 +23,15 @@ esFilters: {
buildPhrasesFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: any[], indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhrasesFilter;
buildExistsFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").ExistsFilter;
buildPhraseFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, value: any, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhraseFilter;
buildQueryFilter: (query: any, index: string, alias: string) => import("@kbn/es-query").QueryStringFilter;
buildQueryFilter: (query: any, index: string, alias: string) => import("@kbn/es-query/target_types/filters/build_filters").QueryStringFilter;
buildRangeFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: import("@kbn/es-query").RangeFilterParams, indexPattern: import("@kbn/es-query").IndexPatternBase, formattedValue?: string | undefined) => import("@kbn/es-query").RangeFilter;
isPhraseFilter: (filter: any) => filter is import("@kbn/es-query").PhraseFilter;
isExistsFilter: (filter: any) => filter is import("@kbn/es-query").ExistsFilter;
isPhrasesFilter: (filter: any) => filter is import("@kbn/es-query").PhrasesFilter;
isRangeFilter: (filter: any) => filter is import("@kbn/es-query").RangeFilter;
isMatchAllFilter: (filter: any) => filter is import("@kbn/es-query").MatchAllFilter;
isMissingFilter: (filter: any) => filter is import("@kbn/es-query").MissingFilter;
isQueryStringFilter: (filter: any) => filter is import("@kbn/es-query").QueryStringFilter;
isQueryStringFilter: (filter: any) => filter is import("@kbn/es-query/target_types/filters/build_filters").QueryStringFilter;
isFilterPinned: (filter: import("@kbn/es-query").Filter) => boolean | undefined;
toggleFilterNegated: (filter: import("@kbn/es-query").Filter) => {
meta: {
Expand All @@ -39,21 +46,21 @@ esFilters: {
params?: any;
value?: string | undefined;
};
$state?: import("@kbn/es-query/target_types/filters/types").FilterState | undefined;
$state?: import("@kbn/es-query").FilterState | undefined;
query?: any;
};
disableFilter: (filter: import("@kbn/es-query").Filter) => import("@kbn/es-query").Filter;
getPhraseFilterField: (filter: import("@kbn/es-query").PhraseFilter) => string;
getPhraseFilterValue: (filter: import("@kbn/es-query").PhraseFilter) => string | number | boolean;
getDisplayValueFromFilter: typeof getDisplayValueFromFilter;
compareFilters: (first: import("@kbn/es-query").Filter | import("@kbn/es-query").Filter[], second: import("@kbn/es-query").Filter | import("@kbn/es-query").Filter[], comparatorOptions?: import("../common").FilterCompareOptions) => boolean;
COMPARE_ALL_OPTIONS: import("../common").FilterCompareOptions;
compareFilters: (first: import("@kbn/es-query").Filter | import("@kbn/es-query").Filter[], second: import("@kbn/es-query").Filter | import("@kbn/es-query").Filter[], comparatorOptions?: import("@kbn/es-query").FilterCompareOptions | undefined) => boolean;
COMPARE_ALL_OPTIONS: import("@kbn/es-query").FilterCompareOptions;
generateFilters: typeof generateFilters;
onlyDisabledFiltersChanged: (newFilters?: import("@kbn/es-query").Filter[] | undefined, oldFilters?: import("@kbn/es-query").Filter[] | undefined) => boolean;
changeTimeFilter: typeof changeTimeFilter;
convertRangeFilterToTimeRangeString: typeof convertRangeFilterToTimeRangeString;
changeTimeFilter: typeof oldChangeTimeFilter;
convertRangeFilterToTimeRangeString: typeof oldConvertRangeFilterToTimeRangeString;
mapAndFlattenFilters: (filters: import("@kbn/es-query").Filter[]) => import("@kbn/es-query").Filter[];
extractTimeFilter: typeof extractTimeFilter;
extractTimeFilter: typeof oldExtractTimeFilter;
extractTimeRange: typeof extractTimeRange;
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [extractTimeRange](./kibana-plugin-plugins-data-public.extracttimerange.md)

## extractTimeRange() function

<b>Signature:</b>

```typescript
export declare function extractTimeRange(filters: Filter[], timeFieldName?: string): {
restOfFilters: Filter[];
timeRange?: TimeRange;
};
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| filters | <code>Filter[]</code> | |
| timeFieldName | <code>string</code> | |

<b>Returns:</b>

`{
restOfFilters: Filter[];
timeRange?: TimeRange;
}`

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [FilterItem](./kibana-plugin-plugins-data-public.filteritem.md)

## FilterItem variable

<b>Signature:</b>

```typescript
FilterItem: (props: FilterItemProps) => JSX.Element
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [FilterLabel](./kibana-plugin-plugins-data-public.filterlabel.md)

## FilterLabel variable

<b>Signature:</b>

```typescript
FilterLabel: (props: FilterLabelProps) => JSX.Element
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [generateFilters](./kibana-plugin-plugins-data-public.generatefilters.md)

## generateFilters() function

Generate filter objects, as a result of triggering a filter action on a specific index pattern field.

<b>Signature:</b>

```typescript
export declare function generateFilters(filterManager: FilterManager, field: IFieldType | string, values: any, operation: string, index: string): Filter[];
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| filterManager | <code>FilterManager</code> | |
| field | <code>IFieldType &#124; string</code> | |
| values | <code>any</code> | |
| operation | <code>string</code> | |
| index | <code>string</code> | |

<b>Returns:</b>

`Filter[]`

{<!-- -->object<!-- -->} An array of filters to be added back to filterManager

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [getDisplayValueFromFilter](./kibana-plugin-plugins-data-public.getdisplayvaluefromfilter.md)

## getDisplayValueFromFilter() function

<b>Signature:</b>

```typescript
export declare function getDisplayValueFromFilter(filter: Filter, indexPatterns: IIndexPattern[]): string;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| filter | <code>Filter</code> | |
| indexPatterns | <code>IIndexPattern[]</code> | |

<b>Returns:</b>

`string`

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [getEsQueryConfig](./kibana-plugin-plugins-data-public.getesqueryconfig.md)

## getEsQueryConfig() function

<b>Signature:</b>

```typescript
export declare function getEsQueryConfig(config: KibanaConfig): EsQueryConfig;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| config | <code>KibanaConfig</code> | |

<b>Returns:</b>

`EsQueryConfig`

Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@

| Function | Description |
| --- | --- |
| [extractTimeRange(filters, timeFieldName)](./kibana-plugin-plugins-data-public.extracttimerange.md) | |
| [generateFilters(filterManager, field, values, operation, index)](./kibana-plugin-plugins-data-public.generatefilters.md) | Generate filter objects, as a result of triggering a filter action on a specific index pattern field. |
| [getDefaultQuery(language)](./kibana-plugin-plugins-data-public.getdefaultquery.md) | |
| [getDisplayValueFromFilter(filter, indexPatterns)](./kibana-plugin-plugins-data-public.getdisplayvaluefromfilter.md) | |
| [getEsPreference(uiSettings, sessionId)](./kibana-plugin-plugins-data-public.getespreference.md) | |
| [getEsQueryConfig(config)](./kibana-plugin-plugins-data-public.getesqueryconfig.md) | |
| [getSearchParamsFromRequest(searchRequest, dependencies)](./kibana-plugin-plugins-data-public.getsearchparamsfromrequest.md) | |
| [getTime(indexPattern, timeRange, options)](./kibana-plugin-plugins-data-public.gettime.md) | |
| [isEsError(e)](./kibana-plugin-plugins-data-public.iseserror.md) | Checks if a given errors originated from Elasticsearch. Those params are assigned to the attributes property of an error. |
Expand Down Expand Up @@ -107,13 +111,15 @@
| [connectToQueryState](./kibana-plugin-plugins-data-public.connecttoquerystate.md) | Helper to setup two-way syncing of global data and a state container |
| [createSavedQueryService](./kibana-plugin-plugins-data-public.createsavedqueryservice.md) | |
| [ES\_SEARCH\_STRATEGY](./kibana-plugin-plugins-data-public.es_search_strategy.md) | |
| [esFilters](./kibana-plugin-plugins-data-public.esfilters.md) | |
| [esFilters](./kibana-plugin-plugins-data-public.esfilters.md) | Filter helpers namespace: |
| [esKuery](./kibana-plugin-plugins-data-public.eskuery.md) | |
| [esQuery](./kibana-plugin-plugins-data-public.esquery.md) | |
| [exporters](./kibana-plugin-plugins-data-public.exporters.md) | |
| [extractSearchSourceReferences](./kibana-plugin-plugins-data-public.extractsearchsourcereferences.md) | |
| [fieldFormats](./kibana-plugin-plugins-data-public.fieldformats.md) | |
| [fieldList](./kibana-plugin-plugins-data-public.fieldlist.md) | |
| [FilterItem](./kibana-plugin-plugins-data-public.filteritem.md) | |
| [FilterLabel](./kibana-plugin-plugins-data-public.filterlabel.md) | |
| [getKbnTypeNames](./kibana-plugin-plugins-data-public.getkbntypenames.md) | Get the esTypes known by all kbnFieldTypes {<!-- -->Array<string>} |
| [INDEX\_PATTERN\_SAVED\_OBJECT\_TYPE](./kibana-plugin-plugins-data-public.index_pattern_saved_object_type.md) | \* |
| [indexPatterns](./kibana-plugin-plugins-data-public.indexpatterns.md) | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [buildQueryFromFilters](./kibana-plugin-plugins-data-server.buildqueryfromfilters.md)

## buildQueryFromFilters variable

> Warning: This API is now obsolete.
>
> Please import from the package kbn/es-query directly. This import will be deprecated in v8.0.0.
>
<b>Signature:</b>

```typescript
buildQueryFromFilters: (filters: oldFilter[] | undefined, indexPattern: import("@kbn/es-query").IndexPatternBase | undefined, ignoreFilterIfFieldNotInIndex?: boolean | undefined) => {
must: never[];
filter: oldFilter[];
should: never[];
must_not: oldFilter[];
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

```typescript
esFilters: {
buildQueryFilter: (query: any, index: string, alias: string) => import("@kbn/es-query").QueryStringFilter;
buildQueryFilter: (query: any, index: string, alias: string) => import("@kbn/es-query/target_types/filters/build_filters").QueryStringFilter;
buildCustomFilter: typeof import("@kbn/es-query").buildCustomFilter;
buildEmptyFilter: (isPinned: boolean, index?: string | undefined) => import("@kbn/es-query").Filter;
buildExistsFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").ExistsFilter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [getEsQueryConfig](./kibana-plugin-plugins-data-server.getesqueryconfig.md)

## getEsQueryConfig() function

<b>Signature:</b>

```typescript
export declare function getEsQueryConfig(config: KibanaConfig): EsQueryConfig;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| config | <code>KibanaConfig</code> | |

<b>Returns:</b>

`EsQueryConfig`

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
| --- | --- |
| [getCapabilitiesForRollupIndices(indices)](./kibana-plugin-plugins-data-server.getcapabilitiesforrollupindices.md) | |
| [getDefaultSearchParams(uiSettingsClient)](./kibana-plugin-plugins-data-server.getdefaultsearchparams.md) | |
| [getEsQueryConfig(config)](./kibana-plugin-plugins-data-server.getesqueryconfig.md) | |
| [getShardTimeout(config)](./kibana-plugin-plugins-data-server.getshardtimeout.md) | |
| [getTime(indexPattern, timeRange, options)](./kibana-plugin-plugins-data-server.gettime.md) | |
| [parseInterval(interval)](./kibana-plugin-plugins-data-server.parseinterval.md) | |
Expand Down Expand Up @@ -72,6 +73,7 @@
| --- | --- |
| [AggGroupLabels](./kibana-plugin-plugins-data-server.agggrouplabels.md) | |
| [AggGroupNames](./kibana-plugin-plugins-data-server.agggroupnames.md) | |
| [buildQueryFromFilters](./kibana-plugin-plugins-data-server.buildqueryfromfilters.md) | |
| [castEsToKbnFieldTypeName](./kibana-plugin-plugins-data-server.castestokbnfieldtypename.md) | Get the KbnFieldType name for an esType string |
| [config](./kibana-plugin-plugins-data-server.config.md) | |
| [ES\_SEARCH\_STRATEGY](./kibana-plugin-plugins-data-server.es_search_strategy.md) | |
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-query/src/es_query/filter_matches_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Filter } from '../filters';
import { IndexPatternBase } from './types';
import { IndexPatternBase } from '..';

/*
* TODO: We should base this on something better than `filter.meta.key`. We should probably modify
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { Filter, FilterMeta, FilterState, FilterStateStore } from './types';

export const buildEmptyFilter = (isPinned: boolean, index?: string): Filter => {
const meta: FilterMeta = {
disabled: false,
negate: false,
alias: null,
index,
};
const $state: FilterState = {
store: isPinned ? FilterStateStore.GLOBAL_STATE : FilterStateStore.APP_STATE,
};

return { meta, $state };
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

import { buildFilter, FilterStateStore, FILTERS } from '.';
import { IndexPatternBase } from '..';
import { fields as stubFields } from './stubs';
import { IndexPatternBase } from '../..';
import { fields as stubFields } from '../stubs';

describe('buildFilter', () => {
const stubIndexPattern: IndexPatternBase = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
* Side Public License, v 1.
*/

import {
Filter,
FILTERS,
buildPhraseFilter,
buildPhrasesFilter,
buildRangeFilter,
buildExistsFilter,
} from '.';
import { IndexPatternFieldBase, IndexPatternBase } from '..';
import { Filter, FILTERS } from './types';

import { buildPhraseFilter } from './phrase_filter';
import { buildPhrasesFilter } from './phrases_filter';
import { buildRangeFilter } from './range_filter';
import { buildExistsFilter } from './exists_filter';

import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query';
import { FilterMeta, FilterStateStore } from './types';

export function buildFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { Filter } from './types';
import type { Filter } from './types';

export type CustomFilter = Filter & {
query: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Side Public License, v 1.
*/

import { IndexPatternBase } from '..';
import { IndexPatternBase } from '../../es_query';
import { buildExistsFilter, getExistsFilterField } from './exists_filter';
import { fields } from './stubs/fields.mocks';
import { fields } from '../stubs/fields.mocks';

describe('exists filter', function () {
const indexPattern: IndexPatternBase = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Side Public License, v 1.
*/

import { IndexPatternFieldBase, IndexPatternBase } from '..';
import { Filter, FilterMeta } from './types';
import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query';
import type { Filter, FilterMeta } from './types';

export type ExistsFilterMeta = FilterMeta;

Expand Down
Loading

0 comments on commit e894c41

Please sign in to comment.