refactor(web): remove useMixedTranslation, better resource loading (#30630)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Stephen Zhou
2026-01-07 13:20:09 +08:00
committed by GitHub
parent 357548ca07
commit e335cd0ef4
58 changed files with 230 additions and 548 deletions

View File

@ -7,9 +7,9 @@ import Line from './line'
// Mock external dependencies only
// ================================
// Mock useMixedTranslation hook
vi.mock('../hooks', () => ({
useMixedTranslation: (_locale?: string) => ({
// Mock i18n translation hook
vi.mock('#i18n', () => ({
useTranslation: () => ({
t: (key: string, options?: { ns?: string }) => {
// Build full key with namespace prefix if provided
const fullKey = options?.ns ? `${options.ns}.${key}` : key
@ -471,36 +471,6 @@ describe('Empty', () => {
})
})
// ================================
// Locale Prop Tests
// ================================
describe('Locale Prop', () => {
it('should pass locale to useMixedTranslation', () => {
render(<Empty locale="zh-CN" />)
// Translation should still work
expect(screen.getByText('No plugin found')).toBeInTheDocument()
})
it('should handle undefined locale', () => {
render(<Empty locale={undefined} />)
expect(screen.getByText('No plugin found')).toBeInTheDocument()
})
it('should handle en-US locale', () => {
render(<Empty locale="en-US" />)
expect(screen.getByText('No plugin found')).toBeInTheDocument()
})
it('should handle ja-JP locale', () => {
render(<Empty locale="ja-JP" />)
expect(screen.getByText('No plugin found')).toBeInTheDocument()
})
})
// ================================
// Placeholder Cards Layout Tests
// ================================
@ -634,7 +604,6 @@ describe('Empty', () => {
text="Custom message"
lightCard
className="custom-wrapper"
locale="en-US"
/>,
)
@ -695,12 +664,6 @@ describe('Empty', () => {
expect(container.querySelector('.only-class')).toBeInTheDocument()
})
it('should render with only locale prop', () => {
render(<Empty locale="zh-CN" />)
expect(screen.getByText('No plugin found')).toBeInTheDocument()
})
it('should handle text with unicode characters', () => {
render(<Empty text="没有找到插件 🔍" />)
@ -813,7 +776,7 @@ describe('Empty and Line Integration', () => {
})
it('should render complete Empty component structure', () => {
const { container } = render(<Empty text="Test" lightCard className="test" locale="en-US" />)
const { container } = render(<Empty text="Test" lightCard className="test" />)
// Container
expect(container.querySelector('.test')).toBeInTheDocument()

View File

@ -1,6 +1,6 @@
'use client'
import { useTranslation } from '#i18n'
import { Group } from '@/app/components/base/icons/src/vender/other'
import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'
import { cn } from '@/utils/classnames'
import Line from './line'
@ -8,16 +8,14 @@ type Props = {
text?: string
lightCard?: boolean
className?: string
locale?: string
}
const Empty = ({
text,
lightCard,
className,
locale,
}: Props) => {
const { t } = useMixedTranslation(locale)
const { t } = useTranslation()
return (
<div

View File

@ -18,8 +18,6 @@ import {
useEffect,
useState,
} from 'react'
import { useTranslation } from 'react-i18next'
import i18n from '@/i18n-config/i18next-config'
import { postMarketplace } from '@/service/base'
import { SCROLL_BOTTOM_THRESHOLD } from './constants'
import {
@ -218,21 +216,6 @@ export const useMarketplacePlugins = () => {
}
}
/**
* ! Support zh-Hans, pt-BR, ja-JP and en-US for Marketplace page
* ! For other languages, use en-US as fallback
*/
export const useMixedTranslation = (localeFromOuter?: string) => {
let t = useTranslation().t
if (localeFromOuter)
t = i18n.getFixedT(localeFromOuter)
return {
t,
}
}
export const useMarketplaceContainerScroll = (
callback: () => void,
scrollContainerId = 'marketplace-container',

View File

@ -11,7 +11,6 @@ import { PluginCategoryEnum } from '@/app/components/plugins/types'
// Note: Import after mocks are set up
import { DEFAULT_SORT, SCROLL_BOTTOM_THRESHOLD } from './constants'
import { MarketplaceContext, MarketplaceContextProvider, useMarketplaceContext } from './context'
import { useMixedTranslation } from './hooks'
import PluginTypeSwitch, { PLUGIN_TYPE_SEARCH_MAP } from './plugin-type-switch'
import StickySearchAndSwitchWrapper from './sticky-search-and-switch-wrapper'
import {
@ -602,48 +601,6 @@ describe('utils', () => {
})
})
// ================================
// Hooks Tests
// ================================
describe('hooks', () => {
describe('useMixedTranslation', () => {
it('should return translation function', () => {
const { result } = renderHook(() => useMixedTranslation())
expect(result.current.t).toBeDefined()
expect(typeof result.current.t).toBe('function')
})
it('should return translation key when no translation found', () => {
const { result } = renderHook(() => useMixedTranslation())
// The global mock returns key with namespace prefix
expect(result.current.t('category.all', { ns: 'plugin' })).toBe('plugin.category.all')
})
it('should use locale from outer when provided', () => {
const { result } = renderHook(() => useMixedTranslation('zh-Hans'))
expect(result.current.t).toBeDefined()
})
it('should handle different locale values', () => {
const locales = ['en-US', 'zh-Hans', 'ja-JP', 'pt-BR']
locales.forEach((locale) => {
const { result } = renderHook(() => useMixedTranslation(locale))
expect(result.current.t).toBeDefined()
expect(typeof result.current.t).toBe('function')
})
})
it('should use getFixedT when localeFromOuter is provided', () => {
const { result } = renderHook(() => useMixedTranslation('fr-FR'))
// The global mock returns key with namespace prefix
expect(result.current.t('search', { ns: 'plugin' })).toBe('plugin.search')
})
})
})
// ================================
// useMarketplaceCollectionsAndPlugins Tests
// ================================
@ -2088,17 +2045,6 @@ describe('StickySearchAndSwitchWrapper', () => {
})
describe('Props', () => {
it('should accept locale prop', () => {
render(
<MarketplaceContextProvider>
<StickySearchAndSwitchWrapper locale="zh-Hans" />
</MarketplaceContextProvider>,
)
// Component should render without errors
expect(screen.getByTestId('portal-elem')).toBeInTheDocument()
})
it('should accept showSearchParams prop', () => {
render(
<MarketplaceContextProvider>

View File

@ -1,6 +1,5 @@
import type { MarketplaceCollection, SearchParams } from './types'
import type { Plugin } from '@/app/components/plugins/types'
import type { Locale } from '@/i18n-config'
import { TanstackQueryInitializer } from '@/context/query-client'
import { MarketplaceContextProvider } from './context'
import Description from './description'
@ -9,7 +8,6 @@ import StickySearchAndSwitchWrapper from './sticky-search-and-switch-wrapper'
import { getMarketplaceCollectionsAndPlugins } from './utils'
type MarketplaceProps = {
locale: Locale
showInstallButton?: boolean
shouldExclude?: boolean
searchParams?: SearchParams
@ -18,7 +16,6 @@ type MarketplaceProps = {
showSearchParams?: boolean
}
const Marketplace = async ({
locale,
showInstallButton = true,
shouldExclude,
searchParams,
@ -44,12 +41,10 @@ const Marketplace = async ({
>
<Description />
<StickySearchAndSwitchWrapper
locale={locale}
pluginTypeSwitchClassName={pluginTypeSwitchClassName}
showSearchParams={showSearchParams}
/>
<ListWrapper
locale={locale}
marketplaceCollections={marketplaceCollections}
marketplaceCollectionPluginsMap={marketplaceCollectionPluginsMap}
showInstallButton={showInstallButton}

View File

@ -1,6 +1,6 @@
'use client'
import type { Plugin } from '@/app/components/plugins/types'
import type { Locale } from '@/i18n-config'
import { useLocale, useTranslation } from '#i18n'
import { RiArrowRightUpLine } from '@remixicon/react'
import { useBoolean } from 'ahooks'
import { useTheme } from 'next-themes'
@ -11,34 +11,30 @@ import Card from '@/app/components/plugins/card'
import CardMoreInfo from '@/app/components/plugins/card/card-more-info'
import { useTags } from '@/app/components/plugins/hooks'
import InstallFromMarketplace from '@/app/components/plugins/install-plugin/install-from-marketplace'
import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'
import { useLocale } from '@/context/i18n'
import { getPluginDetailLinkInMarketplace, getPluginLinkInMarketplace } from '../utils'
type CardWrapperProps = {
plugin: Plugin
showInstallButton?: boolean
locale?: Locale
}
const CardWrapperComponent = ({
plugin,
showInstallButton,
locale,
}: CardWrapperProps) => {
const { t } = useMixedTranslation(locale)
const { t } = useTranslation()
const { theme } = useTheme()
const [isShowInstallFromMarketplace, {
setTrue: showInstallFromMarketplace,
setFalse: hideInstallFromMarketplace,
}] = useBoolean(false)
const localeFromLocale = useLocale()
const { getTagLabel } = useTags(t)
const locale = useLocale()
const { getTagLabel } = useTags()
// Memoize marketplace link params to prevent unnecessary re-renders
const marketplaceLinkParams = useMemo(() => ({
language: localeFromLocale,
language: locale,
theme,
}), [localeFromLocale, theme])
}), [locale, theme])
// Memoize tag labels to prevent recreating array on every render
const tagLabels = useMemo(() =>
@ -52,7 +48,6 @@ const CardWrapperComponent = ({
<Card
key={plugin.name}
payload={plugin}
locale={locale}
footer={(
<CardMoreInfo
downloadCount={plugin.install_count}
@ -99,7 +94,6 @@ const CardWrapperComponent = ({
<Card
key={plugin.name}
payload={plugin}
locale={locale}
footer={(
<CardMoreInfo
downloadCount={plugin.install_count}

View File

@ -1,6 +1,5 @@
import type { MarketplaceCollection, SearchParamsFromCollection } from '../types'
import type { Plugin } from '@/app/components/plugins/types'
import type { Locale } from '@/i18n-config'
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { PluginCategoryEnum } from '@/app/components/plugins/types'
@ -12,9 +11,9 @@ import ListWrapper from './list-wrapper'
// Mock External Dependencies Only
// ================================
// Mock useMixedTranslation hook
vi.mock('../hooks', () => ({
useMixedTranslation: (_locale?: string) => ({
// Mock i18n translation hook
vi.mock('#i18n', () => ({
useTranslation: () => ({
t: (key: string, options?: { ns?: string, num?: number }) => {
// Build full key with namespace prefix if provided
const fullKey = options?.ns ? `${options.ns}.${key}` : key
@ -28,6 +27,7 @@ vi.mock('../hooks', () => ({
return translations[fullKey] || key
},
}),
useLocale: () => 'en-US',
}))
// Mock useMarketplaceContext with controllable values
@ -148,15 +148,15 @@ vi.mock('@/app/components/plugins/install-plugin/install-from-marketplace', () =
// Mock SortDropdown component
vi.mock('../sort-dropdown', () => ({
default: ({ locale }: { locale: Locale }) => (
<div data-testid="sort-dropdown" data-locale={locale}>Sort</div>
default: () => (
<div data-testid="sort-dropdown">Sort</div>
),
}))
// Mock Empty component
vi.mock('../empty', () => ({
default: ({ className, locale }: { className?: string, locale?: string }) => (
<div data-testid="empty-component" className={className} data-locale={locale}>
default: ({ className }: { className?: string }) => (
<div data-testid="empty-component" className={className}>
No plugins found
</div>
),
@ -233,7 +233,6 @@ describe('List', () => {
marketplaceCollectionPluginsMap: {} as Record<string, Plugin[]>,
plugins: undefined,
showInstallButton: false,
locale: 'en-US' as Locale,
cardContainerClassName: '',
cardRender: undefined,
onMoreClick: undefined,
@ -351,18 +350,6 @@ describe('List', () => {
expect(screen.getByTestId('empty-component')).toHaveClass('custom-empty-class')
})
it('should pass locale to Empty component', () => {
render(
<List
{...defaultProps}
plugins={[]}
locale={'zh-CN' as Locale}
/>,
)
expect(screen.getByTestId('empty-component')).toHaveAttribute('data-locale', 'zh-CN')
})
it('should pass showInstallButton to CardWrapper', () => {
const plugins = createMockPluginList(1)
@ -508,7 +495,6 @@ describe('ListWithCollection', () => {
marketplaceCollections: [] as MarketplaceCollection[],
marketplaceCollectionPluginsMap: {} as Record<string, Plugin[]>,
showInstallButton: false,
locale: 'en-US' as Locale,
cardContainerClassName: '',
cardRender: undefined,
onMoreClick: undefined,
@ -820,7 +806,6 @@ describe('ListWrapper', () => {
marketplaceCollections: [] as MarketplaceCollection[],
marketplaceCollectionPluginsMap: {} as Record<string, Plugin[]>,
showInstallButton: false,
locale: 'en-US' as Locale,
}
beforeEach(() => {
@ -901,14 +886,6 @@ describe('ListWrapper', () => {
expect(screen.queryByTestId('sort-dropdown')).not.toBeInTheDocument()
})
it('should pass locale to SortDropdown', () => {
mockContextValues.plugins = createMockPluginList(1)
render(<ListWrapper {...defaultProps} locale={'zh-CN' as Locale} />)
expect(screen.getByTestId('sort-dropdown')).toHaveAttribute('data-locale', 'zh-CN')
})
})
// ================================
@ -1169,7 +1146,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
locale="en-US"
/>,
)
@ -1188,7 +1164,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
locale="en-US"
/>,
)
@ -1209,7 +1184,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
plugins={plugins}
locale="en-US"
/>,
)
@ -1231,7 +1205,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
showInstallButton={true}
locale="en-US"
/>,
)
@ -1252,7 +1225,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
showInstallButton={true}
locale="en-US"
/>,
)
@ -1274,7 +1246,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
showInstallButton={true}
locale="en-US"
/>,
)
@ -1293,7 +1264,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
showInstallButton={true}
locale="en-US"
/>,
)
@ -1310,7 +1280,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
showInstallButton={true}
locale="en-US"
/>,
)
@ -1327,7 +1296,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
showInstallButton={true}
locale="en-US"
/>,
)
@ -1354,7 +1322,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
showInstallButton={false}
locale="en-US"
/>,
)
@ -1375,7 +1342,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
showInstallButton={false}
locale="en-US"
/>,
)
@ -1390,7 +1356,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
locale="en-US"
/>,
)
@ -1414,7 +1379,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
locale="en-US"
/>,
)
@ -1432,7 +1396,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
locale="en-US"
/>,
)
@ -1450,7 +1413,6 @@ describe('CardWrapper (via List integration)', () => {
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
plugins={[plugin]}
locale="en-US"
/>,
)
@ -1482,7 +1444,6 @@ describe('Combined Workflows', () => {
<ListWrapper
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
locale="en-US"
/>,
)
@ -1501,7 +1462,6 @@ describe('Combined Workflows', () => {
<ListWrapper
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
locale="en-US"
/>,
)
@ -1521,7 +1481,6 @@ describe('Combined Workflows', () => {
<ListWrapper
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
locale="en-US"
/>,
)
@ -1535,7 +1494,6 @@ describe('Combined Workflows', () => {
<ListWrapper
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
locale="en-US"
/>,
)
@ -1551,7 +1509,6 @@ describe('Combined Workflows', () => {
<ListWrapper
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
locale="en-US"
/>,
)
@ -1569,7 +1526,6 @@ describe('Combined Workflows', () => {
<ListWrapper
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
locale="en-US"
/>,
)
@ -1601,7 +1557,6 @@ describe('Accessibility', () => {
<ListWithCollection
marketplaceCollections={collections}
marketplaceCollectionPluginsMap={pluginsMap}
locale="en-US"
/>,
)
@ -1625,7 +1580,6 @@ describe('Accessibility', () => {
marketplaceCollections={collections}
marketplaceCollectionPluginsMap={pluginsMap}
onMoreClick={onMoreClick}
locale="en-US"
/>,
)
@ -1642,7 +1596,6 @@ describe('Accessibility', () => {
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
plugins={plugins}
locale="en-US"
/>,
)
@ -1668,7 +1621,6 @@ describe('Performance', () => {
marketplaceCollections={[]}
marketplaceCollectionPluginsMap={{}}
plugins={plugins}
locale="en-US"
/>,
)
const endTime = performance.now()
@ -1689,7 +1641,6 @@ describe('Performance', () => {
<ListWithCollection
marketplaceCollections={collections}
marketplaceCollectionPluginsMap={pluginsMap}
locale="en-US"
/>,
)
const endTime = performance.now()

View File

@ -1,7 +1,6 @@
'use client'
import type { Plugin } from '../../types'
import type { MarketplaceCollection } from '../types'
import type { Locale } from '@/i18n-config'
import { cn } from '@/utils/classnames'
import Empty from '../empty'
import CardWrapper from './card-wrapper'
@ -12,7 +11,6 @@ type ListProps = {
marketplaceCollectionPluginsMap: Record<string, Plugin[]>
plugins?: Plugin[]
showInstallButton?: boolean
locale: Locale
cardContainerClassName?: string
cardRender?: (plugin: Plugin) => React.JSX.Element | null
onMoreClick?: () => void
@ -23,7 +21,6 @@ const List = ({
marketplaceCollectionPluginsMap,
plugins,
showInstallButton,
locale,
cardContainerClassName,
cardRender,
onMoreClick,
@ -37,7 +34,6 @@ const List = ({
marketplaceCollections={marketplaceCollections}
marketplaceCollectionPluginsMap={marketplaceCollectionPluginsMap}
showInstallButton={showInstallButton}
locale={locale}
cardContainerClassName={cardContainerClassName}
cardRender={cardRender}
onMoreClick={onMoreClick}
@ -61,7 +57,6 @@ const List = ({
key={`${plugin.org}/${plugin.name}`}
plugin={plugin}
showInstallButton={showInstallButton}
locale={locale}
/>
)
})
@ -71,7 +66,7 @@ const List = ({
}
{
plugins && !plugins.length && (
<Empty className={emptyClassName} locale={locale} />
<Empty className={emptyClassName} />
)
}
</>

View File

@ -3,9 +3,8 @@
import type { MarketplaceCollection } from '../types'
import type { SearchParamsFromCollection } from '@/app/components/plugins/marketplace/types'
import type { Plugin } from '@/app/components/plugins/types'
import type { Locale } from '@/i18n-config'
import { useLocale, useTranslation } from '#i18n'
import { RiArrowRightSLine } from '@remixicon/react'
import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'
import { getLanguage } from '@/i18n-config/language'
import { cn } from '@/utils/classnames'
import CardWrapper from './card-wrapper'
@ -14,7 +13,6 @@ type ListWithCollectionProps = {
marketplaceCollections: MarketplaceCollection[]
marketplaceCollectionPluginsMap: Record<string, Plugin[]>
showInstallButton?: boolean
locale: Locale
cardContainerClassName?: string
cardRender?: (plugin: Plugin) => React.JSX.Element | null
onMoreClick?: (searchParams?: SearchParamsFromCollection) => void
@ -23,12 +21,12 @@ const ListWithCollection = ({
marketplaceCollections,
marketplaceCollectionPluginsMap,
showInstallButton,
locale,
cardContainerClassName,
cardRender,
onMoreClick,
}: ListWithCollectionProps) => {
const { t } = useMixedTranslation(locale)
const { t } = useTranslation()
const locale = useLocale()
return (
<>
@ -72,7 +70,6 @@ const ListWithCollection = ({
key={plugin.plugin_id}
plugin={plugin}
showInstallButton={showInstallButton}
locale={locale}
/>
)
})

View File

@ -1,10 +1,9 @@
'use client'
import type { Plugin } from '../../types'
import type { MarketplaceCollection } from '../types'
import type { Locale } from '@/i18n-config'
import { useTranslation } from '#i18n'
import { useEffect } from 'react'
import Loading from '@/app/components/base/loading'
import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'
import { useMarketplaceContext } from '../context'
import SortDropdown from '../sort-dropdown'
import List from './index'
@ -13,15 +12,13 @@ type ListWrapperProps = {
marketplaceCollections: MarketplaceCollection[]
marketplaceCollectionPluginsMap: Record<string, Plugin[]>
showInstallButton?: boolean
locale: Locale
}
const ListWrapper = ({
marketplaceCollections,
marketplaceCollectionPluginsMap,
showInstallButton,
locale,
}: ListWrapperProps) => {
const { t } = useMixedTranslation(locale)
const { t } = useTranslation()
const plugins = useMarketplaceContext(v => v.plugins)
const pluginsTotal = useMarketplaceContext(v => v.pluginsTotal)
const marketplaceCollectionsFromClient = useMarketplaceContext(v => v.marketplaceCollectionsFromClient)
@ -55,7 +52,7 @@ const ListWrapper = ({
<div className="mb-4 flex items-center pt-3">
<div className="title-xl-semi-bold text-text-primary">{t('marketplace.pluginsResult', { ns: 'plugin', num: pluginsTotal })}</div>
<div className="mx-3 h-3.5 w-[1px] bg-divider-regular"></div>
<SortDropdown locale={locale} />
<SortDropdown />
</div>
)
}
@ -73,7 +70,6 @@ const ListWrapper = ({
marketplaceCollectionPluginsMap={marketplaceCollectionPluginsMapFromClient || marketplaceCollectionPluginsMap}
plugins={plugins}
showInstallButton={showInstallButton}
locale={locale}
onMoreClick={handleMoreClick}
/>
)

View File

@ -1,4 +1,5 @@
'use client'
import { useTranslation } from '#i18n'
import {
RiArchive2Line,
RiBrain2Line,
@ -12,7 +13,6 @@ import { Trigger as TriggerIcon } from '@/app/components/base/icons/src/vender/p
import { cn } from '@/utils/classnames'
import { PluginCategoryEnum } from '../types'
import { useMarketplaceContext } from './context'
import { useMixedTranslation } from './hooks'
export const PLUGIN_TYPE_SEARCH_MAP = {
all: 'all',
@ -25,16 +25,14 @@ export const PLUGIN_TYPE_SEARCH_MAP = {
bundle: 'bundle',
}
type PluginTypeSwitchProps = {
locale?: string
className?: string
showSearchParams?: boolean
}
const PluginTypeSwitch = ({
locale,
className,
showSearchParams,
}: PluginTypeSwitchProps) => {
const { t } = useMixedTranslation(locale)
const { t } = useTranslation()
const activePluginType = useMarketplaceContext(s => s.activePluginType)
const handleActivePluginTypeChange = useMarketplaceContext(s => s.handleActivePluginTypeChange)

View File

@ -10,9 +10,9 @@ import ToolSelectorTrigger from './trigger/tool-selector'
// Mock external dependencies only
// ================================
// Mock useMixedTranslation hook
vi.mock('../hooks', () => ({
useMixedTranslation: (_locale?: string) => ({
// Mock i18n translation hook
vi.mock('#i18n', () => ({
useTranslation: () => ({
t: (key: string, options?: { ns?: string }) => {
// Build full key with namespace prefix if provided
const fullKey = options?.ns ? `${options.ns}.${key}` : key
@ -364,13 +364,6 @@ describe('SearchBox', () => {
expect(container.querySelector('.custom-input-class')).toBeInTheDocument()
})
it('should pass locale to TagsFilter', () => {
render(<SearchBox {...defaultProps} locale="zh-CN" />)
// TagsFilter should be rendered with locale
expect(screen.getByTestId('portal-elem')).toBeInTheDocument()
})
it('should handle empty placeholder', () => {
render(<SearchBox {...defaultProps} placeholder="" />)
@ -449,12 +442,6 @@ describe('SearchBoxWrapper', () => {
expect(screen.getByRole('textbox')).toBeInTheDocument()
})
it('should render with locale prop', () => {
render(<SearchBoxWrapper locale="en-US" />)
expect(screen.getByRole('textbox')).toBeInTheDocument()
})
it('should render in marketplace mode', () => {
const { container } = render(<SearchBoxWrapper />)
@ -500,13 +487,6 @@ describe('SearchBoxWrapper', () => {
expect(screen.getByPlaceholderText('Search plugins')).toBeInTheDocument()
})
it('should pass locale to useMixedTranslation', () => {
render(<SearchBoxWrapper locale="zh-CN" />)
// Translation should still work
expect(screen.getByPlaceholderText('Search plugins')).toBeInTheDocument()
})
})
})
@ -665,12 +645,6 @@ describe('MarketplaceTrigger', () => {
})
describe('Props Variations', () => {
it('should handle locale prop', () => {
render(<MarketplaceTrigger {...defaultProps} locale="zh-CN" />)
expect(screen.getByText('All Tags')).toBeInTheDocument()
})
it('should handle empty tagsMap', () => {
const { container } = render(
<MarketplaceTrigger {...defaultProps} tagsMap={{}} tags={[]} />,
@ -1251,7 +1225,6 @@ describe('Combined Workflows', () => {
supportAddCustomTool
onShowAddCustomCollectionModal={vi.fn()}
placeholder="Search plugins"
locale="en-US"
wrapperClassName="custom-wrapper"
inputClassName="custom-input"
autoFocus={false}

View File

@ -13,7 +13,6 @@ type SearchBoxProps = {
tags: string[]
onTagsChange: (tags: string[]) => void
placeholder?: string
locale?: string
supportAddCustomTool?: boolean
usedInMarketplace?: boolean
onShowAddCustomCollectionModal?: () => void
@ -28,7 +27,6 @@ const SearchBox = ({
tags,
onTagsChange,
placeholder = '',
locale,
usedInMarketplace = false,
supportAddCustomTool,
onShowAddCustomCollectionModal,
@ -49,7 +47,6 @@ const SearchBox = ({
tags={tags}
onTagsChange={onTagsChange}
usedInMarketplace
locale={locale}
/>
<Divider type="vertical" className="mx-1 h-3.5" />
<div className="flex grow items-center gap-x-2 p-1">
@ -109,7 +106,6 @@ const SearchBox = ({
<TagsFilter
tags={tags}
onTagsChange={onTagsChange}
locale={locale}
/>
</>
)

View File

@ -1,16 +1,11 @@
'use client'
import { useTranslation } from '#i18n'
import { useMarketplaceContext } from '../context'
import { useMixedTranslation } from '../hooks'
import SearchBox from './index'
type SearchBoxWrapperProps = {
locale?: string
}
const SearchBoxWrapper = ({
locale,
}: SearchBoxWrapperProps) => {
const { t } = useMixedTranslation(locale)
const SearchBoxWrapper = () => {
const { t } = useTranslation()
const searchPluginText = useMarketplaceContext(v => v.searchPluginText)
const handleSearchPluginTextChange = useMarketplaceContext(v => v.handleSearchPluginTextChange)
const filterPluginTags = useMarketplaceContext(v => v.filterPluginTags)
@ -24,7 +19,6 @@ const SearchBoxWrapper = ({
onSearchChange={handleSearchPluginTextChange}
tags={filterPluginTags}
onTagsChange={handleFilterPluginTagsChange}
locale={locale}
placeholder={t('searchPlugins', { ns: 'plugin' })}
usedInMarketplace
/>

View File

@ -1,5 +1,6 @@
'use client'
import { useTranslation } from '#i18n'
import { useState } from 'react'
import Checkbox from '@/app/components/base/checkbox'
import Input from '@/app/components/base/input'
@ -9,7 +10,6 @@ import {
PortalToFollowElemTrigger,
} from '@/app/components/base/portal-to-follow-elem'
import { useTags } from '@/app/components/plugins/hooks'
import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'
import MarketplaceTrigger from './trigger/marketplace'
import ToolSelectorTrigger from './trigger/tool-selector'
@ -17,18 +17,16 @@ type TagsFilterProps = {
tags: string[]
onTagsChange: (tags: string[]) => void
usedInMarketplace?: boolean
locale?: string
}
const TagsFilter = ({
tags,
onTagsChange,
usedInMarketplace = false,
locale,
}: TagsFilterProps) => {
const { t } = useMixedTranslation(locale)
const { t } = useTranslation()
const [open, setOpen] = useState(false)
const [searchText, setSearchText] = useState('')
const { tags: options, tagsMap } = useTags(t)
const { tags: options, tagsMap } = useTags()
const filteredOptions = options.filter(option => option.label.toLowerCase().includes(searchText.toLowerCase()))
const handleCheck = (id: string) => {
if (tags.includes(id))
@ -59,7 +57,6 @@ const TagsFilter = ({
open={open}
tags={tags}
tagsMap={tagsMap}
locale={locale}
onTagsChange={onTagsChange}
/>
)

View File

@ -1,15 +1,14 @@
import type { Tag } from '../../../hooks'
import { useTranslation } from '#i18n'
import { RiArrowDownSLine, RiCloseCircleFill, RiFilter3Line } from '@remixicon/react'
import * as React from 'react'
import { cn } from '@/utils/classnames'
import { useMixedTranslation } from '../../hooks'
type MarketplaceTriggerProps = {
selectedTagsLength: number
open: boolean
tags: string[]
tagsMap: Record<string, Tag>
locale?: string
onTagsChange: (tags: string[]) => void
}
@ -18,10 +17,9 @@ const MarketplaceTrigger = ({
open,
tags,
tagsMap,
locale,
onTagsChange,
}: MarketplaceTriggerProps) => {
const { t } = useMixedTranslation(locale)
const { t } = useTranslation()
return (
<div

View File

@ -8,7 +8,7 @@ import SortDropdown from './index'
// Mock external dependencies only
// ================================
// Mock useMixedTranslation hook
// Mock i18n translation hook
const mockTranslation = vi.fn((key: string, options?: { ns?: string }) => {
// Build full key with namespace prefix if provided
const fullKey = options?.ns ? `${options.ns}.${key}` : key
@ -22,8 +22,8 @@ const mockTranslation = vi.fn((key: string, options?: { ns?: string }) => {
return translations[fullKey] || key
})
vi.mock('../hooks', () => ({
useMixedTranslation: (_locale?: string) => ({
vi.mock('#i18n', () => ({
useTranslation: () => ({
t: mockTranslation,
}),
}))
@ -145,36 +145,6 @@ describe('SortDropdown', () => {
})
})
// ================================
// Props Testing
// ================================
describe('Props', () => {
it('should accept locale prop', () => {
render(<SortDropdown locale="zh-CN" />)
expect(screen.getByTestId('portal-wrapper')).toBeInTheDocument()
})
it('should call useMixedTranslation with provided locale', () => {
render(<SortDropdown locale="ja-JP" />)
// Translation function should be called for labels
expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortBy', { ns: 'plugin' })
})
it('should render without locale prop (undefined)', () => {
render(<SortDropdown />)
expect(screen.getByText('Sort by')).toBeInTheDocument()
})
it('should render with empty string locale', () => {
render(<SortDropdown locale="" />)
expect(screen.getByText('Sort by')).toBeInTheDocument()
})
})
// ================================
// State Management Tests
// ================================
@ -618,13 +588,6 @@ describe('SortDropdown', () => {
expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortOption.newlyReleased', { ns: 'plugin' })
expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortOption.firstReleased', { ns: 'plugin' })
})
it('should pass locale to useMixedTranslation', () => {
render(<SortDropdown locale="pt-BR" />)
// Verify component renders with locale
expect(screen.getByTestId('portal-wrapper')).toBeInTheDocument()
})
})
// ================================

View File

@ -1,4 +1,5 @@
'use client'
import { useTranslation } from '#i18n'
import {
RiArrowDownSLine,
RiCheckLine,
@ -9,16 +10,10 @@ import {
PortalToFollowElemContent,
PortalToFollowElemTrigger,
} from '@/app/components/base/portal-to-follow-elem'
import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'
import { useMarketplaceContext } from '../context'
type SortDropdownProps = {
locale?: string
}
const SortDropdown = ({
locale,
}: SortDropdownProps) => {
const { t } = useMixedTranslation(locale)
const SortDropdown = () => {
const { t } = useTranslation()
const options = [
{
value: 'install_count',

View File

@ -5,13 +5,11 @@ import PluginTypeSwitch from './plugin-type-switch'
import SearchBoxWrapper from './search-box/search-box-wrapper'
type StickySearchAndSwitchWrapperProps = {
locale?: string
pluginTypeSwitchClassName?: string
showSearchParams?: boolean
}
const StickySearchAndSwitchWrapper = ({
locale,
pluginTypeSwitchClassName,
showSearchParams,
}: StickySearchAndSwitchWrapperProps) => {
@ -25,9 +23,8 @@ const StickySearchAndSwitchWrapper = ({
pluginTypeSwitchClassName,
)}
>
<SearchBoxWrapper locale={locale} />
<SearchBoxWrapper />
<PluginTypeSwitch
locale={locale}
showSearchParams={showSearchParams}
/>
</div>