refactor(i18n): pass useTranslate's t into the plugin manager's list entries (#39693)

buildPluginListEntries disambiguates plugin names with `t`; the
manager already reads it, so pass it and recompute on a language
switch. The manager would go over budget, so its entries memo and the
auto-update reads it depends on move to use-plugin-manager-entries.

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-11-07 19:29:13 -08:00
committed by GitHub
co-authored by OrcaWin
parent ff6b9a305c
commit 532ae2b0ef
2 changed files with 45 additions and 22 deletions
@@ -1,15 +1,12 @@
import { useCallback, useMemo, useState } from 'react'
import { useCallback, useState } from 'react'
import type { PluginHostListEntry } from '../../../../../preload/api-types'
import { translate } from '@/i18n/i18n'
import { useTranslate, type Translate } from '@/i18n/use-translate'
import { Button } from '../../ui/button'
import { PluginCatalogLayout, type PluginCatalogFilter } from './PluginCatalogLayout'
import { PluginListGroup } from './PluginListGroup'
import {
buildPluginListEntries,
matchesPluginSearch,
type PluginListEntry
} from './plugin-list-entries'
import { matchesPluginSearch, type PluginListEntry } from './plugin-list-entries'
import { usePluginManagerEntries } from './use-plugin-manager-entries'
import type { InstalledRowHandlers } from './PluginManagerRows'
import { PluginMarketplaceSourceDialog } from '../dialogs/PluginMarketplaceSourceDialog'
import { PluginCatalogLinkDialog } from '../dialogs/PluginCatalogLinkDialog'
@@ -34,8 +31,6 @@ import {
PluginNoneInstalled,
PluginPageMissing
} from './PluginListEmptyStates'
import { sortByAttention } from '../presentation/plugin-status-presentation'
import { usePluginAutoUpdatesStore } from '@/store/plugins/updates/plugin-auto-updates'
import { PluginUpdateAllDialog } from '../dialogs/PluginUpdateAllDialog'
import {
matchesPluginFilter,
@@ -137,20 +132,13 @@ export function PluginManager({
})
const prefetch = usePluginHoverPrefetch(catalog.fetchPreview)
const orcaVersion = useOrcaVersion()
const autoUpdated = usePluginAutoUpdatesStore((state) => state.updated)
const autoNeedsReview = usePluginAutoUpdatesStore((state) => state.needsReview)
const entries = useMemo(() => {
const built = buildPluginListEntries(plugins, catalog.listings, {
sources: catalog.sources,
orcaVersion,
autoUpdates: { updated: autoUpdated, needsReview: autoNeedsReview }
})
return {
...built,
installed: sortByAttention(built.installed, (entry) => Boolean(entry.updateVersion))
}
}, [plugins, catalog.listings, catalog.sources, orcaVersion, autoUpdated, autoNeedsReview])
const entries = usePluginManagerEntries(
plugins,
catalog.listings,
catalog.sources,
orcaVersion,
t
)
const query = search.trim()
const filterSize = pluginFilterSize(listFilter)
const narrowed = Boolean(query) || filterSize > 0
@@ -0,0 +1,35 @@
import { useMemo } from 'react'
import type { Translate } from '@/i18n/use-translate'
import { usePluginAutoUpdatesStore } from '@/store/plugins/updates/plugin-auto-updates'
import { sortByAttention } from '../presentation/plugin-status-presentation'
import { buildPluginListEntries } from './plugin-list-entries'
type EntryOptions = NonNullable<Parameters<typeof buildPluginListEntries>[2]>
/** Installed and catalog entries for the plugin manager, installed ones needing attention first. */
export function usePluginManagerEntries(
plugins: Parameters<typeof buildPluginListEntries>[0],
listings: Parameters<typeof buildPluginListEntries>[1],
sources: EntryOptions['sources'],
orcaVersion: EntryOptions['orcaVersion'],
t: Translate
): ReturnType<typeof buildPluginListEntries> {
const autoUpdated = usePluginAutoUpdatesStore((state) => state.updated)
const autoNeedsReview = usePluginAutoUpdatesStore((state) => state.needsReview)
return useMemo(() => {
const built = buildPluginListEntries(
plugins,
listings,
{
sources,
orcaVersion,
autoUpdates: { updated: autoUpdated, needsReview: autoNeedsReview }
},
t
)
return {
...built,
installed: sortByAttention(built.installed, (entry) => Boolean(entry.updateVersion))
}
}, [plugins, listings, sources, orcaVersion, autoUpdated, autoNeedsReview, t])
}