Skip to content

Commit

Permalink
moved switchViewMode out of dashboard input
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomThomson committed Dec 8, 2020
1 parent 79c3b2c commit 4e6bafe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
11 changes: 1 addition & 10 deletions src/plugins/dashboard/public/application/dashboard_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {

import { removeQueryParam } from '../services/kibana_utils';
import { IndexPattern } from '../services/data';
import { ViewMode, EmbeddableRenderer } from '../services/embeddable';
import { EmbeddableRenderer } from '../services/embeddable';

export interface DashboardAppProps {
history: History;
Expand Down Expand Up @@ -74,13 +74,6 @@ export function DashboardApp({
const dashboardStateManager = useDashboardStateManager(savedDashboard, history);
const dashboardContainer = useDashboardContainer(dashboardStateManager, history, false);

const switchViewMode = useCallback(
(newMode: ViewMode) => {
dashboardStateManager?.switchViewMode(newMode);
},
[dashboardStateManager]
);

const refreshDashboardContainer = useCallback(
(lastReloadRequestTime?: number) => {
if (!dashboardContainer || !dashboardStateManager) {
Expand All @@ -94,7 +87,6 @@ export function DashboardApp({
lastReloadRequestTime,
dashboardCapabilities,
query: data.query,
switchViewMode,
}),
});
if (changes) {
Expand All @@ -113,7 +105,6 @@ export function DashboardApp({
history,
data.query,
embedSettings,
switchViewMode,
dashboardContainer,
data.search.session,
dashboardCapabilities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
} from '.';

import { getQueryParams } from '../services/kibana_utils';
import { EmbeddablePackageState, isErrorEmbeddable, ViewMode } from '../services/embeddable';
import { EmbeddablePackageState, isErrorEmbeddable } from '../services/embeddable';
import {
esFilters,
FilterManager,
Expand Down Expand Up @@ -78,7 +78,12 @@ export const getChangesFromAppStateForContainerState = ({
}

Object.keys(
_.omit(containerInput, ['filters', 'searchSessionId', 'lastReloadRequestTime'])
_.omit(containerInput, [
'filters',
'searchSessionId',
'lastReloadRequestTime',
'switchViewMode',
])
).forEach((key) => {
const containerValue = (containerInput as { [key: string]: unknown })[key];
const appStateValue = ((appStateDashboardInput as unknown) as { [key: string]: unknown })[key];
Expand All @@ -102,7 +107,6 @@ export const getChangesFromAppStateForContainerState = ({

export const getDashboardContainerInput = ({
query,
switchViewMode,
searchSessionId,
incomingEmbeddable,
isEmbeddedExternally,
Expand All @@ -115,7 +119,6 @@ export const getDashboardContainerInput = ({
incomingEmbeddable?: EmbeddablePackageState;
lastReloadRequestTime?: number;
isEmbeddedExternally: boolean;
switchViewMode?: (v: ViewMode) => void;
searchSessionId?: string;
query: QueryStart;
}): DashboardContainerInput => {
Expand Down Expand Up @@ -157,7 +160,6 @@ export const getDashboardContainerInput = ({
dashboardCapabilities,
isEmbeddedExternally,
searchSessionId,
switchViewMode,
timeRange: {
..._.cloneDeep(query.timefilter.timefilter.getTime()),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import { PanelPlacementMethod, IPanelPlacementArgs } from './panel/dashboard_pan
import { DashboardCapabilities } from '../types';

export interface DashboardContainerInput extends ContainerInput {
switchViewMode?: (newViewMode: ViewMode) => void;
dashboardCapabilities?: DashboardCapabilities;
refreshConfig?: RefreshInterval;
isEmbeddedExternally?: boolean;
Expand Down Expand Up @@ -114,6 +113,7 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
public readonly type = DASHBOARD_CONTAINER_TYPE;

private embeddablePanel: EmbeddableStart['EmbeddablePanel'];
public switchViewMode?: (newViewMode: ViewMode) => void;

public getPanelCount = () => {
return Object.keys(this.getInput().panels).length;
Expand Down Expand Up @@ -261,7 +261,7 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
<DashboardViewport
container={this}
PanelComponent={this.embeddablePanel}
switchViewMode={this.getInput().switchViewMode}
switchViewMode={this.switchViewMode}
/>
</KibanaContextProvider>
</I18nProvider>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
EmbeddableFactoryNotFoundError,
EmbeddableInput,
isErrorEmbeddable,
ViewMode,
} from '../../../../embeddable/public';

import { DashboardStateManager } from '../dashboard_state_manager';
Expand Down Expand Up @@ -99,6 +100,10 @@ export const useDashboardContainer = (
return;
}

// inject switch view mode callback for the empty screen to use
newContainer.switchViewMode = (newViewMode: ViewMode) =>
dashboardStateManager.switchViewMode(newViewMode);

// If the incoming embeddable is newly created, or doesn't exist in the current panels list,
// add it with `addNewEmbeddable`
if (
Expand Down

0 comments on commit 4e6bafe

Please sign in to comment.