Skip to content

Commit

Permalink
Fix Overview page crashing (elastic#104258) (elastic#104752)
Browse files Browse the repository at this point in the history
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>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
yakhinvadim and kibanamachine authored Jul 7, 2021
1 parent 8cb83a1 commit cba02df
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -46,13 +51,14 @@ describe('RecentActivity', () => {
it('renders an activityFeed with links', () => {
setMockValues({ activityFeed });
const wrapper = shallow(<RecentActivity />);
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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface FeedActivity {
id: string;
message: string;
timestamp: string;
sourceId: string;
sourceId?: string;
}

export const RecentActivity: React.FC = () => {
Expand Down Expand Up @@ -98,23 +98,29 @@ export const RecentActivityItem: React.FC<FeedActivity> = ({
return (
<div className={`activity ${status ? `activity--${status}` : ''}`}>
<div className="activity__message">
<EuiLinkTo
onClick={onClick}
color={status === 'error' ? 'danger' : 'primary'}
to={getContentSourcePath(SOURCE_DETAILS_PATH, sourceId, true)}
data-test-subj="viewSourceDetailsLink"
>
{id} {message}
{status === 'error' && (
<span className="activity--error__label">
{' '}
<FormattedMessage
id="xpack.enterpriseSearch.workplaceSearch.recentActivitySourceLink.linkLabel"
defaultMessage="View Source"
/>
</span>
)}
</EuiLinkTo>
{sourceId ? (
<EuiLinkTo
onClick={onClick}
color={status === 'error' ? 'danger' : 'primary'}
to={getContentSourcePath(SOURCE_DETAILS_PATH, sourceId, true)}
data-test-subj="viewSourceDetailsLink"
>
{id} {message}
{status === 'error' && (
<span className="activity--error__label">
{' '}
<FormattedMessage
id="xpack.enterpriseSearch.workplaceSearch.recentActivitySourceLink.linkLabel"
defaultMessage="View Source"
/>
</span>
)}
</EuiLinkTo>
) : (
<div data-test-subj="newUserTextWrapper">
{id} {message}
</div>
)}
</div>
<div className="activity__date">{moment.utc(timestamp).fromNow()}</div>
</div>
Expand Down

0 comments on commit cba02df

Please sign in to comment.