Files
FEDEO/frontend/components/columnRenderings/externalLink.vue
florianfederspiel 7996c746c3
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 27s
Build and Push Docker Images / build-frontend (push) Successful in 1m3s
Add External Link
Fix Plantafel
2026-03-27 21:41:20 +01:00

49 lines
1.1 KiB
Vue

<script setup>
const props = defineProps({
row: {
type: Object,
required: true,
default: () => ({})
},
keyName: {
type: String,
default: ""
}
})
const resolvedKey = computed(() => {
if (props.keyName) return props.keyName
if (typeof props.row?.supplier_link === "string") return "supplier_link"
if (typeof props.row?.link === "string") return "link"
if (typeof props.row?.url === "string") return "url"
return null
})
const normalizedUrl = computed(() => {
const rawValue = resolvedKey.value ? props.row?.[resolvedKey.value] : null
if (!rawValue || typeof rawValue !== "string") return null
const trimmedValue = rawValue.trim()
if (!trimmedValue) return null
if (/^https?:\/\//i.test(trimmedValue)) return trimmedValue
return `https://${trimmedValue}`
})
</script>
<template>
<a
v-if="normalizedUrl"
:href="normalizedUrl"
target="_blank"
rel="noopener noreferrer"
class="text-primary hover:underline break-all"
>
{{ resolvedKey ? row[resolvedKey] : "" }}
</a>
<span v-else>-</span>
</template>