|
12 | 12 | </div>
|
13 | 13 | </div>
|
14 | 14 |
|
15 |
| - <div v-if="property?.ref" class="mt-1 relative"> |
| 15 | + <div v-if="useRef" class="mt-1 relative"> |
16 | 16 | <button type="button" class="lookup flex relative w-full bg-white dark:bg-black border border-gray-300 dark:border-gray-700 rounded-md shadow-sm pl-3 pr-10 py-2 text-left focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
|
17 |
| - @click="lookup(property!.ref!)" |
| 17 | + @click="lookup(useRef!)" |
18 | 18 | aria-haspopup="listbox" aria-expanded="true" aria-labelledby="listbox-label">
|
19 | 19 | <span class="w-full inline-flex truncate">
|
20 | 20 | <span class="text-blue-700 dark:text-blue-300 flex cursor-pointer">
|
|
37 | 37 |
|
38 | 38 | <script setup lang="ts">
|
39 | 39 | import type { ApiState, InputInfo, MetadataType, RefInfo, ResponseStatus, ModalProvider, InputProp } from '@/types'
|
40 |
| -import { useConfig } from '@/use/config' |
41 |
| -import { LookupValues, typeOf, typeProperties, useMetadata } from '@/use/metadata' |
42 |
| -import { isComplexType } from '@/use/utils' |
| 40 | +import { Sole, useConfig } from '@/use/config' |
| 41 | +import { getPrimaryKey, LookupValues, typeOf, typeProperties, useMetadata } from '@/use/metadata' |
| 42 | +import { isComplexType, scopedExpr } from '@/use/utils' |
43 | 43 | import { errorResponse, humanize, JsonServiceClient, mapGet, toPascalCase } from '@servicestack/client'
|
44 | 44 | import { computed, inject, onMounted, ref, unref } from 'vue'
|
45 | 45 |
|
@@ -73,6 +73,24 @@ const value = computed(() => mapGet(props.modelValue, id.value))
|
73 | 73 | const property = computed(() => typeProperties(props.metadataType).find(x => x.name.toLowerCase() == id.value.toLowerCase()))
|
74 | 74 | const icon = computed(() => typeOf(property.value?.ref?.model)?.icon || config.value.tableIcon)
|
75 | 75 |
|
| 76 | +function withOptions(refInfo:RefInfo|null) { |
| 77 | + return !refInfo |
| 78 | + ? null |
| 79 | + : props.input.options |
| 80 | + ? Object.assign({}, refInfo, scopedExpr(props.input.options, { |
| 81 | + input: props.input, |
| 82 | + $typeFields: typeProperties(props.metadataType).map(x => x.name), |
| 83 | + ...Sole.config.scopeWhitelist |
| 84 | + })) |
| 85 | + : refInfo |
| 86 | +} |
| 87 | +const useRef = computed(() => withOptions(property.value?.ref |
| 88 | + ?? (props.input.type == 'lookup' ? { |
| 89 | + model: props.metadataType.name, |
| 90 | + refId: getPrimaryKey(props.metadataType)?.name ?? 'id', |
| 91 | + refLabel: props.metadataType.properties?.find(x => x.type == 'String' && !x.isPrimaryKey)?.name, |
| 92 | + } as RefInfo : null))) |
| 93 | +
|
76 | 94 | let ModalProvider:ModalProvider|undefined
|
77 | 95 |
|
78 | 96 | function lookup(ref:RefInfo) {
|
@@ -112,8 +130,8 @@ onMounted(async () => {
|
112 | 130 | }
|
113 | 131 |
|
114 | 132 | const prop = property.value
|
115 |
| - const refInfo = prop?.ref |
116 |
| - if (!refInfo) { |
| 133 | + const refInfo = useRef.value |
| 134 | + if (!prop || !refInfo) { |
117 | 135 | console.warn(`No RefInfo for property '${id.value}'`)
|
118 | 136 | return
|
119 | 137 | }
|
|
0 commit comments