2021-05-11 15:41:42 -07:00
|
|
|
import React, { useEffect } from 'react';
|
2021-02-03 11:49:51 -08:00
|
|
|
import { useParams } from 'react-router-dom';
|
|
|
|
import { EntityType } from '../../types.generated';
|
|
|
|
import { BrowsableEntityPage } from '../browse/BrowsableEntityPage';
|
2021-04-03 11:13:25 -07:00
|
|
|
import LineageExplorer from '../lineage/LineageExplorer';
|
|
|
|
import useIsLineageMode from '../lineage/utils/useIsLineageMode';
|
2021-02-03 11:49:51 -08:00
|
|
|
import { useEntityRegistry } from '../useEntityRegistry';
|
2021-05-11 15:41:42 -07:00
|
|
|
import analytics, { EventType } from '../analytics';
|
2022-02-01 10:47:45 -08:00
|
|
|
import { decodeUrn } from './shared/utils';
|
2022-03-29 12:02:22 -07:00
|
|
|
import { useGetGrantedPrivilegesQuery } from '../../graphql/policy.generated';
|
|
|
|
import { Message } from '../shared/Message';
|
|
|
|
import { UnauthorizedPage } from '../authorization/UnauthorizedPage';
|
2022-08-28 20:08:25 -07:00
|
|
|
import { ErrorSection } from '../shared/error/ErrorSection';
|
2023-01-26 12:14:31 -05:00
|
|
|
import { VIEW_ENTITY_PAGE } from './shared/constants';
|
2023-03-21 18:36:21 -07:00
|
|
|
import { useUserContext } from '../context/useUserContext';
|
2021-02-03 11:49:51 -08:00
|
|
|
|
|
|
|
interface RouteParams {
|
|
|
|
urn: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
entityType: EntityType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Responsible for rendering an Entity Profile
|
|
|
|
*/
|
|
|
|
export const EntityPage = ({ entityType }: Props) => {
|
2021-06-03 11:08:43 -07:00
|
|
|
const { urn: encodedUrn } = useParams<RouteParams>();
|
2022-02-01 10:47:45 -08:00
|
|
|
const urn = decodeUrn(encodedUrn);
|
2021-02-03 11:49:51 -08:00
|
|
|
const entityRegistry = useEntityRegistry();
|
2022-03-29 12:02:22 -07:00
|
|
|
const entity = entityRegistry.getEntity(entityType);
|
|
|
|
const isBrowsable = entity.isBrowseEnabled();
|
|
|
|
const isLineageSupported = entity.isLineageEnabled();
|
2021-04-03 11:13:25 -07:00
|
|
|
const isLineageMode = useIsLineageMode();
|
2023-03-21 18:36:21 -07:00
|
|
|
const authenticatedUserUrn = useUserContext()?.user?.urn;
|
2022-03-29 12:02:22 -07:00
|
|
|
const { loading, error, data } = useGetGrantedPrivilegesQuery({
|
|
|
|
variables: {
|
|
|
|
input: {
|
2023-03-21 18:36:21 -07:00
|
|
|
actorUrn: authenticatedUserUrn as string,
|
2022-03-29 12:02:22 -07:00
|
|
|
resourceSpec: { resourceType: entityType, resourceUrn: urn },
|
|
|
|
},
|
|
|
|
},
|
2023-03-21 18:36:21 -07:00
|
|
|
skip: !authenticatedUserUrn,
|
2022-12-19 09:55:56 -08:00
|
|
|
fetchPolicy: 'cache-first',
|
2022-03-29 12:02:22 -07:00
|
|
|
});
|
|
|
|
const privileges = data?.getGrantedPrivileges?.privileges || [];
|
|
|
|
|
2021-05-11 15:41:42 -07:00
|
|
|
useEffect(() => {
|
|
|
|
analytics.event({
|
|
|
|
type: EventType.EntityViewEvent,
|
|
|
|
entityType,
|
|
|
|
entityUrn: urn,
|
|
|
|
});
|
|
|
|
}, [entityType, urn]);
|
2021-04-03 11:13:25 -07:00
|
|
|
|
2023-01-26 12:14:31 -05:00
|
|
|
const canViewEntityPage = privileges.find((privilege) => privilege === VIEW_ENTITY_PAGE);
|
2022-03-29 12:02:22 -07:00
|
|
|
const showNewPage =
|
2021-09-28 10:30:37 -07:00
|
|
|
entityType === EntityType.Dataset ||
|
|
|
|
entityType === EntityType.Dashboard ||
|
|
|
|
entityType === EntityType.Chart ||
|
|
|
|
entityType === EntityType.DataFlow ||
|
2022-02-01 00:51:06 +05:30
|
|
|
entityType === EntityType.DataJob ||
|
2022-04-12 22:42:12 -07:00
|
|
|
entityType === EntityType.Mlmodel ||
|
|
|
|
entityType === EntityType.Mlfeature ||
|
|
|
|
entityType === EntityType.MlprimaryKey ||
|
|
|
|
entityType === EntityType.MlfeatureTable ||
|
|
|
|
entityType === EntityType.MlmodelGroup ||
|
2022-05-30 00:26:07 -04:00
|
|
|
entityType === EntityType.GlossaryTerm ||
|
|
|
|
entityType === EntityType.GlossaryNode;
|
2021-08-31 22:00:56 -07:00
|
|
|
|
2021-02-03 11:49:51 -08:00
|
|
|
return (
|
2022-03-29 12:02:22 -07:00
|
|
|
<>
|
|
|
|
{loading && <Message type="loading" content="Loading..." style={{ marginTop: '10%' }} />}
|
2022-08-28 20:08:25 -07:00
|
|
|
{error && <ErrorSection />}
|
2022-03-29 12:02:22 -07:00
|
|
|
{data && !canViewEntityPage && <UnauthorizedPage />}
|
|
|
|
{canViewEntityPage &&
|
2022-07-01 18:08:08 -04:00
|
|
|
((showNewPage && <>{entityRegistry.renderProfile(entityType, urn)}</>) || (
|
|
|
|
<BrowsableEntityPage
|
2022-03-29 12:02:22 -07:00
|
|
|
isBrowsable={isBrowsable}
|
|
|
|
urn={urn}
|
|
|
|
type={entityType}
|
|
|
|
lineageSupported={isLineageSupported}
|
|
|
|
>
|
|
|
|
{isLineageMode && isLineageSupported ? (
|
|
|
|
<LineageExplorer type={entityType} urn={urn} />
|
|
|
|
) : (
|
|
|
|
entityRegistry.renderProfile(entityType, urn)
|
|
|
|
)}
|
2022-07-01 18:08:08 -04:00
|
|
|
</BrowsableEntityPage>
|
2022-03-29 12:02:22 -07:00
|
|
|
))}
|
|
|
|
</>
|
2021-02-03 11:49:51 -08:00
|
|
|
);
|
|
|
|
};
|