Skip to content

Commit

Permalink
Embeddable input (#73033)
Browse files Browse the repository at this point in the history
* refactor: 💡 move timeRange, filters and query to base embeddabl

* refactor: 💡 use new base embeddable input in explore data

* feat: 🎸 import types as types
  • Loading branch information
streamich authored Aug 21, 2020
1 parent 3ddc2ac commit 74ab989
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
16 changes: 16 additions & 0 deletions src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Adapters } from '../types';
import { IContainer } from '../containers/i_container';
import { ViewMode } from '../types';
import { TriggerContextMapping } from '../../../../ui_actions/public';
import type { TimeRange, Query, Filter } from '../../../../data/common';

export interface EmbeddableError {
name: string;
Expand Down Expand Up @@ -55,6 +56,21 @@ export interface EmbeddableInput {
*/
disableTriggers?: boolean;

/**
* Time range of the chart.
*/
timeRange?: TimeRange;

/**
* Visualization query string used to narrow down results.
*/
query?: Query;

/**
* Visualization filters used to narrow down results.
*/
filters?: Filter[];

[key: string]: unknown;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ export interface VisualizeEmbeddableConfiguration {
}

export interface VisualizeInput extends EmbeddableInput {
timeRange?: TimeRange;
query?: Query;
filters?: Filter[];
vis?: {
colors?: { [key: string]: string };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export abstract class AbstractExploreDataAction<Context extends { embeddable?: I

if (!shared.hasExactlyOneIndexPattern(embeddable)) return false;
if (embeddable.getInput().viewMode !== ViewMode.VIEW) return false;

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import { Action } from '../../../../../../src/plugins/ui_actions/public';
import { DiscoverUrlGeneratorState } from '../../../../../../src/plugins/discover/public';
import {
isTimeRange,
isQuery,
isFilters,
ApplyGlobalFilterActionContext,
esFilters,
} from '../../../../../../src/plugins/data/public';
Expand Down Expand Up @@ -64,9 +61,9 @@ export class ExploreDataChartAction extends AbstractExploreDataAction<ExploreDat

const input = embeddable.getInput();

if (isTimeRange(input.timeRange) && !state.timeRange) state.timeRange = input.timeRange;
if (isQuery(input.query)) state.query = input.query;
if (isFilters(input.filters)) state.filters = [...input.filters, ...(state.filters || [])];
if (input.timeRange && !state.timeRange) state.timeRange = input.timeRange;
if (input.query) state.query = input.query;
if (input.filters) state.filters = [...input.filters, ...(state.filters || [])];
}

const path = await urlGenerator.createUrl(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { Action } from '../../../../../../src/plugins/ui_actions/public';
import { EmbeddableContext } from '../../../../../../src/plugins/embeddable/public';
import { DiscoverUrlGeneratorState } from '../../../../../../src/plugins/discover/public';
import { isTimeRange, isQuery, isFilters } from '../../../../../../src/plugins/data/public';
import { KibanaURL } from './kibana_url';
import * as shared from './shared';
import { AbstractExploreDataAction } from './abstract_explore_data_action';
Expand Down Expand Up @@ -42,9 +41,9 @@ export class ExploreDataContextMenuAction extends AbstractExploreDataAction<Embe

const input = embeddable.getInput();

if (isTimeRange(input.timeRange) && !state.timeRange) state.timeRange = input.timeRange;
if (isQuery(input.query)) state.query = input.query;
if (isFilters(input.filters)) state.filters = [...input.filters, ...(state.filters || [])];
if (input.timeRange && !state.timeRange) state.timeRange = input.timeRange;
if (input.query) state.query = input.query;
if (input.filters) state.filters = [...input.filters, ...(state.filters || [])];
}

const path = await urlGenerator.createUrl(state);
Expand Down

0 comments on commit 74ab989

Please sign in to comment.