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

96 lines
3.1 KiB
TypeScript

import { computed } from '@ember/object';
import { map } from '@ember/object/computed';
/**
* Provides an interface over the Com.Linkedin.Common.Health metadata instance,
* and additional functionality over related values
* @export
* @class HealthProxy
*/
export default class HealthProxy {
/**
* Label text providing a quick description for the Health Score feature
* @static
*/
static descriptiveLabel =
'Health Score is a numeric value computed by applying different quality and usability rules on this data entity';
/**
* Label text providing a description or help for the health score recalculation
* @static
*/
static descriptiveScoreRecalculationLabel =
'The Health Score is recalculated automatically every 24 hours. You can also, if needed, manually recalculate the score for this data entity';
/**
* The Regular Expression object for pattern matching validators
* @readonly
* @static
*/
static get validatorRegExp(): RegExp {
return new RegExp(/validator/, 'gi');
}
/**
* Method to convert a number into a percentage value
* @private
* @param {Com.Linkedin.Common.HealthValidation['score']} score
*/
private scoreAsPercent(score: Com.Linkedin.Common.HealthValidation['score']): number {
return parseInt((score * 100).toFixed(), 10);
}
/**
* Parses the validator as a string that is more user friendly / readable
* @private
* @param {Com.Linkedin.Common.HealthValidation['validator']} validator
*/
private humanReadableValidator(validator: Com.Linkedin.Common.HealthValidation['validator']): string {
// The validator is expected to be a dot delimited string, the last string in the sequence is expected to be
// the human readable name for the validator, this may be suffixed with validatorRegExp, so we replace that
const lastStringInDotDelimitedSequence = validator.split('.').pop() || '';
return lastStringInDotDelimitedSequence.replace(HealthProxy.validatorRegExp, () => '');
}
/**
* Attempts to map the Health score number into a percentage value or null otherwise
* @readonly
*/
@computed('health.score')
get score(): string | null {
const score = this.health?.score;
// score can be 0
return typeof score === 'number' ? String(this.scoreAsPercent(score)) : null;
}
/**
* References the timestamp when the score was last updated
* @readonly
*/
@computed('health.created')
get lastUpdated(): number | undefined {
return this.health?.created?.time;
}
/**
* Maps the validator with a score percent and a validator value
*/
@map('health.validations', function(
this: HealthProxy,
validation: Com.Linkedin.Common.HealthValidation
): Com.Linkedin.Common.HealthValidation {
return {
...validation,
score: this.scoreAsPercent(validation.score),
validator: this.humanReadableValidator(validation.validator)
};
})
validations!: Com.Linkedin.Common.Health['validations'];
/**
* Creates an instance of HealthProxy.
* @param {(Com.Linkedin.Common.Health | null)} [health] the instance of the Health metadata
*/
constructor(readonly health?: Com.Linkedin.Common.Health | null) {}
}