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-03-07 11:26:47 -08:00
|
|
|
import { DatasetProfile } from './profile/DatasetProfile';
|
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-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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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';
|
|
|
|
|
|
|
|
getCollectionName = () => 'Datasets';
|
|
|
|
|
2021-03-07 11:26:47 -08:00
|
|
|
renderProfile = (urn: string) => <DatasetProfile urn={urn} />;
|
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-07-23 04:20:40 +08:00
|
|
|
description={data.editableProperties?.description || data.description}
|
2021-02-23 12:45:42 -08:00
|
|
|
platformName={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}
|
|
|
|
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-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-02-03 11:49:51 -08:00
|
|
|
}
|