Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn if the title is a duplicate #10321

Merged
merged 14 commits into from
Feb 24, 2017

Conversation

stacey-gammon
Copy link
Contributor

@stacey-gammon stacey-gammon commented Feb 13, 2017

Fixes #10073

screen shot 2017-02-13 at 2 12 45 pm

@stacey-gammon
Copy link
Contributor Author

jenkins test this

@LeeDr
Copy link
Contributor

LeeDr commented Feb 13, 2017

Does this PR implement the same functionality for Saved Searches and Visualizations? I didn't do a thorough code review but noticed some dashboard files changed but not others that jumped out as Discover or Visualization changes.

I'm not sure the message is clear enough. It tells them that there already is a dashboard with this title. But it could be more clear about what will happen when I click Save dashboard. It's going to create another dashboard with the same name.

Maybe something like this?
A dashboard with the title 'New Dashboard' already exists. Would you like to make a duplicate with the same name?

But I need to think through the scenarios where I think this is going to appear.

  1. one case, I'm editing an object that has been saved and I click Save, leave the existing name, don't check the Save as new ___ checkbox, and click Save.
    This just updates the existing object with any changes. No need to show the dialog.

  2. I'm editing an object that has been saved and I click Save, leave the existing name, and I check the Save as new ___ checkbox, and click Save. That should show your new dialog.

  3. I create a new object and the first time I go to save it I enter the same name as an existing object (it could be the default name). That should show your new dialog. So I guess this is the same case as 2 above.

@stacey-gammon
Copy link
Contributor Author

@LeeDr Updated the error message. I was already handling #1 and #3 but good catch on #2. Implemented that and added a test for it.

Yes the change is implemented across the board for all objects, as the important changes are in saved_object.js. I only added tests for the dashboard.

@stacey-gammon
Copy link
Contributor Author

Hmmm, my query is not correct as it returns matches on substrings. Trying to figure out how to create an exact match query...

@stacey-gammon
Copy link
Contributor Author

jenkins test this

(looks like the build was aborted)

@stacey-gammon stacey-gammon force-pushed the warn-duplicate-title branch 6 times, most recently from c7540dd to 76b9bdb Compare February 16, 2017 14:48
@stacey-gammon
Copy link
Contributor Author

stacey-gammon commented Feb 16, 2017

Hmm, latest build failure is related to saving, but not sure it's due to this PR:

screen shot 2017-02-16 at 10 18 08 am

15:12:57.770: --- tryForTime failure: [POST http://localhost:4444/wd/hub/session/251abda956b6c9bad5a51ef85b848bc7/element / {"using":"link text","value":"Visualization DataTable"}] no such element: Unable to locate element: {"method":"link text","selector":"Visualization DataTable"}
  (Session info: chrome=55.0.2883.87)
  (Driver info: chromedriver=2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3),platform=Linux 3.13.0-74-generic x86_64)
15:13:08.328: --- tryForTime failed again with the same message  ...
15:13:18.888: --- tryForTime failed again with the same message  ...
15:13:29.451: --- tryForTime failed again with the same message  ...
15:13:30.017: Taking screenshot "/var/lib/jenkins/workspace/elastic+kibana+pull-request+multijob-selenium/test/screenshots/failure/failure_1487258010016_data table_should be able to save and load.png"
>> FAIL: chrome on any platform - kibana - visualize app - visualize app - data table - should be able to save and load (49214ms)
Error: tryForTime timeout: [POST http://localhost:4444/wd/hub/session/251abda956b6c9bad5a51ef85b848bc7/element / {"using":"link text","value":"Visualization DataTable"}] no such element: Unable to locate element: {"method":"link text","selector":"Visualization DataTable"}
  (Session info: chrome=55.0.2883.87)
  (Driver info: chromedriver=2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3),platform=Linux 3.13.0-74-generic x86_64)
    at runRequest (/var/lib/jenkins/workspace/elastic+kibana+pull-request+multijob-selenium/node_modules/leadfoot/Session.js:88:40)
    at /var/lib/jenkins/workspace/elastic+kibana+pull-request+multijob-selenium/node_modules/leadfoot/Session.js:109:39

