{
}}
autoComplete="off"
spellCheck={false}
- aria-label={
- this.props.screenTitle
- ? this.props.intl.formatMessage(
- {
- id: 'data.query.queryBar.searchInputAriaLabel',
- defaultMessage:
- 'You are on search box of {previouslyTranslatedPageTitle} page. Start typing to search and filter the {pageType}',
- },
- {
- previouslyTranslatedPageTitle: this.props.screenTitle,
- pageType: this.props.appName,
- }
- )
- : undefined
- }
+ aria-label={i18n.translate('data.query.queryBar.searchInputAriaLabel', {
+ defaultMessage: 'Start typing to search and filter the {pageType} page',
+ values: { pageType: this.services.appName },
+ })}
type="text"
- data-test-subj="queryInput"
aria-autocomplete="list"
- aria-controls="kbnTypeahead__items"
+ aria-controls={this.state.isSuggestionsVisible ? 'kbnTypeahead__items' : undefined}
aria-activedescendant={
- this.state.isSuggestionsVisible ? 'suggestion-' + this.state.index : ''
+ this.state.isSuggestionsVisible && typeof this.state.index === 'number'
+ ? `suggestion-${this.state.index}`
+ : undefined
}
role="textbox"
prepend={this.props.prepend}
@@ -529,7 +501,7 @@ export class QueryBarInputUI extends Component {
onSelectLanguage={this.onSelectLanguage}
/>
}
- {...rest}
+ data-test-subj={this.props.dataTestSubj || 'queryInput'}
/>
@@ -548,4 +520,4 @@ export class QueryBarInputUI extends Component
{
}
}
-export const QueryBarInput = injectI18n(QueryBarInputUI);
+export const QueryBarInput = injectI18n(withKibana(QueryBarInputUI));
diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.test.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.test.tsx
index 0926af7b30ef78..337bb9f4861c3e 100644
--- a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.test.tsx
+++ b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.test.tsx
@@ -21,7 +21,6 @@ import { mockPersistedLogFactory } from './query_bar_input.test.mocks';
import React from 'react';
import { mount } from 'enzyme';
-import './query_bar_top_row.test.mocks';
import { QueryBarTopRow } from './query_bar_top_row';
import { IndexPattern } from '../../../index';
@@ -97,42 +96,49 @@ const mockIndexPattern = {
],
} as IndexPattern;
-describe('QueryBarTopRowTopRow', () => {
- const QUERY_INPUT_SELECTOR = 'InjectIntl(QueryBarInputUI)';
- const TIMEPICKER_SELECTOR = 'EuiSuperDatePicker';
+function wrapQueryBarTopRowInContext(testProps: any) {
+ const defaultOptions = {
+ screenTitle: 'Another Screen',
+ onSubmit: noop,
+ onChange: noop,
+ intl: null as any,
+ };
+
const services = {
+ appName: 'discover',
uiSettings: startMock.uiSettings,
savedObjects: startMock.savedObjects,
notifications: startMock.notifications,
http: startMock.http,
- };
- const defaultOptions = {
- appName: 'discover',
- screenTitle: 'Another Screen',
- onSubmit: noop,
- onChange: noop,
store: createMockStorage(),
- intl: null as any,
};
+ return (
+
+
+
+
+
+ );
+}
+
+describe('QueryBarTopRowTopRow', () => {
+ const QUERY_INPUT_SELECTOR = 'QueryBarInputUI';
+ const TIMEPICKER_SELECTOR = 'EuiSuperDatePicker';
+
beforeEach(() => {
jest.clearAllMocks();
});
it('Should render the given query', () => {
const component = mount(
-
-
-
-
-
+ wrapQueryBarTopRowInContext({
+ query: kqlQuery,
+ screenTitle: 'Another Screen',
+ isDirty: false,
+ indexPatterns: [mockIndexPattern],
+ timeHistory: timefilterSetupMock.history,
+ })
);
expect(component.find(QUERY_INPUT_SELECTOR).length).toBe(1);
@@ -141,19 +147,14 @@ describe('QueryBarTopRowTopRow', () => {
it('Should create a unique PersistedLog based on the appName and query language', () => {
mount(
-
-
-
-
-
+ wrapQueryBarTopRowInContext({
+ query: kqlQuery,
+ screenTitle: 'Another Screen',
+ indexPatterns: [mockIndexPattern],
+ timeHistory: timefilterSetupMock.history,
+ disableAutoFocus: true,
+ isDirty: false,
+ })
);
expect(mockPersistedLogFactory.mock.calls[0][0]).toBe('typeahead:discover-kuery');
@@ -161,15 +162,10 @@ describe('QueryBarTopRowTopRow', () => {
it('Should render only timepicker when no options provided', () => {
const component = mount(
-
-
-
-
-
+ wrapQueryBarTopRowInContext({
+ isDirty: false,
+ timeHistory: timefilterSetupMock.history,
+ })
);
expect(component.find(QUERY_INPUT_SELECTOR).length).toBe(0);
@@ -178,16 +174,11 @@ describe('QueryBarTopRowTopRow', () => {
it('Should not show timepicker when asked', () => {
const component = mount(
-
-
-
-
-
+ wrapQueryBarTopRowInContext({
+ showDatePicker: false,
+ timeHistory: timefilterSetupMock.history,
+ isDirty: false,
+ })
);
expect(component.find(QUERY_INPUT_SELECTOR).length).toBe(0);
@@ -196,19 +187,14 @@ describe('QueryBarTopRowTopRow', () => {
it('Should render timepicker with options', () => {
const component = mount(
-
-
-
-
-
+ wrapQueryBarTopRowInContext({
+ isDirty: false,
+ screenTitle: 'Another Screen',
+ showDatePicker: true,
+ dateRangeFrom: 'now-7d',
+ dateRangeTo: 'now',
+ timeHistory: timefilterSetupMock.history,
+ })
);
expect(component.find(QUERY_INPUT_SELECTOR).length).toBe(0);
@@ -217,19 +203,16 @@ describe('QueryBarTopRowTopRow', () => {
it('Should render only query input bar', () => {
const component = mount(
-
-
-
-
-
+ wrapQueryBarTopRowInContext({
+ query: kqlQuery,
+ indexPatterns: [mockIndexPattern],
+ isDirty: false,
+ screenTitle: 'Another Screen',
+ showDatePicker: false,
+ dateRangeFrom: 'now-7d',
+ dateRangeTo: 'now',
+ timeHistory: timefilterSetupMock.history,
+ })
);
expect(component.find(QUERY_INPUT_SELECTOR).length).toBe(1);
@@ -238,20 +221,15 @@ describe('QueryBarTopRowTopRow', () => {
it('Should NOT render query input bar if disabled', () => {
const component = mount(
-
-
-
-
-
+ wrapQueryBarTopRowInContext({
+ query: kqlQuery,
+ isDirty: false,
+ screenTitle: 'Another Screen',
+ indexPatterns: [mockIndexPattern],
+ showQueryInput: false,
+ showDatePicker: false,
+ timeHistory: timefilterSetupMock.history,
+ })
);
expect(component.find(QUERY_INPUT_SELECTOR).length).toBe(0);
@@ -260,17 +238,12 @@ describe('QueryBarTopRowTopRow', () => {
it('Should NOT render query input bar if missing options', () => {
const component = mount(
-
-
-
-
-
+ wrapQueryBarTopRowInContext({
+ isDirty: false,
+ screenTitle: 'Another Screen',
+ showDatePicker: false,
+ timeHistory: timefilterSetupMock.history,
+ })
);
expect(component.find(QUERY_INPUT_SELECTOR).length).toBe(0);
diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx
index c25b596973174d..6895c9ecd018cb 100644
--- a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx
+++ b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx
@@ -21,7 +21,6 @@ import { doesKueryExpressionHaveLuceneSyntaxError } from '@kbn/es-query';
import classNames from 'classnames';
import React, { useState, useEffect } from 'react';
-import { Storage } from 'ui/storage';
import { documentationLinks } from 'ui/documentation_links';
import { PersistedLog } from 'ui/persisted_log';
@@ -30,6 +29,7 @@ import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiLink, EuiSuperDatePicker } fro
import { EuiSuperUpdateButton } from '@elastic/eui';
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { Toast } from 'src/core/public';
+import { TimeRange } from 'src/plugins/data/public';
import { useKibana } from '../../../../../../../plugins/kibana_react/public';
import { IndexPattern } from '../../../index_patterns';
@@ -37,21 +37,15 @@ import { QueryBarInput } from './query_bar_input';
import { getQueryLog } from '../lib/get_query_log';
import { Query } from '../index';
import { TimeHistoryContract } from '../../../timefilter';
-
-interface DateRange {
- from: string;
- to: string;
-}
+import { IDataPluginServices } from '../../../types';
interface Props {
query?: Query;
- onSubmit: (payload: { dateRange: DateRange; query?: Query }) => void;
- onChange: (payload: { dateRange: DateRange; query?: Query }) => void;
+ onSubmit: (payload: { dateRange: TimeRange; query?: Query }) => void;
+ onChange: (payload: { dateRange: TimeRange; query?: Query }) => void;
disableAutoFocus?: boolean;
- appName: string;
screenTitle?: string;
indexPatterns?: Array;
- store?: Storage;
intl: InjectedIntl;
prepend?: React.ReactNode;
showQueryInput?: boolean;
@@ -70,15 +64,15 @@ interface Props {
function QueryBarTopRowUI(props: Props) {
const [isDateRangeInvalid, setIsDateRangeInvalid] = useState(false);
- const kibana = useKibana();
- const { uiSettings, http, notifications, savedObjects } = kibana.services;
+ const kibana = useKibana();
+ const { uiSettings, notifications, store, appName } = kibana.services;
const queryLanguage = props.query && props.query.language;
let persistedLog: PersistedLog | undefined;
useEffect(() => {
if (!props.query) return;
- persistedLog = getQueryLog(uiSettings!, props.appName, props.query.language);
+ persistedLog = getQueryLog(uiSettings!, appName, props.query.language);
}, [queryLanguage]);
function onClickSubmitButton(event: React.MouseEvent) {
@@ -131,7 +125,7 @@ function QueryBarTopRowUI(props: Props) {
}
}
- function onSubmit({ query, dateRange }: { query?: Query; dateRange: DateRange }) {
+ function onSubmit({ query, dateRange }: { query?: Query; dateRange: TimeRange }) {
handleLuceneSyntaxWarning();
if (props.timeHistory) {
@@ -153,19 +147,14 @@ function QueryBarTopRowUI(props: Props) {
return (
);
@@ -176,7 +165,7 @@ function QueryBarTopRowUI(props: Props) {
}
function shouldRenderQueryInput(): boolean {
- return Boolean(props.showQueryInput && props.indexPatterns && props.query && props.store);
+ return Boolean(props.showQueryInput && props.indexPatterns && props.query && store);
}
function renderUpdateButton() {
@@ -251,7 +240,7 @@ function QueryBarTopRowUI(props: Props) {
function handleLuceneSyntaxWarning() {
if (!props.query) return;
- const { intl, store } = props;
+ const { intl } = props;
const { query, language } = props.query;
if (
language === 'kuery' &&
@@ -300,8 +289,8 @@ function QueryBarTopRowUI(props: Props) {
}
function onLuceneSyntaxWarningOptOut(toast: Toast) {
- if (!props.store) return;
- props.store.set('kibana.luceneSyntaxWarningOptOut', true);
+ if (!store) return;
+ store.set('kibana.luceneSyntaxWarningOptOut', true);
notifications!.toasts.remove(toast);
}
diff --git a/src/legacy/core_plugins/data/public/search/search_bar/components/create_search_bar.tsx b/src/legacy/core_plugins/data/public/search/search_bar/components/create_search_bar.tsx
new file mode 100644
index 00000000000000..add49e47971d34
--- /dev/null
+++ b/src/legacy/core_plugins/data/public/search/search_bar/components/create_search_bar.tsx
@@ -0,0 +1,93 @@
+/*
+ * 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 { Filter } from '@kbn/es-query';
+import { CoreStart } from 'src/core/public';
+import { Storage } from 'ui/storage';
+import { AutocompletePublicPluginStart } from 'src/plugins/data/public';
+import { KibanaContextProvider } from '../../../../../../../../src/plugins/kibana_react/public';
+import { TimefilterSetup } from '../../../timefilter';
+import { FilterManager, SearchBar } from '../../../';
+import { SearchBarOwnProps } from '.';
+
+interface StatefulSearchBarDeps {
+ core: CoreStart;
+ store: Storage;
+ timefilter: TimefilterSetup;
+ filterManager: FilterManager;
+ autocomplete: AutocompletePublicPluginStart;
+}
+
+export type StatetfulSearchBarProps = SearchBarOwnProps & {
+ appName: string;
+};
+
+const defaultFiltersUpdated = (filterManager: FilterManager) => {
+ return (filters: Filter[]) => {
+ filterManager.setFilters(filters);
+ };
+};
+
+const defaultOnRefreshChange = (timefilter: TimefilterSetup) => {
+ return (options: { isPaused: boolean; refreshInterval: number }) => {
+ timefilter.timefilter.setRefreshInterval({
+ value: options.refreshInterval,
+ pause: options.isPaused,
+ });
+ };
+};
+
+export function createSearchBar({
+ core,
+ store,
+ timefilter,
+ filterManager,
+ autocomplete,
+}: StatefulSearchBarDeps) {
+ // App name should come from the core application service.
+ // Until it's available, we'll ask the user to provide it for the pre-wired component.
+ return (props: StatetfulSearchBarProps) => {
+ const timeRange = timefilter.timefilter.getTime();
+ const refreshInterval = timefilter.timefilter.getRefreshInterval();
+
+ return (
+
+
+
+ );
+ };
+}
diff --git a/src/legacy/core_plugins/data/public/search/search_bar/components/index.tsx b/src/legacy/core_plugins/data/public/search/search_bar/components/index.tsx
index 24ffa939a746e9..accaac163acfcf 100644
--- a/src/legacy/core_plugins/data/public/search/search_bar/components/index.tsx
+++ b/src/legacy/core_plugins/data/public/search/search_bar/components/index.tsx
@@ -18,3 +18,4 @@
*/
export * from './search_bar';
+export * from './create_search_bar';
diff --git a/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.test.tsx b/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.test.tsx
index 7d48977fab8a53..73e81a38572c39 100644
--- a/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.test.tsx
+++ b/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.test.tsx
@@ -18,14 +18,17 @@
*/
import React from 'react';
-import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { SearchBar } from './search_bar';
import { IndexPattern } from '../../../index_patterns';
+import { KibanaContextProvider } from 'src/plugins/kibana_react/public';
+import { I18nProvider } from '@kbn/i18n/react';
+
import { coreMock } from '../../../../../../../../src/core/public/mocks';
const startMock = coreMock.createStart();
import { timefilterServiceMock } from '../../../timefilter/timefilter_service.mock';
+import { mount } from 'enzyme';
const timefilterSetupMock = timefilterServiceMock.createSetupContract();
jest.mock('../../../../../data/public', () => {
@@ -41,13 +44,6 @@ jest.mock('../../../query/query_bar', () => {
};
});
-jest.mock('ui/notify', () => ({
- toastNotifications: {
- addSuccess: () => {},
- addDanger: () => {},
- },
-}));
-
const noop = jest.fn();
const createMockWebStorage = () => ({
@@ -87,26 +83,44 @@ const kqlQuery = {
language: 'kuery',
};
-describe('SearchBar', () => {
- const SEARCH_BAR_ROOT = '.globalQueryBar';
- const FILTER_BAR = '.filterBar';
- const QUERY_BAR = '.queryBar';
-
- const options = {
+function wrapSearchBarInContext(testProps: any) {
+ const defaultOptions = {
appName: 'test',
- savedObjects: startMock.savedObjects,
- notifications: startMock.notifications,
timeHistory: timefilterSetupMock.history,
intl: null as any,
};
+ const services = {
+ uiSettings: startMock.uiSettings,
+ savedObjects: startMock.savedObjects,
+ notifications: startMock.notifications,
+ http: startMock.http,
+ store: createMockStorage(),
+ };
+
+ return (
+
+
+
+
+
+ );
+}
+
+describe('SearchBar', () => {
+ const SEARCH_BAR_ROOT = '.globalQueryBar';
+ const FILTER_BAR = '.filterBar';
+ const QUERY_BAR = '.queryBar';
+
beforeEach(() => {
jest.clearAllMocks();
});
it('Should render query bar when no options provided (in reality - timepicker)', () => {
- const component = mountWithIntl(
-
+ const component = mount(
+ wrapSearchBarInContext({
+ indexPatterns: [mockIndexPattern],
+ })
);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
@@ -115,12 +129,11 @@ describe('SearchBar', () => {
});
it('Should render empty when timepicker is off and no options provided', () => {
- const component = mountWithIntl(
-
+ const component = mount(
+ wrapSearchBarInContext({
+ indexPatterns: [mockIndexPattern],
+ showDatePicker: false,
+ })
);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
@@ -129,14 +142,13 @@ describe('SearchBar', () => {
});
it('Should render filter bar, when required fields are provided', () => {
- const component = mountWithIntl(
-
+ const component = mount(
+ wrapSearchBarInContext({
+ indexPatterns: [mockIndexPattern],
+ showDatePicker: false,
+ onFiltersUpdated: noop,
+ filters: [],
+ })
);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
@@ -145,15 +157,14 @@ describe('SearchBar', () => {
});
it('Should NOT render filter bar, if disabled', () => {
- const component = mountWithIntl(
-
+ const component = mount(
+ wrapSearchBarInContext({
+ indexPatterns: [mockIndexPattern],
+ showFilterBar: false,
+ filters: [],
+ onFiltersUpdated: noop,
+ showDatePicker: false,
+ })
);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
@@ -162,15 +173,13 @@ describe('SearchBar', () => {
});
it('Should render query bar, when required fields are provided', () => {
- const component = mountWithIntl(
-
+ const component = mount(
+ wrapSearchBarInContext({
+ indexPatterns: [mockIndexPattern],
+ screenTitle: 'test screen',
+ onQuerySubmit: noop,
+ query: kqlQuery,
+ })
);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
@@ -179,16 +188,14 @@ describe('SearchBar', () => {
});
it('Should NOT render query bar, if disabled', () => {
- const component = mountWithIntl(
-
+ const component = mount(
+ wrapSearchBarInContext({
+ indexPatterns: [mockIndexPattern],
+ screenTitle: 'test screen',
+ onQuerySubmit: noop,
+ query: kqlQuery,
+ showQueryBar: false,
+ })
);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
@@ -197,17 +204,15 @@ describe('SearchBar', () => {
});
it('Should render query bar and filter bar', () => {
- const component = mountWithIntl(
-
+ const component = mount(
+ wrapSearchBarInContext({
+ indexPatterns: [mockIndexPattern],
+ screenTitle: 'test screen',
+ onQuerySubmit: noop,
+ query: kqlQuery,
+ filters: [],
+ onFiltersUpdated: noop,
+ })
);
expect(component.find(SEARCH_BAR_ROOT).length).toBe(1);
diff --git a/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.tsx b/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.tsx
index 6c73fa3614cc3c..ed2a6638aba114 100644
--- a/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.tsx
+++ b/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.tsx
@@ -22,10 +22,9 @@ import { InjectedIntl, injectI18n } from '@kbn/i18n/react';
import classNames from 'classnames';
import React, { Component } from 'react';
import ResizeObserver from 'resize-observer-polyfill';
-import { Storage } from 'ui/storage';
import { get, isEqual } from 'lodash';
-import { CoreStart } from 'src/core/public';
+import { TimeRange } from 'src/plugins/data/common/types';
import { IndexPattern, Query, FilterBar } from '../../../../../data/public';
import { QueryBarTopRow } from '../../../query';
import { SavedQuery, SavedQueryAttributes } from '../index';
@@ -34,54 +33,52 @@ import { SavedQueryManagementComponent } from './saved_query_management/saved_qu
import { SavedQueryService } from '../lib/saved_query_service';
import { createSavedQueryService } from '../lib/saved_query_service';
import { TimeHistoryContract } from '../../../timefilter';
-
-interface DateRange {
- from: string;
- to: string;
-}
-
-/**
- * NgReact lib requires that changes to the props need to be made in the directive config as well
- * See [search_bar\directive\index.js] file
- */
-export interface SearchBarProps {
- appName: string;
+import {
+ withKibana,
+ KibanaReactContextValue,
+} from '../../../../../../../plugins/kibana_react/public';
+import { IDataPluginServices } from '../../../types';
+
+interface SearchBarInjectedDeps {
+ kibana: KibanaReactContextValue;
intl: InjectedIntl;
- indexPatterns?: IndexPattern[];
-
- // Query bar
- showQueryBar?: boolean;
- showQueryInput?: boolean;
- screenTitle?: string;
- store?: Storage;
- query?: Query;
- savedQuery?: SavedQuery;
- onQuerySubmit?: (payload: { dateRange: DateRange; query?: Query }) => void;
timeHistory: TimeHistoryContract;
// Filter bar
- showFilterBar?: boolean;
- filters?: Filter[];
onFiltersUpdated?: (filters: Filter[]) => void;
+ filters?: Filter[];
// Date picker
- showDatePicker?: boolean;
dateRangeFrom?: string;
dateRangeTo?: string;
// Autorefresh
+ onRefreshChange?: (options: { isPaused: boolean; refreshInterval: number }) => void;
isRefreshPaused?: boolean;
refreshInterval?: number;
+}
+
+export interface SearchBarOwnProps {
+ indexPatterns?: IndexPattern[];
+ customSubmitButton?: React.ReactNode;
+ screenTitle?: string;
+
+ // Togglers
+ showQueryBar?: boolean;
+ showQueryInput?: boolean;
+ showFilterBar?: boolean;
+ showDatePicker?: boolean;
showAutoRefreshOnly?: boolean;
showSaveQuery?: boolean;
- onRefreshChange?: (options: { isPaused: boolean; refreshInterval: number }) => void;
+
+ // Query bar - should be in SearchBarInjectedDeps
+ query?: Query;
+ savedQuery?: SavedQuery;
+ onQuerySubmit?: (payload: { dateRange: TimeRange; query?: Query }) => void;
onSaved?: (savedQuery: SavedQuery) => void;
onSavedQueryUpdated?: (savedQuery: SavedQuery) => void;
onClearSavedQuery?: () => void;
- customSubmitButton?: React.ReactNode;
-
- // TODO: deprecate
- savedObjects: CoreStart['savedObjects'];
- notifications: CoreStart['notifications'];
}
+export type SearchBarProps = SearchBarOwnProps & SearchBarInjectedDeps;
+
interface State {
isFiltersVisible: boolean;
showSaveQueryModal: boolean;
@@ -102,7 +99,7 @@ class SearchBarUI extends Component {
};
private savedQueryService!: SavedQueryService;
-
+ private services = this.props.kibana.services;
public filterBarRef: Element | null = null;
public filterBarWrapperRef: Element | null = null;
@@ -253,7 +250,7 @@ class SearchBarUI extends Component {
response = await this.savedQueryService.saveQuery(savedQueryAttributes);
}
- this.props.notifications.toasts.addSuccess(
+ this.services.notifications.toasts.addSuccess(
`Your query "${response.attributes.title}" was saved`
);
@@ -266,7 +263,7 @@ class SearchBarUI extends Component {
this.props.onSaved(response);
}
} catch (error) {
- this.props.notifications.toasts.addDanger(
+ this.services.notifications.toasts.addDanger(
`An error occured while saving your query: ${error.message}`
);
throw error;
@@ -285,7 +282,7 @@ class SearchBarUI extends Component {
});
};
- public onQueryBarChange = (queryAndDateRange: { dateRange: DateRange; query?: Query }) => {
+ public onQueryBarChange = (queryAndDateRange: { dateRange: TimeRange; query?: Query }) => {
this.setState({
query: queryAndDateRange.query,
dateRangeFrom: queryAndDateRange.dateRange.from,
@@ -293,7 +290,7 @@ class SearchBarUI extends Component {
});
};
- public onQueryBarSubmit = (queryAndDateRange: { dateRange?: DateRange; query?: Query }) => {
+ public onQueryBarSubmit = (queryAndDateRange: { dateRange?: TimeRange; query?: Query }) => {
this.setState(
{
query: queryAndDateRange.query,
@@ -337,8 +334,8 @@ class SearchBarUI extends Component {
this.setFilterBarHeight();
this.ro.observe(this.filterBarRef);
}
- if (this.props.savedObjects) {
- this.savedQueryService = createSavedQueryService(this.props.savedObjects!.client);
+ if (this.services.savedObjects) {
+ this.savedQueryService = createSavedQueryService(this.services.savedObjects.client);
}
}
@@ -370,9 +367,7 @@ class SearchBarUI extends Component {
query={this.state.query}
screenTitle={this.props.screenTitle}
onSubmit={this.onQueryBarSubmit}
- appName={this.props.appName}
indexPatterns={this.props.indexPatterns}
- store={this.props.store}
prepend={this.props.showFilterBar ? savedQueryManagement : undefined}
showDatePicker={this.props.showDatePicker}
dateRangeFrom={this.state.dateRangeFrom}
@@ -449,4 +444,4 @@ class SearchBarUI extends Component {
}
}
-export const SearchBar = injectI18n(SearchBarUI);
+export const SearchBar = injectI18n(withKibana(SearchBarUI));
diff --git a/src/legacy/core_plugins/data/public/shim/legacy_dependencies_plugin.ts b/src/legacy/core_plugins/data/public/shim/legacy_dependencies_plugin.ts
index 4289d56b33c605..126754388f13f2 100644
--- a/src/legacy/core_plugins/data/public/shim/legacy_dependencies_plugin.ts
+++ b/src/legacy/core_plugins/data/public/shim/legacy_dependencies_plugin.ts
@@ -18,7 +18,8 @@
*/
import chrome from 'ui/chrome';
-import { CoreStart, Plugin } from '../../../../../../src/core/public';
+import { Storage } from 'ui/storage';
+import { Plugin } from '../../../../../../src/core/public';
import { initLegacyModule } from './legacy_module';
/** @internal */
@@ -26,6 +27,10 @@ export interface LegacyDependenciesPluginSetup {
savedObjectsClient: any;
}
+export interface LegacyDependenciesPluginStart {
+ storage: Storage;
+}
+
export class LegacyDependenciesPlugin implements Plugin {
public setup() {
initLegacyModule();
@@ -35,7 +40,9 @@ export class LegacyDependenciesPlugin implements Plugin {
} as LegacyDependenciesPluginSetup;
}
- public start(core: CoreStart) {
- // nothing to do here yet
+ public start() {
+ return {
+ storage: new Storage(window.localStorage),
+ } as LegacyDependenciesPluginStart;
}
}
diff --git a/src/legacy/core_plugins/data/public/timefilter/get_time.ts b/src/legacy/core_plugins/data/public/timefilter/get_time.ts
index e54725dd9ba486..18a43d789714d7 100644
--- a/src/legacy/core_plugins/data/public/timefilter/get_time.ts
+++ b/src/legacy/core_plugins/data/public/timefilter/get_time.ts
@@ -18,8 +18,8 @@
*/
import dateMath from '@elastic/datemath';
-import { Field, IndexPattern } from 'ui/index_patterns';
import { TimeRange } from 'src/plugins/data/public';
+import { IndexPattern, Field } from '../index_patterns';
interface CalculateBoundsOptions {
forceNow?: Date;
diff --git a/src/legacy/core_plugins/data/public/timefilter/timefilter.ts b/src/legacy/core_plugins/data/public/timefilter/timefilter.ts
index c08ea9043da927..64129ea2af5ffb 100644
--- a/src/legacy/core_plugins/data/public/timefilter/timefilter.ts
+++ b/src/legacy/core_plugins/data/public/timefilter/timefilter.ts
@@ -25,7 +25,7 @@ import { IndexPattern, TimeHistoryContract } from '../index';
import { areRefreshIntervalsDifferent, areTimeRangesDifferent } from './lib/diff_time_picker_vals';
import { parseQueryString } from './lib/parse_querystring';
import { calculateBounds, getTime } from './get_time';
-import { TimefilterConfig, InputTimeRange } from './types';
+import { TimefilterConfig, InputTimeRange, TimeRangeBounds } from './types';
export class Timefilter {
// Fired when isTimeRangeSelectorEnabled \ isAutoRefreshSelectorEnabled are toggled
@@ -148,19 +148,19 @@ export class Timefilter {
return getTime(indexPattern, timeRange ? timeRange : this._time, this.getForceNow());
};
- public getBounds = () => {
+ public getBounds(): TimeRangeBounds {
return this.calculateBounds(this._time);
- };
+ }
- public calculateBounds = (timeRange: TimeRange) => {
+ public calculateBounds(timeRange: TimeRange): TimeRangeBounds {
return calculateBounds(timeRange, { forceNow: this.getForceNow() });
- };
+ }
- public getActiveBounds = () => {
+ public getActiveBounds(): TimeRangeBounds | undefined {
if (this.isTimeRangeSelectorEnabled) {
return this.getBounds();
}
- };
+ }
/**
* Show the time bounds selector part of the time filter
diff --git a/src/legacy/core_plugins/data/public/timefilter/timefilter.test.mocks.ts b/src/legacy/core_plugins/data/public/types.ts
similarity index 63%
rename from src/legacy/core_plugins/data/public/timefilter/timefilter.test.mocks.ts
rename to src/legacy/core_plugins/data/public/types.ts
index 7354916c3fc359..4b7a5c1402ea72 100644
--- a/src/legacy/core_plugins/data/public/timefilter/timefilter.test.mocks.ts
+++ b/src/legacy/core_plugins/data/public/types.ts
@@ -17,12 +17,15 @@
* under the License.
*/
-import { chromeServiceMock } from '../../../../../core/public/mocks';
+import { UiSettingsClientContract, CoreStart } from 'src/core/public';
+import { AutocompletePublicPluginStart } from 'src/plugins/data/public';
-jest.doMock('ui/new_platform', () => ({
- npStart: {
- core: {
- chrome: chromeServiceMock.createStartContract(),
- },
- },
-}));
+export interface IDataPluginServices extends Partial {
+ appName: string;
+ uiSettings: UiSettingsClientContract;
+ savedObjects: CoreStart['savedObjects'];
+ notifications: CoreStart['notifications'];
+ http: CoreStart['http'];
+ store: Storage;
+ autocomplete: AutocompletePublicPluginStart;
+}
diff --git a/src/legacy/core_plugins/elasticsearch/index.d.ts b/src/legacy/core_plugins/elasticsearch/index.d.ts
index eeee5f3f4c6c71..4cbb1c82cc1e40 100644
--- a/src/legacy/core_plugins/elasticsearch/index.d.ts
+++ b/src/legacy/core_plugins/elasticsearch/index.d.ts
@@ -482,7 +482,7 @@ export interface CallCluster {
(endpoint: 'indices.upgrade', params: IndicesUpgradeParams, options?: CallClusterOptions): ReturnType;
(endpoint: 'indices.validateQuery', params: IndicesValidateQueryParams, options?: CallClusterOptions): ReturnType;
- // ingest namepsace
+ // ingest namespace
(endpoint: 'ingest.deletePipeline', params: IngestDeletePipelineParams, options?: CallClusterOptions): ReturnType;
(endpoint: 'ingest.getPipeline', params: IngestGetPipelineParams, options?: CallClusterOptions): ReturnType;
(endpoint: 'ingest.putPipeline', params: IngestPutPipelineParams, options?: CallClusterOptions): ReturnType;
diff --git a/src/legacy/core_plugins/input_control_vis/public/register_vis.js b/src/legacy/core_plugins/input_control_vis/public/register_vis.js
index 76320b331bb066..731cf2dac9dd2e 100644
--- a/src/legacy/core_plugins/input_control_vis/public/register_vis.js
+++ b/src/legacy/core_plugins/input_control_vis/public/register_vis.js
@@ -24,7 +24,7 @@ import { OptionsTab } from './components/editor/options_tab';
import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message';
import { Status } from 'ui/vis/update_status';
import { i18n } from '@kbn/i18n';
-import { setup as visualizations } from '../../visualizations/public/legacy';
+import { setup as visualizations } from '../../visualizations/public/np_ready/public/legacy';
function InputControlVisProvider() {
diff --git a/src/legacy/core_plugins/interpreter/public/functions/__snapshots__/kibana.test.js.snap b/src/legacy/core_plugins/interpreter/public/functions/__snapshots__/kibana.test.ts.snap
similarity index 100%
rename from src/legacy/core_plugins/interpreter/public/functions/__snapshots__/kibana.test.js.snap
rename to src/legacy/core_plugins/interpreter/public/functions/__snapshots__/kibana.test.ts.snap
diff --git a/src/legacy/core_plugins/interpreter/public/functions/__tests__/font.js b/src/legacy/core_plugins/interpreter/public/functions/__tests__/font.js
deleted file mode 100644
index 4a7ebc1522f2ab..00000000000000
--- a/src/legacy/core_plugins/interpreter/public/functions/__tests__/font.js
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * 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 expect from '@kbn/expect';
-import { openSans } from '../../../common/lib/fonts';
-import { font } from '../font';
-import { functionWrapper } from '../../../test_helpers';
-
-describe('font', () => {
- const fn = functionWrapper(font);
-
- describe('default output', () => {
- const result = fn(null);
-
- it('returns a style', () => {
- expect(result)
- .to.have.property('type', 'style')
- .and.to.have.property('spec')
- .and.to.have.property('css');
- });
- });
-
- describe('args', () => {
- describe('size', () => {
- it('sets font size', () => {
- const result = fn(null, { size: 20 });
- expect(result.spec).to.have.property('fontSize', '20px');
- expect(result.css).to.contain('font-size:20px');
- });
-
- it('defaults to 14px', () => {
- const result = fn(null);
- expect(result.spec).to.have.property('fontSize', '14px');
- expect(result.css).to.contain('font-size:14px');
- });
- });
-
- describe('lHeight', () => {
- it('sets line height', () => {
- const result = fn(null, { lHeight: 30 });
- expect(result.spec).to.have.property('lineHeight', '30px');
- expect(result.css).to.contain('line-height:30px');
- });
-
- it('defaults to 1', () => {
- const result = fn(null);
- expect(result.spec).to.have.property('lineHeight', '1');
- expect(result.css).to.contain('line-height:1');
- });
- });
-
- describe('family', () => {
- it('sets font family', () => {
- const result = fn(null, { family: 'Optima, serif' });
- expect(result.spec).to.have.property('fontFamily', 'Optima, serif');
- expect(result.css).to.contain('font-family:Optima, serif');
- });
-
- it(`defaults to "${openSans.value}"`, () => {
- const result = fn(null);
- expect(result.spec).to.have.property('fontFamily', `"${openSans.value}"`);
- expect(result.css).to.contain(`font-family:"${openSans.value}"`);
- });
- });
-
- describe('color', () => {
- it('sets font color', () => {
- const result = fn(null, { color: 'blue' });
- expect(result.spec).to.have.property('color', 'blue');
- expect(result.css).to.contain('color:blue');
- });
- });
-
- describe('weight', () => {
- it('sets font weight', () => {
- let result = fn(null, { weight: 'normal' });
- expect(result.spec).to.have.property('fontWeight', 'normal');
- expect(result.css).to.contain('font-weight:normal');
-
- result = fn(null, { weight: 'bold' });
- expect(result.spec).to.have.property('fontWeight', 'bold');
- expect(result.css).to.contain('font-weight:bold');
-
- result = fn(null, { weight: 'bolder' });
- expect(result.spec).to.have.property('fontWeight', 'bolder');
- expect(result.css).to.contain('font-weight:bolder');
-
- result = fn(null, { weight: 'lighter' });
- expect(result.spec).to.have.property('fontWeight', 'lighter');
- expect(result.css).to.contain('font-weight:lighter');
-
- result = fn(null, { weight: '400' });
- expect(result.spec).to.have.property('fontWeight', '400');
- expect(result.css).to.contain('font-weight:400');
- });
-
- it('defaults to \'normal\'', () => {
- const result = fn(null);
- expect(result.spec).to.have.property('fontWeight', 'normal');
- expect(result.css).to.contain('font-weight:normal');
- });
-
- it('throws when provided an invalid weight', () => {
- expect(() => fn(null, { weight: 'foo' })).to.throwException();
- });
- });
-
- describe('underline', () => {
- it('sets text underline', () => {
- let result = fn(null, { underline: true });
- expect(result.spec).to.have.property('textDecoration', 'underline');
- expect(result.css).to.contain('text-decoration:underline');
-
- result = fn(null, { underline: false });
- expect(result.spec).to.have.property('textDecoration', 'none');
- expect(result.css).to.contain('text-decoration:none');
- });
-
- it('defaults to false', () => {
- const result = fn(null);
- expect(result.spec).to.have.property('textDecoration', 'none');
- expect(result.css).to.contain('text-decoration:none');
- });
- });
-
- describe('italic', () => {
- it('sets italic', () => {
- let result = fn(null, { italic: true });
- expect(result.spec).to.have.property('fontStyle', 'italic');
- expect(result.css).to.contain('font-style:italic');
-
- result = fn(null, { italic: false });
- expect(result.spec).to.have.property('fontStyle', 'normal');
- expect(result.css).to.contain('font-style:normal');
- });
-
- it('defaults to false', () => {
- const result = fn(null);
- expect(result.spec).to.have.property('fontStyle', 'normal');
- expect(result.css).to.contain('font-style:normal');
- });
- });
-
- describe('align', () => {
- it('sets text alignment', () => {
- let result = fn(null, { align: 'left' });
- expect(result.spec).to.have.property('textAlign', 'left');
- expect(result.css).to.contain('text-align:left');
-
- result = fn(null, { align: 'center' });
- expect(result.spec).to.have.property('textAlign', 'center');
- expect(result.css).to.contain('text-align:center');
-
- result = fn(null, { align: 'right' });
- expect(result.spec).to.have.property('textAlign', 'right');
- expect(result.css).to.contain('text-align:right');
-
- result = fn(null, { align: 'justify' });
- expect(result.spec).to.have.property('textAlign', 'justify');
- expect(result.css).to.contain('text-align:justify');
- });
-
- it(`defaults to 'left'`, () => {
- const result = fn(null);
- expect(result.spec).to.have.property('textAlign', 'left');
- expect(result.css).to.contain('text-align:left');
- });
-
- it('throws when provided an invalid alignment', () => {
- expect(fn)
- .withArgs(null, { align: 'foo' })
- .to.throwException();
- });
- });
- });
-});
diff --git a/src/legacy/core_plugins/interpreter/public/functions/clog.js b/src/legacy/core_plugins/interpreter/public/functions/clog.ts
similarity index 91%
rename from src/legacy/core_plugins/interpreter/public/functions/clog.js
rename to src/legacy/core_plugins/interpreter/public/functions/clog.ts
index 634d166f5f0bb5..4867726a42d72c 100644
--- a/src/legacy/core_plugins/interpreter/public/functions/clog.js
+++ b/src/legacy/core_plugins/interpreter/public/functions/clog.ts
@@ -20,8 +20,8 @@
export const clog = () => ({
name: 'clog',
help: 'Outputs the context to the console',
- fn: context => {
- console.log(context); //eslint-disable-line no-console
+ fn: (context: any) => {
+ console.log(context); // eslint-disable-line no-console
return context;
},
});
diff --git a/src/legacy/core_plugins/interpreter/public/functions/font.test.ts b/src/legacy/core_plugins/interpreter/public/functions/font.test.ts
new file mode 100644
index 00000000000000..dba540178777bc
--- /dev/null
+++ b/src/legacy/core_plugins/interpreter/public/functions/font.test.ts
@@ -0,0 +1,202 @@
+/*
+ * 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 { openSans } from '../../common/lib/fonts';
+import { font } from './font';
+import { functionWrapper } from '../../test_helpers';
+
+describe('font', () => {
+ const fn: any = functionWrapper(font);
+
+ describe('default output', () => {
+ const result = fn(null);
+
+ it('returns a style', () => {
+ expect(result).toMatchObject({
+ type: 'style',
+ spec: expect.any(Object),
+ css: expect.any(String),
+ });
+ });
+ });
+
+ describe('args', () => {
+ describe('size', () => {
+ it('sets font size', () => {
+ const result = fn(null, { size: 20 });
+ expect(result).toMatchObject({
+ spec: {
+ fontSize: '20px',
+ },
+ });
+ expect(result.css).toContain('font-size:20px');
+ });
+
+ it('defaults to 14px', () => {
+ const result = fn(null);
+ expect(result).toMatchObject({
+ spec: {
+ fontSize: '14px',
+ },
+ });
+ expect(result.css).toContain('font-size:14px');
+ });
+ });
+
+ describe('lHeight', () => {
+ it('sets line height', () => {
+ const result = fn(null, { lHeight: 30 });
+ expect(result).toMatchObject({
+ spec: {
+ lineHeight: '30px',
+ },
+ });
+ expect(result.css).toContain('line-height:30px');
+ });
+
+ it('defaults to 1', () => {
+ const result = fn(null);
+ expect(result.spec.lineHeight).toBe('1');
+ expect(result.css).toContain('line-height:1');
+ });
+ });
+
+ describe('family', () => {
+ it('sets font family', () => {
+ const result = fn(null, { family: 'Optima, serif' });
+ expect(result.spec.fontFamily).toBe('Optima, serif');
+ expect(result.css).toContain('font-family:Optima, serif');
+ });
+
+ it(`defaults to "${openSans.value}"`, () => {
+ const result = fn(null);
+ expect(result.spec.fontFamily).toBe(`"${openSans.value}"`);
+ expect(result.css).toContain(`font-family:"${openSans.value}"`);
+ });
+ });
+
+ describe('color', () => {
+ it('sets font color', () => {
+ const result = fn(null, { color: 'blue' });
+ expect(result.spec.color).toBe('blue');
+ expect(result.css).toContain('color:blue');
+ });
+ });
+
+ describe('weight', () => {
+ it('sets font weight', () => {
+ let result = fn(null, { weight: 'normal' });
+ expect(result.spec.fontWeight).toBe('normal');
+ expect(result.css).toContain('font-weight:normal');
+
+ result = fn(null, { weight: 'bold' });
+ expect(result.spec.fontWeight).toBe('bold');
+ expect(result.css).toContain('font-weight:bold');
+
+ result = fn(null, { weight: 'bolder' });
+ expect(result.spec.fontWeight).toBe('bolder');
+ expect(result.css).toContain('font-weight:bolder');
+
+ result = fn(null, { weight: 'lighter' });
+ expect(result.spec.fontWeight).toBe('lighter');
+ expect(result.css).toContain('font-weight:lighter');
+
+ result = fn(null, { weight: '400' });
+ expect(result.spec.fontWeight).toBe('400');
+ expect(result.css).toContain('font-weight:400');
+ });
+
+ it("defaults to 'normal'", () => {
+ const result = fn(null);
+ expect(result.spec.fontWeight).toBe('normal');
+ expect(result.css).toContain('font-weight:normal');
+ });
+
+ it('throws when provided an invalid weight', () => {
+ expect(() => fn(null, { weight: 'foo' })).toThrow();
+ });
+ });
+
+ describe('underline', () => {
+ it('sets text underline', () => {
+ let result = fn(null, { underline: true });
+ expect(result.spec.textDecoration).toBe('underline');
+ expect(result.css).toContain('text-decoration:underline');
+
+ result = fn(null, { underline: false });
+ expect(result.spec.textDecoration).toBe('none');
+ expect(result.css).toContain('text-decoration:none');
+ });
+
+ it('defaults to false', () => {
+ const result = fn(null);
+ expect(result.spec.textDecoration).toBe('none');
+ expect(result.css).toContain('text-decoration:none');
+ });
+ });
+
+ describe('italic', () => {
+ it('sets italic', () => {
+ let result = fn(null, { italic: true });
+ expect(result.spec.fontStyle).toBe('italic');
+ expect(result.css).toContain('font-style:italic');
+
+ result = fn(null, { italic: false });
+ expect(result.spec.fontStyle).toBe('normal');
+ expect(result.css).toContain('font-style:normal');
+ });
+
+ it('defaults to false', () => {
+ const result = fn(null);
+ expect(result.spec.fontStyle).toBe('normal');
+ expect(result.css).toContain('font-style:normal');
+ });
+ });
+
+ describe('align', () => {
+ it('sets text alignment', () => {
+ let result = fn(null, { align: 'left' });
+ expect(result.spec.textAlign).toBe('left');
+ expect(result.css).toContain('text-align:left');
+
+ result = fn(null, { align: 'center' });
+ expect(result.spec.textAlign).toBe('center');
+ expect(result.css).toContain('text-align:center');
+
+ result = fn(null, { align: 'right' });
+ expect(result.spec.textAlign).toBe('right');
+ expect(result.css).toContain('text-align:right');
+
+ result = fn(null, { align: 'justify' });
+ expect(result.spec.textAlign).toBe('justify');
+ expect(result.css).toContain('text-align:justify');
+ });
+
+ it(`defaults to 'left'`, () => {
+ const result = fn(null);
+ expect(result.spec.textAlign).toBe('left');
+ expect(result.css).toContain('text-align:left');
+ });
+
+ it('throws when provided an invalid alignment', () => {
+ expect(() => fn(null, { align: 'foo' })).toThrow();
+ });
+ });
+ });
+});
diff --git a/src/legacy/core_plugins/interpreter/public/functions/index.js b/src/legacy/core_plugins/interpreter/public/functions/index.ts
similarity index 92%
rename from src/legacy/core_plugins/interpreter/public/functions/index.js
rename to src/legacy/core_plugins/interpreter/public/functions/index.ts
index 38c3920f91bd29..d86f033acb3d13 100644
--- a/src/legacy/core_plugins/interpreter/public/functions/index.js
+++ b/src/legacy/core_plugins/interpreter/public/functions/index.ts
@@ -27,5 +27,12 @@ import { visualization } from './visualization';
import { visDimension } from './vis_dimension';
export const functions = [
- clog, esaggs, font, kibana, kibanaContext, range, visualization, visDimension,
+ clog,
+ esaggs,
+ font,
+ kibana,
+ kibanaContext,
+ range,
+ visualization,
+ visDimension,
];
diff --git a/src/legacy/core_plugins/interpreter/public/functions/kibana.test.js b/src/legacy/core_plugins/interpreter/public/functions/kibana.test.ts
similarity index 97%
rename from src/legacy/core_plugins/interpreter/public/functions/kibana.test.js
rename to src/legacy/core_plugins/interpreter/public/functions/kibana.test.ts
index 4757b9b12b50da..9f80449ac36be4 100644
--- a/src/legacy/core_plugins/interpreter/public/functions/kibana.test.js
+++ b/src/legacy/core_plugins/interpreter/public/functions/kibana.test.ts
@@ -22,9 +22,9 @@ import { kibana } from './kibana';
describe('interpreter/functions#kibana', () => {
const fn = functionWrapper(kibana);
- let context;
- let initialContext;
- let handlers;
+ let context: any;
+ let initialContext: any;
+ let handlers: any;
beforeEach(() => {
context = { timeRange: { from: '0', to: '1' } };
diff --git a/src/legacy/core_plugins/interpreter/public/functions/kibana.js b/src/legacy/core_plugins/interpreter/public/functions/kibana.ts
similarity index 93%
rename from src/legacy/core_plugins/interpreter/public/functions/kibana.js
rename to src/legacy/core_plugins/interpreter/public/functions/kibana.ts
index e0817d8e04b026..37ff337f58b8d4 100644
--- a/src/legacy/core_plugins/interpreter/public/functions/kibana.js
+++ b/src/legacy/core_plugins/interpreter/public/functions/kibana.ts
@@ -24,10 +24,10 @@ export const kibana = () => ({
type: 'kibana_context',
context: {},
help: i18n.translate('interpreter.functions.kibana.help', {
- defaultMessage: 'Gets kibana global context'
+ defaultMessage: 'Gets kibana global context',
}),
args: {},
- fn(context, args, handlers) {
+ fn(context: any, args: any, handlers: any) {
const initialContext = handlers.getInitialContext ? handlers.getInitialContext() : {};
if (context.query) {
@@ -45,7 +45,7 @@ export const kibana = () => ({
type: 'kibana_context',
query: initialContext.query,
filters: initialContext.filters,
- timeRange: timeRange,
+ timeRange,
};
},
});
diff --git a/src/legacy/core_plugins/interpreter/public/functions/kibana_context.js b/src/legacy/core_plugins/interpreter/public/functions/kibana_context.ts
similarity index 87%
rename from src/legacy/core_plugins/interpreter/public/functions/kibana_context.js
rename to src/legacy/core_plugins/interpreter/public/functions/kibana_context.ts
index 7b7294a87831d6..2f2241a3670945 100644
--- a/src/legacy/core_plugins/interpreter/public/functions/kibana_context.js
+++ b/src/legacy/core_plugins/interpreter/public/functions/kibana_context.ts
@@ -24,13 +24,10 @@ export const kibanaContext = () => ({
name: 'kibana_context',
type: 'kibana_context',
context: {
- types: [
- 'kibana_context',
- 'null',
- ],
+ types: ['kibana_context', 'null'],
},
help: i18n.translate('interpreter.functions.kibana_context.help', {
- defaultMessage: 'Updates kibana global context'
+ defaultMessage: 'Updates kibana global context',
}),
args: {
q: {
@@ -49,11 +46,11 @@ export const kibanaContext = () => ({
savedSearchId: {
types: ['string', 'null'],
default: null,
- }
+ },
},
- async fn(context, args) {
+ async fn(context: any, args: any) {
const $injector = await chrome.dangerouslyGetActiveInjector();
- const savedSearches = $injector.get('savedSearches');
+ const savedSearches = $injector.get('savedSearches') as any;
const queryArg = args.q ? JSON.parse(args.q) : [];
let queries = Array.isArray(queryArg) ? queryArg : [queryArg];
let filters = args.filters ? JSON.parse(args.filters) : [];
@@ -71,7 +68,7 @@ export const kibanaContext = () => ({
}
if (context.filters) {
- filters = filters.concat(context.filters).filter(f => !f.meta.disabled);
+ filters = filters.concat(context.filters).filter((f: any) => !f.meta.disabled);
}
const timeRange = args.timeRange ? JSON.parse(args.timeRange) : context.timeRange;
@@ -79,8 +76,8 @@ export const kibanaContext = () => ({
return {
type: 'kibana_context',
query: queries,
- filters: filters,
- timeRange: timeRange,
+ filters,
+ timeRange,
};
},
});
diff --git a/src/legacy/core_plugins/interpreter/public/functions/vis_dimension.js b/src/legacy/core_plugins/interpreter/public/functions/vis_dimension.ts
similarity index 74%
rename from src/legacy/core_plugins/interpreter/public/functions/vis_dimension.js
rename to src/legacy/core_plugins/interpreter/public/functions/vis_dimension.ts
index e1a6c41198bad4..19503dbe03ae98 100644
--- a/src/legacy/core_plugins/interpreter/public/functions/vis_dimension.js
+++ b/src/legacy/core_plugins/interpreter/public/functions/vis_dimension.ts
@@ -22,48 +22,48 @@ import { i18n } from '@kbn/i18n';
export const visDimension = () => ({
name: 'visdimension',
help: i18n.translate('interpreter.function.visDimension.help', {
- defaultMessage: 'Generates visConfig dimension object'
+ defaultMessage: 'Generates visConfig dimension object',
}),
type: 'vis_dimension',
context: {
- types: [
- 'kibana_datatable'
- ],
+ types: ['kibana_datatable'],
},
args: {
accessor: {
types: ['string', 'number'],
aliases: ['_'],
help: i18n.translate('interpreter.function.visDimension.accessor.help', {
- defaultMessage: 'Column in your dataset to use (either column index or column name)'
+ defaultMessage: 'Column in your dataset to use (either column index or column name)',
}),
},
format: {
types: ['string'],
- default: 'string'
+ default: 'string',
},
formatParams: {
types: ['string'],
default: '"{}"',
- }
+ },
},
- fn: (context, args) => {
- const accessor = Number.isInteger(args.accessor) ?
- args.accessor :
- context.columns.find(c => c.id === args.accessor);
+ fn: (context: any, args: any) => {
+ const accessor = Number.isInteger(args.accessor)
+ ? args.accessor
+ : context.columns.find((c: any) => c.id === args.accessor);
if (accessor === undefined) {
- throw new Error(i18n.translate('interpreter.function.visDimension.error.accessor', {
- defaultMessage: 'Column name provided is invalid'
- }));
+ throw new Error(
+ i18n.translate('interpreter.function.visDimension.error.accessor', {
+ defaultMessage: 'Column name provided is invalid',
+ })
+ );
}
return {
type: 'vis_dimension',
- accessor: accessor,
+ accessor,
format: {
id: args.format,
params: JSON.parse(args.formatParams),
- }
+ },
};
},
});
diff --git a/src/legacy/core_plugins/interpreter/public/functions/visualization.js b/src/legacy/core_plugins/interpreter/public/functions/visualization.ts
similarity index 90%
rename from src/legacy/core_plugins/interpreter/public/functions/visualization.js
rename to src/legacy/core_plugins/interpreter/public/functions/visualization.ts
index 7dceeaf6843540..d46044b544c419 100644
--- a/src/legacy/core_plugins/interpreter/public/functions/visualization.js
+++ b/src/legacy/core_plugins/interpreter/public/functions/visualization.ts
@@ -20,17 +20,16 @@
import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
import chrome from 'ui/chrome';
-import { setup as data } from '../../../data/public/legacy';
-import { start as visualizations } from '../../../visualizations/public/legacy';
-
import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter';
import { PersistedState } from 'ui/persisted_state';
+import { setup as data } from '../../../data/public/legacy';
+import { start as visualizations } from '../../../visualizations/public/np_ready/public/legacy';
export const visualization = () => ({
name: 'visualization',
type: 'render',
help: i18n.translate('interpreter.functions.visualization.help', {
- defaultMessage: 'A simple visualization'
+ defaultMessage: 'A simple visualization',
}),
args: {
index: {
@@ -60,17 +59,17 @@ export const visualization = () => ({
uiState: {
types: ['string'],
default: '"{}"',
- }
+ },
},
- async fn(context, args, handlers) {
+ async fn(context: any, args: any, handlers: any) {
const $injector = await chrome.dangerouslyGetActiveInjector();
- const Private = $injector.get('Private');
+ const Private = $injector.get('Private') as any;
const { indexPatterns } = data.indexPatterns;
const queryFilter = Private(FilterBarQueryFilterProvider);
const visConfigParams = JSON.parse(args.visConfig);
const schemas = JSON.parse(args.schemas);
- const visType = visualizations.types.get(args.type || 'histogram');
+ const visType = visualizations.types.get(args.type || 'histogram') as any;
const indexPattern = args.index ? await indexPatterns.get(args.index) : null;
const uiStateParams = JSON.parse(args.uiState);
@@ -85,7 +84,7 @@ export const visualization = () => ({
timeRange: get(context, 'timeRange', null),
query: get(context, 'query', null),
filters: get(context, 'filters', null),
- uiState: uiState,
+ uiState,
inspectorAdapters: handlers.inspectorAdapters,
queryFilter,
forceFetch: true,
@@ -95,14 +94,14 @@ export const visualization = () => ({
if (typeof visType.responseHandler === 'function') {
if (context.columns) {
// assign schemas to aggConfigs
- context.columns.forEach(column => {
+ context.columns.forEach((column: any) => {
if (column.aggConfig) {
column.aggConfig.aggConfigs.schemas = visType.schemas.all;
}
});
Object.keys(schemas).forEach(key => {
- schemas[key].forEach(i => {
+ schemas[key].forEach((i: any) => {
if (context.columns[i] && context.columns[i].aggConfig) {
context.columns[i].aggConfig.schema = key;
}
@@ -119,8 +118,8 @@ export const visualization = () => ({
value: {
visData: context,
visType: args.type,
- visConfig: visConfigParams
- }
+ visConfig: visConfigParams,
+ },
};
- }
+ },
});
diff --git a/src/legacy/core_plugins/interpreter/public/interpreter.test.js b/src/legacy/core_plugins/interpreter/public/interpreter.test.ts
similarity index 96%
rename from src/legacy/core_plugins/interpreter/public/interpreter.test.js
rename to src/legacy/core_plugins/interpreter/public/interpreter.test.ts
index bd7dc0a47c1240..1de1e8c0cc0598 100644
--- a/src/legacy/core_plugins/interpreter/public/interpreter.test.js
+++ b/src/legacy/core_plugins/interpreter/public/interpreter.test.ts
@@ -24,9 +24,9 @@ jest.mock('ui/new_platform', () => ({
injectedMetadata: {
getKibanaVersion: () => '8.0.0',
getBasePath: () => '/lol',
- }
- }
- }
+ },
+ },
+ },
}));
jest.mock('uiExports/interpreter');
@@ -38,7 +38,7 @@ jest.mock('@kbn/interpreter/common', () => ({
const mockInterpreter = {
interpreter: {
interpretAst: jest.fn(),
- }
+ },
};
jest.mock('./lib/interpreter', () => ({
initializeInterpreter: jest.fn().mockReturnValue(Promise.resolve(mockInterpreter)),
@@ -57,9 +57,9 @@ jest.mock('./functions', () => ({ functions: [{}, {}, {}] }));
jest.mock('./renderers/visualization', () => ({ visualization: {} }));
describe('interpreter/interpreter', () => {
- let getInterpreter;
- let interpretAst;
- let initializeInterpreter;
+ let getInterpreter: any;
+ let interpretAst: any;
+ let initializeInterpreter: any;
beforeEach(() => {
jest.clearAllMocks();
@@ -117,5 +117,4 @@ describe('interpreter/interpreter', () => {
expect(mockInterpreter.interpreter.interpretAst).toHaveBeenCalledTimes(2);
});
});
-
});
diff --git a/src/legacy/core_plugins/interpreter/public/interpreter.js b/src/legacy/core_plugins/interpreter/public/interpreter.ts
similarity index 87%
rename from src/legacy/core_plugins/interpreter/public/interpreter.js
rename to src/legacy/core_plugins/interpreter/public/interpreter.ts
index 84e05bb10d9fa6..8ba82d5daf759a 100644
--- a/src/legacy/core_plugins/interpreter/public/interpreter.js
+++ b/src/legacy/core_plugins/interpreter/public/interpreter.ts
@@ -18,6 +18,7 @@
*/
import 'uiExports/interpreter';
+// @ts-ignore
import { register, registryFactory } from '@kbn/interpreter/common';
import { initializeInterpreter } from './lib/interpreter';
import { registries } from './registries';
@@ -27,7 +28,10 @@ import { typeSpecs } from '../../../../plugins/expressions/common';
// Expose kbnInterpreter.register(specs) and kbnInterpreter.registries() globally so that plugins
// can register without a transpile step.
-global.kbnInterpreter = Object.assign(global.kbnInterpreter || {}, registryFactory(registries));
+(global as any).kbnInterpreter = Object.assign(
+ (global as any).kbnInterpreter || {},
+ registryFactory(registries)
+);
register(registries, {
types: typeSpecs,
@@ -35,7 +39,7 @@ register(registries, {
renderers: [visualization],
});
-let interpreterPromise;
+let interpreterPromise: Promise | undefined;
export const getInterpreter = async () => {
if (!interpreterPromise) {
@@ -44,7 +48,7 @@ export const getInterpreter = async () => {
return await interpreterPromise;
};
-export const interpretAst = async (...params) => {
+export const interpretAst = async (...params: any) => {
const { interpreter } = await getInterpreter();
return await interpreter.interpretAst(...params);
};
diff --git a/src/legacy/core_plugins/interpreter/public/lib/render_function.js b/src/legacy/core_plugins/interpreter/public/lib/render_function.ts
similarity index 92%
rename from src/legacy/core_plugins/interpreter/public/lib/render_function.js
rename to src/legacy/core_plugins/interpreter/public/lib/render_function.ts
index 04aa05951be70f..76d1f58b661950 100644
--- a/src/legacy/core_plugins/interpreter/public/lib/render_function.js
+++ b/src/legacy/core_plugins/interpreter/public/lib/render_function.ts
@@ -17,7 +17,7 @@
* under the License.
*/
-export function RenderFunction(config) {
+export function RenderFunction(this: any, config: any) {
// This must match the name of the function that is used to create the `type: render` object
this.name = config.name;
@@ -36,7 +36,7 @@ export function RenderFunction(config) {
// the function called to render the data
this.render =
config.render ||
- function render(domNode, data, done) {
+ function render(domNode: any, data: any, done: any) {
done();
};
}
diff --git a/src/legacy/core_plugins/interpreter/public/lib/render_functions_registry.js b/src/legacy/core_plugins/interpreter/public/lib/render_functions_registry.ts
similarity index 88%
rename from src/legacy/core_plugins/interpreter/public/lib/render_functions_registry.js
rename to src/legacy/core_plugins/interpreter/public/lib/render_functions_registry.ts
index 60e823baf0fa78..427e7f7454c24e 100644
--- a/src/legacy/core_plugins/interpreter/public/lib/render_functions_registry.js
+++ b/src/legacy/core_plugins/interpreter/public/lib/render_functions_registry.ts
@@ -20,9 +20,9 @@
import { Registry } from '@kbn/interpreter/common';
import { RenderFunction } from './render_function';
-class RenderFunctionsRegistry extends Registry {
- wrapper(obj) {
- return new RenderFunction(obj);
+class RenderFunctionsRegistry extends Registry {
+ wrapper(obj: any) {
+ return new (RenderFunction as any)(obj);
}
}
diff --git a/src/legacy/core_plugins/interpreter/public/renderers/visualization.js b/src/legacy/core_plugins/interpreter/public/renderers/visualization.ts
similarity index 84%
rename from src/legacy/core_plugins/interpreter/public/renderers/visualization.js
rename to src/legacy/core_plugins/interpreter/public/renderers/visualization.ts
index 38fe02436380c7..960e925b132213 100644
--- a/src/legacy/core_plugins/interpreter/public/renderers/visualization.js
+++ b/src/legacy/core_plugins/interpreter/public/renderers/visualization.ts
@@ -19,17 +19,18 @@
import chrome from 'ui/chrome';
import { visualizationLoader } from 'ui/visualize/loader/visualization_loader';
+// @ts-ignore
import { VisProvider } from 'ui/visualize/loader/vis';
export const visualization = () => ({
name: 'visualization',
displayName: 'visualization',
reuseDomNode: true,
- render: async (domNode, config, handlers) => {
+ render: async (domNode: HTMLElement, config: any, handlers: any) => {
const { visData, visConfig, params } = config;
const visType = config.visType || visConfig.type;
const $injector = await chrome.dangerouslyGetActiveInjector();
- const Private = $injector.get('Private');
+ const Private = $injector.get('Private') as any;
const Vis = Private(VisProvider);
if (handlers.vis) {
@@ -49,8 +50,10 @@ export const visualization = () => ({
handlers.onDestroy(() => visualizationLoader.destroy());
- await visualizationLoader.render(domNode, handlers.vis, visData, handlers.vis.params, uiState, params).then(() => {
- if (handlers.done) handlers.done();
- });
+ await visualizationLoader
+ .render(domNode, handlers.vis, visData, handlers.vis.params, uiState, params)
+ .then(() => {
+ if (handlers.done) handlers.done();
+ });
},
});
diff --git a/src/legacy/core_plugins/interpreter/server/lib/__tests__/create_handlers.js b/src/legacy/core_plugins/interpreter/server/lib/__tests__/create_handlers.ts
similarity index 95%
rename from src/legacy/core_plugins/interpreter/server/lib/__tests__/create_handlers.js
rename to src/legacy/core_plugins/interpreter/server/lib/__tests__/create_handlers.ts
index a6e0e13049e1c9..00886630807748 100644
--- a/src/legacy/core_plugins/interpreter/server/lib/__tests__/create_handlers.js
+++ b/src/legacy/core_plugins/interpreter/server/lib/__tests__/create_handlers.ts
@@ -28,13 +28,13 @@ const mockServer = {
plugins: {
elasticsearch: {
getCluster: () => ({
- callWithRequest: (...args) => Promise.resolve(args),
+ callWithRequest: (...args: any) => Promise.resolve(args),
}),
},
},
config: () => ({
has: () => false,
- get: val => val,
+ get: (val: any) => val,
}),
info: {
uri: 'serveruri',
diff --git a/src/legacy/core_plugins/interpreter/server/lib/create_handlers.js b/src/legacy/core_plugins/interpreter/server/lib/create_handlers.ts
similarity index 88%
rename from src/legacy/core_plugins/interpreter/server/lib/create_handlers.js
rename to src/legacy/core_plugins/interpreter/server/lib/create_handlers.ts
index d4ea9b3dc6180f..6e295d0aecaa59 100644
--- a/src/legacy/core_plugins/interpreter/server/lib/create_handlers.js
+++ b/src/legacy/core_plugins/interpreter/server/lib/create_handlers.ts
@@ -17,7 +17,7 @@
* under the License.
*/
-export const createHandlers = (request, server) => {
+export const createHandlers = (request: any, server: any) => {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('data');
const config = server.config();
@@ -27,6 +27,6 @@ export const createHandlers = (request, server) => {
config.has('server.rewriteBasePath') && config.get('server.rewriteBasePath')
? `${server.info.uri}${config.get('server.basePath')}`
: server.info.uri,
- elasticsearchClient: async (...args) => callWithRequest(request, ...args),
+ elasticsearchClient: async (...args: any) => callWithRequest(request, ...args),
};
};
diff --git a/src/legacy/core_plugins/interpreter/server/routes/index.js b/src/legacy/core_plugins/interpreter/server/routes/index.ts
similarity index 95%
rename from src/legacy/core_plugins/interpreter/server/routes/index.js
rename to src/legacy/core_plugins/interpreter/server/routes/index.ts
index 9140f93a9bde64..50385147dd38e6 100644
--- a/src/legacy/core_plugins/interpreter/server/routes/index.js
+++ b/src/legacy/core_plugins/interpreter/server/routes/index.ts
@@ -19,6 +19,6 @@
import { registerServerFunctions } from './server_functions';
-export function routes(server) {
+export function routes(server: any) {
registerServerFunctions(server);
}
diff --git a/src/legacy/core_plugins/interpreter/server/routes/server_functions.js b/src/legacy/core_plugins/interpreter/server/routes/server_functions.ts
similarity index 84%
rename from src/legacy/core_plugins/interpreter/server/routes/server_functions.js
rename to src/legacy/core_plugins/interpreter/server/routes/server_functions.ts
index b64a9af006e412..740b046610d9e9 100644
--- a/src/legacy/core_plugins/interpreter/server/routes/server_functions.js
+++ b/src/legacy/core_plugins/interpreter/server/routes/server_functions.ts
@@ -18,16 +18,16 @@
*/
import Boom from 'boom';
+import Joi from 'joi';
import { serializeProvider, API_ROUTE } from '../../common';
import { createHandlers } from '../lib/create_handlers';
-import Joi from 'joi';
/**
* Register the Canvas function endopints.
*
* @param {*} server - The Kibana server
*/
-export function registerServerFunctions(server) {
+export function registerServerFunctions(server: any) {
getServerFunctions(server);
runServerFunctions(server);
}
@@ -37,7 +37,7 @@ export function registerServerFunctions(server) {
*
* @param {*} server - The Kibana server
*/
-function runServerFunctions(server) {
+function runServerFunctions(server: any) {
server.route({
method: 'POST',
path: `${API_ROUTE}/fns`,
@@ -48,19 +48,20 @@ function runServerFunctions(server) {
},
validate: {
payload: Joi.object({
- functions: Joi.array().items(
- Joi.object()
- .keys({
+ functions: Joi.array()
+ .items(
+ Joi.object().keys({
id: Joi.number().required(),
functionName: Joi.string().required(),
args: Joi.object().default({}),
context: Joi.any().default(null),
- }),
- ).required(),
+ })
+ )
+ .required(),
}).required(),
},
},
- async handler(req) {
+ async handler(req: any) {
const handlers = await createHandlers(req, server);
const { functions } = req.payload;
@@ -73,19 +74,19 @@ function runServerFunctions(server) {
// Send the initial headers.
res.writeHead(200, {
'Content-Type': 'text/plain',
- 'Connection': 'keep-alive',
+ Connection: 'keep-alive',
'Transfer-Encoding': 'chunked',
'Cache-Control': 'no-cache',
});
// Write a length-delimited response
- const streamResult = (result) => {
+ const streamResult = (result: any) => {
const payload = JSON.stringify(result) + '\n';
res.write(`${payload.length}:${payload}`);
};
// Tries to run an interpreter function, and ensures a consistent error payload on failure.
- const tryFunction = async (id, fnCall) => {
+ const tryFunction = async (id: any, fnCall: any) => {
try {
const result = await runFunction(server, handlers, fnCall);
@@ -96,7 +97,7 @@ function runServerFunctions(server) {
return { id, statusCode: 200, result };
} catch (err) {
if (Boom.isBoom(err)) {
- return batchError(id, err.output.payload, err.statusCode);
+ return batchError(id, err.output.payload, (err as any).statusCode);
} else if (err instanceof Error) {
return batchError(id, err.message);
}
@@ -107,7 +108,9 @@ function runServerFunctions(server) {
};
// Process each function individually, and stream the responses back to the client
- await Promise.all(functions.map(({ id, ...fnCall }) => tryFunction(id, fnCall).then(streamResult)));
+ await Promise.all(
+ functions.map(({ id, ...fnCall }: any) => tryFunction(id, fnCall).then(streamResult))
+ );
// All of the responses have been written, so we can close the response.
res.end();
@@ -118,7 +121,7 @@ function runServerFunctions(server) {
/**
* A helper function for bundling up errors.
*/
-function batchError(id, message, statusCode = 500) {
+function batchError(id: any, message: any, statusCode = 500) {
return {
id,
statusCode,
@@ -130,7 +133,7 @@ function batchError(id, message, statusCode = 500) {
* Register the endpoint that returns the list of server-only functions.
* @param {*} server - The Kibana server
*/
-function getServerFunctions(server) {
+function getServerFunctions(server: any) {
server.route({
method: 'GET',
path: `${API_ROUTE}/fns`,
@@ -147,7 +150,7 @@ function getServerFunctions(server) {
* @param {*} handlers - The Canvas handlers
* @param {*} fnCall - Describes the function being run `{ functionName, args, context }`
*/
-async function runFunction(server, handlers, fnCall) {
+async function runFunction(server: any, handlers: any, fnCall: any) {
const registries = server.plugins.interpreter.registries();
const { functionName, args, context } = fnCall;
const types = registries.types.toJS();
diff --git a/src/legacy/core_plugins/interpreter/test_helpers.js b/src/legacy/core_plugins/interpreter/test_helpers.ts
similarity index 86%
rename from src/legacy/core_plugins/interpreter/test_helpers.js
rename to src/legacy/core_plugins/interpreter/test_helpers.ts
index e743b8a09280e2..741cd83bb47fed 100644
--- a/src/legacy/core_plugins/interpreter/test_helpers.js
+++ b/src/legacy/core_plugins/interpreter/test_helpers.ts
@@ -21,8 +21,9 @@ import { mapValues } from 'lodash';
// Takes a function spec and passes in default args,
// overriding with any provided args.
-export const functionWrapper = fnSpec => {
+export const functionWrapper = (fnSpec: any) => {
const spec = fnSpec();
const defaultArgs = mapValues(spec.args, argSpec => argSpec.default);
- return (context, args, handlers) => spec.fn(context, { ...defaultArgs, ...args }, handlers);
+ return (context: any, args: any, handlers: any) =>
+ spec.fn(context, { ...defaultArgs, ...args }, handlers);
};
diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/gauge/labels_panel.tsx b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/gauge/labels_panel.tsx
index a24a37ca971d58..b96132fa29380f 100644
--- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/gauge/labels_panel.tsx
+++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/gauge/labels_panel.tsx
@@ -29,12 +29,12 @@ function LabelsPanel({ stateParams, setValue, setGaugeValue }: GaugeOptionsInter
return (
-
+
-
+
diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/gauge/ranges_panel.tsx b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/gauge/ranges_panel.tsx
index 4abfb2e604b1dc..4e3b511782c9e7 100644
--- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/gauge/ranges_panel.tsx
+++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/gauge/ranges_panel.tsx
@@ -38,12 +38,12 @@ function RangesPanel({
return (
-
+
-
+
diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/gauge/style_panel.tsx b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/gauge/style_panel.tsx
index f606080afbdb2f..a76171673d9a82 100644
--- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/gauge/style_panel.tsx
+++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/gauge/style_panel.tsx
@@ -34,12 +34,12 @@ function StylePanel({ aggs, setGaugeValue, stateParams, vis }: GaugeOptionsInter
return (
-
+
-
+
diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/metrics_axes/__snapshots__/category_axis_panel.test.tsx.snap b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/metrics_axes/__snapshots__/category_axis_panel.test.tsx.snap
index 6eef5047634f4f..d88654cfdc0c43 100644
--- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/metrics_axes/__snapshots__/category_axis_panel.test.tsx.snap
+++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/metrics_axes/__snapshots__/category_axis_panel.test.tsx.snap
@@ -7,13 +7,13 @@ exports[`CategoryAxisPanel component should init with the default set of props 1
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/metrics_axes/series_panel.tsx b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/metrics_axes/series_panel.tsx
index 434202d64d6c30..5a455f4adde31f 100644
--- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/metrics_axes/series_panel.tsx
+++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/metrics_axes/series_panel.tsx
@@ -38,12 +38,12 @@ function SeriesPanel(props: SeriesPanelProps) {
return (
-
+
-
+
diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/metrics_axes/value_axes_panel.tsx b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/metrics_axes/value_axes_panel.tsx
index 34a0d2cd981c5f..eb0ab4333af599 100644
--- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/metrics_axes/value_axes_panel.tsx
+++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/metrics_axes/value_axes_panel.tsx
@@ -109,12 +109,12 @@ function ValueAxesPanel(props: ValueAxesPanelProps) {
-
+
-
+
diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/pie.tsx b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/pie.tsx
index 982c7265d5494c..53dde185ec09fe 100644
--- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/pie.tsx
+++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/pie.tsx
@@ -36,12 +36,12 @@ function PieOptions(props: VisOptionsProps) {
<>
-
+
-
+
) {
-
+
-
+
-
+
-
+
diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/point_series/point_series.tsx b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/point_series/point_series.tsx
index 11034f7f7335e4..8e3f66d12b9bdf 100644
--- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/point_series/point_series.tsx
+++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/point_series/point_series.tsx
@@ -34,12 +34,12 @@ function PointSeriesOptions(props: VisOptionsProps) {
<>
-
+
-
+
diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/point_series/threshold_panel.tsx b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/point_series/threshold_panel.tsx
index 9877b84345a1fe..49e56e377a8d56 100644
--- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/point_series/threshold_panel.tsx
+++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/components/options/point_series/threshold_panel.tsx
@@ -42,12 +42,12 @@ function ThresholdPanel({ stateParams, setValue, vis }: VisOptionsProps
-
+
-
+
diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/kbn_vislib_vis_types.js b/src/legacy/core_plugins/kbn_vislib_vis_types/public/kbn_vislib_vis_types.js
index b11f21a96f38da..fe2cca3b800641 100644
--- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/kbn_vislib_vis_types.js
+++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/kbn_vislib_vis_types.js
@@ -17,7 +17,7 @@
* under the License.
*/
-import { setup as visualizations } from '../../visualizations/public/legacy';
+import { setup as visualizations } from '../../visualizations/public/np_ready/public/legacy';
import histogramVisTypeProvider from './histogram';
import lineVisTypeProvider from './line';
diff --git a/src/legacy/core_plugins/kibana/common/field_formats/types/boolean.js b/src/legacy/core_plugins/kibana/common/field_formats/types/boolean.ts
similarity index 82%
rename from src/legacy/core_plugins/kibana/common/field_formats/types/boolean.js
rename to src/legacy/core_plugins/kibana/common/field_formats/types/boolean.ts
index 0e1e1ecf058b9e..c232f65143d859 100644
--- a/src/legacy/core_plugins/kibana/common/field_formats/types/boolean.js
+++ b/src/legacy/core_plugins/kibana/common/field_formats/types/boolean.ts
@@ -17,11 +17,19 @@
* under the License.
*/
-import { asPrettyString } from '../../../../../../plugins/data/common/field_formats';
+import {
+ FieldFormat,
+ asPrettyString,
+ KBN_FIELD_TYPES,
+} from '../../../../../../plugins/data/common';
-export function createBoolFormat(FieldFormat) {
+export function createBoolFormat() {
return class BoolFormat extends FieldFormat {
- _convert(value) {
+ static id = 'boolean';
+ static title = 'Boolean';
+ static fieldType = [KBN_FIELD_TYPES.BOOLEAN, KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.STRING];
+
+ _convert(value: any): string {
if (typeof value === 'string') {
value = value.trim().toLowerCase();
}
@@ -41,9 +49,5 @@ export function createBoolFormat(FieldFormat) {
return asPrettyString(value);
}
}
-
- static id = 'boolean';
- static title = 'Boolean';
- static fieldType = ['boolean', 'number', 'string'];
};
}
diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app.html b/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app.html
index 5ceb28e6b225b8..39db357a69321f 100644
--- a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app.html
+++ b/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app.html
@@ -120,6 +120,7 @@
+