[Maps] fix refreshing the page causes loss of unsaved change (#81226)

* [Maps] fix refreshing the page causes loss of unsaved change

* fix functional tests

* remove unneeded check for app leave modal

* check for appLeaveConfirmModal for clicking confirmModalConfirmButton

* see failures without closing appLeaveModal

* start clearing unsaved changes warning in maps

* clean up more unsaved state in functional tests

* more cleaning up of unsaved state in functional tests

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Nathan Reese 2020-10-22 15:00:55 -06:00 committed by GitHub
parent 06ea880712
commit 95516432ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 12 deletions

View file

@ -117,11 +117,12 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
} else {
log.debug(`navigateToUrl ${appUrl}`);
await browser.get(appUrl, insertTimestamp);
// accept alert if it pops up
const alert = await browser.getAlert();
await alert?.accept();
}
// accept alert if it pops up
const alert = await browser.getAlert();
await alert?.accept();
const currentUrl = shouldLoginIfPrompted
? await this.loginIfPrompted(appUrl, insertTimestamp)
: await browser.getCurrentUrl();

View file

@ -5,17 +5,21 @@
*/
import { i18n } from '@kbn/i18n';
import { getNavigateToApp } from '../../../kibana_services';
import { getCoreOverlays, getNavigateToApp } from '../../../kibana_services';
import { goToSpecifiedPath } from '../../maps_router';
import { getAppTitle } from '../../../../common/i18n_getters';
export const unsavedChangesWarning = i18n.translate(
'xpack.maps.breadCrumbs.unsavedChangesWarning',
{
defaultMessage: 'Your map has unsaved changes. Are you sure you want to leave?',
defaultMessage: 'Leave Maps with unsaved work?',
}
);
export const unsavedChangesTitle = i18n.translate('xpack.maps.breadCrumbs.unsavedChangesTitle', {
defaultMessage: 'Unsaved changes',
});
export function getBreadcrumbs({
title,
getHasUnsavedChanges,
@ -39,10 +43,13 @@ export function getBreadcrumbs({
breadcrumbs.push({
text: getAppTitle(),
onClick: () => {
onClick: async () => {
if (getHasUnsavedChanges()) {
const navigateAway = window.confirm(unsavedChangesWarning);
if (navigateAway) {
const confirmed = await getCoreOverlays().openConfirm(unsavedChangesWarning, {
title: unsavedChangesTitle,
'data-test-subj': 'appLeaveConfirmModal',
});
if (confirmed) {
goToSpecifiedPath('/');
}
} else {

View file

@ -43,7 +43,7 @@ import {
import { MapContainer } from '../../../connected_components/map_container';
import { getIndexPatternsFromIds } from '../../../index_pattern_util';
import { getTopNavConfig } from './top_nav_config';
import { getBreadcrumbs, unsavedChangesWarning } from './get_breadcrumbs';
import { getBreadcrumbs, unsavedChangesTitle, unsavedChangesWarning } from './get_breadcrumbs';
import {
LayerDescriptor,
MapRefreshConfig,
@ -138,9 +138,7 @@ export class MapsAppView extends React.Component<Props, State> {
this.props.onAppLeave((actions) => {
if (this._hasUnsavedChanges()) {
if (!window.confirm(unsavedChangesWarning)) {
return {} as AppLeaveAction;
}
return actions.confirm(unsavedChangesWarning, unsavedChangesTitle);
}
return actions.default() as AppLeaveAction;
});

View file

@ -36,6 +36,7 @@ export default function ({ getService, getPageObjects }) {
expect(doesLayerExist).to.equal(true);
const hits = await PageObjects.maps.getHits();
expect(hits).to.equal('4');
await PageObjects.maps.refreshAndClearUnsavedChangesWarning();
});
it('should link geo_point fields to Maps application with time and query context', async () => {
@ -55,6 +56,7 @@ export default function ({ getService, getPageObjects }) {
expect(doesLayerExist).to.equal(true);
const hits = await PageObjects.maps.getHits();
expect(hits).to.equal('7');
await PageObjects.maps.refreshAndClearUnsavedChangesWarning();
});
});
}

View file

@ -38,6 +38,7 @@ export default function ({ getPageObjects, getService }) {
after(async () => {
await inspector.close();
await PageObjects.maps.refreshAndClearUnsavedChangesWarning();
await security.testUser.restoreDefaults();
});

View file

@ -19,6 +19,7 @@ export default function ({ getPageObjects, getService }) {
afterEach(async () => {
await inspector.close();
await PageObjects.maps.refreshAndClearUnsavedChangesWarning();
await security.testUser.restoreDefaults();
});

View file

@ -16,6 +16,7 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.maps.loadSavedMap('document example');
});
after(async () => {
await PageObjects.maps.refreshAndClearUnsavedChangesWarning();
await security.testUser.restoreDefaults();
});

View file

@ -19,6 +19,7 @@ export function GisPageProvider({ getService, getPageObjects }: FtrProviderConte
const queryBar = getService('queryBar');
const comboBox = getService('comboBox');
const renderable = getService('renderable');
const browser = getService('browser');
function escapeLayerName(layerName: string) {
return layerName.split(' ').join('_');
@ -692,6 +693,13 @@ export function GisPageProvider({ getService, getPageObjects }: FtrProviderConte
}
await testSubjects.click('mapSettingSubmitButton');
}
async refreshAndClearUnsavedChangesWarning() {
await browser.refresh();
// accept alert if it pops up
const alert = await browser.getAlert();
await alert?.accept();
}
}
return new GisPage();
}