Skip to content

Commit

Permalink
cutOriginatingAppConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Aug 5, 2020
1 parent 2b2c9f9 commit f34ae2f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 6 additions & 2 deletions x-pack/plugins/maps/public/kibana_services.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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';
Expand Down Expand Up @@ -81,6 +82,9 @@ export function setIsGoldPlus(isGoldPlus: boolean): void;
export function setEmbeddableService(embeddableService: EmbeddableStart): void;
export function getEmbeddableService(): EmbeddableStart;
export function setNavigateToApp(
navigateToApp: (appId: string, options?: unknown | undefined) => Promise<void>
navigateToApp: (appId: string, options?: NavigateToAppOptions | undefined) => Promise<void>
): void;
// export navigateToApp: (appId: string, options?: unknown | undefined) => Promise<void>;
export const navigateToApp: (
appId: string,
options?: NavigateToAppOptions | undefined
) => Promise<void>;
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 @@ -308,7 +310,10 @@ export class MapsAppView extends React.Component {
inspectorAdapters: this.props.inspectorAdapters,
setBreadcrumbs: this._setBreadcrumbs,
stateTransfer: this.props.stateTransfer,
originatingApp: this.props.originatingApp,
originatingApp: this.state.originatingApp,
cutOriginatingAppConnection: () => {
this.setState({ originatingApp: undefined });
},
});

const { TopNavMenu } = getNavigation().ui;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function getTopNavConfig({
setBreadcrumbs,
stateTransfer,
originatingApp,
cutOriginatingAppConnection,
}: {
savedMap: ISavedGisMap;
isOpenSettingsDisabled: boolean;
Expand All @@ -46,6 +47,7 @@ export function getTopNavConfig({
setBreadcrumbs: () => void;
stateTransfer?: EmbeddableStateTransfer;
originatingApp?: string;
cutOriginatingAppConnection: () => void;
}) {
const topNavConfigs = [];
const isNewMap = !savedMap.id;
Expand Down Expand Up @@ -106,6 +108,10 @@ export function getTopNavConfig({
setBreadcrumbs();
goToSpecifiedPath(`/map/${id}${window.location.hash}`);

if (newCopyOnSave && !returnToOrigin) {
cutOriginatingAppConnection();
}

if (!!originatingApp && returnToOrigin) {
const newlyCreated = newCopyOnSave || isNewMap;
if (newlyCreated && stateTransfer) {
Expand All @@ -130,11 +136,12 @@ export function getTopNavConfig({
iconType: 'check',
run: () => {
onSave({
newTitle: savedMap.title,
newTitle: savedMap.title ? savedMap.title : '',
newDescription: savedMap.description ? savedMap.description : '',
newCopyOnSave: false,
isTitleDuplicateConfirmed: false,
returnToOrigin: true,
onTitleDuplicate: () => {},
});
},
testId: 'mapSaveAndReturnButton',
Expand Down

0 comments on commit f34ae2f

Please sign in to comment.