Skip to content

Commit

Permalink
[Dashboard] Remove Multiple History Entries & Stay in Edit Mode on Sa…
Browse files Browse the repository at this point in the history
…ve As (#92105)

* made save as stay in edit mode when not navigating to another dashboard. Removed extra history entires from save
  • Loading branch information
ThomThomson authored Feb 23, 2021
1 parent 8ab6860 commit cb93207
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class DashboardStateManager {
// setup initial state by merging defaults with state from url & panels storage
// also run migration, as state in url could be of older version
const initialUrlState = this.kbnUrlStateStorage.get<DashboardAppState>(STATE_STORAGE_KEY);

const initialState = migrateAppState(
{
...this.stateDefaults,
Expand Down Expand Up @@ -345,7 +346,7 @@ export class DashboardStateManager {
/**
* Resets the state back to the last saved version of the dashboard.
*/
public resetState(resetViewMode: boolean) {
public resetState() {
// In order to show the correct warning, we have to store the unsaved
// title on the dashboard object. We should fix this at some point, but this is how all the other object
// save panels work at the moment.
Expand All @@ -368,12 +369,8 @@ export class DashboardStateManager {
this.stateDefaults.filters = [...this.getLastSavedFilterBars()];
this.isDirty = false;

if (resetViewMode) {
this.stateContainer.set(this.stateDefaults);
} else {
const currentViewMode = this.stateContainer.get().viewMode;
this.stateContainer.set({ ...this.stateDefaults, viewMode: currentViewMode });
}
const currentViewMode = this.stateContainer.get().viewMode;
this.stateContainer.set({ ...this.stateDefaults, viewMode: currentViewMode });
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export function saveDashboard(
// reset state only when save() was successful
// e.g. save() could be interrupted if title is duplicated and not confirmed
dashboardStateManager.lastSavedDashboardFilters = dashboardStateManager.getFilterState();
dashboardStateManager.resetState(!saveOptions.stayInEditMode);
}

return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
openAddPanelFlyout,
ViewMode,
} from '../../services/embeddable';
import { getSavedObjectFinder, SaveResult, showSaveModal } from '../../services/saved_objects';
import {
getSavedObjectFinder,
SavedObjectSaveOpts,
SaveResult,
showSaveModal,
} from '../../services/saved_objects';

import { NavAction } from '../../types';
import { DashboardSavedObject } from '../..';
Expand All @@ -43,7 +48,6 @@ import { OverlayRef } from '../../../../../core/public';
import { getNewDashboardTitle, unsavedChangesBadge } from '../../dashboard_strings';
import { DASHBOARD_PANELS_UNSAVED_ID } from '../lib/dashboard_panel_storage';
import { DashboardContainer } from '..';
import { SavedDashboardSaveOpts } from '../lib/save_dashboard';

export interface DashboardTopNavState {
chromeIsVisible: boolean;
Expand Down Expand Up @@ -176,7 +180,7 @@ export function DashboardTopNav({
}

function discardChanges() {
dashboardStateManager.resetState(true);
dashboardStateManager.resetState();
dashboardStateManager.clearUnsavedPanels();

// We need to do a hard reset of the timepicker. appState will not reload like
Expand Down Expand Up @@ -221,7 +225,8 @@ export function DashboardTopNav({
* @resolved {String} - The id of the doc
*/
const save = useCallback(
async (saveOptions: SavedDashboardSaveOpts) => {
async (saveOptions: SavedObjectSaveOpts) => {
setIsSaveInProgress(true);
return saveDashboard(angular.toJson, timefilter, dashboardStateManager, saveOptions)
.then(function (id) {
if (id) {
Expand All @@ -235,8 +240,15 @@ export function DashboardTopNav({

dashboardPanelStorage.clearPanels(lastDashboardId);
if (id !== lastDashboardId) {
redirectTo({ destination: 'dashboard', id, useReplace: !lastDashboardId });
redirectTo({
id,
// editMode: true,
destination: 'dashboard',
useReplace: true,
});
} else {
setIsSaveInProgress(false);
dashboardStateManager.resetState();
chrome.docTitle.change(dashboardStateManager.savedDashboard.lastSavedTitle);
}
}
Expand Down Expand Up @@ -354,7 +366,7 @@ export function DashboardTopNav({
}

setIsSaveInProgress(true);
save({ stayInEditMode: true }).then((response: SaveResult) => {
save({}).then((response: SaveResult) => {
// If the save wasn't successful, put the original values back.
if (!(response as { id: string }).id) {
dashboardStateManager.setTitle(currentTitle);
Expand Down
5 changes: 4 additions & 1 deletion test/functional/apps/dashboard/full_screen_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

it('available in view mode', async () => {
await PageObjects.dashboard.saveDashboard('full screen test', { saveAsNew: true });
await PageObjects.dashboard.saveDashboard('full screen test', {
saveAsNew: true,
exitFromEditMode: true,
});
const exists = await PageObjects.dashboard.fullScreenModeMenuItemExists();
expect(exists).to.be(true);
});
Expand Down
2 changes: 0 additions & 2 deletions test/functional/apps/dashboard/view_edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
storeTimeWithDashboard: true,
});

await PageObjects.dashboard.switchToEditMode();
await PageObjects.timePicker.setAbsoluteRange(
'Sep 19, 2013 @ 06:31:44.000',
'Sep 19, 2013 @ 06:31:44.000'
Expand Down Expand Up @@ -210,7 +209,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
it('when time changed is not stored with dashboard', async function () {
await PageObjects.dashboard.gotoDashboardEditMode(dashboardName);
await PageObjects.dashboard.saveDashboard(dashboardName, { storeTimeWithDashboard: false });
await PageObjects.dashboard.switchToEditMode();
await PageObjects.timePicker.setAbsoluteRange(
'Oct 19, 2014 @ 06:31:44.000',
'Dec 19, 2014 @ 06:31:44.000'
Expand Down
9 changes: 8 additions & 1 deletion test/functional/page_objects/dashboard_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function DashboardPageProvider({ getService, getPageObjects }: FtrProvide
* @default true
*/
waitDialogIsClosed?: boolean;
exitFromEditMode?: boolean;
needsConfirm?: boolean;
storeTimeWithDashboard?: boolean;
saveAsNew?: boolean;
Expand Down Expand Up @@ -376,7 +377,7 @@ export function DashboardPageProvider({ getService, getPageObjects }: FtrProvide
*/
public async saveDashboard(
dashboardName: string,
saveOptions: SaveDashboardOptions = { waitDialogIsClosed: true }
saveOptions: SaveDashboardOptions = { waitDialogIsClosed: true, exitFromEditMode: true }
) {
await retry.try(async () => {
await this.enterDashboardTitleAndClickSave(dashboardName, saveOptions);
Expand All @@ -393,6 +394,12 @@ export function DashboardPageProvider({ getService, getPageObjects }: FtrProvide
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.common.waitForSaveModalToClose();

const isInViewMode = await testSubjects.exists('dashboardEditMode');
if (saveOptions.exitFromEditMode && !isInViewMode) {
await this.clickCancelOutOfEditMode();
}
await PageObjects.header.waitUntilLoadingHasFinished();

return message;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
{
saveAsNew: false,
waitDialogIsClosed: true,
exitFromEditMode: true,
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
{
saveAsNew: false,
waitDialogIsClosed: true,
exitFromEditMode: true,
}
);

Expand Down

0 comments on commit cb93207

Please sign in to comment.