[MNT-24698] Concatenate aspect name to the title when there are duplicated aspect titles (#10374)

* [MNT-24698] Concatenate aspect name to title when there are duplicated titles

* [MNT-24698] Added validation to check if name should be concatenated

* [MNT-24698] Add unit test

* [MNT-24698] Distinguish aspect without title from other aspect with title equals to its name
This commit is contained in:
Tiago Salvado
2024-11-12 15:00:03 +00:00
committed by GitHub
parent 3111008044
commit 9520b2a4e5
2 changed files with 99 additions and 16 deletions

View File

@@ -18,11 +18,12 @@
import { AppConfigService } from '@alfresco/adf-core'; import { AppConfigService } from '@alfresco/adf-core';
import { ClassesApi, Node } from '@alfresco/js-api'; import { ClassesApi, Node } from '@alfresco/js-api';
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { ContentMetadataService } from './content-metadata.service';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { PropertyGroup } from '../interfaces/property-group.interface';
import { ContentTypePropertiesService } from './content-type-property.service';
import { ContentTestingModule } from '../../testing/content.testing.module'; import { ContentTestingModule } from '../../testing/content.testing.module';
import { OrganisedPropertyGroup } from '../interfaces/content-metadata.interfaces';
import { PropertyGroup } from '../interfaces/property-group.interface';
import { ContentMetadataService } from './content-metadata.service';
import { ContentTypePropertiesService } from './content-type-property.service';
import { PropertyDescriptorsService } from './property-descriptors.service'; import { PropertyDescriptorsService } from './property-descriptors.service';
const fakeNode: Node = { const fakeNode: Node = {
@@ -130,6 +131,62 @@ describe('ContentMetaDataService', () => {
} }
}; };
const aspect1Group: OrganisedPropertyGroup = {
name: 'test:aspect1',
title: 'Test Aspect',
properties: [
{
title: 'Property 1',
name: 'test:property1',
dataType: 'd:text',
mandatory: false,
multiValued: false
}
]
};
const aspect2Group: OrganisedPropertyGroup = {
name: 'test:aspect2',
title: 'Test Aspect',
properties: [
{
title: 'Property 2',
name: 'test:property2',
dataType: 'd:text',
mandatory: false,
multiValued: false
}
]
};
const aspect3Group: OrganisedPropertyGroup = {
name: 'test:aspect3',
title: undefined,
properties: [
{
title: 'Property 3',
name: 'test:property3',
dataType: 'd:text',
mandatory: false,
multiValued: false
}
]
};
const aspect4Group: OrganisedPropertyGroup = {
name: 'test:aspect4',
title: 'test:aspect3',
properties: [
{
title: 'Property 4',
name: 'test:property4',
dataType: 'd:text',
mandatory: false,
multiValued: false
}
]
};
const setConfig = (presetName, presetConfig) => { const setConfig = (presetName, presetConfig) => {
appConfig.config['content-metadata'] = { appConfig.config['content-metadata'] = {
presets: { presets: {
@@ -176,6 +233,20 @@ describe('ContentMetaDataService', () => {
}); });
}); });
it('should distinguish aspects with same title', () => {
const groupedProperties = service.setTitleToNameIfNotSet([aspect1Group, aspect2Group]);
expect(groupedProperties.length).toEqual(2);
expect(groupedProperties[0].title).toEqual('Test Aspect');
expect(groupedProperties[1].title).toEqual('Test Aspect (test:aspect2)');
});
it('should distinguish aspect without title from other aspect with title equals to its name', () => {
const groupedProperties = service.setTitleToNameIfNotSet([aspect3Group, aspect4Group]);
expect(groupedProperties.length).toEqual(2);
expect(groupedProperties[0].title).toEqual('test:aspect3');
expect(groupedProperties[1].title).toEqual('test:aspect3 (test:aspect4)');
});
describe('AspectOriented preset', () => { describe('AspectOriented preset', () => {
it('should return response with exif property', async () => { it('should return response with exif property', async () => {
setConfig('default', { 'exif:exif': '*' }); setConfig('default', { 'exif:exif': '*' });

View File

@@ -30,15 +30,15 @@ import { ContentTypePropertiesService } from './content-type-property.service';
providedIn: 'root' providedIn: 'root'
}) })
export class ContentMetadataService { export class ContentMetadataService {
error = new Subject<{ statusCode: number; message: string }>(); error = new Subject<{ statusCode: number; message: string }>();
constructor(private basicPropertiesService: BasicPropertiesService, constructor(
private contentMetadataConfigFactory: ContentMetadataConfigFactory, private basicPropertiesService: BasicPropertiesService,
private propertyGroupTranslatorService: PropertyGroupTranslatorService, private contentMetadataConfigFactory: ContentMetadataConfigFactory,
private propertyDescriptorsService: PropertyDescriptorsService, private propertyGroupTranslatorService: PropertyGroupTranslatorService,
private contentTypePropertyService: ContentTypePropertiesService) { private propertyDescriptorsService: PropertyDescriptorsService,
} private contentTypePropertyService: ContentTypePropertiesService
) {}
getBasicProperties(node: Node): Observable<CardViewItem[]> { getBasicProperties(node: Node): Observable<CardViewItem[]> {
return of(this.basicPropertiesService.getProperties(node)); return of(this.basicPropertiesService.getProperties(node));
@@ -63,9 +63,7 @@ export class ContentMetadataService {
contentMetadataConfig = this.contentMetadataConfigFactory.createConfig(preset); contentMetadataConfig = this.contentMetadataConfigFactory.createConfig(preset);
} }
const groupNames = node.aspectNames const groupNames = node.aspectNames.concat(node.nodeType).filter((groupName) => contentMetadataConfig.isGroupAllowed(groupName));
.concat(node.nodeType)
.filter((groupName) => contentMetadataConfig.isGroupAllowed(groupName));
if (groupNames.length > 0) { if (groupNames.length > 0) {
groupedProperties = this.propertyDescriptorsService.load(groupNames).pipe( groupedProperties = this.propertyDescriptorsService.load(groupNames).pipe(
@@ -74,7 +72,8 @@ export class ContentMetadataService {
() => contentMetadataConfig.isIncludeAllEnabled(), () => contentMetadataConfig.isIncludeAllEnabled(),
of(contentMetadataConfig.appendAllPreset(groups).concat(contentMetadataConfig.reorganiseByConfig(groups))), of(contentMetadataConfig.appendAllPreset(groups).concat(contentMetadataConfig.reorganiseByConfig(groups))),
of(contentMetadataConfig.reorganiseByConfig(groups)) of(contentMetadataConfig.reorganiseByConfig(groups))
)), )
),
map((groups) => contentMetadataConfig.filterExcludedPreset(groups)), map((groups) => contentMetadataConfig.filterExcludedPreset(groups)),
map((groups) => this.filterEmptyPreset(groups)), map((groups) => this.filterEmptyPreset(groups)),
map((groups) => this.setTitleToNameIfNotSet(groups)), map((groups) => this.setTitleToNameIfNotSet(groups)),
@@ -87,13 +86,26 @@ export class ContentMetadataService {
} }
setTitleToNameIfNotSet(propertyGroups: OrganisedPropertyGroup[]): OrganisedPropertyGroup[] { setTitleToNameIfNotSet(propertyGroups: OrganisedPropertyGroup[]): OrganisedPropertyGroup[] {
const propertyGroupsTitles = [];
propertyGroups.map((propertyGroup) => { propertyGroups.map((propertyGroup) => {
propertyGroup.title = propertyGroup.title || propertyGroup.name; const title = propertyGroup.title;
const name = propertyGroup.name;
if (title) {
if (propertyGroupsTitles.includes(title)) {
propertyGroup.title = name ? `${title} (${name})` : title;
} else {
propertyGroup.title = title;
}
propertyGroupsTitles.push(title);
} else {
propertyGroup.title = name;
propertyGroupsTitles.push(name);
}
}); });
return propertyGroups; return propertyGroups;
} }
filterEmptyPreset(propertyGroups: OrganisedPropertyGroup[]): OrganisedPropertyGroup[] { filterEmptyPreset(propertyGroups: OrganisedPropertyGroup[]): OrganisedPropertyGroup[] {
return propertyGroups.filter((props) => props.properties.length); return propertyGroups.filter((props) => props.properties.length);
} }
} }