2021-08-31 22:00:56 -07:00
|
|
|
import { Image, Typography } from 'antd';
|
2021-10-14 10:11:56 -07:00
|
|
|
import React, { ReactNode } from 'react';
|
2021-02-03 11:49:51 -08:00
|
|
|
import { Link } from 'react-router-dom';
|
2021-03-23 15:18:32 -07:00
|
|
|
import styled from 'styled-components';
|
2021-10-14 10:11:56 -07:00
|
|
|
import { GlobalTags, Owner, GlossaryTerms, SearchInsight } from '../../types.generated';
|
2021-02-23 12:45:42 -08:00
|
|
|
import { useEntityRegistry } from '../useEntityRegistry';
|
2021-05-11 17:55:45 -07:00
|
|
|
import AvatarsGroup from '../shared/avatar/AvatarsGroup';
|
2021-05-18 07:49:42 +05:30
|
|
|
import TagTermGroup from '../shared/tags/TagTermGroup';
|
2021-08-31 22:00:56 -07:00
|
|
|
import { ANTD_GRAY } from '../entity/shared/constants';
|
|
|
|
import NoMarkdownViewer from '../entity/shared/components/styled/StripMarkdownText';
|
2021-02-03 11:49:51 -08:00
|
|
|
|
2021-02-23 12:45:42 -08:00
|
|
|
interface Props {
|
|
|
|
name: string;
|
|
|
|
logoUrl?: string;
|
2021-05-13 09:18:49 +05:30
|
|
|
logoComponent?: JSX.Element;
|
2021-02-03 11:49:51 -08:00
|
|
|
url: string;
|
2021-02-23 12:45:42 -08:00
|
|
|
description: string;
|
2021-03-07 11:26:47 -08:00
|
|
|
type?: string;
|
|
|
|
platform?: string;
|
2021-02-23 12:45:42 -08:00
|
|
|
qualifier?: string | null;
|
2021-03-07 11:26:47 -08:00
|
|
|
tags?: GlobalTags;
|
2021-05-11 17:55:45 -07:00
|
|
|
owners?: Array<Owner> | null;
|
2021-03-23 15:18:32 -07:00
|
|
|
snippet?: React.ReactNode;
|
2021-10-14 10:11:56 -07:00
|
|
|
insights?: Array<SearchInsight> | null;
|
2021-05-25 10:42:35 +05:30
|
|
|
glossaryTerms?: GlossaryTerms;
|
2021-05-26 09:58:43 +08:00
|
|
|
dataTestID?: string;
|
2021-02-03 11:49:51 -08:00
|
|
|
}
|
|
|
|
|
2021-08-31 22:00:56 -07:00
|
|
|
const PreviewContainer = styled.div`
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
justify-content: space-between;
|
2021-10-12 23:21:43 -07:00
|
|
|
align-items: center;
|
2021-03-23 15:18:32 -07:00
|
|
|
`;
|
|
|
|
|
2021-08-31 22:00:56 -07:00
|
|
|
const PlatformInfo = styled.div`
|
|
|
|
margin-bottom: 8px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
height: 24px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const TitleContainer = styled.div`
|
|
|
|
margin-bottom: 8px;
|
2021-07-23 04:20:40 +08:00
|
|
|
`;
|
|
|
|
|
2021-05-10 19:23:34 -07:00
|
|
|
const PreviewImage = styled(Image)`
|
2021-08-31 22:00:56 -07:00
|
|
|
max-height: 18px;
|
2021-05-10 19:23:34 -07:00
|
|
|
width: auto;
|
|
|
|
object-fit: contain;
|
2021-08-31 22:00:56 -07:00
|
|
|
margin-right: 10px;
|
|
|
|
background-color: transparent;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const EntityTitle = styled(Typography.Text)`
|
|
|
|
&&& {
|
|
|
|
margin-bottom: 0;
|
2021-10-12 23:21:43 -07:00
|
|
|
font-size: 18px;
|
2021-08-31 22:00:56 -07:00
|
|
|
font-weight: 600;
|
|
|
|
vertical-align: middle;
|
|
|
|
}
|
2021-05-10 19:23:34 -07:00
|
|
|
`;
|
|
|
|
|
2021-08-31 22:00:56 -07:00
|
|
|
const PlatformText = styled(Typography.Text)`
|
|
|
|
font-size: 12px;
|
|
|
|
line-height: 20px;
|
|
|
|
font-weight: 700;
|
|
|
|
color: ${ANTD_GRAY[7]};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const PlatformDivider = styled.div`
|
|
|
|
display: inline-block;
|
|
|
|
padding-left: 10px;
|
|
|
|
margin-right: 10px;
|
|
|
|
border-right: 1px solid ${ANTD_GRAY[4]};
|
|
|
|
height: 21px;
|
|
|
|
vertical-align: text-top;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const DescriptionContainer = styled.div`
|
|
|
|
margin-top: 5px;
|
2021-10-14 10:11:56 -07:00
|
|
|
color: ${ANTD_GRAY[7]};
|
2021-08-31 22:00:56 -07:00
|
|
|
`;
|
|
|
|
|
|
|
|
const AvatarContainer = styled.div`
|
|
|
|
margin-top: 12px;
|
2021-10-12 23:21:43 -07:00
|
|
|
margin-right: 32px;
|
2021-08-31 22:00:56 -07:00
|
|
|
`;
|
|
|
|
|
|
|
|
const TagContainer = styled.div`
|
|
|
|
display: inline-block;
|
|
|
|
margin-left: 8px;
|
|
|
|
margin-top: -2px;
|
|
|
|
`;
|
2021-02-23 12:45:42 -08:00
|
|
|
|
2021-10-14 10:11:56 -07:00
|
|
|
const InsightContainer = styled.div`
|
|
|
|
margin-top: 12px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const InsightsText = styled(Typography.Text)`
|
|
|
|
font-size: 12px;
|
|
|
|
line-height: 20px;
|
|
|
|
font-weight: 600;
|
|
|
|
color: ${ANTD_GRAY[7]};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const InsightIconContainer = styled.span`
|
|
|
|
margin-right: 4px;
|
|
|
|
`;
|
|
|
|
|
2021-02-23 12:45:42 -08:00
|
|
|
export default function DefaultPreviewCard({
|
|
|
|
name,
|
|
|
|
logoUrl,
|
2021-05-13 09:18:49 +05:30
|
|
|
logoComponent,
|
2021-02-23 12:45:42 -08:00
|
|
|
url,
|
|
|
|
description,
|
|
|
|
type,
|
|
|
|
platform,
|
2021-08-31 22:00:56 -07:00
|
|
|
// TODO(Gabe): support qualifier in the new preview card
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2021-02-23 12:45:42 -08:00
|
|
|
qualifier,
|
|
|
|
tags,
|
|
|
|
owners,
|
2021-03-23 15:18:32 -07:00
|
|
|
snippet,
|
2021-10-14 10:11:56 -07:00
|
|
|
insights,
|
2021-05-25 10:42:35 +05:30
|
|
|
glossaryTerms,
|
2021-05-26 09:58:43 +08:00
|
|
|
dataTestID,
|
2021-02-23 12:45:42 -08:00
|
|
|
}: Props) {
|
|
|
|
const entityRegistry = useEntityRegistry();
|
2021-10-14 10:11:56 -07:00
|
|
|
const insightViews: Array<ReactNode> = [
|
|
|
|
...(insights?.map((insight) => (
|
|
|
|
<>
|
|
|
|
<InsightIconContainer>{insight.icon}</InsightIconContainer>
|
|
|
|
<InsightsText>{insight.text}</InsightsText>
|
|
|
|
</>
|
|
|
|
)) || []),
|
|
|
|
];
|
|
|
|
if (snippet) {
|
|
|
|
insightViews.push(snippet);
|
|
|
|
}
|
2021-02-03 11:49:51 -08:00
|
|
|
return (
|
2021-08-31 22:00:56 -07:00
|
|
|
<PreviewContainer data-testid={dataTestID}>
|
|
|
|
<div>
|
2021-10-26 12:13:53 -07:00
|
|
|
<TitleContainer>
|
|
|
|
<Link to={url}>
|
2021-08-31 22:00:56 -07:00
|
|
|
<PlatformInfo>
|
2021-10-12 23:21:43 -07:00
|
|
|
{logoComponent && logoComponent}
|
2021-09-02 15:39:08 -07:00
|
|
|
{!!logoUrl && <PreviewImage preview={false} src={logoUrl} alt={platform} />}
|
2021-10-12 23:21:43 -07:00
|
|
|
{platform && <PlatformText>{platform}</PlatformText>}
|
2021-08-31 22:00:56 -07:00
|
|
|
<PlatformDivider />
|
|
|
|
<PlatformText>{type}</PlatformText>
|
|
|
|
</PlatformInfo>
|
2021-10-26 12:13:53 -07:00
|
|
|
<EntityTitle>{name || ' '}</EntityTitle>
|
|
|
|
</Link>
|
|
|
|
<TagContainer>
|
|
|
|
<TagTermGroup uneditableGlossaryTerms={glossaryTerms} uneditableTags={tags} maxShow={3} />
|
|
|
|
</TagContainer>
|
|
|
|
</TitleContainer>
|
2021-08-31 22:00:56 -07:00
|
|
|
{description.length > 0 && (
|
|
|
|
<DescriptionContainer>
|
|
|
|
<NoMarkdownViewer limit={200}>{description}</NoMarkdownViewer>
|
|
|
|
</DescriptionContainer>
|
|
|
|
)}
|
2021-10-12 23:21:43 -07:00
|
|
|
{owners && owners.length > 0 && (
|
|
|
|
<AvatarContainer>
|
|
|
|
<AvatarsGroup size={28} owners={owners} entityRegistry={entityRegistry} maxCount={4} />
|
|
|
|
</AvatarContainer>
|
|
|
|
)}
|
2021-10-14 10:11:56 -07:00
|
|
|
{insightViews.length > 0 && (
|
|
|
|
<InsightContainer>
|
|
|
|
{insightViews.map((insightView, index) => (
|
|
|
|
<span>
|
|
|
|
{insightView}
|
|
|
|
{index < insightViews.length - 1 && <PlatformDivider />}
|
|
|
|
</span>
|
|
|
|
))}
|
|
|
|
</InsightContainer>
|
|
|
|
)}
|
2021-08-31 22:00:56 -07:00
|
|
|
</div>
|
|
|
|
</PreviewContainer>
|
2021-02-03 11:49:51 -08:00
|
|
|
);
|
|
|
|
}
|