2022-02-02 13:51:39 -08:00
|
|
|
import { CheckOutlined, CopyOutlined, FolderOpenOutlined } from '@ant-design/icons';
|
2022-01-19 17:02:17 -08:00
|
|
|
import { Typography, Image, Button, Tooltip } from 'antd';
|
|
|
|
import React, { useState } from 'react';
|
2021-08-31 22:00:56 -07:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import styled from 'styled-components';
|
2022-02-02 13:51:39 -08:00
|
|
|
import { EntityType } from '../../../../../../types.generated';
|
|
|
|
import { capitalizeFirstLetterOnly } from '../../../../../shared/textUtil';
|
2021-09-28 10:30:37 -07:00
|
|
|
import { useEntityRegistry } from '../../../../../useEntityRegistry';
|
2022-01-19 17:02:17 -08:00
|
|
|
import { IconStyleType } from '../../../../Entity';
|
2021-08-31 22:00:56 -07:00
|
|
|
import { ANTD_GRAY } from '../../../constants';
|
|
|
|
import { useEntityData } from '../../../EntityContext';
|
|
|
|
import { useEntityPath } from '../utils';
|
|
|
|
|
2022-01-19 17:02:17 -08:00
|
|
|
const LogoContainer = styled.span`
|
|
|
|
margin-right: 10px;
|
|
|
|
`;
|
|
|
|
|
2021-08-31 22:00:56 -07:00
|
|
|
const PreviewImage = styled(Image)`
|
|
|
|
max-height: 17px;
|
|
|
|
width: auto;
|
|
|
|
object-fit: contain;
|
|
|
|
background-color: transparent;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const EntityTitle = styled(Typography.Title)`
|
|
|
|
&&& {
|
|
|
|
margin-bottom: 0;
|
2022-01-07 17:29:15 -08:00
|
|
|
word-break: break-all;
|
2021-08-31 22:00:56 -07:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const PlatformContent = styled.div`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
margin-bottom: 8px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const PlatformText = styled(Typography.Text)`
|
|
|
|
font-size: 12px;
|
|
|
|
line-height: 20px;
|
|
|
|
font-weight: 700;
|
|
|
|
color: ${ANTD_GRAY[7]};
|
|
|
|
`;
|
|
|
|
|
2022-02-02 13:51:39 -08:00
|
|
|
const EntityCountText = styled(Typography.Text)`
|
|
|
|
font-size: 12px;
|
|
|
|
line-height: 20px;
|
|
|
|
font-weight: 400;
|
|
|
|
color: ${ANTD_GRAY[7]};
|
|
|
|
`;
|
|
|
|
|
2021-08-31 22:00:56 -07:00
|
|
|
const PlatformDivider = styled.div`
|
|
|
|
display: inline-block;
|
|
|
|
padding-left: 10px;
|
|
|
|
margin-right: 10px;
|
|
|
|
border-right: 1px solid ${ANTD_GRAY[4]};
|
|
|
|
height: 18px;
|
|
|
|
vertical-align: text-top;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const HeaderContainer = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: space-between;
|
|
|
|
margin-bottom: 4px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const MainHeaderContent = styled.div`
|
|
|
|
flex: 1;
|
|
|
|
`;
|
|
|
|
|
2022-02-02 13:51:39 -08:00
|
|
|
const ExternalLinkButton = styled(Button)`
|
|
|
|
margin-right: 12px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const TypeIcon = styled.span`
|
|
|
|
margin-right: 8px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ContainerText = styled(Typography.Text)`
|
|
|
|
font-size: 12px;
|
|
|
|
line-height: 20px;
|
|
|
|
font-weight: 400;
|
|
|
|
color: ${ANTD_GRAY[9]};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ContainerIcon = styled(FolderOpenOutlined)`
|
|
|
|
&&& {
|
|
|
|
font-size: 12px;
|
|
|
|
margin-right: 4px;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2021-08-31 22:00:56 -07:00
|
|
|
export const EntityHeader = () => {
|
|
|
|
const { urn, entityType, entityData } = useEntityData();
|
2021-09-28 10:30:37 -07:00
|
|
|
const entityRegistry = useEntityRegistry();
|
2022-01-19 17:02:17 -08:00
|
|
|
const [copiedUrn, setCopiedUrn] = useState(false);
|
2022-02-02 13:51:39 -08:00
|
|
|
const basePlatformName = entityData?.platform?.properties?.displayName || entityData?.platform?.name;
|
|
|
|
const platformName = capitalizeFirstLetterOnly(basePlatformName);
|
2022-01-25 21:03:31 -06:00
|
|
|
const platformLogoUrl = entityData?.platform?.properties?.logoUrl;
|
2022-01-19 17:02:17 -08:00
|
|
|
const entityLogoComponent = entityRegistry.getIcon(entityType, 12, IconStyleType.ACCENT);
|
2022-02-02 13:51:39 -08:00
|
|
|
const entityTypeCased =
|
|
|
|
(entityData?.subTypes?.typeNames?.length && capitalizeFirstLetterOnly(entityData?.subTypes.typeNames[0])) ||
|
|
|
|
entityRegistry.getEntityName(entityType);
|
2021-08-31 22:00:56 -07:00
|
|
|
const entityPath = useEntityPath(entityType, urn);
|
|
|
|
const externalUrl = entityData?.externalUrl || undefined;
|
|
|
|
const hasExternalUrl = !!externalUrl;
|
2022-02-02 13:51:39 -08:00
|
|
|
const entityCount = entityData?.entityCount;
|
|
|
|
const typeIcon = entityRegistry.getIcon(entityType, 12, IconStyleType.ACCENT);
|
|
|
|
const container = entityData?.container;
|
2021-08-31 22:00:56 -07:00
|
|
|
return (
|
|
|
|
<HeaderContainer>
|
|
|
|
<MainHeaderContent>
|
|
|
|
<PlatformContent>
|
2022-01-19 17:02:17 -08:00
|
|
|
<LogoContainer>
|
|
|
|
{(!!platformLogoUrl && (
|
|
|
|
<PreviewImage preview={false} src={platformLogoUrl} alt={platformName} />
|
|
|
|
)) ||
|
|
|
|
entityLogoComponent}
|
|
|
|
</LogoContainer>
|
2021-08-31 22:00:56 -07:00
|
|
|
<PlatformText>{platformName}</PlatformText>
|
2022-01-19 17:02:17 -08:00
|
|
|
{(platformLogoUrl || platformName) && <PlatformDivider />}
|
2022-02-02 13:51:39 -08:00
|
|
|
{typeIcon && <TypeIcon>{typeIcon}</TypeIcon>}
|
2021-08-31 22:00:56 -07:00
|
|
|
<PlatformText>{entityData?.entityTypeOverride || entityTypeCased}</PlatformText>
|
2022-02-02 13:51:39 -08:00
|
|
|
{container && (
|
|
|
|
<Link to={entityRegistry.getEntityUrl(EntityType.Container, container?.urn)}>
|
|
|
|
<PlatformDivider />
|
|
|
|
<ContainerIcon
|
|
|
|
style={{
|
|
|
|
color: ANTD_GRAY[9],
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<ContainerText>
|
|
|
|
{entityRegistry.getDisplayName(EntityType.Container, container)}
|
|
|
|
</ContainerText>
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
{entityCount && entityCount > 0 ? (
|
|
|
|
<>
|
|
|
|
<PlatformDivider />
|
|
|
|
<EntityCountText>{entityCount.toLocaleString()} entities</EntityCountText>
|
|
|
|
</>
|
|
|
|
) : null}
|
2021-08-31 22:00:56 -07:00
|
|
|
</PlatformContent>
|
|
|
|
<Link to={entityPath}>
|
|
|
|
<EntityTitle level={3}>{entityData?.name || ' '}</EntityTitle>
|
|
|
|
</Link>
|
|
|
|
</MainHeaderContent>
|
2022-02-02 13:51:39 -08:00
|
|
|
{hasExternalUrl && <ExternalLinkButton href={externalUrl}>View in {platformName}</ExternalLinkButton>}
|
2022-01-19 17:02:17 -08:00
|
|
|
<Tooltip title="Copy URN. An URN uniquely identifies an entity on DataHub.">
|
|
|
|
<Button
|
|
|
|
icon={copiedUrn ? <CheckOutlined /> : <CopyOutlined />}
|
|
|
|
onClick={() => {
|
|
|
|
navigator.clipboard.writeText(urn);
|
|
|
|
setCopiedUrn(true);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Tooltip>
|
2021-08-31 22:00:56 -07:00
|
|
|
</HeaderContainer>
|
|
|
|
);
|
|
|
|
};
|