Skip to content

Commit

Permalink
Consolidate TimeRange, Query and Filter types. Stop exporting/importi…
Browse files Browse the repository at this point in the history
…ng from embeddables. (elastic#39074) (elastic#39267)
  • Loading branch information
stacey-gammon authored Jun 19, 2019
1 parent 36f094b commit 924c837
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ import { Ast } from '@kbn/interpreter/common';
// the interpreter plugin itself once they are ready
import { Registry } from '@kbn/interpreter/common';
import { Adapters } from 'ui/inspector';
import { Query, Filters, TimeRange } from 'ui/embeddable';
import { TimeRange } from 'ui/timefilter/time_history';
import { Filter } from '@kbn/es-query';
import { createRenderer } from './expression_renderer';
import { createRunFn } from './expression_runner';
import { Query } from '../query';

export interface InitialContextObject {
timeRange?: TimeRange;
filters?: Filters;
filters?: Filter[];
query?: Query;
}

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/embeddable_api/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export {
isErrorEmbeddable,
} from './embeddables';

export { Query, TimeRange, ViewMode, QueryLanguageType, Trigger, IRegistry } from './types';
export { ViewMode, Trigger, IRegistry } from './types';

export { actionRegistry, Action, ActionContext, IncompatibleActionError } from './actions';

Expand Down
14 changes: 0 additions & 14 deletions src/legacy/core_plugins/embeddable_api/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,3 @@ export enum ViewMode {
EDIT = 'edit',
VIEW = 'view',
}
export interface TimeRange {
to: string;
from: string;
}

export enum QueryLanguageType {
KUERY = 'kuery',
LUCENE = 'lucene',
}

export interface Query {
language: QueryLanguageType;
query: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
* under the License.
*/

import { Filters, Query, TimeRange } from 'ui/visualize';
import { Query } from 'src/legacy/core_plugins/data/public';
import { TimeRange } from 'ui/timefilter/time_history';
import { Filter } from '@kbn/es-query';

const name = 'kibana_context';

export interface KibanaContext {
type: typeof name;
query?: Query;
filters?: Filters;
filters?: Filter[];
timeRange?: TimeRange;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
/* eslint-disable @typescript-eslint/no-empty-interface */

import { createAction } from 'redux-actions';
import { Filters, Query, TimeRange } from 'ui/embeddable';
import { RefreshInterval } from 'ui/timefilter/timefilter';
import { TimeRange } from 'ui/timefilter/time_history';
import { Filter } from '@kbn/es-query';
import { Query } from 'src/legacy/core_plugins/data/public';
import { KibanaAction } from '../../selectors/types';
import { DashboardViewMode } from '../dashboard_view_mode';
import { PanelId } from '../selectors';
Expand Down Expand Up @@ -72,7 +74,7 @@ export interface UpdateRefreshConfigAction
extends KibanaAction<ViewActionTypeKeys.UPDATE_REFRESH_CONFIG, RefreshInterval> {}

export interface UpdateFiltersAction
extends KibanaAction<ViewActionTypeKeys.UPDATE_FILTERS, Filters> {}
extends KibanaAction<ViewActionTypeKeys.UPDATE_FILTERS, Filter[]> {}

export interface UpdateQueryAction extends KibanaAction<ViewActionTypeKeys.UPDATE_QUERY, Query> {}

Expand Down Expand Up @@ -108,5 +110,5 @@ export const updateTimeRange = createAction<TimeRange>(ViewActionTypeKeys.UPDATE
export const updateRefreshConfig = createAction<RefreshInterval>(
ViewActionTypeKeys.UPDATE_REFRESH_CONFIG
);
export const updateFilters = createAction<Filters>(ViewActionTypeKeys.UPDATE_FILTERS);
export const updateFilters = createAction<Filter[]>(ViewActionTypeKeys.UPDATE_FILTERS);
export const updateQuery = createAction<Query | string>(ViewActionTypeKeys.UPDATE_QUERY);
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import * as filterActions from 'plugins/kibana/discover/doc_table/actions/filter
// @ts-ignore
import { FilterManagerProvider } from 'ui/filter_manager';
import { EmbeddableFactoriesRegistryProvider } from 'ui/embeddable/embeddable_factories_registry';
import { ContextMenuActionsRegistryProvider, Query, EmbeddableFactory } from 'ui/embeddable';
import { ContextMenuActionsRegistryProvider, EmbeddableFactory } from 'ui/embeddable';
import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
import { timefilter } from 'ui/timefilter';

Expand All @@ -63,7 +63,7 @@ import { Filter } from '@kbn/es-query';
import { TimeRange } from 'ui/timefilter/time_history';
import { IndexPattern } from 'ui/index_patterns';
import { IPrivate } from 'ui/private';
import { StaticIndexPattern } from 'src/legacy/core_plugins/data/public';
import { StaticIndexPattern, Query } from 'src/legacy/core_plugins/data/public';
import { SaveOptions } from 'ui/saved_objects/saved_object';
import moment from 'moment';
import { SavedObjectDashboard } from './saved_dashboard/saved_dashboard';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import _ from 'lodash';
import { stateMonitorFactory, StateMonitor } from 'ui/state_management/state_monitor_factory';
import { StaticIndexPattern } from 'ui/index_patterns';
import { AppStateClass as TAppStateClass } from 'ui/state_management/app_state';
import { TimeRange, Query } from 'ui/embeddable';
import { Timefilter } from 'ui/timefilter';
import { Filter } from '@kbn/es-query';
import moment from 'moment';
import { RefreshInterval } from 'ui/timefilter/timefilter';
import { Query } from 'src/legacy/core_plugins/data/public';
import { TimeRange } from 'ui/timefilter/time_history';
import { DashboardViewMode } from './dashboard_view_mode';
import { FilterUtils } from './lib/filter_utils';
import { PanelUtils } from './panel/panel_utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
import { cloneDeep } from 'lodash';
import { Reducer } from 'redux';

import { Filters, Query, TimeRange } from 'ui/embeddable';
import { QueryLanguageType } from 'ui/embeddable/types';
import { RefreshInterval } from 'ui/timefilter/timefilter';
import { TimeRange } from 'ui/timefilter/time_history';
import { Filter } from '@kbn/es-query';
import { Query } from 'src/legacy/core_plugins/data/public';
import { ViewActions, ViewActionTypeKeys } from '../actions';
import { DashboardViewMode } from '../dashboard_view_mode';
import { PanelId, ViewState } from '../selectors';
Expand Down Expand Up @@ -67,7 +68,7 @@ const updateRefreshConfig = (view: ViewState, refreshConfig: RefreshInterval) =>
refreshConfig,
});

const updateFilters = (view: ViewState, filters: Filters) => ({
const updateFilters = (view: ViewState, filters: Filter[]) => ({
...view,
filters: cloneDeep(filters),
});
Expand All @@ -92,7 +93,7 @@ export const viewReducer: Reducer<ViewState> = (
filters: [],
hidePanelTitles: false,
isFullScreenMode: false,
query: { language: QueryLanguageType.LUCENE, query: '' },
query: { language: 'lucene', query: '' },
timeRange: { to: 'now', from: 'now-15m' },
refreshConfig: { pause: true, value: 0 },
useMargins: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
*/

import _ from 'lodash';
import { ContainerState, EmbeddableMetadata, Query, TimeRange } from 'ui/embeddable';
import { ContainerState, EmbeddableMetadata } from 'ui/embeddable';
import { EmbeddableCustomization } from 'ui/embeddable/types';
import { Filter } from '@kbn/es-query';
import { RefreshInterval } from 'ui/timefilter/timefilter';
import { Query } from 'src/legacy/core_plugins/data/public';
import { TimeRange } from 'ui/timefilter/time_history';
import { DashboardViewMode } from '../dashboard_view_mode';
import {
DashboardMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
* under the License.
*/

import { EmbeddableMetadata, Query, TimeRange } from 'ui/embeddable';
import { EmbeddableMetadata } from 'ui/embeddable';
import { Filter } from '@kbn/es-query';
import { RefreshInterval } from 'ui/timefilter/timefilter';
import { TimeRange } from 'ui/timefilter/time_history';
import { Query } from 'src/legacy/core_plugins/data/public';
import { DashboardViewMode } from '../dashboard_view_mode';
import { SavedDashboardPanelMap } from '../types';

Expand Down
3 changes: 2 additions & 1 deletion src/legacy/core_plugins/kibana/public/dashboard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
* under the License.
*/

import { Query, EmbeddableFactory } from 'ui/embeddable';
import { EmbeddableFactory } from 'ui/embeddable';
import { AppState } from 'ui/state_management/app_state';
import { UIRegistry } from 'ui/registry/_registry';
import { Filter } from '@kbn/es-query';
import { Query } from 'src/legacy/core_plugins/data/public';
import { DashboardViewMode } from './dashboard_view_mode';

export interface EmbeddableFactoryRegistry extends UIRegistry<EmbeddableFactory> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import {
Embeddable,
EmbeddableState,
OnEmbeddableStateChanged,
TimeRange,
} from 'ui/embeddable';
import { Filters, Query } from 'ui/embeddable/types';
import { RequestAdapter } from 'ui/inspector/adapters';
import { Adapters } from 'ui/inspector/types';
import { getTime } from 'ui/timefilter/get_time';
import { TimeRange } from 'ui/timefilter/time_history';
import { Filter } from '@kbn/es-query';
import { Query } from 'src/legacy/core_plugins/data/public';
import * as columnActions from '../doc_table/actions/columns';
import { SavedSearch } from '../types';
import searchTemplate from './search_template.html';
Expand Down Expand Up @@ -75,7 +76,7 @@ export class SearchEmbeddable extends Embeddable {
private panelTitle: string = '';
private filtersSearchSource: SearchSource;
private timeRange?: TimeRange;
private filters?: Filters;
private filters?: Filter[];
private query?: Query;
private searchInstance?: JQLite;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
* under the License.
*/

import { Query, TimeRange } from 'ui/embeddable';
import { Filter } from '@kbn/es-query';
import { TimeRange } from 'ui/timefilter/time_history';
import { Query } from 'src/legacy/core_plugins/data/public';
import { DashboardViewMode } from '../dashboard/dashboard_view_mode';
import * as DashboardSelectors from '../dashboard/selectors';
import { PanelId } from '../dashboard/selectors/types';
Expand Down
3 changes: 1 addition & 2 deletions src/legacy/core_plugins/kibana/public/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import { applyMiddleware, compose, createStore } from 'redux';
import thunk from 'redux-thunk';

import { QueryLanguageType } from 'ui/embeddable/types';
import { DashboardViewMode } from './dashboard/dashboard_view_mode';
import { reducers } from './reducers';

Expand All @@ -39,7 +38,7 @@ export const store = createStore(
filters: [],
hidePanelTitles: false,
isFullScreenMode: false,
query: { language: QueryLanguageType.LUCENE, query: '' },
query: { language: 'lucene', query: '' },
timeRange: { from: 'now-15m', to: 'now' },
useMargins: true,
viewMode: DashboardViewMode.VIEW,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import _ from 'lodash';
import { ContainerState, Embeddable } from 'ui/embeddable';
import { OnEmbeddableStateChanged } from 'ui/embeddable/embeddable_factory';
import { Filters, Query, TimeRange } from 'ui/embeddable/types';
import { StaticIndexPattern } from 'ui/index_patterns';
import { PersistedState } from 'ui/persisted_state';
import { VisualizeLoader } from 'ui/visualize/loader';
Expand All @@ -31,6 +30,9 @@ import {
VisualizeUpdateParams,
} from 'ui/visualize/loader/types';
import { i18n } from '@kbn/i18n';
import { TimeRange } from 'ui/timefilter/time_history';
import { Query } from 'src/legacy/core_plugins/data/public';
import { Filter } from '@kbn/es-query';

export interface VisualizeEmbeddableConfiguration {
onEmbeddableStateChanged: OnEmbeddableStateChanged;
Expand All @@ -51,7 +53,7 @@ export class VisualizeEmbeddable extends Embeddable {
private panelTitle?: string;
private timeRange?: TimeRange;
private query?: Query;
private filters?: Filters;
private filters?: Filter[];

constructor({
onEmbeddableStateChanged,
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/ui/public/embeddable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ export { EmbeddableFactory, OnEmbeddableStateChanged } from './embeddable_factor
export * from './embeddable';
export * from './context_menu_actions';
export { EmbeddableFactoriesRegistryProvider } from './embeddable_factories_registry';
export { ContainerState, EmbeddableState, Query, Filters, Filter, TimeRange } from './types';
export { ContainerState, EmbeddableState } from './types';
28 changes: 2 additions & 26 deletions src/legacy/ui/public/embeddable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,8 @@

import { Filter } from '@kbn/es-query';
import { RefreshInterval } from 'ui/timefilter/timefilter';

// Should go away soon once everyone imports from kbn/es-query
export { Filter } from '@kbn/es-query';

export interface TimeRange {
to: string;
from: string;
}

export interface FilterMeta {
disabled: boolean;
}

export type Filters = Filter[];

export enum QueryLanguageType {
KUERY = 'kuery',
LUCENE = 'lucene',
}

// It's a string sometimes in old version formats, before Kuery came along and there
// was the language specifier.
export interface Query {
language: QueryLanguageType;
query: string;
}
import { TimeRange } from 'ui/timefilter/time_history';
import { Query } from 'src/legacy/core_plugins/data/public';

export interface EmbeddableCustomization {
[key: string]: object | string;
Expand Down
10 changes: 4 additions & 6 deletions src/legacy/ui/public/timefilter/get_time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@

import dateMath from '@elastic/datemath';
import { Field, IndexPattern } from 'ui/index_patterns';
import { TimeRange } from './time_history';

interface CalculateBoundsOptions {
forceNow?: Date;
}

interface TimeRange {
to: string;
from: string;
}

interface RangeFilter {
gte?: string | number;
lte?: string | number;
Expand Down Expand Up @@ -68,7 +64,9 @@ export function getTime(
if (!bounds) {
return;
}
const filter: Filter = { range: { [timefield.name]: { format: 'strict_date_optional_time' } } };
const filter: Filter = {
range: { [timefield.name]: { format: 'strict_date_optional_time' } },
};

if (bounds.min) {
filter.range[timefield.name].gte = bounds.min.toISOString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
* under the License.
*/

import { TimeRange } from 'ui/timefilter/time_history';
import { Query } from 'src/legacy/core_plugins/data/public';
import { Filter } from '@kbn/es-query';
import { SearchSource } from '../../courier';
import { QueryFilter } from '../../filter_manager/query_filter';
import { Adapters } from '../../inspector/types';
import { PersistedState } from '../../persisted_state';
import { Filters, Query, TimeRange } from '../../visualize';
import { AggConfigs } from '../agg_configs';
import { Vis } from '../vis';

Expand All @@ -30,7 +32,7 @@ export interface RequestHandlerParams {
aggs: AggConfigs;
timeRange?: TimeRange;
query?: Query;
filters?: Filters;
filters?: Filter[];
forceFetch: boolean;
queryFilter: QueryFilter;
uiState?: PersistedState;
Expand Down
1 change: 0 additions & 1 deletion src/legacy/ui/public/visualize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@
*/

export * from './loader';
export { Filters, Query, TimeRange } from './loader/types';
Loading

0 comments on commit 924c837

Please sign in to comment.