Skip to content

Commit

Permalink
Embeddable triggers (#58440) (#60311)
Browse files Browse the repository at this point in the history
* feat: ๐ŸŽธ add Embeddable.supportedTriggers() method

* feat: ๐ŸŽธ report supported triggers on visualization embeddable

* feat: ๐ŸŽธ hard-code supportedTriggers() in visualize_embed

* feat: ๐ŸŽธ use VIS_EVENT_TO_TRIGGER when executing trigger

* perf: โšก๏ธ improve type

* fix: ๐Ÿ› revert back trigger check to how it is done on master

* chore: ๐Ÿค– remove unused import

* feat: ๐ŸŽธ hard-code triggers for each visualization

* fix: ๐Ÿ› fix import

* feat: ๐ŸŽธ reshuffle vis_types in supportedTriggers() method

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
streamich and elasticmachine committed Mar 17, 2020
1 parent 692e035 commit f841d38
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 {
SELECT_RANGE_TRIGGER,
VALUE_CLICK_TRIGGER,
} from '../../../../../../../plugins/ui_actions/public';

export interface VisEventToTrigger {
['brush']: typeof SELECT_RANGE_TRIGGER;
['filter']: typeof VALUE_CLICK_TRIGGER;
}

export const VIS_EVENT_TO_TRIGGER: VisEventToTrigger = {
brush: SELECT_RANGE_TRIGGER,
filter: VALUE_CLICK_TRIGGER,
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ import {
Container,
EmbeddableVisTriggerContext,
} from '../../../../../../../plugins/embeddable/public';
import {
selectRangeTrigger,
valueClickTrigger,
} from '../../../../../../../plugins/ui_actions/public';
import { dispatchRenderComplete } from '../../../../../../../plugins/kibana_utils/public';
import {
IExpressionLoaderParams,
Expand All @@ -50,6 +46,7 @@ import { buildPipeline } from '../legacy/build_pipeline';
import { Vis } from '../vis';
import { getExpressions, getUiActions } from '../services';
import { VisSavedObject } from '../types';
import { VIS_EVENT_TO_TRIGGER } from './events';

const getKeys = <T extends {}>(o: T): Array<keyof T> => Object.keys(o) as Array<keyof T>;

Expand Down Expand Up @@ -295,8 +292,8 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
}

if (!this.input.disableTriggers) {
const triggerId: 'SELECT_RANGE_TRIGGER' | 'VALUE_CLICK_TRIGGER' =
event.name === 'brush' ? selectRangeTrigger.id : valueClickTrigger.id;
const triggerId =
event.name === 'brush' ? VIS_EVENT_TO_TRIGGER.brush : VIS_EVENT_TO_TRIGGER.filter;
const context: EmbeddableVisTriggerContext = {
embeddable: this,
timeFieldName: this.vis.indexPattern.timeFieldName,
Expand Down Expand Up @@ -395,4 +392,31 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
...this.uiState.toJSON(),
});
};

public supportedTriggers() {
// TODO: Report a correct list of triggers for each vis_type.
switch (this.vis.type.name) {
case 'area':
case 'heatmap':
case 'histogram':
case 'horizontal_bar':
case 'line':
case 'pie':
case 'table':
case 'tagcloud':
return [VIS_EVENT_TO_TRIGGER.filter];
case 'gauge':
case 'goal':
case 'input_control_vis':
case 'markdown':
case 'metric':
case 'metrics':
case 'region_map':
case 'tile_map':
case 'timelion':
case 'vega':
default:
return [];
}
}
}
5 changes: 5 additions & 0 deletions src/plugins/embeddable/public/lib/embeddables/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Adapters } from '../types';
import { IContainer } from '../containers';
import { IEmbeddable, EmbeddableInput, EmbeddableOutput } from './i_embeddable';
import { ViewMode } from '../types';
import { TriggerContextMapping } from '../ui_actions';
import { EmbeddableActionStorage } from './embeddable_action_storage';

function getPanelTitle(input: EmbeddableInput, output: EmbeddableOutput) {
Expand Down Expand Up @@ -195,4 +196,8 @@ export abstract class Embeddable<

this.onResetInput(newInput);
}

public supportedTriggers(): Array<keyof TriggerContextMapping> {
return [];
}
}
6 changes: 6 additions & 0 deletions src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Observable } from 'rxjs';
import { Adapters } from '../types';
import { IContainer } from '../containers/i_container';
import { ViewMode } from '../types';
import { TriggerContextMapping } from '../../../../ui_actions/public';

export interface EmbeddableInput {
viewMode?: ViewMode;
Expand Down Expand Up @@ -161,4 +162,9 @@ export interface IEmbeddable<
* Cleans up subscriptions, destroy nodes mounted from calls to render.
*/
destroy(): void;

/**
* List of triggers that this embeddable will execute.
*/
supportedTriggers(): Array<keyof TriggerContextMapping>;
}

0 comments on commit f841d38

Please sign in to comment.