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-09 11:55:25 -07:00
|
|
|
import { Dataset, EntityType, RelatedDataset, 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-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-04-09 11:55:25 -07:00
|
|
|
export default function getChildren(entity: Dataset, direction: Direction | null): Array<RelatedDataset> {
|
|
|
|
if (direction === Direction.Upstream) {
|
|
|
|
return entity.upstreamLineage?.upstreams || [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (direction === Direction.Downstream) {
|
|
|
|
return entity.downstreamLineage?.downstreams || [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
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' }} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
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}
|
|
|
|
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-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}
|
|
|
|
description={data.description}
|
|
|
|
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,
|
|
|
|
upstreamChildren: getChildren(entity, Direction.Upstream).map((child) => child.dataset.urn),
|
|
|
|
downstreamChildren: getChildren(entity, Direction.Downstream).map((child) => child.dataset.urn),
|
|
|
|
icon: entity.platform.info?.logoUrl || undefined,
|
|
|
|
};
|
|
|
|
};
|
2021-02-03 11:49:51 -08:00
|
|
|
}
|