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>
This commit is contained in:
Vadim Yakhin 2021-07-05 12:45:43 -03:00 committed by GitHub
parent 2a37ef8c5f
commit 1b92c29d18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 22 deletions

View file

@ -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(<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', () => {

View file

@ -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<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>