2021-02-03 11:49:51 -08:00
|
|
|
import * as React from 'react';
|
2021-02-23 12:45:42 -08:00
|
|
|
import { DatabaseFilled, DatabaseOutlined } from '@ant-design/icons';
|
2021-03-23 15:18:32 -07:00
|
|
|
import { Tag, Typography } from 'antd';
|
|
|
|
import styled from 'styled-components';
|
2021-04-23 00:18:39 -07:00
|
|
|
import { Dataset, EntityType, SearchResult } from '../../../types.generated';
|
2021-02-23 12:45:42 -08:00
|
|
|
import { Entity, IconStyleType, PreviewType } from '../Entity';
|
2021-02-03 11:49:51 -08:00
|
|
|
import { Preview } from './preview/Preview';
|
2021-03-23 15:18:32 -07:00
|
|
|
import { FIELDS_TO_HIGHLIGHT } from './search/highlights';
|
2021-04-09 11:55:25 -07:00
|
|
|
import { Direction } from '../../lineage/types';
|
2021-04-23 00:18:39 -07:00
|
|
|
import getChildren from '../../lineage/utils/getChildren';
|
2021-08-31 22:00:56 -07:00
|
|
|
import { EntityProfile } from '../shared/containers/profile/EntityProfile';
|
|
|
|
import { GetDatasetQuery, useGetDatasetQuery, useUpdateDatasetMutation } from '../../../graphql/dataset.generated';
|
|
|
|
import { GenericEntityProperties } from '../shared/types';
|
|
|
|
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 { SidebarOwnerSection } from '../shared/containers/profile/sidebar/Ownership/SidebarOwnerSection';
|
|
|
|
import { SidebarTagsSection } from '../shared/containers/profile/sidebar/SidebarTagsSection';
|
|
|
|
import { SidebarStatsSection } from '../shared/containers/profile/sidebar/Dataset/StatsSidebarSection';
|
|
|
|
import StatsTab from '../shared/tabs/Dataset/Stats/StatsTab';
|
|
|
|
import { LineageTab } from '../shared/tabs/Lineage/LineageTab';
|
2021-10-06 23:39:52 -07:00
|
|
|
import { capitalizeFirstLetter } from '../../shared/capitalizeFirstLetter';
|
2021-10-12 15:47:29 -07:00
|
|
|
import ViewDefinitionTab from '../shared/tabs/Dataset/View/ViewDefinitionTab';
|
|
|
|
import { SidebarViewDefinitionSection } from '../shared/containers/profile/sidebar/Dataset/View/SidebarViewDefinitionSection';
|
2021-03-23 15:18:32 -07:00
|
|
|
|
|
|
|
const MatchTag = styled(Tag)`
|
|
|
|
&&& {
|
|
|
|
margin-bottom: 0px;
|
|
|
|
margin-top: 10px;
|
|
|
|
}
|
|
|
|
`;
|
2021-02-03 11:49:51 -08:00
|
|
|
|
2021-10-12 15:47:29 -07:00
|
|
|
const SUBTYPES = {
|
|
|
|
VIEW: 'view',
|
|
|
|
};
|
|
|
|
|
2021-02-03 11:49:51 -08:00
|
|
|
/**
|
|
|
|
* Definition of the DataHub Dataset entity.
|
|
|
|
*/
|
|
|
|
export class DatasetEntity implements Entity<Dataset> {
|
|
|
|
type: EntityType = EntityType.Dataset;
|
|
|
|
|
2021-02-23 12:45:42 -08:00
|
|
|
icon = (fontSize: number, styleType: IconStyleType) => {
|
|
|
|
if (styleType === IconStyleType.TAB_VIEW) {
|
|
|
|
return <DatabaseOutlined style={{ fontSize }} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (styleType === IconStyleType.HIGHLIGHT) {
|
|
|
|
return <DatabaseFilled style={{ fontSize, color: '#B37FEB' }} />;
|
|
|
|
}
|
|
|
|
|
2021-04-17 00:46:02 +08:00
|
|
|
if (styleType === IconStyleType.SVG) {
|
|
|
|
return (
|
2021-04-19 11:58:04 -07:00
|
|
|
<path d="M832 64H192c-17.7 0-32 14.3-32 32v832c0 17.7 14.3 32 32 32h640c17.7 0 32-14.3 32-32V96c0-17.7-14.3-32-32-32zm-600 72h560v208H232V136zm560 480H232V408h560v208zm0 272H232V680h560v208zM304 240a40 40 0 1080 0 40 40 0 10-80 0zm0 272a40 40 0 1080 0 40 40 0 10-80 0zm0 272a40 40 0 1080 0 40 40 0 10-80 0z" />
|
2021-04-17 00:46:02 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-23 12:45:42 -08:00
|
|
|
return (
|
|
|
|
<DatabaseFilled
|
|
|
|
style={{
|
|
|
|
fontSize,
|
|
|
|
color: '#BFBFBF',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-02-03 11:49:51 -08:00
|
|
|
isSearchEnabled = () => true;
|
|
|
|
|
|
|
|
isBrowseEnabled = () => true;
|
|
|
|
|
2021-04-09 11:55:25 -07:00
|
|
|
isLineageEnabled = () => true;
|
|
|
|
|
2021-02-03 11:49:51 -08:00
|
|
|
getAutoCompleteFieldName = () => 'name';
|
|
|
|
|
|
|
|
getPathName = () => 'dataset';
|
|
|
|
|
2021-09-28 10:30:37 -07:00
|
|
|
getEntityName = () => 'Dataset';
|
|
|
|
|
2021-02-03 11:49:51 -08:00
|
|
|
getCollectionName = () => 'Datasets';
|
|
|
|
|
2021-08-31 22:00:56 -07:00
|
|
|
renderProfile = (urn: string) => (
|
|
|
|
<EntityProfile
|
|
|
|
urn={urn}
|
|
|
|
entityType={EntityType.Dataset}
|
|
|
|
useEntityQuery={useGetDatasetQuery}
|
|
|
|
useUpdateQuery={useUpdateDatasetMutation}
|
|
|
|
getOverrideProperties={this.getOverrideProperties}
|
|
|
|
tabs={[
|
|
|
|
{
|
|
|
|
name: 'Schema',
|
|
|
|
component: SchemaTab,
|
|
|
|
},
|
2021-10-12 15:47:29 -07:00
|
|
|
{
|
|
|
|
name: 'View Definition',
|
|
|
|
component: ViewDefinitionTab,
|
|
|
|
display: {
|
|
|
|
visible: (_, dataset: GetDatasetQuery) =>
|
|
|
|
(dataset?.dataset?.subTypes?.typeNames?.includes(SUBTYPES.VIEW) as boolean) || false,
|
|
|
|
enabled: (_, dataset: GetDatasetQuery) =>
|
|
|
|
(dataset?.dataset?.viewProperties?.logic && true) || false,
|
|
|
|
},
|
|
|
|
},
|
2021-08-31 22:00:56 -07:00
|
|
|
{
|
|
|
|
name: 'Documentation',
|
|
|
|
component: DocumentationTab,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Properties',
|
|
|
|
component: PropertiesTab,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Lineage',
|
|
|
|
component: LineageTab,
|
2021-10-12 15:47:29 -07:00
|
|
|
display: {
|
|
|
|
visible: (_, _1) => true,
|
|
|
|
enabled: (_, dataset: GetDatasetQuery) =>
|
|
|
|
(dataset?.dataset?.upstreamLineage?.entities?.length || 0) > 0 ||
|
|
|
|
(dataset?.dataset?.downstreamLineage?.entities?.length || 0) > 0,
|
|
|
|
},
|
2021-08-31 22:00:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Queries',
|
|
|
|
component: QueriesTab,
|
2021-10-12 15:47:29 -07:00
|
|
|
display: {
|
|
|
|
visible: (_, _1) => true,
|
|
|
|
enabled: (_, dataset: GetDatasetQuery) =>
|
|
|
|
(dataset?.dataset?.usageStats?.buckets?.length || 0) > 0,
|
|
|
|
},
|
2021-08-31 22:00:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Stats',
|
|
|
|
component: StatsTab,
|
2021-10-12 15:47:29 -07:00
|
|
|
display: {
|
|
|
|
visible: (_, _1) => true,
|
|
|
|
enabled: (_, dataset: GetDatasetQuery) =>
|
|
|
|
(dataset?.dataset?.datasetProfiles?.length || 0) > 0 ||
|
|
|
|
(dataset?.dataset?.usageStats?.buckets?.length || 0) > 0,
|
|
|
|
},
|
2021-08-31 22:00:56 -07:00
|
|
|
},
|
|
|
|
]}
|
|
|
|
sidebarSections={[
|
|
|
|
{
|
|
|
|
component: SidebarAboutSection,
|
|
|
|
},
|
2021-10-12 15:47:29 -07:00
|
|
|
{
|
|
|
|
component: SidebarViewDefinitionSection,
|
|
|
|
display: {
|
|
|
|
visible: (_, dataset: GetDatasetQuery) =>
|
|
|
|
(dataset?.dataset?.viewProperties?.logic && true) || false,
|
|
|
|
},
|
|
|
|
},
|
2021-08-31 22:00:56 -07:00
|
|
|
{
|
|
|
|
component: SidebarStatsSection,
|
2021-10-12 15:47:29 -07:00
|
|
|
display: {
|
|
|
|
visible: (_, dataset: GetDatasetQuery) =>
|
|
|
|
(dataset?.dataset?.datasetProfiles?.length || 0) > 0 ||
|
|
|
|
(dataset?.dataset?.usageStats?.buckets?.length || 0) > 0,
|
|
|
|
},
|
2021-08-31 22:00:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
component: SidebarTagsSection,
|
2021-09-13 09:16:37 -07:00
|
|
|
properties: {
|
|
|
|
hasTags: true,
|
|
|
|
hasTerms: true,
|
|
|
|
},
|
2021-08-31 22:00:56 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
component: SidebarOwnerSection,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2021-10-06 07:13:38 -07:00
|
|
|
getOverrideProperties = (dataset: GetDatasetQuery): GenericEntityProperties => {
|
2021-10-06 23:39:52 -07:00
|
|
|
// if dataset has subTypes filled out, pick the most specific subtype and return it
|
|
|
|
const subTypes = dataset?.dataset?.subTypes;
|
2021-10-06 07:13:38 -07:00
|
|
|
return {
|
|
|
|
externalUrl: dataset.dataset?.properties?.externalUrl,
|
2021-10-06 23:39:52 -07:00
|
|
|
entityTypeOverride: subTypes ? capitalizeFirstLetter(subTypes.typeNames?.[0]) : '',
|
2021-10-06 07:13:38 -07:00
|
|
|
};
|
2021-08-31 22:00:56 -07:00
|
|
|
};
|
2021-02-03 11:49:51 -08:00
|
|
|
|
2021-02-09 14:30:23 -08:00
|
|
|
renderPreview = (_: PreviewType, data: Dataset) => {
|
2021-02-03 11:49:51 -08:00
|
|
|
return (
|
|
|
|
<Preview
|
|
|
|
urn={data.urn}
|
|
|
|
name={data.name}
|
|
|
|
origin={data.origin}
|
2021-10-06 23:39:52 -07:00
|
|
|
subtype={data.subTypes?.typeNames?.[0]}
|
2021-07-23 04:20:40 +08:00
|
|
|
description={data.editableProperties?.description || data.description}
|
2021-07-30 17:41:03 -07:00
|
|
|
platformName={data.platform.displayName || data.platform.name}
|
2021-03-04 23:16:13 -08:00
|
|
|
platformLogo={data.platform.info?.logoUrl}
|
2021-02-23 12:45:42 -08:00
|
|
|
owners={data.ownership?.owners}
|
2021-03-07 11:26:47 -08:00
|
|
|
globalTags={data.globalTags}
|
2021-05-25 10:42:35 +05:30
|
|
|
glossaryTerms={data.glossaryTerms}
|
2021-02-03 11:49:51 -08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2021-03-23 15:18:32 -07:00
|
|
|
|
|
|
|
renderSearch = (result: SearchResult) => {
|
|
|
|
const data = result.entity as Dataset;
|
|
|
|
return (
|
|
|
|
<Preview
|
|
|
|
urn={data.urn}
|
|
|
|
name={data.name}
|
|
|
|
origin={data.origin}
|
2021-07-23 04:20:40 +08:00
|
|
|
description={data.editableProperties?.description || data.description}
|
2021-03-23 15:18:32 -07:00
|
|
|
platformName={data.platform.name}
|
|
|
|
platformLogo={data.platform.info?.logoUrl}
|
|
|
|
owners={data.ownership?.owners}
|
|
|
|
globalTags={data.globalTags}
|
2021-10-06 23:39:52 -07:00
|
|
|
subtype={data.subTypes?.typeNames?.[0]}
|
2021-03-23 15:18:32 -07:00
|
|
|
snippet={
|
|
|
|
// Add match highlights only if all the matched fields are in the FIELDS_TO_HIGHLIGHT
|
|
|
|
result.matchedFields.length > 0 &&
|
|
|
|
result.matchedFields.every((field) => FIELDS_TO_HIGHLIGHT.has(field.name)) && (
|
|
|
|
<MatchTag>
|
|
|
|
<Typography.Text>
|
|
|
|
Matches {FIELDS_TO_HIGHLIGHT.get(result.matchedFields[0].name)}{' '}
|
|
|
|
<b>{result.matchedFields[0].value}</b>
|
|
|
|
</Typography.Text>
|
|
|
|
</MatchTag>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2021-04-09 11:55:25 -07:00
|
|
|
|
|
|
|
getLineageVizConfig = (entity: Dataset) => {
|
|
|
|
return {
|
|
|
|
urn: entity.urn,
|
|
|
|
name: entity.name,
|
|
|
|
type: EntityType.Dataset,
|
2021-10-06 23:39:52 -07:00
|
|
|
subtype: entity.subTypes?.typeNames?.[0] || undefined,
|
2021-04-23 00:18:39 -07:00
|
|
|
upstreamChildren: getChildren({ entity, type: EntityType.Dataset }, Direction.Upstream).map(
|
|
|
|
(child) => child.entity.urn,
|
|
|
|
),
|
|
|
|
downstreamChildren: getChildren({ entity, type: EntityType.Dataset }, Direction.Downstream).map(
|
|
|
|
(child) => child.entity.urn,
|
|
|
|
),
|
2021-04-09 11:55:25 -07:00
|
|
|
icon: entity.platform.info?.logoUrl || undefined,
|
2021-04-23 00:18:39 -07:00
|
|
|
platform: entity.platform.name,
|
2021-04-09 11:55:25 -07:00
|
|
|
};
|
|
|
|
};
|
2021-09-02 19:05:13 -07:00
|
|
|
|
|
|
|
displayName = (data: Dataset) => {
|
|
|
|
return data.name;
|
|
|
|
};
|
2021-02-03 11:49:51 -08:00
|
|
|
}
|