Skip to content

Commit

Permalink
feat(search): Add SchemaFieldEntity to search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-visa committed Apr 2, 2024
1 parent 56b3066 commit ee865dd
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ private SearchUtils() {}
EntityType.DOMAIN,
EntityType.DATA_PRODUCT,
EntityType.NOTEBOOK,
EntityType.BUSINESS_ATTRIBUTE);
EntityType.BUSINESS_ATTRIBUTE,
EntityType.SCHEMA_FIELD);

/** Entities that are part of autocomplete by default in Auto Complete Across Entities */
public static final List<EntityType> AUTO_COMPLETE_ENTITY_TYPES =
Expand Down
2 changes: 2 additions & 0 deletions datahub-web-react/src/app/buildEntityRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ERModelRelationshipEntity } from './entity/ermodelrelationships/ERModel
import { RoleEntity } from './entity/Access/RoleEntity';
import { RestrictedEntity } from './entity/restricted/RestrictedEntity';
import {BusinessAttributeEntity} from "./entity/businessAttribute/BusinessAttributeEntity";
import { SchemaFieldPropertiesEntity } from './entity/schemaField/SchemaFieldPropertiesEntity';

export default function buildEntityRegistry() {
const registry = new EntityRegistry();
Expand Down Expand Up @@ -50,5 +51,6 @@ export default function buildEntityRegistry() {
registry.register(new ERModelRelationshipEntity())
registry.register(new RestrictedEntity());
registry.register(new BusinessAttributeEntity());
registry.register(new SchemaFieldPropertiesEntity());
return registry;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as React from 'react';
import { PicCenterOutlined } from '@ant-design/icons';
import { EntityType, SchemaFieldEntity, SearchResult } from '../../../types.generated';
import { Entity, IconStyleType, PreviewType } from '../Entity';
import { getDataForEntityType } from '../shared/containers/profile/utils';
import { Preview } from './preview/Preview';

export class SchemaFieldPropertiesEntity implements Entity<SchemaFieldEntity> {
type: EntityType = EntityType.SchemaField;

icon = (fontSize: number, styleType: IconStyleType, color = '#BFBFBF') => (
<PicCenterOutlined style={{ fontSize, color }} />
);

isSearchEnabled = () => true;

isBrowseEnabled = () => false;

isLineageEnabled = () => false;

// Currently unused.
getAutoCompleteFieldName = () => 'schemaField';

// Currently unused.
getPathName = () => 'schemaField';

// Currently unused.
getEntityName = () => 'schemaField';

// Currently unused.
getCollectionName = () => 'schemaFields';

// Currently unused.
renderProfile = (_: string) => <></>;

renderPreview = (previewType: PreviewType, data: SchemaFieldEntity) => (
<Preview
previewType={previewType}
datasetUrn={data.parent.urn}
businessAttributeUrn={data.businessAttributes?.businessAttribute?.businessAttribute.urn || ''}
name={data.fieldPath}
/>
);

renderSearch = (result: SearchResult) => this.renderPreview(PreviewType.SEARCH, result.entity as SchemaFieldEntity);

displayName = (data: SchemaFieldEntity) => data?.fieldPath || data.urn;

getGenericEntityProperties = (data: SchemaFieldEntity) =>
getDataForEntityType({ data, entityType: this.type, getOverrideProperties: (newData) => newData });

supportedCapabilities = () => new Set([]);
}
50 changes: 50 additions & 0 deletions datahub-web-react/src/app/entity/schemaField/preview/Preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import { PicCenterOutlined } from '@ant-design/icons';
import { useLocation } from 'react-router-dom';
import { EntityType, Owner } from '../../../../types.generated';
import DefaultPreviewCard from '../../../preview/DefaultPreviewCard';
import { useEntityRegistry } from '../../../useEntityRegistry';
import { IconStyleType, PreviewType } from '../../Entity';
import UrlButton from '../../shared/UrlButton';
import { getRelatedEntitiesUrl } from '../../../businessAttribute/businessAttributeUtils';

export const Preview = ({
datasetUrn,
businessAttributeUrn,
name,
description,
owners,
previewType,
}: {
datasetUrn: string;
businessAttributeUrn: string;
name: string;
description?: string | null;
owners?: Array<Owner> | null;
previewType: PreviewType;
}): JSX.Element => {
const entityRegistry = useEntityRegistry();
const location = useLocation();
const relatedEntitiesUrl = getRelatedEntitiesUrl(entityRegistry, businessAttributeUrn);

const url = `${entityRegistry.getEntityUrl(EntityType.Dataset, datasetUrn)}/${encodeURIComponent('Schema')}?schemaFilter=${encodeURIComponent('customer_id')}`;

return (
<DefaultPreviewCard
previewType={previewType}
url={url}
name={name ?? ''}
urn={datasetUrn}
description={description ?? ''}
owners={owners}
logoComponent={<PicCenterOutlined style={{ fontSize: '20px' }} />}
type="Column"
typeIcon={entityRegistry.getIcon(EntityType.SchemaField, 14, IconStyleType.ACCENT)}
entityTitleSuffix={
decodeURIComponent(location.pathname) !== decodeURIComponent(relatedEntitiesUrl) && (
<UrlButton href={relatedEntitiesUrl}>View Related Entities</UrlButton>
)
}
/>
);
};
23 changes: 23 additions & 0 deletions datahub-web-react/src/graphql/search.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,9 @@ fragment searchResultFields on Entity {
... on BusinessAttribute {
...businessAttributeFields
}
... on SchemaFieldEntity {
...entityField
}
}

fragment facetFields on FacetMetadata {
Expand Down Expand Up @@ -961,6 +964,26 @@ fragment searchResults on SearchResults {
}
}

fragment entityField on SchemaFieldEntity {
urn
type
parent {
urn
type
}
fieldPath
structuredProperties {
properties {
...structuredPropertiesFields
}
}
businessAttributes {
businessAttribute {
...businessAttribute
}
}
}

fragment schemaFieldEntityFields on SchemaFieldEntity {
urn
type
Expand Down

0 comments on commit ee865dd

Please sign in to comment.