mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-21 15:48:05 +00:00

* 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
70 lines
2.2 KiB
TypeScript
70 lines
2.2 KiB
TypeScript
import { typeOf } from '@ember/utils';
|
|
import { IFacetsSelectionsMap, IFacetSelections } from '@datahub/data-models/types/entity/facets';
|
|
import { ISearchEntityRenderProps } from '@datahub/data-models/types/search/search-entity-render-prop';
|
|
import { KeyNamesWithValueType } from '@datahub/utils/types/base';
|
|
|
|
/**
|
|
* Filtering field names that returns array
|
|
*/
|
|
type FieldNames = KeyNamesWithValueType<ISearchEntityRenderProps, Array<string> | undefined>;
|
|
|
|
/**
|
|
* returns key/value pairs depending on key of field
|
|
* @param fields
|
|
* @param filterField
|
|
*/
|
|
const facetFilter = (
|
|
fields: Array<ISearchEntityRenderProps>,
|
|
filterField: FieldNames
|
|
): Record<string, Array<string>> => {
|
|
return fields.reduce((facetsApiParams: Record<string, Array<string>>, field): Record<string, Array<string>> => {
|
|
if (filterField && typeOf(field[filterField]) !== 'undefined') {
|
|
return {
|
|
...facetsApiParams,
|
|
[field.fieldName]: field[filterField] || []
|
|
};
|
|
}
|
|
return facetsApiParams;
|
|
}, {});
|
|
};
|
|
|
|
/**
|
|
* Will return an key value object with forced facets given a list of fields
|
|
*/
|
|
export const getFacetForcedValueForEntity = (fields: Array<ISearchEntityRenderProps>): Record<string, Array<string>> =>
|
|
facetFilter(fields, 'forcedFacetValue');
|
|
|
|
/**
|
|
* Will return an key value object with deafult facets given a list of fields
|
|
*/
|
|
export const getFacetDefaultValueForEntity = (fields: Array<ISearchEntityRenderProps>): Record<string, Array<string>> =>
|
|
facetFilter(fields, 'facetDefaultValue');
|
|
|
|
/**
|
|
* Transforms an input like this:
|
|
* {
|
|
* status: ['PUBLISHED']
|
|
* }
|
|
*
|
|
* into this:
|
|
* {
|
|
* status: {
|
|
* PUBLISHED: true
|
|
* }
|
|
* }
|
|
*
|
|
* This is useful to transform default facets into a string
|
|
* @param defaults
|
|
*/
|
|
export const transformDefaultsIntoSelections = (defaults: Record<string, Array<string>>): IFacetsSelectionsMap =>
|
|
Object.keys(defaults).reduce((selections: IFacetsSelectionsMap, facetKey: string): IFacetsSelectionsMap => {
|
|
const values = defaults[facetKey];
|
|
return {
|
|
...selections,
|
|
[facetKey]: values.reduce(
|
|
(selection: IFacetSelections, value: string): IFacetSelections => ({ ...selection, [value]: true }),
|
|
{}
|
|
)
|
|
};
|
|
}, {});
|