Skip to content

Commit be3dbd6

Browse files
authored
Merge pull request #4340 from alexandrevryghem/w2p-130424_impossible-to-add-new-values-for-fields-without-qualifiers_contribute-main
Fix unqualified metadata field validation in Edit Metadata tab by sorting fields in validation request
2 parents f277832 + 15f96f3 commit be3dbd6

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
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
@@ -116,6 +116,14 @@ describe('MetadataFieldSelectorComponent', () => {
116116
});
117117
});
118118

119+
it('should sort the fields by name to ensure the one without a qualifier is first', () => {
120+
component.mdField = 'dc.relation';
121+
122+
component.validate();
123+
124+
expect(registryService.queryMetadataFields).toHaveBeenCalledWith('dc.relation', { elementsPerPage: 20, sort: new SortOptions('fieldName', SortDirection.ASC), currentPage: 1 }, true, false, followLink('schema'));
125+
});
126+
119127
describe('when querying the metadata fields returns an error response', () => {
120128
beforeEach(() => {
121129
(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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
SortDirection,
4444
SortOptions,
4545
} from '../../../core/cache/models/sort-options.model';
46+
import { FindListOptions } from '../../../core/data/find-list-options.model';
4647
import { RegistryService } from '../../../core/registry/registry.service';
4748
import {
4849
getAllSucceededRemoteData,
@@ -153,7 +154,10 @@ export class MetadataFieldSelectorComponent implements OnInit, OnDestroy, AfterV
153154
/**
154155
* Default page option for this feature
155156
*/
156-
pageOptions = { elementsPerPage: 20, sort: new SortOptions('fieldName', SortDirection.ASC) };
157+
pageOptions: FindListOptions = {
158+
elementsPerPage: 20,
159+
sort: new SortOptions('fieldName', SortDirection.ASC),
160+
};
157161

158162

159163
constructor(protected registryService: RegistryService,
@@ -209,7 +213,7 @@ export class MetadataFieldSelectorComponent implements OnInit, OnDestroy, AfterV
209213
* Upon subscribing to the returned observable, the showInvalid flag is updated accordingly to show the feedback under the input
210214
*/
211215
validate(): Observable<boolean> {
212-
return this.registryService.queryMetadataFields(this.mdField, null, true, false, followLink('schema')).pipe(
216+
return this.registryService.queryMetadataFields(this.mdField, Object.assign({}, this.pageOptions, { currentPage: 1 }), true, false, followLink('schema')).pipe(
213217
getFirstCompletedRemoteData(),
214218
switchMap((rd) => {
215219
if (rd.hasSucceeded) {
@@ -263,9 +267,7 @@ export class MetadataFieldSelectorComponent implements OnInit, OnDestroy, AfterV
263267
* @param useCache Whether or not to use the cache
264268
*/
265269
search(query: string, page: number, useCache: boolean = true) {
266-
return this.registryService.queryMetadataFields(query,{
267-
elementsPerPage: this.pageOptions.elementsPerPage, sort: this.pageOptions.sort,
268-
currentPage: page }, useCache, false, followLink('schema'))
270+
return this.registryService.queryMetadataFields(query, Object.assign({}, this.pageOptions, { currentPage: page }), useCache, false, followLink('schema'))
269271
.pipe(
270272
getAllSucceededRemoteData(),
271273
metadataFieldsToString(),

0 commit comments

Comments
 (0)