Skip to content

Commit 97a32fd

Browse files
[lens] fix unhandled promise rejection when saving Lens with duplicate title (#82195)
* [lens] fix unhandled promise rejection when saving Lens with duplicate title * more clean up * restore getDisplayName, used by return of checkForDuplicateTitle * fix jest test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent ba1b20d commit 97a32fd

4 files changed

Lines changed: 29 additions & 32 deletions

File tree

x-pack/plugins/lens/public/app_plugin/app.test.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,15 +722,14 @@ describe('Lens App', () => {
722722
});
723723
expect(services.attributeService.wrapAttributes).toHaveBeenCalledWith(
724724
expect.objectContaining({
725-
savedObjectId: undefined,
726725
title: 'hello there',
727726
}),
728727
true,
729728
undefined
730729
);
731-
expect(props.redirectTo).toHaveBeenCalledWith('aaa');
730+
expect(props.redirectTo).toHaveBeenCalledWith(defaultSavedObjectId);
732731
await act(async () => {
733-
component.setProps({ initialInput: { savedObjectId: 'aaa' } });
732+
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
734733
});
735734
expect(services.attributeService.wrapAttributes).toHaveBeenCalledTimes(1);
736735
expect(services.notifications.toasts.addSuccess).toHaveBeenCalledWith(
@@ -781,7 +780,6 @@ describe('Lens App', () => {
781780
await act(async () => {
782781
testSave(component, { newCopyOnSave: false, newTitle: 'hello there' });
783782
});
784-
expect(services.notifications.toasts.addDanger).toHaveBeenCalled();
785783
expect(props.redirectTo).not.toHaveBeenCalled();
786784
expect(getButton(component).disableButton).toEqual(false);
787785
});
@@ -857,6 +855,7 @@ describe('Lens App', () => {
857855
);
858856
component.update();
859857
await act(async () => {
858+
component.setProps({ initialInput: { savedObjectId: '123' } });
860859
getButton(component).run(component.getDOMNode());
861860
});
862861
component.update();
@@ -871,7 +870,7 @@ describe('Lens App', () => {
871870
});
872871
});
873872
expect(checkForDuplicateTitle).toHaveBeenCalledWith(
874-
expect.objectContaining({ savedObjectId: '123' }),
873+
expect.objectContaining({ id: '123' }),
875874
false,
876875
onTitleDuplicate,
877876
expect.anything()

x-pack/plugins/lens/public/app_plugin/app.tsx

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ export function App({
359359
const docToSave = {
360360
...getLastKnownDocWithoutPinnedFilters()!,
361361
description: saveProps.newDescription,
362-
savedObjectId: saveProps.newCopyOnSave ? undefined : lastKnownDoc.savedObjectId,
363362
title: saveProps.newTitle,
364363
};
365364

@@ -375,25 +374,31 @@ export function App({
375374

376375
const originalInput = saveProps.newCopyOnSave ? undefined : initialInput;
377376
const originalSavedObjectId = (originalInput as LensByReferenceInput)?.savedObjectId;
378-
if (options.saveToLibrary && !originalInput) {
379-
await checkForDuplicateTitle(
380-
{
381-
...docToSave,
382-
copyOnSave: saveProps.newCopyOnSave,
383-
lastSavedTitle: lastKnownDoc.title,
384-
getEsType: () => 'lens',
385-
getDisplayName: () =>
386-
i18n.translate('xpack.lens.app.saveModalType', {
387-
defaultMessage: 'Lens visualization',
388-
}),
389-
},
390-
saveProps.isTitleDuplicateConfirmed,
391-
saveProps.onTitleDuplicate,
392-
{
393-
savedObjectsClient,
394-
overlays,
395-
}
396-
);
377+
if (options.saveToLibrary) {
378+
try {
379+
await checkForDuplicateTitle(
380+
{
381+
id: originalSavedObjectId,
382+
title: docToSave.title,
383+
copyOnSave: saveProps.newCopyOnSave,
384+
lastSavedTitle: lastKnownDoc.title,
385+
getEsType: () => 'lens',
386+
getDisplayName: () =>
387+
i18n.translate('xpack.lens.app.saveModalType', {
388+
defaultMessage: 'Lens visualization',
389+
}),
390+
},
391+
saveProps.isTitleDuplicateConfirmed,
392+
saveProps.onTitleDuplicate,
393+
{
394+
savedObjectsClient,
395+
overlays,
396+
}
397+
);
398+
} catch (e) {
399+
// ignore duplicate title failure, user notified in save modal
400+
return;
401+
}
397402
}
398403
try {
399404
const newInput = (await attributeService.wrapAttributes(
@@ -453,11 +458,6 @@ export function App({
453458
// eslint-disable-next-line no-console
454459
console.dir(e);
455460
trackUiEvent('save_failed');
456-
notifications.toasts.addDanger(
457-
i18n.translate('xpack.lens.app.docSavingError', {
458-
defaultMessage: 'Error saving document',
459-
})
460-
);
461461
setState((s) => ({ ...s, isSaveModalVisible: false }));
462462
}
463463
};

x-pack/plugins/translations/translations/ja-JP.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10692,7 +10692,6 @@
1069210692
"xpack.lens.app.cancel": "キャンセル",
1069310693
"xpack.lens.app.cancelButtonAriaLabel": "変更を保存せずに最後に使用していたアプリに戻る",
1069410694
"xpack.lens.app.docLoadingError": "保存されたドキュメントの保存中にエラーが発生",
10695-
"xpack.lens.app.docSavingError": "ドキュメントの保存中にエラーが発生",
1069610695
"xpack.lens.app.indexPatternLoadingError": "インデックスパターンの読み込み中にエラーが発生",
1069710696
"xpack.lens.app.save": "保存",
1069810697
"xpack.lens.app.saveAndReturn": "保存して戻る",

x-pack/plugins/translations/translations/zh-CN.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10705,7 +10705,6 @@
1070510705
"xpack.lens.app.cancel": "取消",
1070610706
"xpack.lens.app.cancelButtonAriaLabel": "返回到上一个应用而不保存更改",
1070710707
"xpack.lens.app.docLoadingError": "加载已保存文档时出错",
10708-
"xpack.lens.app.docSavingError": "保存文档时出错",
1070910708
"xpack.lens.app.indexPatternLoadingError": "加载索引模式时出错",
1071010709
"xpack.lens.app.save": "保存",
1071110710
"xpack.lens.app.saveAndReturn": "保存并返回",

0 commit comments

Comments
 (0)