From 1b92c29d18959f571c18bdb1447f8dc1ed04080a Mon Sep 17 00:00:00 2001 From: Vadim Yakhin Date: Mon, 5 Jul 2021 12:45:43 -0300 Subject: [PATCH] Fix Overview page crashing (#104258) The activity feed tried to render a link to a source for activity items like "New user joined organization". This couldn't be done and the page crashed. This PR accounts for this case by rendering an item with no link for such cases. This was already fixed before in ent-search in https://github.com/elastic/ent-search/pull/2574 But we didn't port the PR, because we thought there is no need to port a part of Standard auth functionality. Turned out there is. Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../views/overview/recent_activity.test.tsx | 14 +++++-- .../views/overview/recent_activity.tsx | 42 +++++++++++-------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/recent_activity.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/recent_activity.test.tsx index 0cb3f77c681a..78e4954a4bf1 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/recent_activity.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/recent_activity.test.tsx @@ -30,6 +30,11 @@ const activityFeed = [ target: 'http://localhost:3002/ws/org/sources', timestamp: '2020-06-24 16:34:16', }, + { + id: '(foo@example.com)', + message: 'joined the organization', + timestamp: '2021-07-02 16:38:27', + }, ]; describe('RecentActivity', () => { @@ -46,13 +51,14 @@ describe('RecentActivity', () => { it('renders an activityFeed with links', () => { setMockValues({ activityFeed }); const wrapper = shallow(); - const activity = wrapper.find(RecentActivityItem).dive(); + const sourceActivityItem = wrapper.find(RecentActivityItem).first().dive(); + const newUserActivityItem = wrapper.find(RecentActivityItem).last().dive(); - expect(activity).toHaveLength(1); - - const link = activity.find('[data-test-subj="viewSourceDetailsLink"]'); + const link = sourceActivityItem.find('[data-test-subj="viewSourceDetailsLink"]'); link.simulate('click'); expect(mockTelemetryActions.sendWorkplaceSearchTelemetry).toHaveBeenCalled(); + + expect(newUserActivityItem.find('[data-test-subj="newUserTextWrapper"]')).toHaveLength(1); }); it('renders activity item error state', () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/recent_activity.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/recent_activity.tsx index 8bda7c2843b9..51a650898603 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/recent_activity.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/recent_activity.tsx @@ -29,7 +29,7 @@ export interface FeedActivity { id: string; message: string; timestamp: string; - sourceId: string; + sourceId?: string; } export const RecentActivity: React.FC = () => { @@ -98,23 +98,29 @@ export const RecentActivityItem: React.FC = ({ return (
- - {id} {message} - {status === 'error' && ( - - {' '} - - - )} - + {sourceId ? ( + + {id} {message} + {status === 'error' && ( + + {' '} + + + )} + + ) : ( +
+ {id} {message} +
+ )}
{moment.utc(timestamp).fromNow()}