Skip to content

Commit

Permalink
[7.11] Fix Lens Save and Return Removing Tags (#89613) (#89728)
Browse files Browse the repository at this point in the history
* Fix Lens Save and Return Removing Tags (#89613)
  • Loading branch information
ThomThomson authored Jan 29, 2021
1 parent e7d0ecd commit 2beeccc
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 21 deletions.
38 changes: 24 additions & 14 deletions test/functional/page_objects/visualize_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
import { FtrProviderContext } from '../ftr_provider_context';
import { VisualizeConstants } from '../../../src/plugins/visualize/public/application/visualize_constants';

interface VisualizeSaveModalArgs {
saveAsNew?: boolean;
redirectToOrigin?: boolean;
}

export function VisualizePageProvider({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const retry = getService('retry');
Expand Down Expand Up @@ -321,11 +326,27 @@ export function VisualizePageProvider({ getService, getPageObjects }: FtrProvide
}
}

public async saveVisualization(
public async saveVisualization(vizName: string, saveModalArgs: VisualizeSaveModalArgs = {}) {
await this.ensureSavePanelOpen();

await this.setSaveModalValues(vizName, saveModalArgs);
log.debug('Click Save Visualization button');

await testSubjects.click('confirmSaveSavedObjectButton');

// Confirm that the Visualization has actually been saved
await testSubjects.existOrFail('saveVisualizationSuccess');
const message = await common.closeToast();
await header.waitUntilLoadingHasFinished();
await common.waitForSaveModalToClose();

return message;
}

public async setSaveModalValues(
vizName: string,
{ saveAsNew = false, redirectToOrigin = false } = {}
{ saveAsNew, redirectToOrigin }: VisualizeSaveModalArgs = {}
) {
await this.ensureSavePanelOpen();
await testSubjects.setValue('savedObjectTitle', vizName);

const saveAsNewCheckboxExists = await testSubjects.exists('saveAsNewCheckbox');
Expand All @@ -341,17 +362,6 @@ export function VisualizePageProvider({ getService, getPageObjects }: FtrProvide
log.debug('redirect to origin checkbox exists. Setting its state to', state);
await testSubjects.setEuiSwitch('returnToOriginModeSwitch', state);
}
log.debug('Click Save Visualization button');

await testSubjects.click('confirmSaveSavedObjectButton');

// Confirm that the Visualization has actually been saved
await testSubjects.existOrFail('saveVisualizationSuccess');
const message = await common.closeToast();
await header.waitUntilLoadingHasFinished();
await common.waitForSaveModalToClose();

return message;
}

public async saveVisualizationExpectSuccess(
Expand Down
17 changes: 10 additions & 7 deletions x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ export function App({
state.persistedDoc?.state,
]);

const tagsIds =
state.persistedDoc && savedObjectsTagging
? savedObjectsTagging.ui.getTagIdsFromReferences(state.persistedDoc.references)
: [];

const runSave = async (
saveProps: Omit<OnSaveProps, 'onTitleDuplicate' | 'newDescription'> & {
returnToOrigin: boolean;
Expand All @@ -369,8 +374,11 @@ export function App({
}

let references = lastKnownDoc.references;
if (savedObjectsTagging && saveProps.newTags) {
references = savedObjectsTagging.ui.updateTagsReferences(references, saveProps.newTags);
if (savedObjectsTagging) {
references = savedObjectsTagging.ui.updateTagsReferences(
references,
saveProps.newTags || tagsIds
);
}

const docToSave = {
Expand Down Expand Up @@ -570,11 +578,6 @@ export function App({
},
});

const tagsIds =
state.persistedDoc && savedObjectsTagging
? savedObjectsTagging.ui.getTagIdsFromReferences(state.persistedDoc.references)
: [];

return (
<>
<div className="lnsApp">
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/functional/apps/lens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./colors'));
loadTestFile(require.resolve('./drag_and_drop'));
loadTestFile(require.resolve('./lens_reporting'));
loadTestFile(require.resolve('./lens_tagging'));

// has to be last one in the suite because it overrides saved objects
loadTestFile(require.resolve('./rollup'));
Expand Down
118 changes: 118 additions & 0 deletions x-pack/test/functional/apps/lens/lens_tagging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const listingTable = getService('listingTable');
const testSubjects = getService('testSubjects');
const esArchiver = getService('esArchiver');
const retry = getService('retry');
const find = getService('find');
const dashboardVisualizations = getService('dashboardVisualizations');
const dashboardPanelActions = getService('dashboardPanelActions');
const PageObjects = getPageObjects([
'common',
'tagManagement',
'header',
'dashboard',
'visualize',
'lens',
]);

const lensTag = 'extreme-lens-tag';
const lensTitle = 'lens tag test';

describe('lens tagging', () => {
before(async () => {
await esArchiver.loadIfNeeded('logstash_functional');
await esArchiver.loadIfNeeded('lens/basic');
await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.preserveCrossAppState();
await PageObjects.dashboard.clickNewDashboard();
});

it('adds a new tag to a Lens visualization', async () => {
// create lens
await dashboardVisualizations.ensureNewVisualizationDialogIsShowing();
await PageObjects.visualize.clickLensWidget();
await PageObjects.lens.goToTimeRange();
await PageObjects.lens.configureDimension({
dimension: 'lnsXY_xDimensionPanel > lns-empty-dimension',
operation: 'date_histogram',
field: '@timestamp',
});
await PageObjects.lens.configureDimension({
dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension',
operation: 'avg',
field: 'bytes',
});

await PageObjects.lens.configureDimension({
dimension: 'lnsXY_splitDimensionPanel > lns-empty-dimension',
operation: 'terms',
field: 'ip',
});

await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.click('lnsApp_saveButton');

await PageObjects.visualize.setSaveModalValues(lensTitle, {
saveAsNew: false,
redirectToOrigin: true,
});
await testSubjects.click('savedObjectTagSelector');
await testSubjects.click(`tagSelectorOption-action__create`);

expect(await PageObjects.tagManagement.tagModal.isOpened()).to.be(true);

await PageObjects.tagManagement.tagModal.fillForm(
{
name: lensTag,
color: '#FFCC33',
description: '',
},
{
submit: true,
}
);

expect(await PageObjects.tagManagement.tagModal.isOpened()).to.be(false);
await testSubjects.click('confirmSaveSavedObjectButton');
await retry.waitForWithTimeout('Save modal to disappear', 1000, () =>
testSubjects
.missingOrFail('confirmSaveSavedObjectButton')
.then(() => true)
.catch(() => false)
);
});

it('retains its saved object tags after save and return', async () => {
await dashboardPanelActions.openContextMenu();
await dashboardPanelActions.clickEdit();
await PageObjects.lens.saveAndReturn();
await PageObjects.header.waitUntilLoadingHasFinished();

await PageObjects.visualize.gotoVisualizationLandingPage();
await listingTable.waitUntilTableIsLoaded();

// open the filter dropdown
const filterButton = await find.byCssSelector('.euiFilterGroup .euiFilterButton');
await filterButton.click();
await testSubjects.click(
`tag-searchbar-option-${PageObjects.tagManagement.testSubjFriendly(lensTag)}`
);
// click elsewhere to close the filter dropdown
const searchFilter = await find.byCssSelector('main .euiFieldSearch');
await searchFilter.click();
// wait until the table refreshes
await listingTable.waitUntilTableIsLoaded();
const itemNames = await listingTable.getAllItemsNames();
expect(itemNames).to.contain(lensTitle);
});
});
}

0 comments on commit 2beeccc

Please sign in to comment.