Skip to content

Commit 35556eb

Browse files
hyq2015Huang Yun Qi
andauthored
fIx: side toolbar tab tooltip not reactive when changing locale (#4213)
Co-authored-by: Huang Yun Qi <[email protected]>
1 parent 92b65ca commit 35556eb

File tree

8 files changed

+32
-23
lines changed

8 files changed

+32
-23
lines changed

src/components/sidebar/SideToolbar.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
:key="tab.id"
77
:icon="tab.icon"
88
:icon-badge="tab.iconBadge"
9-
:tooltip="tab.tooltip + getTabTooltipSuffix(tab)"
9+
:tooltip="tab.tooltip"
10+
:tooltip-suffix="getTabTooltipSuffix(tab)"
1011
:selected="tab.id === selectedTab?.id"
1112
:class="tab.id + '-tab-button'"
1213
@click="onTabClick(tab)"

src/components/sidebar/SidebarIcon.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PrimeVue from 'primevue/config'
44
import OverlayBadge from 'primevue/overlaybadge'
55
import Tooltip from 'primevue/tooltip'
66
import { describe, expect, it } from 'vitest'
7+
import { createI18n } from 'vue-i18n'
78

89
import SidebarIcon from './SidebarIcon.vue'
910

@@ -15,6 +16,14 @@ type SidebarIconProps = {
1516
iconBadge?: string | (() => string | null)
1617
}
1718

19+
const i18n = createI18n({
20+
legacy: false,
21+
locale: 'en',
22+
messages: {
23+
en: {}
24+
}
25+
})
26+
1827
describe('SidebarIcon', () => {
1928
const exampleProps: SidebarIconProps = {
2029
icon: 'pi pi-cog',
@@ -24,7 +33,7 @@ describe('SidebarIcon', () => {
2433
const mountSidebarIcon = (props: Partial<SidebarIconProps>, options = {}) => {
2534
return mount(SidebarIcon, {
2635
global: {
27-
plugins: [PrimeVue],
36+
plugins: [PrimeVue, i18n],
2837
directives: { tooltip: Tooltip },
2938
components: { OverlayBadge, Button }
3039
},

src/components/sidebar/SidebarIcon.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<template>
22
<Button
3-
v-tooltip="{ value: tooltip, showDelay: 300, hideDelay: 300 }"
3+
v-tooltip="{
4+
value: computedTooltip,
5+
showDelay: 300,
6+
hideDelay: 300
7+
}"
48
text
59
:pt="{
610
root: {
@@ -9,7 +13,7 @@
913
? 'p-button-primary side-bar-button-selected'
1014
: 'p-button-secondary'
1115
}`,
12-
'aria-label': tooltip
16+
'aria-label': computedTooltip
1317
}
1418
}"
1519
@click="emit('click', $event)"
@@ -27,16 +31,20 @@
2731
import Button from 'primevue/button'
2832
import OverlayBadge from 'primevue/overlaybadge'
2933
import { computed } from 'vue'
34+
import { useI18n } from 'vue-i18n'
3035
36+
const { t } = useI18n()
3137
const {
3238
icon = '',
3339
selected = false,
3440
tooltip = '',
41+
tooltipSuffix = '',
3542
iconBadge = ''
3643
} = defineProps<{
3744
icon?: string
3845
selected?: boolean
3946
tooltip?: string
47+
tooltipSuffix?: string
4048
iconBadge?: string | (() => string | null)
4149
}>()
4250
@@ -47,6 +55,7 @@ const overlayValue = computed(() =>
4755
typeof iconBadge === 'function' ? iconBadge() ?? '' : iconBadge
4856
)
4957
const shouldShowBadge = computed(() => !!overlayValue.value)
58+
const computedTooltip = computed(() => t(tooltip) + tooltipSuffix)
5059
</script>
5160

5261
<style>

src/composables/sidebarTabs/useModelLibrarySidebarTab.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import { markRaw } from 'vue'
2-
import { useI18n } from 'vue-i18n'
32

43
import ModelLibrarySidebarTab from '@/components/sidebar/tabs/ModelLibrarySidebarTab.vue'
54
import { useElectronDownloadStore } from '@/stores/electronDownloadStore'
65
import type { SidebarTabExtension } from '@/types/extensionTypes'
76
import { isElectron } from '@/utils/envUtil'
87

98
export const useModelLibrarySidebarTab = (): SidebarTabExtension => {
10-
const { t } = useI18n()
11-
129
return {
1310
id: 'model-library',
1411
icon: 'pi pi-box',
15-
title: t('sideToolbar.modelLibrary'),
16-
tooltip: t('sideToolbar.modelLibrary'),
12+
title: 'sideToolbar.modelLibrary',
13+
tooltip: 'sideToolbar.modelLibrary',
1714
component: markRaw(ModelLibrarySidebarTab),
1815
type: 'vue',
1916
iconBadge: () => {

src/composables/sidebarTabs/useNodeLibrarySidebarTab.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import { markRaw } from 'vue'
2-
import { useI18n } from 'vue-i18n'
32

43
import NodeLibrarySidebarTab from '@/components/sidebar/tabs/NodeLibrarySidebarTab.vue'
54
import type { SidebarTabExtension } from '@/types/extensionTypes'
65

76
export const useNodeLibrarySidebarTab = (): SidebarTabExtension => {
8-
const { t } = useI18n()
97
return {
108
id: 'node-library',
119
icon: 'pi pi-book',
12-
title: t('sideToolbar.nodeLibrary'),
13-
tooltip: t('sideToolbar.nodeLibrary'),
10+
title: 'sideToolbar.nodeLibrary',
11+
tooltip: 'sideToolbar.nodeLibrary',
1412
component: markRaw(NodeLibrarySidebarTab),
1513
type: 'vue'
1614
}

src/composables/sidebarTabs/useQueueSidebarTab.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { markRaw } from 'vue'
2-
import { useI18n } from 'vue-i18n'
32

43
import QueueSidebarTab from '@/components/sidebar/tabs/QueueSidebarTab.vue'
54
import { useQueuePendingTaskCountStore } from '@/stores/queueStore'
65
import type { SidebarTabExtension } from '@/types/extensionTypes'
76

87
export const useQueueSidebarTab = (): SidebarTabExtension => {
9-
const { t } = useI18n()
108
const queuePendingTaskCountStore = useQueuePendingTaskCountStore()
119
return {
1210
id: 'queue',
@@ -15,8 +13,8 @@ export const useQueueSidebarTab = (): SidebarTabExtension => {
1513
const value = queuePendingTaskCountStore.count.toString()
1614
return value === '0' ? null : value
1715
},
18-
title: t('sideToolbar.queue'),
19-
tooltip: t('sideToolbar.queue'),
16+
title: 'sideToolbar.queue',
17+
tooltip: 'sideToolbar.queue',
2018
component: markRaw(QueueSidebarTab),
2119
type: 'vue'
2220
}

src/composables/sidebarTabs/useWorkflowsSidebarTab.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { markRaw } from 'vue'
2-
import { useI18n } from 'vue-i18n'
32

43
import WorkflowsSidebarTab from '@/components/sidebar/tabs/WorkflowsSidebarTab.vue'
54
import { useSettingStore } from '@/stores/settingStore'
65
import { useWorkflowStore } from '@/stores/workflowStore'
76
import type { SidebarTabExtension } from '@/types/extensionTypes'
87

98
export const useWorkflowsSidebarTab = (): SidebarTabExtension => {
10-
const { t } = useI18n()
119
const settingStore = useSettingStore()
1210
const workflowStore = useWorkflowStore()
13-
1411
return {
1512
id: 'workflows',
1613
icon: 'pi pi-folder-open',
@@ -23,8 +20,8 @@ export const useWorkflowsSidebarTab = (): SidebarTabExtension => {
2320
const value = workflowStore.openWorkflows.length.toString()
2421
return value === '0' ? null : value
2522
},
26-
title: t('sideToolbar.workflows'),
27-
tooltip: t('sideToolbar.workflows'),
23+
title: 'sideToolbar.workflows',
24+
tooltip: 'sideToolbar.workflows',
2825
component: markRaw(WorkflowsSidebarTab),
2926
type: 'vue'
3027
}

src/stores/workspace/sidebarTabStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const useSidebarTabStore = defineStore('sidebarTab', () => {
2828
useCommandStore().registerCommand({
2929
id: `Workspace.ToggleSidebarTab.${tab.id}`,
3030
icon: tab.icon,
31-
label: `Toggle ${tab.title} Sidebar`,
31+
label: tab.title,
3232
tooltip: tab.tooltip,
3333
versionAdded: '1.3.9',
3434
function: () => {

0 commit comments

Comments
 (0)