Skip to content

Commit

Permalink
feat(ui) Add new embedded profile to be displayed in extension (datah…
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscollins3456 authored and Eric Yomi committed Feb 8, 2023
1 parent bfa8561 commit e1bca87
Show file tree
Hide file tree
Showing 56 changed files with 1,526 additions and 482 deletions.
12 changes: 12 additions & 0 deletions datahub-web-react/src/app/ProtectedRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import AppConfigProvider from '../AppConfigProvider';
import { SearchRoutes } from './SearchRoutes';
import { EducationStepsProvider } from '../providers/EducationStepsProvider';
import UserContextProvider from './context/UserContextProvider';
import { PageRoutes } from '../conf/Global';
import EmbeddedPage from './embed/EmbeddedPage';
import { useEntityRegistry } from './useEntityRegistry';

/**
* Container for all views behind an authentication wall.
*/
export const ProtectedRoutes = (): JSX.Element => {
const entityRegistry = useEntityRegistry();

return (
<AppConfigProvider>
<UserContextProvider>
Expand All @@ -19,6 +24,13 @@ export const ProtectedRoutes = (): JSX.Element => {
<Layout>
<Switch>
<Route exact path="/" render={() => <HomePage />} />
{entityRegistry.getEntities().map((entity) => (
<Route
key={`${entity.getPathName()}/${PageRoutes.EMBED}`}
path={`${PageRoutes.EMBED}/${entity.getPathName()}/:urn`}
render={() => <EmbeddedPage entityType={entity.type} />}
/>
))}
<Route path="/*" render={() => <SearchRoutes />} />
</Switch>
</Layout>
Expand Down
54 changes: 54 additions & 0 deletions datahub-web-react/src/app/embed/EmbeddedPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import { useParams } from 'react-router';
import styled from 'styled-components/macro';
import { useGetGrantedPrivilegesQuery } from '../../graphql/policy.generated';
import { EntityType } from '../../types.generated';
import { UnauthorizedPage } from '../authorization/UnauthorizedPage';
import { VIEW_ENTITY_PAGE } from '../entity/shared/constants';
import { decodeUrn } from '../entity/shared/utils';
import CompactContext from '../shared/CompactContext';
import { useEntityRegistry } from '../useEntityRegistry';
import { useGetAuthenticatedUserUrn } from '../useGetAuthenticatedUser';

const EmbeddedPageWrapper = styled.div`
max-height: 100%;
overflow: auto;
padding: 16px;
`;

interface RouteParams {
urn: string;
}

interface Props {
entityType: EntityType;
}

export default function EmbeddedPage({ entityType }: Props) {
const entityRegistry = useEntityRegistry();
const { urn: encodedUrn } = useParams<RouteParams>();
const urn = decodeUrn(encodedUrn);

const authenticatedUserUrn = useGetAuthenticatedUserUrn();
const { data } = useGetGrantedPrivilegesQuery({
variables: {
input: {
actorUrn: authenticatedUserUrn,
resourceSpec: { resourceType: entityType, resourceUrn: urn },
},
},
fetchPolicy: 'cache-first',
});

const privileges = data?.getGrantedPrivileges?.privileges || [];
const canViewEntityPage = privileges.find((privilege) => privilege === VIEW_ENTITY_PAGE);

return (
<CompactContext.Provider value>
{data && !canViewEntityPage && <UnauthorizedPage />}
{data && canViewEntityPage && (
<EmbeddedPageWrapper>{entityRegistry.renderEmbeddedProfile(entityType, urn)}</EmbeddedPageWrapper>
)}
</CompactContext.Provider>
);
}
5 changes: 5 additions & 0 deletions datahub-web-react/src/app/entity/Entity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,9 @@ export interface Entity<T> {
* Returns the supported features for the entity
*/
supportedCapabilities: () => Set<EntityCapabilityType>;

/**
* Returns the profile component to be displayed in our Chrome extension
*/
renderEmbeddedProfile?: (urn: string) => JSX.Element;
}
3 changes: 2 additions & 1 deletion datahub-web-react/src/app/entity/EntityPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useGetGrantedPrivilegesQuery } from '../../graphql/policy.generated';
import { Message } from '../shared/Message';
import { UnauthorizedPage } from '../authorization/UnauthorizedPage';
import { ErrorSection } from '../shared/error/ErrorSection';
import { VIEW_ENTITY_PAGE } from './shared/constants';

interface RouteParams {
urn: string;
Expand Down Expand Up @@ -52,7 +53,7 @@ export const EntityPage = ({ entityType }: Props) => {
});
}, [entityType, urn]);

const canViewEntityPage = privileges.find((privilege) => privilege === 'VIEW_ENTITY_PAGE');
const canViewEntityPage = privileges.find((privilege) => privilege === VIEW_ENTITY_PAGE);
const showNewPage =
entityType === EntityType.Dataset ||
entityType === EntityType.Dashboard ||
Expand Down
6 changes: 6 additions & 0 deletions datahub-web-react/src/app/entity/EntityRegistry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ export default class EntityRegistry {
return entity.renderPreview(PreviewType.BROWSE, data);
}

// render the regular profile if embedded profile doesn't exist. Compact context should be set to true.
renderEmbeddedProfile(type: EntityType, urn: string): JSX.Element {
const entity = validatedGet(type, this.entityTypeToEntity);
return entity.renderEmbeddedProfile ? entity.renderEmbeddedProfile(urn) : entity.renderProfile(urn);
}

getLineageVizConfig<T>(type: EntityType, data: T): FetchedEntity | undefined {
const entity = validatedGet(type, this.entityTypeToEntity);
const genericEntityProperties = this.getGenericEntityProperties(type, data);
Expand Down
2 changes: 1 addition & 1 deletion datahub-web-react/src/app/entity/chart/ChartEntity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Entity, EntityCapabilityType, IconStyleType, PreviewType } from '../Ent
import { ChartPreview } from './preview/ChartPreview';
import { GetChartQuery, useGetChartQuery, useUpdateChartMutation } from '../../../graphql/chart.generated';
import { DocumentationTab } from '../shared/tabs/Documentation/DocumentationTab';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { SidebarTagsSection } from '../shared/containers/profile/sidebar/SidebarTagsSection';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { GenericEntityProperties } from '../shared/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Entity, EntityCapabilityType, IconStyleType, PreviewType } from '../Ent
import { Preview } from './preview/Preview';
import { EntityProfile } from '../shared/containers/profile/EntityProfile';
import { DocumentationTab } from '../shared/tabs/Documentation/DocumentationTab';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { getDataForEntityType } from '../shared/containers/profile/utils';
import { useGetContainerQuery } from '../../../graphql/container.generated';
Expand Down
12 changes: 11 additions & 1 deletion datahub-web-react/src/app/entity/dashboard/DashboardEntity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Dashboard, EntityType, LineageDirection, OwnershipType, SearchResult }
import { Entity, EntityCapabilityType, IconStyleType, PreviewType } from '../Entity';
import { EntityProfile } from '../shared/containers/profile/EntityProfile';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { SidebarTagsSection } from '../shared/containers/profile/sidebar/SidebarTagsSection';
import { DocumentationTab } from '../shared/tabs/Documentation/DocumentationTab';
import { DashboardChartsTab } from '../shared/tabs/Entity/DashboardChartsTab';
Expand All @@ -26,6 +26,7 @@ import { capitalizeFirstLetterOnly } from '../../shared/textUtil';
import { DashboardStatsSummarySubHeader } from './profile/DashboardStatsSummarySubHeader';
import { ChartSnippet } from '../chart/ChartSnippet';
import { EmbedTab } from '../shared/tabs/Embed/EmbedTab';
import EmbeddedProfile from '../shared/embed/EmbeddedProfile';

