|
3 | 3 | import type { AppListUrlQuery } from './query-params' |
4 | 4 | import { cn } from '@langgenius/dify-ui/cn' |
5 | 5 | import { |
6 | | - DropdownMenu, |
7 | | - DropdownMenuContent, |
8 | | - DropdownMenuRadioGroup, |
9 | | - DropdownMenuRadioItem, |
10 | | - DropdownMenuRadioItemIndicator, |
11 | | - DropdownMenuTrigger, |
12 | | -} from '@langgenius/dify-ui/dropdown-menu' |
| 6 | + Select, |
| 7 | + SelectContent, |
| 8 | + SelectItem, |
| 9 | + SelectItemIndicator, |
| 10 | + SelectItemText, |
| 11 | + SelectTrigger, |
| 12 | + SelectValue, |
| 13 | +} from '@langgenius/dify-ui/select' |
13 | 14 | import { useMemo } from 'react' |
14 | 15 | import { useTranslation } from 'react-i18next' |
15 | 16 | import { studioAppListCategories } from './query-params' |
16 | 17 |
|
17 | 18 | type AppListCategory = AppListUrlQuery['category'] |
18 | 19 |
|
19 | | -const chipClassName = |
20 | | - 'flex h-8 items-center whitespace-nowrap rounded-lg border-[0.5px] px-2 text-[13px] leading-4 transition-colors' |
21 | | - |
22 | 20 | type AppTypeFilterProps = { |
23 | 21 | value: AppListCategory |
24 | | - onChange: (value: AppListCategory) => void |
| 22 | + onValueChange: (value: AppListCategory) => void |
25 | 23 | } |
26 | 24 |
|
27 | | -export function AppTypeFilter({ value, onChange }: AppTypeFilterProps) { |
| 25 | +export function AppTypeFilter({ value, onValueChange }: AppTypeFilterProps) { |
28 | 26 | const { t } = useTranslation(['app']) |
29 | 27 |
|
30 | 28 | const options = useMemo(() => { |
31 | 29 | const optionsByCategory = { |
32 | 30 | all: { |
33 | | - text: t(($) => $['types.all'], { ns: 'app' }), |
| 31 | + label: t(($) => $['types.all'], { ns: 'app' }), |
34 | 32 | iconClassName: 'i-ri-apps-2-line', |
35 | 33 | }, |
36 | 34 | workflow: { |
37 | | - text: t(($) => $['types.workflow'], { ns: 'app' }), |
| 35 | + label: t(($) => $['types.workflow'], { ns: 'app' }), |
38 | 36 | iconClassName: 'i-ri-exchange-2-line', |
39 | 37 | }, |
40 | 38 | 'advanced-chat': { |
41 | | - text: t(($) => $['types.advanced'], { ns: 'app' }), |
| 39 | + label: t(($) => $['types.advanced'], { ns: 'app' }), |
42 | 40 | iconClassName: 'i-ri-message-3-line', |
43 | 41 | }, |
44 | 42 | chat: { |
45 | | - text: t(($) => $['types.chatbot'], { ns: 'app' }), |
| 43 | + label: t(($) => $['types.chatbot'], { ns: 'app' }), |
46 | 44 | iconClassName: 'i-ri-message-3-line', |
47 | 45 | }, |
48 | 46 | 'agent-chat': { |
49 | | - text: t(($) => $['types.agent'], { ns: 'app' }), |
| 47 | + label: t(($) => $['types.agent'], { ns: 'app' }), |
50 | 48 | iconClassName: 'i-ri-robot-3-line', |
51 | 49 | }, |
52 | 50 | completion: { |
53 | | - text: t(($) => $['newApp.completeApp'], { ns: 'app' }), |
| 51 | + label: t(($) => $['newApp.completeApp'], { ns: 'app' }), |
54 | 52 | iconClassName: 'i-ri-file-4-line', |
55 | 53 | }, |
56 | | - } satisfies Record<AppListCategory, { text: string; iconClassName: string }> |
| 54 | + } satisfies Record<AppListCategory, { label: string; iconClassName: string }> |
57 | 55 |
|
58 | 56 | return studioAppListCategories.map((value) => ({ |
59 | 57 | value, |
60 | 58 | ...optionsByCategory[value], |
61 | 59 | })) |
62 | 60 | }, [t]) |
63 | 61 |
|
64 | | - const activeOption = options.find((option) => option.value === value) |
65 | | - const isSelected = value !== 'all' |
66 | | - const triggerLabel = isSelected |
67 | | - ? activeOption?.text |
68 | | - : t(($) => $['studio.filters.types'], { ns: 'app' }) |
| 62 | + const isFiltered = value !== 'all' |
| 63 | + const typesLabel = t(($) => $['studio.filters.types'], { ns: 'app' }) |
69 | 64 |
|
70 | 65 | return ( |
71 | | - <DropdownMenu> |
72 | | - <DropdownMenuTrigger |
73 | | - render={ |
74 | | - <button |
75 | | - type="button" |
76 | | - className={cn( |
77 | | - chipClassName, |
78 | | - isSelected |
79 | | - ? 'border-components-button-secondary-border bg-components-button-secondary-bg shadow-xs hover:bg-state-base-hover' |
80 | | - : 'border-transparent bg-components-input-bg-normal text-text-tertiary hover:bg-components-input-bg-hover', |
81 | | - )} |
82 | | - /> |
83 | | - } |
84 | | - > |
85 | | - <span className="px-1 text-text-tertiary">{triggerLabel}</span> |
86 | | - <span aria-hidden className="i-ri-arrow-down-s-line h-4 w-4 shrink-0 text-text-tertiary" /> |
87 | | - </DropdownMenuTrigger> |
88 | | - <DropdownMenuContent placement="bottom-start" className="w-55"> |
89 | | - <DropdownMenuRadioGroup<AppListCategory> |
90 | | - value={value} |
91 | | - onValueChange={(nextValue) => onChange(nextValue)} |
92 | | - > |
93 | | - {options.map((option) => ( |
94 | | - <DropdownMenuRadioItem<AppListCategory> key={option.value} value={option.value}> |
95 | | - <span |
96 | | - aria-hidden |
97 | | - className={cn('h-4 w-4 shrink-0 text-text-tertiary', option.iconClassName)} |
98 | | - /> |
99 | | - <span>{option.text}</span> |
100 | | - <DropdownMenuRadioItemIndicator /> |
101 | | - </DropdownMenuRadioItem> |
102 | | - ))} |
103 | | - </DropdownMenuRadioGroup> |
104 | | - </DropdownMenuContent> |
105 | | - </DropdownMenu> |
| 66 | + <Select<AppListCategory> |
| 67 | + items={options} |
| 68 | + value={value} |
| 69 | + onValueChange={(nextValue) => { |
| 70 | + if (nextValue !== null) onValueChange(nextValue) |
| 71 | + }} |
| 72 | + > |
| 73 | + <SelectTrigger aria-label={typesLabel} className="w-auto"> |
| 74 | + <SelectValue className="text-text-tertiary"> |
| 75 | + {isFiltered ? undefined : typesLabel} |
| 76 | + </SelectValue> |
| 77 | + </SelectTrigger> |
| 78 | + <SelectContent className="w-55"> |
| 79 | + {options.map((option) => ( |
| 80 | + <SelectItem<AppListCategory> key={option.value} value={option.value} className="gap-1"> |
| 81 | + <span |
| 82 | + aria-hidden |
| 83 | + className={cn('h-4 w-4 shrink-0 text-text-tertiary', option.iconClassName)} |
| 84 | + /> |
| 85 | + <SelectItemText>{option.label}</SelectItemText> |
| 86 | + <SelectItemIndicator /> |
| 87 | + </SelectItem> |
| 88 | + ))} |
| 89 | + </SelectContent> |
| 90 | + </Select> |
106 | 91 | ) |
107 | 92 | } |
0 commit comments