-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3090ca9
commit aec421c
Showing
102 changed files
with
2,686 additions
and
4,823 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "dashboard_embeddable", | ||
"version": "kibana" | ||
} |
90 changes: 90 additions & 0 deletions
90
src/legacy/core_plugins/dashboard_embeddable/public/actions/expand_panel_action.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/legacy/core_plugins/dashboard_embeddable/public/embeddable/_index.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
1 change: 1 addition & 0 deletions
1
src/legacy/core_plugins/dashboard_embeddable/public/embeddable/_variables.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$dshEditingModeHoverColor: transparentize($euiColorWarning, lightOrDarkTheme(.9, .7)); |
33 changes: 33 additions & 0 deletions
33
src/legacy/core_plugins/dashboard_embeddable/public/embeddable/dashboard_constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
} |
182 changes: 182 additions & 0 deletions
182
src/legacy/core_plugins/dashboard_embeddable/public/embeddable/dashboard_container.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; | ||
} | ||
} |
Oops, something went wrong.