Skip to content

Commit

Permalink
Incorporating new state transfer logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Maja Grubic committed Jun 25, 2020
1 parent 7a6a891 commit 5aeb2b2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ export class DashboardAppController {
kbnUrlStateStorage,
usageCollection,
navigation,
dashboard,
}: DashboardAppControllerDependencies) {
const filterManager = queryService.filterManager;
const queryFilter = filterManager;
Expand Down Expand Up @@ -431,9 +430,16 @@ export class DashboardAppController {
.getStateTransfer(scopedHistory())
.getIncomingEmbeddablePackage();
if (incomingState) {
container.addNewEmbeddable<SavedObjectEmbeddableInput>(incomingState.type, {
savedObjectId: incomingState.id,
});
if ('id' in incomingState) {
container.addNewEmbeddable<SavedObjectEmbeddableInput>(incomingState.type, {
savedObjectId: incomingState.id,
});
} else if ('input' in incomingState) {
container.addNewEmbeddable<SavedObjectEmbeddableInput>(
incomingState.type,
incomingState.input
);
}
}
}

Expand Down Expand Up @@ -1112,7 +1118,6 @@ export class DashboardAppController {
outputSubscription.unsubscribe();
}
if (dashboardContainer) {
dashboard.setLastLoadedDashboardAppDashboardInput(dashboardContainer.getInput());
dashboardContainer.destroy();
}
});
Expand Down
19 changes: 14 additions & 5 deletions src/plugins/embeddable/public/lib/state_transfer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

import { EmbeddableInput } from '../embeddables';

/**
* Represents a state package that contains the last active app id.
* @public
Expand All @@ -31,19 +33,26 @@ export function isEmbeddableOriginatingAppState(
return ensureFieldOfTypeExists('originatingApp', state, 'string');
}

export interface EmbeddableByReference {
type: string;
id: string;
}

export interface EmbeddableByValue {
type: string;
input: EmbeddableInput;
}

/**
* Represents a state package that contains all fields necessary to create an embeddable in a container.
* @public
*/
export interface EmbeddablePackageState {
type: string;
id: string;
}
export type EmbeddablePackageState = EmbeddableByValue | EmbeddableByReference;

export function isEmbeddablePackageState(state: unknown): state is EmbeddablePackageState {
return (
ensureFieldOfTypeExists('type', state, 'string') &&
ensureFieldOfTypeExists('id', state, 'string')
(ensureFieldOfTypeExists('id', state, 'string') || ensureFieldOfTypeExists('input', state))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export class VisualizeEmbeddableFactory
public async create(input: VisualizeInput & { savedVis?: SerializedVis }, parent?: IContainer) {
// TODO: This is a bit of a hack to preserve the original functionality. Ideally we will clean this up
// to allow for in place creation of visualizations without having to navigate away to a new URL.
const originatingAppParam = await this.getCurrentAppId();
if (input.savedVis) {
const visState = input.savedVis;
const vis = new Vis(visState.type, visState);
Expand Down
20 changes: 6 additions & 14 deletions src/plugins/visualize/public/application/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ function VisualizeAppController($scope, $route, $injector, $timeout, kbnUrlState
I18nContext,
setActiveUrl,
visualizations,
dashboard,
embeddable,
featureFlagConfig,
scopedHistory,
Expand Down Expand Up @@ -254,20 +253,13 @@ function VisualizeAppController($scope, $route, $injector, $timeout, kbnUrlState
};

const createVisReference = () => {
const currentDashboardInput = dashboard.getLastLoadedDashboardAppDashboardInput();
const input = {
savedVis: { ...vis.serialize() },
};
embeddable
.getEmbeddableFactory('dashboard')
.create(currentDashboardInput)
.then((currentDashboard) => {
if (currentDashboard) {
const input = {
savedVis: { ...vis.serialize() },
};
currentDashboard.addNewEmbeddable('visualization', input).then(() => {
const dashInput = currentDashboard.getInput();
dashboard.navigateToDashboard(dashInput);
});
}
.getStateTransfer()
.navigateToWithEmbeddablePackage($scope.getOriginatingApp(), {
state: { input, type: VISUALIZE_EMBEDDABLE_TYPE },
});
};

Expand Down
1 change: 0 additions & 1 deletion src/plugins/visualize/public/kibana_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export interface VisualizeKibanaServices {
kibanaLegacy: KibanaLegacyStart;
visualizeCapabilities: any;
visualizations: VisualizationsStart;
embeddable: EmbeddableStart;
I18nContext: I18nStart['Context'];
setActiveUrl: (newUrl: string) => void;
restorePreviousUrl: () => void;
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/visualize/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export interface VisualizePluginStartDependencies {
embeddable: EmbeddableStart;
kibanaLegacy: KibanaLegacyStart;
savedObjects: SavedObjectsStart;
embeddable: EmbeddableStart;
}

export interface VisualizePluginSetupDependencies {
Expand Down Expand Up @@ -146,7 +145,6 @@ export class VisualizePlugin
pluginsStart.visualizations.__LEGACY.createVisEmbeddableFromObject,
scopedHistory: () => this.currentHistory!,
savedObjects: pluginsStart.savedObjects,
embeddable: pluginsStart.embeddable,
featureFlagConfig: this.initializerContext.config.get<FeatureFlagConfig>(),
restorePreviousUrl,
};
Expand Down

0 comments on commit 5aeb2b2

Please sign in to comment.