Skip to content

Commit

Permalink
[maps] implement save and return from dashboard (#74303) (#74852)
Browse files Browse the repository at this point in the history
* pass originatingApp into App

* save and return top nav option

* clean up

* navigate to originating app

* functional test

* tslint

* cutOriginatingAppConnection

* add functional test for cutting originating app flow

* one more fix for cutting originator app and another functional test to verify

* typo

* review feedback

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
nreese and elasticmachine authored Aug 12, 2020
1 parent 05735a2 commit e476ba1
Show file tree
Hide file tree
Showing 15 changed files with 349 additions and 161 deletions.
11 changes: 11 additions & 0 deletions test/functional/services/dashboard/panel_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ export function DashboardPanelActionsProvider({ getService, getPageObjects }: Ft
await PageObjects.common.waitForTopNavToBeVisible();
}

async editPanelByTitle(title?: string) {
log.debug(`editPanelByTitle(${title})`);
if (title) {
const panelOptions = await this.getPanelHeading(title);
await this.openContextMenu(panelOptions);
} else {
await this.openContextMenu();
}
await testSubjects.clickWhenNotDisabled(EDIT_PANEL_DATA_TEST_SUBJ);
}

async clickExpandPanelToggle() {
await testSubjects.click(TOGGLE_EXPAND_PANEL_DATA_TEST_SUBJ);
}
Expand Down
11 changes: 11 additions & 0 deletions x-pack/plugins/maps/public/kibana_services.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import { DataPublicPluginStart } from 'src/plugins/data/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { IndexPatternsService } from 'src/plugins/data/public/index_patterns';
import { NavigateToAppOptions } from 'kibana/public';
import { MapsConfigType } from '../config';
import { MapsLegacyConfigType } from '../../../../src/plugins/maps_legacy/public';
import { EmbeddableStart } from '../../../../src/plugins/embeddable/public';

export function getLicenseId(): any;
export function getInspector(): any;
Expand Down Expand Up @@ -77,3 +79,12 @@ export function setKibanaCommonConfig(config: MapsLegacyConfigType): void;
export function setMapAppConfig(config: MapsConfigType): void;
export function setKibanaVersion(version: string): void;
export function setIsGoldPlus(isGoldPlus: boolean): void;
export function setEmbeddableService(embeddableService: EmbeddableStart): void;
export function getEmbeddableService(): EmbeddableStart;
export function setNavigateToApp(
navigateToApp: (appId: string, options?: NavigateToAppOptions | undefined) => Promise<void>
): void;
export const navigateToApp: (
appId: string,
options?: NavigateToAppOptions | undefined
) => Promise<void>;
13 changes: 13 additions & 0 deletions x-pack/plugins/maps/public/kibana_services.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,16 @@ export const setIsGoldPlus = (igp) => {
export const getIsGoldPlus = () => {
return isGoldPlus;
};

let embeddableService;
export const setEmbeddableService = (_embeddableService) => {
embeddableService = _embeddableService;
};
export const getEmbeddableService = () => {
return embeddableService;
};

export let navigateToApp;
export function setNavigateToApp(_navigateToApp) {
navigateToApp = _navigateToApp;
}
4 changes: 4 additions & 0 deletions x-pack/plugins/maps/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import {
setUiActions,
setUiSettings,
setVisualizations,
setEmbeddableService,
setNavigateToApp,
} from './kibana_services';
import { featureCatalogueEntry } from './feature_catalogue_entry';
// @ts-ignore
Expand Down Expand Up @@ -113,6 +115,8 @@ export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => {
setUiActions(plugins.uiActions);
setNavigation(plugins.navigation);
setCoreI18n(core.i18n);
setEmbeddableService(plugins.embeddable);
setNavigateToApp(core.application.navigateToApp);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface ISavedGisMap extends SavedObject {
layerListJSON?: string;
mapStateJSON?: string;
uiStateJSON?: string;
description?: string;
getLayerList(): LayerDescriptor[];
syncWithStore(): void;
}
Expand Down
17 changes: 15 additions & 2 deletions x-pack/plugins/maps/public/routing/maps_router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { Router, Switch, Route, Redirect } from 'react-router-dom';
import { getCoreI18n, getToasts } from '../kibana_services';
import { getCoreI18n, getToasts, getEmbeddableService } from '../kibana_services';
import {
createKbnUrlStateStorage,
withNotifyOnErrors,
Expand Down Expand Up @@ -39,6 +39,11 @@ const App = ({ history, appBasePath, onAppLeave }) => {
const store = getStore();
const I18nContext = getCoreI18n().Context;

const stateTransfer = getEmbeddableService()?.getStateTransfer(history);

const { originatingApp } =
stateTransfer?.getIncomingEditorState({ keysToRemoveAfterFetch: ['originatingApp'] }) || {};

return (
<I18nContext>
<Provider store={store}>
Expand All @@ -50,13 +55,21 @@ const App = ({ history, appBasePath, onAppLeave }) => {
<LoadMapAndRender
savedMapId={props.match.params.savedMapId}
onAppLeave={onAppLeave}
stateTransfer={stateTransfer}
originatingApp={originatingApp}
/>
)}
/>
<Route
exact
path={`/map`}
render={() => <LoadMapAndRender onAppLeave={onAppLeave} />}
render={() => (
<LoadMapAndRender
onAppLeave={onAppLeave}
stateTransfer={stateTransfer}
originatingApp={originatingApp}
/>
)}
/>
// Redirect other routes to list, or if hash-containing, their non-hash equivalents
<Route
Expand Down
6 changes: 0 additions & 6 deletions x-pack/plugins/maps/public/routing/routes/maps_app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
updateFlyout,
enableFullScreen,
openMapSettings,
removePreviewLayers,
} from '../../../actions';
import { FLYOUT_STATE } from '../../../reducers/ui';
import { getMapsCapabilities } from '../../../kibana_services';
Expand Down Expand Up @@ -74,11 +73,6 @@ function mapDispatchToProps(dispatch) {
dispatch(updateFlyout(FLYOUT_STATE.NONE));
dispatch(setReadOnly(!getMapsCapabilities().save));
},
closeFlyout: () => {
dispatch(setSelectedLayer(null));
dispatch(updateFlyout(FLYOUT_STATE.NONE));
dispatch(removePreviewLayers());
},
enableFullScreen: () => dispatch(enableFullScreen()),
openMapSettings: () => dispatch(openMapSettings()),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ export const LoadMapAndRender = class extends React.Component {
return <Redirect to="/" />;
}

return savedMap ? <MapsAppView savedMap={savedMap} onAppLeave={this.props.onAppLeave} /> : null;
return savedMap ? (
<MapsAppView
savedMap={savedMap}
onAppLeave={this.props.onAppLeave}
stateTransfer={this.props.stateTransfer}
originatingApp={this.props.originatingApp}
/>
) : null;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class MapsAppView extends React.Component {
initialized: false,
savedQuery: '',
initialLayerListConfig: null,
// tracking originatingApp in state so the connection can be broken by users
originatingApp: props.originatingApp,
};
}

Expand Down Expand Up @@ -311,11 +313,15 @@ export class MapsAppView extends React.Component {
savedMap: this.props.savedMap,
isOpenSettingsDisabled: this.props.isOpenSettingsDisabled,
isSaveDisabled: this.props.isSaveDisabled,
closeFlyout: this.props.closeFlyout,
enableFullScreen: this.props.enableFullScreen,
openMapSettings: this.props.openMapSettings,
inspectorAdapters: this.props.inspectorAdapters,
setBreadcrumbs: this._setBreadcrumbs,
stateTransfer: this.props.stateTransfer,
originatingApp: this.state.originatingApp,
cutOriginatingAppConnection: () => {
this.setState({ originatingApp: undefined });
},
});

const { TopNavMenu } = getNavigation().ui;
Expand Down
Loading

0 comments on commit e476ba1

Please sign in to comment.