Skip to content

Commit 8c6a0a6

Browse files
Andrea Barbassovins01-4science
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-2298 (pull request DSpace#3047)
[DSC-2298] remove whitespaces by default in identifier links Approved-by: Francesco Molinaro
2 parents ba3a27f + a95c925 commit 8c6a0a6

6 files changed

Lines changed: 48 additions & 4 deletions

File tree

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/identifier/identifier.component.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { LayoutField } from '../../../../../../../core/layout/models/box.model';
1111
import { MetadataValue } from '../../../../../../../core/shared/metadata.models';
1212
import { FieldRenderingType } from '../metadata-box.decorator';
1313
import { ResolverStrategyService } from '../../../../../../services/resolver-strategy.service';
14+
import { APP_CONFIG } from '../../../../../../../../config/app-config.interface';
15+
import { environment } from '../../../../../../../../environments/environment';
1416

1517
describe('IdentifierComponent', () => {
1618
let component: IdentifierComponent;
@@ -84,7 +86,8 @@ describe('IdentifierComponent', () => {
8486
{ provide: 'metadataValueProvider', useValue: doiMetadataValueWithoutSubType },
8587
{ provide: 'renderingSubTypeProvider', useValue: '' },
8688
{ provide: 'tabNameProvider', useValue: '' },
87-
{ provide: ResolverStrategyService, useClass: ResolverStrategyService }
89+
{ provide: ResolverStrategyService, useClass: ResolverStrategyService },
90+
{ provide: APP_CONFIG, useValue: environment }
8891
],
8992
declarations: [IdentifierComponent]
9093
})
@@ -223,4 +226,18 @@ describe('IdentifierComponent', () => {
223226
});
224227
});
225228

229+
it('should keep white space in metadata value if shouldKeepWhiteSpaces is true', () => {
230+
expect(component.composeLink('keep my white spaces', 'keepMyWhiteSpaces')).toEqual({
231+
href: 'https://keepmywhitespaces.com/keep my white spaces',
232+
text: 'keep my white spaces'
233+
});
234+
});
235+
236+
it('should not keep white space in metadata value if shouldKeepWhiteSpaces is false', () => {
237+
expect(component.composeLink('do not keep my white spaces', 'doi')).toEqual({
238+
href: 'https://doi.org/donotkeepmywhitespaces',
239+
text: 'do not keep my white spaces'
240+
});
241+
});
242+
226243
});

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/identifier/identifier.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ export class IdentifierComponent extends RenderingTypeValueModelComponent implem
139139
if (metadataValue.startsWith(rep)) {
140140
value = metadataValue.replace(rep, '');
141141
}
142-
const href = this.resolver.getBaseUrl(urn) + value;
142+
const shouldKeepWhiteSpaces = environment.crisLayout
143+
.urn?.find((urnConfig) => urnConfig.name === urn)?.shouldKeepWhiteSpaces;
144+
const href = this.resolver.getBaseUrl(urn) + (shouldKeepWhiteSpaces ? value : value.replace(/\s/g, ''));
143145
return this.createMetadataLinkValue(href, value);
144146
}
145147

src/app/shared/object-list/search-result-list-element/additional-metadata/additional-metadata.component.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { AdditionalMetadataComponent } from './additional-metadata.component';
44
import { Item } from '../../../../core/shared/item.model';
55
import { VocabularyService } from '../../../../core/submission/vocabularies/vocabulary.service';
66
import { VocabularyServiceStub } from '../../../testing/vocabulary-service.stub';
7+
import { APP_CONFIG } from '../../../../../config/app-config.interface';
8+
import { environment } from '../../../../../environments/environment';
79

810
describe('AdditionalMetadataComponent', () => {
911
let component: AdditionalMetadataComponent;
@@ -24,7 +26,8 @@ describe('AdditionalMetadataComponent', () => {
2426
await TestBed.configureTestingModule({
2527
declarations: [ AdditionalMetadataComponent ],
2628
providers: [
27-
{ provide: VocabularyService, useValue: new VocabularyServiceStub() }
29+
{ provide: VocabularyService, useValue: new VocabularyServiceStub() },
30+
{ provide: APP_CONFIG, useValue: environment }
2831
],
2932
})
3033
.compileComponents();
@@ -40,4 +43,18 @@ describe('AdditionalMetadataComponent', () => {
4043
it('should create', () => {
4144
expect(component).toBeTruthy();
4245
});
46+
47+
it('should keep white space in metadata value if shouldKeepWhiteSpaces is true', () => {
48+
expect(component.composeLink('keep my white spaces', 'keepMyWhiteSpaces')).toEqual({
49+
href: 'https://keepmywhitespaces.com/keep my white spaces',
50+
text: 'keep my white spaces'
51+
});
52+
});
53+
54+
it('should not keep white space in metadata value if shouldKeepWhiteSpaces is false', () => {
55+
expect(component.composeLink('do not keep my white spaces', 'doi')).toEqual({
56+
href: 'https://doi.org/donotkeepmywhitespaces',
57+
text: 'do not keep my white spaces'
58+
});
59+
});
4360
});

src/app/shared/object-list/search-result-list-element/additional-metadata/additional-metadata.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ export class AdditionalMetadataComponent implements OnInit {
130130
if (metadataValue.startsWith(rep)) {
131131
value = metadataValue.replace(rep, '');
132132
}
133-
const href = this.resolver.getBaseUrl(urn) + value;
133+
const shouldKeepWhiteSpaces = environment.crisLayout
134+
.urn?.find((urnConfig) => urnConfig.name === urn)?.shouldKeepWhiteSpaces;
135+
const href = this.resolver.getBaseUrl(urn) + (shouldKeepWhiteSpaces ? value : value.replace(/\s/g, ''));
134136
const text = isNotEmpty(value) && value !== '' ? value : href;
135137
return {
136138
href,

src/config/layout-config.interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Config } from './config.interface';
33
export interface UrnConfig extends Config {
44
name: string;
55
baseUrl: string;
6+
shouldKeepWhiteSpaces?: boolean;
67
}
78

89
export interface CrisRefEntityStyleConfig extends Config {

src/environments/environment.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ export const environment: BuildConfig = {
389389
name: 'doi',
390390
baseUrl: 'https://doi.org/'
391391
},
392+
{
393+
name: 'keepMyWhiteSpaces',
394+
baseUrl: 'https://keepmywhitespaces.com/',
395+
shouldKeepWhiteSpaces: true
396+
},
392397
{
393398
name: 'hdl',
394399
baseUrl: 'https://hdl.handle.net/'

0 commit comments

Comments
 (0)