-
Notifications
You must be signed in to change notification settings - Fork 960
/
index.tsx
70 lines (60 loc) · 1.66 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright Contributors to the Amundsen project.
// SPDX-License-Identifier: Apache-2.0
import * as React from 'react';
import * as Avatar from 'react-avatar';
import { OverlayTrigger, Popover } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import { TableReader } from 'interfaces';
import { indexUsersEnabled } from 'config/config-utils';
import { logClick } from 'utils/analytics';
import './styles.scss';
export interface FrequentUsersProps {
readers: TableReader[];
}
export function renderReader(
reader: TableReader,
index: number,
readers: TableReader[]
) {
const { user } = reader;
let link = user.profile_url;
let target = '_blank';
if (indexUsersEnabled()) {
link = `/user/${user.user_id}?source=frequent_users`;
target = '';
}
return (
<OverlayTrigger
key={user.display_name}
trigger={['hover', 'focus']}
placement="top"
overlay={
<Popover id="popover-trigger-hover-focus">{user.display_name}</Popover>
}
>
<Link
className="avatar-overlap"
onClick={logClick}
data-type="frequent-users"
to={link}
target={target}
>
<Avatar
name={user.display_name}
round
size={25}
style={{ zIndex: readers.length - index, position: 'relative' }}
/>
</Link>
</OverlayTrigger>
);
}
const FrequentUsers: React.FC<FrequentUsersProps> = ({
readers,
}: FrequentUsersProps) => {
if (readers.length === 0) {
return <span className="body-3">No frequent users exist</span>;
}
return <div className="frequent-users">{readers.map(renderReader)}</div>;
};
export default FrequentUsers;