2022-01-19 17:02:17 -08:00
|
|
|
import React, { useState } from 'react';
|
2022-07-17 22:02:09 -07:00
|
|
|
import { ArrowRightOutlined } from '@ant-design/icons';
|
|
|
|
import { Button } from 'antd';
|
2022-05-30 00:26:07 -04:00
|
|
|
import styled from 'styled-components/macro';
|
2022-02-02 13:51:39 -08:00
|
|
|
import { capitalizeFirstLetterOnly } from '../../../../../shared/textUtil';
|
2022-06-29 22:41:41 -04:00
|
|
|
import { useEntityData, useRefetch } 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-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';
|
2022-07-17 22:02:09 -07:00
|
|
|
import { DeprecationPill } from '../../../components/styled/DeprecationPill';
|
|
|
|
import CompactContext from '../../../../../shared/CompactContext';
|
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-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-07-17 22:02:09 -07:00
|
|
|
const ExternalUrlContainer = styled.span`
|
|
|
|
font-size: 14px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ExternalUrlButton = styled(Button)`
|
|
|
|
> :hover {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
padding-left: 12px;
|
|
|
|
padding-right: 12px;
|
|
|
|
`;
|
|
|
|
|
2022-06-27 19:09:36 -04:00
|
|
|
export function getCanEditName(entityType: EntityType, privileges?: PlatformPrivileges) {
|
2022-05-30 00:26:07 -04:00
|
|
|
switch (entityType) {
|
|
|
|
case EntityType.GlossaryTerm:
|
|
|
|
case EntityType.GlossaryNode:
|
|
|
|
return privileges?.manageGlossaries;
|
2022-06-27 19:09:36 -04:00
|
|
|
case EntityType.Domain:
|
|
|
|
return privileges?.manageDomains;
|
2022-05-30 00:26:07 -04:00
|
|
|
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-06-29 22:41:41 -04:00
|
|
|
const refetch = useRefetch();
|
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;
|
2022-07-17 22:02:09 -07:00
|
|
|
const isCompact = React.useContext(CompactContext);
|
2022-02-07 22:52:59 +05:30
|
|
|
|
|
|
|
const sendAnalytics = () => {
|
|
|
|
analytics.event({
|
|
|
|
type: EventType.EntityActionEvent,
|
|
|
|
actionType: EntityActionType.ClickExternalUrl,
|
|
|
|
entityType,
|
|
|
|
entityUrn: urn,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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-07-14 14:23:12 -07:00
|
|
|
<HeaderContainer data-testid="entity-header-test-id">
|
2022-05-30 00:26:07 -04:00
|
|
|
<MainHeaderContent>
|
|
|
|
<PlatformContent />
|
|
|
|
<TitleWrapper>
|
|
|
|
<EntityName isNameEditable={canEditName} />
|
2022-07-17 22:02:09 -07:00
|
|
|
{entityData?.deprecation && (
|
|
|
|
<DeprecationPill deprecation={entityData?.deprecation} preview={isCompact} />
|
2022-05-30 00:26:07 -04:00
|
|
|
)}
|
2022-06-22 15:21:34 -04:00
|
|
|
{entityData?.health?.map((health) => (
|
2022-05-30 00:26:07 -04:00
|
|
|
<EntityHealthStatus
|
2022-06-22 15:21:34 -04:00
|
|
|
type={health.type}
|
|
|
|
status={health.status}
|
|
|
|
message={health.message || undefined}
|
2022-05-30 00:26:07 -04:00
|
|
|
/>
|
2022-06-22 15:21:34 -04:00
|
|
|
))}
|
2022-05-30 00:26:07 -04:00
|
|
|
</TitleWrapper>
|
|
|
|
<EntityCount entityCount={entityCount} />
|
|
|
|
</MainHeaderContent>
|
|
|
|
<SideHeaderContent>
|
|
|
|
<TopButtonsWrapper>
|
2022-07-17 22:02:09 -07:00
|
|
|
{externalUrl && (
|
|
|
|
<ExternalUrlContainer>
|
|
|
|
<ExternalUrlButton type="link" href={externalUrl} target="_blank" onClick={sendAnalytics}>
|
|
|
|
View in {platformName} <ArrowRightOutlined style={{ fontSize: 12 }} />
|
|
|
|
</ExternalUrlButton>
|
|
|
|
</ExternalUrlContainer>
|
|
|
|
)}
|
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
|
2022-06-29 22:41:41 -04:00
|
|
|
urn={urn}
|
|
|
|
entityType={entityType}
|
|
|
|
entityData={entityData}
|
2022-05-30 00:26:07 -04:00
|
|
|
menuItems={headerDropdownItems}
|
2022-06-29 22:41:41 -04:00
|
|
|
refetchForEntity={refetch}
|
2022-05-30 00:26:07 -04:00
|
|
|
refreshBrowser={refreshBrowser}
|
|
|
|
platformPrivileges={me?.platformPrivileges as PlatformPrivileges}
|
|
|
|
/>
|
2022-04-22 16:46:09 -04:00
|
|
|
)}
|
2022-05-30 00:26:07 -04:00
|
|
|
</TopButtonsWrapper>
|
|
|
|
</SideHeaderContent>
|
|
|
|
</HeaderContainer>
|
2021-08-31 22:00:56 -07:00
|
|
|
);
|
|
|
|
};
|