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

[Lens] Add toast notification when visualization is saved #80788

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,9 @@ describe('Lens App', () => {
undefined
);
expect(props.redirectTo).toHaveBeenCalledWith('aaa');
expect(services.notifications.toasts.addSuccess).toHaveBeenCalledWith(
"Saved 'hello there'"
);
});

it('adds to the recently accessed list on save', async () => {
Expand Down Expand Up @@ -729,6 +732,9 @@ describe('Lens App', () => {
component.setProps({ initialInput: { savedObjectId: 'aaa' } });
});
expect(services.attributeService.wrapAttributes).toHaveBeenCalledTimes(1);
expect(services.notifications.toasts.addSuccess).toHaveBeenCalledWith(
"Saved 'hello there'"
);
});

it('saves existing docs', async () => {
Expand All @@ -750,6 +756,9 @@ describe('Lens App', () => {
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
});
expect(services.attributeService.unwrapAttributes).toHaveBeenCalledTimes(1);
expect(services.notifications.toasts.addSuccess).toHaveBeenCalledWith(
"Saved 'hello there'"
);
});

it('handles save failure by showing a warning, but still allows another save', async () => {
Expand Down
16 changes: 16 additions & 0 deletions x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,14 @@ export function App({
isSaveModalVisible: false,
isLinkedToOriginatingApp: false,
}));
notifications.toasts.addSuccess(
Copy link
Contributor

Choose a reason for hiding this comment

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

You put the same notification in this conditional branch and in the main one (https://github.com/elastic/kibana/pull/80788/files#diff-62b4eca6ab93c938023295869419d9b3031fd1c11470d5a3fec89f0012bbf036R451-R458) - it seems like putting just a single invocation in front of the branched code (line 413 of this file) would achieve the same result. Is there any reason I'm missing you didn't do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right! I was actually following where isSaveModalVisible: false was to display the toast notification when the save modal is closed. I just tried your suggestion, and it indeed achieves the same result. I also did a manual test and ran node scripts/jest lens to verify the suggested change.

i18n.translate('visualize.topNavMenu.saveVisualization.successNotificationText', {
defaultMessage: `Saved '{visTitle}'`,
values: {
visTitle: docToSave.title,
},
})
);
redirectTo(newInput.savedObjectId);
return;
}
Expand All @@ -440,6 +448,14 @@ export function App({
isSaveModalVisible: false,
isLinkedToOriginatingApp: false,
}));
notifications.toasts.addSuccess(
i18n.translate('visualize.topNavMenu.saveVisualization.successNotificationText', {
defaultMessage: `Saved '{visTitle}'`,
values: {
visTitle: newDoc.title,
},
})
);
} catch (e) {
// eslint-disable-next-line no-console
console.dir(e);
Expand Down