forked from ansible/ansible-hub-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollection-card.tsx
180 lines (173 loc) · 4.63 KB
/
collection-card.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import { Trans, t } from '@lingui/macro';
import {
Badge,
Button,
Card,
CardBody,
CardFooter,
CardHeader,
Text,
TextContent,
TextVariants,
} from '@patternfly/react-core';
import ArrowRightIcon from '@patternfly/react-icons/dist/esm/icons/arrow-right-icon';
import React from 'react';
import { Link } from 'react-router-dom';
import { CollectionVersionSearch } from 'src/api';
import {
CollectionNumericLabel,
Logo,
SignatureBadge,
Tooltip,
} from 'src/components';
import { Constants } from 'src/constants';
import { useContext } from 'src/loaders/app-context';
import { Paths, formatPath } from 'src/paths';
import { convertContentSummaryCounts, namespaceTitle } from 'src/utilities';
interface IProps extends CollectionVersionSearch {
displaySignatures: boolean;
footer?: React.ReactNode;
menu?: React.ReactNode;
}
export const CollectionNextPageCard = ({
onClick,
}: {
onClick: () => void;
}) => {
return (
<Card className='hub-c-card-collection-container card'>
<div
style={{
display: 'flex',
height: '100%',
justifyContent: 'center',
}}
>
<Button variant='link' onClick={onClick}>
{t`View more`}
<br />
<br />
<ArrowRightIcon />
</Button>
</div>
</Card>
);
};
export const CollectionCard = ({
collection_version,
namespace_metadata: namespace,
repository,
is_signed,
displaySignatures,
menu,
footer,
}: IProps) => {
const { featureFlags } = useContext();
const MAX_DESCRIPTION_LENGTH = 60;
const nsTitle = namespaceTitle(
namespace || { name: collection_version.namespace },
);
const contentSummary = convertContentSummaryCounts(collection_version);
return (
<Card className='hub-c-card-collection-container card'>
<CardHeader className='logo-row'>
<Logo
alt={t`${nsTitle} logo`}
fallbackToDefault
image={namespace?.avatar_url}
size='40px'
unlockWidth
flexGrow
/>
<div className='card-badge-area'>
{featureFlags.display_repositories ? (
<TextContent>
<Text component={TextVariants.small}>
<Badge isRead>
<Link
to={formatPath(Paths.ansibleRepositoryDetail, {
name: repository.name,
})}
>
{repository.name === Constants.CERTIFIED_REPO
? t`Certified`
: repository.name}
</Link>
</Badge>
</Text>
</TextContent>
) : null}
{displaySignatures ? (
<SignatureBadge
isCompact
signState={is_signed ? 'signed' : 'unsigned'}
/>
) : null}
</div>
{menu}
</CardHeader>
<CardHeader>
<div className='name'>
<Link
to={formatPath(Paths.collectionByRepo, {
collection: collection_version.name,
namespace: collection_version.namespace,
repo: repository.name,
})}
>
{collection_version.name}
</Link>
</div>
<div className='author'>
<TextContent>
<Text component={TextVariants.small}>
<Trans>
Provided by
<Link
to={formatPath(Paths.namespaceDetail, {
namespace: collection_version.namespace,
})}
>
{nsTitle}
</Link>
</Trans>
</Text>
</TextContent>
</div>
</CardHeader>
<CardBody>
<Tooltip content={<div>{collection_version.description}</div>}>
<div className='description'>
{getDescription(
collection_version.description,
MAX_DESCRIPTION_LENGTH,
)}
</div>
</Tooltip>
</CardBody>
<CardBody className='type-container'>
{Object.keys(contentSummary.contents).map((k) =>
renderTypeCount(k, contentSummary.contents[k]),
)}
</CardBody>
{footer && <CardFooter>{footer}</CardFooter>}
</Card>
);
};
function getDescription(d: string, MAX_DESCRIPTION_LENGTH) {
if (!d) {
return '';
}
if (d.length > MAX_DESCRIPTION_LENGTH) {
return d.slice(0, MAX_DESCRIPTION_LENGTH) + '...';
} else {
return d;
}
}
function renderTypeCount(type, count) {
return (
<div key={type}>
<CollectionNumericLabel count={count} newline type={type} />
</div>
);
}