Skip to content

Commit

Permalink
[lens] fix unhandled promise rejection when saving Lens with duplicat…
Browse files Browse the repository at this point in the history
…e 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 <[email protected]>
  • Loading branch information
nreese and kibanamachine authored Nov 2, 2020
1 parent ba1b20d commit 97a32fd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 32 deletions.
9 changes: 4 additions & 5 deletions x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -722,15 +722,14 @@ describe('Lens App', () => {
});
expect(services.attributeService.wrapAttributes).toHaveBeenCalledWith(
expect.objectContaining({
savedObjectId: undefined,
title: 'hello there',
}),
true,
undefined
);
expect(props.redirectTo).toHaveBeenCalledWith('aaa');
expect(props.redirectTo).toHaveBeenCalledWith(defaultSavedObjectId);
await act(async () => {
component.setProps({ initialInput: { savedObjectId: 'aaa' } });
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
});
expect(services.attributeService.wrapAttributes).toHaveBeenCalledTimes(1);
expect(services.notifications.toasts.addSuccess).toHaveBeenCalledWith(
Expand Down Expand Up @@ -781,7 +780,6 @@ describe('Lens App', () => {
await act(async () => {
testSave(component, { newCopyOnSave: false, newTitle: 'hello there' });
});
expect(services.notifications.toasts.addDanger).toHaveBeenCalled();
expect(props.redirectTo).not.toHaveBeenCalled();
expect(getButton(component).disableButton).toEqual(false);
});
Expand Down Expand Up @@ -857,6 +855,7 @@ describe('Lens App', () => {
);
component.update();
await act(async () => {
component.setProps({ initialInput: { savedObjectId: '123' } });
getButton(component).run(component.getDOMNode());
});
component.update();
Expand All @@ -871,7 +870,7 @@ describe('Lens App', () => {
});
});
expect(checkForDuplicateTitle).toHaveBeenCalledWith(
expect.objectContaining({ savedObjectId: '123' }),
expect.objectContaining({ id: '123' }),
false,
onTitleDuplicate,
expect.anything()
Expand Down
50 changes: 25 additions & 25 deletions x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ export function App({
const docToSave = {
...getLastKnownDocWithoutPinnedFilters()!,
description: saveProps.newDescription,
savedObjectId: saveProps.newCopyOnSave ? undefined : lastKnownDoc.savedObjectId,
title: saveProps.newTitle,
};

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

const originalInput = saveProps.newCopyOnSave ? undefined : initialInput;
const originalSavedObjectId = (originalInput as LensByReferenceInput)?.savedObjectId;
if (options.saveToLibrary && !originalInput) {
await checkForDuplicateTitle(
{
...docToSave,
copyOnSave: saveProps.newCopyOnSave,
lastSavedTitle: lastKnownDoc.title,
getEsType: () => 'lens',
getDisplayName: () =>
i18n.translate('xpack.lens.app.saveModalType', {
defaultMessage: 'Lens visualization',
}),
},
saveProps.isTitleDuplicateConfirmed,
saveProps.onTitleDuplicate,
{
savedObjectsClient,
overlays,
}
);
if (options.saveToLibrary) {
try {
await checkForDuplicateTitle(
{
id: originalSavedObjectId,
title: docToSave.title,
copyOnSave: saveProps.newCopyOnSave,
lastSavedTitle: lastKnownDoc.title,
getEsType: () => 'lens',
getDisplayName: () =>
i18n.translate('xpack.lens.app.saveModalType', {
defaultMessage: 'Lens visualization',
}),
},
saveProps.isTitleDuplicateConfirmed,
saveProps.onTitleDuplicate,
{
savedObjectsClient,
overlays,
}
);
} catch (e) {
// ignore duplicate title failure, user notified in save modal
return;
}
}
try {
const newInput = (await attributeService.wrapAttributes(
Expand Down Expand Up @@ -453,11 +458,6 @@ export function App({
// eslint-disable-next-line no-console
console.dir(e);
trackUiEvent('save_failed');
notifications.toasts.addDanger(
i18n.translate('xpack.lens.app.docSavingError', {
defaultMessage: 'Error saving document',
})
);
setState((s) => ({ ...s, isSaveModalVisible: false }));
}
};
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -10692,7 +10692,6 @@
"xpack.lens.app.cancel": "キャンセル",
"xpack.lens.app.cancelButtonAriaLabel": "変更を保存せずに最後に使用していたアプリに戻る",
"xpack.lens.app.docLoadingError": "保存されたドキュメントの保存中にエラーが発生",
"xpack.lens.app.docSavingError": "ドキュメントの保存中にエラーが発生",
"xpack.lens.app.indexPatternLoadingError": "インデックスパターンの読み込み中にエラーが発生",
"xpack.lens.app.save": "保存",
"xpack.lens.app.saveAndReturn": "保存して戻る",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -10705,7 +10705,6 @@
"xpack.lens.app.cancel": "取消",
"xpack.lens.app.cancelButtonAriaLabel": "返回到上一个应用而不保存更改",
"xpack.lens.app.docLoadingError": "加载已保存文档时出错",
"xpack.lens.app.docSavingError": "保存文档时出错",
"xpack.lens.app.indexPatternLoadingError": "加载索引模式时出错",
"xpack.lens.app.save": "保存",
"xpack.lens.app.saveAndReturn": "保存并返回",
Expand Down

0 comments on commit 97a32fd

Please sign in to comment.