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 { return {
owner, owner,
avatar: avatarProperties avatar: avatarProperties
? makeAvatar(avatarProperties)({ userName: owner.userName }) ? makeAvatar(avatarProperties)(owner)
: { imageUrl: '', imageUrlFallback: '/assets/images/default_avatar.png' }, : { imageUrl: '', imageUrlFallback: '/assets/images/default_avatar.png' },
profile: PersonEntity.profileLinkFromUsername(owner.userName) profile: PersonEntity.profileLinkFromUsername(owner.userName)
}; };

View File

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

View File

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

View File

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

View File

@ -2,28 +2,31 @@ import { IDataPlatform } from '@datahub/metadata-types/types/entity/dataset/plat
import { ISuggestionBuilder } from 'wherehows-web/utils/parsers/autocomplete/types'; import { ISuggestionBuilder } from 'wherehows-web/utils/parsers/autocomplete/types';
import { readDataPlatforms } from '@datahub/data-models/api/dataset/platforms'; 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 * when we expect to autosuggest a platform, we call backend to get the entire list
* then cache it and do a local search. * 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 = (
if (!platforms) { defaultPlatforms: Array<IDataPlatform> = []
platforms = await readDataPlatforms(); ): ((builder: ISuggestionBuilder, facetValue: string) => Promise<ISuggestionBuilder>) => {
} let platforms: Array<IDataPlatform> = defaultPlatforms;
return { return async (builder: ISuggestionBuilder, facetValue: string): Promise<ISuggestionBuilder> => {
...builder, if (!platforms) {
facetNames: [ platforms = await readDataPlatforms();
...builder.facetNames, }
...platforms
.filter(platform => platform.name.indexOf(facetValue) >= 0) return {
.map(platform => ({ ...builder,
title: `platform:${platform.name}`, facetNames: [
text: `${builder.textPrevious}platform:${platform.name} ` ...builder.facetNames,
})) ...platforms
] .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>> => { ): Promise<Array<string>> => {
// otherwise lets invoke api to fetch values // otherwise lets invoke api to fetch values
let suggestions: Array<string> = []; let suggestions: Array<string> = [];
const searchRenderProps = DataModelEntity[entity].renderProps.search; const { apiName, attributes } = DataModelEntity[entity].renderProps.search;
const searchAttributes = searchRenderProps.attributes; const fieldMeta = attributes.find((attr): boolean => attr.fieldName === facetName);
const fieldMeta = searchAttributes.find((attr): boolean => attr.fieldName === facetName);
const { minAutocompleteFetchLength } = fieldMeta || { minAutocompleteFetchLength: undefined }; const { minAutocompleteFetchLength } = fieldMeta || { minAutocompleteFetchLength: undefined };
const cacheKey = `${facetName}:${facetValue}`; const cacheKey = `${facetName}:${facetValue}`;
@ -39,7 +38,7 @@ export const fetchFacetValue = async (
const request: FieldValuesRequestV2<Record<string, string>> = { const request: FieldValuesRequestV2<Record<string, string>> = {
field: facetName, field: facetName,
input: facetValue, input: facetValue,
type: searchRenderProps.apiName type: apiName
}; };
const facetValueReturn: IFieldValuesResponseV2 | undefined = await facetValuesApiEntities({ const facetValueReturn: IFieldValuesResponseV2 | undefined = await facetValuesApiEntities({
query: facetValue, 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, entity: DatasetEntity.displayName,
description: 'Dataset with filter platform', description: 'Dataset with filter platform',
text: 'platform:', text: 'platform:',
results: [ results: []
{
groupName: 'Filter By',
options: [
{
text: 'platform:hive ',
title: 'platform:hive'
},
{
text: 'platform:mysql ',
title: 'platform:mysql'
}
]
}
]
}, },
{ {
entity: DatasetEntity.displayName, entity: DatasetEntity.displayName,
description: 'Dataset with filter platform my', description: 'Dataset with filter platform my',
text: 'platform:my', text: 'platform:my',
results: [ results: []
{
groupName: 'Filter By',
options: [
{
text: 'platform:mysql ',
title: 'platform:mysql'
}
]
}
]
}, },
{ {
entity: DatasetEntity.displayName, entity: DatasetEntity.displayName,
description: 'Dataset with filter fabric', description: 'Dataset with filter fabric',
text: 'origin:co', text: 'origin:co',
results: [ results: []
{
groupName: 'Filter By',
options: [
{
text: 'dataorigin:corp ',
title: 'dataorigin:corp'
},
{
text: 'dataorigin:azurecontrol ',
title: 'dataorigin:azurecontrol'
}
]
}
]
}, },
{ {
entity: DatasetEntity.displayName, entity: DatasetEntity.displayName,