Skip to content

Commit

Permalink
Merge 8381146 into 0f0a4d7
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOtherDude authored Dec 8, 2017
2 parents 0f0a4d7 + 8381146 commit 7ae52f2
Show file tree
Hide file tree
Showing 3 changed files with 2,487 additions and 3 deletions.
23 changes: 20 additions & 3 deletions addon/list-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,16 @@ export function getItemsFromEmberData ({value, modelDef, data, bunsenId, store,
const modelType = modelDef.modelType || 'resources'
const {labelAttribute, queryForCurrentValue, valueAttribute} = modelDef
const valueAsId = get(value, bunsenId)
const actuallyFindCurrentValue = keepCurrentValue && queryForCurrentValue && valueAsId !== undefined
let arrayValues
if (isArray(valueAsId) && queryForCurrentValue) {
arrayValues = valueAsId.asMutable() // frost-multi-select does not support immutable values
arrayValues = RSVP.Promise.all(arrayValues.map((id) => store.findRecord(modelType, id)))
.catch((err) => {
Logger.log(`Error fetching ${modelType}`, err)
throw err
})
}
const actuallyFindCurrentValue = keepCurrentValue && queryForCurrentValue && valueAsId !== undefined && !arrayValues

const query = getQuery({
bunsenId,
Expand All @@ -166,13 +175,21 @@ export function getItemsFromEmberData ({value, modelDef, data, bunsenId, store,
.catch((err) => {
Logger.log(`Error fetching ${modelType}`, err)
throw err
}) : RSVP.resolve(null)
}) : RSVP.resolve(null),
arrayRecords: arrayValues || RSVP.resolve(null)
})
.then(({items, valueRecord}) => {
.then(({arrayRecords, items, valueRecord}) => {
if (actuallyFindCurrentValue &&
shouldAddCurrentValue({items, valueRecord, labelAttribute, valueAttribute, filter})) {
return normalizeItems({data: items, labelAttribute, records: [valueRecord], valueAttribute})
}

if (arrayRecords) {
const recordsToAdd = arrayRecords.filter(record => {
return shouldAddCurrentValue({items, valueRecord: record, labelAttribute, valueAttribute, filter})
})
return normalizeItems({data: items, labelAttribute, records: recordsToAdd, valueAttribute})
}
return items
})
}
Expand Down
Loading

0 comments on commit 7ae52f2

Please sign in to comment.