WIP - fix lookup field

This commit is contained in:
Francisco Gaona
2025-12-24 00:05:15 +01:00
parent fc1bec4de7
commit 962c84e6d2
3 changed files with 11 additions and 11 deletions

View File

@@ -19,11 +19,11 @@ interface Props {
config: RelatedListConfig config: RelatedListConfig
parentId: string parentId: string
relatedRecords?: any[] // Can be passed in if already fetched relatedRecords?: any[] // Can be passed in if already fetched
baseUrl?: string // Base API URL, defaults to '/api/central' baseUrl?: string // Base API URL, defaults to '/central'
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
baseUrl: '/api/central', baseUrl: '/central',
relatedRecords: undefined, relatedRecords: undefined,
}) })
@@ -32,7 +32,7 @@ const emit = defineEmits<{
'create': [objectApiName: string, parentId: string] 'create': [objectApiName: string, parentId: string]
}>() }>()
const { $api } = useNuxtApp() as unknown as { $api: Function } const { api } = useApi()
const records = ref<any[]>([]) const records = ref<any[]>([])
const loading = ref(false) const loading = ref(false)
const error = ref<string | null>(null) const error = ref<string | null>(null)
@@ -52,7 +52,7 @@ const fetchRelatedRecords = async () => {
error.value = null error.value = null
try { try {
const response = await $api(`${props.baseUrl}/${props.config.objectApiName}`, { const response = await api.get(`${props.baseUrl}/${props.config.objectApiName}`, {
params: { params: {
parentId: props.parentId, parentId: props.parentId,
}, },

View File

@@ -21,14 +21,14 @@ interface Props {
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
baseUrl: '/api/central', baseUrl: '/central',
}) })
const emit = defineEmits<{ const emit = defineEmits<{
'update:modelValue': [value: any] 'update:modelValue': [value: any]
}>() }>()
const { $api } = useNuxtApp() as unknown as { $api: Function } const { api } = useApi()
// For relationship fields, store the related record for display // For relationship fields, store the related record for display
const relatedRecord = ref<any | null>(null) const relatedRecord = ref<any | null>(null)
@@ -65,7 +65,7 @@ const fetchRelatedRecord = async () => {
loadingRelated.value = true loadingRelated.value = true
try { try {
const record = await $api(`${props.baseUrl}/${relationObject}/${props.modelValue}`) const record = await api.get(`${props.baseUrl}/${relationObject}/${props.modelValue}`)
relatedRecord.value = record relatedRecord.value = record
} catch (err) { } catch (err) {
console.error('Error fetching related record:', err) console.error('Error fetching related record:', err)

View File

@@ -12,11 +12,11 @@ interface Props {
field: FieldConfig field: FieldConfig
modelValue: string | null // The ID of the selected record modelValue: string | null // The ID of the selected record
readonly?: boolean readonly?: boolean
baseUrl?: string // Base API URL, defaults to '/api/central' baseUrl?: string // Base API URL, defaults to '/central'
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
baseUrl: '/api/central', baseUrl: '/central',
modelValue: null, modelValue: null,
}) })
@@ -24,7 +24,7 @@ const emit = defineEmits<{
'update:modelValue': [value: string | null] 'update:modelValue': [value: string | null]
}>() }>()
const { $api } = useNuxtApp() as unknown as { $api: Function } const { api } = useApi()
const open = ref(false) const open = ref(false)
const searchQuery = ref('') const searchQuery = ref('')
const records = ref<any[]>([]) const records = ref<any[]>([])
@@ -56,7 +56,7 @@ const filteredRecords = computed(() => {
const fetchRecords = async () => { const fetchRecords = async () => {
loading.value = true loading.value = true
try { try {
const response = await $api(`${props.baseUrl}/${relationObject.value}`) const response = await api.get(`${props.baseUrl}/${relationObject.value}`)
records.value = response || [] records.value = response || []
// If we have a modelValue, find the selected record // If we have a modelValue, find the selected record