2021-08-31 22:00:56 -07:00
|
|
|
import { Typography, Image, Button } from 'antd';
|
|
|
|
import React from 'react';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
|
|
|
import { capitalizeFirstLetter } from '../../../../../shared/capitalizeFirstLetter';
|
2021-09-28 10:30:37 -07:00
|
|
|
import { useEntityRegistry } from '../../../../../useEntityRegistry';
|
2021-08-31 22:00:56 -07:00
|
|
|
import { ANTD_GRAY } from '../../../constants';
|
|
|
|
import { useEntityData } from '../../../EntityContext';
|
|
|
|
import { useEntityPath } from '../utils';
|
|
|
|
|
|
|
|
const PreviewImage = styled(Image)`
|
|
|
|
max-height: 17px;
|
|
|
|
width: auto;
|
|
|
|
object-fit: contain;
|
|
|
|
margin-right: 10px;
|
|
|
|
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]};
|
|
|
|
`;
|
|
|
|
|
|
|
|
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;
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const EntityHeader = () => {
|
|
|
|
const { urn, entityType, entityData } = useEntityData();
|
2021-09-28 10:30:37 -07:00
|
|
|
const entityRegistry = useEntityRegistry();
|
2021-08-31 22:00:56 -07:00
|
|
|
|
|
|
|
const platformName = capitalizeFirstLetter(entityData?.platform?.name);
|
|
|
|
const platformLogoUrl = entityData?.platform?.info?.logoUrl;
|
2021-09-28 10:30:37 -07:00
|
|
|
const entityTypeCased = entityRegistry.getEntityName(entityType);
|
2021-08-31 22:00:56 -07:00
|
|
|
const entityPath = useEntityPath(entityType, urn);
|
|
|
|
const externalUrl = entityData?.externalUrl || undefined;
|
|
|
|
const hasExternalUrl = !!externalUrl;
|
|
|
|
return (
|
|
|
|
<HeaderContainer>
|
|
|
|
<MainHeaderContent>
|
|
|
|
<PlatformContent>
|
|
|
|
<span>
|
2021-09-02 15:39:08 -07:00
|
|
|
{!!platformLogoUrl && <PreviewImage preview={false} src={platformLogoUrl} alt={platformName} />}
|
2021-08-31 22:00:56 -07:00
|
|
|
</span>
|
|
|
|
<PlatformText>{platformName}</PlatformText>
|
|
|
|
<PlatformDivider />
|
|
|
|
<PlatformText>{entityData?.entityTypeOverride || entityTypeCased}</PlatformText>
|
|
|
|
</PlatformContent>
|
|
|
|
<Link to={entityPath}>
|
|
|
|
<EntityTitle level={3}>{entityData?.name || ' '}</EntityTitle>
|
|
|
|
</Link>
|
|
|
|
</MainHeaderContent>
|
|
|
|
{hasExternalUrl && <Button href={externalUrl}>View in {platformName}</Button>}
|
|
|
|
</HeaderContainer>
|
|
|
|
);
|
|
|
|
};
|