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

75 lines
2.8 KiB
TypeScript

import { TestPersonEntity } from '@datahub/data-models/mirage-addon/test-helpers/test-entities/test-person-entity';
import {
IDataModelEntity,
DataModelEntity,
DataModelName,
DataModelEntityInstance
} from '@datahub/data-models/constants/entity';
import { PersonEntity } from '@datahub/data-models/entity/person/person-entity';
import DataModelsService from '@datahub/data-models/services/data-models';
/**
* Maps DataModelEntity to our test entities instead where applicable
*/
interface ITestDataModelEntity extends IDataModelEntity {
[PersonEntity.displayName]: typeof TestPersonEntity;
}
/**
* Overrides the map of DataModelEntity with our own mapping to test versions of the entities
* (where necessary)
*/
export const TestDataModelEntity: ITestDataModelEntity = {
...DataModelEntity,
[PersonEntity.displayName]: TestPersonEntity
};
/**
* Because the open source data models entities can sometimes be too generic, we will want to be
* able to provide some implementation to the class definitions in order to test certain
* behaviors that rely on those implementations. In order to do so, we create "test entities" that
* extend from the open source versions of the entities that provide these implementations. These
* test entities can also provide an example of how an adopter of DataHub can define their own
* entity implementations.
*
* Since we have these entities, the data models service sometimes needs to be mapped to the test
* entities instead of the open source entities. We create this extended service to apply that map
* instead and can be stubbed in place of the regular service when needed
*/
export default class TestDataModelsService extends DataModelsService {
/**
* Overrides dataModelEntitiesMapping with a mapping to our test entities instead
*/
dataModelEntitiesMap = TestDataModelEntity;
/**
* Overrides getModel with the map to our test entities instead
*/
getModel<K extends DataModelName>(modelKey: K): typeof TestDataModelEntity[K] {
return TestDataModelEntity[modelKey];
}
/**
* Overrides createInstance with our typings for testing instances
*/
createInstance<K extends DataModelName>(
modelKey: K,
urn: string
): Promise<InstanceType<typeof TestDataModelEntity[K]>> {
return super.createInstance(modelKey as DataModelName, urn) as Promise<InstanceType<typeof TestDataModelEntity[K]>>;
}
/**
* Overrides open source generic method wih our specific test entity typings
*/
createPartialInstance<K extends DataModelName>(
modelName: K,
data: DataModelEntityInstance['entity'] | string
): InstanceType<typeof TestDataModelEntity[K]> {
return super.createPartialInstance(
modelName as DataModelName,
data as DataModelEntityInstance['entity']
) as InstanceType<typeof TestDataModelEntity[K]>;
}
}