Skip to content

Commit

Permalink
Clear editor state when maps listing page loads. (#90071)
Browse files Browse the repository at this point in the history
* Clear editor state when maps listing page loads.
  • Loading branch information
ThomThomson authored Feb 3, 2021
1 parent 71dec81 commit bb802c0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions x-pack/plugins/maps/public/render_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ export async function renderApp({
...withNotifyOnErrors(getToasts()),
});

const stateTransfer = getEmbeddableService().getStateTransfer();

setAppChrome();

function renderMapApp(routeProps: RouteComponentProps<{ savedMapId?: string }>) {
const stateTransfer = getEmbeddableService()?.getStateTransfer();

const { embeddableId, originatingApp, valueInput } =
stateTransfer?.getIncomingEditorState() || {};
stateTransfer.getIncomingEditorState() || {};

let mapEmbeddableInput;
if (routeProps.match.params.savedMapId) {
Expand Down Expand Up @@ -119,7 +119,7 @@ export async function renderApp({
const newPath = hash.substr(1);
return <Redirect to={newPath} />;
} else if (pathname === '/' || pathname === '') {
return <ListPage />;
return <ListPage stateTransfer={stateTransfer} />;
} else {
return <Redirect to="/" />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { Redirect } from 'react-router-dom';
import { getSavedObjectsClient, getToasts } from '../../kibana_services';
import { MapsListView } from './maps_list_view';
import { MAP_SAVED_OBJECT_TYPE } from '../../../common/constants';
import { EmbeddableStateTransfer } from '../../../../../../src/plugins/embeddable/public';

export class LoadListAndRender extends React.Component {
export class LoadListAndRender extends React.Component<{ stateTransfer: EmbeddableStateTransfer }> {
_isMounted: boolean = false;
state = {
mapsLoaded: false,
Expand All @@ -20,6 +21,7 @@ export class LoadListAndRender extends React.Component {

componentDidMount() {
this._isMounted = true;
this.props.stateTransfer.clearEditorState();
this._loadMapsList();
}

Expand Down
13 changes: 13 additions & 0 deletions x-pack/test/functional/apps/maps/embeddable/save_and_return.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ export default function ({ getPageObjects, getService }) {
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.equal(2);
});

it('should lose its connection to the dashboard when creating new map', async () => {
await PageObjects.maps.gotoMapListingPage();
await PageObjects.maps.openNewMap();
await PageObjects.maps.expectMissingSaveAndReturnButton();

// return to origin should not be present in save modal
await testSubjects.click('mapSaveButton');
const redirectToOriginCheckboxExists = await testSubjects.exists(
'returnToOriginModeSwitch'
);
expect(redirectToOriginCheckboxExists).to.be(false);
});
});

describe('save as', () => {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/test/functional/page_objects/gis_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export function GisPageProvider({ getService, getPageObjects }: FtrProviderConte
await testSubjects.click('mapSaveAndReturnButton');
}

async expectMissingSaveAndReturnButton() {
await testSubjects.missingOrFail('mapSaveAndReturnButton');
}

async expectMissingSaveButton() {
await testSubjects.missingOrFail('mapSaveButton');
}
Expand Down

0 comments on commit bb802c0

Please sign in to comment.