Skip to content

Commit

Permalink
Dashboard Embeddable Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
stacey-gammon committed Apr 25, 2019
1 parent 3090ca9 commit aec421c
Show file tree
Hide file tree
Showing 102 changed files with 2,686 additions and 4,823 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@
* under the License.
*/

import ngMock from 'ng_mock';
import expect from '@kbn/expect';
import { resolve } from 'path';

describe('SavedDashboards Service', function () {
let savedDashboardLoader;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (savedDashboards) {
savedDashboardLoader = savedDashboards;
}));

it('delete returns a native promise', function () {
expect(savedDashboardLoader.delete(['1', '2'])).to.be.a(Promise);
// eslint-disable-next-line import/no-default-export
export default function(kibana: any) {
return new kibana.Plugin({
uiExports: {
embeddableActions: ['plugins/dashboard_embeddable/actions/expand_panel_action'],
embeddableFactories: ['plugins/dashboard_embeddable/embeddable/dashboard_container_factory'],
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
},
});
});
}
4 changes: 4 additions & 0 deletions src/legacy/core_plugins/dashboard_embeddable/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "dashboard_embeddable",
"version": "kibana"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* 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 { EuiIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import {
Action,
actionRegistry,
Embeddable,
CONTEXT_MENU_TRIGGER,
triggerRegistry,
ViewMode,
} from 'plugins/embeddable_api/index';
import React from 'react';
import { DASHBOARD_CONTAINER_TYPE, DashboardContainer } from '../embeddable';

export const EXPAND_PANEL_ACTION = 'EXPAND_PANEL_ACTION';

function isDashboard(embeddable: Embeddable): embeddable is DashboardContainer {
return (embeddable as DashboardContainer).type === DASHBOARD_CONTAINER_TYPE;
}

export class ExpandPanelAction extends Action {
constructor() {
super('EXPAND_PANEL_ACTION');
this.priority = 7;
}

public getTitle({ embeddable }: { embeddable: Embeddable }) {
if (!embeddable.parent || !isDashboard(embeddable.parent)) {
throw new Error('Action is incompatible with context');
}

return embeddable.parent.getInput().expandedPanelId
? i18n.translate('kbn.embeddable.actions.toggleExpandPanel.expandedDisplayName', {
defaultMessage: 'Minimize',
})
: i18n.translate('kbn.embeddable.actions.toggleExpandPanel.notExpandedDisplayName', {
defaultMessage: 'Full screen',
});
}

public getIcon({ embeddable }: { embeddable: Embeddable }) {
if (!embeddable.parent || !isDashboard(embeddable.parent)) {
throw new Error('Action is incompatible with context');
}
const isExpanded = embeddable.parent.getInput().expandedPanelId === embeddable.id;
return <EuiIcon type={isExpanded ? 'expand' : 'expand'} />;
}

public isCompatible({ embeddable }: { embeddable: Embeddable }) {
return Promise.resolve(
Boolean(
embeddable.parent &&
isDashboard(embeddable.parent) &&
embeddable.getInput().viewMode === ViewMode.VIEW
)
);
}

public execute({ embeddable }: { embeddable: Embeddable }) {
if (!embeddable.parent || !isDashboard(embeddable.parent)) {
throw new Error('Action is incompatible with context');
}
embeddable.parent.onToggleExpandPanel(embeddable.id);
}
}

actionRegistry.addAction(new ExpandPanelAction());

triggerRegistry.attachAction({
triggerId: CONTEXT_MENU_TRIGGER,
actionId: EXPAND_PANEL_ACTION,
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@
* specific language governing permissions and limitations
* under the License.
*/

export enum DashboardViewMode {
EDIT = 'edit',
VIEW = 'view',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

@import './variables';

@import './viewport/index';
@import './panel/index';
@import './grid/index';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$dshEditingModeHoverColor: transparentize($euiColorWarning, lightOrDarkTheme(.9, .7));
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.
*/

export const DashboardConstants = {
ADD_VISUALIZATION_TO_DASHBOARD_MODE_PARAM: 'addToDashboard',
NEW_VISUALIZATION_ID_PARAM: 'addVisualization',
LANDING_PAGE_PATH: '/dashboards',
CREATE_NEW_DASHBOARD_URL: '/dashboard',
};
export const DASHBOARD_GRID_COLUMN_COUNT = 48;
export const DASHBOARD_GRID_HEIGHT = 20;
export const DEFAULT_PANEL_WIDTH = DASHBOARD_GRID_COLUMN_COUNT / 2;
export const DEFAULT_PANEL_HEIGHT = 15;

export function createDashboardEditUrl(id: string) {
return `/dashboard/${id}`;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* 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 React from 'react';
import ReactDOM from 'react-dom';
import uuid from 'uuid';

import { I18nProvider } from '@kbn/i18n/react';
import { IndexPattern } from 'ui/index_patterns';

import { TimeRange } from 'ui/timefilter/time_history';
import {
Container,
ContainerInput,
Embeddable,
EmbeddableFactoryRegistry,
EmbeddableInput,
Filter,
Query,
RefreshConfig,
ViewMode,
EmbeddableOutput,
EmbeddableInputMissingFromContainer,
isErrorEmbeddable,
EmbeddableFactory,
} from '../../../embeddable_api/public/index';

import { DASHBOARD_CONTAINER_TYPE } from './dashboard_container_factory';
import { createPanelState } from './panel';
import { DashboardPanelState } from './types';
import { DashboardViewport } from './viewport/dashboard_viewport';

export interface DashboardContainerInput extends ContainerInput {
viewMode: ViewMode;
filters: Filter[];
query: Query;
timeRange: TimeRange;
refreshConfig?: RefreshConfig;
expandedPanelId?: string;
useMargins: boolean;
title: string;
description?: string;
isFullScreenMode: boolean;
panels: { [panelId: string]: DashboardPanelState };

// Used to force a refresh of embeddables even if there were no other input state
// changes.
lastReloadRequestTime?: number;
}

export interface DashboardEmbeddableInput {
filters: Filter[];
query: Query;
timeRange: TimeRange;
refreshConfig?: RefreshConfig;
viewMode: ViewMode;
hidePanelTitles?: boolean;
id: string;
firstName: string;
}

export interface DashboardEmbeddableOutput extends EmbeddableOutput {
indexPatterns?: IndexPattern[];
}

export type DashboardEmbeddable = Embeddable<
DashboardEmbeddableInput & EmbeddableInput,
DashboardEmbeddableOutput
>;

export class DashboardContainer extends Container<
DashboardEmbeddableInput,
DashboardEmbeddableOutput,
DashboardContainerInput
> {
constructor(
initialInput: DashboardContainerInput,
embeddableFactories: EmbeddableFactoryRegistry,
parent?: Container
) {
super(
DASHBOARD_CONTAINER_TYPE,
{
panels: {},
isFullScreenMode: false,
filters: [],
useMargins: true,
...initialInput,
},
{ embeddableLoaded: {} },
embeddableFactories,
parent
);
}

protected createNewPanelState<EEI extends EmbeddableInput = EmbeddableInput>(
factory: EmbeddableFactory<EEI>,
partial: Partial<EmbeddableInputMissingFromContainer<EEI, DashboardEmbeddableInput>> & {
id?: string;
} = {}
): DashboardPanelState<EmbeddableInputMissingFromContainer<EEI, DashboardEmbeddableInput>> {
const panelState = super.createNewPanelState(factory, partial);
return createPanelState<EmbeddableInputMissingFromContainer<EEI, DashboardEmbeddableInput>>(
panelState,
Object.values(this.input.panels)
);
}

public onToggleExpandPanel(id: string) {
const newValue = this.input.expandedPanelId ? undefined : id;
this.updateInput({
expandedPanelId: newValue,
});
}

public onPanelsUpdated = (panels: { [panelId: string]: DashboardPanelState }) => {
this.updateInput({
panels: {
...panels,
},
});
};

public onExitFullScreenMode = () => {
this.updateInput({
isFullScreenMode: false,
});
};

public render(dom: React.ReactNode) {
ReactDOM.render(
// @ts-ignore
<I18nProvider>
<DashboardViewport embeddableFactories={this.embeddableFactories} container={this} />
</I18nProvider>,
dom
);
}

public getPanelIndexPatterns() {
const indexPatterns: IndexPattern[] = [];
Object.values(this.children).forEach(embeddable => {
if (!isErrorEmbeddable(embeddable)) {
const embeddableIndexPatterns = embeddable.getOutput().indexPatterns;
if (embeddableIndexPatterns) {
indexPatterns.push(...embeddableIndexPatterns);
}
}
});
return indexPatterns;
}

protected getInheritedInput(id: string): DashboardEmbeddableInput {
const { viewMode, refreshConfig, timeRange, query, hidePanelTitles, filters } = this.input;
return {
filters,
hidePanelTitles,
query,
timeRange,
refreshConfig,
viewMode,
id,
firstName: 'suuuue',
};
}
}
Loading

0 comments on commit aec421c

Please sign in to comment.