mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 14:29:15 +08:00
feature: Hide disabled options for web search (#5943)
* refactor(WebSearchButton): streamline provider item creation and filter disabled items * refactor(WebSearchButton): optimize provider items mapping and add pageSize to quick panel * refactor(WebSearchButton): filter out disabled providers in items mapping
This commit is contained in:
parent
e4d1dd0c87
commit
dac200f330
@ -50,29 +50,34 @@ const WebSearchButton: FC<Props> = ({ ref, assistant, ToolbarButton }) => {
|
|||||||
const providerItems = useMemo<QuickPanelListItem[]>(() => {
|
const providerItems = useMemo<QuickPanelListItem[]>(() => {
|
||||||
const isWebSearchModelEnabled = assistant.model && isWebSearchModel(assistant.model)
|
const isWebSearchModelEnabled = assistant.model && isWebSearchModel(assistant.model)
|
||||||
|
|
||||||
const items: QuickPanelListItem[] = providers.map((p) => ({
|
const items: QuickPanelListItem[] = providers
|
||||||
label: p.name,
|
.map((p) => ({
|
||||||
description: WebSearchService.isWebSearchEnabled(p.id)
|
label: p.name,
|
||||||
? hasObjectKey(p, 'apiKey')
|
description: WebSearchService.isWebSearchEnabled(p.id)
|
||||||
? t('settings.websearch.apikey')
|
? hasObjectKey(p, 'apiKey')
|
||||||
: t('settings.websearch.free')
|
? t('settings.websearch.apikey')
|
||||||
: t('chat.input.web_search.enable_content'),
|
: t('settings.websearch.free')
|
||||||
icon: <Globe />,
|
: t('chat.input.web_search.enable_content'),
|
||||||
isSelected: p.id === assistant?.webSearchProviderId,
|
icon: <Globe />,
|
||||||
disabled: !WebSearchService.isWebSearchEnabled(p.id),
|
isSelected: p.id === assistant?.webSearchProviderId,
|
||||||
action: () => updateSelectedWebSearchProvider(p.id)
|
disabled: !WebSearchService.isWebSearchEnabled(p.id),
|
||||||
}))
|
action: () => updateSelectedWebSearchProvider(p.id)
|
||||||
|
}))
|
||||||
|
.filter((o) => !o.disabled)
|
||||||
|
|
||||||
|
if (isWebSearchModelEnabled) {
|
||||||
|
items.unshift({
|
||||||
|
label: t('chat.input.web_search.builtin'),
|
||||||
|
description: isWebSearchModelEnabled
|
||||||
|
? t('chat.input.web_search.builtin.enabled_content')
|
||||||
|
: t('chat.input.web_search.builtin.disabled_content'),
|
||||||
|
icon: <Globe />,
|
||||||
|
isSelected: assistant.enableWebSearch,
|
||||||
|
disabled: !isWebSearchModelEnabled,
|
||||||
|
action: () => updateSelectedWebSearchBuiltin()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
items.unshift({
|
|
||||||
label: t('chat.input.web_search.builtin'),
|
|
||||||
description: isWebSearchModelEnabled
|
|
||||||
? t('chat.input.web_search.builtin.enabled_content')
|
|
||||||
: t('chat.input.web_search.builtin.disabled_content'),
|
|
||||||
icon: <Globe />,
|
|
||||||
isSelected: assistant.enableWebSearch,
|
|
||||||
disabled: !isWebSearchModelEnabled,
|
|
||||||
action: () => updateSelectedWebSearchBuiltin()
|
|
||||||
})
|
|
||||||
items.push({
|
items.push({
|
||||||
label: '前往设置' + '...',
|
label: '前往设置' + '...',
|
||||||
icon: <Settings />,
|
icon: <Settings />,
|
||||||
@ -105,7 +110,8 @@ const WebSearchButton: FC<Props> = ({ ref, assistant, ToolbarButton }) => {
|
|||||||
quickPanel.open({
|
quickPanel.open({
|
||||||
title: t('chat.input.web_search'),
|
title: t('chat.input.web_search'),
|
||||||
list: providerItems,
|
list: providerItems,
|
||||||
symbol: '?'
|
symbol: '?',
|
||||||
|
pageSize: 9
|
||||||
})
|
})
|
||||||
}, [quickPanel, providerItems, t])
|
}, [quickPanel, providerItems, t])
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user