Merge pull request #1506 from theseyi/datahub

Remove local facet construction for platform and origin autocomplete …
This commit is contained in:
Seyi Adebajo 2019-10-16 20:03:51 -07:00 committed by GitHub
commit 46c55c2635
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 90 deletions

View File

@ -192,7 +192,7 @@ export default class DatasetAuthors extends Component {
return {
owner,
avatar: avatarProperties
? makeAvatar(avatarProperties)({ userName: owner.userName })
? makeAvatar(avatarProperties)(owner)
: { imageUrl: '', imageUrlFallback: '/assets/images/default_avatar.png' },
profile: PersonEntity.profileLinkFromUsername(owner.userName)
};

View File

@ -14,9 +14,10 @@ const fallback = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAA
* @param {IAppConfig.userEntityProps.aviUrlFallback} aviUrlFallback
* @return {IAvatar}
*/
const makeAvatar = ({ aviUrlPrimary, aviUrlFallback = fallback }: IAppConfig['userEntityProps']): AvatarCreatorFunc => (
object: Partial<IAvatar>
): IAvatar => {
export const makeAvatar = ({
aviUrlPrimary,
aviUrlFallback = fallback
}: IAppConfig['userEntityProps']): AvatarCreatorFunc => (object: Partial<IAvatar>): IAvatar => {
const props = pick(object, ['email', 'userName', 'name', 'imageUrl', 'pictureLink']);
const { userName, pictureLink } = props;
const imageUrlFallback = aviUrlFallback || fallback;
@ -32,5 +33,3 @@ const makeAvatar = ({ aviUrlPrimary, aviUrlFallback = fallback }: IAppConfig['us
...props
};
};
export { makeAvatar };

View File

@ -13,7 +13,7 @@
<thead>
<tr>
<th class="dataset-author-column--extra-wide">
LDAP Username
Username
</th>
<th class="dataset-author-column--extra-wide">Full Name</th>
<th class="dataset-author-column--narrow">ID Type</th>

View File

@ -3,12 +3,9 @@ import {
AutocompleteRuleNames,
ISuggestionBuilder,
IState,
INodeFacetProcessor,
ISuggestion
} from 'wherehows-web/utils/parsers/autocomplete/types';
import { dataToString } from 'wherehows-web/utils/parsers/autocomplete/utils';
import { platform } from 'wherehows-web/utils/parsers/autocomplete/processors/facets/platform';
import { fabric } from 'wherehows-web/utils/parsers/autocomplete/processors/facets/fabric';
import { ISearchEntityRenderProps } from '@datahub/data-models/types/entity/rendering/search-entity-render-prop';
import { DataModelEntity } from '@datahub/data-models/constants/entity';
import { fetchFacetValue } from 'wherehows-web/utils/parsers/helpers';
@ -50,15 +47,6 @@ const getFacetValueFromStateRule = (state: IState): string => {
return '';
};
/**
* Current facets processors available
* @type {INodeFacetProcessor}
*/
export const facetNameProcessor: INodeFacetProcessor = {
platform,
origin: fabric
};
export const facetsProcessor: INodeProcessor = {
/**
* When 'name' is expected we just return 'name:' as suggestion
@ -97,14 +85,6 @@ export const facetsProcessor: INodeProcessor = {
): Promise<ISuggestionBuilder> => {
const facetName = getFacetNameFromStateRule(ruleState);
const facetValue = getFacetValueFromStateRule(ruleState);
// First lets check if we have a special processing for that property
const processor = facetNameProcessor[facetName];
if (processor) {
return await processor(builder, facetValue);
}
const suggestions = await fetchFacetValue(facetName, facetValue, builder.entity);
return {

View File

@ -2,14 +2,16 @@ import { IDataPlatform } from '@datahub/metadata-types/types/entity/dataset/plat
import { ISuggestionBuilder } from 'wherehows-web/utils/parsers/autocomplete/types';
import { readDataPlatforms } from '@datahub/data-models/api/dataset/platforms';
let platforms: Array<IDataPlatform>;
/**
* when we expect to autosuggest a platform, we call backend to get the entire list
* then cache it and do a local search.
* TODO: META-7667 scope cache to function instead of module
*/
export const platform = async (builder: ISuggestionBuilder, facetValue: string): Promise<ISuggestionBuilder> => {
export const getPlatformProcessor = (
defaultPlatforms: Array<IDataPlatform> = []
): ((builder: ISuggestionBuilder, facetValue: string) => Promise<ISuggestionBuilder>) => {
let platforms: Array<IDataPlatform> = defaultPlatforms;
return async (builder: ISuggestionBuilder, facetValue: string): Promise<ISuggestionBuilder> => {
if (!platforms) {
platforms = await readDataPlatforms();
}
@ -19,11 +21,12 @@ export const platform = async (builder: ISuggestionBuilder, facetValue: string):
facetNames: [
...builder.facetNames,
...platforms
.filter(platform => platform.name.indexOf(facetValue) >= 0)
.map(platform => ({
.filter((platform: IDataPlatform): boolean => platform.name.indexOf(facetValue) >= 0)
.map((platform): { title: string; text: string } => ({
title: `platform:${platform.name}`,
text: `${builder.textPrevious}platform:${platform.name} `
}))
]
};
};
};

View File

@ -28,9 +28,8 @@ export const fetchFacetValue = async (
): Promise<Array<string>> => {
// otherwise lets invoke api to fetch values
let suggestions: Array<string> = [];
const searchRenderProps = DataModelEntity[entity].renderProps.search;
const searchAttributes = searchRenderProps.attributes;
const fieldMeta = searchAttributes.find((attr): boolean => attr.fieldName === facetName);
const { apiName, attributes } = DataModelEntity[entity].renderProps.search;
const fieldMeta = attributes.find((attr): boolean => attr.fieldName === facetName);
const { minAutocompleteFetchLength } = fieldMeta || { minAutocompleteFetchLength: undefined };
const cacheKey = `${facetName}:${facetValue}`;
@ -39,7 +38,7 @@ export const fetchFacetValue = async (
const request: FieldValuesRequestV2<Record<string, string>> = {
field: facetName,
input: facetValue,
type: searchRenderProps.apiName
type: apiName
};
const facetValueReturn: IFieldValuesResponseV2 | undefined = await facetValuesApiEntities({
query: facetValue,

View File

@ -150,61 +150,24 @@ const createTests = (server: IMirageWherehows): Array<ITestSet> => {
}
]
},
// TODO: update tests with sample api response data for "text: 'platform:'", "text: 'platform:my'", and "text: 'origin:co'"
{
entity: DatasetEntity.displayName,
description: 'Dataset with filter platform',
text: 'platform:',
results: [
{
groupName: 'Filter By',
options: [
{
text: 'platform:hive ',
title: 'platform:hive'
},
{
text: 'platform:mysql ',
title: 'platform:mysql'
}
]
}
]
results: []
},
{
entity: DatasetEntity.displayName,
description: 'Dataset with filter platform my',
text: 'platform:my',
results: [
{
groupName: 'Filter By',
options: [
{
text: 'platform:mysql ',
title: 'platform:mysql'
}
]
}
]
results: []
},
{
entity: DatasetEntity.displayName,
description: 'Dataset with filter fabric',
text: 'origin:co',
results: [
{
groupName: 'Filter By',
options: [
{
text: 'dataorigin:corp ',
title: 'dataorigin:corp'
},
{
text: 'dataorigin:azurecontrol ',
title: 'dataorigin:azurecontrol'
}
]
}
]
results: []
},
{
entity: DatasetEntity.displayName,