2022-01-19 17:02:17 -08:00
|
|
|
import React, { useState } from 'react';
|
2022-06-03 07:47:39 -07:00
|
|
|
import { InfoCircleOutlined, RightOutlined } from '@ant-design/icons';
|
2022-05-30 00:26:07 -04:00
|
|
|
import { Typography, Button, Tooltip, Popover } from 'antd';
|
|
|
|
import styled from 'styled-components/macro';
|
2022-04-16 03:40:44 +05:30
|
|
|
import moment from 'moment';
|
2022-02-02 13:51:39 -08:00
|
|
|
import { capitalizeFirstLetterOnly } from '../../../../../shared/textUtil';
|
2021-08-31 22:00:56 -07:00
|
|
|
import { ANTD_GRAY } from '../../../constants';
|
2022-05-30 00:26:07 -04:00
|
|
|
import { useEntityData } from '../../../EntityContext';
|
2022-02-07 22:52:59 +05:30
|
|
|
import analytics, { EventType, EntityActionType } from '../../../../../analytics';
|
2022-03-04 11:51:31 -08:00
|
|
|
import { EntityHealthStatus } from './EntityHealthStatus';
|
2022-04-16 03:40:44 +05:30
|
|
|
import { getLocaleTimezone } from '../../../../../shared/time/timeUtils';
|
2022-05-30 00:26:07 -04:00
|
|
|
import EntityDropdown, { EntityMenuItems } from '../../../EntityDropdown/EntityDropdown';
|
2022-05-13 00:17:19 -04:00
|
|
|
import PlatformContent from './PlatformContent';
|
|
|
|
import { getPlatformName } from '../../../utils';
|
2022-05-30 00:26:07 -04:00
|
|
|
import { useGetAuthenticatedUser } from '../../../../../useGetAuthenticatedUser';
|
|
|
|
import { EntityType, PlatformPrivileges } from '../../../../../../types.generated';
|
2022-05-13 00:17:19 -04:00
|
|
|
import EntityCount from './EntityCount';
|
2022-05-30 00:26:07 -04:00
|
|
|
import EntityName from './EntityName';
|
2022-06-03 07:47:39 -07:00
|
|
|
import CopyUrn from '../../../../../shared/CopyUrn';
|
2021-08-31 22:00:56 -07:00
|
|
|
|
2022-05-30 00:26:07 -04:00
|
|
|
const TitleWrapper = styled.div`
|
|
|
|
display: flex;
|
|
|
|
justify-content: left;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
.ant-typography-edit-content {
|
|
|
|
padding-top: 7px;
|
|
|
|
margin-left: 15px;
|
2021-08-31 22:00:56 -07:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const HeaderContainer = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: space-between;
|
|
|
|
margin-bottom: 4px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const MainHeaderContent = styled.div`
|
|
|
|
flex: 1;
|
2022-05-13 00:17:19 -04:00
|
|
|
width: 85%;
|
2022-02-02 13:51:39 -08:00
|
|
|
|
2022-05-13 00:17:19 -04:00
|
|
|
.entityCount {
|
|
|
|
margin: 5px 0 -4px 0;
|
2022-02-02 13:51:39 -08:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2022-04-16 03:40:44 +05:30
|
|
|
const DeprecatedContainer = styled.div`
|
|
|
|
width: 110px;
|
|
|
|
height: 18px;
|
|
|
|
border: 1px solid #ef5b5b;
|
|
|
|
border-radius: 15px;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
color: #ef5b5b;
|
|
|
|
margin-left: 15px;
|
|
|
|
padding-top: 12px;
|
|
|
|
padding-bottom: 12px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const DeprecatedText = styled.div`
|
|
|
|
color: #ef5b5b;
|
|
|
|
margin-left: 5px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const LastEvaluatedAtLabel = styled.div`
|
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
color: ${ANTD_GRAY[7]};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Divider = styled.div`
|
|
|
|
border-top: 1px solid #f0f0f0;
|
|
|
|
padding-top: 5px;
|
|
|
|
`;
|
|
|
|
|
2022-04-22 16:46:09 -04:00
|
|
|
const SideHeaderContent = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const TopButtonsWrapper = styled.div`
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
margin-bottom: 8px;
|
|
|
|
`;
|
|
|
|
|
2022-05-30 00:26:07 -04:00
|
|
|
function getCanEditName(entityType: EntityType, privileges?: PlatformPrivileges) {
|
|
|
|
switch (entityType) {
|
|
|
|
case EntityType.GlossaryTerm:
|
|
|
|
case EntityType.GlossaryNode:
|
|
|
|
return privileges?.manageGlossaries;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 09:51:47 -07:00
|
|
|
type Props = {
|
2022-05-30 00:26:07 -04:00
|
|
|
refreshBrowser?: () => void;
|
|
|
|
headerDropdownItems?: Set<EntityMenuItems>;
|
|
|
|
isNameEditable?: boolean;
|
2022-04-21 09:51:47 -07:00
|
|
|
};
|
|
|
|
|
2022-05-30 00:26:07 -04:00
|
|
|
export const EntityHeader = ({ refreshBrowser, headerDropdownItems, isNameEditable }: Props) => {
|
2021-08-31 22:00:56 -07:00
|
|
|
const { urn, entityType, entityData } = useEntityData();
|
2022-05-30 00:26:07 -04:00
|
|
|
const me = useGetAuthenticatedUser();
|
2022-01-19 17:02:17 -08:00
|
|
|
const [copiedUrn, setCopiedUrn] = useState(false);
|
2022-05-13 00:17:19 -04:00
|
|
|
const basePlatformName = getPlatformName(entityData);
|
2022-02-02 13:51:39 -08:00
|
|
|
const platformName = capitalizeFirstLetterOnly(basePlatformName);
|
2021-08-31 22:00:56 -07:00
|
|
|
const externalUrl = entityData?.externalUrl || undefined;
|
2022-05-13 00:17:19 -04:00
|
|
|
const entityCount = entityData?.entityCount;
|
2021-08-31 22:00:56 -07:00
|
|
|
const hasExternalUrl = !!externalUrl;
|
2022-02-07 22:52:59 +05:30
|
|
|
|
|
|
|
const sendAnalytics = () => {
|
|
|
|
analytics.event({
|
|
|
|
type: EventType.EntityActionEvent,
|
|
|
|
actionType: EntityActionType.ClickExternalUrl,
|
|
|
|
entityType,
|
|
|
|
entityUrn: urn,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-04-16 03:40:44 +05:30
|
|
|
/**
|
|
|
|
* Deprecation Decommission Timestamp
|
|
|
|
*/
|
|
|
|
const localeTimezone = getLocaleTimezone();
|
|
|
|
const decommissionTimeLocal =
|
|
|
|
(entityData?.deprecation?.decommissionTime &&
|
|
|
|
`Scheduled to be decommissioned on ${moment
|
|
|
|
.unix(entityData?.deprecation?.decommissionTime)
|
|
|
|
.format('DD/MMM/YYYY')} at ${moment
|
|
|
|
.unix(entityData?.deprecation?.decommissionTime)
|
|
|
|
.format('HH:mm:ss')} (${localeTimezone})`) ||
|
|
|
|
undefined;
|
|
|
|
const decommissionTimeGMT =
|
|
|
|
entityData?.deprecation?.decommissionTime &&
|
|
|
|
moment.unix(entityData?.deprecation?.decommissionTime).utc().format('dddd, DD/MMM/YYYY HH:mm:ss z');
|
|
|
|
|
|
|
|
const hasDetails = entityData?.deprecation?.note !== '' || entityData?.deprecation?.decommissionTime !== null;
|
|
|
|
const isDividerNeeded = entityData?.deprecation?.note !== '' && entityData?.deprecation?.decommissionTime !== null;
|
2022-05-30 00:26:07 -04:00
|
|
|
const canEditName = isNameEditable && getCanEditName(entityType, me?.platformPrivileges as PlatformPrivileges);
|
2022-04-16 03:40:44 +05:30
|
|
|
|
2021-08-31 22:00:56 -07:00
|
|
|
return (
|
2022-05-30 00:26:07 -04:00
|
|
|
<HeaderContainer>
|
|
|
|
<MainHeaderContent>
|
|
|
|
<PlatformContent />
|
|
|
|
<TitleWrapper>
|
|
|
|
<EntityName isNameEditable={canEditName} />
|
|
|
|
{entityData?.deprecation?.deprecated && (
|
|
|
|
<Popover
|
|
|
|
overlayStyle={{ maxWidth: 240 }}
|
|
|
|
placement="right"
|
|
|
|
content={
|
|
|
|
hasDetails ? (
|
|
|
|
<>
|
|
|
|
{entityData?.deprecation?.note !== '' && (
|
|
|
|
<Typography.Text>{entityData?.deprecation?.note}</Typography.Text>
|
|
|
|
)}
|
|
|
|
{isDividerNeeded && <Divider />}
|
|
|
|
{entityData?.deprecation?.decommissionTime !== null && (
|
|
|
|
<Typography.Text type="secondary">
|
|
|
|
<Tooltip placement="right" title={decommissionTimeGMT}>
|
|
|
|
<LastEvaluatedAtLabel>{decommissionTimeLocal}</LastEvaluatedAtLabel>
|
|
|
|
</Tooltip>
|
|
|
|
</Typography.Text>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
'No additional details'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<DeprecatedContainer>
|
|
|
|
<InfoCircleOutlined />
|
|
|
|
<DeprecatedText>Deprecated</DeprecatedText>
|
|
|
|
</DeprecatedContainer>
|
|
|
|
</Popover>
|
|
|
|
)}
|
|
|
|
{entityData?.health && (
|
|
|
|
<EntityHealthStatus
|
|
|
|
status={entityData?.health.status}
|
|
|
|
message={entityData?.health?.message || undefined}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</TitleWrapper>
|
|
|
|
<EntityCount entityCount={entityCount} />
|
|
|
|
</MainHeaderContent>
|
|
|
|
<SideHeaderContent>
|
|
|
|
<TopButtonsWrapper>
|
2022-06-03 07:47:39 -07:00
|
|
|
<CopyUrn urn={urn} isActive={copiedUrn} onClick={() => setCopiedUrn(true)} />
|
2022-05-30 00:26:07 -04:00
|
|
|
{headerDropdownItems && (
|
|
|
|
<EntityDropdown
|
|
|
|
menuItems={headerDropdownItems}
|
|
|
|
refreshBrowser={refreshBrowser}
|
|
|
|
platformPrivileges={me?.platformPrivileges as PlatformPrivileges}
|
|
|
|
/>
|
2022-04-22 16:46:09 -04:00
|
|
|
)}
|
2022-05-30 00:26:07 -04:00
|
|
|
</TopButtonsWrapper>
|
|
|
|
{hasExternalUrl && (
|
|
|
|
<Button href={externalUrl} onClick={sendAnalytics}>
|
|
|
|
View in {platformName}
|
|
|
|
<RightOutlined style={{ fontSize: 12 }} />
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</SideHeaderContent>
|
|
|
|
</HeaderContainer>
|
2021-08-31 22:00:56 -07:00
|
|
|
);
|
|
|
|
};
|