Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drilldowns #59632

Merged
merged 109 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from 101 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
502a60a
Add drilldown wizard components
Dosant Mar 9, 2020
a7ed6ab
Dynamic actions (#58216)
streamich Mar 9, 2020
43583c2
Drilldown context menu (#59638)
streamich Mar 9, 2020
e145241
Add basic ActionFactoryService. Pass data from it into components ins…
Dosant Mar 9, 2020
81e6bcb
Dashboard x pack (#59653)
streamich Mar 9, 2020
1f2cc4c
feat: 🎸 "implement" registerDrilldown() method
streamich Mar 9, 2020
86885c4
fix ConfigurableBaseConfig type
Dosant Mar 9, 2020
6463118
Implement connected flyout_manage_drilldowns component
Dosant Mar 9, 2020
dcacf10
Merge branch 'master' of github.com:elastic/kibana into drilldowns
Dosant Mar 9, 2020
26dfa30
Merge branch 'master' of github.com:elastic/kibana into drilldowns
Dosant Mar 10, 2020
d3cd9e8
Simplify connected flyout manage drilldowns component. Remove interme…
Dosant Mar 10, 2020
1077518
Merge branch 'master' of github.com:elastic/kibana into drilldowns
Dosant Mar 10, 2020
840e873
clean up data-testid workaround in new components
Dosant Mar 10, 2020
f057979
Connect welcome message to storage
Dosant Mar 10, 2020
d60fc96
require `context` in Presentable. drill context down through wizard c…
Dosant Mar 10, 2020
140c5dc
Drilldown factory (#59823)
streamich Mar 10, 2020
b8cf696
Drilldown registration (#59834)
streamich Mar 10, 2020
2e65fd0
Drilldown events 3 (#59854)
streamich Mar 11, 2020
beb053b
Drilldown events 4 (#59876)
streamich Mar 11, 2020
ab6fb4b
Drilldown events 5 (#59885)
streamich Mar 11, 2020
12b8a3f
Merge remote-tracking branch 'upstream/master' into drilldowns
streamich Mar 11, 2020
27b1854
Merge branch 'master' into drilldowns
elasticmachine Mar 11, 2020
0f3ff3e
basic integration of components with dynamicActionManager
Dosant Mar 11, 2020
5009f71
Merge branch 'drilldowns' of github.com:elastic/kibana into drilldowns
Dosant Mar 11, 2020
f176550
fix: 🐛 don't overwrite explicitInput with combined input (#59938)
streamich Mar 11, 2020
4a4766e
display drilldown count in embeddable edit mode
mattkime Mar 11, 2020
0c14ff0
display drilldown count in embeddable edit mode
mattkime Mar 11, 2020
0d4bee2
improve wizard components. more tests.
Dosant Mar 12, 2020
ae98c6b
partial progress, dashboard drilldowns (#59977)
mattkime Mar 12, 2020
3200151
Manage drilldowns toasts. Add basic error handling.
Dosant Mar 12, 2020
ff4e9ad
support order in action factory selector
Dosant Mar 12, 2020
c7d4aa6
fix column order in manage drilldowns list
Dosant Mar 12, 2020
c731afa
remove accidental debug info
Dosant Mar 12, 2020
7d47d9f
Merge branch 'master' into drilldowns
elasticmachine Mar 12, 2020
f2d9056
bunch of nit ui fixes
Dosant Mar 13, 2020
8ad5cd4
Drilldowns reactive action manager (#60099)
streamich Mar 13, 2020
3c94332
Merge branch 'master' into drilldowns
elasticmachine Mar 13, 2020
6f59d1a
Drilldowns various 2 (#60103)
streamich Mar 13, 2020
66e791e
test: 💍 stub DynamicActionManager tests (#60104)
streamich Mar 13, 2020
1f238fe
Drilldowns review 1 (#60139)
streamich Mar 13, 2020
a772987
chore: 🤖 catch up with master
streamich Mar 16, 2020
e66513c
fix: 🐛 correct merge
streamich Mar 16, 2020
6efef2b
Drilldowns various 4 (#60264)
streamich Mar 16, 2020
537f8ee
workaround issue with closing flyout when navigating away
Dosant Mar 16, 2020
0ad8933
fix react key issue in action_wizard
Dosant Mar 16, 2020
94894c1
don’t open 2 flyouts
Dosant Mar 16, 2020
65f5414
fix action order
Dosant Mar 16, 2020
d3487ab
Merge branch 'master' into drilldowns
elasticmachine Mar 16, 2020
a405f83
Drilldowns reload stored (#60336)
streamich Mar 16, 2020
894aec7
chore: 🤖 catch up with master
streamich Mar 16, 2020
cfdab22
Drilldowns triggers (#60339)
streamich Mar 16, 2020
e96f815
Merge branch 'master' into drilldowns
elasticmachine Mar 16, 2020
62edd23
fix: 🐛 stop infinite re-rendering
streamich Mar 17, 2020
7a7beeb
Drilldowns multitrigger (#60357)
streamich Mar 17, 2020
5418305
"Create drilldown" flyout - design cleanup (#60309)
andreadelrio Mar 17, 2020
45f6f4d
basic unit tests for flyout_create_drildown action
Dosant Mar 17, 2020
ceb5cfe
Drilldowns finalize (#60371)
streamich Mar 17, 2020
4646ad2
Merge branch 'master' into drilldowns
elasticmachine Mar 17, 2020
6d0b8cb
basic unit tests for drilldown actions
Dosant Mar 17, 2020
ab3f4bf
Merge branch 'drilldowns' of github.com:elastic/kibana into drilldowns
Dosant Mar 17, 2020
5b4434b
Merge branch 'master' of github.com:elastic/kibana into drilldowns
mattkime Mar 17, 2020
65fae5e
Merge branch 'master' into drilldowns
mattkime Mar 17, 2020
6229d4f
Merge branch 'drilldowns' of github.com:elastic/kibana into drilldowns
mattkime Mar 17, 2020
1252f37
Drilldowns finalize 2 (#60510)
streamich Mar 18, 2020
243e5ce
Merge branch 'master' into drilldowns
elasticmachine Mar 19, 2020
469250f
feat: 🎸 don't show "OPTIONS" title on drilldown context menus
streamich Mar 19, 2020
c73319a
feat: 🎸 add server-side for x-pack dashboard plugin
streamich Mar 19, 2020
2280fdf
feat: 🎸 disable Drilldowns for TSVB
streamich Mar 19, 2020
adcb0a3
feat: 🎸 enable drilldowns on kibana.yml feature flag
streamich Mar 19, 2020
9e22e55
feat: 🎸 add feature flag comment to kibana.yml
streamich Mar 19, 2020
c3e6a61
Merge branch 'master' into drilldowns
elasticmachine Mar 19, 2020
ed8580a
feat: 🎸 remove places from drilldown interface
streamich Mar 20, 2020
73a91f3
refactor: 💡 remove place in factory context
streamich Mar 20, 2020
4d500b5
chore: 🤖 remove doExecute
streamich Mar 20, 2020
054fc8f
remove not needed now error_configure_action component
Dosant Mar 20, 2020
1e9efde
remove workaround for storybook
Dosant Mar 20, 2020
1a3e67b
feat: 🎸 improve DrilldownDefinition interface
streamich Mar 20, 2020
d1666ca
style: 💄 replace any by unknown
streamich Mar 20, 2020
32466a5
chore: 🤖 remove any
streamich Mar 20, 2020
df10920
chore: 🤖 make isConfigValid return type a boolean
streamich Mar 20, 2020
fb3bde9
Merge remote-tracking branch 'upstream/drilldowns' into drilldowns
streamich Mar 20, 2020
ce39459
Merge branch 'master' into drilldowns
elasticmachine Mar 20, 2020
d480655
refactor: 💡 move getDisplayName to factory, remove deprecated
streamich Mar 20, 2020
eb24e41
style: 💄 remove any
streamich Mar 20, 2020
930b695
feat: 🎸 improve ActionFactoryDefinition
streamich Mar 20, 2020
6a98f45
refactor: 💡 change visualize_embeddable params
streamich Mar 20, 2020
da49052
feat: 🎸 add dashboard dependency to dashboard_enhanced
streamich Mar 20, 2020
baf0f5e
style: 💄 rename drilldown plugin life-cycle contracts
streamich Mar 20, 2020
a5d7a38
refactor: 💡 do naming adjustments for dashboard drilldown
streamich Mar 20, 2020
36fb629
Merge branch 'master' into drilldowns
elasticmachine Mar 20, 2020
e68dcfb
fix: 🐛 fix Type error
streamich Mar 20, 2020
fcecc9a
Merge branch 'master' into drilldowns
elasticmachine Mar 20, 2020
47f1095
fix: 🐛 fix TypeScript type errors
streamich Mar 20, 2020
e678e06
test: 💍 fix test after refactor
streamich Mar 21, 2020
1604ab5
refactor: 💡 rename context -> placeContext in React component
streamich Mar 21, 2020
e14cf4a
Merge branch 'master' into drilldowns
elasticmachine Mar 21, 2020
03b2b37
Merge branch 'master' into drilldowns
elasticmachine Mar 22, 2020
d10aa7b
Merge branch 'master' into drilldowns
elasticmachine Mar 23, 2020
0d076d7
Merge branch 'master' into drilldowns
elasticmachine Mar 23, 2020
0dafa57
chore: 🤖 remove setting from kibana.yml
streamich Mar 23, 2020
29ee51c
refactor: 💡 change return type of getAction as per review
streamich Mar 23, 2020
2b162e8
remove custom css per review
Dosant Mar 23, 2020
de6c6b1
refactor: 💡 rename drilldownCount to eventCount
streamich Mar 23, 2020
88a81e2
style: 💄 remove any
streamich Mar 23, 2020
af3777c
Merge remote-tracking branch 'upstream/drilldowns' into drilldowns
streamich Mar 23, 2020
e29030f
refactor: 💡 change how uiActions are passed to vis embeddable
streamich Mar 23, 2020
78e64d6
Merge branch 'master' into drilldowns
elasticmachine Mar 23, 2020
00c42c4
chore: 🤖 catch up with master
streamich Mar 23, 2020
6cd07c5
style: 💄 remove unused import
streamich Mar 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# For more info, see https://help.github.com/articles/about-codeowners/

# App
/x-pack/legacy/plugins/dashboard_enhanced/ @elastic/kibana-app
/x-pack/legacy/plugins/lens/ @elastic/kibana-app
/x-pack/legacy/plugins/graph/ @elastic/kibana-app
/src/legacy/server/url_shortening/ @elastic/kibana-app
Expand Down
2 changes: 1 addition & 1 deletion examples/ui_action_examples/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class UiActionExamplesPlugin
}));

uiActions.registerAction(helloWorldAction);
uiActions.attachAction(helloWorldTrigger.id, helloWorldAction);
uiActions.addTriggerAction(helloWorldTrigger.id, helloWorldAction);
}

public start() {}
Expand Down
3 changes: 1 addition & 2 deletions examples/ui_actions_explorer/public/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ const ActionsExplorer = ({ uiActionsApi, openModal }: Props) => {
);
},
});
uiActionsApi.registerAction(dynamicAction);
streamich marked this conversation as resolved.
Show resolved Hide resolved
uiActionsApi.attachAction(HELLO_WORLD_TRIGGER_ID, dynamicAction);
uiActionsApi.addTriggerAction(HELLO_WORLD_TRIGGER_ID, dynamicAction);
setConfirmationText(
`You've successfully added a new action: ${dynamicAction.getDisplayName(
{}
Expand Down
16 changes: 8 additions & 8 deletions examples/ui_actions_explorer/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ export class UiActionsExplorerPlugin implements Plugin<void, void, {}, StartDeps

const startServices = core.getStartServices();

deps.uiActions.attachAction(
deps.uiActions.addTriggerAction(
USER_TRIGGER,
createPhoneUserAction(async () => (await startServices)[1].uiActions)
);
deps.uiActions.attachAction(
deps.uiActions.addTriggerAction(
USER_TRIGGER,
createEditUserAction(async () => (await startServices)[0].overlays.openModal)
);

deps.uiActions.attachAction(COUNTRY_TRIGGER, viewInMapsAction);
deps.uiActions.attachAction(COUNTRY_TRIGGER, lookUpWeatherAction);
deps.uiActions.attachAction(COUNTRY_TRIGGER, showcasePluggability);
deps.uiActions.attachAction(PHONE_TRIGGER, makePhoneCallAction);
deps.uiActions.attachAction(PHONE_TRIGGER, showcasePluggability);
deps.uiActions.attachAction(USER_TRIGGER, showcasePluggability);
deps.uiActions.addTriggerAction(COUNTRY_TRIGGER, viewInMapsAction);
deps.uiActions.addTriggerAction(COUNTRY_TRIGGER, lookUpWeatherAction);
deps.uiActions.addTriggerAction(COUNTRY_TRIGGER, showcasePluggability);
deps.uiActions.addTriggerAction(PHONE_TRIGGER, makePhoneCallAction);
deps.uiActions.addTriggerAction(PHONE_TRIGGER, showcasePluggability);
deps.uiActions.addTriggerAction(USER_TRIGGER, showcasePluggability);

core.application.register({
id: 'uiActionsExplorer',
Expand Down
1 change: 1 addition & 0 deletions src/core/public/overlays/flyout/flyout_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export interface OverlayFlyoutStart {
export interface OverlayFlyoutOpenOptions {
className?: string;
closeButtonAriaLabel?: string;
ownFocus?: boolean;
Dosant marked this conversation as resolved.
Show resolved Hide resolved
'data-test-subj'?: string;
}

Expand Down
4 changes: 3 additions & 1 deletion src/dev/storybook/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
*/

export const storybookAliases = {
advanced_ui_actions: 'x-pack/plugins/advanced_ui_actions/scripts/storybook.js',
apm: 'x-pack/legacy/plugins/apm/scripts/storybook.js',
canvas: 'x-pack/legacy/plugins/canvas/scripts/storybook_new.js',
codeeditor: 'src/plugins/kibana_react/public/code_editor/scripts/storybook.ts',
dashboard_enhanced: 'x-pack/plugins/dashboard_enhanced/scripts/storybook.js',
drilldowns: 'x-pack/plugins/drilldowns/scripts/storybook.js',
embeddable: 'src/plugins/embeddable/scripts/storybook.js',
infra: 'x-pack/legacy/plugins/infra/scripts/storybook.js',
siem: 'x-pack/legacy/plugins/siem/scripts/storybook.js',
ui_actions: 'x-pack/plugins/advanced_ui_actions/scripts/storybook.js',
ui_actions: 'src/plugins/ui_actions/scripts/storybook.js',
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { buildPipeline } from '../legacy/build_pipeline';
import { Vis } from '../vis';
import { getExpressions, getUiActions } from '../services';
import { VisSavedObject } from '../types';
import { VisualizationsStartDeps } from '../plugin';
import { VIS_EVENT_TO_TRIGGER } from './events';

const getKeys = <T extends {}>(o: T): Array<keyof T> => Object.keys(o) as Array<keyof T>;
Expand All @@ -57,6 +58,7 @@ export interface VisualizeEmbeddableConfiguration {
editable: boolean;
appState?: { save(): void };
uiState?: PersistedState;
uiActions?: VisualizationsStartDeps['uiActions'];
}

export interface VisualizeInput extends EmbeddableInput {
Expand Down Expand Up @@ -106,6 +108,7 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
editable,
appState,
uiState,
uiActions,
}: VisualizeEmbeddableConfiguration,
initialInput: VisualizeInput,
parent?: Container
Expand All @@ -120,7 +123,8 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
savedObjectId: savedVisualization.id!,
visTypeName: savedVisualization.vis.type.name,
},
parent
parent,
{ uiActions }
);
this.timefilter = timefilter;
this.appState = appState;
Expand Down Expand Up @@ -299,6 +303,7 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
timeFieldName: this.vis.indexPattern.timeFieldName,
data: event.data,
};

getUiActions()
.getTrigger(triggerId)
.exec(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
getTimeFilter,
} from '../services';
import { showNewVisModal } from '../wizard';
import { VisualizationsStartDeps } from '../plugin';

interface VisualizationAttributes extends SavedObjectAttributes {
visState: string;
Expand All @@ -52,7 +53,9 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
> {
public readonly type = VISUALIZE_EMBEDDABLE_TYPE;

constructor() {
constructor(
private readonly getServices: () => Promise<Pick<VisualizationsStartDeps, 'uiActions'>>
streamich marked this conversation as resolved.
Show resolved Hide resolved
) {
super({
savedObjectMetaData: {
name: i18n.translate('visualizations.savedObjectName', { defaultMessage: 'Visualization' }),
Expand Down Expand Up @@ -114,6 +117,8 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<

const indexPattern = await getIndexPattern(savedObject);
const indexPatterns = indexPattern ? [indexPattern] : [];
const { uiActions } = await this.getServices();

const editable = await this.isEditable();
return new VisualizeEmbeddable(
getTimeFilter(),
Expand All @@ -124,6 +129,7 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
editable,
appState: input.appState,
uiState: input.uiState,
uiActions,
},
input,
parent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { PluginInitializerContext } from '../../../../../../core/public';
import { CoreSetup, PluginInitializerContext } from '../../../../../../core/public';
import { VisualizationsSetup, VisualizationsStart } from './';
import { VisualizationsPlugin } from './plugin';
import { coreMock } from '../../../../../../core/public/mocks';
Expand All @@ -26,6 +26,7 @@ import { expressionsPluginMock } from '../../../../../../plugins/expressions/pub
import { dataPluginMock } from '../../../../../../plugins/data/public/mocks';
import { usageCollectionPluginMock } from '../../../../../../plugins/usage_collection/public/mocks';
import { uiActionsPluginMock } from '../../../../../../plugins/ui_actions/public/mocks';
import { VisualizationsStartDeps } from './plugin';

const createSetupContract = (): VisualizationsSetup => ({
createBaseVisualization: jest.fn(),
Expand All @@ -46,7 +47,7 @@ const createStartContract = (): VisualizationsStart => ({
const createInstance = async () => {
const plugin = new VisualizationsPlugin({} as PluginInitializerContext);

const setup = plugin.setup(coreMock.createSetup(), {
const setup = plugin.setup(coreMock.createSetup() as CoreSetup<VisualizationsStartDeps>, {
data: dataPluginMock.createSetupContract(),
expressions: expressionsPluginMock.createSetupContract(),
embeddable: embeddablePluginMock.createSetupContract(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class VisualizationsPlugin
constructor(initializerContext: PluginInitializerContext) {}

public setup(
core: CoreSetup,
core: CoreSetup<VisualizationsStartDeps>,
{ expressions, embeddable, usageCollection, data }: VisualizationsSetupDeps
): VisualizationsSetup {
setUISettings(core.uiSettings);
Expand All @@ -114,7 +114,9 @@ export class VisualizationsPlugin
expressions.registerFunction(visualizationFunction);
expressions.registerRenderer(visualizationRenderer);

const embeddableFactory = new VisualizeEmbeddableFactory();
const embeddableFactory = new VisualizeEmbeddableFactory(
async () => (await core.getStartServices())[1]
);
embeddable.registerEmbeddableFactory(VISUALIZE_EMBEDDABLE_TYPE, embeddableFactory);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface ReplacePanelActionContext {
export class ReplacePanelAction implements ActionByType<typeof ACTION_REPLACE_PANEL> {
public readonly type = ACTION_REPLACE_PANEL;
public readonly id = ACTION_REPLACE_PANEL;
public order = 11;
public order = 3;

constructor(
private core: CoreStart,
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class DashboardEmbeddableContainerPublicPlugin
): Setup {
const expandPanelAction = new ExpandPanelAction();
uiActions.registerAction(expandPanelAction);
uiActions.attachAction(CONTEXT_MENU_TRIGGER, expandPanelAction);
uiActions.attachAction(CONTEXT_MENU_TRIGGER, expandPanelAction.id);
streamich marked this conversation as resolved.
Show resolved Hide resolved
const startServices = core.getStartServices();

if (share) {
Expand Down Expand Up @@ -134,7 +134,7 @@ export class DashboardEmbeddableContainerPublicPlugin
plugins.embeddable.getEmbeddableFactories
);
uiActions.registerAction(changeViewAction);
uiActions.attachAction(CONTEXT_MENU_TRIGGER, changeViewAction);
uiActions.addTriggerAction(CONTEXT_MENU_TRIGGER, changeViewAction);
}

public stop() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test('DashboardContainer in edit mode shows edit mode actions', async () => {

const editModeAction = createEditModeAction();
uiActionsSetup.registerAction(editModeAction);
uiActionsSetup.attachAction(CONTEXT_MENU_TRIGGER, editModeAction);
uiActionsSetup.addTriggerAction(CONTEXT_MENU_TRIGGER, editModeAction);
setup.registerEmbeddableFactory(
CONTACT_CARD_EMBEDDABLE,
new ContactCardEmbeddableFactory({} as any, (() => null) as any, {} as any)
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli
createFilterAction(queryService.filterManager, queryService.timefilter.timefilter)
);

uiActions.attachAction(
uiActions.addTriggerAction(
SELECT_RANGE_TRIGGER,
selectRangeAction(queryService.filterManager, queryService.timefilter.timefilter)
);

uiActions.attachAction(
uiActions.addTriggerAction(
VALUE_CLICK_TRIGGER,
valueClickAction(queryService.filterManager, queryService.timefilter.timefilter)
);
Expand Down Expand Up @@ -146,7 +146,10 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli
const search = this.searchService.start(core);
setSearchService(search);

uiActions.attachAction(APPLY_FILTER_TRIGGER, uiActions.getAction(ACTION_GLOBAL_APPLY_FILTER));
uiActions.addTriggerAction(
APPLY_FILTER_TRIGGER,
uiActions.getAction(ACTION_GLOBAL_APPLY_FILTER)
);

const dataServices = {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface ActionContext {
export class EditPanelAction implements Action<ActionContext> {
public readonly type = ACTION_EDIT_PANEL;
public readonly id = ACTION_EDIT_PANEL;
public order = 15;
public order = 50;

constructor(private readonly getEmbeddableFactory: EmbeddableStart['getEmbeddableFactory']) {}

Expand Down
73 changes: 65 additions & 8 deletions src/plugins/embeddable/public/lib/embeddables/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,35 @@
* specific language governing permissions and limitations
* under the License.
*/
import { isEqual, cloneDeep } from 'lodash';
import { cloneDeep, isEqual } from 'lodash';
import * as Rx from 'rxjs';
import { Adapters } from '../types';
import { Adapters, ViewMode } from '../types';
import { IContainer } from '../containers';
import { IEmbeddable, EmbeddableInput, EmbeddableOutput } from './i_embeddable';
import { ViewMode } from '../types';
import { EmbeddableInput, EmbeddableOutput, IEmbeddable } from './i_embeddable';
import { TriggerContextMapping } from '../ui_actions';
import { EmbeddableActionStorage } from './embeddable_action_storage';
import {
UiActionsDynamicActionManager,
UiActionsStart,
} from '../../../../../plugins/ui_actions/public';
import { EmbeddableContext } from '../triggers';

function getPanelTitle(input: EmbeddableInput, output: EmbeddableOutput) {
return input.hidePanelTitles ? '' : input.title === undefined ? output.defaultTitle : input.title;
}

export interface EmbeddableParams {
uiActions?: UiActionsStart;
}

export abstract class Embeddable<
TEmbeddableInput extends EmbeddableInput = EmbeddableInput,
TEmbeddableOutput extends EmbeddableOutput = EmbeddableOutput
> implements IEmbeddable<TEmbeddableInput, TEmbeddableOutput> {
static runtimeId: number = 0;

public readonly runtimeId = Embeddable.runtimeId++;

public readonly parent?: IContainer;
public readonly isContainer: boolean = false;
public abstract readonly type: string;
Expand All @@ -48,15 +60,34 @@ export abstract class Embeddable<
// to update input when the parent changes.
private parentSubscription?: Rx.Subscription;

private storageSubscription?: Rx.Subscription;

// TODO: Rename to destroyed.
private destoyed: boolean = false;

private __actionStorage?: EmbeddableActionStorage;
public get actionStorage(): EmbeddableActionStorage {
return this.__actionStorage || (this.__actionStorage = new EmbeddableActionStorage(this));
private storage = new EmbeddableActionStorage((this as unknown) as Embeddable);

private cachedDynamicActions?: UiActionsDynamicActionManager;
public get dynamicActions(): UiActionsDynamicActionManager | undefined {
if (!this.params.uiActions) return undefined;
if (!this.cachedDynamicActions) {
this.cachedDynamicActions = new UiActionsDynamicActionManager({
isCompatible: async (context: unknown) =>
(context as EmbeddableContext).embeddable.runtimeId === this.runtimeId,
storage: this.storage,
uiActions: this.params.uiActions,
});
}

return this.cachedDynamicActions;
}

constructor(input: TEmbeddableInput, output: TEmbeddableOutput, parent?: IContainer) {
constructor(
input: TEmbeddableInput,
output: TEmbeddableOutput,
parent?: IContainer,
public readonly params: EmbeddableParams = {}
) {
this.id = input.id;
this.output = {
title: getPanelTitle(input, output),
Expand All @@ -80,6 +111,18 @@ export abstract class Embeddable<
this.onResetInput(newInput);
});
}

if (this.dynamicActions) {
this.dynamicActions.start().catch(error => {
/* eslint-disable */
console.log('Failed to start embeddable dynamic actions', this);
console.error(error);
/* eslint-enable */
});
this.storageSubscription = this.input$.subscribe(() => {
this.storage.reload$.next();
});
}
}

public getIsContainer(): this is IContainer {
Expand Down Expand Up @@ -158,6 +201,20 @@ export abstract class Embeddable<
*/
public destroy(): void {
this.destoyed = true;

if (this.dynamicActions) {
this.dynamicActions.stop().catch(error => {
/* eslint-disable */
console.log('Failed to stop embeddable dynamic actions', this);
console.error(error);
/* eslint-enable */
});
}

if (this.storageSubscription) {
this.storageSubscription.unsubscribe();
}

if (this.parentSubscription) {
this.parentSubscription.unsubscribe();
}
Expand Down
Loading