Skip to content

Commit

Permalink
refactor: 💡 rename trigger contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 26, 2020
1 parent 98a1c5c commit eb08d0e
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import moment from 'moment';
import { esFilters, IFieldType, RangeFilterParams } from '../../../public';
import { getIndexPatterns } from '../../../public/services';
import { deserializeAggConfig } from '../../search/expressions/utils';
import { RangeSelectTriggerContext } from '../../../../embeddable/public';
import { RangeSelectContext } from '../../../../embeddable/public';

export async function createFiltersFromRangeSelectAction(event: RangeSelectTriggerContext['data']) {
export async function createFiltersFromRangeSelectAction(event: RangeSelectContext['data']) {
const column: Record<string, any> = event.table.columns[event.column];

if (!column || !column.meta) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { dataPluginMock } from '../../../public/mocks';
import { setIndexPatterns } from '../../../public/services';
import { mockDataServices } from '../../../public/search/aggs/test_helpers';
import { createFiltersFromValueClickAction } from './create_filters_from_value_click';
import { ValueClickTriggerContext } from '../../../../embeddable/public';
import { ValueClickContext } from '../../../../embeddable/public';

const mockField = {
name: 'bytes',
Expand All @@ -39,7 +39,7 @@ const mockField = {
};

describe('createFiltersFromValueClick', () => {
let dataPoints: ValueClickTriggerContext['data']['data'];
let dataPoints: ValueClickContext['data']['data'];

beforeEach(() => {
dataPoints = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { KibanaDatatable } from '../../../../../plugins/expressions/public';
import { deserializeAggConfig } from '../../search/expressions';
import { esFilters, Filter } from '../../../public';
import { getIndexPatterns } from '../../../public/services';
import { ValueClickTriggerContext } from '../../../../embeddable/public';
import { ValueClickContext } from '../../../../embeddable/public';

/**
* For terms aggregations on `__other__` buckets, this assembles a list of applicable filter
Expand Down Expand Up @@ -114,7 +114,7 @@ const createFilter = async (
export const createFiltersFromValueClickAction = async ({
data,
negate,
}: ValueClickTriggerContext['data']) => {
}: ValueClickContext['data']) => {
const filters: Filter[] = [];

await Promise.all(
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/public/actions/select_range_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import {
ActionByType,
} from '../../../../plugins/ui_actions/public';
import { createFiltersFromRangeSelectAction } from './filters/create_filters_from_range_select';
import { RangeSelectTriggerContext } from '../../../embeddable/public';
import { RangeSelectContext } from '../../../embeddable/public';
import { FilterManager, TimefilterContract, esFilters } from '..';

export const ACTION_SELECT_RANGE = 'ACTION_SELECT_RANGE';

export type SelectRangeActionContext = RangeSelectTriggerContext;
export type SelectRangeActionContext = RangeSelectContext;

async function isCompatible(context: SelectRangeActionContext) {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/public/actions/value_click_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import {
import { getOverlays, getIndexPatterns } from '../services';
import { applyFiltersPopover } from '../ui/apply_filters';
import { createFiltersFromValueClickAction } from './filters/create_filters_from_value_click';
import { ValueClickTriggerContext } from '../../../embeddable/public';
import { ValueClickContext } from '../../../embeddable/public';
import { Filter, FilterManager, TimefilterContract, esFilters } from '..';

export const ACTION_VALUE_CLICK = 'ACTION_VALUE_CLICK';

export type ValueClickActionContext = ValueClickTriggerContext;
export type ValueClickActionContext = ValueClickContext;

async function isCompatible(context: ValueClickActionContext) {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/embeddable/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export {
EmbeddableOutput,
EmbeddablePanel,
EmbeddableRoot,
ValueClickTriggerContext,
RangeSelectTriggerContext,
ValueClickContext,
RangeSelectContext,
ErrorEmbeddable,
IContainer,
IEmbeddable,
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/embeddable/public/lib/triggers/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface EmbeddableContext {
embeddable: IEmbeddable;
}

export interface ValueClickTriggerContext<T extends IEmbeddable = IEmbeddable> {
export interface ValueClickContext<T extends IEmbeddable = IEmbeddable> {
embeddable?: T;
data: {
data: Array<{
Expand All @@ -39,7 +39,7 @@ export interface ValueClickTriggerContext<T extends IEmbeddable = IEmbeddable> {
};
}

export interface RangeSelectTriggerContext<T extends IEmbeddable = IEmbeddable> {
export interface RangeSelectContext<T extends IEmbeddable = IEmbeddable> {
embeddable?: T;
data: {
table: KibanaDatatable;
Expand All @@ -50,16 +50,16 @@ export interface RangeSelectTriggerContext<T extends IEmbeddable = IEmbeddable>
}

export type ChartActionContext<T extends IEmbeddable = IEmbeddable> =
| ValueClickTriggerContext<T>
| RangeSelectTriggerContext<T>;
| ValueClickContext<T>
| RangeSelectContext<T>;

export const isValueClickTriggerContext = (
context: ChartActionContext
): context is ValueClickTriggerContext => context.data && 'data' in context.data;
): context is ValueClickContext => context.data && 'data' in context.data;

export const isRangeSelectTriggerContext = (
context: ChartActionContext
): context is RangeSelectTriggerContext => context.data && 'range' in context.data;
): context is RangeSelectContext => context.data && 'range' in context.data;

export const CONTEXT_MENU_TRIGGER = 'CONTEXT_MENU_TRIGGER';
export const contextMenuTrigger: Trigger<'CONTEXT_MENU_TRIGGER'> = {
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/ui_actions/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { TriggerInternal } from './triggers/trigger_internal';
import { Filter } from '../../data/public';
import { SELECT_RANGE_TRIGGER, VALUE_CLICK_TRIGGER, APPLY_FILTER_TRIGGER } from './triggers';
import { IEmbeddable } from '../../embeddable/public';
import { RangeSelectTriggerContext, ValueClickTriggerContext } from '../../embeddable/public';
import { RangeSelectContext, ValueClickContext } from '../../embeddable/public';

export type TriggerRegistry = Map<TriggerId, TriggerInternal<any>>;
export type ActionRegistry = Map<string, ActionInternal>;
Expand All @@ -37,8 +37,8 @@ export type TriggerContext = BaseContext;

export interface TriggerContextMapping {
[DEFAULT_TRIGGER]: TriggerContext;
[SELECT_RANGE_TRIGGER]: RangeSelectTriggerContext;
[VALUE_CLICK_TRIGGER]: ValueClickTriggerContext;
[SELECT_RANGE_TRIGGER]: RangeSelectContext;
[VALUE_CLICK_TRIGGER]: ValueClickContext;
[APPLY_FILTER_TRIGGER]: {
embeddable: IEmbeddable;
filters: Filter[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { createDashboardUrlGenerator } from '../../../../../../../src/plugins/da
import { UrlGeneratorsService } from '../../../../../../../src/plugins/share/public/url_generators';
import { VisualizeEmbeddableContract } from '../../../../../../../src/plugins/visualizations/public';
import {
RangeSelectTriggerContext,
ValueClickTriggerContext,
RangeSelectContext,
ValueClickContext,
} from '../../../../../../../src/plugins/embeddable/public';
import { StartDependencies } from '../../../plugin';
import { SavedObjectLoader } from '../../../../../../../src/plugins/saved_objects/public';
Expand Down Expand Up @@ -136,8 +136,8 @@ describe('.execute() & getHref', () => {
const context = ({
data: {
...(useRangeEvent
? ({ range: {} } as RangeSelectTriggerContext['data'])
: ({ data: [] } as ValueClickTriggerContext['data'])),
? ({ range: {} } as RangeSelectContext['data'])
: ({ data: [] } as ValueClickContext['data'])),
timeFieldName: 'order_date',
},
embeddable: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/

import {
ValueClickTriggerContext,
RangeSelectTriggerContext,
ValueClickContext,
RangeSelectContext,
IEmbeddable,
} from '../../../../../../../src/plugins/embeddable/public';

export type ActionContext<T extends IEmbeddable = IEmbeddable> =
| ValueClickTriggerContext<T>
| RangeSelectTriggerContext<T>;
| ValueClickContext<T>
| RangeSelectContext<T>;

export interface Config {
dashboardId?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { coreMock } from '../../../../../../src/core/public/mocks';
import { UrlGeneratorContract } from '../../../../../../src/plugins/share/public';
import {
EmbeddableStart,
RangeSelectTriggerContext,
ValueClickTriggerContext,
RangeSelectContext,
ValueClickContext,
ChartActionContext,
} from '../../../../../../src/plugins/embeddable/public';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -85,8 +85,8 @@ const setup = ({ useRangeEvent = false }: { useRangeEvent?: boolean } = {}) => {

const data: ChartActionContext<typeof embeddable>['data'] = {
...(useRangeEvent
? ({ range: {} } as RangeSelectTriggerContext['data'])
: ({ data: [] } as ValueClickTriggerContext['data'])),
? ({ range: {} } as RangeSelectContext['data'])
: ({ data: [] } as ValueClickContext['data'])),
timeFieldName: 'order_date',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

import { Action } from '../../../../../../src/plugins/ui_actions/public';
import {
ValueClickTriggerContext,
RangeSelectTriggerContext,
ValueClickContext,
RangeSelectContext,
} 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';

export type ExploreDataChartActionContext = ValueClickTriggerContext | RangeSelectTriggerContext;
export type ExploreDataChartActionContext = ValueClickContext | RangeSelectContext;

export const ACTION_EXPLORE_DATA_CHART = 'ACTION_EXPLORE_DATA_CHART';

Expand Down

0 comments on commit eb08d0e

Please sign in to comment.