I'll rebase

@stacey-gammon stacey-gammon force-pushed the warn-duplicate-title branch 3 times, most recently from 973b6c5 to f661370 Compare February 16, 2017 20:16
Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality looks great! Just had some minor code suggestions.

err.message === OVERWRITE_REJECTED ||
err.message === SAVE_DUPLICATE_REJECTED)) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we break this up to make it a little more readable?

if (err) {
  if (err.message === OVERWRITE_REJECTED) {
    return;
  }

  if (err.message === SAVE_DUPLICATE_REJECTED) {
    return;
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ehhh, I don't love suggestion, I'd look at that and be like, why not just combine them into an ||?

how about this new variation as a compromise?

@@ -3,7 +3,7 @@
In previous versions of Kibana, changing the name of a {{savedObject.getDisplayName()}} would make a copy with the new name. Use the 'Save as a new {{savedObject.getDisplayName()}}' checkbox to do this now.
</div>
<label>
<input type="checkbox" ng-model="savedObject.copyOnSave" ng-checked="savedObject.copyOnSave">
<input type="checkbox" data-test-subj="saveAsNewCheckbox" ng-model="savedObject.copyOnSave" ng-checked="savedObject.copyOnSave">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put these attributes on multiple lines?

<input
  type="checkbox"
  data-test-subj="saveAsNewCheckbox"
  ng-model="savedObject.copyOnSave"
  ng-checked="savedObject.copyOnSave"
>

expect(countOfDashboards).to.equal(2);
});

bdd.it('Does not warn when saving a duplicate title that remains unchanged for an existing dashboard', async function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a hard time parsing this description... how does this sound to you: "Does not warn when you save an existing dashboard with the title it already has, and that title is a duplicate"? Does that describe this test accurately?

expect(isConfirmOpen).to.equal(false);
});

