import React, { useState } from 'react'; import { ArrowRightOutlined } from '@ant-design/icons'; import { Button } from 'antd'; import styled from 'styled-components/macro'; import { capitalizeFirstLetterOnly } from '../../../../../shared/textUtil'; import { useEntityData, useRefetch } from '../../../EntityContext'; import analytics, { EventType, EntityActionType } from '../../../../../analytics'; import { EntityHealthStatus } from './EntityHealthStatus'; import EntityDropdown, { EntityMenuItems } from '../../../EntityDropdown/EntityDropdown'; import PlatformContent from './PlatformContent'; import { getPlatformName } from '../../../utils'; import { useGetAuthenticatedUser } from '../../../../../useGetAuthenticatedUser'; import { EntityType, PlatformPrivileges } from '../../../../../../types.generated'; import EntityCount from './EntityCount'; import EntityName from './EntityName'; import CopyUrn from '../../../../../shared/CopyUrn'; import { DeprecationPill } from '../../../components/styled/DeprecationPill'; import CompactContext from '../../../../../shared/CompactContext'; const TitleWrapper = styled.div` display: flex; justify-content: left; align-items: center; .ant-typography-edit-content { padding-top: 7px; margin-left: 15px; } `; const HeaderContainer = styled.div` display: flex; flex-direction: row; align-items: space-between; margin-bottom: 4px; `; const MainHeaderContent = styled.div` flex: 1; width: 85%; .entityCount { margin: 5px 0 -4px 0; } `; const SideHeaderContent = styled.div` display: flex; flex-direction: column; `; const TopButtonsWrapper = styled.div` display: flex; justify-content: flex-end; margin-bottom: 8px; `; const ExternalUrlContainer = styled.span` font-size: 14px; `; const ExternalUrlButton = styled(Button)` > :hover { text-decoration: underline; } padding-left: 12px; padding-right: 12px; `; export function getCanEditName(entityType: EntityType, privileges?: PlatformPrivileges) { switch (entityType) { case EntityType.GlossaryTerm: case EntityType.GlossaryNode: return privileges?.manageGlossaries; case EntityType.Domain: return privileges?.manageDomains; default: return false; } } type Props = { refreshBrowser?: () => void; headerDropdownItems?: Set; isNameEditable?: boolean; }; export const EntityHeader = ({ refreshBrowser, headerDropdownItems, isNameEditable }: Props) => { const { urn, entityType, entityData } = useEntityData(); const refetch = useRefetch(); const me = useGetAuthenticatedUser(); const [copiedUrn, setCopiedUrn] = useState(false); const basePlatformName = getPlatformName(entityData); const platformName = capitalizeFirstLetterOnly(basePlatformName); const externalUrl = entityData?.externalUrl || undefined; const entityCount = entityData?.entityCount; const isCompact = React.useContext(CompactContext); const sendAnalytics = () => { analytics.event({ type: EventType.EntityActionEvent, actionType: EntityActionType.ClickExternalUrl, entityType, entityUrn: urn, }); }; const canEditName = isNameEditable && getCanEditName(entityType, me?.platformPrivileges as PlatformPrivileges); return ( {entityData?.deprecation?.deprecated && ( )} {entityData?.health?.map((health) => ( ))} {externalUrl && ( View in {platformName} )} setCopiedUrn(true)} /> {headerDropdownItems && ( )} ); };