-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
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? |
There was a problem hiding this 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.
x-pack/legacy/plugins/spaces/server/lib/copy_to_spaces/copy_to_spaces.ts
Outdated
Show resolved
Hide resolved
x-pack/legacy/plugins/spaces/server/lib/copy_to_spaces/copy_to_spaces.ts
Outdated
Show resolved
Hide resolved
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 |
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"? |
…d in extractErrors
@kobelb: You are totally right. |
There was a problem hiding this 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.
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 []; | ||
} |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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' } }, |
There was a problem hiding this comment.
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' } }, |
There was a problem hiding this comment.
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.
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! |
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").