Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions web/app/components/apps/__tests__/list.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ type AppStarredListQueryOptions = {
}

const openAppTypeSelect = async (user = userEvent.setup()) => {
await user.click(screen.getByRole('button', { name: /^(Types|app\.types\.)/ }))
await user.click(screen.getByRole('combobox', { name: 'Types' }))
return user
}

Expand Down Expand Up @@ -869,7 +869,7 @@ describe('List', () => {
expect(screen.getByText('app.firstEmpty.title'))!.toBeInTheDocument()
expect(screen.getByText('app.firstEmpty.learnDifyTitle'))!.toBeInTheDocument()
expect(screen.getByText('app.firstEmpty.or'))!.toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Types' }))!.toBeInTheDocument()
expect(screen.getByRole('combobox', { name: 'Types' }))!.toBeInTheDocument()
expect(screen.queryByTestId('new-app-card')).not.toBeInTheDocument()
expect(screen.queryByTestId('empty-state')).not.toBeInTheDocument()
expect(
Expand Down Expand Up @@ -911,7 +911,7 @@ describe('List', () => {
renderList()

expect(screen.queryByText('app.firstEmpty.title')).not.toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Types' }))!.toBeInTheDocument()
expect(screen.getByRole('combobox', { name: 'Types' }))!.toBeInTheDocument()
})

it('should not render first empty state from placeholder data during a filter transition', () => {
Expand All @@ -936,7 +936,7 @@ describe('List', () => {
'aria-busy',
'false',
)
expect(screen.getByRole('button', { name: 'Types' }))!.toBeInTheDocument()
expect(screen.getByRole('combobox', { name: 'Types' }))!.toBeInTheDocument()
expect(screen.queryByTestId('new-app-card')).not.toBeInTheDocument()
expect(screen.queryByText('app.firstEmpty.title')).not.toBeInTheDocument()
})
Expand Down Expand Up @@ -1033,13 +1033,15 @@ describe('List', () => {
it('should render selected category in the trigger', () => {
renderList('?category=workflow')

expect(screen.getByRole('button', { name: 'app.types.workflow' }))!.toBeInTheDocument()
expect(screen.getByRole('combobox', { name: 'Types' })).toHaveTextContent(
'app.types.workflow',
)
})

it('should reject API modes that the Studio category control does not support', () => {
renderList('?category=channel')

expect(screen.getByRole('button', { name: 'Types' })).toBeInTheDocument()
expect(screen.getByRole('combobox', { name: 'Types' })).toBeInTheDocument()
const options = mockAppListInfiniteOptions.mock.calls.at(-1)?.[0] as AppListInfiniteOptions
expect(options.input(1).query).not.toHaveProperty('mode')
})
Expand All @@ -1049,7 +1051,7 @@ describe('List', () => {
const { onUrlUpdate } = renderList()
await openAppTypeSelect(user)

await user.click(await screen.findByRole('menuitemradio', { name: 'app.types.workflow' }))
await user.click(await screen.findByRole('option', { name: 'app.types.workflow' }))

await waitFor(() => expect(onUrlUpdate).toHaveBeenCalled())
expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.get('category')).toBe(
Expand All @@ -1062,10 +1064,15 @@ describe('List', () => {
const { onUrlUpdate } = renderList('?category=workflow')
await openAppTypeSelect(user)

await user.click(await screen.findByRole('menuitemradio', { name: 'All' }))
expect(await screen.findByRole('option', { name: 'app.types.workflow' })).toHaveAttribute(
'aria-selected',
'true',
)
await user.click(screen.getByRole('option', { name: 'All' }))

await waitFor(() => expect(onUrlUpdate).toHaveBeenCalled())
expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.has('category')).toBe(false)
expect(screen.getByRole('combobox', { name: 'Types' })).toHaveTextContent('Types')
})
})

Expand Down Expand Up @@ -1237,7 +1244,7 @@ describe('List', () => {
const user = userEvent.setup()
const { onUrlUpdate, unmount } = renderList()
await openAppTypeSelect(user)
await user.click(await screen.findByRole('menuitemradio', { name: text }))
await user.click(await screen.findByRole('option', { name: text }))
await waitFor(() => expect(onUrlUpdate).toHaveBeenCalled())
expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.get('category')).toBe(mode)
unmount()
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/apps/app-list-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function AppListHeader({
>
<div className="flex flex-wrap items-start justify-between gap-2">
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-2">
<AppTypeFilter value={category} onChange={onCategoryChange} />
<AppTypeFilter value={category} onValueChange={onCategoryChange} />
<TagFilter
type="app"
value={tagIDs}
Expand Down
103 changes: 44 additions & 59 deletions web/app/components/apps/app-type-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,105 +3,90 @@
import type { AppListUrlQuery } from './query-params'
import { cn } from '@langgenius/dify-ui/cn'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuRadioItemIndicator,
DropdownMenuTrigger,
} from '@langgenius/dify-ui/dropdown-menu'
Select,
SelectContent,
SelectItem,
SelectItemIndicator,
SelectItemText,
SelectTrigger,
SelectValue,
} from '@langgenius/dify-ui/select'
import { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { studioAppListCategories } from './query-params'

type AppListCategory = AppListUrlQuery['category']

const chipClassName =
'flex h-8 items-center whitespace-nowrap rounded-lg border-[0.5px] px-2 text-[13px] leading-4 transition-colors'

type AppTypeFilterProps = {
value: AppListCategory
onChange: (value: AppListCategory) => void
onValueChange: (value: AppListCategory) => void
}

export function AppTypeFilter({ value, onChange }: AppTypeFilterProps) {
export function AppTypeFilter({ value, onValueChange }: AppTypeFilterProps) {
const { t } = useTranslation(['app'])

const options = useMemo(() => {
const optionsByCategory = {
all: {
text: t(($) => $['types.all'], { ns: 'app' }),
label: t(($) => $['types.all'], { ns: 'app' }),
iconClassName: 'i-ri-apps-2-line',
},
workflow: {
text: t(($) => $['types.workflow'], { ns: 'app' }),
label: t(($) => $['types.workflow'], { ns: 'app' }),
iconClassName: 'i-ri-exchange-2-line',
},
'advanced-chat': {
text: t(($) => $['types.advanced'], { ns: 'app' }),
label: t(($) => $['types.advanced'], { ns: 'app' }),
iconClassName: 'i-ri-message-3-line',
},
chat: {
text: t(($) => $['types.chatbot'], { ns: 'app' }),
label: t(($) => $['types.chatbot'], { ns: 'app' }),
iconClassName: 'i-ri-message-3-line',
},
'agent-chat': {
text: t(($) => $['types.agent'], { ns: 'app' }),
label: t(($) => $['types.agent'], { ns: 'app' }),
iconClassName: 'i-ri-robot-3-line',
},
completion: {
text: t(($) => $['newApp.completeApp'], { ns: 'app' }),
label: t(($) => $['newApp.completeApp'], { ns: 'app' }),
iconClassName: 'i-ri-file-4-line',
},
} satisfies Record<AppListCategory, { text: string; iconClassName: string }>
} satisfies Record<AppListCategory, { label: string; iconClassName: string }>

return studioAppListCategories.map((value) => ({
value,
...optionsByCategory[value],
}))
}, [t])

const activeOption = options.find((option) => option.value === value)
const isSelected = value !== 'all'
const triggerLabel = isSelected
? activeOption?.text
: t(($) => $['studio.filters.types'], { ns: 'app' })
const isFiltered = value !== 'all'
const typesLabel = t(($) => $['studio.filters.types'], { ns: 'app' })

return (
<DropdownMenu>
<DropdownMenuTrigger
render={
<button
type="button"
className={cn(
chipClassName,
isSelected
? 'border-components-button-secondary-border bg-components-button-secondary-bg shadow-xs hover:bg-state-base-hover'
: 'border-transparent bg-components-input-bg-normal text-text-tertiary hover:bg-components-input-bg-hover',
)}
/>
}
>
<span className="px-1 text-text-tertiary">{triggerLabel}</span>
<span aria-hidden className="i-ri-arrow-down-s-line h-4 w-4 shrink-0 text-text-tertiary" />
</DropdownMenuTrigger>
<DropdownMenuContent placement="bottom-start" className="w-55">
<DropdownMenuRadioGroup<AppListCategory>
value={value}
onValueChange={(nextValue) => onChange(nextValue)}
>
{options.map((option) => (
<DropdownMenuRadioItem<AppListCategory> key={option.value} value={option.value}>
<span
aria-hidden
className={cn('h-4 w-4 shrink-0 text-text-tertiary', option.iconClassName)}
/>
<span>{option.text}</span>
<DropdownMenuRadioItemIndicator />
</DropdownMenuRadioItem>
))}
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
<Select<AppListCategory>
items={options}
value={value}
onValueChange={(nextValue) => {
if (nextValue !== null) onValueChange(nextValue)
}}
>
<SelectTrigger aria-label={typesLabel} className="w-auto">
<SelectValue className="text-text-tertiary">
{isFiltered ? undefined : typesLabel}
</SelectValue>
</SelectTrigger>
<SelectContent className="w-55">
{options.map((option) => (
<SelectItem<AppListCategory> key={option.value} value={option.value} className="gap-1">
<span
aria-hidden
className={cn('h-4 w-4 shrink-0 text-text-tertiary', option.iconClassName)}
/>
<SelectItemText>{option.label}</SelectItemText>
<SelectItemIndicator />
</SelectItem>
))}
</SelectContent>
</Select>
)
}
Loading