-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathPackageResourceCard.vue
More file actions
111 lines (104 loc) · 2.7 KB
/
PackageResourceCard.vue
File metadata and controls
111 lines (104 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<template>
<a
:href="addUTMTracking(getPackageUrl(nodePackage))"
target="_blank"
rel="noopener noreferrer"
class="package-card"
>
<img
:src="'https://www.google.com/s2/favicons?domain=flows.nodered.org'"
alt="Node-RED"
class="package-favicon"
@error="handleImageError"
>
<div class="package-info">
<div class="package-name">{{ getPackageName(nodePackage) }}</div>
<div class="package-url">{{ getPackageUrl(nodePackage) }}</div>
</div>
</a>
</template>
<script>
export default {
name: 'PackageResourceCard',
props: {
nodePackage: {
type: Object,
required: true
}
},
methods: {
getPackageName (pkg) {
// Handle both object format {id: "..." or name: "..."} and string format
return typeof pkg === 'object' ? (pkg.id || pkg.name) : pkg
},
getPackageUrl (pkg) {
const packageName = this.getPackageName(pkg)
return `https://flows.nodered.org/node/${packageName}`
},
addUTMTracking (url) {
try {
const urlObj = new URL(url)
urlObj.searchParams.set('utm_source', 'flowfuse-expert')
urlObj.searchParams.set('utm_medium', 'assistant')
urlObj.searchParams.set('utm_campaign', 'expert-chat')
return urlObj.toString()
} catch (e) {
// If URL parsing fails, return original
return url
}
},
handleImageError (event) {
// Hide broken image icon
event.target.style.display = 'none'
}
}
}
</script>
<style scoped lang="scss">
.package-card {
display: flex;
align-items: flex-start;
gap: 0.5rem;
padding: 0.75rem;
background-color: white;
border: 1px solid $ff-grey-200;
border-radius: 0.5rem;
text-decoration: none;
color: $ff-grey-900;
transition: all 0.2s ease;
&:hover {
border-color: $ff-indigo-300;
background-color: $ff-grey-50;
}
}
.package-favicon {
flex-shrink: 0;
width: 1rem;
height: 1rem;
margin-top: 0.125rem;
}
.package-info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.package-name {
font-size: 0.875rem;
font-weight: 500;
font-family: monospace;
color: $ff-grey-900;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.package-url {
font-size: 0.75rem;
color: $ff-grey-500;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin: 0;
}
</style>