Skip to content

Commit da6ace1

Browse files
130424: Fix validation on the edit metadata tab sometimes wrongly displaying an error message
This only happens when the request that validates the metadata field doesn't return the field with qualifier null on the first page
1 parent 404ccd9 commit da6ace1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/app/dso-shared/dso-edit-metadata/metadata-field-selector/metadata-field-selector.component.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ describe('MetadataFieldSelectorComponent', () => {
105105
});
106106
});
107107

108+
it('should sort the fields by name to ensure the one without a qualifier is first', () => {
109+
component.mdField = 'dc.relation';
110+
111+
component.validate();
112+
113+
expect(registryService.queryMetadataFields).toHaveBeenCalledWith('dc.relation', { elementsPerPage: 10, sort: new SortOptions('fieldName', SortDirection.ASC) }, true, false, followLink('schema'));
114+
});
115+
108116
describe('when querying the metadata fields returns an error response', () => {
109117
beforeEach(() => {
110118
(registryService.queryMetadataFields as jasmine.Spy).and.returnValue(createFailedRemoteDataObject$('Failed'));

src/app/dso-shared/dso-edit-metadata/metadata-field-selector/metadata-field-selector.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { of } from 'rxjs/internal/observable/of';
2626
import { NotificationsService } from '../../../shared/notifications/notifications.service';
2727
import { TranslateService } from '@ngx-translate/core';
2828
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
29+
import { FindListOptions } from '../../../core/data/find-list-options.model';
2930

3031
@Component({
3132
selector: 'ds-metadata-field-selector',
@@ -97,6 +98,11 @@ export class MetadataFieldSelectorComponent implements OnInit, OnDestroy, AfterV
9798
*/
9899
showInvalid = false;
99100

101+
searchOptions: FindListOptions = {
102+
elementsPerPage: 10,
103+
sort: new SortOptions('fieldName', SortDirection.ASC),
104+
};
105+
100106
/**
101107
* Subscriptions to unsubscribe from on destroy
102108
*/
@@ -129,7 +135,7 @@ export class MetadataFieldSelectorComponent implements OnInit, OnDestroy, AfterV
129135
switchMap((query: string) => {
130136
this.showInvalid = false;
131137
if (query !== null) {
132-
return this.registryService.queryMetadataFields(query, { elementsPerPage: 10, sort: new SortOptions('fieldName', SortDirection.ASC) }, true, false, followLink('schema')).pipe(
138+
return this.registryService.queryMetadataFields(query, this.searchOptions, true, false, followLink('schema')).pipe(
133139
getAllSucceededRemoteData(),
134140
metadataFieldsToString(),
135141
);
@@ -154,7 +160,7 @@ export class MetadataFieldSelectorComponent implements OnInit, OnDestroy, AfterV
154160
* Upon subscribing to the returned observable, the showInvalid flag is updated accordingly to show the feedback under the input
155161
*/
156162
validate(): Observable<boolean> {
157-
return this.registryService.queryMetadataFields(this.mdField, null, true, false, followLink('schema')).pipe(
163+
return this.registryService.queryMetadataFields(this.mdField, this.searchOptions, true, false, followLink('schema')).pipe(
158164
getFirstCompletedRemoteData(),
159165
switchMap((rd) => {
160166
if (rd.hasSucceeded) {

0 commit comments

Comments
 (0)