2022-11-22 08:48:03 -08:00
|
|
|
import React from 'react';
|
2022-05-30 00:26:07 -04:00
|
|
|
import styled from 'styled-components/macro';
|
2022-06-29 22:41:41 -04:00
|
|
|
import { useEntityData, useRefetch } from '../../../EntityContext';
|
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-07-17 22:02:09 -07:00
|
|
|
import { DeprecationPill } from '../../../components/styled/DeprecationPill';
|
|
|
|
import CompactContext from '../../../../../shared/CompactContext';
|
2022-11-03 16:06:40 -04:00
|
|
|
import { EntitySubHeaderSection, GenericEntityProperties } from '../../../types';
|
2022-08-02 15:20:24 -07:00
|
|
|
import EntityActions, { EntityActionItem } from '../../../entity/EntityActions';
|
2022-10-24 00:29:35 -04:00
|
|
|
import ExternalUrlButton from '../../../ExternalUrlButton';
|
2022-11-22 08:48:03 -08:00
|
|
|
import ShareButton from '../../../../../shared/share/ShareButton';
|
2023-01-25 18:32:15 +01:00
|
|
|
import { capitalizeFirstLetterOnly } from '../../../../../shared/textUtil';
|
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-11-03 16:06:40 -04:00
|
|
|
export function getCanEditName(
|
|
|
|
entityType: EntityType,
|
|
|
|
entityData: GenericEntityProperties | null,
|
|
|
|
privileges?: PlatformPrivileges,
|
|
|
|
) {
|
2022-05-30 00:26:07 -04:00
|
|
|
switch (entityType) {
|
|
|
|
case EntityType.GlossaryTerm:
|
|
|
|
case EntityType.GlossaryNode:
|
2022-11-03 16:06:40 -04:00
|
|
|
return privileges?.manageGlossaries || !!entityData?.privileges?.canManageEntity;
|
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>;
|
2022-07-28 17:40:03 -07:00
|
|
|
headerActionItems?: Set<EntityActionItem>;
|
2022-05-30 00:26:07 -04:00
|
|
|
isNameEditable?: boolean;
|
2022-07-19 15:46:43 -07:00
|
|
|
subHeader?: EntitySubHeaderSection;
|
2022-04-21 09:51:47 -07:00
|
|
|
};
|
|
|
|
|
2022-07-28 17:40:03 -07:00
|
|
|
export const EntityHeader = ({
|
|
|
|
refreshBrowser,
|
|
|
|
headerDropdownItems,
|
|
|
|
headerActionItems,
|
|
|
|
isNameEditable,
|
|
|
|
subHeader,
|
|
|
|
}: 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();
|
2023-01-25 18:32:15 +01:00
|
|
|
const platformName = getPlatformName(entityData);
|
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
|
|
|
|
2022-11-22 08:48:03 -08:00
|
|
|
const entityName = entityData?.name;
|
2023-01-25 18:32:15 +01:00
|
|
|
const subType = capitalizeFirstLetterOnly(entityData?.subTypes?.typeNames?.[0]) || undefined;
|
2022-11-22 08:48:03 -08:00
|
|
|
|
2022-11-03 16:06:40 -04:00
|
|
|
const canEditName =
|
|
|
|
isNameEditable && getCanEditName(entityType, entityData, me?.platformPrivileges as PlatformPrivileges);
|
2022-04-16 03:40:44 +05:30
|
|
|
|
2021-08-31 22:00:56 -07:00
|
|
|
return (
|
2022-07-19 15:46:43 -07:00
|
|
|
<>
|
|
|
|
<HeaderContainer data-testid="entity-header-test-id">
|
|
|
|
<MainHeaderContent>
|
|
|
|
<PlatformContent />
|
|
|
|
<TitleWrapper>
|
|
|
|
<EntityName isNameEditable={canEditName} />
|
|
|
|
{entityData?.deprecation?.deprecated && (
|
2022-10-07 01:06:39 +05:30
|
|
|
<DeprecationPill
|
|
|
|
urn={urn}
|
|
|
|
deprecation={entityData?.deprecation}
|
|
|
|
showUndeprecate
|
|
|
|
preview={isCompact}
|
|
|
|
refetch={refetch}
|
|
|
|
/>
|
2022-07-19 15:46:43 -07:00
|
|
|
)}
|
|
|
|
{entityData?.health?.map((health) => (
|
|
|
|
<EntityHealthStatus
|
|
|
|
type={health.type}
|
|
|
|
status={health.status}
|
|
|
|
message={health.message || undefined}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</TitleWrapper>
|
|
|
|
<EntityCount entityCount={entityCount} />
|
|
|
|
</MainHeaderContent>
|
|
|
|
<SideHeaderContent>
|
|
|
|
<TopButtonsWrapper>
|
|
|
|
{externalUrl && (
|
2022-10-24 00:29:35 -04:00
|
|
|
<ExternalUrlButton
|
|
|
|
externalUrl={externalUrl}
|
|
|
|
entityUrn={urn}
|
|
|
|
platformName={platformName}
|
|
|
|
entityType={entityType}
|
|
|
|
/>
|
2022-07-19 15:46:43 -07:00
|
|
|
)}
|
2022-08-02 15:20:24 -07:00
|
|
|
{headerActionItems && (
|
|
|
|
<EntityActions urn={urn} actionItems={headerActionItems} refetchForEntity={refetch} />
|
|
|
|
)}
|
2022-11-22 08:48:03 -08:00
|
|
|
<ShareButton entityType={entityType} subType={subType} urn={urn} name={entityName} />
|
2022-07-19 15:46:43 -07:00
|
|
|
{headerDropdownItems && (
|
|
|
|
<EntityDropdown
|
|
|
|
urn={urn}
|
|
|
|
entityType={entityType}
|
|
|
|
entityData={entityData}
|
|
|
|
menuItems={headerDropdownItems}
|
|
|
|
refetchForEntity={refetch}
|
|
|
|
refreshBrowser={refreshBrowser}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</TopButtonsWrapper>
|
|
|
|
</SideHeaderContent>
|
|
|
|
</HeaderContainer>
|
|
|
|
{subHeader && <subHeader.component />}
|
|
|
|
</>
|
2021-08-31 22:00:56 -07:00
|
|
|
);
|
|
|
|
};
|