/**
* Definition of the DataHub Dashboard entity.
Expand Down Expand Up @@ -256,4 +257,13 @@ export class DashboardEntity implements Entity<Dashboard> {
EntityCapabilityType.SOFT_DELETE,
]);
};

renderEmbeddedProfile = (urn: string) => (
<EmbeddedProfile
urn={urn}
entityType={EntityType.Dashboard}
useEntityQuery={useGetDashboardQuery}
getOverrideProperties={this.getOverridePropertiesFromEntity}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EntityProfile } from '../shared/containers/profile/EntityProfile';
import { useGetDataFlowQuery, useUpdateDataFlowMutation } from '../../../graphql/dataFlow.generated';
import { DocumentationTab } from '../shared/tabs/Documentation/DocumentationTab';
import { PropertiesTab } from '../shared/tabs/Properties/PropertiesTab';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { SidebarTagsSection } from '../shared/containers/profile/sidebar/SidebarTagsSection';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { GenericEntityProperties } from '../shared/types';
Expand Down
2 changes: 1 addition & 1 deletion datahub-web-react/src/app/entity/dataJob/DataJobEntity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { GetDataJobQuery, useGetDataJobQuery, useUpdateDataJobMutation } from '.
import { DocumentationTab } from '../shared/tabs/Documentation/DocumentationTab';
import { PropertiesTab } from '../shared/tabs/Properties/PropertiesTab';
import { LineageTab } from '../shared/tabs/Lineage/LineageTab';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { SidebarTagsSection } from '../shared/containers/profile/sidebar/SidebarTagsSection';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { GenericEntityProperties } from '../shared/types';
Expand Down
12 changes: 11 additions & 1 deletion datahub-web-react/src/app/entity/dataset/DatasetEntity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PropertiesTab } from '../shared/tabs/Properties/PropertiesTab';
import { DocumentationTab } from '../shared/tabs/Documentation/DocumentationTab';
import { SchemaTab } from '../shared/tabs/Dataset/Schema/SchemaTab';
import QueriesTab from '../shared/tabs/Dataset/Queries/QueriesTab';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { SidebarTagsSection } from '../shared/containers/profile/sidebar/SidebarTagsSection';
import StatsTab from '../shared/tabs/Dataset/Stats/StatsTab';
Expand All @@ -28,6 +28,7 @@ import { SidebarSiblingsSection } from '../shared/containers/profile/sidebar/Sid
import { DatasetStatsSummarySubHeader } from './profile/stats/stats/DatasetStatsSummarySubHeader';
import { DatasetSearchSnippet } from './DatasetSearchSnippet';
import { EmbedTab } from '../shared/tabs/Embed/EmbedTab';
import EmbeddedProfile from '../shared/embed/EmbeddedProfile';

const SUBTYPES = {
VIEW: 'view',
Expand Down Expand Up @@ -329,4 +330,13 @@ export class DatasetEntity implements Entity<Dataset> {
EntityCapabilityType.SOFT_DELETE,
]);
};

renderEmbeddedProfile = (urn: string) => (
<EmbeddedProfile
urn={urn}
entityType={EntityType.Dataset}
useEntityQuery={useGetDatasetQuery}
getOverrideProperties={this.getOverridePropertiesFromEntity}
/>
);
}
2 changes: 1 addition & 1 deletion datahub-web-react/src/app/entity/domain/DomainEntity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Entity, EntityCapabilityType, IconStyleType, PreviewType } from '../Ent
import { Preview } from './preview/Preview';
import { EntityProfile } from '../shared/containers/profile/EntityProfile';
import { DocumentationTab } from '../shared/tabs/Documentation/DocumentationTab';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { getDataForEntityType } from '../shared/containers/profile/utils';
import { useGetDomainQuery } from '../../../graphql/domain.generated';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import GlossaryEntitiesPath from '../../glossary/GlossaryEntitiesPath';
import { Entity, EntityCapabilityType, IconStyleType, PreviewType } from '../Entity';
import { EntityProfile } from '../shared/containers/profile/EntityProfile';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { getDataForEntityType } from '../shared/containers/profile/utils';
import { EntityMenuItems } from '../shared/EntityDropdown/EntityDropdown';
import { DocumentationTab } from '../shared/tabs/Documentation/DocumentationTab';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import GlossayRelatedTerms from './profile/GlossaryRelatedTerms';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { PropertiesTab } from '../shared/tabs/Properties/PropertiesTab';
import { DocumentationTab } from '../shared/tabs/Documentation/DocumentationTab';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import GlossaryEntitiesPath from '../../glossary/GlossaryEntitiesPath';
import { EntityMenuItems } from '../shared/EntityDropdown/EntityDropdown';
import { EntityActionItem } from '../shared/entity/EntityActions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button, Typography } from 'antd';
import React, { useState } from 'react';
import styled from 'styled-components';
import { EntityType, Ownership } from '../../../types.generated';
import { ExpandedOwner } from '../shared/components/styled/ExpandedOwner';
import { ExpandedOwner } from '../shared/components/styled/ExpandedOwner/ExpandedOwner';
import { EditOwnersModal } from '../shared/containers/profile/sidebar/Ownership/EditOwnersModal';
import { DisplayCount, GroupSectionTitle, GroupSectionHeader } from '../shared/SidebarStyledComponents';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getDataForEntityType } from '../shared/containers/profile/utils';
import { EntityProfile } from '../shared/containers/profile/EntityProfile';
import { GenericEntityProperties } from '../shared/types';
import { GetMlFeatureQuery, useGetMlFeatureQuery } from '../../../graphql/mlFeature.generated';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { SidebarTagsSection } from '../shared/containers/profile/sidebar/SidebarTagsSection';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { SidebarDomainSection } from '../shared/containers/profile/sidebar/Domain/SidebarDomainSection';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useGetMlFeatureTableQuery } from '../../../graphql/mlFeatureTable.gener
import { EntityProfile } from '../shared/containers/profile/EntityProfile';
import { SidebarDomainSection } from '../shared/containers/profile/sidebar/Domain/SidebarDomainSection';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { SidebarTagsSection } from '../shared/containers/profile/sidebar/SidebarTagsSection';
import MlFeatureTableFeatures from './profile/features/MlFeatureTableFeatures';
import Sources from './profile/Sources';
Expand Down
2 changes: 1 addition & 1 deletion datahub-web-react/src/app/entity/mlModel/MLModelEntity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { GenericEntityProperties } from '../shared/types';
import MLModelSummary from './profile/MLModelSummary';
import MLModelGroupsTab from './profile/MLModelGroupsTab';
import { SidebarTagsSection } from '../shared/containers/profile/sidebar/SidebarTagsSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { SidebarDomainSection } from '../shared/containers/profile/sidebar/Domain/SidebarDomainSection';
import { PropertiesTab } from '../shared/tabs/Properties/PropertiesTab';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { GenericEntityProperties } from '../shared/types';
import { EntityProfile } from '../shared/containers/profile/EntityProfile';
import { SidebarDomainSection } from '../shared/containers/profile/sidebar/Domain/SidebarDomainSection';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { SidebarTagsSection } from '../shared/containers/profile/sidebar/SidebarTagsSection';
import { useGetMlModelGroupQuery } from '../../../graphql/mlModelGroup.generated';
import ModelGroupModels from './profile/ModelGroupModels';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EntityProfile } from '../shared/containers/profile/EntityProfile';
import { FeatureTableTab } from '../shared/tabs/ML/MlPrimaryKeyFeatureTableTab';
import { DocumentationTab } from '../shared/tabs/Documentation/DocumentationTab';
import { SidebarTagsSection } from '../shared/containers/profile/sidebar/SidebarTagsSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/SidebarAboutSection';
import { SidebarAboutSection } from '../shared/containers/profile/sidebar/AboutSection/SidebarAboutSection';
import { SidebarDomainSection } from '../shared/containers/profile/sidebar/Domain/SidebarDomainSection';
import { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
import { LineageTab } from '../shared/tabs/Lineage/LineageTab';
Expand Down
Loading

0 comments on commit e1bca87

Please sign in to comment.