Skip to content

Commit 21365ff

Browse files
committed
fix(ui): add fallback tool icon
1 parent c07d63e commit 21365ff

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

shared/ui/src/components/tool/grid/ToolThing.dom.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ vi.mock('naive-ui', async () => {
2929
return {
3030
NThing,
3131
NAvatar: base('NAvatar', 'span'),
32-
NIcon: base('NIcon', 'span'),
32+
NIcon: defineComponent({
33+
name: 'NIcon',
34+
props: {
35+
component: {
36+
type: Object,
37+
default: undefined,
38+
},
39+
},
40+
template: '<span class="n-icon" :data-has-component="String(!!component)" />',
41+
}),
3342
NTag: base('NTag', 'span'),
3443
useThemeVars: () => ({
3544
cubicBezierEaseInOut: 'ease',
@@ -125,4 +134,18 @@ describe('ToolThing', () => {
125134
expect(wrapper.find('a.tool-link').exists()).toBe(true)
126135
expect(wrapper.findComponent({ name: 'NAvatar' }).exists()).toBe(true)
127136
})
137+
138+
it('falls back to the default icon when a tool does not provide one', () => {
139+
const tool = createTool({ icon: undefined })
140+
const wrapper = mount(ToolThing, {
141+
props: { tool, showIcon: true },
142+
global: {
143+
stubs: {
144+
CustomRouterLink: RouterLinkStub,
145+
},
146+
},
147+
})
148+
149+
expect(wrapper.find('.n-icon').attributes('data-has-component')).toBe('true')
150+
})
128151
})

shared/ui/src/components/tool/grid/ToolThing.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<n-thing>
55
<template v-if="showIcon" #avatar>
66
<n-avatar>
7-
<n-icon :component="props.tool.icon" />
7+
<n-icon :component="iconComponent" />
88
</n-avatar>
99
</template>
1010
<template #header>
@@ -19,7 +19,7 @@
1919
<n-thing>
2020
<template v-if="showIcon" #avatar>
2121
<n-avatar>
22-
<n-icon :component="props.tool.icon" />
22+
<n-icon :component="iconComponent" />
2323
</n-avatar>
2424
</template>
2525
<template v-if="props.tool.thirdParty" #header-extra>
@@ -40,6 +40,7 @@
4040
</template>
4141

4242
<script setup lang="ts">
43+
import AppGeneric20Regular from '@vicons/fluent/AppGeneric20Regular'
4344
import { NThing, NAvatar, NIcon, useThemeVars, NTag } from 'naive-ui'
4445
import type { ToolInfo } from '@shared/tools'
4546
import { computed } from 'vue'
@@ -52,6 +53,7 @@ const props = defineProps<{
5253
}>()
5354
5455
const path = computed(() => props.tool.path)
56+
const iconComponent = computed(() => props.tool.icon ?? AppGeneric20Regular)
5557
const themeVars = useThemeVars()
5658
5759
const { t } = useI18n({

0 commit comments

Comments
 (0)