mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-10-08 14:51:32 +00:00
[ACS-8001] move isDefined to object-utils
This commit is contained in:
committed by
Mykyta Maliarchuk
parent
1e79753ad0
commit
e359e5fbea
@@ -18,7 +18,6 @@
|
||||
import { ObjectUtils } from './object-utils';
|
||||
|
||||
describe('ObjectUtils', () => {
|
||||
|
||||
it('should get top level property value', () => {
|
||||
const obj = {
|
||||
id: 1
|
||||
@@ -246,4 +245,19 @@ describe('ObjectUtils', () => {
|
||||
expect(ObjectUtils.booleanPrettify(obj, enhancer)).toBe('✅ testOnetest\n❌ testTwotest');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isValueDefined', () => {
|
||||
it('should return true for defined values', () => {
|
||||
expect(ObjectUtils.isValueDefined(0)).toBe(true);
|
||||
expect(ObjectUtils.isValueDefined('')).toBe(true);
|
||||
expect(ObjectUtils.isValueDefined([])).toBe(true);
|
||||
expect(ObjectUtils.isValueDefined({})).toBe(true);
|
||||
expect(ObjectUtils.isValueDefined(false)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for undefined or null values', () => {
|
||||
expect(ObjectUtils.isValueDefined(undefined)).toBe(false);
|
||||
expect(ObjectUtils.isValueDefined(null)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -25,7 +25,6 @@ export class ObjectUtils {
|
||||
* @returns object property value
|
||||
*/
|
||||
static getValue(target: any, key: string): any {
|
||||
|
||||
if (!target || !key) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -80,37 +79,29 @@ export class ObjectUtils {
|
||||
}
|
||||
|
||||
static isBooleanObject(target: any): boolean {
|
||||
return Object.values(target).every(value => typeof value === 'boolean');
|
||||
return Object.values(target).every((value) => typeof value === 'boolean');
|
||||
}
|
||||
|
||||
static booleanPrettify(target: any, enhancer?: (param: string) => string): string {
|
||||
|
||||
if (
|
||||
!target ||
|
||||
ObjectUtils.isEmpty(target) ||
|
||||
!ObjectUtils.isBooleanObject(target)
|
||||
) {
|
||||
if (!target || ObjectUtils.isEmpty(target) || !ObjectUtils.isBooleanObject(target)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (
|
||||
!ObjectUtils.isObject(target) ||
|
||||
!ObjectUtils.hasKeys(target)
|
||||
) {
|
||||
if (!ObjectUtils.isObject(target) || !ObjectUtils.hasKeys(target)) {
|
||||
return target.toString();
|
||||
}
|
||||
|
||||
const greenBorderWhiteCheckSymbol = '✅';
|
||||
const redCrossSymbol = '❌';
|
||||
|
||||
target = Object.keys(target).map((key) => {
|
||||
target = Object.keys(target)
|
||||
.map((key) => {
|
||||
if (target[key]) {
|
||||
if (enhancer) {
|
||||
return `${greenBorderWhiteCheckSymbol} ${enhancer(key)}`;
|
||||
} else {
|
||||
return `${greenBorderWhiteCheckSymbol} ${key}`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (enhancer) {
|
||||
@@ -118,9 +109,13 @@ export class ObjectUtils {
|
||||
} else {
|
||||
return `${redCrossSymbol} ${key}`;
|
||||
}
|
||||
|
||||
}).join('\n');
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
static isValueDefined(value: any): boolean {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ import { Prediction, ReviewStatus } from '@alfresco/js-api';
|
||||
import { IconComponent } from '../../../icon';
|
||||
import { LocalizedDatePipe } from '../../../pipes';
|
||||
import { PredictionService } from '../../services';
|
||||
import { ObjectUtils } from '../../../common';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
@@ -65,8 +66,8 @@ export class ContentEnrichmentMenuComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.confidencePercentage = this.prediction?.confidenceLevel * 100 || 0;
|
||||
this.previousValue = this.isDefined(this.prediction?.previousValue) ? this.prediction.previousValue : '';
|
||||
this.predictionValue = this.isDefined(this.prediction?.predictionValue) ? this.prediction.predictionValue : '';
|
||||
this.previousValue = ObjectUtils.isValueDefined(this.prediction?.previousValue) ? this.prediction.previousValue : '';
|
||||
this.predictionValue = ObjectUtils.isValueDefined(this.prediction?.predictionValue) ? this.prediction.predictionValue : '';
|
||||
this.predictionDateTime = this.prediction?.predictionDateTime || null;
|
||||
}
|
||||
|
||||
@@ -94,8 +95,4 @@ export class ContentEnrichmentMenuComponent implements OnInit {
|
||||
this.focusTrap.destroy();
|
||||
this.focusTrap = null;
|
||||
}
|
||||
|
||||
private isDefined(value: any): boolean {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user