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

Fixes #9680 (wrong title when overwriting saved objects) #44441

Closed
wants to merge 5 commits into from

Conversation

friol
Copy link
Contributor

@friol friol commented Aug 29, 2019

Summary

As reported in issue #9680, currently, when overwriting a saved object with a new one with a different title, the confirmation message box will ask (erroneously) if you want to overwrite the object with the new title.
This fix shows the correct (old) title of the object you are going to overwrite.

Also, I updated the code to pass jest and Chrome functional tests ("copy saved object").

@friol friol requested review from a team as code owners August 29, 2019 22:46
@elasticmachine
Copy link
Contributor

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

Copy link
Contributor

@kobelb kobelb left a comment

Choose a reason for hiding this comment

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

I will defer to others on whether or not we should be displaying the title of the object being imported, or the existing title of the saved-object in these situations. However, there are some existing issues with the implementation which we'll want addressed if we do proceed with these changes which I've commented on below.

@friol
Copy link
Contributor Author

friol commented Aug 30, 2019

Hello @kobelb and thanks for your comments.

The reason why the related Issue was opened is that, currently, when you are about to import a saved object with the same id, Kibana asks "Are you sure you want to overwrite <title of the object in .ndjson file>?", which is wrong in any case.

I'm passing down the source space Id, because, as far as I can see, "namespace" is the name of the target space. So, to recover the title of the object that is about to be overwritten, I need the source space - parameter to savedObjectsClient.get().

Ok for the bulkGet.

Thanks

@kobelb
Copy link
Contributor

kobelb commented Sep 4, 2019

I'm passing down the source space Id, because, as far as I can see, "namespace" is the name of the target space. So, to recover the title of the object that is about to be overwritten, I need the source space - parameter to savedObjectsClient.get().

The target namespace is where we're going to be writing the saved object. If I understand correctly, we're wanting to display the title of the saved object we're about to overwrite, we'd be retrieving the title from the target namespace. Would you mind providing an example scenario where the "namespace" property on the "options" is different than the "sourceSpaceId"?

@friol
Copy link
Contributor Author

friol commented Sep 5, 2019

I'm passing down the source space Id, because, as far as I can see, "namespace" is the name of the target space. So, to recover the title of the object that is about to be overwritten, I need the source space - parameter to savedObjectsClient.get().

The target namespace is where we're going to be writing the saved object. If I understand correctly, we're wanting to display the title of the saved object we're about to overwrite, we'd be retrieving the title from the target namespace. Would you mind providing an example scenario where the "namespace" property on the "options" is different than the "sourceSpaceId"?

@kobelb: You are totally right.
I have removed the changes for srcSpaceId and used destSpaceId in the query.
I think one functional test will fail, but I suspect the test may be wrong, at this point.
Thanks.

@friol friol requested a review from kobelb September 17, 2019 19:59
Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

Thanks for your contributions @friol and sorry for taking so long to review, this one slipped under the radar.

I left some comments on the current implementation, but wonder if it wouldn't be much simpler to move all of the existing title resolution to the frontend? If you do savedObjectsClient.bulkGet on the frontend it's a single API call and with a bulk operation like importing all of your saved objects a little bit of extra latency shouldn't matter.

Comment on lines +37 to +47
const errorSavedObjects = new Array();
for (const savedObject of savedObjectResults) {
if (savedObject.error) {
errorSavedObjects.push(savedObject);
}
}

// return an empty array if there are no errors
if (errorSavedObjects.length === 0) {
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 test for savedObject.error.statusCode === 409 instead of just savedObject.error.

Nit: This code would be much more compact and readable if you used an array.filter like:

const errorSavedObjects = savedObjectResults.filter((so) => so.error && so.error.statusCode === 409)

errors.push({
id: savedObject.id,
type: savedObject.type,
title,
title: realTitle,
Copy link
Contributor

Choose a reason for hiding this comment

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

When the import API returns an error, I think the correct response is to include the title of the object that failed to import. The API is saying "I failed while trying to import the title you gave me". Perhaps we can add a new field to the response like existingTitle.

test('extracts errors from saved objects', async () => {
const clientResponse = {
saved_objects: [
{ id: '2', type: 'dashboard', attributes: { title: 'My Dashboard 2' } },
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change these titles to something like 'Existing Dashboard 2' otherwise we're not testing the existing title finding logic you added. I think this will also surface the the bug where we resolve the existing title of "My Dashboard 3" even though this wasn't a conflict error.


const clientResponse = {
saved_objects: [
{ id: '1', type: 'index-pattern', attributes: { title: 'My Index Pattern' } },
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 also change these titles to verify the existing title matching in the test.

@lukeelmers
Copy link
Member

Hi @friol - thanks for this contribution. I'm going to go ahead and close the PR as stale since there hasn't been any activity for quite some time. If you'd still like to contribute, feel free to re-open & we can pick the conversation back up.

Thanks!

@lukeelmers lukeelmers closed this Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants