Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add entity name to label attribute in refs for clarity #388

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/field-types/MultiSelectFieldComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
trackBy="id"
@search-change="fetchOptions"
>
<template slot="option" slot-scope="props">
<div :title="`from entity: ${props.option.entity}`"><span class="option__title">{{ props.option.label || props.option.value }}</span></div>
</template>
<template slot="clear">
<button class="multiselect__clear" name="Clear All Values" @click.prevent="clearValue"></button>
</template>
Expand Down
3 changes: 3 additions & 0 deletions src/components/field-types/SingleSelectFieldComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
label="label"
trackBy="id"
@search-change="fetchOptions">
<template slot="option" slot-scope="props">
<div :title="`from entity: ${props.option.entity}`"><span class="option__title">{{ props.option.label || props.option.value }}</span></div>
</template>
<template slot="clear">
<button class="multiselect__clear" name="Clear All Values" @click.prevent="clearValue"></button>
</template>
Expand Down
11 changes: 6 additions & 5 deletions src/util/EntityToFormMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ 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<string>): Promise<Array<FieldOption>> => {
const fetchFieldOptions = (refEntity: RefEntityType, search: ?string | ?Array<string>, entityMetadata: ?any): Promise<Array<FieldOption>> => {
const uri = buildRefOptionsQuery(refEntity, search)

const itemToOption = (item) => ({
id: item[refEntity.idAttribute],
value: item[refEntity.idAttribute],
label: item[refEntityLabelAttribute(refEntity)]
label: item[refEntityLabelAttribute(refEntity)],
entity: entityMetadata && entityMetadata.name ? entityMetadata.name : ''
})

if (refOptionsCache[uri]) {
Expand Down Expand Up @@ -141,9 +142,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<Array<FieldOption>>) => {
const getFieldOptions = (attribute, entityMetadata:any, options: MapperSettings): ?(() => Promise<Array<FieldOption>>) => {
const fetchOptionsFunction = (search: ?string | Array<string>): Promise<Array<FieldOption>> => {
return fetchFieldOptions(attribute.refEntity, search).then(response => {
return fetchFieldOptions(attribute.refEntity, search, entityMetadata).then(response => {
return response
})
}
Expand Down Expand Up @@ -334,7 +335,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,
Expand Down
38 changes: 19 additions & 19 deletions test/unit/specs/util/EntityToFormMapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '' }
])
})

Expand Down Expand Up @@ -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()
})
Expand Down Expand Up @@ -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()
})
Expand All @@ -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()
})
Expand Down Expand Up @@ -812,17 +812,17 @@ 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)
})

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()
})
Expand Down Expand Up @@ -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()
})
Expand Down