From 77b66a57b87c297f95d9dad0d5fbfc6a04da3040 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Sat, 26 Oct 2024 17:48:20 +0200 Subject: [PATCH] 119915: Changed the dspace.entity.type textarea with a select to prevent incorrect values --- ...-edit-metadata-entity-field.component.html | 5 +++ ...-edit-metadata-entity-field.component.scss | 0 ...it-metadata-entity-field.component.spec.ts | 32 ++++++++++++++++ ...so-edit-metadata-entity-field.component.ts | 38 +++++++++++++++++++ .../dso-edit-metadata-field-type.enum.ts | 1 + .../dso-edit-metadata-value.component.ts | 3 ++ src/app/dso-shared/dso-shared.module.ts | 2 + .../testing/entity-type-data.service.stub.ts | 19 ++++++++++ 8 files changed, 100 insertions(+) create mode 100644 src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.html create mode 100644 src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.scss create mode 100644 src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.spec.ts create mode 100644 src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.ts create mode 100644 src/app/shared/testing/entity-type-data.service.stub.ts diff --git a/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.html b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.html new file mode 100644 index 00000000000..514f3147bb5 --- /dev/null +++ b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.html @@ -0,0 +1,5 @@ + diff --git a/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.scss b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.scss new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.spec.ts b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.spec.ts new file mode 100644 index 00000000000..cb68809f713 --- /dev/null +++ b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.spec.ts @@ -0,0 +1,32 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { DsoEditMetadataEntityFieldComponent } from './dso-edit-metadata-entity-field.component'; +import { EntityTypeDataServiceStub } from '../../../../shared/testing/entity-type-data.service.stub'; +import { EntityTypeDataService } from '../../../../core/data/entity-type-data.service'; + +describe('DsoEditMetadataEntityFieldComponent', () => { + let component: DsoEditMetadataEntityFieldComponent; + let fixture: ComponentFixture; + + let entityTypeService: EntityTypeDataServiceStub; + + beforeEach(async () => { + entityTypeService = new EntityTypeDataServiceStub(); + + await TestBed.configureTestingModule({ + declarations: [ + DsoEditMetadataEntityFieldComponent, + ], + providers: [ + { provide: EntityTypeDataService, useValue: entityTypeService }, + ], + }).compileComponents(); + + fixture = TestBed.createComponent(DsoEditMetadataEntityFieldComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.ts b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.ts new file mode 100644 index 00000000000..627508b6f07 --- /dev/null +++ b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component.ts @@ -0,0 +1,38 @@ +import { Component, OnInit } from '@angular/core'; +import { editMetadataValueFieldComponent } from '../dso-edit-metadata-value-field-loader/dso-edit-metadata-value-field.decorator'; +import { EditMetadataValueFieldType } from '../dso-edit-metadata-field-type.enum'; +import { EntityTypeDataService } from '../../../../core/data/entity-type-data.service'; +import { Observable } from 'rxjs'; +import { getFirstSucceededRemoteListPayload } from '../../../../core/shared/operators'; +import { ItemType } from '../../../../core/shared/item-relationships/item-type.model'; +import { AbstractDsoEditMetadataValueFieldComponent } from '../abstract-dso-edit-metadata-value-field.component'; + +/** + * The component used to gather input for entity-type metadata fields + */ +@Component({ + selector: 'ds-dso-edit-metadata-entity-field', + templateUrl: './dso-edit-metadata-entity-field.component.html', + styleUrls: ['./dso-edit-metadata-entity-field.component.scss'], +}) +@editMetadataValueFieldComponent(EditMetadataValueFieldType.ENTITY_TYPE) +export class DsoEditMetadataEntityFieldComponent extends AbstractDsoEditMetadataValueFieldComponent implements OnInit { + + /** + * List of all the existing entity types + */ + entities$: Observable; + + constructor( + protected entityTypeService: EntityTypeDataService, + ) { + super(); + } + + ngOnInit(): void { + this.entities$ = this.entityTypeService.findAll({ elementsPerPage: 100, currentPage: 1 }).pipe( + getFirstSucceededRemoteListPayload(), + ); + } + +} diff --git a/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-field-type.enum.ts b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-field-type.enum.ts index 0f16a1b962c..5a9b3c493ef 100644 --- a/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-field-type.enum.ts +++ b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-field-type.enum.ts @@ -3,4 +3,5 @@ */ export enum EditMetadataValueFieldType { PLAIN_TEXT = 'PLAIN_TEXT', + ENTITY_TYPE = 'ENTITY_TYPE', } diff --git a/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.ts b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.ts index 9c1ca26a34f..f976a4dd47c 100644 --- a/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.ts +++ b/src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.ts @@ -146,6 +146,9 @@ export class DsoEditMetadataValueComponent implements OnInit, OnChanges { * Retrieves the {@link EditMetadataValueFieldType} to be displayed for the current field while in edit mode. */ getFieldType(): EditMetadataValueFieldType { + if (this.mdField === 'dspace.entity.type') { + return EditMetadataValueFieldType.ENTITY_TYPE; + } return EditMetadataValueFieldType.PLAIN_TEXT; } diff --git a/src/app/dso-shared/dso-shared.module.ts b/src/app/dso-shared/dso-shared.module.ts index 45536b05c43..9534c69f6c3 100644 --- a/src/app/dso-shared/dso-shared.module.ts +++ b/src/app/dso-shared/dso-shared.module.ts @@ -10,9 +10,11 @@ import { ThemedDsoEditMetadataComponent } from './dso-edit-metadata/themed-dso-e import { DsoEditMetadataValueFieldLoaderComponent } from './dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-value-field-loader/dso-edit-metadata-value-field-loader.component'; import { DsoEditMetadataTextFieldComponent } from './dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-text-field/dso-edit-metadata-text-field.component'; import { DsoEditMetadataValueFieldLoaderDirective } from './dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-value-field-loader/dso-edit-metadata-value-field-loader.directive'; +import { DsoEditMetadataEntityFieldComponent } from './dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component'; const ENTRY_COMPONENTS = [ DsoEditMetadataTextFieldComponent, + DsoEditMetadataEntityFieldComponent, ]; @NgModule({ diff --git a/src/app/shared/testing/entity-type-data.service.stub.ts b/src/app/shared/testing/entity-type-data.service.stub.ts new file mode 100644 index 00000000000..5d2cdb185de --- /dev/null +++ b/src/app/shared/testing/entity-type-data.service.stub.ts @@ -0,0 +1,19 @@ +import { FindListOptions } from '../../core/data/find-list-options.model'; +import { FollowLinkConfig } from '../utils/follow-link-config.model'; +import { ItemType } from '../../core/shared/item-relationships/item-type.model'; +import { Observable } from 'rxjs'; +import { RemoteData } from '../../core/data/remote-data'; +import { PaginatedList } from '../../core/data/paginated-list.model'; +import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils'; +import { createPaginatedList } from './utils.test'; + +/** + * Stub class {@link EntityTypeDataService} + */ +export class EntityTypeDataServiceStub { + + public findAll(_options?: FindListOptions, _useCachedVersionIfAvailable?: boolean, _reRequestOnStale?: boolean, ..._linksToFollow: FollowLinkConfig[]): Observable>> { + return createSuccessfulRemoteDataObject$(createPaginatedList()); + } + +}