refactor: streamline AI agent options handling and add disabled state to combobox options
This commit is contained in:
@@ -417,14 +417,10 @@ function ChannelFormBody({
|
|||||||
])
|
])
|
||||||
|
|
||||||
const selectedAIAgent = aiAgents.find((item) => String(item.id) === aiAgentId)
|
const selectedAIAgent = aiAgents.find((item) => String(item.id) === aiAgentId)
|
||||||
const availableAIAgents = aiAgents.filter(
|
const aiAgentOptions = aiAgents.map((item) => ({
|
||||||
(item) => isAgentChannelBindable(item) || String(item.id) === aiAgentId
|
|
||||||
)
|
|
||||||
const aiAgentOptions = availableAIAgents.map((item) => ({
|
|
||||||
value: String(item.id),
|
value: String(item.id),
|
||||||
label: isAgentChannelBindable(item)
|
label: isAgentChannelBindable(item) ? item.name : `${item.name} · 未发布`,
|
||||||
? `${item.name} · Revision #${item.publishedRevisionId}`
|
disabled: !isAgentChannelBindable(item),
|
||||||
: `${item.name} · 未发布`,
|
|
||||||
}))
|
}))
|
||||||
const wxWorkKFAccountOptions = wxWorkKFAccounts.map((item) => ({
|
const wxWorkKFAccountOptions = wxWorkKFAccounts.map((item) => ({
|
||||||
value: item.openKfId,
|
value: item.openKfId,
|
||||||
@@ -502,7 +498,7 @@ function ChannelFormBody({
|
|||||||
open={true}
|
open={true}
|
||||||
onOpenChange={onOpenChange}
|
onOpenChange={onOpenChange}
|
||||||
title={itemId ? t("channel.editTitle") : t("channel.createTitle")}
|
title={itemId ? t("channel.editTitle") : t("channel.createTitle")}
|
||||||
size="lg"
|
size="xl"
|
||||||
allowFullscreen
|
allowFullscreen
|
||||||
footer={
|
footer={
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import { useI18n } from "@/i18n/provider"
|
|||||||
export type ComboboxOption = {
|
export type ComboboxOption = {
|
||||||
value: string
|
value: string
|
||||||
label: string
|
label: string
|
||||||
|
disabled?: boolean
|
||||||
group?: string
|
group?: string
|
||||||
subtitle?: string
|
subtitle?: string
|
||||||
description?: string
|
description?: string
|
||||||
@@ -90,6 +91,10 @@ export function OptionCombobox(props: OptionComboboxProps) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
function selectOption(optionValue: string) {
|
function selectOption(optionValue: string) {
|
||||||
|
const option = options.find((item) => item.value === optionValue)
|
||||||
|
if (option?.disabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (props.multiple) {
|
if (props.multiple) {
|
||||||
props.onValuesChange(
|
props.onValuesChange(
|
||||||
props.values.includes(optionValue)
|
props.values.includes(optionValue)
|
||||||
@@ -132,6 +137,7 @@ export function OptionCombobox(props: OptionComboboxProps) {
|
|||||||
<CommandItem
|
<CommandItem
|
||||||
key={option.value}
|
key={option.value}
|
||||||
value={`${option.group ?? ""} ${option.label} ${option.value} ${option.subtitle ?? ""} ${option.description ?? ""}`}
|
value={`${option.group ?? ""} ${option.label} ${option.value} ${option.subtitle ?? ""} ${option.description ?? ""}`}
|
||||||
|
disabled={option.disabled}
|
||||||
onSelect={() => selectOption(option.value)}
|
onSelect={() => selectOption(option.value)}
|
||||||
>
|
>
|
||||||
<div className="flex min-w-0 flex-1 items-center justify-between gap-2">
|
<div className="flex min-w-0 flex-1 items-center justify-between gap-2">
|
||||||
|
|||||||
Reference in New Issue
Block a user