bdd.it('Warns when saving a duplicate title that remains unchanged when Save as New Dashboard is checked', async function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here, how about: "Warns you when you Save as New Dashboard, and the title is a duplicate"?

'intern/dojo/node!./apps/dashboard',
'intern/dojo/node!./status_page'
// 'intern/dojo/node!./status_page'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha I do this all the time! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This time it was actually intentional :) Trying to reduce the time for a build because I was having a very tough time figuring out what the issue was (turns out it was a delay between saving a new dashboard and reloading the url to point to the newly saved dashboard).

PageObjects.common.debug('Storing time with dashboard: ' + on);
const saveAsNewCheckbox = await PageObjects.common.findTestSubject('saveAsNewCheckbox');
const checked = await saveAsNewCheckbox.getProperty('checked');
if (checked === true && on === false ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be made terser?

if (checked !== isAlreadyChecked) {
  PageObjects.common.debug('Flipping save as new checkbox');
  await saveAsNewCheckbox.click();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh! Good catch, much clearer. :)

@@ -276,8 +319,19 @@ export default class DashboardPage {
await PageObjects.header.setAbsoluteRange(fromTime, toTime);
}

async storeTimeWithDashboard(on) {
async saveAsNewCheckbox(on) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to setSaveAsNewCheckBox(checked) to make it clear what the action is that we're taking?

PageObjects.common.debug('Storing time with dashboard: ' + on);
const saveAsNewCheckbox = await PageObjects.common.findTestSubject('saveAsNewCheckbox');
const checked = await saveAsNewCheckbox.getProperty('checked');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to isAlreadyChecked?

@stacey-gammon stacey-gammon force-pushed the warn-duplicate-title branch 2 times, most recently from 0eae3c7 to c1e2f59 Compare February 17, 2017 17:31
* @param error {Error} the error
* @return {boolean}
*/
function getShouldSuppressExpectedError(error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming this to isErrorNonFatal? This way the name of function helps us assign meaning to the error without specifying what we should do about it. If for some reason we decide to return the error instead of suppressing it, this function will still be useful and won't need to be renamed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a little confusing too because it's not an error at all, it's a user response. The whole flow is a bit awkward, and it'd be better if we just stopped using the confirmModalPromise to begin with, but I don't want to do that refactor now.

I have no better suggestion, so sgtm for now.

@stacey-gammon stacey-gammon force-pushed the warn-duplicate-title branch 3 times, most recently from a0c8896 to a0c5daf Compare February 22, 2017 17:02
@stacey-gammon
Copy link
Contributor Author

@cjcenizal or @LeeDr, any more comments on this PR? I think I addressed everything.

@LeeDr
Copy link
Contributor

LeeDr commented Feb 23, 2017

I just tried a case with saving Visualizations where it didn't work, probably because of the characters I used?

  1. I saved a search as ----- #####
  2. I saved it again and checked the box Save as a new visualization
  3. I should have gotten the message that it already exists, but I didn't.

Obviously this is an odd case, and I only tried this one visualization name so far. So I don't know exactly what cases work and which don't. Are we comparing analyzed names which would remove those chars?

I'll keep testing a bit more.

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@LeeDr
Copy link
Contributor

LeeDr commented Feb 23, 2017

Also if I name an object ///// I can create more of them with no warnings.

But combinations of special characters and letter always seems to work correctly.
- test - name gives a warning if I try to make a copy.
and test - name doesn't incorrectly give a warning matching - test - name.

And I also tested that the duplication check is only within that object type. So I can create a saved search, visualization, and dashboard all with the name test1 with no warnings (as I would expect).

If the special character cases aren't easy to solve, I'd still give a LGTM.

@stacey-gammon
Copy link
Contributor Author

Unfortunately it's not easy to fix @LeeDr. If I have a visualization name /// and I run this query in devtools:

GET _search
{
  "query": {
    "bool": {
     "must": { "match_phrase": {  "title": "///" } }
    }
  }
}

Nothing is returned, presumably because it strips special characters.

If this issue were resolved: #10348 then we could get around this shortcoming.

For the short term, I think we should acknowledge it as a limitation, but move forward.

Copy link
Contributor

@LeeDr LeeDr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks / for - checking # on the special ! chars :-)

@stacey-gammon stacey-gammon merged commit c253583 into elastic:master Feb 24, 2017
elastic-jasper added a commit that referenced this pull request Feb 24, 2017
Backports PR #10321

**Commit 1:**
Warn if the title is a duplicate

* Original sha: b0aa0b8
* Authored by Stacey Gammon <[email protected]> on 2017-02-13T18:07:23Z

**Commit 2:**
warn when copyOnSave is checked.  add a test

* Original sha: ee42002
* Authored by Stacey Gammon <[email protected]> on 2017-02-14T14:20:37Z

**Commit 3:**
update message

* Original sha: c90c8ae
* Authored by Stacey Gammon <[email protected]> on 2017-02-14T14:24:50Z

**Commit 4:**
fix tests

* Original sha: 5ec1a92
* Authored by Stacey Gammon <[email protected]> on 2017-02-14T15:04:14Z

**Commit 5:**
Fix issues with substring matching

add more tests.

* Original sha: 4335e9e
* Authored by Stacey Gammon <[email protected]> on 2017-02-14T18:54:58Z

**Commit 6:**
make case insensitive and return matching title

* Original sha: 8881739
* Authored by Stacey Gammon <[email protected]> on 2017-02-14T19:34:04Z

**Commit 7:**
Fix bug caused by subtle difference between this.type and type

Add a comment and rename one of the variables to make the distinction
clearer.

* Original sha: f4011ce
* Authored by Stacey Gammon <[email protected]> on 2017-02-16T16:31:13Z

**Commit 8:**
add debug messages.

* Original sha: 2d44889
* Authored by Stacey Gammon <[email protected]> on 2017-02-16T18:05:03Z

**Commit 9:**
fix tests again

* Original sha: 3212c91
* Authored by Stacey Gammon <[email protected]> on 2017-02-16T22:10:25Z

**Commit 10:**
uncomment out tests

* Original sha: 1f2cb28
* Authored by Stacey Gammon <[email protected]> on 2017-02-16T22:12:06Z

**Commit 11:**
more debug messages

* Original sha: 807b190
* Authored by Stacey Gammon <[email protected]> on 2017-02-17T02:09:37Z

**Commit 12:**
save more screenshots

* Original sha: 3d025e9
* Authored by Stacey Gammon <[email protected]> on 2017-02-17T02:34:29Z

**Commit 13:**
Need to wait till save finishes or the page may redirect the url after the page has navigated away

* Original sha: de00e24
* Authored by Stacey Gammon <[email protected]> on 2017-02-17T14:01:22Z

**Commit 14:**
address code review comments

* Original sha: 7bc0268
* Authored by Stacey Gammon <[email protected]> on 2017-02-17T17:28:34Z
stacey-gammon pushed a commit to stacey-gammon/kibana that referenced this pull request Feb 24, 2017
Backports PR elastic#10321

**Commit 1:**
Warn if the title is a duplicate

* Original sha: b0aa0b8
* Authored by Stacey Gammon <[email protected]> on 2017-02-13T18:07:23Z

**Commit 2:**
warn when copyOnSave is checked.  add a test

* Original sha: ee42002
* Authored by Stacey Gammon <[email protected]> on 2017-02-14T14:20:37Z

**Commit 3:**
update message

* Original sha: c90c8ae
* Authored by Stacey Gammon <[email protected]> on 2017-02-14T14:24:50Z

**Commit 4:**
fix tests

* Original sha: 5ec1a92
* Authored by Stacey Gammon <[email protected]> on 2017-02-14T15:04:14Z

**Commit 5:**
Fix issues with substring matching

add more tests.

* Original sha: 4335e9e
* Authored by Stacey Gammon <[email protected]> on 2017-02-14T18:54:58Z

**Commit 6:**
make case insensitive and return matching title

* Original sha: 8881739
* Authored by Stacey Gammon <[email protected]> on 2017-02-14T19:34:04Z

**Commit 7:**
Fix bug caused by subtle difference between this.type and type

Add a comment and rename one of the variables to make the distinction
clearer.

* Original sha: f4011ce
* Authored by Stacey Gammon <[email protected]> on 2017-02-16T16:31:13Z

**Commit 8:**
add debug messages.

* Original sha: 2d44889
* Authored by Stacey Gammon <[email protected]> on 2017-02-16T18:05:03Z

**Commit 9:**
fix tests again

* Original sha: 3212c91
* Authored by Stacey Gammon <[email protected]> on 2017-02-16T22:10:25Z

**Commit 10:**
uncomment out tests

* Original sha: 1f2cb28
* Authored by Stacey Gammon <[email protected]> on 2017-02-16T22:12:06Z

**Commit 11:**
more debug messages

* Original sha: 807b190
* Authored by Stacey Gammon <[email protected]> on 2017-02-17T02:09:37Z

**Commit 12:**
save more screenshots

* Original sha: 3d025e9
* Authored by Stacey Gammon <[email protected]> on 2017-02-17T02:34:29Z

**Commit 13:**
Need to wait till save finishes or the page may redirect the url after the page has navigated away

* Original sha: de00e24
* Authored by Stacey Gammon <[email protected]> on 2017-02-17T14:01:22Z

**Commit 14:**
address code review comments

* Original sha: 7bc0268
* Authored by Stacey Gammon <[email protected]> on 2017-02-17T17:28:34Z
stacey-gammon added a commit to stacey-gammon/kibana that referenced this pull request Feb 24, 2017
stacey-gammon added a commit that referenced this pull request Feb 25, 2017
@stacey-gammon stacey-gammon deleted the warn-duplicate-title branch April 6, 2017 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Dashboard Dashboard related features v5.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants