forked from ansible/ansible-hub-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlegacy-namespace-item.tsx
90 lines (78 loc) · 2.13 KB
/
legacy-namespace-item.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { t } from '@lingui/macro';
import {
DataListCell,
DataListItem,
DataListItemCells,
DataListItemRow,
DropdownItem,
} from '@patternfly/react-core';
import React from 'react';
import { Link } from 'react-router-dom';
import { LegacyNamespaceDetailType } from 'src/api';
import { Logo, StatefulDropdown } from 'src/components';
import { useContext } from 'src/loaders/app-context';
import { Paths, formatPath } from 'src/paths';
import './legacy-namespace-item.scss';
interface LegacyNamespaceProps {
namespace: LegacyNamespaceDetailType;
openModal?: (namespace) => void;
}
export function LegacyNamespaceListItem({
namespace,
openModal,
}: LegacyNamespaceProps) {
const {
featureFlags: { ai_deny_index },
user: { username, is_superuser },
} = useContext();
const { id, avatar_url, name, summary_fields } = namespace;
const namespace_url = formatPath(Paths.standaloneNamespace, {
namespaceid: id,
});
const cells = [];
cells.push(
<DataListCell isFilled={false} alignRight={false} key='ns'>
<Logo
alt='logo'
fallbackToDefault
image={avatar_url}
size='40px'
unlockWidth
width='97px'
/>
</DataListCell>,
);
cells.push(
<DataListCell key='content' size={10}>
<div>
<Link to={namespace_url}>{name}</Link>
</div>
</DataListCell>,
);
const userOwnsLegacyNamespace = !!summary_fields.owners.find(
(n) => n.username == username,
);
const showWisdom = ai_deny_index && (is_superuser || userOwnsLegacyNamespace);
const dropdownItems = [];
dropdownItems.push(
<DropdownItem
onClick={() => openModal(namespace)}
>{t`Ansible Lightspeed settings`}</DropdownItem>,
);
if (showWisdom && openModal) {
cells.push(
<DataListCell key='menu' alignRight={true}>
<div style={{ float: 'right' }}>
<StatefulDropdown items={dropdownItems} />
</div>
</DataListCell>,
);
}
return (
<DataListItem data-cy='LegacyNamespaceListItem'>
<DataListItemRow>
<DataListItemCells dataListCells={cells} />
</DataListItemRow>
</DataListItem>
);
}