}
@@ -16,7 +16,7 @@ exports[`CallOuts should render normally 1`] = `
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.test.tsx b/src/plugins/advanced_settings/public/management_app/components/call_outs/call_outs.test.tsx
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.test.tsx
rename to src/plugins/advanced_settings/public/management_app/components/call_outs/call_outs.test.tsx
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.tsx b/src/plugins/advanced_settings/public/management_app/components/call_outs/call_outs.tsx
similarity index 93%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.tsx
rename to src/plugins/advanced_settings/public/management_app/components/call_outs/call_outs.tsx
index cbd2bcfeb5454..3c6b4a51ed540 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.tsx
+++ b/src/plugins/advanced_settings/public/management_app/components/call_outs/call_outs.tsx
@@ -28,7 +28,7 @@ export const CallOuts = () => {
}
@@ -37,7 +37,7 @@ export const CallOuts = () => {
>
@@ -137,7 +137,7 @@ exports[`Field for array setting should render as read only with help text if ov
>
@@ -196,7 +196,7 @@ exports[`Field for array setting should render custom setting icon if it is cust
content={
}
@@ -335,7 +335,7 @@ exports[`Field for array setting should render user value if there is user value
@@ -382,7 +382,7 @@ exports[`Field for array setting should render user value if there is user value
>
@@ -468,7 +468,7 @@ exports[`Field for boolean setting should render as read only if saving is disab
label={
}
@@ -512,7 +512,7 @@ exports[`Field for boolean setting should render as read only with help text if
@@ -555,7 +555,7 @@ exports[`Field for boolean setting should render as read only with help text if
>
@@ -572,7 +572,7 @@ exports[`Field for boolean setting should render as read only with help text if
label={
}
@@ -620,7 +620,7 @@ exports[`Field for boolean setting should render custom setting icon if it is cu
content={
}
@@ -655,7 +655,7 @@ exports[`Field for boolean setting should render custom setting icon if it is cu
label={
}
@@ -727,7 +727,7 @@ exports[`Field for boolean setting should render default value if there is no us
label={
}
@@ -771,7 +771,7 @@ exports[`Field for boolean setting should render user value if there is user val
@@ -818,7 +818,7 @@ exports[`Field for boolean setting should render user value if there is user val
>
@@ -838,7 +838,7 @@ exports[`Field for boolean setting should render user value if there is user val
label={
}
@@ -949,7 +949,7 @@ exports[`Field for image setting should render as read only with help text if ov
@@ -992,7 +992,7 @@ exports[`Field for image setting should render as read only with help text if ov
>
@@ -1048,7 +1048,7 @@ exports[`Field for image setting should render custom setting icon if it is cust
content={
}
@@ -1189,7 +1189,7 @@ exports[`Field for image setting should render user value if there is user value
@@ -1236,7 +1236,7 @@ exports[`Field for image setting should render user value if there is user value
>
@@ -1250,7 +1250,7 @@ exports[`Field for image setting should render user value if there is user value
>
@@ -1304,7 +1304,7 @@ exports[`Field for json setting should render as read only if saving is disabled
@@ -1538,7 +1538,7 @@ exports[`Field for json setting should render custom setting icon if it is custo
content={
}
@@ -1630,7 +1630,7 @@ exports[`Field for json setting should render default value if there is no user
@@ -1757,7 +1757,7 @@ exports[`Field for json setting should render user value if there is user value
@@ -1969,7 +1969,7 @@ exports[`Field for markdown setting should render as read only with help text if
@@ -2012,7 +2012,7 @@ exports[`Field for markdown setting should render as read only with help text if
>
@@ -2090,7 +2090,7 @@ exports[`Field for markdown setting should render custom setting icon if it is c
content={
}
@@ -2267,7 +2267,7 @@ exports[`Field for markdown setting should render user value if there is user va
@@ -2314,7 +2314,7 @@ exports[`Field for markdown setting should render user value if there is user va
>
@@ -2457,7 +2457,7 @@ exports[`Field for number setting should render as read only with help text if o
@@ -2500,7 +2500,7 @@ exports[`Field for number setting should render as read only with help text if o
>
@@ -2559,7 +2559,7 @@ exports[`Field for number setting should render custom setting icon if it is cus
content={
}
@@ -2698,7 +2698,7 @@ exports[`Field for number setting should render user value if there is user valu
@@ -2745,7 +2745,7 @@ exports[`Field for number setting should render user value if there is user valu
>
@@ -2885,7 +2885,7 @@ exports[`Field for select setting should render as read only with help text if o
@@ -2928,7 +2928,7 @@ exports[`Field for select setting should render as read only with help text if o
>
@@ -3003,7 +3003,7 @@ exports[`Field for select setting should render custom setting icon if it is cus
content={
}
@@ -3174,7 +3174,7 @@ exports[`Field for select setting should render user value if there is user valu
@@ -3221,7 +3221,7 @@ exports[`Field for select setting should render user value if there is user valu
>
@@ -3361,7 +3361,7 @@ exports[`Field for string setting should render as read only with help text if o
@@ -3404,7 +3404,7 @@ exports[`Field for string setting should render as read only with help text if o
>
@@ -3463,7 +3463,7 @@ exports[`Field for string setting should render custom setting icon if it is cus
content={
}
@@ -3602,7 +3602,7 @@ exports[`Field for string setting should render user value if there is user valu
@@ -3649,7 +3649,7 @@ exports[`Field for string setting should render user value if there is user valu
>
@@ -3773,7 +3773,7 @@ exports[`Field for stringWithValidation setting should render as read only with
@@ -3816,7 +3816,7 @@ exports[`Field for stringWithValidation setting should render as read only with
>
@@ -3875,7 +3875,7 @@ exports[`Field for stringWithValidation setting should render custom setting ico
content={
}
@@ -4014,7 +4014,7 @@ exports[`Field for stringWithValidation setting should render user value if ther
@@ -4061,7 +4061,7 @@ exports[`Field for stringWithValidation setting should render user value if ther
>
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.tsx b/src/plugins/advanced_settings/public/management_app/components/field/field.test.tsx
similarity index 88%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.tsx
rename to src/plugins/advanced_settings/public/management_app/components/field/field.test.tsx
index bd2ba8ac0ebcc..81df22ccf6e43 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.tsx
+++ b/src/plugins/advanced_settings/public/management_app/components/field/field.test.tsx
@@ -22,7 +22,8 @@ import { I18nProvider } from '@kbn/i18n/react';
import { shallowWithI18nProvider, mountWithI18nProvider } from 'test_utils/enzyme_helpers';
import { mount } from 'enzyme';
import { FieldSetting } from '../../types';
-import { UiSettingsType, StringValidation } from '../../../../../../../../../core/public';
+import { UiSettingsType, StringValidation } from '../../../../../../core/public';
+import { notificationServiceMock, docLinksServiceMock } from '../../../../../../core/public/mocks';
// @ts-ignore
import { findTestSubject } from '@elastic/eui/lib/test';
@@ -35,8 +36,6 @@ jest.mock('ui/notify', () => ({
},
}));
-import { toastNotifications } from 'ui/notify';
-
jest.mock('brace/theme/textmate', () => 'brace/theme/textmate');
jest.mock('brace/mode/markdown', () => 'brace/mode/markdown');
@@ -196,7 +195,14 @@ describe('Field', () => {
describe(`for ${type} setting`, () => {
it('should render default value if there is no user value set', async () => {
const component = shallowWithI18nProvider(
-
+
);
expect(component).toMatchSnapshot();
@@ -214,6 +220,8 @@ describe('Field', () => {
save={save}
clear={clear}
enableSaving={true}
+ toasts={notificationServiceMock.createStartContract().toasts}
+ dockLinks={docLinksServiceMock.createStartContract().links}
/>
);
@@ -222,7 +230,14 @@ describe('Field', () => {
it('should render as read only if saving is disabled', async () => {
const component = shallowWithI18nProvider(
-
+
);
expect(component).toMatchSnapshot();
@@ -239,6 +254,8 @@ describe('Field', () => {
save={save}
clear={clear}
enableSaving={true}
+ toasts={notificationServiceMock.createStartContract().toasts}
+ dockLinks={docLinksServiceMock.createStartContract().links}
/>
);
@@ -255,6 +272,8 @@ describe('Field', () => {
save={save}
clear={clear}
enableSaving={true}
+ toasts={notificationServiceMock.createStartContract().toasts}
+ dockLinks={docLinksServiceMock.createStartContract().links}
/>
);
@@ -273,6 +292,8 @@ describe('Field', () => {
save={save}
clear={clear}
enableSaving={true}
+ toasts={notificationServiceMock.createStartContract().toasts}
+ dockLinks={docLinksServiceMock.createStartContract().links}
/>
);
const select = findTestSubject(component, `advancedSetting-editField-${setting.name}`);
@@ -291,6 +312,8 @@ describe('Field', () => {
save={save}
clear={clear}
enableSaving={true}
+ toasts={notificationServiceMock.createStartContract().toasts}
+ dockLinks={docLinksServiceMock.createStartContract().links}
/>
);
const select = findTestSubject(component, `advancedSetting-editField-${setting.name}`);
@@ -303,7 +326,15 @@ describe('Field', () => {
const setup = () => {
const Wrapper = (props: Record) => (
-
+
);
const wrapper = mount();
@@ -489,15 +520,23 @@ describe('Field', () => {
...settings.string,
requiresPageReload: true,
};
+ const toasts = notificationServiceMock.createStartContract().toasts;
const wrapper = mountWithI18nProvider(
-
+
);
(wrapper.instance() as Field).onFieldChange({ target: { value: 'a new value' } });
const updated = wrapper.update();
findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate('click');
expect(save).toHaveBeenCalled();
await save();
- expect(toastNotifications.add).toHaveBeenCalledWith(
+ expect(toasts.add).toHaveBeenCalledWith(
expect.objectContaining({
title: expect.stringContaining('Please reload the page'),
})
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.tsx b/src/plugins/advanced_settings/public/management_app/components/field/field.tsx
similarity index 87%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.tsx
rename to src/plugins/advanced_settings/public/management_app/components/field/field.tsx
index 524160191d8f0..e11a257e78545 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.tsx
+++ b/src/plugins/advanced_settings/public/management_app/components/field/field.tsx
@@ -19,19 +19,19 @@
import React, { PureComponent, Fragment } from 'react';
import ReactDOM from 'react-dom';
-import { npStart } from 'ui/new_platform';
import 'brace/theme/textmate';
import 'brace/mode/markdown';
-import { toastNotifications } from 'ui/notify';
import {
EuiBadge,
EuiButton,
EuiButtonEmpty,
EuiCode,
EuiCodeBlock,
+ // @ts-ignore
EuiCodeEditor,
+ // @ts-ignore
EuiDescribedFormGroup,
EuiFieldNumber,
EuiFieldText,
@@ -59,13 +59,17 @@ import {
UiSettingsType,
ImageValidation,
StringValidationRegex,
-} from '../../../../../../../../../core/public';
+ DocLinksStart,
+ ToastsStart,
+} from '../../../../../../core/public';
interface FieldProps {
setting: FieldSetting;
save: (name: string, value: string) => Promise;
clear: (name: string) => Promise;
enableSaving: boolean;
+ dockLinks: DocLinksStart['links'];
+ toasts: ToastsStart;
}
interface FieldState {
@@ -175,7 +179,7 @@ export class Field extends PureComponent {
JSON.parse(newUnsavedValue);
} catch (e) {
isInvalid = true;
- error = i18n.translate('kbn.management.settings.field.codeEditorSyntaxErrorMessage', {
+ error = i18n.translate('advancedSettings.field.codeEditorSyntaxErrorMessage', {
defaultMessage: 'Invalid JSON syntax',
});
}
@@ -267,7 +271,7 @@ export class Field extends PureComponent {
this.setState({
isInvalid,
error: isInvalid
- ? i18n.translate('kbn.management.settings.field.imageTooLargeErrorMessage', {
+ ? i18n.translate('advancedSettings.field.imageTooLargeErrorMessage', {
defaultMessage: 'Image is too large, maximum size is {maxSizeDescription}',
values: {
maxSizeDescription: maxSize.description,
@@ -278,8 +282,8 @@ export class Field extends PureComponent {
unsavedValue: base64Image,
});
} catch (err) {
- toastNotifications.addDanger(
- i18n.translate('kbn.management.settings.field.imageChangeErrorMessage', {
+ this.props.toasts.addDanger(
+ i18n.translate('advancedSettings.field.imageChangeErrorMessage', {
defaultMessage: 'Image could not be saved',
})
);
@@ -331,8 +335,8 @@ export class Field extends PureComponent {
showPageReloadToast = () => {
if (this.props.setting.requiresPageReload) {
- toastNotifications.add({
- title: i18n.translate('kbn.management.settings.field.requiresPageReloadToastDescription', {
+ this.props.toasts.add({
+ title: i18n.translate('advancedSettings.field.requiresPageReloadToastDescription', {
defaultMessage: 'Please reload the page for the "{settingName}" setting to take effect.',
values: {
settingName: this.props.setting.displayName || this.props.setting.name,
@@ -344,10 +348,9 @@ export class Field extends PureComponent {
window.location.reload()}>
- {i18n.translate(
- 'kbn.management.settings.field.requiresPageReloadToastButtonLabel',
- { defaultMessage: 'Reload page' }
- )}
+ {i18n.translate('advancedSettings.field.requiresPageReloadToastButtonLabel', {
+ defaultMessage: 'Reload page',
+ })}
@@ -398,8 +401,8 @@ export class Field extends PureComponent {
this.cancelChangeImage();
}
} catch (e) {
- toastNotifications.addDanger(
- i18n.translate('kbn.management.settings.field.saveFieldErrorMessage', {
+ this.props.toasts.addDanger(
+ i18n.translate('advancedSettings.field.saveFieldErrorMessage', {
defaultMessage: 'Unable to save {name}',
values: { name },
})
@@ -417,8 +420,8 @@ export class Field extends PureComponent {
this.cancelChangeImage();
this.clearError();
} catch (e) {
- toastNotifications.addDanger(
- i18n.translate('kbn.management.settings.field.resetFieldErrorMessage', {
+ this.props.toasts.addDanger(
+ i18n.translate('advancedSettings.field.resetFieldErrorMessage', {
defaultMessage: 'Unable to reset {name}',
values: { name },
})
@@ -438,12 +441,9 @@ export class Field extends PureComponent {
+
) : (
-
+
)
}
checked={!!unsavedValue}
@@ -553,7 +553,7 @@ export class Field extends PureComponent {
return (
@@ -584,12 +584,12 @@ export class Field extends PureComponent {
}
@@ -606,7 +606,7 @@ export class Field extends PureComponent {
let deprecation;
if (setting.deprecation) {
- const { links } = npStart.core.docLinks;
+ const links = this.props.dockLinks;
deprecation = (
<>
@@ -616,15 +616,12 @@ export class Field extends PureComponent {
onClick={() => {
window.open(links.management[setting.deprecation!.docLinksKey], '_blank');
}}
- onClickAriaLabel={i18n.translate(
- 'kbn.management.settings.field.deprecationClickAreaLabel',
- {
- defaultMessage: 'Click to view deprecation documentation for {settingName}.',
- values: {
- settingName: setting.name,
- },
- }
- )}
+ onClickAriaLabel={i18n.translate('advancedSettings.field.deprecationClickAreaLabel', {
+ defaultMessage: 'Click to view deprecation documentation for {settingName}.',
+ values: {
+ settingName: setting.name,
+ },
+ })}
>
Deprecated
@@ -669,7 +666,7 @@ export class Field extends PureComponent {
{type === 'json' ? (
{
) : (
{
return (
{
data-test-subj={`advancedSetting-resetField-${name}`}
>
@@ -738,7 +735,7 @@ export class Field extends PureComponent {
return (
{
data-test-subj={`advancedSetting-changeImage-${name}`}
>
@@ -771,7 +768,7 @@ export class Field extends PureComponent {
{
disabled={isDisabled || isInvalid}
data-test-subj={`advancedSetting-saveEditField-${name}`}
>
-
+
(changeImage ? this.cancelChangeImage() : this.cancelEdit())}
disabled={isDisabled}
data-test-subj={`advancedSetting-cancelEditField-${name}`}
>
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/index.ts b/src/plugins/advanced_settings/public/management_app/components/field/index.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/index.ts
rename to src/plugins/advanced_settings/public/management_app/components/field/index.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/__snapshots__/form.test.tsx.snap b/src/plugins/advanced_settings/public/management_app/components/form/__snapshots__/form.test.tsx.snap
similarity index 92%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/__snapshots__/form.test.tsx.snap
rename to src/plugins/advanced_settings/public/management_app/components/form/__snapshots__/form.test.tsx.snap
index b43c17c2a8865..8c471f5f5be9c 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/__snapshots__/form.test.tsx.snap
+++ b/src/plugins/advanced_settings/public/management_app/components/form/__snapshots__/form.test.tsx.snap
@@ -9,7 +9,7 @@ exports[`Form should render no settings message when there are no settings 1`] =
>
,
@@ -52,6 +52,7 @@ exports[`Form should render normally 1`] = `
/>
@@ -125,6 +129,7 @@ exports[`Form should render normally 1`] = `
/>
@@ -173,7 +179,7 @@ exports[`Form should render normally 1`] = `
@@ -200,6 +206,7 @@ exports[`Form should render normally 1`] = `
/>
@@ -254,6 +262,7 @@ exports[`Form should render read-only when saving is disabled 1`] = `
/>
@@ -327,6 +339,7 @@ exports[`Form should render read-only when saving is disabled 1`] = `
/>
@@ -375,7 +389,7 @@ exports[`Form should render read-only when saving is disabled 1`] = `
@@ -402,6 +416,7 @@ exports[`Form should render read-only when saving is disabled 1`] = `
/>
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.test.tsx b/src/plugins/advanced_settings/public/management_app/components/form/form.test.tsx
similarity index 93%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.test.tsx
rename to src/plugins/advanced_settings/public/management_app/components/form/form.test.tsx
index 6bbcfd543a629..468cfbfc70820 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.test.tsx
+++ b/src/plugins/advanced_settings/public/management_app/components/form/form.test.tsx
@@ -19,7 +19,7 @@
import React from 'react';
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';
-import { UiSettingsType } from '../../../../../../../../../core/public';
+import { UiSettingsType } from '../../../../../../core/public';
import { Form } from './form';
@@ -101,6 +101,8 @@ describe('Form', () => {
clearQuery={clearQuery}
showNoResultsMessage={true}
enableSaving={true}
+ toasts={{} as any}
+ dockLinks={{} as any}
/>
);
@@ -118,6 +120,8 @@ describe('Form', () => {
clearQuery={clearQuery}
showNoResultsMessage={true}
enableSaving={false}
+ toasts={{} as any}
+ dockLinks={{} as any}
/>
);
@@ -135,6 +139,8 @@ describe('Form', () => {
clearQuery={clearQuery}
showNoResultsMessage={true}
enableSaving={true}
+ toasts={{} as any}
+ dockLinks={{} as any}
/>
);
@@ -152,6 +158,8 @@ describe('Form', () => {
clearQuery={clearQuery}
showNoResultsMessage={false}
enableSaving={true}
+ toasts={{} as any}
+ dockLinks={{} as any}
/>
);
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.tsx b/src/plugins/advanced_settings/public/management_app/components/form/form.tsx
similarity index 90%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.tsx
rename to src/plugins/advanced_settings/public/management_app/components/form/form.tsx
index 113e0b2db5f30..91d587866836e 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.tsx
+++ b/src/plugins/advanced_settings/public/management_app/components/form/form.tsx
@@ -29,6 +29,7 @@ import {
EuiText,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
+import { DocLinksStart, ToastsStart } from '../../../../../../core/public';
import { getCategoryName } from '../../lib';
import { Field } from '../field';
@@ -45,6 +46,8 @@ interface FormProps {
clear: (key: string) => Promise;
showNoResultsMessage: boolean;
enableSaving: boolean;
+ dockLinks: DocLinksStart['links'];
+ toasts: ToastsStart;
}
export class Form extends PureComponent {
@@ -56,7 +59,7 @@ export class Form extends PureComponent {
{
@@ -102,6 +105,8 @@ export class Form extends PureComponent {
save={this.props.save}
clear={this.props.clear}
enableSaving={this.props.enableSaving}
+ dockLinks={this.props.dockLinks}
+ toasts={this.props.toasts}
/>
);
})}
@@ -117,13 +122,13 @@ export class Form extends PureComponent {
return (
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/index.ts b/src/plugins/advanced_settings/public/management_app/components/form/index.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/index.ts
rename to src/plugins/advanced_settings/public/management_app/components/form/index.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/__snapshots__/search.test.tsx.snap b/src/plugins/advanced_settings/public/management_app/components/search/__snapshots__/search.test.tsx.snap
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/__snapshots__/search.test.tsx.snap
rename to src/plugins/advanced_settings/public/management_app/components/search/__snapshots__/search.test.tsx.snap
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/index.ts b/src/plugins/advanced_settings/public/management_app/components/search/index.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/index.ts
rename to src/plugins/advanced_settings/public/management_app/components/search/index.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.test.tsx b/src/plugins/advanced_settings/public/management_app/components/search/search.test.tsx
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.test.tsx
rename to src/plugins/advanced_settings/public/management_app/components/search/search.test.tsx
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.tsx b/src/plugins/advanced_settings/public/management_app/components/search/search.tsx
similarity index 92%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.tsx
rename to src/plugins/advanced_settings/public/management_app/components/search/search.tsx
index 471f2ba28005c..51402296a44a2 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.tsx
+++ b/src/plugins/advanced_settings/public/management_app/components/search/search.tsx
@@ -75,7 +75,7 @@ export class Search extends PureComponent {
const box = {
incremental: true,
'data-test-subj': 'settingsSearchBar',
- 'aria-label': i18n.translate('kbn.management.settings.searchBarAriaLabel', {
+ 'aria-label': i18n.translate('advancedSettings.searchBarAriaLabel', {
defaultMessage: 'Search advanced settings',
}), // hack until EuiSearchBar is fixed
};
@@ -84,7 +84,7 @@ export class Search extends PureComponent {
{
type: 'field_value_selection',
field: 'category',
- name: i18n.translate('kbn.management.settings.categorySearchLabel', {
+ name: i18n.translate('advancedSettings.categorySearchLabel', {
defaultMessage: 'Category',
}),
multiSelect: 'or',
@@ -95,7 +95,7 @@ export class Search extends PureComponent {
let queryParseError;
if (!this.state.isSearchTextValid) {
const parseErrorMsg = i18n.translate(
- 'kbn.management.settings.searchBar.unableToParseQueryErrorMessage',
+ 'advancedSettings.searchBar.unableToParseQueryErrorMessage',
{ defaultMessage: 'Unable to parse query' }
);
queryParseError = (
diff --git a/src/plugins/advanced_settings/public/management_app/index.tsx b/src/plugins/advanced_settings/public/management_app/index.tsx
new file mode 100644
index 0000000000000..27d3114051c16
--- /dev/null
+++ b/src/plugins/advanced_settings/public/management_app/index.tsx
@@ -0,0 +1,102 @@
+/*
+ * 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 React from 'react';
+import ReactDOM from 'react-dom';
+import { HashRouter, Switch, Route } from 'react-router-dom';
+import { i18n } from '@kbn/i18n';
+import { I18nProvider } from '@kbn/i18n/react';
+import { AdvancedSettings } from './advanced_settings';
+import { ManagementSetup } from '../../../management/public';
+import { CoreSetup } from '../../../../core/public';
+import { ComponentRegistry } from '../types';
+
+const title = i18n.translate('advancedSettings.advancedSettingsLabel', {
+ defaultMessage: 'Advanced Settings',
+});
+const crumb = [{ text: title }];
+
+const readOnlyBadge = {
+ text: i18n.translate('advancedSettings.badge.readOnly.text', {
+ defaultMessage: 'Read only',
+ }),
+ tooltip: i18n.translate('advancedSettings.badge.readOnly.tooltip', {
+ defaultMessage: 'Unable to save advanced settings',
+ }),
+ iconType: 'glasses',
+};
+
+export async function registerAdvSettingsMgmntApp({
+ management,
+ getStartServices,
+ componentRegistry,
+}: {
+ management: ManagementSetup;
+ getStartServices: CoreSetup['getStartServices'];
+ componentRegistry: ComponentRegistry['start'];
+}) {
+ const kibanaSection = management.sections.getSection('kibana');
+ if (!kibanaSection) {
+ throw new Error('`kibana` management section not found.');
+ }
+
+ const advancedSettingsManagementApp = kibanaSection.registerApp({
+ id: 'settings',
+ title,
+ order: 20,
+ async mount(params) {
+ params.setBreadcrumbs(crumb);
+ const [
+ { uiSettings, notifications, docLinks, application, chrome },
+ ] = await getStartServices();
+
+ const canSave = application.capabilities.advancedSettings.save as boolean;
+
+ if (!canSave) {
+ chrome.setBadge(readOnlyBadge);
+ }
+
+ ReactDOM.render(
+
+
+
+
+
+
+
+
+ ,
+ params.element
+ );
+ return () => {
+ ReactDOM.unmountComponentAtNode(params.element);
+ };
+ },
+ });
+ const [{ application }] = await getStartServices();
+ if (!application.capabilities.management.kibana.settings) {
+ advancedSettingsManagementApp.disable();
+ }
+}
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/default_category.ts b/src/plugins/advanced_settings/public/management_app/lib/default_category.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/default_category.ts
rename to src/plugins/advanced_settings/public/management_app/lib/default_category.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.test.ts b/src/plugins/advanced_settings/public/management_app/lib/get_aria_name.test.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.test.ts
rename to src/plugins/advanced_settings/public/management_app/lib/get_aria_name.test.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.ts b/src/plugins/advanced_settings/public/management_app/lib/get_aria_name.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.ts
rename to src/plugins/advanced_settings/public/management_app/lib/get_aria_name.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.test.ts b/src/plugins/advanced_settings/public/management_app/lib/get_category_name.test.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.test.ts
rename to src/plugins/advanced_settings/public/management_app/lib/get_category_name.test.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.ts b/src/plugins/advanced_settings/public/management_app/lib/get_category_name.ts
similarity index 65%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.ts
rename to src/plugins/advanced_settings/public/management_app/lib/get_category_name.ts
index d0361ba698eeb..46d28ce9d5c40 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.ts
+++ b/src/plugins/advanced_settings/public/management_app/lib/get_category_name.ts
@@ -22,31 +22,31 @@ import { i18n } from '@kbn/i18n';
const upperFirst = (str = '') => str.replace(/^./, strng => strng.toUpperCase());
const names: Record = {
- general: i18n.translate('kbn.management.settings.categoryNames.generalLabel', {
+ general: i18n.translate('advancedSettings.categoryNames.generalLabel', {
defaultMessage: 'General',
}),
- timelion: i18n.translate('kbn.management.settings.categoryNames.timelionLabel', {
+ timelion: i18n.translate('advancedSettings.categoryNames.timelionLabel', {
defaultMessage: 'Timelion',
}),
- notifications: i18n.translate('kbn.management.settings.categoryNames.notificationsLabel', {
+ notifications: i18n.translate('advancedSettings.categoryNames.notificationsLabel', {
defaultMessage: 'Notifications',
}),
- visualizations: i18n.translate('kbn.management.settings.categoryNames.visualizationsLabel', {
+ visualizations: i18n.translate('advancedSettings.categoryNames.visualizationsLabel', {
defaultMessage: 'Visualizations',
}),
- discover: i18n.translate('kbn.management.settings.categoryNames.discoverLabel', {
+ discover: i18n.translate('advancedSettings.categoryNames.discoverLabel', {
defaultMessage: 'Discover',
}),
- dashboard: i18n.translate('kbn.management.settings.categoryNames.dashboardLabel', {
+ dashboard: i18n.translate('advancedSettings.categoryNames.dashboardLabel', {
defaultMessage: 'Dashboard',
}),
- reporting: i18n.translate('kbn.management.settings.categoryNames.reportingLabel', {
+ reporting: i18n.translate('advancedSettings.categoryNames.reportingLabel', {
defaultMessage: 'Reporting',
}),
- search: i18n.translate('kbn.management.settings.categoryNames.searchLabel', {
+ search: i18n.translate('advancedSettings.categoryNames.searchLabel', {
defaultMessage: 'Search',
}),
- siem: i18n.translate('kbn.management.settings.categoryNames.siemLabel', {
+ siem: i18n.translate('advancedSettings.categoryNames.siemLabel', {
defaultMessage: 'SIEM',
}),
};
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.test.ts b/src/plugins/advanced_settings/public/management_app/lib/get_val_type.test.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.test.ts
rename to src/plugins/advanced_settings/public/management_app/lib/get_val_type.test.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.ts b/src/plugins/advanced_settings/public/management_app/lib/get_val_type.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.ts
rename to src/plugins/advanced_settings/public/management_app/lib/get_val_type.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/index.ts b/src/plugins/advanced_settings/public/management_app/lib/index.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/index.ts
rename to src/plugins/advanced_settings/public/management_app/lib/index.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.test.ts b/src/plugins/advanced_settings/public/management_app/lib/is_default_value.test.ts
similarity index 98%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.test.ts
rename to src/plugins/advanced_settings/public/management_app/lib/is_default_value.test.ts
index 30531ca89b0b5..836dcb6b87676 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.test.ts
+++ b/src/plugins/advanced_settings/public/management_app/lib/is_default_value.test.ts
@@ -19,7 +19,7 @@
import expect from '@kbn/expect';
import { isDefaultValue } from './is_default_value';
-import { UiSettingsType } from '../../../../../../../../core/public';
+import { UiSettingsType } from '../../../../../core/public';
describe('Settings', function() {
describe('Advanced', function() {
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.ts b/src/plugins/advanced_settings/public/management_app/lib/is_default_value.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.ts
rename to src/plugins/advanced_settings/public/management_app/lib/is_default_value.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.test.ts b/src/plugins/advanced_settings/public/management_app/lib/to_editable_config.test.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.test.ts
rename to src/plugins/advanced_settings/public/management_app/lib/to_editable_config.test.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.ts b/src/plugins/advanced_settings/public/management_app/lib/to_editable_config.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.ts
rename to src/plugins/advanced_settings/public/management_app/lib/to_editable_config.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/types.ts b/src/plugins/advanced_settings/public/management_app/types.ts
similarity index 97%
rename from src/legacy/core_plugins/kibana/public/management/sections/settings/types.ts
rename to src/plugins/advanced_settings/public/management_app/types.ts
index fea70110f6071..05bb5e754563d 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/settings/types.ts
+++ b/src/plugins/advanced_settings/public/management_app/types.ts
@@ -22,7 +22,7 @@ import {
StringValidation,
ImageValidation,
SavedObjectAttribute,
-} from '../../../../../../../core/public';
+} from '../../../../core/public';
export interface FieldSetting {
displayName: string;
diff --git a/src/plugins/advanced_settings/public/plugin.ts b/src/plugins/advanced_settings/public/plugin.ts
index bffd5a5157615..e9472fbdee0e6 100644
--- a/src/plugins/advanced_settings/public/plugin.ts
+++ b/src/plugins/advanced_settings/public/plugin.ts
@@ -17,29 +17,20 @@
* under the License.
*/
-import { i18n } from '@kbn/i18n';
import { CoreSetup, CoreStart, Plugin } from 'kibana/public';
import { ComponentRegistry } from './component_registry';
-import { AdvancedSettingsSetup, AdvancedSettingsStart } from './types';
-import { FeatureCatalogueCategory, HomePublicPluginSetup } from '../../home/public';
+import { AdvancedSettingsSetup, AdvancedSettingsStart, AdvancedSettingsPluginSetup } from './types';
+import { registerAdvSettingsMgmntApp } from './management_app';
const component = new ComponentRegistry();
export class AdvancedSettingsPlugin
- implements Plugin {
- public setup(core: CoreSetup, { home }: { home: HomePublicPluginSetup }) {
- home.featureCatalogue.register({
- id: 'advanced_settings',
- title: i18n.translate('advancedSettings.advancedSettingsLabel', {
- defaultMessage: 'Advanced Settings',
- }),
- description: i18n.translate('advancedSettings.advancedSettingsDescription', {
- defaultMessage: 'Directly edit settings that control behavior in Kibana.',
- }),
- icon: 'advancedSettingsApp',
- path: '/app/kibana#/management/kibana/settings',
- showOnHomePage: false,
- category: FeatureCatalogueCategory.ADMIN,
+ implements Plugin {
+ public setup(core: CoreSetup, { management }: AdvancedSettingsPluginSetup) {
+ registerAdvSettingsMgmntApp({
+ management,
+ getStartServices: core.getStartServices,
+ componentRegistry: component.start,
});
return {
diff --git a/src/plugins/advanced_settings/public/types.ts b/src/plugins/advanced_settings/public/types.ts
index a9b965c3c22de..a233b3debab8d 100644
--- a/src/plugins/advanced_settings/public/types.ts
+++ b/src/plugins/advanced_settings/public/types.ts
@@ -18,6 +18,7 @@
*/
import { ComponentRegistry } from './component_registry';
+import { ManagementSetup } from '../../management/public';
export interface AdvancedSettingsSetup {
component: ComponentRegistry['setup'];
@@ -25,3 +26,9 @@ export interface AdvancedSettingsSetup {
export interface AdvancedSettingsStart {
component: ComponentRegistry['start'];
}
+
+export interface AdvancedSettingsPluginSetup {
+ management: ManagementSetup;
+}
+
+export { ComponentRegistry };
diff --git a/src/plugins/console/public/application/containers/editor/legacy/console_editor/editor.tsx b/src/plugins/console/public/application/containers/editor/legacy/console_editor/editor.tsx
index b3e966ddffa4c..bfa74392c14fb 100644
--- a/src/plugins/console/public/application/containers/editor/legacy/console_editor/editor.tsx
+++ b/src/plugins/console/public/application/containers/editor/legacy/console_editor/editor.tsx
@@ -21,11 +21,7 @@ import React, { CSSProperties, useCallback, useEffect, useRef, useState } from '
import { EuiToolTip } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { debounce } from 'lodash';
-
-// Node v5 querystring for browser.
-// @ts-ignore
-import * as qs from 'querystring-browser';
-
+import { parse } from 'query-string';
import { EuiIcon, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { useServicesContext, useEditorReadContext } from '../../../../contexts';
import { useUIAceKeyboardMode } from '../use_ui_ace_keyboard_mode';
@@ -51,6 +47,10 @@ export interface EditorProps {
initialTextValue: string;
}
+interface QueryParams {
+ load_from: string;
+}
+
const abs: CSSProperties = {
position: 'absolute',
top: '0',
@@ -98,7 +98,8 @@ function EditorUI({ initialTextValue }: EditorProps) {
const readQueryParams = () => {
const [, queryString] = (window.location.hash || '').split('?');
- return qs.parse(queryString || '');
+
+ return parse(queryString || '', { sort: false }) as Required;
};
const loadBufferFromRemote = (url: string) => {
@@ -138,6 +139,7 @@ function EditorUI({ initialTextValue }: EditorProps) {
window.addEventListener('hashchange', onHashChange);
const initialQueryParams = readQueryParams();
+
if (initialQueryParams.load_from) {
loadBufferFromRemote(initialQueryParams.load_from);
} else {
diff --git a/src/plugins/console/public/lib/es/es.ts b/src/plugins/console/public/lib/es/es.ts
index 52aba98d9e662..f11692e1befad 100644
--- a/src/plugins/console/public/lib/es/es.ts
+++ b/src/plugins/console/public/lib/es/es.ts
@@ -17,8 +17,8 @@
* under the License.
*/
-import { stringify as formatQueryString } from 'querystring';
import $ from 'jquery';
+import { stringify } from 'query-string';
const esVersion: string[] = [];
@@ -35,7 +35,7 @@ export function send(method: string, path: string, data: any) {
const wrappedDfd = $.Deferred(); // eslint-disable-line new-cap
const options: JQuery.AjaxSettings = {
- url: '../api/console/proxy?' + formatQueryString({ path, method }),
+ url: '../api/console/proxy?' + stringify({ path, method }, { sort: false }),
data,
contentType: getContentType(data),
cache: false,
diff --git a/src/plugins/dashboard_embeddable_container/public/embeddable/dashboard_container.tsx b/src/plugins/dashboard_embeddable_container/public/embeddable/dashboard_container.tsx
index 21bd1eeac6688..f9443ab97416d 100644
--- a/src/plugins/dashboard_embeddable_container/public/embeddable/dashboard_container.tsx
+++ b/src/plugins/dashboard_embeddable_container/public/embeddable/dashboard_container.tsx
@@ -20,7 +20,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { I18nProvider } from '@kbn/i18n/react';
-import { RefreshInterval, TimeRange, Query, esFilters } from '../../../data/public';
+import { RefreshInterval, TimeRange, Query, Filter } from '../../../data/public';
import { CoreStart } from '../../../../core/public';
import { UiActionsStart } from '../ui_actions_plugin';
import {
@@ -45,7 +45,7 @@ import {
export interface DashboardContainerInput extends ContainerInput {
viewMode: ViewMode;
- filters: esFilters.Filter[];
+ filters: Filter[];
query: Query;
timeRange: TimeRange;
refreshConfig?: RefreshInterval;
@@ -64,7 +64,7 @@ interface IndexSignature {
}
export interface InheritedChildInput extends IndexSignature {
- filters: esFilters.Filter[];
+ filters: Filter[];
query: Query;
timeRange: TimeRange;
refreshConfig?: RefreshInterval;
diff --git a/src/plugins/data/common/es_query/filters/build_filters.ts b/src/plugins/data/common/es_query/filters/build_filters.ts
index affd213c29517..e86414f240439 100644
--- a/src/plugins/data/common/es_query/filters/build_filters.ts
+++ b/src/plugins/data/common/es_query/filters/build_filters.ts
@@ -17,19 +17,28 @@
* under the License.
*/
-import { esFilters, IIndexPattern, IFieldType } from '../..';
-import { FilterMeta, FilterStateStore } from '.';
+import { IIndexPattern, IFieldType } from '../..';
+import {
+ Filter,
+ FILTERS,
+ FilterStateStore,
+ FilterMeta,
+ buildPhraseFilter,
+ buildPhrasesFilter,
+ buildRangeFilter,
+ buildExistsFilter,
+} from '.';
export function buildFilter(
indexPattern: IIndexPattern,
field: IFieldType,
- type: esFilters.FILTERS,
+ type: FILTERS,
negate: boolean,
disabled: boolean,
params: any,
alias: string | null,
- store: esFilters.FilterStateStore
-): esFilters.Filter {
+ store: FilterStateStore
+): Filter {
const filter = buildBaseFilter(indexPattern, field, type, params);
filter.meta.alias = alias;
filter.meta.negate = negate;
@@ -45,15 +54,15 @@ export function buildCustomFilter(
negate: boolean,
alias: string | null,
store: FilterStateStore
-): esFilters.Filter {
+): Filter {
const meta: FilterMeta = {
index: indexPatternString,
- type: esFilters.FILTERS.CUSTOM,
+ type: FILTERS.CUSTOM,
disabled,
negate,
alias,
};
- const filter: esFilters.Filter = { ...queryDsl, meta };
+ const filter: Filter = { ...queryDsl, meta };
filter.$state = { store };
return filter;
}
@@ -61,19 +70,19 @@ export function buildCustomFilter(
function buildBaseFilter(
indexPattern: IIndexPattern,
field: IFieldType,
- type: esFilters.FILTERS,
+ type: FILTERS,
params: any
-): esFilters.Filter {
+): Filter {
switch (type) {
case 'phrase':
- return esFilters.buildPhraseFilter(field, params, indexPattern);
+ return buildPhraseFilter(field, params, indexPattern);
case 'phrases':
- return esFilters.buildPhrasesFilter(field, params, indexPattern);
+ return buildPhrasesFilter(field, params, indexPattern);
case 'range':
const newParams = { gte: params.from, lt: params.to };
- return esFilters.buildRangeFilter(field, newParams, indexPattern);
+ return buildRangeFilter(field, newParams, indexPattern);
case 'exists':
- return esFilters.buildExistsFilter(field, indexPattern);
+ return buildExistsFilter(field, indexPattern);
default:
throw new Error(`Unknown filter type: ${type}`);
}
diff --git a/src/plugins/data/common/es_query/filters/stubs/exists_filter.ts b/src/plugins/data/common/es_query/filters/stubs/exists_filter.ts
index 13b8189b6e22f..9860697449372 100644
--- a/src/plugins/data/common/es_query/filters/stubs/exists_filter.ts
+++ b/src/plugins/data/common/es_query/filters/stubs/exists_filter.ts
@@ -17,9 +17,9 @@
* under the License.
*/
-import { esFilters } from '../../..';
+import { ExistsFilter, FilterStateStore } from '..';
-export const existsFilter: esFilters.ExistsFilter = {
+export const existsFilter: ExistsFilter = {
meta: {
index: 'logstash-*',
negate: false,
@@ -29,6 +29,6 @@ export const existsFilter: esFilters.ExistsFilter = {
alias: null,
},
$state: {
- store: esFilters.FilterStateStore.APP_STATE,
+ store: FilterStateStore.APP_STATE,
},
};
diff --git a/src/plugins/data/common/es_query/filters/stubs/phrase_filter.ts b/src/plugins/data/common/es_query/filters/stubs/phrase_filter.ts
index 7456e056a02b1..8c6f9b310fea8 100644
--- a/src/plugins/data/common/es_query/filters/stubs/phrase_filter.ts
+++ b/src/plugins/data/common/es_query/filters/stubs/phrase_filter.ts
@@ -17,9 +17,9 @@
* under the License.
*/
-import { esFilters } from '../../..';
+import { PhraseFilter, FilterStateStore } from '..';
-export const phraseFilter: esFilters.PhraseFilter = {
+export const phraseFilter: PhraseFilter = {
meta: {
negate: false,
index: 'logstash-*',
@@ -33,6 +33,6 @@ export const phraseFilter: esFilters.PhraseFilter = {
},
},
$state: {
- store: esFilters.FilterStateStore.APP_STATE,
+ store: FilterStateStore.APP_STATE,
},
};
diff --git a/src/plugins/data/common/es_query/filters/stubs/phrases_filter.ts b/src/plugins/data/common/es_query/filters/stubs/phrases_filter.ts
index 4bd70b85e186a..91a954fcc226d 100644
--- a/src/plugins/data/common/es_query/filters/stubs/phrases_filter.ts
+++ b/src/plugins/data/common/es_query/filters/stubs/phrases_filter.ts
@@ -17,9 +17,9 @@
* under the License.
*/
-import { esFilters } from '../../..';
+import { FilterStateStore, PhrasesFilter } from '..';
-export const phrasesFilter: esFilters.PhrasesFilter = {
+export const phrasesFilter: PhrasesFilter = {
meta: {
index: 'logstash-*',
type: 'phrases',
@@ -31,6 +31,6 @@ export const phrasesFilter: esFilters.PhrasesFilter = {
alias: null,
},
$state: {
- store: esFilters.FilterStateStore.APP_STATE,
+ store: FilterStateStore.APP_STATE,
},
};
diff --git a/src/plugins/data/common/es_query/filters/stubs/range_filter.ts b/src/plugins/data/common/es_query/filters/stubs/range_filter.ts
index 5a6d245e2ef6f..20b43c29f0e61 100644
--- a/src/plugins/data/common/es_query/filters/stubs/range_filter.ts
+++ b/src/plugins/data/common/es_query/filters/stubs/range_filter.ts
@@ -17,9 +17,9 @@
* under the License.
*/
-import { esFilters } from '../../..';
+import { RangeFilter, FilterStateStore } from '..';
-export const rangeFilter: esFilters.RangeFilter = {
+export const rangeFilter: RangeFilter = {
meta: {
index: 'logstash-*',
negate: false,
@@ -34,7 +34,7 @@ export const rangeFilter: esFilters.RangeFilter = {
},
},
$state: {
- store: esFilters.FilterStateStore.APP_STATE,
+ store: FilterStateStore.APP_STATE,
},
range: {},
};
diff --git a/src/plugins/data/common/es_query/index.ts b/src/plugins/data/common/es_query/index.ts
index e585fda8aff80..74cd4f450fc67 100644
--- a/src/plugins/data/common/es_query/index.ts
+++ b/src/plugins/data/common/es_query/index.ts
@@ -16,8 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-import * as esQuery from './es_query';
-import * as esFilters from './filters';
-import * as esKuery from './kuery';
-
-export { esFilters, esQuery, esKuery };
+export * from './es_query';
+export * from './filters';
+export * from './kuery';
diff --git a/src/plugins/data/common/es_query/kuery/ast/ast.ts b/src/plugins/data/common/es_query/kuery/ast/ast.ts
index 253f432617972..01ce77fa8f578 100644
--- a/src/plugins/data/common/es_query/kuery/ast/ast.ts
+++ b/src/plugins/data/common/es_query/kuery/ast/ast.ts
@@ -19,11 +19,12 @@
import { nodeTypes } from '../node_types/index';
import { KQLSyntaxError } from '../kuery_syntax_error';
-import { KueryNode, JsonObject, DslQuery, KueryParseOptions } from '../types';
+import { KueryNode, DslQuery, KueryParseOptions } from '../types';
import { IIndexPattern } from '../../../index_patterns/types';
// @ts-ignore
import { parse as parseKuery } from './_generated_/kuery';
+import { JsonObject } from '../../../../../kibana_utils/public';
const fromExpression = (
expression: string | DslQuery,
diff --git a/src/plugins/data/common/es_query/kuery/kuery_syntax_error.ts b/src/plugins/data/common/es_query/kuery/kuery_syntax_error.ts
index 0d5cd6ea17f16..4ada139a10a0f 100644
--- a/src/plugins/data/common/es_query/kuery/kuery_syntax_error.ts
+++ b/src/plugins/data/common/es_query/kuery/kuery_syntax_error.ts
@@ -20,21 +20,21 @@
import { repeat } from 'lodash';
import { i18n } from '@kbn/i18n';
-const endOfInputText = i18n.translate('data.common.esQuery.kql.errors.endOfInputText', {
+const endOfInputText = i18n.translate('data.common.kql.errors.endOfInputText', {
defaultMessage: 'end of input',
});
const grammarRuleTranslations: Record = {
- fieldName: i18n.translate('data.common.esQuery.kql.errors.fieldNameText', {
+ fieldName: i18n.translate('data.common.kql.errors.fieldNameText', {
defaultMessage: 'field name',
}),
- value: i18n.translate('data.common.esQuery.kql.errors.valueText', {
+ value: i18n.translate('data.common.kql.errors.valueText', {
defaultMessage: 'value',
}),
- literal: i18n.translate('data.common.esQuery.kql.errors.literalText', {
+ literal: i18n.translate('data.common.kql.errors.literalText', {
defaultMessage: 'literal',
}),
- whitespace: i18n.translate('data.common.esQuery.kql.errors.whitespaceText', {
+ whitespace: i18n.translate('data.common.kql.errors.whitespaceText', {
defaultMessage: 'whitespace',
}),
};
@@ -61,7 +61,7 @@ export class KQLSyntaxError extends Error {
const translatedExpectationText = translatedExpectations.join(', ');
- message = i18n.translate('data.common.esQuery.kql.errors.syntaxError', {
+ message = i18n.translate('data.common.kql.errors.syntaxError', {
defaultMessage: 'Expected {expectedList} but {foundInput} found.',
values: {
expectedList: translatedExpectationText,
diff --git a/src/plugins/data/common/es_query/kuery/node_types/function.ts b/src/plugins/data/common/es_query/kuery/node_types/function.ts
index 5b09bc2a67349..3137177fbfcc0 100644
--- a/src/plugins/data/common/es_query/kuery/node_types/function.ts
+++ b/src/plugins/data/common/es_query/kuery/node_types/function.ts
@@ -22,7 +22,7 @@ import _ from 'lodash';
import { functions } from '../functions';
import { IIndexPattern } from '../../..';
import { FunctionName, FunctionTypeBuildNode } from './types';
-import { JsonValue } from '..';
+import { JsonValue } from '../../../../../kibana_utils/public';
export function buildNode(functionName: FunctionName, ...args: any[]) {
const kueryFunction = functions[functionName];
diff --git a/src/plugins/data/common/es_query/kuery/node_types/named_arg.ts b/src/plugins/data/common/es_query/kuery/node_types/named_arg.ts
index 750801990f44e..398cb1a164415 100644
--- a/src/plugins/data/common/es_query/kuery/node_types/named_arg.ts
+++ b/src/plugins/data/common/es_query/kuery/node_types/named_arg.ts
@@ -21,7 +21,7 @@ import _ from 'lodash';
import * as ast from '../ast';
import { nodeTypes } from '../node_types';
import { NamedArgTypeBuildNode } from './types';
-import { JsonObject } from '../types';
+import { JsonObject } from '../../../../../kibana_utils/public';
export function buildNode(name: string, value: any): NamedArgTypeBuildNode {
const argumentNode =
diff --git a/src/plugins/data/common/es_query/kuery/node_types/types.ts b/src/plugins/data/common/es_query/kuery/node_types/types.ts
index 1af4a20583d46..937b5c6e7ef9c 100644
--- a/src/plugins/data/common/es_query/kuery/node_types/types.ts
+++ b/src/plugins/data/common/es_query/kuery/node_types/types.ts
@@ -22,7 +22,8 @@
*/
import { IIndexPattern } from '../../../index_patterns';
-import { JsonValue, KueryNode } from '..';
+import { JsonValue } from '../../../../../kibana_utils/public';
+import { KueryNode } from '..';
export type FunctionName =
| 'is'
diff --git a/src/plugins/data/common/es_query/kuery/types.ts b/src/plugins/data/common/es_query/kuery/types.ts
index 63c52bb64dc65..086a1d97a2faf 100644
--- a/src/plugins/data/common/es_query/kuery/types.ts
+++ b/src/plugins/data/common/es_query/kuery/types.ts
@@ -38,10 +38,3 @@ export interface KueryParseOptions {
}
export { nodeTypes } from './node_types';
-
-export type JsonArray = JsonValue[];
-export type JsonValue = null | boolean | number | string | JsonObject | JsonArray;
-
-export interface JsonObject {
- [key: string]: JsonValue;
-}
diff --git a/src/plugins/data/public/actions/apply_filter_action.ts b/src/plugins/data/public/actions/apply_filter_action.ts
index cc8bcf7679cf1..6edb3237987fa 100644
--- a/src/plugins/data/public/actions/apply_filter_action.ts
+++ b/src/plugins/data/public/actions/apply_filter_action.ts
@@ -22,18 +22,12 @@ import { toMountPoint } from '../../../kibana_react/public';
import { Action, createAction, IncompatibleActionError } from '../../../ui_actions/public';
import { getOverlays, getIndexPatterns } from '../services';
import { applyFiltersPopover } from '../ui/apply_filters';
-import {
- esFilters,
- FilterManager,
- TimefilterContract,
- changeTimeFilter,
- extractTimeFilter,
-} from '..';
+import { Filter, FilterManager, TimefilterContract, esFilters } from '..';
export const GLOBAL_APPLY_FILTER_ACTION = 'GLOBAL_APPLY_FILTER_ACTION';
interface ActionContext {
- filters: esFilters.Filter[];
+ filters: Filter[];
timeFieldName?: string;
}
@@ -63,7 +57,7 @@ export function createFilterAction(
throw new IncompatibleActionError();
}
- let selectedFilters: esFilters.Filter[] = filters;
+ let selectedFilters: Filter[] = filters;
if (selectedFilters.length > 1) {
const indexPatterns = await Promise.all(
@@ -72,7 +66,7 @@ export function createFilterAction(
})
);
- const filterSelectionPromise: Promise = new Promise(resolve => {
+ const filterSelectionPromise: Promise = new Promise(resolve => {
const overlay = getOverlays().openModal(
toMountPoint(
applyFiltersPopover(
@@ -82,7 +76,7 @@ export function createFilterAction(
overlay.close();
resolve([]);
},
- (filterSelection: esFilters.Filter[]) => {
+ (filterSelection: Filter[]) => {
overlay.close();
resolve(filterSelection);
}
@@ -98,13 +92,13 @@ export function createFilterAction(
}
if (timeFieldName) {
- const { timeRangeFilter, restOfFilters } = extractTimeFilter(
+ const { timeRangeFilter, restOfFilters } = esFilters.extractTimeFilter(
timeFieldName,
selectedFilters
);
filterManager.addFilters(restOfFilters);
if (timeRangeFilter) {
- changeTimeFilter(timeFilter, timeRangeFilter);
+ esFilters.changeTimeFilter(timeFilter, timeRangeFilter);
}
} else {
filterManager.addFilters(selectedFilters);
diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts
index 6c14739d42bf1..548417f3769aa 100644
--- a/src/plugins/data/public/index.ts
+++ b/src/plugins/data/public/index.ts
@@ -20,12 +20,133 @@
import { PluginInitializerContext } from '../../../core/public';
/*
- * Field Formatters helper namespace:
+ * Filters:
+ */
+
+import {
+ FILTERS,
+ buildEmptyFilter,
+ buildPhrasesFilter,
+ buildExistsFilter,
+ buildPhraseFilter,
+ buildQueryFilter,
+ buildRangeFilter,
+ toggleFilterNegated,
+ disableFilter,
+ FilterStateStore,
+ getPhraseFilterField,
+ getPhraseFilterValue,
+ isPhraseFilter,
+ isExistsFilter,
+ isPhrasesFilter,
+ isRangeFilter,
+ isMatchAllFilter,
+ isMissingFilter,
+ isQueryStringFilter,
+ getDisplayValueFromFilter,
+ isFilterPinned,
+} from '../common';
+
+import { FilterLabel } from './ui/filter_bar';
+
+import {
+ compareFilters,
+ COMPARE_ALL_OPTIONS,
+ generateFilters,
+ onlyDisabledFiltersChanged,
+ changeTimeFilter,
+ mapAndFlattenFilters,
+ extractTimeFilter,
+} from './query';
+
+// Filter helpers namespace:
+export const esFilters = {
+ FilterLabel,
+
+ FILTERS,
+ FilterStateStore,
+
+ buildEmptyFilter,
+ buildPhrasesFilter,
+ buildExistsFilter,
+ buildPhraseFilter,
+ buildQueryFilter,
+ buildRangeFilter,
+
+ isPhraseFilter,
+ isExistsFilter,
+ isPhrasesFilter,
+ isRangeFilter,
+ isMatchAllFilter,
+ isMissingFilter,
+ isQueryStringFilter,
+ isFilterPinned,
+
+ toggleFilterNegated,
+ disableFilter,
+ getPhraseFilterField,
+ getPhraseFilterValue,
+ getDisplayValueFromFilter,
+
+ compareFilters,
+ COMPARE_ALL_OPTIONS,
+ generateFilters,
+ onlyDisabledFiltersChanged,
+
+ changeTimeFilter,
+ mapAndFlattenFilters,
+ extractTimeFilter,
+};
+
+export {
+ RangeFilter,
+ RangeFilterMeta,
+ RangeFilterParams,
+ ExistsFilter,
+ PhrasesFilter,
+ PhraseFilter,
+ CustomFilter,
+ MatchAllFilter,
+} from '../common';
+
+/*
+ * esQuery and esKuery:
+ */
+
+import {
+ fromKueryExpression,
+ toElasticsearchQuery,
+ nodeTypes,
+ buildEsQuery,
+ getEsQueryConfig,
+ buildQueryFromFilters,
+ luceneStringToDsl,
+ decorateQuery,
+} from '../common';
+
+export const esKuery = {
+ nodeTypes,
+ fromKueryExpression,
+ toElasticsearchQuery,
+};
+
+export const esQuery = {
+ buildEsQuery,
+ getEsQueryConfig,
+ buildQueryFromFilters,
+ luceneStringToDsl,
+ decorateQuery,
+};
+
+export { EsQueryConfig, KueryNode } from '../common';
+
+/*
+ * Field Formatters:
*/
import {
FieldFormat,
- FieldFormatsRegistry, // exported only for tests. Consider mock.
+ FieldFormatsRegistry,
DEFAULT_CONVERTER_COLOR,
HTML_CONTEXT_TYPE,
TEXT_CONTEXT_TYPE,
@@ -47,6 +168,7 @@ import {
TruncateFormat,
} from '../common/field_formats';
+// Field formats helpers namespace:
export const fieldFormats = {
FieldFormat,
FieldFormatsRegistry, // exported only for tests. Consider mock.
@@ -73,38 +195,73 @@ export const fieldFormats = {
TruncateFormat,
};
-export function plugin(initializerContext: PluginInitializerContext) {
- return new DataPublicPlugin(initializerContext);
-}
+export {
+ IFieldFormat,
+ IFieldFormatsRegistry,
+ FieldFormatsContentType,
+ FieldFormatsGetConfigFn,
+ FieldFormatConfig,
+ FieldFormatId,
+} from '../common';
-/**
- * Types to be shared externally
- * @public
+/*
+ * Index patterns:
*/
-export { IRequestTypesMap, IResponseTypesMap } from './search';
-export * from './types';
+
+import { isNestedField, isFilterable } from '../common';
+
+import {
+ ILLEGAL_CHARACTERS_KEY,
+ CONTAINS_SPACES_KEY,
+ ILLEGAL_CHARACTERS_VISIBLE,
+ ILLEGAL_CHARACTERS,
+ isDefault,
+ validateIndexPattern,
+ getFromSavedObject,
+ flattenHitWrapper,
+ getRoutes,
+ formatHitProvider,
+} from './index_patterns';
+
+// Index patterns namespace:
+export const indexPatterns = {
+ ILLEGAL_CHARACTERS_KEY,
+ CONTAINS_SPACES_KEY,
+ ILLEGAL_CHARACTERS_VISIBLE,
+ ILLEGAL_CHARACTERS,
+ isDefault,
+ isFilterable,
+ isNestedField,
+ validate: validateIndexPattern,
+ getFromSavedObject,
+ flattenHitWrapper,
+ // TODO: exported only in stub_index_pattern test. Move into data plugin and remove export.
+ getRoutes,
+ formatHitProvider,
+};
+
+export {
+ IndexPatternsContract,
+ IndexPattern,
+ Field as IndexPatternField,
+ TypeMeta as IndexPatternTypeMeta,
+ AggregationRestrictions as IndexPatternAggRestrictions,
+ // TODO: exported only in stub_index_pattern test. Move into data plugin and remove export.
+ FieldList as IndexPatternFieldList,
+} from './index_patterns';
+
export {
- // index patterns
IIndexPattern,
IFieldType,
IFieldSubType,
- // kbn field types
ES_FIELD_TYPES,
KBN_FIELD_TYPES,
- // query
- Query,
- // timefilter
- RefreshInterval,
- TimeRange,
- // Field Formats
- IFieldFormat,
- IFieldFormatsRegistry,
- FieldFormatsContentType,
- FieldFormatsGetConfigFn,
- FieldFormatConfig,
- FieldFormatId,
} from '../common';
+/*
+ * Autocomplete query suggestions:
+ */
+
export {
QuerySuggestion,
QuerySuggestionTypes,
@@ -114,27 +271,58 @@ export {
QuerySuggestionField,
} from './autocomplete';
-export * from './field_formats';
-export * from './index_patterns';
+/*
+ * Search:
+ */
+
+export { IRequestTypesMap, IResponseTypesMap } from './search';
export * from './search';
-export * from './query';
+
+/**
+ * Types to be shared externally
+ * @public
+ */
+export { Filter, Query, RefreshInterval, TimeRange } from '../common';
+
+export {
+ createSavedQueryService,
+ syncAppFilters,
+ syncQuery,
+ getTime,
+ getQueryLog,
+ getQueryStateContainer,
+ FilterManager,
+ SavedQuery,
+ SavedQueryService,
+ SavedQueryTimeFilter,
+ SavedQueryAttributes,
+ InputTimeRange,
+ TimefilterSetup,
+ TimeHistory,
+ TimefilterContract,
+ TimeHistoryContract,
+} from './query';
export * from './ui';
+
export {
- // es query
- esFilters,
- esKuery,
- esQuery,
- // index patterns
- isFilterable,
// kbn field types
castEsToKbnFieldTypeName,
- getKbnFieldType,
getKbnTypeNames,
// utils
parseInterval,
- isNestedField,
} from '../common';
-// Export plugin after all other imports
+/*
+ * Plugin setup
+ */
+
import { DataPublicPlugin } from './plugin';
+
+export function plugin(initializerContext: PluginInitializerContext) {
+ return new DataPublicPlugin(initializerContext);
+}
+
+export { DataPublicPluginSetup, DataPublicPluginStart, IDataPluginServices } from './types';
+
+// Export plugin after all other imports
export { DataPublicPlugin as Plugin };
diff --git a/src/plugins/data/public/index_patterns/index.ts b/src/plugins/data/public/index_patterns/index.ts
index ecddd893d1a54..dcf799184b01c 100644
--- a/src/plugins/data/public/index_patterns/index.ts
+++ b/src/plugins/data/public/index_patterns/index.ts
@@ -17,40 +17,25 @@
* under the License.
*/
-import {
+export {
ILLEGAL_CHARACTERS_KEY,
CONTAINS_SPACES_KEY,
ILLEGAL_CHARACTERS_VISIBLE,
ILLEGAL_CHARACTERS,
- IndexPatternMissingIndices,
validateIndexPattern,
getFromSavedObject,
isDefault,
} from './lib';
-import { getRoutes } from './utils';
-import { flattenHitWrapper, formatHitProvider } from './index_patterns';
-
-export const indexPatterns = {
- ILLEGAL_CHARACTERS_KEY,
- CONTAINS_SPACES_KEY,
- ILLEGAL_CHARACTERS_VISIBLE,
- ILLEGAL_CHARACTERS,
- IndexPatternMissingIndices,
- validate: validateIndexPattern,
- getRoutes,
- getFromSavedObject,
- flattenHitWrapper,
- formatHitProvider,
- isDefault,
-};
+export { getRoutes } from './utils';
+export { flattenHitWrapper, formatHitProvider } from './index_patterns';
export { Field, FieldList } from './fields';
// TODO: figure out how to replace IndexPatterns in get_inner_angular.
export {
- IndexPattern,
- IndexPatterns,
+ IndexPatternsService,
IndexPatternsContract,
+ IndexPattern,
TypeMeta,
AggregationRestrictions,
} from './index_patterns';
diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts
index c09c9f4828799..06d4a881447dc 100644
--- a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts
+++ b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts
@@ -31,7 +31,7 @@ import {
import { ES_FIELD_TYPES, KBN_FIELD_TYPES, IIndexPattern, IFieldType } from '../../../common';
import { findByTitle, getRoutes } from '../utils';
-import { indexPatterns } from '../';
+import { IndexPatternMissingIndices } from '../lib';
import { Field, FieldList, IFieldList } from '../fields';
import { createFieldsFetcher } from './_fields_fetcher';
import { formatHitProvider } from './format_hit';
@@ -489,7 +489,7 @@ export class IndexPattern implements IIndexPattern {
// so do not rethrow the error here
const { toasts } = getNotifications();
- if (err instanceof indexPatterns.IndexPatternMissingIndices) {
+ if (err instanceof IndexPatternMissingIndices) {
toasts.addDanger((err as any).message);
return [];
diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts
index f21a1610f29e2..c429431b632bd 100644
--- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts
+++ b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts
@@ -18,7 +18,7 @@
*/
// eslint-disable-next-line max-classes-per-file
-import { IndexPatterns } from './index_patterns';
+import { IndexPatternsService } from './index_patterns';
import {
SavedObjectsClientContract,
IUiSettingsClient,
@@ -49,7 +49,7 @@ jest.mock('./index_patterns_api_client', () => {
});
describe('IndexPatterns', () => {
- let indexPatterns: IndexPatterns;
+ let indexPatterns: IndexPatternsService;
let savedObjectsClient: SavedObjectsClientContract;
beforeEach(() => {
@@ -64,7 +64,7 @@ describe('IndexPatterns', () => {
const uiSettings = {} as IUiSettingsClient;
const http = {} as HttpSetup;
- indexPatterns = new IndexPatterns(uiSettings, savedObjectsClient, http);
+ indexPatterns = new IndexPatternsService(uiSettings, savedObjectsClient, http);
});
test('does cache gets for the same id', async () => {
diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts
index 2c93ed7fb79bf..5f95b101302ef 100644
--- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts
+++ b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts
@@ -32,7 +32,7 @@ const indexPatternCache = createIndexPatternCache();
type IndexPatternCachedFieldType = 'id' | 'title';
-export class IndexPatterns {
+export class IndexPatternsService {
private config: IUiSettingsClient;
private savedObjectsClient: SavedObjectsClientContract;
private savedObjectsCache?: Array>> | null;
@@ -150,4 +150,4 @@ export class IndexPatterns {
};
}
-export type IndexPatternsContract = PublicMethodsOf;
+export type IndexPatternsContract = PublicMethodsOf;
diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts
index 52d18170168d4..4d4e8d8827b48 100644
--- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts
+++ b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts
@@ -18,7 +18,7 @@
*/
import { HttpSetup } from 'src/core/public';
-import { indexPatterns } from '../';
+import { IndexPatternMissingIndices } from '../lib';
const API_BASE_URL: string = `/api/index_patterns/`;
@@ -46,7 +46,7 @@ export class IndexPatternsApiClient {
})
.catch((resp: any) => {
if (resp.body.statusCode === 404 && resp.body.statuscode === 'no_matching_indices') {
- throw new indexPatterns.IndexPatternMissingIndices(resp.body.message);
+ throw new IndexPatternMissingIndices(resp.body.message);
}
throw new Error(resp.body.message || resp.body.error || `${resp.body.statusCode} Response`);
diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts
index 8a45d9fc2f23b..560f415eb082a 100644
--- a/src/plugins/data/public/plugin.ts
+++ b/src/plugins/data/public/plugin.ts
@@ -36,7 +36,7 @@ import { SearchService } from './search/search_service';
import { FieldFormatsService } from './field_formats';
import { QueryService } from './query';
import { createIndexPatternSelect } from './ui/index_pattern_select';
-import { IndexPatterns } from './index_patterns';
+import { IndexPatternsService } from './index_patterns';
import {
setNotifications,
setFieldFormats,
@@ -90,7 +90,7 @@ export class DataPublicPlugin implements Plugin {
let updateListener: sinon.SinonSpy;
let filterManager: FilterManager;
- let readyFilters: esFilters.Filter[];
+ let readyFilters: Filter[];
beforeEach(() => {
updateListener = sinon.stub();
@@ -89,7 +89,7 @@ describe('filter_manager', () => {
test('app state should be set', async () => {
updateSubscription = filterManager.getUpdates$().subscribe(updateListener);
- const f1 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'age', 34);
+ const f1 = getFilter(FilterStateStore.APP_STATE, false, false, 'age', 34);
filterManager.setFilters([f1]);
expect(filterManager.getAppFilters()).toHaveLength(1);
expect(filterManager.getGlobalFilters()).toHaveLength(0);
@@ -103,7 +103,7 @@ describe('filter_manager', () => {
test('global state should be set', async () => {
updateSubscription = filterManager.getUpdates$().subscribe(updateListener);
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
filterManager.setFilters([f1]);
expect(filterManager.getAppFilters()).toHaveLength(0);
expect(filterManager.getGlobalFilters()).toHaveLength(1);
@@ -117,8 +117,8 @@ describe('filter_manager', () => {
test('both states should be set', async () => {
updateSubscription = filterManager.getUpdates$().subscribe(updateListener);
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
- const f2 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'gender', 'FEMALE');
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
+ const f2 = getFilter(FilterStateStore.APP_STATE, false, false, 'gender', 'FEMALE');
filterManager.setFilters([f1, f2]);
expect(filterManager.getAppFilters()).toHaveLength(1);
expect(filterManager.getGlobalFilters()).toHaveLength(1);
@@ -135,8 +135,8 @@ describe('filter_manager', () => {
test('set state should override previous state', async () => {
updateSubscription = filterManager.getUpdates$().subscribe(updateListener);
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
- const f2 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'gender', 'FEMALE');
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
+ const f2 = getFilter(FilterStateStore.APP_STATE, false, false, 'gender', 'FEMALE');
filterManager.setFilters([f1]);
filterManager.setFilters([f2]);
@@ -157,7 +157,7 @@ describe('filter_manager', () => {
test('changing a disabled filter should fire only update event', async function() {
const updateStub = jest.fn();
const fetchStub = jest.fn();
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, true, false, 'age', 34);
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, true, false, 'age', 34);
filterManager.setFilters([f1]);
@@ -183,12 +183,12 @@ describe('filter_manager', () => {
const appFilter1 = _.cloneDeep(readyFilters[1]);
appFilter1.meta.negate = true;
appFilter1.$state = {
- store: esFilters.FilterStateStore.APP_STATE,
+ store: FilterStateStore.APP_STATE,
};
const appFilter2 = _.cloneDeep(readyFilters[2]);
appFilter2.meta.negate = true;
appFilter2.$state = {
- store: esFilters.FilterStateStore.APP_STATE,
+ store: FilterStateStore.APP_STATE,
};
const globalFilters = filterManager.getFilters();
@@ -199,7 +199,7 @@ describe('filter_manager', () => {
expect(res).toHaveLength(3);
expect(
res.filter(function(filter) {
- return filter.$state && filter.$state.store === esFilters.FilterStateStore.GLOBAL_STATE;
+ return filter.$state && filter.$state.store === FilterStateStore.GLOBAL_STATE;
}).length
).toBe(3);
});
@@ -233,7 +233,7 @@ describe('filter_manager', () => {
});
test('set filter with no state, and force pin', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
f1.$state = undefined;
filterManager.setFilters([f1], true);
@@ -242,7 +242,7 @@ describe('filter_manager', () => {
});
test('set filter with no state, and no pin', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
f1.$state = undefined;
filterManager.setFilters([f1], false);
@@ -251,7 +251,7 @@ describe('filter_manager', () => {
});
test('set filters with default pin', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
f1.$state = undefined;
setupMock.uiSettings.get.mockImplementationOnce(uiSettingsMock(true));
@@ -261,7 +261,7 @@ describe('filter_manager', () => {
});
test('set filters without default pin', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
f1.$state = undefined;
setupMock.uiSettings.get.mockImplementationOnce(uiSettingsMock(false));
@@ -274,7 +274,7 @@ describe('filter_manager', () => {
describe('add filters', () => {
test('app state should accept a single filter', async function() {
updateSubscription = filterManager.getUpdates$().subscribe(updateListener);
- const f1 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'age', 34);
+ const f1 = getFilter(FilterStateStore.APP_STATE, false, false, 'age', 34);
filterManager.addFilters(f1);
const appFilters = filterManager.getAppFilters();
expect(appFilters).toHaveLength(1);
@@ -284,8 +284,8 @@ describe('filter_manager', () => {
});
test('app state should accept array and preserve order', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'age', 34);
- const f2 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'gender', 'female');
+ const f1 = getFilter(FilterStateStore.APP_STATE, false, false, 'age', 34);
+ const f2 = getFilter(FilterStateStore.APP_STATE, false, false, 'gender', 'female');
filterManager.addFilters([f1]);
filterManager.addFilters([f2]);
@@ -297,7 +297,7 @@ describe('filter_manager', () => {
test('global state should accept a single filer', async () => {
updateSubscription = filterManager.getUpdates$().subscribe(updateListener);
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
filterManager.addFilters(f1);
expect(filterManager.getAppFilters()).toHaveLength(0);
const globalFilters = filterManager.getGlobalFilters();
@@ -307,14 +307,8 @@ describe('filter_manager', () => {
});
test('global state should be accept array and preserve order', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
- const f2 = getFilter(
- esFilters.FilterStateStore.GLOBAL_STATE,
- false,
- false,
- 'gender',
- 'female'
- );
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
+ const f2 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'gender', 'female');
filterManager.addFilters([f1, f2]);
expect(filterManager.getAppFilters()).toHaveLength(0);
@@ -324,8 +318,8 @@ describe('filter_manager', () => {
});
test('mixed filters: global filters should stay in the beginning', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
- const f2 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'gender', 'female');
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
+ const f2 = getFilter(FilterStateStore.APP_STATE, false, false, 'gender', 'female');
filterManager.addFilters([f1, f2]);
const filters = filterManager.getFilters();
expect(filters).toHaveLength(2);
@@ -333,14 +327,8 @@ describe('filter_manager', () => {
});
test('mixed filters: global filters should move to the beginning', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'age', 34);
- const f2 = getFilter(
- esFilters.FilterStateStore.GLOBAL_STATE,
- false,
- false,
- 'gender',
- 'female'
- );
+ const f1 = getFilter(FilterStateStore.APP_STATE, false, false, 'age', 34);
+ const f2 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'gender', 'female');
filterManager.addFilters([f1, f2]);
const filters = filterManager.getFilters();
expect(filters).toHaveLength(2);
@@ -349,14 +337,8 @@ describe('filter_manager', () => {
test('add multiple filters at once', async () => {
updateSubscription = filterManager.getUpdates$().subscribe(updateListener);
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
- const f2 = getFilter(
- esFilters.FilterStateStore.GLOBAL_STATE,
- false,
- false,
- 'gender',
- 'female'
- );
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
+ const f2 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'gender', 'female');
filterManager.addFilters([f1, f2]);
expect(filterManager.getAppFilters()).toHaveLength(0);
expect(filterManager.getGlobalFilters()).toHaveLength(2);
@@ -365,8 +347,8 @@ describe('filter_manager', () => {
test('add same filter to global and app', async () => {
updateSubscription = filterManager.getUpdates$().subscribe(updateListener);
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
- const f2 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'age', 34);
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
+ const f2 = getFilter(FilterStateStore.APP_STATE, false, false, 'age', 34);
filterManager.addFilters([f1, f2]);
// FILTER SHOULD BE ADDED ONLY ONCE, TO GLOBAL
@@ -377,8 +359,8 @@ describe('filter_manager', () => {
test('add same filter with different values to global and app', async () => {
updateSubscription = filterManager.getUpdates$().subscribe(updateListener);
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
- const f2 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'age', 34);
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
+ const f2 = getFilter(FilterStateStore.APP_STATE, false, false, 'age', 34);
filterManager.addFilters([f1, f2]);
// FILTER SHOULD BE ADDED TWICE
@@ -388,7 +370,7 @@ describe('filter_manager', () => {
});
test('add filter with no state, and force pin', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
f1.$state = undefined;
filterManager.addFilters([f1], true);
@@ -397,12 +379,12 @@ describe('filter_manager', () => {
const f1Output = filterManager.getFilters()[0];
expect(f1Output.$state).toBeDefined();
if (f1Output.$state) {
- expect(f1Output.$state.store).toBe(esFilters.FilterStateStore.GLOBAL_STATE);
+ expect(f1Output.$state.store).toBe(FilterStateStore.GLOBAL_STATE);
}
});
test('add filter with no state, and dont force pin', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
f1.$state = undefined;
filterManager.addFilters([f1], false);
@@ -411,7 +393,7 @@ describe('filter_manager', () => {
const f1Output = filterManager.getFilters()[0];
expect(f1Output.$state).toBeDefined();
if (f1Output.$state) {
- expect(f1Output.$state.store).toBe(esFilters.FilterStateStore.APP_STATE);
+ expect(f1Output.$state.store).toBe(FilterStateStore.APP_STATE);
}
});
@@ -423,11 +405,11 @@ describe('filter_manager', () => {
// global filters should be listed first
let res = filterManager.getFilters();
expect(res).toHaveLength(2);
- expect(res[0].$state && res[0].$state.store).toEqual(esFilters.FilterStateStore.GLOBAL_STATE);
+ expect(res[0].$state && res[0].$state.store).toEqual(FilterStateStore.GLOBAL_STATE);
expect(res[0].meta.disabled).toEqual(filters[1].meta.disabled);
expect(res[0].query).toEqual(filters[1].query);
- expect(res[1].$state && res[1].$state.store).toEqual(esFilters.FilterStateStore.APP_STATE);
+ expect(res[1].$state && res[1].$state.store).toEqual(FilterStateStore.APP_STATE);
expect(res[1].meta.disabled).toEqual(filters[0].meta.disabled);
expect(res[1].query).toEqual(filters[0].query);
@@ -447,7 +429,7 @@ describe('filter_manager', () => {
const res = filterManager.getFilters();
expect(res).toHaveLength(3);
_.each(res, function(filter) {
- expect(filter.$state && filter.$state.store).toBe(esFilters.FilterStateStore.GLOBAL_STATE);
+ expect(filter.$state && filter.$state.store).toBe(FilterStateStore.GLOBAL_STATE);
});
});
@@ -530,7 +512,7 @@ describe('filter_manager', () => {
});
test('should de-dupe global filters being set', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
const f2 = _.cloneDeep(f1);
filterManager.setFilters([f1, f2]);
expect(filterManager.getAppFilters()).toHaveLength(0);
@@ -539,7 +521,7 @@ describe('filter_manager', () => {
});
test('should de-dupe app filters being set', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'age', 34);
+ const f1 = getFilter(FilterStateStore.APP_STATE, false, false, 'age', 34);
const f2 = _.cloneDeep(f1);
filterManager.setFilters([f1, f2]);
expect(filterManager.getAppFilters()).toHaveLength(1);
@@ -554,7 +536,7 @@ describe('filter_manager', () => {
const appFilter = _.cloneDeep(readyFilters[idx]);
appFilter.meta.negate = true;
appFilter.$state = {
- store: esFilters.FilterStateStore.APP_STATE,
+ store: FilterStateStore.APP_STATE,
};
filterManager.addFilters(appFilter);
const res = filterManager.getFilters();
@@ -571,7 +553,7 @@ describe('filter_manager', () => {
const appFilter = _.cloneDeep(readyFilters[1]);
appFilter.meta.negate = true;
appFilter.$state = {
- store: esFilters.FilterStateStore.APP_STATE,
+ store: FilterStateStore.APP_STATE,
};
filterManager.addFilters(appFilter, false);
@@ -580,7 +562,7 @@ describe('filter_manager', () => {
expect(res).toHaveLength(3);
expect(
res.filter(function(filter) {
- return filter.$state && filter.$state.store === esFilters.FilterStateStore.GLOBAL_STATE;
+ return filter.$state && filter.$state.store === FilterStateStore.GLOBAL_STATE;
}).length
).toBe(3);
});
@@ -633,8 +615,8 @@ describe('filter_manager', () => {
});
test('remove on full should clean and fire events', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
- const f2 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'gender', 'FEMALE');
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
+ const f2 = getFilter(FilterStateStore.APP_STATE, false, false, 'gender', 'FEMALE');
filterManager.setFilters([f1, f2]);
updateSubscription = filterManager.getUpdates$().subscribe(updateListener);
@@ -644,9 +626,9 @@ describe('filter_manager', () => {
});
test('remove non existing filter should do nothing and not fire events', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
- const f2 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'gender', 'FEMALE');
- const f3 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'country', 'US');
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
+ const f2 = getFilter(FilterStateStore.APP_STATE, false, false, 'gender', 'FEMALE');
+ const f3 = getFilter(FilterStateStore.APP_STATE, false, false, 'country', 'US');
filterManager.setFilters([f1, f2]);
expect(filterManager.getFilters()).toHaveLength(2);
@@ -657,9 +639,9 @@ describe('filter_manager', () => {
});
test('remove existing filter should remove and fire events', async () => {
- const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
- const f2 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'gender', 'FEMALE');
- const f3 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'country', 'US');
+ const f1 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'age', 34);
+ const f2 = getFilter(FilterStateStore.APP_STATE, false, false, 'gender', 'FEMALE');
+ const f3 = getFilter(FilterStateStore.APP_STATE, false, false, 'country', 'US');
filterManager.setFilters([f1, f2, f3]);
expect(filterManager.getFilters()).toHaveLength(3);
diff --git a/src/plugins/data/public/query/filter_manager/filter_manager.ts b/src/plugins/data/public/query/filter_manager/filter_manager.ts
index aa77f10d89f63..c951953b26555 100644
--- a/src/plugins/data/public/query/filter_manager/filter_manager.ts
+++ b/src/plugins/data/public/query/filter_manager/filter_manager.ts
@@ -28,10 +28,10 @@ import { mapAndFlattenFilters } from './lib/map_and_flatten_filters';
import { uniqFilters } from './lib/uniq_filters';
import { onlyDisabledFiltersChanged } from './lib/only_disabled';
import { PartitionedFilters } from './types';
-import { esFilters } from '../../../common';
+import { FilterStateStore, Filter, isFilterPinned } from '../../../common';
export class FilterManager {
- private filters: esFilters.Filter[] = [];
+ private filters: Filter[] = [];
private updated$: Subject = new Subject();
private fetch$: Subject = new Subject();
private uiSettings: IUiSettingsClient;
@@ -40,13 +40,13 @@ export class FilterManager {
this.uiSettings = uiSettings;
}
- private mergeIncomingFilters(partitionedFilters: PartitionedFilters): esFilters.Filter[] {
+ private mergeIncomingFilters(partitionedFilters: PartitionedFilters): Filter[] {
const globalFilters = partitionedFilters.globalFilters;
const appFilters = partitionedFilters.appFilters;
// existing globalFilters should be mutated by appFilters
// ignore original appFilters which are already inside globalFilters
- const cleanedAppFilters: esFilters.Filter[] = [];
+ const cleanedAppFilters: Filter[] = [];
_.each(appFilters, function(filter, i) {
const match = _.find(globalFilters, function(globalFilter) {
return compareFilters(globalFilter, filter);
@@ -64,22 +64,19 @@ export class FilterManager {
return FilterManager.mergeFilters(cleanedAppFilters, globalFilters);
}
- private static mergeFilters(
- appFilters: esFilters.Filter[],
- globalFilters: esFilters.Filter[]
- ): esFilters.Filter[] {
+ private static mergeFilters(appFilters: Filter[], globalFilters: Filter[]): Filter[] {
return uniqFilters(appFilters.reverse().concat(globalFilters.reverse())).reverse();
}
- private static partitionFilters(filters: esFilters.Filter[]): PartitionedFilters {
- const [globalFilters, appFilters] = _.partition(filters, esFilters.isFilterPinned);
+ private static partitionFilters(filters: Filter[]): PartitionedFilters {
+ const [globalFilters, appFilters] = _.partition(filters, isFilterPinned);
return {
globalFilters,
appFilters,
};
}
- private handleStateUpdate(newFilters: esFilters.Filter[]) {
+ private handleStateUpdate(newFilters: Filter[]) {
newFilters.sort(sortFilters);
const filtersUpdated = !compareFilters(this.filters, newFilters, COMPARE_ALL_OPTIONS);
@@ -125,7 +122,7 @@ export class FilterManager {
/* Setters */
public addFilters(
- filters: esFilters.Filter[] | esFilters.Filter,
+ filters: Filter[] | Filter,
pinFilterStatus: boolean = this.uiSettings.get('filters:pinnedByDefault')
) {
if (!Array.isArray(filters)) {
@@ -136,9 +133,7 @@ export class FilterManager {
return;
}
- const store = pinFilterStatus
- ? esFilters.FilterStateStore.GLOBAL_STATE
- : esFilters.FilterStateStore.APP_STATE;
+ const store = pinFilterStatus ? FilterStateStore.GLOBAL_STATE : FilterStateStore.APP_STATE;
FilterManager.setFiltersStore(filters, store);
@@ -155,12 +150,10 @@ export class FilterManager {
}
public setFilters(
- newFilters: esFilters.Filter[],
+ newFilters: Filter[],
pinFilterStatus: boolean = this.uiSettings.get('filters:pinnedByDefault')
) {
- const store = pinFilterStatus
- ? esFilters.FilterStateStore.GLOBAL_STATE
- : esFilters.FilterStateStore.APP_STATE;
+ const store = pinFilterStatus ? FilterStateStore.GLOBAL_STATE : FilterStateStore.APP_STATE;
FilterManager.setFiltersStore(newFilters, store);
@@ -175,9 +168,9 @@ export class FilterManager {
* Removes app filters for which there is a duplicate within new global filters
* @param newGlobalFilters
*/
- public setGlobalFilters(newGlobalFilters: esFilters.Filter[]) {
+ public setGlobalFilters(newGlobalFilters: Filter[]) {
newGlobalFilters = mapAndFlattenFilters(newGlobalFilters);
- FilterManager.setFiltersStore(newGlobalFilters, esFilters.FilterStateStore.GLOBAL_STATE, true);
+ FilterManager.setFiltersStore(newGlobalFilters, FilterStateStore.GLOBAL_STATE, true);
const { appFilters: currentAppFilters } = this.getPartitionedFilters();
// remove duplicates from current app filters, to make sure global will take precedence
const filteredAppFilters = currentAppFilters.filter(
@@ -196,9 +189,9 @@ export class FilterManager {
* Removes app filters for which there is a duplicate within new global filters
* @param newAppFilters
*/
- public setAppFilters(newAppFilters: esFilters.Filter[]) {
+ public setAppFilters(newAppFilters: Filter[]) {
newAppFilters = mapAndFlattenFilters(newAppFilters);
- FilterManager.setFiltersStore(newAppFilters, esFilters.FilterStateStore.APP_STATE, true);
+ FilterManager.setFiltersStore(newAppFilters, FilterStateStore.APP_STATE, true);
const { globalFilters: currentGlobalFilters } = this.getPartitionedFilters();
// remove duplicates from current global filters, to make sure app will take precedence
const filteredGlobalFilters = currentGlobalFilters.filter(
@@ -212,7 +205,7 @@ export class FilterManager {
this.handleStateUpdate(newFilters);
}
- public removeFilter(filter: esFilters.Filter) {
+ public removeFilter(filter: Filter) {
const filterIndex = _.findIndex(this.filters, item => {
return _.isEqual(item.meta, filter.meta) && _.isEqual(item.query, filter.query);
});
@@ -229,11 +222,11 @@ export class FilterManager {
}
public static setFiltersStore(
- filters: esFilters.Filter[],
- store: esFilters.FilterStateStore,
+ filters: Filter[],
+ store: FilterStateStore,
shouldOverrideStore = false
) {
- _.map(filters, (filter: esFilters.Filter) => {
+ _.map(filters, (filter: Filter) => {
// Override status only for filters that didn't have state in the first place.
// or if shouldOverrideStore is explicitly true
if (shouldOverrideStore || filter.$state === undefined) {
diff --git a/src/plugins/data/public/query/filter_manager/lib/compare_filters.test.ts b/src/plugins/data/public/query/filter_manager/lib/compare_filters.test.ts
index 9cc5938750c4e..e7e947c49d0e4 100644
--- a/src/plugins/data/public/query/filter_manager/lib/compare_filters.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/compare_filters.test.ts
@@ -18,28 +18,28 @@
*/
import { compareFilters, COMPARE_ALL_OPTIONS } from './compare_filters';
-import { esFilters } from '../../../../common';
+import { buildEmptyFilter, buildQueryFilter, FilterStateStore } from '../../../../common';
describe('filter manager utilities', () => {
describe('compare filters', () => {
test('should compare filters', () => {
- const f1 = esFilters.buildQueryFilter(
+ const f1 = buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index',
''
);
- const f2 = esFilters.buildEmptyFilter(true);
+ const f2 = buildEmptyFilter(true);
expect(compareFilters(f1, f2)).toBeFalsy();
});
test('should compare duplicates', () => {
- const f1 = esFilters.buildQueryFilter(
+ const f1 = buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index',
''
);
- const f2 = esFilters.buildQueryFilter(
+ const f2 = buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index',
''
@@ -49,12 +49,12 @@ describe('filter manager utilities', () => {
});
test('should compare duplicates, ignoring meta attributes', () => {
- const f1 = esFilters.buildQueryFilter(
+ const f1 = buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index1',
''
);
- const f2 = esFilters.buildQueryFilter(
+ const f2 = buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index2',
''
@@ -65,33 +65,25 @@ describe('filter manager utilities', () => {
test('should compare duplicates, ignoring $state attributes', () => {
const f1 = {
- $state: { store: esFilters.FilterStateStore.APP_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.APP_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const f2 = {
- $state: { store: esFilters.FilterStateStore.GLOBAL_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.GLOBAL_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
expect(compareFilters(f1, f2)).toBeTruthy();
});
test('should compare filters array to non array', () => {
- const f1 = esFilters.buildQueryFilter(
+ const f1 = buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index',
''
);
- const f2 = esFilters.buildQueryFilter(
+ const f2 = buildQueryFilter(
{ _type: { match: { query: 'mochi', type: 'phrase' } } },
'index',
''
@@ -101,13 +93,13 @@ describe('filter manager utilities', () => {
});
test('should compare filters array to partial array', () => {
- const f1 = esFilters.buildQueryFilter(
+ const f1 = buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index',
''
);
- const f2 = esFilters.buildQueryFilter(
+ const f2 = buildQueryFilter(
{ _type: { match: { query: 'mochi', type: 'phrase' } } },
'index',
''
@@ -117,13 +109,13 @@ describe('filter manager utilities', () => {
});
test('should compare filters array to exact array', () => {
- const f1 = esFilters.buildQueryFilter(
+ const f1 = buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index',
''
);
- const f2 = esFilters.buildQueryFilter(
+ const f2 = buildQueryFilter(
{ _type: { match: { query: 'mochi', type: 'phrase' } } },
'index',
''
@@ -133,12 +125,12 @@ describe('filter manager utilities', () => {
});
test('should compare array of duplicates, ignoring meta attributes', () => {
- const f1 = esFilters.buildQueryFilter(
+ const f1 = buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index1',
''
);
- const f2 = esFilters.buildQueryFilter(
+ const f2 = buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index2',
''
@@ -149,20 +141,12 @@ describe('filter manager utilities', () => {
test('should compare array of duplicates, ignoring $state attributes', () => {
const f1 = {
- $state: { store: esFilters.FilterStateStore.APP_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.APP_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const f2 = {
- $state: { store: esFilters.FilterStateStore.GLOBAL_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.GLOBAL_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
expect(compareFilters([f1], [f2])).toBeTruthy();
@@ -170,20 +154,12 @@ describe('filter manager utilities', () => {
test('should compare duplicates with COMPARE_ALL_OPTIONS should check store', () => {
const f1 = {
- $state: { store: esFilters.FilterStateStore.APP_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.APP_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const f2 = {
- $state: { store: esFilters.FilterStateStore.GLOBAL_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.GLOBAL_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
expect(compareFilters([f1], [f2], COMPARE_ALL_OPTIONS)).toBeFalsy();
@@ -191,20 +167,12 @@ describe('filter manager utilities', () => {
test('should compare duplicates with COMPARE_ALL_OPTIONS should not check key and value ', () => {
const f1 = {
- $state: { store: esFilters.FilterStateStore.GLOBAL_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.GLOBAL_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const f2 = {
- $state: { store: esFilters.FilterStateStore.GLOBAL_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.GLOBAL_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
f2.meta.key = 'wassup';
diff --git a/src/plugins/data/public/query/filter_manager/lib/compare_filters.ts b/src/plugins/data/public/query/filter_manager/lib/compare_filters.ts
index 218b9d492b61f..cd4a966184f83 100644
--- a/src/plugins/data/public/query/filter_manager/lib/compare_filters.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/compare_filters.ts
@@ -18,7 +18,7 @@
*/
import { defaults, isEqual, omit, map } from 'lodash';
-import { esFilters } from '../../../../common';
+import { FilterMeta, Filter } from '../../../../common';
export interface FilterCompareOptions {
disabled?: boolean;
@@ -36,11 +36,11 @@ export const COMPARE_ALL_OPTIONS: FilterCompareOptions = {
};
const mapFilter = (
- filter: esFilters.Filter,
+ filter: Filter,
comparators: FilterCompareOptions,
excludedAttributes: string[]
) => {
- const cleaned: esFilters.FilterMeta = omit(filter, excludedAttributes);
+ const cleaned: FilterMeta = omit(filter, excludedAttributes);
if (comparators.negate) cleaned.negate = filter.meta && Boolean(filter.meta.negate);
if (comparators.disabled) cleaned.disabled = filter.meta && Boolean(filter.meta.disabled);
@@ -49,28 +49,26 @@ const mapFilter = (
};
const mapFilterArray = (
- filters: esFilters.Filter[],
+ filters: Filter[],
comparators: FilterCompareOptions,
excludedAttributes: string[]
) => {
- return map(filters, (filter: esFilters.Filter) =>
- mapFilter(filter, comparators, excludedAttributes)
- );
+ return map(filters, (filter: Filter) => mapFilter(filter, comparators, excludedAttributes));
};
/**
* Compare two filters or filter arrays to see if they match.
* For filter arrays, the assumption is they are sorted.
*
- * @param {esFilters.Filter | esFilters.Filter[]} first The first filter or filter array to compare
- * @param {esFilters.Filter | esFilters.Filter[]} second The second filter or filter array to compare
+ * @param {Filter | Filter[]} first The first filter or filter array to compare
+ * @param {Filter | Filter[]} second The second filter or filter array to compare
* @param {FilterCompareOptions} comparatorOptions Parameters to use for comparison
*
* @returns {bool} Filters are the same
*/
export const compareFilters = (
- first: esFilters.Filter | esFilters.Filter[],
- second: esFilters.Filter | esFilters.Filter[],
+ first: Filter | Filter[],
+ second: Filter | Filter[],
comparatorOptions: FilterCompareOptions = {}
) => {
let comparators: FilterCompareOptions = {};
diff --git a/src/plugins/data/public/query/filter_manager/lib/dedup_filters.test.ts b/src/plugins/data/public/query/filter_manager/lib/dedup_filters.test.ts
index ebad5ad6b02c5..ecc0ec94e07c8 100644
--- a/src/plugins/data/public/query/filter_manager/lib/dedup_filters.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/dedup_filters.test.ts
@@ -18,7 +18,14 @@
*/
import { dedupFilters } from './dedup_filters';
-import { esFilters, IIndexPattern, IFieldType } from '../../../../common';
+import {
+ Filter,
+ IIndexPattern,
+ IFieldType,
+ buildRangeFilter,
+ buildQueryFilter,
+ FilterStateStore,
+} from '../../../../common';
describe('filter manager utilities', () => {
let indexPattern: IIndexPattern;
@@ -31,31 +38,18 @@ describe('filter manager utilities', () => {
describe('dedupFilters(existing, filters)', () => {
test('should return only filters which are not in the existing', () => {
- const existing: esFilters.Filter[] = [
- esFilters.buildRangeFilter(
- { name: 'bytes' } as IFieldType,
- { from: 0, to: 1024 },
- indexPattern,
- ''
- ),
- esFilters.buildQueryFilter(
- { match: { _term: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ const existing: Filter[] = [
+ buildRangeFilter({ name: 'bytes' } as IFieldType, { from: 0, to: 1024 }, indexPattern, ''),
+ buildQueryFilter({ match: { _term: { query: 'apache', type: 'phrase' } } }, 'index', ''),
];
- const filters: esFilters.Filter[] = [
- esFilters.buildRangeFilter(
+ const filters: Filter[] = [
+ buildRangeFilter(
{ name: 'bytes' } as IFieldType,
{ from: 1024, to: 2048 },
indexPattern,
''
),
- esFilters.buildQueryFilter(
- { match: { _term: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ buildQueryFilter({ match: { _term: { query: 'apache', type: 'phrase' } } }, 'index', ''),
];
const results = dedupFilters(existing, filters);
@@ -64,15 +58,10 @@ describe('filter manager utilities', () => {
});
test('should ignore the disabled attribute when comparing ', () => {
- const existing: esFilters.Filter[] = [
- esFilters.buildRangeFilter(
- { name: 'bytes' } as IFieldType,
- { from: 0, to: 1024 },
- indexPattern,
- ''
- ),
+ const existing: Filter[] = [
+ buildRangeFilter({ name: 'bytes' } as IFieldType, { from: 0, to: 1024 }, indexPattern, ''),
{
- ...esFilters.buildQueryFilter(
+ ...buildQueryFilter(
{ match: { _term: { query: 'apache', type: 'phrase' } } },
'index1',
''
@@ -80,18 +69,14 @@ describe('filter manager utilities', () => {
meta: { disabled: true, negate: false, alias: null },
},
];
- const filters: esFilters.Filter[] = [
- esFilters.buildRangeFilter(
+ const filters: Filter[] = [
+ buildRangeFilter(
{ name: 'bytes' } as IFieldType,
{ from: 1024, to: 2048 },
indexPattern,
''
),
- esFilters.buildQueryFilter(
- { match: { _term: { query: 'apache', type: 'phrase' } } },
- 'index1',
- ''
- ),
+ buildQueryFilter({ match: { _term: { query: 'apache', type: 'phrase' } } }, 'index1', ''),
];
const results = dedupFilters(existing, filters);
@@ -100,36 +85,31 @@ describe('filter manager utilities', () => {
});
test('should ignore $state attribute', () => {
- const existing: esFilters.Filter[] = [
- esFilters.buildRangeFilter(
- { name: 'bytes' } as IFieldType,
- { from: 0, to: 1024 },
- indexPattern,
- ''
- ),
+ const existing: Filter[] = [
+ buildRangeFilter({ name: 'bytes' } as IFieldType, { from: 0, to: 1024 }, indexPattern, ''),
{
- ...esFilters.buildQueryFilter(
+ ...buildQueryFilter(
{ match: { _term: { query: 'apache', type: 'phrase' } } },
'index',
''
),
- $state: { store: esFilters.FilterStateStore.APP_STATE },
+ $state: { store: FilterStateStore.APP_STATE },
},
];
- const filters: esFilters.Filter[] = [
- esFilters.buildRangeFilter(
+ const filters: Filter[] = [
+ buildRangeFilter(
{ name: 'bytes' } as IFieldType,
{ from: 1024, to: 2048 },
indexPattern,
''
),
{
- ...esFilters.buildQueryFilter(
+ ...buildQueryFilter(
{ match: { _term: { query: 'apache', type: 'phrase' } } },
'index',
''
),
- $state: { store: esFilters.FilterStateStore.GLOBAL_STATE },
+ $state: { store: FilterStateStore.GLOBAL_STATE },
},
];
const results = dedupFilters(existing, filters);
diff --git a/src/plugins/data/public/query/filter_manager/lib/dedup_filters.ts b/src/plugins/data/public/query/filter_manager/lib/dedup_filters.ts
index 897a645e87b5a..d5d0e70504b41 100644
--- a/src/plugins/data/public/query/filter_manager/lib/dedup_filters.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/dedup_filters.ts
@@ -19,7 +19,7 @@
import { filter, find } from 'lodash';
import { compareFilters, FilterCompareOptions } from './compare_filters';
-import { esFilters } from '../../../../common';
+import { Filter } from '../../../../common';
/**
* Combine 2 filter collections, removing duplicates
@@ -31,8 +31,8 @@ import { esFilters } from '../../../../common';
* @returns {object} An array of filters that were not in existing
*/
export const dedupFilters = (
- existingFilters: esFilters.Filter[],
- filters: esFilters.Filter[],
+ existingFilters: Filter[],
+ filters: Filter[],
comparatorOptions: FilterCompareOptions = {}
) => {
if (!Array.isArray(filters)) {
@@ -41,8 +41,8 @@ export const dedupFilters = (
return filter(
filters,
- (f: esFilters.Filter) =>
- !find(existingFilters, (existingFilter: esFilters.Filter) =>
+ (f: Filter) =>
+ !find(existingFilters, (existingFilter: Filter) =>
compareFilters(existingFilter, f, comparatorOptions)
)
);
diff --git a/src/plugins/data/public/query/filter_manager/lib/generate_filter.test.ts b/src/plugins/data/public/query/filter_manager/lib/generate_filter.test.ts
index b8de08fc3a610..659f28e3ce9cc 100644
--- a/src/plugins/data/public/query/filter_manager/lib/generate_filter.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/generate_filter.test.ts
@@ -20,7 +20,15 @@
import { generateFilters } from './generate_filters';
import { FilterManager } from '../filter_manager';
-import { esFilters, IFieldType, IIndexPattern } from '../../../../common';
+import {
+ Filter,
+ IFieldType,
+ IIndexPattern,
+ isExistsFilter,
+ buildExistsFilter,
+ PhraseFilter,
+ isPhraseFilter,
+} from '../../../../common';
const INDEX_NAME = 'my-index';
const EXISTS_FIELD_NAME = '_exists_';
@@ -31,7 +39,7 @@ const PHRASE_VALUE = 'my-value';
describe('Generate filters', () => {
let mockFilterManager: FilterManager;
- let filtersArray: esFilters.Filter[];
+ let filtersArray: Filter[];
beforeEach(() => {
filtersArray = [];
@@ -53,7 +61,7 @@ describe('Generate filters', () => {
expect(filters).toHaveLength(1);
expect(filters[0].meta.index === INDEX_NAME);
expect(filters[0].meta.negate).toBeFalsy();
- expect(esFilters.isExistsFilter(filters[0])).toBeTruthy();
+ expect(isExistsFilter(filters[0])).toBeTruthy();
});
it('should create negated exists filter', () => {
@@ -67,11 +75,11 @@ describe('Generate filters', () => {
expect(filters).toHaveLength(1);
expect(filters[0].meta.index === INDEX_NAME);
expect(filters[0].meta.negate).toBeTruthy();
- expect(esFilters.isExistsFilter(filters[0])).toBeTruthy();
+ expect(isExistsFilter(filters[0])).toBeTruthy();
});
it('should update and re-enable EXISTING exists filter', () => {
- const filter = esFilters.buildExistsFilter(FIELD, { id: INDEX_NAME } as IIndexPattern);
+ const filter = buildExistsFilter(FIELD, { id: INDEX_NAME } as IIndexPattern);
filter.meta.disabled = true;
filtersArray.push(filter);
@@ -80,7 +88,7 @@ describe('Generate filters', () => {
expect(filters[0].meta.index === INDEX_NAME);
expect(filters[0].meta.negate).toBeTruthy();
expect(filters[0].meta.disabled).toBeFalsy();
- expect(esFilters.isExistsFilter(filters[0])).toBeTruthy();
+ expect(isExistsFilter(filters[0])).toBeTruthy();
});
it('should create phrase filter', () => {
@@ -88,8 +96,8 @@ describe('Generate filters', () => {
expect(filters).toHaveLength(1);
expect(filters[0].meta.index === INDEX_NAME);
expect(filters[0].meta.negate).toBeFalsy();
- expect(esFilters.isPhraseFilter(filters[0])).toBeTruthy();
- expect((filters[0] as esFilters.PhraseFilter).query.match_phrase).toEqual({
+ expect(isPhraseFilter(filters[0])).toBeTruthy();
+ expect((filters[0] as PhraseFilter).query.match_phrase).toEqual({
[FIELD.name]: PHRASE_VALUE,
});
});
@@ -99,8 +107,8 @@ describe('Generate filters', () => {
expect(filters).toHaveLength(1);
expect(filters[0].meta.index === INDEX_NAME);
expect(filters[0].meta.negate).toBeTruthy();
- expect(esFilters.isPhraseFilter(filters[0])).toBeTruthy();
- expect((filters[0] as esFilters.PhraseFilter).query.match_phrase).toEqual({
+ expect(isPhraseFilter(filters[0])).toBeTruthy();
+ expect((filters[0] as PhraseFilter).query.match_phrase).toEqual({
[FIELD.name]: PHRASE_VALUE,
});
});
@@ -119,12 +127,12 @@ describe('Generate filters', () => {
expect(filters[0].meta.negate).toBeFalsy();
expect(filters[1].meta.index === INDEX_NAME);
expect(filters[1].meta.negate).toBeFalsy();
- expect(esFilters.isPhraseFilter(filters[0])).toBeTruthy();
- expect(esFilters.isPhraseFilter(filters[1])).toBeTruthy();
- expect((filters[0] as esFilters.PhraseFilter).query.match_phrase).toEqual({
+ expect(isPhraseFilter(filters[0])).toBeTruthy();
+ expect(isPhraseFilter(filters[1])).toBeTruthy();
+ expect((filters[0] as PhraseFilter).query.match_phrase).toEqual({
[FIELD.name]: PHRASE_VALUE,
});
- expect((filters[1] as esFilters.PhraseFilter).query.match_phrase).toEqual({
+ expect((filters[1] as PhraseFilter).query.match_phrase).toEqual({
[FIELD.name]: ANOTHER_PHRASE,
});
});
diff --git a/src/plugins/data/public/query/filter_manager/lib/generate_filters.ts b/src/plugins/data/public/query/filter_manager/lib/generate_filters.ts
index b4d46ae9fb3cf..105e932f696f0 100644
--- a/src/plugins/data/public/query/filter_manager/lib/generate_filters.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/generate_filters.ts
@@ -18,36 +18,45 @@
*/
import _ from 'lodash';
-import { esFilters, IFieldType, IIndexPattern } from '../../../../common';
+import {
+ IFieldType,
+ IIndexPattern,
+ Filter,
+ isExistsFilter,
+ isPhraseFilter,
+ getPhraseFilterValue,
+ getPhraseFilterField,
+ isScriptedPhraseFilter,
+ buildFilter,
+ FilterStateStore,
+ FILTERS,
+} from '../../../../common';
import { FilterManager } from '../filter_manager';
function getExistingFilter(
- appFilters: esFilters.Filter[],
+ appFilters: Filter[],
fieldName: string,
value: any
-): esFilters.Filter | undefined {
+): Filter | undefined {
// TODO: On array fields, negating does not negate the combination, rather all terms
return _.find(appFilters, function(filter) {
if (!filter) return;
- if (fieldName === '_exists_' && esFilters.isExistsFilter(filter)) {
+ if (fieldName === '_exists_' && isExistsFilter(filter)) {
return filter.exists!.field === value;
}
- if (esFilters.isPhraseFilter(filter)) {
- return (
- esFilters.getPhraseFilterField(filter) === fieldName &&
- esFilters.getPhraseFilterValue(filter) === value
- );
+ if (isPhraseFilter(filter)) {
+ return getPhraseFilterField(filter) === fieldName && getPhraseFilterValue(filter) === value;
}
- if (esFilters.isScriptedPhraseFilter(filter)) {
+ if (isScriptedPhraseFilter(filter)) {
return filter.meta.field === fieldName && filter.script!.script.params.value === value;
}
});
}
-function updateExistingFilter(existingFilter: esFilters.Filter, negate: boolean) {
+function updateExistingFilter(existingFilter: Filter, negate: boolean) {
existingFilter.meta.disabled = false;
if (existingFilter.meta.negate !== negate) {
existingFilter.meta.negate = !existingFilter.meta.negate;
@@ -72,7 +81,7 @@ export function generateFilters(
values: any,
operation: string,
index: string
-): esFilters.Filter[] {
+): Filter[] {
values = Array.isArray(values) ? values : [values];
const fieldObj = (_.isObject(field)
? field
@@ -80,7 +89,7 @@ export function generateFilters(
name: field,
}) as IFieldType;
const fieldName = fieldObj.name;
- const newFilters: esFilters.Filter[] = [];
+ const newFilters: Filter[] = [];
const appFilters = filterManager.getAppFilters();
const negate = operation === '-';
@@ -95,9 +104,8 @@ export function generateFilters(
} else {
const tmpIndexPattern = { id: index } as IIndexPattern;
- const filterType =
- fieldName === '_exists_' ? esFilters.FILTERS.EXISTS : esFilters.FILTERS.PHRASE;
- filter = esFilters.buildFilter(
+ const filterType = fieldName === '_exists_' ? FILTERS.EXISTS : FILTERS.PHRASE;
+ filter = buildFilter(
tmpIndexPattern,
fieldObj,
filterType,
@@ -105,7 +113,7 @@ export function generateFilters(
false,
value,
null,
- esFilters.FilterStateStore.APP_STATE
+ FilterStateStore.APP_STATE
);
}
diff --git a/src/plugins/data/public/query/filter_manager/lib/generate_mapping_chain.test.ts b/src/plugins/data/public/query/filter_manager/lib/generate_mapping_chain.test.ts
index 9e386bdc7c80d..8322e79dd67d1 100644
--- a/src/plugins/data/public/query/filter_manager/lib/generate_mapping_chain.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/generate_mapping_chain.test.ts
@@ -19,7 +19,7 @@
import sinon from 'sinon';
import { generateMappingChain } from './generate_mapping_chain';
-import { esFilters } from '../../../../common';
+import { buildEmptyFilter } from '../../../../common';
describe('filter manager utilities', () => {
let mapping: any;
@@ -32,7 +32,7 @@ describe('filter manager utilities', () => {
describe('generateMappingChain()', () => {
test('should create a chaining function which calls the next function if the error is thrown', async () => {
- const filter = esFilters.buildEmptyFilter(true);
+ const filter = buildEmptyFilter(true);
mapping.throws(filter);
next.returns('good');
@@ -45,7 +45,7 @@ describe('filter manager utilities', () => {
});
test('should create a chaining function which DOES NOT call the next function if the result is returned', async () => {
- const filter = esFilters.buildEmptyFilter(true);
+ const filter = buildEmptyFilter(true);
mapping.returns('good');
next.returns('bad');
@@ -57,7 +57,7 @@ describe('filter manager utilities', () => {
});
test('should resolve result for the mapping function', async () => {
- const filter = esFilters.buildEmptyFilter(true);
+ const filter = buildEmptyFilter(true);
mapping.returns({ key: 'test', value: 'example' });
@@ -70,7 +70,7 @@ describe('filter manager utilities', () => {
test('should call the mapping function with the argument to the chain', async () => {
// @ts-ignore
- const filter: esFilters.Filter = { test: 'example' };
+ const filter: Filter = { test: 'example' };
mapping.returns({ key: 'test', value: 'example' });
@@ -84,7 +84,7 @@ describe('filter manager utilities', () => {
});
test('should resolve result for the next function', async () => {
- const filter = esFilters.buildEmptyFilter(true);
+ const filter = buildEmptyFilter(true);
mapping.throws(filter);
next.returns({ key: 'test', value: 'example' });
@@ -98,7 +98,7 @@ describe('filter manager utilities', () => {
});
test('should throw an error if no functions match', async done => {
- const filter = esFilters.buildEmptyFilter(true);
+ const filter = buildEmptyFilter(true);
mapping.throws(filter);
diff --git a/src/plugins/data/public/query/filter_manager/lib/generate_mapping_chain.ts b/src/plugins/data/public/query/filter_manager/lib/generate_mapping_chain.ts
index 1af8482a96e0f..ce805cd8893b5 100644
--- a/src/plugins/data/public/query/filter_manager/lib/generate_mapping_chain.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/generate_mapping_chain.ts
@@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-import { esFilters } from '../../../../common';
+import { Filter } from '../../../../common';
const noop = () => {
throw new Error('No mappings have been found for filter.');
};
export const generateMappingChain = (fn: Function, next: Function = noop) => {
- return (filter: esFilters.Filter) => {
+ return (filter: Filter) => {
try {
return fn(filter);
} catch (result) {
diff --git a/src/plugins/data/public/query/filter_manager/lib/map_and_flatten_filters.test.ts b/src/plugins/data/public/query/filter_manager/lib/map_and_flatten_filters.test.ts
index 3190b6777a9e1..1b2d476570902 100644
--- a/src/plugins/data/public/query/filter_manager/lib/map_and_flatten_filters.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/map_and_flatten_filters.test.ts
@@ -18,13 +18,13 @@
*/
import { mapAndFlattenFilters } from './map_and_flatten_filters';
-import { esFilters } from '../../../../common';
+import { Filter } from '../../../../common';
describe('filter manager utilities', () => {
describe('mapAndFlattenFilters()', () => {
let filters: unknown;
- function getDisplayName(filter: esFilters.Filter) {
+ function getDisplayName(filter: Filter) {
return typeof filter.meta.value === 'function' ? filter.meta.value() : filter.meta.value;
}
@@ -45,7 +45,7 @@ describe('filter manager utilities', () => {
});
test('should map and flatten the filters', () => {
- const results = mapAndFlattenFilters(filters as esFilters.Filter[]);
+ const results = mapAndFlattenFilters(filters as Filter[]);
expect(results).toHaveLength(5);
expect(results[0]).toHaveProperty('meta');
diff --git a/src/plugins/data/public/query/filter_manager/lib/map_and_flatten_filters.ts b/src/plugins/data/public/query/filter_manager/lib/map_and_flatten_filters.ts
index 28b5e8d151ff6..13c99e1655d4c 100644
--- a/src/plugins/data/public/query/filter_manager/lib/map_and_flatten_filters.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/map_and_flatten_filters.ts
@@ -19,8 +19,8 @@
import { compact, flatten } from 'lodash';
import { mapFilter } from './map_filter';
-import { esFilters } from '../../../../common';
+import { Filter } from '../../../../common';
-export const mapAndFlattenFilters = (filters: esFilters.Filter[]) => {
- return compact(flatten(filters)).map((item: esFilters.Filter) => mapFilter(item));
+export const mapAndFlattenFilters = (filters: Filter[]) => {
+ return compact(flatten(filters)).map((item: Filter) => mapFilter(item));
};
diff --git a/src/plugins/data/public/query/filter_manager/lib/map_filter.test.ts b/src/plugins/data/public/query/filter_manager/lib/map_filter.test.ts
index 9df07718d5bcb..f75970d4dec18 100644
--- a/src/plugins/data/public/query/filter_manager/lib/map_filter.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/map_filter.test.ts
@@ -18,10 +18,10 @@
*/
import { mapFilter } from './map_filter';
-import { esFilters } from '../../../../common';
+import { Filter } from '../../../../common';
describe('filter manager utilities', () => {
- function getDisplayName(filter: esFilters.Filter) {
+ function getDisplayName(filter: Filter) {
return typeof filter.meta.value === 'function' ? filter.meta.value() : filter.meta.value;
}
@@ -31,7 +31,7 @@ describe('filter manager utilities', () => {
meta: { index: 'logstash-*' },
query: { match: { _type: { query: 'apache', type: 'phrase' } } },
};
- const after = mapFilter(before as esFilters.Filter);
+ const after = mapFilter(before as Filter);
expect(after).toHaveProperty('meta');
expect(after.meta).toHaveProperty('key', '_type');
@@ -43,7 +43,7 @@ describe('filter manager utilities', () => {
test('should map exists filters', async () => {
const before: any = { meta: { index: 'logstash-*' }, exists: { field: '@timestamp' } };
- const after = mapFilter(before as esFilters.Filter);
+ const after = mapFilter(before as Filter);
expect(after).toHaveProperty('meta');
expect(after.meta).toHaveProperty('key', '@timestamp');
@@ -55,7 +55,7 @@ describe('filter manager utilities', () => {
test('should map missing filters', async () => {
const before: any = { meta: { index: 'logstash-*' }, missing: { field: '@timestamp' } };
- const after = mapFilter(before as esFilters.Filter);
+ const after = mapFilter(before as Filter);
expect(after).toHaveProperty('meta');
expect(after.meta).toHaveProperty('key', '@timestamp');
@@ -67,7 +67,7 @@ describe('filter manager utilities', () => {
test('should map json filter', async () => {
const before: any = { meta: { index: 'logstash-*' }, query: { match_all: {} } };
- const after = mapFilter(before as esFilters.Filter);
+ const after = mapFilter(before as Filter);
expect(after).toHaveProperty('meta');
expect(after.meta).toHaveProperty('key', 'query');
@@ -81,7 +81,7 @@ describe('filter manager utilities', () => {
const before: any = { meta: { index: 'logstash-*' } };
try {
- mapFilter(before as esFilters.Filter);
+ mapFilter(before as Filter);
} catch (e) {
expect(e).toBeInstanceOf(Error);
expect(e.message).toBe('No mappings have been found for filter.');
diff --git a/src/plugins/data/public/query/filter_manager/lib/map_filter.ts b/src/plugins/data/public/query/filter_manager/lib/map_filter.ts
index dc3deb93bd27b..7b223a6845559 100644
--- a/src/plugins/data/public/query/filter_manager/lib/map_filter.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/map_filter.ts
@@ -31,9 +31,9 @@ import { mapGeoBoundingBox } from './mappers/map_geo_bounding_box';
import { mapGeoPolygon } from './mappers/map_geo_polygon';
import { mapDefault } from './mappers/map_default';
import { generateMappingChain } from './generate_mapping_chain';
-import { esFilters } from '../../../../common';
+import { Filter } from '../../../../common';
-export function mapFilter(filter: esFilters.Filter) {
+export function mapFilter(filter: Filter) {
/** Mappers **/
// Each mapper is a simple promise function that test if the mapper can
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_default.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_default.test.ts
index f6baaa9218d74..1fdace52e89f5 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_default.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_default.test.ts
@@ -18,12 +18,12 @@
*/
import { mapDefault } from './map_default';
-import { esFilters } from '../../../../../common';
+import { buildQueryFilter, buildEmptyFilter } from '../../../../../common';
describe('filter manager utilities', () => {
describe('mapDefault()', () => {
test('should return the key and value for matching filters', async () => {
- const filter = esFilters.buildQueryFilter({ match_all: {} }, 'index', '');
+ const filter = buildQueryFilter({ match_all: {} }, 'index', '');
const result = mapDefault(filter);
expect(result).toHaveProperty('key', 'query');
@@ -31,7 +31,7 @@ describe('filter manager utilities', () => {
});
test('should return undefined if there is no valid key', async () => {
- const filter = esFilters.buildEmptyFilter(true);
+ const filter = buildEmptyFilter(true);
try {
mapDefault(filter);
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_default.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_default.ts
index 3fee6a063be5a..c90c056f4eb35 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_default.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_default.ts
@@ -18,14 +18,14 @@
*/
import { find, keys, get } from 'lodash';
-import { esFilters } from '../../../../../common';
+import { Filter, FILTERS } from '../../../../../common';
-export const mapDefault = (filter: esFilters.Filter) => {
+export const mapDefault = (filter: Filter) => {
const metaProperty = /(^\$|meta)/;
const key = find(keys(filter), item => !item.match(metaProperty));
if (key) {
- const type = esFilters.FILTERS.CUSTOM;
+ const type = FILTERS.CUSTOM;
const value = JSON.stringify(get(filter, key, {}));
return { type, key, value };
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_exists.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_exists.test.ts
index 2f0ab136bc59f..83c39e449d3ea 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_exists.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_exists.test.ts
@@ -19,7 +19,12 @@
import { mapExists } from './map_exists';
import { mapQueryString } from './map_query_string';
-import { esFilters, IIndexPattern, IFieldType } from '../../../../../common';
+import {
+ IIndexPattern,
+ IFieldType,
+ buildExistsFilter,
+ buildEmptyFilter,
+} from '../../../../../common';
describe('filter manager utilities', () => {
describe('mapExists()', () => {
@@ -32,7 +37,7 @@ describe('filter manager utilities', () => {
});
test('should return the key and value for matching filters', async () => {
- const filter = esFilters.buildExistsFilter({ name: '_type' } as IFieldType, indexPattern);
+ const filter = buildExistsFilter({ name: '_type' } as IFieldType, indexPattern);
const result = mapExists(filter);
expect(result).toHaveProperty('key', '_type');
@@ -40,7 +45,7 @@ describe('filter manager utilities', () => {
});
test('should return undefined for none matching', async done => {
- const filter = esFilters.buildEmptyFilter(true);
+ const filter = buildEmptyFilter(true);
try {
mapQueryString(filter);
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_exists.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_exists.ts
index 38f9b1554c5c8..6555652a37ca8 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_exists.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_exists.ts
@@ -18,13 +18,13 @@
*/
import { get } from 'lodash';
-import { esFilters } from '../../../../../common';
+import { Filter, isExistsFilter, FILTERS } from '../../../../../common';
-export const mapExists = (filter: esFilters.Filter) => {
- if (esFilters.isExistsFilter(filter)) {
+export const mapExists = (filter: Filter) => {
+ if (isExistsFilter(filter)) {
return {
- type: esFilters.FILTERS.EXISTS,
- value: esFilters.FILTERS.EXISTS,
+ type: FILTERS.EXISTS,
+ value: FILTERS.EXISTS,
key: get(filter, 'exists.field'),
};
}
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_bounding_box.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_bounding_box.test.ts
index 322b086c2cf49..97f275b05a520 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_bounding_box.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_bounding_box.test.ts
@@ -18,7 +18,7 @@
*/
import { mapGeoBoundingBox } from './map_geo_bounding_box';
-import { esFilters } from '../../../../../common';
+import { Filter, GeoBoundingBoxFilter } from '../../../../../common';
describe('filter manager utilities', () => {
describe('mapGeoBoundingBox()', () => {
@@ -34,7 +34,7 @@ describe('filter manager utilities', () => {
bottom_right: { lat: 15, lon: 20 },
},
},
- } as esFilters.GeoBoundingBoxFilter;
+ } as GeoBoundingBoxFilter;
const result = mapGeoBoundingBox(filter);
@@ -63,7 +63,7 @@ describe('filter manager utilities', () => {
bottom_right: { lat: 15, lon: 20 },
},
},
- } as esFilters.GeoBoundingBoxFilter;
+ } as GeoBoundingBoxFilter;
const result = mapGeoBoundingBox(filter);
@@ -83,7 +83,7 @@ describe('filter manager utilities', () => {
const filter = {
meta: { index: 'logstash-*' },
query: { query_string: { query: 'foo:bar' } },
- } as esFilters.Filter;
+ } as Filter;
try {
mapGeoBoundingBox(filter);
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_bounding_box.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_bounding_box.ts
index be63d2de5b0df..f32c459baee5d 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_bounding_box.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_bounding_box.ts
@@ -16,10 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-import { esFilters } from '../../../../../common';
+import {
+ FilterValueFormatter,
+ GeoBoundingBoxFilter,
+ FILTERS,
+ isGeoBoundingBoxFilter,
+ Filter,
+} from '../../../../../common';
const getFormattedValueFn = (params: any) => {
- return (formatter?: esFilters.FilterValueFormatter) => {
+ return (formatter?: FilterValueFormatter) => {
const corners = formatter
? {
topLeft: formatter.convert(params.top_left),
@@ -34,20 +40,20 @@ const getFormattedValueFn = (params: any) => {
};
};
-const getParams = (filter: esFilters.GeoBoundingBoxFilter) => {
+const getParams = (filter: GeoBoundingBoxFilter) => {
const key = Object.keys(filter.geo_bounding_box).filter(k => k !== 'ignore_unmapped')[0];
const params = filter.geo_bounding_box[key];
return {
key,
params,
- type: esFilters.FILTERS.GEO_BOUNDING_BOX,
+ type: FILTERS.GEO_BOUNDING_BOX,
value: getFormattedValueFn(params),
};
};
-export const mapGeoBoundingBox = (filter: esFilters.Filter) => {
- if (!esFilters.isGeoBoundingBoxFilter(filter)) {
+export const mapGeoBoundingBox = (filter: Filter) => {
+ if (!isGeoBoundingBoxFilter(filter)) {
throw filter;
}
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_polygon.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_polygon.test.ts
index 2713f0fd17734..4af881aa58542 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_polygon.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_polygon.test.ts
@@ -18,10 +18,10 @@
*/
import { mapGeoPolygon } from './map_geo_polygon';
-import { esFilters } from '../../../../../common';
+import { Filter, GeoPolygonFilter } from '../../../../../common';
describe('filter manager utilities', () => {
- let filter: esFilters.GeoPolygonFilter;
+ let filter: GeoPolygonFilter;
beforeEach(() => {
filter = {
@@ -36,7 +36,7 @@ describe('filter manager utilities', () => {
],
},
},
- } as esFilters.GeoPolygonFilter;
+ } as GeoPolygonFilter;
});
describe('mapGeoPolygon()', () => {
@@ -74,7 +74,7 @@ describe('filter manager utilities', () => {
const wrongFilter = {
meta: { index: 'logstash-*' },
query: { query_string: { query: 'foo:bar' } },
- } as esFilters.Filter;
+ } as Filter;
try {
mapGeoPolygon(wrongFilter);
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_polygon.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_polygon.ts
index 8cca92a81cb5f..df5379289dd28 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_polygon.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_polygon.ts
@@ -17,32 +17,38 @@
* under the License.
*/
-import { esFilters } from '../../../../../common';
+import {
+ FilterValueFormatter,
+ GeoPolygonFilter,
+ FILTERS,
+ Filter,
+ isGeoPolygonFilter,
+} from '../../../../../common';
const POINTS_SEPARATOR = ', ';
const getFormattedValueFn = (points: string[]) => {
- return (formatter?: esFilters.FilterValueFormatter) => {
+ return (formatter?: FilterValueFormatter) => {
return points
.map((point: string) => (formatter ? formatter.convert(point) : JSON.stringify(point)))
.join(POINTS_SEPARATOR);
};
};
-function getParams(filter: esFilters.GeoPolygonFilter) {
+function getParams(filter: GeoPolygonFilter) {
const key = Object.keys(filter.geo_polygon).filter(k => k !== 'ignore_unmapped')[0];
const params = filter.geo_polygon[key];
return {
key,
params,
- type: esFilters.FILTERS.GEO_POLYGON,
+ type: FILTERS.GEO_POLYGON,
value: getFormattedValueFn(params.points || []),
};
}
-export function mapGeoPolygon(filter: esFilters.Filter) {
- if (!esFilters.isGeoPolygonFilter(filter)) {
+export function mapGeoPolygon(filter: Filter) {
+ if (!isGeoPolygonFilter(filter)) {
throw filter;
}
return getParams(filter);
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_match_all.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_match_all.test.ts
index 4d6bba6429b47..b22583ff8bb24 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_match_all.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_match_all.test.ts
@@ -18,11 +18,11 @@
*/
import { mapMatchAll } from './map_match_all';
-import { esFilters } from '../../../../../common';
+import { MatchAllFilter } from '../../../../../common';
describe('filter_manager/lib', () => {
describe('mapMatchAll()', () => {
- let filter: esFilters.MatchAllFilter;
+ let filter: MatchAllFilter;
beforeEach(() => {
filter = {
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_match_all.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_match_all.ts
index 9a4ea8430a305..b93642618c96c 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_match_all.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_match_all.ts
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-import { esFilters } from '../../../../../common';
+import { Filter, isMatchAllFilter, FILTERS } from '../../../../../common';
-export const mapMatchAll = (filter: esFilters.Filter) => {
- if (esFilters.isMatchAllFilter(filter)) {
+export const mapMatchAll = (filter: Filter) => {
+ if (isMatchAllFilter(filter)) {
return {
- type: esFilters.FILTERS.MATCH_ALL,
+ type: FILTERS.MATCH_ALL,
key: filter.meta.field,
value: filter.meta.formattedValue || 'all',
};
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_missing.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_missing.test.ts
index faf4b54989e20..67e5987818fb5 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_missing.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_missing.test.ts
@@ -18,14 +18,14 @@
*/
import { mapMissing } from './map_missing';
-import { esFilters } from '../../../../../common';
+import { MissingFilter, buildEmptyFilter } from '../../../../../common';
describe('filter manager utilities', () => {
describe('mapMissing()', () => {
test('should return the key and value for matching filters', async () => {
- const filter: esFilters.MissingFilter = {
+ const filter: MissingFilter = {
missing: { field: '_type' },
- ...esFilters.buildEmptyFilter(true),
+ ...buildEmptyFilter(true),
};
const result = mapMissing(filter);
@@ -34,7 +34,7 @@ describe('filter manager utilities', () => {
});
test('should return undefined for none matching', async done => {
- const filter = esFilters.buildEmptyFilter(true);
+ const filter = buildEmptyFilter(true);
try {
mapMissing(filter);
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_missing.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_missing.ts
index a1b6474365f40..875e3a9c3353d 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_missing.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_missing.ts
@@ -17,13 +17,13 @@
* under the License.
*/
-import { esFilters } from '../../../../../common';
+import { Filter, isMissingFilter, FILTERS } from '../../../../../common';
-export const mapMissing = (filter: esFilters.Filter) => {
- if (esFilters.isMissingFilter(filter)) {
+export const mapMissing = (filter: Filter) => {
+ if (isMissingFilter(filter)) {
return {
- type: esFilters.FILTERS.MISSING,
- value: esFilters.FILTERS.MISSING,
+ type: FILTERS.MISSING,
+ value: FILTERS.MISSING,
key: filter.missing.field,
};
}
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrase.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrase.test.ts
index 5150b32f118ae..5dd10ce30111f 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrase.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrase.test.ts
@@ -17,7 +17,7 @@
* under the License.
*/
import { mapPhrase } from './map_phrase';
-import { esFilters } from '../../../../../common';
+import { PhraseFilter, Filter } from '../../../../../common';
describe('filter manager utilities', () => {
describe('mapPhrase()', () => {
@@ -25,7 +25,7 @@ describe('filter manager utilities', () => {
const filter = {
meta: { index: 'logstash-*' },
query: { match: { _type: { query: 'apache', type: 'phrase' } } },
- } as esFilters.PhraseFilter;
+ } as PhraseFilter;
const result = mapPhrase(filter);
@@ -42,7 +42,7 @@ describe('filter manager utilities', () => {
const filter = {
meta: { index: 'logstash-*' },
query: { query_string: { query: 'foo:bar' } },
- } as esFilters.Filter;
+ } as Filter;
try {
mapPhrase(filter);
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrase.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrase.ts
index ae7701bf3a501..a5e92d57d6a5b 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrase.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrase.ts
@@ -18,36 +18,45 @@
*/
import { get } from 'lodash';
-import { esFilters } from '../../../../../common';
+import {
+ PhraseFilter,
+ FilterValueFormatter,
+ getPhraseFilterValue,
+ getPhraseFilterField,
+ FILTERS,
+ isScriptedPhraseFilter,
+ Filter,
+ isPhraseFilter,
+} from '../../../../../common';
-const getScriptedPhraseValue = (filter: esFilters.PhraseFilter) =>
+const getScriptedPhraseValue = (filter: PhraseFilter) =>
get(filter, ['script', 'script', 'params', 'value']);
const getFormattedValueFn = (value: any) => {
- return (formatter?: esFilters.FilterValueFormatter) => {
+ return (formatter?: FilterValueFormatter) => {
return formatter ? formatter.convert(value) : value;
};
};
-const getParams = (filter: esFilters.PhraseFilter) => {
+const getParams = (filter: PhraseFilter) => {
const scriptedPhraseValue = getScriptedPhraseValue(filter);
const isScriptedFilter = Boolean(scriptedPhraseValue);
- const key = isScriptedFilter ? filter.meta.field || '' : esFilters.getPhraseFilterField(filter);
- const query = scriptedPhraseValue || esFilters.getPhraseFilterValue(filter);
+ const key = isScriptedFilter ? filter.meta.field || '' : getPhraseFilterField(filter);
+ const query = scriptedPhraseValue || getPhraseFilterValue(filter);
const params = { query };
return {
key,
params,
- type: esFilters.FILTERS.PHRASE,
+ type: FILTERS.PHRASE,
value: getFormattedValueFn(query),
};
};
-export const isMapPhraseFilter = (filter: any): filter is esFilters.PhraseFilter =>
- esFilters.isPhraseFilter(filter) || esFilters.isScriptedPhraseFilter(filter);
+export const isMapPhraseFilter = (filter: any): filter is PhraseFilter =>
+ isPhraseFilter(filter) || isScriptedPhraseFilter(filter);
-export const mapPhrase = (filter: esFilters.Filter) => {
+export const mapPhrase = (filter: Filter) => {
if (!isMapPhraseFilter(filter)) {
throw filter;
}
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrases.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrases.ts
index f8f2aba1309b7..9d02e29522448 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrases.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrases.ts
@@ -17,10 +17,10 @@
* under the License.
*/
-import { esFilters } from '../../../../../common';
+import { Filter, isPhrasesFilter } from '../../../../../common';
-export const mapPhrases = (filter: esFilters.Filter) => {
- if (!esFilters.isPhrasesFilter(filter)) {
+export const mapPhrases = (filter: Filter) => {
+ if (!isPhrasesFilter(filter)) {
throw filter;
}
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_query_string.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_query_string.test.ts
index c65bc00b7df61..0589215955562 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_query_string.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_query_string.test.ts
@@ -18,27 +18,23 @@
*/
import { mapQueryString } from './map_query_string';
-import { esFilters } from '../../../../../common';
+import { buildQueryFilter, buildEmptyFilter, Filter } from '../../../../../common';
describe('filter manager utilities', () => {
describe('mapQueryString()', () => {
test('should return the key and value for matching filters', async () => {
- const filter = esFilters.buildQueryFilter(
- { query_string: { query: 'foo:bar' } },
- 'index',
- ''
- );
- const result = mapQueryString(filter as esFilters.Filter);
+ const filter = buildQueryFilter({ query_string: { query: 'foo:bar' } }, 'index', '');
+ const result = mapQueryString(filter as Filter);
expect(result).toHaveProperty('key', 'query');
expect(result).toHaveProperty('value', 'foo:bar');
});
test('should return undefined for none matching', async done => {
- const filter = esFilters.buildEmptyFilter(true);
+ const filter = buildEmptyFilter(true);
try {
- mapQueryString(filter as esFilters.Filter);
+ mapQueryString(filter as Filter);
} catch (e) {
expect(e).toBe(filter);
done();
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_query_string.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_query_string.ts
index e8e4e68318973..c49247cd96eaa 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_query_string.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_query_string.ts
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-import { esFilters } from '../../../../../common';
+import { FILTERS, Filter, isQueryStringFilter } from '../../../../../common';
-export const mapQueryString = (filter: esFilters.Filter) => {
- if (esFilters.isQueryStringFilter(filter)) {
+export const mapQueryString = (filter: Filter) => {
+ if (isQueryStringFilter(filter)) {
return {
- type: esFilters.FILTERS.QUERY_STRING,
+ type: FILTERS.QUERY_STRING,
key: 'query',
value: filter.query.query_string.query,
};
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.test.ts
index 2d312351c0f31..c8868b412707b 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.test.ts
@@ -18,15 +18,15 @@
*/
import { mapRange } from './map_range';
-import { esFilters } from '../../../../../common';
+import { FilterMeta, RangeFilter, Filter } from '../../../../../common';
describe('filter manager utilities', () => {
describe('mapRange()', () => {
test('should return the key and value for matching filters with gt/lt', async () => {
const filter = {
- meta: { index: 'logstash-*' } as esFilters.FilterMeta,
+ meta: { index: 'logstash-*' } as FilterMeta,
range: { bytes: { lt: 2048, gt: 1024 } },
- } as esFilters.RangeFilter;
+ } as RangeFilter;
const result = mapRange(filter);
expect(result).toHaveProperty('key', 'bytes');
@@ -41,7 +41,7 @@ describe('filter manager utilities', () => {
const filter = {
meta: { index: 'logstash-*' },
query: { query_string: { query: 'foo:bar' } },
- } as esFilters.Filter;
+ } as Filter;
try {
mapRange(filter);
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.ts
index affc8e6343076..d2d5a4b069218 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.ts
@@ -18,10 +18,17 @@
*/
import { get, has } from 'lodash';
-import { esFilters } from '../../../../../common';
+import {
+ FilterValueFormatter,
+ RangeFilter,
+ isScriptedRangeFilter,
+ isRangeFilter,
+ Filter,
+ FILTERS,
+} from '../../../../../common';
const getFormattedValueFn = (left: any, right: any) => {
- return (formatter?: esFilters.FilterValueFormatter) => {
+ return (formatter?: FilterValueFormatter) => {
let displayValue = `${left} to ${right}`;
if (formatter) {
const convert = formatter.getConverterFor('text');
@@ -31,12 +38,11 @@ const getFormattedValueFn = (left: any, right: any) => {
};
};
-const getFirstRangeKey = (filter: esFilters.RangeFilter) =>
- filter.range && Object.keys(filter.range)[0];
-const getRangeByKey = (filter: esFilters.RangeFilter, key: string) => get(filter, ['range', key]);
+const getFirstRangeKey = (filter: RangeFilter) => filter.range && Object.keys(filter.range)[0];
+const getRangeByKey = (filter: RangeFilter, key: string) => get(filter, ['range', key]);
-function getParams(filter: esFilters.RangeFilter) {
- const isScriptedRange = esFilters.isScriptedRangeFilter(filter);
+function getParams(filter: RangeFilter) {
+ const isScriptedRange = isScriptedRangeFilter(filter);
const key: string = (isScriptedRange ? filter.meta.field : getFirstRangeKey(filter)) || '';
const params: any = isScriptedRange
? get(filter, 'script.script.params')
@@ -50,13 +56,13 @@ function getParams(filter: esFilters.RangeFilter) {
const value = getFormattedValueFn(left, right);
- return { type: esFilters.FILTERS.RANGE, key, value, params };
+ return { type: FILTERS.RANGE, key, value, params };
}
-export const isMapRangeFilter = (filter: any): filter is esFilters.RangeFilter =>
- esFilters.isRangeFilter(filter) || esFilters.isScriptedRangeFilter(filter);
+export const isMapRangeFilter = (filter: any): filter is RangeFilter =>
+ isRangeFilter(filter) || isScriptedRangeFilter(filter);
-export const mapRange = (filter: esFilters.Filter) => {
+export const mapRange = (filter: Filter) => {
if (!isMapRangeFilter(filter)) {
throw filter;
}
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.test.ts
index 70876b4e2be77..aee1bf257be01 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.test.ts
@@ -18,7 +18,7 @@
*/
import { mapSpatialFilter } from './map_spatial_filter';
-import { esFilters } from '../../../../../common';
+import { FilterMeta, Filter, FILTERS } from '../../../../../common';
describe('mapSpatialFilter()', () => {
test('should return the key for matching multi polygon filter', async () => {
@@ -26,8 +26,8 @@ describe('mapSpatialFilter()', () => {
meta: {
key: 'location',
alias: 'my spatial filter',
- type: esFilters.FILTERS.SPATIAL_FILTER,
- } as esFilters.FilterMeta,
+ type: FILTERS.SPATIAL_FILTER,
+ } as FilterMeta,
query: {
bool: {
should: [
@@ -39,12 +39,12 @@ describe('mapSpatialFilter()', () => {
],
},
},
- } as esFilters.Filter;
+ } as Filter;
const result = mapSpatialFilter(filter);
expect(result).toHaveProperty('key', 'location');
expect(result).toHaveProperty('value', '');
- expect(result).toHaveProperty('type', esFilters.FILTERS.SPATIAL_FILTER);
+ expect(result).toHaveProperty('type', FILTERS.SPATIAL_FILTER);
});
test('should return the key for matching polygon filter', async () => {
@@ -52,17 +52,17 @@ describe('mapSpatialFilter()', () => {
meta: {
key: 'location',
alias: 'my spatial filter',
- type: esFilters.FILTERS.SPATIAL_FILTER,
- } as esFilters.FilterMeta,
+ type: FILTERS.SPATIAL_FILTER,
+ } as FilterMeta,
geo_polygon: {
geoCoordinates: { points: [] },
},
- } as esFilters.Filter;
+ } as Filter;
const result = mapSpatialFilter(filter);
expect(result).toHaveProperty('key', 'location');
expect(result).toHaveProperty('value', '');
- expect(result).toHaveProperty('type', esFilters.FILTERS.SPATIAL_FILTER);
+ expect(result).toHaveProperty('type', FILTERS.SPATIAL_FILTER);
});
test('should return undefined for none matching', async done => {
@@ -70,11 +70,11 @@ describe('mapSpatialFilter()', () => {
meta: {
key: 'location',
alias: 'my spatial filter',
- } as esFilters.FilterMeta,
+ } as FilterMeta,
geo_polygon: {
geoCoordinates: { points: [] },
},
- } as esFilters.Filter;
+ } as Filter;
try {
mapSpatialFilter(filter);
diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts
index ed2e5df82e37e..2d66d116eb4f2 100644
--- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-import { esFilters } from '../../../../../common';
+import { Filter, FILTERS } from '../../../../../common';
// Use mapSpatialFilter mapper to avoid bloated meta with value and params for spatial filters.
-export const mapSpatialFilter = (filter: esFilters.Filter) => {
+export const mapSpatialFilter = (filter: Filter) => {
if (
filter.meta &&
filter.meta.key &&
filter.meta.alias &&
- filter.meta.type === esFilters.FILTERS.SPATIAL_FILTER
+ filter.meta.type === FILTERS.SPATIAL_FILTER
) {
return {
key: filter.meta.key,
diff --git a/src/plugins/data/public/query/filter_manager/lib/only_disabled.test.ts b/src/plugins/data/public/query/filter_manager/lib/only_disabled.test.ts
index a9863696d47cd..34a0636869e9d 100644
--- a/src/plugins/data/public/query/filter_manager/lib/only_disabled.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/only_disabled.test.ts
@@ -18,7 +18,7 @@
*/
import { onlyDisabledFiltersChanged } from './only_disabled';
-import { esFilters } from '../../../../common';
+import { Filter } from '../../../../common';
describe('filter manager utilities', () => {
describe('onlyDisabledFiltersChanged()', () => {
@@ -27,20 +27,20 @@ describe('filter manager utilities', () => {
{ meta: { disabled: true } },
{ meta: { disabled: true } },
{ meta: { disabled: true } },
- ] as esFilters.Filter[];
- const newFilters = [{ meta: { disabled: true } }] as esFilters.Filter[];
+ ] as Filter[];
+ const newFilters = [{ meta: { disabled: true } }] as Filter[];
expect(onlyDisabledFiltersChanged(newFilters, filters)).toBe(true);
});
test('should return false if there are no old filters', () => {
- const newFilters = [{ meta: { disabled: false } }] as esFilters.Filter[];
+ const newFilters = [{ meta: { disabled: false } }] as Filter[];
expect(onlyDisabledFiltersChanged(newFilters, undefined)).toBe(false);
});
test('should return false if there are no new filters', () => {
- const filters = [{ meta: { disabled: false } }] as esFilters.Filter[];
+ const filters = [{ meta: { disabled: false } }] as Filter[];
expect(onlyDisabledFiltersChanged(undefined, filters)).toBe(false);
});
@@ -50,8 +50,8 @@ describe('filter manager utilities', () => {
{ meta: { disabled: false } },
{ meta: { disabled: false } },
{ meta: { disabled: false } },
- ] as esFilters.Filter[];
- const newFilters = [{ meta: { disabled: false } }] as esFilters.Filter[];
+ ] as Filter[];
+ const newFilters = [{ meta: { disabled: false } }] as Filter[];
expect(onlyDisabledFiltersChanged(newFilters, filters)).toBe(false);
});
@@ -61,8 +61,8 @@ describe('filter manager utilities', () => {
{ meta: { disabled: true } },
{ meta: { disabled: true } },
{ meta: { disabled: true } },
- ] as esFilters.Filter[];
- const newFilters = [{ meta: { disabled: false } }] as esFilters.Filter[];
+ ] as Filter[];
+ const newFilters = [{ meta: { disabled: false } }] as Filter[];
expect(onlyDisabledFiltersChanged(newFilters, filters)).toBe(false);
});
@@ -72,8 +72,8 @@ describe('filter manager utilities', () => {
{ meta: { disabled: false } },
{ meta: { disabled: false } },
{ meta: { disabled: false } },
- ] as esFilters.Filter[];
- const newFilters = [{ meta: { disabled: true } }] as esFilters.Filter[];
+ ] as Filter[];
+ const newFilters = [{ meta: { disabled: true } }] as Filter[];
expect(onlyDisabledFiltersChanged(newFilters, filters)).toBe(false);
});
@@ -83,8 +83,8 @@ describe('filter manager utilities', () => {
{ meta: { disabled: true } },
{ meta: { disabled: true } },
{ meta: { disabled: true } },
- ] as esFilters.Filter[];
- const newFilters = [] as esFilters.Filter[];
+ ] as Filter[];
+ const newFilters = [] as Filter[];
expect(onlyDisabledFiltersChanged(newFilters, filters)).toBe(true);
});
@@ -94,8 +94,8 @@ describe('filter manager utilities', () => {
{ meta: { disabled: false } },
{ meta: { disabled: false } },
{ meta: { disabled: false } },
- ] as esFilters.Filter[];
- const newFilters = [] as esFilters.Filter[];
+ ] as Filter[];
+ const newFilters = [] as Filter[];
expect(onlyDisabledFiltersChanged(newFilters, filters)).toBe(false);
});
@@ -104,11 +104,11 @@ describe('filter manager utilities', () => {
const filters = [
{ meta: { disabled: true, negate: false } },
{ meta: { disabled: true, negate: false } },
- ] as esFilters.Filter[];
+ ] as Filter[];
const newFilters = [
{ meta: { disabled: true, negate: true } },
{ meta: { disabled: true, negate: true } },
- ] as esFilters.Filter[];
+ ] as Filter[];
expect(onlyDisabledFiltersChanged(newFilters, filters)).toBe(true);
});
@@ -118,8 +118,8 @@ describe('filter manager utilities', () => {
{ meta: { disabled: false } },
{ meta: { disabled: false } },
{ meta: { disabled: true } },
- ] as esFilters.Filter[];
- const newFilters = [{ meta: { disabled: false } }] as esFilters.Filter[];
+ ] as Filter[];
+ const newFilters = [{ meta: { disabled: false } }] as Filter[];
expect(onlyDisabledFiltersChanged(newFilters, filters)).toBe(false);
});
@@ -129,15 +129,15 @@ describe('filter manager utilities', () => {
{ meta: { disabled: true } },
{ meta: { disabled: false } },
{ meta: { disabled: true } },
- ] as esFilters.Filter[];
- const newFilters = [] as esFilters.Filter[];
+ ] as Filter[];
+ const newFilters = [] as Filter[];
expect(onlyDisabledFiltersChanged(newFilters, filters)).toBe(false);
});
test('should not throw with null filters', () => {
- const filters = [null, { meta: { disabled: true } }] as esFilters.Filter[];
- const newFilters = [] as esFilters.Filter[];
+ const filters = [null, { meta: { disabled: true } }] as Filter[];
+ const newFilters = [] as Filter[];
expect(() => {
onlyDisabledFiltersChanged(newFilters, filters);
diff --git a/src/plugins/data/public/query/filter_manager/lib/only_disabled.ts b/src/plugins/data/public/query/filter_manager/lib/only_disabled.ts
index 3f35c94a3f858..34e1ac38ae95f 100644
--- a/src/plugins/data/public/query/filter_manager/lib/only_disabled.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/only_disabled.ts
@@ -18,20 +18,17 @@
*/
import { filter } from 'lodash';
-import { esFilters } from '../../../../common';
+import { Filter } from '../../../../common';
import { compareFilters, COMPARE_ALL_OPTIONS } from './compare_filters';
-const isEnabled = (f: esFilters.Filter) => f && f.meta && !f.meta.disabled;
+const isEnabled = (f: Filter) => f && f.meta && !f.meta.disabled;
/**
* Checks to see if only disabled filters have been changed
*
* @returns {bool} Only disabled filters
*/
-export const onlyDisabledFiltersChanged = (
- newFilters?: esFilters.Filter[],
- oldFilters?: esFilters.Filter[]
-) => {
+export const onlyDisabledFiltersChanged = (newFilters?: Filter[], oldFilters?: Filter[]) => {
// If it's the same - compare only enabled filters
const newEnabledFilters = filter(newFilters || [], isEnabled);
const oldEnabledFilters = filter(oldFilters || [], isEnabled);
diff --git a/src/plugins/data/public/query/filter_manager/lib/sort_filters.test.ts b/src/plugins/data/public/query/filter_manager/lib/sort_filters.test.ts
index 949c57e43ce74..009102f50d490 100644
--- a/src/plugins/data/public/query/filter_manager/lib/sort_filters.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/sort_filters.test.ts
@@ -18,26 +18,18 @@
*/
import { sortFilters } from './sort_filters';
-import { esFilters } from '../../../../common';
+import { FilterStateStore, buildQueryFilter } from '../../../../common';
describe('sortFilters', () => {
describe('sortFilters()', () => {
test('Not sort two application level filters', () => {
const f1 = {
- $state: { store: esFilters.FilterStateStore.APP_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.APP_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const f2 = {
- $state: { store: esFilters.FilterStateStore.APP_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.APP_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const filters = [f1, f2].sort(sortFilters);
@@ -46,20 +38,12 @@ describe('sortFilters', () => {
test('Not sort two global level filters', () => {
const f1 = {
- $state: { store: esFilters.FilterStateStore.GLOBAL_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.GLOBAL_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const f2 = {
- $state: { store: esFilters.FilterStateStore.GLOBAL_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.GLOBAL_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const filters = [f1, f2].sort(sortFilters);
@@ -68,20 +52,12 @@ describe('sortFilters', () => {
test('Move global level filter to the beginning of the array', () => {
const f1 = {
- $state: { store: esFilters.FilterStateStore.APP_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.APP_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const f2 = {
- $state: { store: esFilters.FilterStateStore.GLOBAL_STATE },
- ...esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ $state: { store: FilterStateStore.GLOBAL_STATE },
+ ...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const filters = [f1, f2].sort(sortFilters);
diff --git a/src/plugins/data/public/query/filter_manager/lib/sort_filters.ts b/src/plugins/data/public/query/filter_manager/lib/sort_filters.ts
index 657c80fe0ccb2..d7c8ee64a341f 100644
--- a/src/plugins/data/public/query/filter_manager/lib/sort_filters.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/sort_filters.ts
@@ -17,7 +17,7 @@
* under the License.
*/
-import { esFilters } from '../../../../common';
+import { Filter, FilterStateStore } from '../../../../common';
/**
* Sort filters according to their store - global filters go first
@@ -27,15 +27,11 @@ import { esFilters } from '../../../../common';
*
* @returns {number} Sorting order of filters
*/
-export const sortFilters = (
- { $state: a }: esFilters.Filter,
- { $state: b }: esFilters.Filter
-): number => {
+export const sortFilters = ({ $state: a }: Filter, { $state: b }: Filter): number => {
if (a!.store === b!.store) {
return 0;
} else {
- return a!.store === esFilters.FilterStateStore.GLOBAL_STATE &&
- b!.store !== esFilters.FilterStateStore.GLOBAL_STATE
+ return a!.store === FilterStateStore.GLOBAL_STATE && b!.store !== FilterStateStore.GLOBAL_STATE
? -1
: 1;
}
diff --git a/src/plugins/data/public/query/filter_manager/lib/uniq_filters.test.ts b/src/plugins/data/public/query/filter_manager/lib/uniq_filters.test.ts
index f71ac2940f32b..8b525a3d2a2e4 100644
--- a/src/plugins/data/public/query/filter_manager/lib/uniq_filters.test.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/uniq_filters.test.ts
@@ -18,22 +18,14 @@
*/
import { uniqFilters } from './uniq_filters';
-import { esFilters } from '../../../../common';
+import { buildQueryFilter, Filter, FilterStateStore } from '../../../../common';
describe('filter manager utilities', () => {
describe('niqFilter', () => {
test('should filter out dups', () => {
- const before: esFilters.Filter[] = [
- esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
- esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index',
- ''
- ),
+ const before: Filter[] = [
+ buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
+ buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
];
const results = uniqFilters(before);
@@ -41,17 +33,9 @@ describe('filter manager utilities', () => {
});
test('should filter out duplicates, ignoring meta attributes', () => {
- const before: esFilters.Filter[] = [
- esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index1',
- ''
- ),
- esFilters.buildQueryFilter(
- { _type: { match: { query: 'apache', type: 'phrase' } } },
- 'index2',
- ''
- ),
+ const before: Filter[] = [
+ buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index1', ''),
+ buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index2', ''),
];
const results = uniqFilters(before);
@@ -59,18 +43,18 @@ describe('filter manager utilities', () => {
});
test('should filter out duplicates, ignoring $state attributes', () => {
- const before: esFilters.Filter[] = [
+ const before: Filter[] = [
{
- $state: { store: esFilters.FilterStateStore.APP_STATE },
- ...esFilters.buildQueryFilter(
+ $state: { store: FilterStateStore.APP_STATE },
+ ...buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index',
''
),
},
{
- $state: { store: esFilters.FilterStateStore.GLOBAL_STATE },
- ...esFilters.buildQueryFilter(
+ $state: { store: FilterStateStore.GLOBAL_STATE },
+ ...buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index',
''
diff --git a/src/plugins/data/public/query/filter_manager/lib/uniq_filters.ts b/src/plugins/data/public/query/filter_manager/lib/uniq_filters.ts
index b6001d698c5f1..44c102d7ab15d 100644
--- a/src/plugins/data/public/query/filter_manager/lib/uniq_filters.ts
+++ b/src/plugins/data/public/query/filter_manager/lib/uniq_filters.ts
@@ -18,7 +18,7 @@
*/
import { each, union } from 'lodash';
import { dedupFilters } from './dedup_filters';
-import { esFilters } from '../../../../common';
+import { Filter } from '../../../../common';
/**
* Remove duplicate filters from an array of filters
@@ -28,10 +28,10 @@ import { esFilters } from '../../../../common';
* @returns {object} The original filters array with duplicates removed
*/
-export const uniqFilters = (filters: esFilters.Filter[], comparatorOptions: any = {}) => {
- let results: esFilters.Filter[] = [];
+export const uniqFilters = (filters: Filter[], comparatorOptions: any = {}) => {
+ let results: Filter[] = [];
- each(filters, (filter: esFilters.Filter) => {
+ each(filters, (filter: Filter) => {
results = union(results, dedupFilters(results, [filter]), comparatorOptions);
});
diff --git a/src/plugins/data/public/query/filter_manager/test_helpers/get_filters_array.ts b/src/plugins/data/public/query/filter_manager/test_helpers/get_filters_array.ts
index c5f0b11ce13f8..b381fe10a0b8a 100644
--- a/src/plugins/data/public/query/filter_manager/test_helpers/get_filters_array.ts
+++ b/src/plugins/data/public/query/filter_manager/test_helpers/get_filters_array.ts
@@ -17,9 +17,9 @@
* under the License.
*/
-import { esFilters } from '../../../../common';
+import { Filter } from '../../../../common';
-export function getFiltersArray(): esFilters.Filter[] {
+export function getFiltersArray(): Filter[] {
return [
{
query: { match: { extension: { query: 'jpg', type: 'phrase' } } },
diff --git a/src/plugins/data/public/query/filter_manager/test_helpers/get_stub_filter.ts b/src/plugins/data/public/query/filter_manager/test_helpers/get_stub_filter.ts
index a531ce7e03984..6748a83d5d6cb 100644
--- a/src/plugins/data/public/query/filter_manager/test_helpers/get_stub_filter.ts
+++ b/src/plugins/data/public/query/filter_manager/test_helpers/get_stub_filter.ts
@@ -17,15 +17,15 @@
* under the License.
*/
-import { esFilters } from '../../../../common';
+import { Filter, FilterStateStore } from '../../../../common';
export function getFilter(
- store: esFilters.FilterStateStore,
+ store: FilterStateStore,
disabled: boolean,
negated: boolean,
queryKey: string,
queryValue: any
-): esFilters.Filter {
+): Filter {
return {
$state: {
store,
diff --git a/src/plugins/data/public/query/filter_manager/types.ts b/src/plugins/data/public/query/filter_manager/types.ts
index 0f74a243ca91a..95b784eac79f6 100644
--- a/src/plugins/data/public/query/filter_manager/types.ts
+++ b/src/plugins/data/public/query/filter_manager/types.ts
@@ -17,9 +17,9 @@
* under the License.
*/
-import { esFilters } from '../../../common';
+import { Filter } from '../../../common';
export interface PartitionedFilters {
- globalFilters: esFilters.Filter[];
- appFilters: esFilters.Filter[];
+ globalFilters: Filter[];
+ appFilters: Filter[];
}
diff --git a/src/plugins/data/public/query/saved_query/saved_query_service.test.ts b/src/plugins/data/public/query/saved_query/saved_query_service.test.ts
index ecb3fc2d606ec..a6b8de32a00bd 100644
--- a/src/plugins/data/public/query/saved_query/saved_query_service.test.ts
+++ b/src/plugins/data/public/query/saved_query/saved_query_service.test.ts
@@ -18,7 +18,8 @@
*/
import { createSavedQueryService } from './saved_query_service';
-import { esFilters, SavedQueryAttributes } from '../..';
+import { SavedQueryAttributes } from '../..';
+import { FilterStateStore } from '../../../common';
const savedQueryAttributes: SavedQueryAttributes = {
title: 'foo',
@@ -42,7 +43,7 @@ const savedQueryAttributesWithFilters: SavedQueryAttributes = {
filters: [
{
query: { match_all: {} },
- $state: { store: esFilters.FilterStateStore.APP_STATE },
+ $state: { store: FilterStateStore.APP_STATE },
meta: {
disabled: false,
negate: false,
diff --git a/src/plugins/data/public/query/saved_query/types.ts b/src/plugins/data/public/query/saved_query/types.ts
index c278c2476c2e7..d05eada7b29e6 100644
--- a/src/plugins/data/public/query/saved_query/types.ts
+++ b/src/plugins/data/public/query/saved_query/types.ts
@@ -17,7 +17,7 @@
* under the License.
*/
-import { RefreshInterval, TimeRange, Query, esFilters } from '../..';
+import { RefreshInterval, TimeRange, Query, Filter } from '../..';
export type SavedQueryTimeFilter = TimeRange & {
refreshInterval: RefreshInterval;
@@ -32,7 +32,7 @@ export interface SavedQueryAttributes {
title: string;
description: string;
query: Query;
- filters?: esFilters.Filter[];
+ filters?: Filter[];
timefilter?: SavedQueryTimeFilter;
}
diff --git a/src/plugins/data/public/query/state_sync/sync_app_filters.test.ts b/src/plugins/data/public/query/state_sync/sync_app_filters.test.ts
index 61270ecc09979..e01547b1c0fd8 100644
--- a/src/plugins/data/public/query/state_sync/sync_app_filters.test.ts
+++ b/src/plugins/data/public/query/state_sync/sync_app_filters.test.ts
@@ -20,7 +20,7 @@
import { Subscription } from 'rxjs';
import { FilterManager } from '../filter_manager';
import { getFilter } from '../filter_manager/test_helpers/get_stub_filter';
-import { esFilters } from '../../../common';
+import { Filter, FilterStateStore } from '../../../common';
import { syncAppFilters } from './sync_app_filters';
import { coreMock } from '../../../../../core/public/mocks';
import { BaseStateContainer, createStateContainer } from '../../../../kibana_utils/public';
@@ -33,30 +33,30 @@ setupMock.uiSettings.get.mockImplementation((key: string) => {
describe('sync_app_filters', () => {
let filterManager: FilterManager;
- let appState: BaseStateContainer;
+ let appState: BaseStateContainer;
let appStateSub: Subscription;
let appStateChangeTriggered = jest.fn();
let filterManagerChangeSub: Subscription;
let filterManagerChangeTriggered = jest.fn();
- let gF1: esFilters.Filter;
- let gF2: esFilters.Filter;
- let aF1: esFilters.Filter;
- let aF2: esFilters.Filter;
+ let gF1: Filter;
+ let gF2: Filter;
+ let aF1: Filter;
+ let aF2: Filter;
beforeEach(() => {
filterManager = new FilterManager(setupMock.uiSettings);
- appState = createStateContainer([] as esFilters.Filter[]);
+ appState = createStateContainer([] as Filter[]);
appStateChangeTriggered = jest.fn();
appStateSub = appState.state$.subscribe(appStateChangeTriggered);
filterManagerChangeTriggered = jest.fn();
filterManagerChangeSub = filterManager.getUpdates$().subscribe(filterManagerChangeTriggered);
- gF1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, true, true, 'key1', 'value1');
- gF2 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'key2', 'value2');
- aF1 = getFilter(esFilters.FilterStateStore.APP_STATE, true, true, 'key3', 'value3');
- aF2 = getFilter(esFilters.FilterStateStore.APP_STATE, false, false, 'key4', 'value4');
+ gF1 = getFilter(FilterStateStore.GLOBAL_STATE, true, true, 'key1', 'value1');
+ gF2 = getFilter(FilterStateStore.GLOBAL_STATE, false, false, 'key2', 'value2');
+ aF1 = getFilter(FilterStateStore.APP_STATE, true, true, 'key3', 'value3');
+ aF2 = getFilter(FilterStateStore.APP_STATE, false, false, 'key4', 'value4');
});
afterEach(() => {
appStateSub.unsubscribe();
diff --git a/src/plugins/data/public/query/state_sync/sync_app_filters.ts b/src/plugins/data/public/query/state_sync/sync_app_filters.ts
index 7954729cd8665..d9956fcc0f6ae 100644
--- a/src/plugins/data/public/query/state_sync/sync_app_filters.ts
+++ b/src/plugins/data/public/query/state_sync/sync_app_filters.ts
@@ -20,7 +20,7 @@
import _ from 'lodash';
import { filter, map } from 'rxjs/operators';
import { COMPARE_ALL_OPTIONS, compareFilters } from '../filter_manager/lib/compare_filters';
-import { esFilters } from '../../../common';
+import { Filter } from '../../../common';
import { FilterManager } from '../filter_manager';
import { BaseStateContainer } from '../../../../../plugins/kibana_utils/public';
@@ -31,7 +31,7 @@ import { BaseStateContainer } from '../../../../../plugins/kibana_utils/public';
*/
export function syncAppFilters(
filterManager: FilterManager,
- appState: BaseStateContainer
+ appState: BaseStateContainer
) {
// make sure initial app filters are picked by filterManager
filterManager.setAppFilters(_.cloneDeep(appState.get()));
diff --git a/src/plugins/data/public/query/state_sync/sync_query.test.ts b/src/plugins/data/public/query/state_sync/sync_query.test.ts
index 4796da4f5fd4b..1e7db2b9fd22f 100644
--- a/src/plugins/data/public/query/state_sync/sync_query.test.ts
+++ b/src/plugins/data/public/query/state_sync/sync_query.test.ts
@@ -21,7 +21,7 @@ import { Subscription } from 'rxjs';
import { createBrowserHistory, History } from 'history';
import { FilterManager } from '../filter_manager';
import { getFilter } from '../filter_manager/test_helpers/get_stub_filter';
-import { esFilters } from '../../../common';
+import { Filter, FilterStateStore } from '../../../common';
import { coreMock } from '../../../../../core/public/mocks';
import {
createKbnUrlStateStorage,
@@ -59,8 +59,8 @@ describe('sync_query', () => {
let filterManagerChangeSub: Subscription;
let filterManagerChangeTriggered = jest.fn();
- let gF: esFilters.Filter;
- let aF: esFilters.Filter;
+ let gF: Filter;
+ let aF: Filter;
const pathWithFilter =
"/#?_g=(filters:!(('$state':(store:globalState),meta:(alias:!n,disabled:!t,index:'logstash-*',key:query,negate:!t,type:custom,value:'%7B%22match%22:%7B%22key1%22:%22value1%22%7D%7D'),query:(match:(key1:value1)))),refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))";
@@ -82,8 +82,8 @@ describe('sync_query', () => {
history = createBrowserHistory();
kbnUrlStateStorage = createKbnUrlStateStorage({ useHash: false, history });
- gF = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, true, true, 'key1', 'value1');
- aF = getFilter(esFilters.FilterStateStore.APP_STATE, true, true, 'key3', 'value3');
+ gF = getFilter(FilterStateStore.GLOBAL_STATE, true, true, 'key1', 'value1');
+ aF = getFilter(FilterStateStore.APP_STATE, true, true, 'key3', 'value3');
});
afterEach(() => {
filterManagerChangeSub.unsubscribe();
diff --git a/src/plugins/data/public/query/state_sync/sync_query.ts b/src/plugins/data/public/query/state_sync/sync_query.ts
index 9a4e9cbba2990..373f9aa0a5668 100644
--- a/src/plugins/data/public/query/state_sync/sync_query.ts
+++ b/src/plugins/data/public/query/state_sync/sync_query.ts
@@ -26,7 +26,7 @@ import {
syncState,
} from '../../../../kibana_utils/public';
import { COMPARE_ALL_OPTIONS, compareFilters } from '../filter_manager/lib/compare_filters';
-import { esFilters, RefreshInterval, TimeRange } from '../../../common';
+import { Filter, RefreshInterval, TimeRange } from '../../../common';
import { QuerySetup, QueryStart } from '../query_service';
const GLOBAL_STATE_STORAGE_KEY = '_g';
@@ -34,7 +34,7 @@ const GLOBAL_STATE_STORAGE_KEY = '_g';
export interface QuerySyncState {
time?: TimeRange;
refreshInterval?: RefreshInterval;
- filters?: esFilters.Filter[];
+ filters?: Filter[];
}
/**
@@ -140,7 +140,7 @@ export const getQueryStateContainer = (
...state,
refreshInterval,
}),
- setFilters: (state: QuerySyncState) => (filters: esFilters.Filter[]) => ({
+ setFilters: (state: QuerySyncState) => (filters: Filter[]) => ({
...state,
filters,
}),
diff --git a/src/plugins/data/public/query/timefilter/get_time.ts b/src/plugins/data/public/query/timefilter/get_time.ts
index 76f39da1cf706..fa15406189041 100644
--- a/src/plugins/data/public/query/timefilter/get_time.ts
+++ b/src/plugins/data/public/query/timefilter/get_time.ts
@@ -19,10 +19,7 @@
import dateMath from '@elastic/datemath';
import { IIndexPattern } from '../..';
-import { TimeRange, IFieldType } from '../../../common';
-
-// TODO: remove this
-import { esFilters } from '../../../common';
+import { TimeRange, IFieldType, buildRangeFilter } from '../../../common';
interface CalculateBoundsOptions {
forceNow?: Date;
@@ -57,7 +54,7 @@ export function getTime(
if (!bounds) {
return;
}
- return esFilters.buildRangeFilter(
+ return buildRangeFilter(
timefield,
{
...(bounds.min && { gte: bounds.min.toISOString() }),
diff --git a/src/plugins/data/public/query/timefilter/lib/change_time_filter.test.ts b/src/plugins/data/public/query/timefilter/lib/change_time_filter.test.ts
index 62805cde15936..f99bf50fc8b4d 100644
--- a/src/plugins/data/public/query/timefilter/lib/change_time_filter.test.ts
+++ b/src/plugins/data/public/query/timefilter/lib/change_time_filter.test.ts
@@ -18,7 +18,7 @@
*/
import { changeTimeFilter } from './change_time_filter';
import { timefilterServiceMock } from '../timefilter_service.mock';
-import { TimeRange, esFilters } from '../../../../common';
+import { TimeRange, RangeFilter } from '../../../../common';
const timefilterMock = timefilterServiceMock.createSetupContract();
const timefilter = timefilterMock.timefilter;
@@ -41,7 +41,7 @@ describe('changeTimeFilter()', () => {
test('should change the timefilter to match the range gt/lt', () => {
const filter: any = { range: { '@timestamp': { gt, lt } } };
- changeTimeFilter(timefilter, filter as esFilters.RangeFilter);
+ changeTimeFilter(timefilter, filter as RangeFilter);
const { to, from } = timefilter.getTime();
@@ -51,7 +51,7 @@ describe('changeTimeFilter()', () => {
test('should change the timefilter to match the range gte/lte', () => {
const filter: any = { range: { '@timestamp': { gte: gt, lte: lt } } };
- changeTimeFilter(timefilter, filter as esFilters.RangeFilter);
+ changeTimeFilter(timefilter, filter as RangeFilter);
const { to, from } = timefilter.getTime();
diff --git a/src/plugins/data/public/query/timefilter/lib/change_time_filter.ts b/src/plugins/data/public/query/timefilter/lib/change_time_filter.ts
index cae464f1449bc..8da83580ef5d6 100644
--- a/src/plugins/data/public/query/timefilter/lib/change_time_filter.ts
+++ b/src/plugins/data/public/query/timefilter/lib/change_time_filter.ts
@@ -20,9 +20,9 @@
import moment from 'moment';
import { keys } from 'lodash';
import { TimefilterContract } from '../../timefilter';
-import { esFilters } from '../../../../common';
+import { RangeFilter } from '../../../../common';
-export function convertRangeFilterToTimeRange(filter: esFilters.RangeFilter) {
+export function convertRangeFilterToTimeRange(filter: RangeFilter) {
const key = keys(filter.range)[0];
const values = filter.range[key];
@@ -32,6 +32,6 @@ export function convertRangeFilterToTimeRange(filter: esFilters.RangeFilter) {
};
}
-export function changeTimeFilter(timeFilter: TimefilterContract, filter: esFilters.RangeFilter) {
+export function changeTimeFilter(timeFilter: TimefilterContract, filter: RangeFilter) {
timeFilter.setTime(convertRangeFilterToTimeRange(filter));
}
diff --git a/src/plugins/data/public/query/timefilter/lib/extract_time_filter.test.ts b/src/plugins/data/public/query/timefilter/lib/extract_time_filter.test.ts
index d371f4587d2b8..6942a4501f9a4 100644
--- a/src/plugins/data/public/query/timefilter/lib/extract_time_filter.test.ts
+++ b/src/plugins/data/public/query/timefilter/lib/extract_time_filter.test.ts
@@ -18,7 +18,14 @@
*/
import { extractTimeFilter } from './extract_time_filter';
-import { esFilters, IIndexPattern, IFieldType } from '../../../../common';
+import {
+ Filter,
+ IIndexPattern,
+ IFieldType,
+ buildQueryFilter,
+ buildRangeFilter,
+ buildPhraseFilter,
+} from '../../../../common';
describe('filter manager utilities', () => {
let indexPattern: IIndexPattern;
@@ -31,13 +38,13 @@ describe('filter manager utilities', () => {
describe('extractTimeFilter()', () => {
test('should detect timeFilter', async () => {
- const filters: esFilters.Filter[] = [
- esFilters.buildQueryFilter(
+ const filters: Filter[] = [
+ buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'logstash-*',
''
),
- esFilters.buildRangeFilter(
+ buildRangeFilter(
{ name: 'time' } as IFieldType,
{ gt: 1388559600000, lt: 1388646000000 },
indexPattern
@@ -50,13 +57,13 @@ describe('filter manager utilities', () => {
});
test("should not return timeFilter when name doesn't match", async () => {
- const filters: esFilters.Filter[] = [
- esFilters.buildQueryFilter(
+ const filters: Filter[] = [
+ buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'logstash-*',
''
),
- esFilters.buildRangeFilter(
+ buildRangeFilter(
{ name: '@timestamp' } as IFieldType,
{ from: 1, to: 2 },
indexPattern,
@@ -70,13 +77,13 @@ describe('filter manager utilities', () => {
});
test('should not return a non range filter, even when names match', async () => {
- const filters: esFilters.Filter[] = [
- esFilters.buildQueryFilter(
+ const filters: Filter[] = [
+ buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'logstash-*',
''
),
- esFilters.buildPhraseFilter({ name: 'time' } as IFieldType, 'banana', indexPattern),
+ buildPhraseFilter({ name: 'time' } as IFieldType, 'banana', indexPattern),
];
const result = await extractTimeFilter('time', filters);
diff --git a/src/plugins/data/public/query/timefilter/lib/extract_time_filter.ts b/src/plugins/data/public/query/timefilter/lib/extract_time_filter.ts
index af2e8be65fb62..23dd1547baf10 100644
--- a/src/plugins/data/public/query/timefilter/lib/extract_time_filter.ts
+++ b/src/plugins/data/public/query/timefilter/lib/extract_time_filter.ts
@@ -18,13 +18,13 @@
*/
import { keys, partition } from 'lodash';
-import { esFilters } from '../../../../common';
+import { Filter, isRangeFilter, RangeFilter } from '../../../../common';
-export function extractTimeFilter(timeFieldName: string, filters: esFilters.Filter[]) {
- const [timeRangeFilter, restOfFilters] = partition(filters, (obj: esFilters.Filter) => {
+export function extractTimeFilter(timeFieldName: string, filters: Filter[]) {
+ const [timeRangeFilter, restOfFilters] = partition(filters, (obj: Filter) => {
let key;
- if (esFilters.isRangeFilter(obj)) {
+ if (isRangeFilter(obj)) {
key = keys(obj.range)[0];
}
@@ -33,6 +33,6 @@ export function extractTimeFilter(timeFieldName: string, filters: esFilters.Filt
return {
restOfFilters,
- timeRangeFilter: timeRangeFilter[0] as esFilters.RangeFilter | undefined,
+ timeRangeFilter: timeRangeFilter[0] as RangeFilter | undefined,
};
}
diff --git a/src/plugins/data/public/query/timefilter/lib/parse_querystring.ts b/src/plugins/data/public/query/timefilter/lib/parse_querystring.ts
index 467110b6f32ea..2220ad4eef1b7 100644
--- a/src/plugins/data/public/query/timefilter/lib/parse_querystring.ts
+++ b/src/plugins/data/public/query/timefilter/lib/parse_querystring.ts
@@ -16,8 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-
-import qs from 'querystring';
+import { parse } from 'query-string';
export function parseQueryString() {
// window.location.search is an empty string
@@ -27,5 +26,5 @@ export function parseQueryString() {
return {};
}
- return qs.parse(hrefSplit[1]);
+ return parse(hrefSplit[1], { sort: false });
}
diff --git a/src/plugins/data/public/search/search_source/search_source.ts b/src/plugins/data/public/search/search_source/search_source.ts
index 1ebf9a8ca534c..21e5ded6983ac 100644
--- a/src/plugins/data/public/search/search_source/search_source.ts
+++ b/src/plugins/data/public/search/search_source/search_source.ts
@@ -73,12 +73,13 @@ import _ from 'lodash';
import { normalizeSortRequest } from './normalize_sort_request';
import { filterDocvalueFields } from './filter_docvalue_fields';
import { fieldWildcardFilter } from '../../../../kibana_utils/public';
-import { esFilters, esQuery, SearchRequest } from '../..';
+import { SearchRequest } from '../..';
import { SearchSourceOptions, SearchSourceFields } from './types';
import { fetchSoon, FetchOptions, RequestFailure } from '../fetch';
import { getSearchService, getUiSettings, getInjectedMetadata } from '../../services';
-import { getHighlightRequest } from '../../../common';
+import { getEsQueryConfig, buildEsQuery, Filter } from '../../../common';
+import { getHighlightRequest } from '../../../common/field_formats';
export type ISearchSource = Pick;
@@ -379,15 +380,15 @@ export class SearchSource {
_.set(body, '_source.includes', remainingFields);
}
- const esQueryConfigs = esQuery.getEsQueryConfig(getUiSettings());
- body.query = esQuery.buildEsQuery(index, query, filters, esQueryConfigs);
+ const esQueryConfigs = getEsQueryConfig(getUiSettings());
+ body.query = buildEsQuery(index, query, filters, esQueryConfigs);
if (highlightAll && body.query) {
body.highlight = getHighlightRequest(body.query, getUiSettings().get('doc_table:highlight'));
delete searchRequest.highlightAll;
}
- const translateToQuery = (filter: esFilters.Filter) => filter && (filter.query || filter);
+ const translateToQuery = (filter: Filter) => filter && (filter.query || filter);
// re-write filters within filter aggregations
(function recurse(aggBranch) {
diff --git a/src/plugins/data/public/search/search_source/types.ts b/src/plugins/data/public/search/search_source/types.ts
index 268d24aaa6df1..c2f8701a64fa3 100644
--- a/src/plugins/data/public/search/search_source/types.ts
+++ b/src/plugins/data/public/search/search_source/types.ts
@@ -17,7 +17,8 @@
* under the License.
*/
import { NameList } from 'elasticsearch';
-import { esFilters, IndexPattern, Query } from '../..';
+import { IndexPattern, Query } from '../..';
+import { Filter } from '../../../common';
export type EsQuerySearchAfter = [string | number, string | number];
@@ -36,10 +37,7 @@ export type EsQuerySortValue = Record esFilters.Filter[] | esFilters.Filter | undefined);
+ filter?: Filter[] | Filter | (() => Filter[] | Filter | undefined);
sort?: EsQuerySortValue | EsQuerySortValue[];
highlight?: any;
highlightAll?: boolean;
diff --git a/src/plugins/data/public/search/search_strategy/default_search_strategy.ts b/src/plugins/data/public/search/search_strategy/default_search_strategy.ts
index 6c178fd9cd4c8..6dde6bfe22e4a 100644
--- a/src/plugins/data/public/search/search_strategy/default_search_strategy.ts
+++ b/src/plugins/data/public/search/search_strategy/default_search_strategy.ts
@@ -18,7 +18,7 @@
*/
import { SearchStrategyProvider, SearchStrategySearchParams } from './types';
-import { indexPatterns } from '../../index_patterns';
+import { isDefault } from '../../index_patterns';
import { getSearchParams, getMSearchParams, getPreference, getTimeout } from './get_search_params';
export const defaultSearchStrategy: SearchStrategyProvider = {
@@ -29,7 +29,7 @@ export const defaultSearchStrategy: SearchStrategyProvider = {
},
isViable: indexPattern => {
- return indexPattern && indexPatterns.isDefault(indexPattern);
+ return indexPattern && isDefault(indexPattern);
},
};
diff --git a/src/plugins/data/public/ui/apply_filters/apply_filter_popover_content.tsx b/src/plugins/data/public/ui/apply_filters/apply_filter_popover_content.tsx
index 92582ef1d15c2..33928e4f87afc 100644
--- a/src/plugins/data/public/ui/apply_filters/apply_filter_popover_content.tsx
+++ b/src/plugins/data/public/ui/apply_filters/apply_filter_popover_content.tsx
@@ -30,14 +30,16 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Component } from 'react';
-import { mapAndFlattenFilters, esFilters, IIndexPattern } from '../..';
+import { IIndexPattern } from '../..';
+import { getDisplayValueFromFilter, Filter } from '../../../common';
import { FilterLabel } from '../filter_bar';
+import { mapAndFlattenFilters } from '../../query';
interface Props {
- filters: esFilters.Filter[];
+ filters: Filter[];
indexPatterns: IIndexPattern[];
onCancel: () => void;
- onSubmit: (filters: esFilters.Filter[]) => void;
+ onSubmit: (filters: Filter[]) => void;
}
interface State {
@@ -55,8 +57,8 @@ export class ApplyFiltersPopoverContent extends Component {
isFilterSelected: props.filters.map(() => true),
};
}
- private getLabel(filter: esFilters.Filter) {
- const valueLabel = esFilters.getDisplayValueFromFilter(filter, this.props.indexPatterns);
+ private getLabel(filter: Filter) {
+ const valueLabel = getDisplayValueFromFilter(filter, this.props.indexPatterns);
return ;
}
diff --git a/src/plugins/data/public/ui/apply_filters/apply_filters_popover.tsx b/src/plugins/data/public/ui/apply_filters/apply_filters_popover.tsx
index 71a042adffa39..cffcad66cbc24 100644
--- a/src/plugins/data/public/ui/apply_filters/apply_filters_popover.tsx
+++ b/src/plugins/data/public/ui/apply_filters/apply_filters_popover.tsx
@@ -19,13 +19,13 @@
import React from 'react';
import { ApplyFiltersPopoverContent } from './apply_filter_popover_content';
-import { IIndexPattern, esFilters } from '../..';
+import { IIndexPattern, Filter } from '../..';
type CancelFnType = () => void;
-type SubmitFnType = (filters: esFilters.Filter[]) => void;
+type SubmitFnType = (filters: Filter[]) => void;
export const applyFiltersPopover = (
- filters: esFilters.Filter[],
+ filters: Filter[],
indexPatterns: IIndexPattern[],
onCancel: CancelFnType,
onSubmit: SubmitFnType
diff --git a/src/plugins/data/public/ui/filter_bar/filter_bar.tsx b/src/plugins/data/public/ui/filter_bar/filter_bar.tsx
index 2aaceddd68f0c..6852152d059be 100644
--- a/src/plugins/data/public/ui/filter_bar/filter_bar.tsx
+++ b/src/plugins/data/public/ui/filter_bar/filter_bar.tsx
@@ -26,11 +26,21 @@ import { FilterEditor } from './filter_editor';
import { FilterItem } from './filter_item';
import { FilterOptions } from './filter_options';
import { useKibana } from '../../../../kibana_react/public';
-import { IIndexPattern, esFilters } from '../..';
+import { IIndexPattern } from '../..';
+import {
+ buildEmptyFilter,
+ Filter,
+ enableFilter,
+ disableFilter,
+ pinFilter,
+ toggleFilterDisabled,
+ toggleFilterNegated,
+ unpinFilter,
+} from '../../../common';
interface Props {
- filters: esFilters.Filter[];
- onFiltersUpdated?: (filters: esFilters.Filter[]) => void;
+ filters: Filter[];
+ onFiltersUpdated?: (filters: Filter[]) => void;
className: string;
indexPatterns: IIndexPattern[];
intl: InjectedIntl;
@@ -43,7 +53,7 @@ function FilterBarUI(props: Props) {
const uiSettings = kibana.services.uiSettings;
if (!uiSettings) return null;
- function onFiltersUpdated(filters: esFilters.Filter[]) {
+ function onFiltersUpdated(filters: Filter[]) {
if (props.onFiltersUpdated) {
props.onFiltersUpdated(filters);
}
@@ -68,7 +78,7 @@ function FilterBarUI(props: Props) {
const isPinned = uiSettings!.get('filters:pinnedByDefault');
const [indexPattern] = props.indexPatterns;
const index = indexPattern && indexPattern.id;
- const newFilter = esFilters.buildEmptyFilter(isPinned, index);
+ const newFilter = buildEmptyFilter(isPinned, index);
const button = (
void;
+ onSubmit: (filter: Filter) => void;
onCancel: () => void;
intl: InjectedIntl;
}
@@ -76,10 +85,10 @@ class FilterEditorUI extends Component {
selectedIndexPattern: this.getIndexPatternFromFilter(),
selectedField: this.getFieldFromFilter(),
selectedOperator: this.getSelectedOperator(),
- params: esFilters.getFilterParams(props.filter),
+ params: getFilterParams(props.filter),
useCustomLabel: props.filter.meta.alias !== null,
customLabel: props.filter.meta.alias,
- queryDsl: JSON.stringify(esFilters.cleanFilter(props.filter), null, 2),
+ queryDsl: JSON.stringify(cleanFilter(props.filter), null, 2),
isCustomEditorOpen: this.isUnknownFilterType(),
};
}
@@ -372,14 +381,12 @@ class FilterEditorUI extends Component {
}
private getIndexPatternFromFilter() {
- return esFilters.getIndexPatternFromFilter(this.props.filter, this.props.indexPatterns);
+ return getIndexPatternFromFilter(this.props.filter, this.props.indexPatterns);
}
private getFieldFromFilter() {
const indexPattern = this.getIndexPatternFromFilter();
- return (
- indexPattern && getFieldFromFilter(this.props.filter as esFilters.FieldFilter, indexPattern)
- );
+ return indexPattern && getFieldFromFilter(this.props.filter as FieldFilter, indexPattern);
}
private getSelectedOperator() {
@@ -470,17 +477,10 @@ class FilterEditorUI extends Component {
const { index, disabled, negate } = this.props.filter.meta;
const newIndex = index || this.props.indexPatterns[0].id!;
const body = JSON.parse(queryDsl);
- const filter = esFilters.buildCustomFilter(
- newIndex,
- body,
- disabled,
- negate,
- alias,
- $state.store
- );
+ const filter = buildCustomFilter(newIndex, body, disabled, negate, alias, $state.store);
this.props.onSubmit(filter);
} else if (indexPattern && field && operator) {
- const filter = esFilters.buildFilter(
+ const filter = buildFilter(
indexPattern,
field,
operator.type,
diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.test.ts b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.test.ts
index fb3fbc10d7455..771743a3e5df2 100644
--- a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.test.ts
+++ b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.test.ts
@@ -25,7 +25,7 @@ import {
stubIndexPattern,
stubFields,
} from '../../../../stubs';
-import { esFilters } from '../../../../index';
+import { toggleFilterNegated } from '../../../../../common';
import {
getFieldFromFilter,
getFilterableFields,
@@ -54,7 +54,7 @@ describe('Filter editor utils', () => {
});
it('should return "is not" for phrase filter', () => {
- const negatedPhraseFilter = esFilters.toggleFilterNegated(phraseFilter);
+ const negatedPhraseFilter = toggleFilterNegated(phraseFilter);
const operator = getOperatorFromFilter(negatedPhraseFilter);
expect(operator).not.toBeUndefined();
expect(operator && operator.type).toBe('phrase');
@@ -69,7 +69,7 @@ describe('Filter editor utils', () => {
});
it('should return "is not one of" for negated phrases filter', () => {
- const negatedPhrasesFilter = esFilters.toggleFilterNegated(phrasesFilter);
+ const negatedPhrasesFilter = toggleFilterNegated(phrasesFilter);
const operator = getOperatorFromFilter(negatedPhrasesFilter);
expect(operator).not.toBeUndefined();
expect(operator && operator.type).toBe('phrases');
@@ -84,7 +84,7 @@ describe('Filter editor utils', () => {
});
it('should return "is not between" for negated range filter', () => {
- const negatedRangeFilter = esFilters.toggleFilterNegated(rangeFilter);
+ const negatedRangeFilter = toggleFilterNegated(rangeFilter);
const operator = getOperatorFromFilter(negatedRangeFilter);
expect(operator).not.toBeUndefined();
expect(operator && operator.type).toBe('range');
@@ -99,7 +99,7 @@ describe('Filter editor utils', () => {
});
it('should return "does not exists" for negated exists filter', () => {
- const negatedExistsFilter = esFilters.toggleFilterNegated(existsFilter);
+ const negatedExistsFilter = toggleFilterNegated(existsFilter);
const operator = getOperatorFromFilter(negatedExistsFilter);
expect(operator).not.toBeUndefined();
expect(operator && operator.type).toBe('exists');
diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts
index 422ffb162125d..beb7714ffcca3 100644
--- a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts
+++ b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts
@@ -20,13 +20,19 @@
import dateMath from '@elastic/datemath';
import { Ipv4Address } from '../../../../../../kibana_utils/public';
import { FILTER_OPERATORS, Operator } from './filter_operators';
-import { esFilters, IIndexPattern, IFieldType, isFilterable } from '../../../..';
+import {
+ isFilterable,
+ IIndexPattern,
+ IFieldType,
+ Filter,
+ FieldFilter,
+} from '../../../../../common';
-export function getFieldFromFilter(filter: esFilters.FieldFilter, indexPattern: IIndexPattern) {
+export function getFieldFromFilter(filter: FieldFilter, indexPattern: IIndexPattern) {
return indexPattern.fields.find(field => field.name === filter.meta.key);
}
-export function getOperatorFromFilter(filter: esFilters.Filter) {
+export function getOperatorFromFilter(filter: Filter) {
return FILTER_OPERATORS.find(operator => {
return filter.meta.type === operator.type && filter.meta.negate === operator.negate;
});
diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_label.tsx b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_label.tsx
index 49a0d6f2ab3bd..8f9be6b9c079a 100644
--- a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_label.tsx
+++ b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_label.tsx
@@ -21,10 +21,10 @@ import React, { Fragment } from 'react';
import { EuiTextColor } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { existsOperator, isOneOfOperator } from './filter_operators';
-import { esFilters } from '../../../..';
+import { Filter, FILTERS } from '../../../../../common';
interface Props {
- filter: esFilters.Filter;
+ filter: Filter;
valueLabel?: string;
}
@@ -51,43 +51,43 @@ export function FilterLabel({ filter, valueLabel }: Props) {
}
switch (filter.meta.type) {
- case esFilters.FILTERS.EXISTS:
+ case FILTERS.EXISTS:
return (
{prefix}
{filter.meta.key} {existsOperator.message}
);
- case esFilters.FILTERS.GEO_BOUNDING_BOX:
+ case FILTERS.GEO_BOUNDING_BOX:
return (
{prefix}
{filter.meta.key}: {valueLabel}
);
- case esFilters.FILTERS.GEO_POLYGON:
+ case FILTERS.GEO_POLYGON:
return (
{prefix}
{filter.meta.key}: {valueLabel}
);
- case esFilters.FILTERS.PHRASES:
+ case FILTERS.PHRASES:
return (
{prefix}
{filter.meta.key} {isOneOfOperator.message} {valueLabel}
);
- case esFilters.FILTERS.QUERY_STRING:
+ case FILTERS.QUERY_STRING:
return (
{prefix}
{valueLabel}
);
- case esFilters.FILTERS.PHRASE:
- case esFilters.FILTERS.RANGE:
+ case FILTERS.PHRASE:
+ case FILTERS.RANGE:
return (
{prefix}
diff --git a/src/plugins/data/public/ui/filter_bar/filter_item.tsx b/src/plugins/data/public/ui/filter_bar/filter_item.tsx
index 788663041fd03..0febfe807a946 100644
--- a/src/plugins/data/public/ui/filter_bar/filter_item.tsx
+++ b/src/plugins/data/public/ui/filter_bar/filter_item.tsx
@@ -24,14 +24,22 @@ import React, { Component, MouseEvent } from 'react';
import { IUiSettingsClient } from 'src/core/public';
import { FilterEditor } from './filter_editor';
import { FilterView } from './filter_view';
-import { esFilters, IIndexPattern } from '../..';
+import { IIndexPattern } from '../..';
+import {
+ Filter,
+ isFilterPinned,
+ getDisplayValueFromFilter,
+ toggleFilterNegated,
+ toggleFilterPinned,
+ toggleFilterDisabled,
+} from '../../../common';
interface Props {
id: string;
- filter: esFilters.Filter;
+ filter: Filter;
indexPatterns: IIndexPattern[];
className?: string;
- onUpdate: (filter: esFilters.Filter) => void;
+ onUpdate: (filter: Filter) => void;
onRemove: () => void;
intl: InjectedIntl;
uiSettings: IUiSettingsClient;
@@ -61,13 +69,13 @@ class FilterItemUI extends Component