Skip to content

Commit 6702e64

Browse files
committed
Fix lookups when for models containing multiple of the same type of references
1 parent ca5fc0c commit 6702e64

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/components/LookupInput.vue

+13-7
Original file line numberDiff line numberDiff line change
@@ -124,31 +124,37 @@ onMounted(async () => {
124124
: mapGet(model, refInfo.selfId)
125125
126126
const isRefType = isComplexType(refIdValue)
127+
console.log('refIdValue', refIdValue, isComplexType(refIdValue), model, refInfo)
127128
if (isRefType) {
128129
refIdValue = mapGet(model, refInfo.refId)
129130
}
130131
if (refIdValue == null)
131132
return
132133
133134
const queryOp = metadataApi.value?.operations.find(x => x.dataModel?.name == refInfo.model)
134-
//console.debug('LookupInput queryOp', queryOp)
135+
console.debug('LookupInput queryOp', queryOp)
135136
if (queryOp != null) {
136137
const propValue = mapGet(model, prop.name)
137138
if (isComplexType(propValue)) return
138139
139140
refInfoValue.value = `${propValue}`
140141
refPropertyName.value = prop.name
141142
142-
//console.debug('LookupInput refInfoValue', refInfoValue.value, refInfo.refLabel)
143+
// console.debug('refInfoValue', refInfoValue.value)
144+
// console.debug('refInfo', refInfo)
143145
if (refInfo.refLabel != null) {
144-
const colModel = typeProperties(props.metadataType).find(x => x.type == refInfo.model)
145-
if (colModel == null) {
146+
const colModels = typeProperties(props.metadataType).filter(x => x.type == refInfo.model)
147+
if (!colModels.length) {
146148
console.warn(`Could not find ${refInfo.model} Property on ${props.metadataType.name}`)
147149
}
148-
const modelValue = colModel != null ? mapGet(model, colModel.name) : null
150+
const modelValues = colModels.map(x => mapGet(model, x.name)).filter(x => !!x)
151+
const modelValue = modelValues.length <= 1
152+
? modelValues[0]
153+
: modelValues.find(x => x[refInfo.refId ?? 'id'] == refIdValue)
154+
// console.log('models', modelValue, colModels, modelValues)
149155
if (modelValue != null) {
150156
let label = mapGet(modelValue,refInfo.refLabel)
151-
//console.debug('LookupInput refInfoValue (label)', label, JSON.stringify(model), refInfo.refLabel)
157+
// console.debug('LookupInput refInfoValue (label)', label, JSON.stringify(model), refInfo.refLabel)
152158
if (label) {
153159
refInfoValue.value = `${label}`
154160
LookupValues.setValue(refInfo.model, refIdValue, refInfo.refLabel, label)
@@ -157,7 +163,7 @@ onMounted(async () => {
157163
const isComputed = prop.attributes?.some(x => x.name == 'Computed') == true
158164
let label = await LookupValues.getOrFetchValue(client, metadataApi.value!, refInfo.model, refInfo.refId, refInfo.refLabel, isComputed, refIdValue)
159165
refInfoValue.value = label ? label : `${refInfo.model}: ${refInfoValue.value}`
160-
//console.debug('LookupInput refInfoValue (!label)', refInfoValue.value)
166+
// console.debug('LookupInput refInfoValue (!label)', refInfoValue.value)
161167
}
162168
}
163169
}

0 commit comments

Comments
 (0)