From b102e87eb1c1d3458d202c6650288c5c3b1f30a4 Mon Sep 17 00:00:00 2001 From: Jelmer Veen Date: Tue, 16 Nov 2021 12:15:43 +0100 Subject: [PATCH 1/3] fix: add entity names if they are present --- src/util/EntityToFormMapper.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/EntityToFormMapper.js b/src/util/EntityToFormMapper.js index 7b0d9763..50d07e7f 100644 --- a/src/util/EntityToFormMapper.js +++ b/src/util/EntityToFormMapper.js @@ -69,13 +69,13 @@ const buildRefOptionsQuery = (refEntity: RefEntityType, search: ?string | ?Array * @param search An optional search query used to filter the items of the response * @return {Promise} Promise object representing an Array of FieldOption */ -const fetchFieldOptions = (refEntity: RefEntityType, search: ?string | ?Array): Promise> => { +const fetchFieldOptions = (refEntity: RefEntityType, search: ?string | ?Array, entityMetadata: ?any): Promise> => { const uri = buildRefOptionsQuery(refEntity, search) const itemToOption = (item) => ({ id: item[refEntity.idAttribute], value: item[refEntity.idAttribute], - label: item[refEntityLabelAttribute(refEntity)] + label: entityMetadata && entityMetadata.name ? `${item[refEntityLabelAttribute(refEntity)]} - ${entityMetadata.name}` : item[refEntityLabelAttribute(refEntity)] }) if (refOptionsCache[uri]) { @@ -141,9 +141,9 @@ const isUserAllowedAddOption = (refEntity: RefEntityType, search: ?string | ?Arr * @param options MapperOptions optional object containing options to configure mapper * @returns {Function|null} Function which returns a Promise representing an Array of FieldOptions */ -const getFieldOptions = (attribute, options: MapperSettings): ?(() => Promise>) => { +const getFieldOptions = (attribute, entityMetadata:any, options: MapperSettings): ?(() => Promise>) => { const fetchOptionsFunction = (search: ?string | Array): Promise> => { - return fetchFieldOptions(attribute.refEntity, search).then(response => { + return fetchFieldOptions(attribute.refEntity, search, entityMetadata).then(response => { return response }) } @@ -334,7 +334,7 @@ const isDisabledField = (attribute, entityMetaData, mapperOptions: MapperSetting */ const generateFormSchemaField = (attribute, entityMetadata:any, mapperOptions: MapperSettings): FormField => { // options is a function that always returns an array of option objects - const options = getFieldOptions(attribute, mapperOptions) + const options = getFieldOptions(attribute, entityMetadata, mapperOptions) const isDisabled = isDisabledField(attribute, entityMetadata, mapperOptions) let fieldProperties = { id: attribute.name, From 9df32aa42c8ef93aee2ad92046db9c5a962d34a5 Mon Sep 17 00:00:00 2001 From: Jelmer Veen Date: Tue, 16 Nov 2021 15:20:00 +0100 Subject: [PATCH 2/3] fix: use it as title to be less intrusive --- .../field-types/MultiSelectFieldComponent.vue | 3 ++ src/util/EntityToFormMapper.js | 3 +- .../specs/util/EntityToFormMapper.spec.js | 38 +++++++++---------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/components/field-types/MultiSelectFieldComponent.vue b/src/components/field-types/MultiSelectFieldComponent.vue index 8cde336e..d8acf932 100644 --- a/src/components/field-types/MultiSelectFieldComponent.vue +++ b/src/components/field-types/MultiSelectFieldComponent.vue @@ -28,6 +28,9 @@ trackBy="id" @search-change="fetchOptions" > + diff --git a/src/util/EntityToFormMapper.js b/src/util/EntityToFormMapper.js index 50d07e7f..d3746933 100644 --- a/src/util/EntityToFormMapper.js +++ b/src/util/EntityToFormMapper.js @@ -75,7 +75,8 @@ const fetchFieldOptions = (refEntity: RefEntityType, search: ?string | ?Array ({ id: item[refEntity.idAttribute], value: item[refEntity.idAttribute], - label: entityMetadata && entityMetadata.name ? `${item[refEntityLabelAttribute(refEntity)]} - ${entityMetadata.name}` : item[refEntityLabelAttribute(refEntity)] + label: item[refEntityLabelAttribute(refEntity)], + entity: entityMetadata && entityMetadata.name ? entityMetadata.name : '' }) if (refOptionsCache[uri]) { diff --git a/test/unit/specs/util/EntityToFormMapper.spec.js b/test/unit/specs/util/EntityToFormMapper.spec.js index f7d43c71..632d98ce 100644 --- a/test/unit/specs/util/EntityToFormMapper.spec.js +++ b/test/unit/specs/util/EntityToFormMapper.spec.js @@ -668,9 +668,9 @@ describe('Entity to state mapper', () => { expect(typeof field.options).to.equal('function') expect((await field.isAddOptionAllowed())).to.equal(true) expect((await field.options())).to.deep.equal([ - { id: 'ref1', value: 'ref1', label: 'ref1' }, - { id: 'ref2', value: 'ref2', label: 'ref2' }, - { id: 'ref3', value: 'ref3', label: 'ref3' } + { id: 'ref1', value: 'ref1', label: 'ref1', entity: '' }, + { id: 'ref2', value: 'ref2', label: 'ref2', entity: '' }, + { id: 'ref3', value: 'ref3', label: 'ref3', entity: '' } ]) }) @@ -726,9 +726,9 @@ describe('Entity to state mapper', () => { field.options().then(response => { expect(response).to.deep.equal([ - { id: 'ref1', value: 'ref1', label: 'label1' }, - { id: 'ref2', value: 'ref2', label: 'label2' }, - { id: 'ref3', value: 'ref3', label: 'label3' } + { id: 'ref1', value: 'ref1', label: 'label1', entity: '' }, + { id: 'ref2', value: 'ref2', label: 'label2', entity: '' }, + { id: 'ref3', value: 'ref3', label: 'label3', entity: '' } ]) done() }) @@ -763,9 +763,9 @@ describe('Entity to state mapper', () => { expect(typeof field.options).to.equal('function') field.options().then(response => { expect(response).to.deep.equal([ - { id: 'ref1', value: 'ref1', label: 'label1' }, - { id: 'ref2', value: 'ref2', label: 'label2' }, - { id: 'ref3', value: 'ref3', label: 'label3' } + { id: 'ref1', value: 'ref1', label: 'label1', entity: '' }, + { id: 'ref2', value: 'ref2', label: 'label2', entity: '' }, + { id: 'ref3', value: 'ref3', label: 'label3', entity: '' } ]) done() }) @@ -774,9 +774,9 @@ describe('Entity to state mapper', () => { it('should filter [MREF] response based on search', done => { field.options(['ref1', 'ref2', 'ref3']).then(response => { expect(response).to.deep.equal([ - { id: 'ref1', value: 'ref1', label: 'label1' }, - { id: 'ref2', value: 'ref2', label: 'label2' }, - { id: 'ref3', value: 'ref3', label: 'label3' } + { id: 'ref1', value: 'ref1', label: 'label1', entity: '' }, + { id: 'ref2', value: 'ref2', label: 'label2', entity: '' }, + { id: 'ref3', value: 'ref3', label: 'label3', entity: '' } ]) done() }) @@ -812,9 +812,9 @@ describe('Entity to state mapper', () => { expect(typeof field.options).to.equal('function') const optionsResponse = await field.options() expect(optionsResponse).to.deep.equal([ - { id: 'ref1', value: 'ref1', label: 'label1' }, - { id: 'ref2', value: 'ref2', label: 'label2' }, - { id: 'ref3', value: 'ref3', label: 'label3' } + { id: 'ref1', value: 'ref1', label: 'label1', entity: '' }, + { id: 'ref2', value: 'ref2', label: 'label2', entity: '' }, + { id: 'ref3', value: 'ref3', label: 'label3', entity: '' } ]) expect((await field.isAddOptionAllowed())).to.equal(true) }) @@ -822,7 +822,7 @@ describe('Entity to state mapper', () => { it('should filter [XREF] response based on search', done => { field.options('ref1').then(response => { expect(response).to.deep.equal([ - { id: 'ref1', value: 'ref1', label: 'label1' } + { id: 'ref1', value: 'ref1', label: 'label1', entity: '' } ]) done() }) @@ -860,9 +860,9 @@ describe('Entity to state mapper', () => { expect(typeof field.options).to.equal('function') field.options().then(response => { expect(response).to.deep.equal([ - { id: 'ref1', value: 'ref1', label: 'label1' }, - { id: 'ref2', value: 'ref2', label: 'label2' }, - { id: 'ref3', value: 'ref3', label: 'label3' } + { id: 'ref1', value: 'ref1', label: 'label1', entity: '' }, + { id: 'ref2', value: 'ref2', label: 'label2', entity: '' }, + { id: 'ref3', value: 'ref3', label: 'label3', entity: '' } ]) done() }) From 47e38d04e8c4fcc398b0c9bb0451482330af90a3 Mon Sep 17 00:00:00 2001 From: Jelmer Veen Date: Tue, 16 Nov 2021 15:29:20 +0100 Subject: [PATCH 3/3] chore: add title to xref as well --- src/components/field-types/SingleSelectFieldComponent.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/field-types/SingleSelectFieldComponent.vue b/src/components/field-types/SingleSelectFieldComponent.vue index a63bbc27..e24c656d 100644 --- a/src/components/field-types/SingleSelectFieldComponent.vue +++ b/src/components/field-types/SingleSelectFieldComponent.vue @@ -28,6 +28,9 @@ label="label" trackBy="id" @search-change="fetchOptions"> +