Charlie Tran 843a6c5bbb
feat(frontend): update datahub-web client UI code (#1806)
* Releases updated version of datahub-web client UI code

* Fix typo in yarn lock

* Change yarn lock to match yarn registry directories

* Previous commit missed some paths

* Even more changes to yarnlock missing in previous commit

* Include codegen file for typings

* Add files to get parity for datahub-web and current OS datahub-midtier

* Add in typo fix from previous commit - change to proper license

* Implement proper OS fix for person entity picture url

* Workarounds for open source DH issues

* Fixes institutional memory api and removes unopensourced tabs for datasets

* Fixes search dataset deprecation and user search issue as a result of changes

* Remove internal only options in the avatar menu
2020-08-26 15:44:50 -07:00

57 lines
2.1 KiB
TypeScript

import { ISuggestionGroup } from 'datahub-web/utils/parsers/autocomplete/types';
import { DataModelEntity } from '@datahub/data-models/constants/entity';
import { IFieldValuesResponseV2, FieldValuesRequestV2 } from 'datahub-web/typings/app/search/fields-v2';
import { facetValuesApiEntities } from 'datahub-web/utils/parsers/autocomplete/utils';
import { getFacetForcedValueForEntity } from '@datahub/data-models/entity/utils/facets';
export const createSuggestionsFromError = (error: string): Array<ISuggestionGroup> => {
return [
{
groupName: ' ',
options: [
{
title: error,
text: '-',
disabled: true
}
]
}
];
};
/**
* Will fetch autocomplete facet values given an entity (feature, metric, dataset).
*/
export const fetchFacetValue = async (
facetName: string,
facetValue: string,
entity: DataModelEntity
): Promise<Array<string>> => {
// otherwise lets invoke api to fetch values
let suggestions: Array<string> = [];
const { search: searchRenderProps, apiEntityName } = entity.renderProps;
const searchAttributes = searchRenderProps.attributes;
const fieldMeta = searchAttributes.find((attr): boolean => attr.fieldName === facetName);
const { minAutocompleteFetchLength } = fieldMeta || { minAutocompleteFetchLength: undefined };
const cacheKey = `${facetName}:${facetValue}`;
const forcedFacets = getFacetForcedValueForEntity(searchAttributes);
// if `facetValue` length (query length) is smaller than the minimum threshold,
// then an api will not be queried and the default suggestions value ([]) will be returned
const request: FieldValuesRequestV2<Record<string, string>> = {
field: facetName,
input: facetValue,
type: apiEntityName,
...forcedFacets
};
const facetValueReturn: IFieldValuesResponseV2 | undefined = await facetValuesApiEntities({
query: facetValue,
queryLengthThreshold: minAutocompleteFetchLength,
cacheKey,
requestParams: [request]
});
suggestions = (facetValueReturn && facetValueReturn.suggestions) || [];
return suggestions;
};