Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix(ui): align sort controls and stabilize overlay handles (#43864)
yyheac329a614fc
diff --git a/packages/dify-ui/src/dropdown-menu/index.stories.tsx b/packages/dify-ui/src/dropdown-menu/index.stories.tsxindex 693114b97c6..23a7f1e04ff 100644--- a/packages/dify-ui/src/dropdown-menu/index.stories.tsx+++ b/packages/dify-ui/src/dropdown-menu/index.stories.tsx@@ -431,7 +431,7 @@ export const Complex: Story = {}function DetachedTriggerDemo() {- const handle = React.useMemo(() => createDropdownMenuHandle<{ name: string }>(), [])+ const [handle] = React.useState(() => createDropdownMenuHandle<{ name: string }>())const [selected, setSelected] = React.useState('')return (<React.Fragment>diff --git a/web/app/components/apps/__tests__/list.spec.tsx b/web/app/components/apps/__tests__/list.spec.tsxindex d0f281bbe21..88fce2a74c6 100644--- a/web/app/components/apps/__tests__/list.spec.tsx+++ b/web/app/components/apps/__tests__/list.spec.tsx@@ -531,7 +531,7 @@ const openAppTypeSelect = async (user = userEvent.setup()) => {}const openAppSortSelect = async (user = userEvent.setup()) => {- await user.click(screen.getByRole('button', { name: 'Sort by Last modified' }))+ await user.click(screen.getByRole('combobox', { name: 'Sort by' }))return user}@@ -616,7 +616,7 @@ describe('List', () => {const searchInput = screen.getByRole('searchbox', {name: 'app.gotoAnything.actions.searchApplications',})- const sortButton = screen.getByRole('button', { name: 'Sort by Last modified' })+ const sortButton = screen.getByRole('combobox', { name: 'Sort by' })const snippetsLink = screen.getByRole('link', { name: 'app.studio.viewSnippets' })const createButton = screen.getByRole('button', { name: 'common.operation.create' })@@ -1240,15 +1240,44 @@ describe('List', () => {}})- it('should update app list query when sort option changes', async () => {+ it.each([+ ['earliest_created', 'earliest_created', 'Earliest created'],+ ['invalid', 'last_modified', 'Last modified'],+ ])('should resolve URL sort %s for the control and query', (urlSort, expectedSort, label) => {+ renderList(`?sort_by=${urlSort}`)++ expect(screen.getByRole('combobox', { name: 'Sort by' })).toHaveTextContent(label)+ const options = mockAppListInfiniteOptions.mock.calls.at(-1)?.[0] as AppListInfiniteOptions+ expect(options.input(1).query.sort_by).toBe(expectedSort)+ })++ it('should update URL and query sorting while preserving filters and resetting scroll', async () => {const user = userEvent.setup()- renderList()+ const { onUrlUpdate } = renderList('?category=workflow&keywords=sales')+ const scrollContainer = screen.getByRole('region', { name: 'navigation.menus.apps' })+ const scrollTo = vi.fn()+ scrollContainer.scrollTo = scrollToawait openAppSortSelect(user)- await user.click(await screen.findByRole('menuitemradio', { name: 'Recently created' }))+ await user.click(await screen.findByRole('option', { name: 'Recently created' }))const options = mockAppListInfiniteOptions.mock.calls.at(-1)?.[0] as AppListInfiniteOptionsexpect(options.input(1).query.sort_by).toBe('recently_created')+ expect(scrollTo).toHaveBeenCalledWith({ top: 0 })+ await waitFor(() => {+ const params = onUrlUpdate.mock.calls.at(-1)?.[0].searchParams+ expect(params?.get('sort_by')).toBe('recently_created')+ expect(params?.get('category')).toBe('workflow')+ expect(params?.get('keywords')).toBe('sales')+ })++ await openAppSortSelect(user)+ await user.click(await screen.findByRole('option', { name: 'Last modified' }))++ await waitFor(() => {+ expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.has('sort_by')).toBe(false)+ })+ expect(screen.getByRole('combobox', { name: 'Sort by' })).toHaveTextContent('Last modified')})})diff --git a/web/app/components/apps/app-sort-filter.tsx b/web/app/components/apps/app-sort-filter.tsxindex 19cc69d61c6..cf5990b77d0 100644--- a/web/app/components/apps/app-sort-filter.tsx+++ b/web/app/components/apps/app-sort-filter.tsx@@ -2,14 +2,15 @@import type { GetAppsData } from '@dify/contracts/api/console/apps/types.gen'import {- DropdownMenu,- DropdownMenuContent,- DropdownMenuRadioGroup,- DropdownMenuRadioItem,- DropdownMenuRadioItemIndicator,- DropdownMenuTrigger,-} from '@langgenius/dify-ui/dropdown-menu'-import { useMemo } from 'react'+ Select,+ SelectContent,+ SelectItem,+ SelectItemIndicator,+ SelectItemText,+ SelectTrigger,+ SelectValue,+} from '@langgenius/dify-ui/select'+import { useId } from 'react'import { useTranslation } from 'react-i18next'type AppListQuery = NonNullable<GetAppsData['query']>@@ -22,52 +23,51 @@ type AppSortFilterProps = {export function AppSortFilter({ value, onChange }: AppSortFilterProps) {const { t } = useTranslation(['app'])+ const sortLabelId = useId()- const options = useMemo(- () =>- [- { value: 'last_modified', text: t(($) => $['studio.sort.lastModified'], { ns: 'app' }) },- {- value: 'recently_created',- text: t(($) => $['studio.sort.recentlyCreated'], { ns: 'app' }),- },- {- value: 'earliest_created',- text: t(($) => $['studio.sort.earliestCreated'], { ns: 'app' }),- },- ] satisfies Array<{ value: AppListSortBy; text: string }>,- [t],- )+ const options = [+ { value: 'last_modified', label: t(($) => $['studio.sort.lastModified'], { ns: 'app' }) },+ {+ value: 'recently_created',+ label: t(($) => $['studio.sort.recentlyCreated'], { ns: 'app' }),+ },+ {+ value: 'earliest_created',+ label: t(($) => $['studio.sort.earliestCreated'], { ns: 'app' }),+ },+ ] satisfies Array<{ value: AppListSortBy; label: string }>- const activeOption = options.find((option) => option.value === value) ?? options[0]!const sortByLabel = t(($) => $['studio.sort.sortBy'], { ns: 'app' })return (- <DropdownMenu>- <DropdownMenuTrigger className="flex h-8 cursor-pointer items-center rounded-lg border-none bg-components-input-bg-normal py-1 pr-2.5 pl-2 text-left whitespace-nowrap hover:bg-state-base-hover data-popup-open:bg-state-base-hover">- <span className="flex items-center gap-1 p-1 text-[13px] leading-4 whitespace-nowrap">- <span className="font-normal text-text-tertiary">{sortByLabel}</span>{' '}- <span className="font-medium text-text-secondary">{activeOption.text}</span>+ <Select<AppListSortBy>+ items={options}+ value={value}+ onValueChange={(nextValue) => {+ if (nextValue !== null) onChange(nextValue)+ }}+ >+ <SelectTrigger aria-labelledby={sortLabelId} className="w-auto">+ <span className="flex min-w-0 items-center gap-1 whitespace-nowrap">+ {/* aria-labelledby names the control; exclude this prefix from its accessible value. */}+ <span+ id={sortLabelId}+ aria-hidden="true"+ className="shrink-0 font-normal text-text-tertiary"+ >+ {sortByLabel}+ </span>{' '}+ <SelectValue className="min-w-0 truncate font-medium text-text-secondary" /></span>- <span aria-hidden className="i-ri-arrow-down-s-line size-4 shrink-0 text-text-tertiary" />- </DropdownMenuTrigger>- <DropdownMenuContent placement="bottom-start" sideOffset={4} className="w-55">- <DropdownMenuRadioGroup<AppListSortBy>- value={value}- onValueChange={(nextValue) => onChange(nextValue)}- >- {options.map((option) => (- <DropdownMenuRadioItem<AppListSortBy>- key={option.value}- value={option.value}- closeOnClick- >- <span className="min-w-0 flex-1 truncate">{option.text}</span>- <DropdownMenuRadioItemIndicator />- </DropdownMenuRadioItem>- ))}- </DropdownMenuRadioGroup>- </DropdownMenuContent>- </DropdownMenu>+ </SelectTrigger>+ <SelectContent>+ {options.map((option) => (+ <SelectItem<AppListSortBy> key={option.value} value={option.value}>+ <SelectItemText>{option.label}</SelectItemText>+ <SelectItemIndicator />+ </SelectItem>+ ))}+ </SelectContent>+ </Select>)}diff --git a/web/app/components/apps/list.tsx b/web/app/components/apps/list.tsxindex 69e9b9ab0c0..39193ae7ee1 100644--- a/web/app/components/apps/list.tsx+++ b/web/app/components/apps/list.tsx@@ -39,10 +39,9 @@ export function List({ onCreateLearnDify, onTryLearnDify }: Props) {const workspacePermissionKeys = useAtomValue(workspacePermissionKeysAtom)const [urlQuery, setUrlQuery] = useQueryStates(appListQueryParsers)- const { category, keywords } = urlQuery+ const { category, keywords, sort_by: sortBy } = urlQueryconst [creatorIDs, setCreatorIDs] = useState<string[]>([])const [tagIDs, setTagIDs] = useState<string[]>([])- const [sortBy, setSortBy] = useState<AppListSortBy>('last_modified')const debouncedKeywords = useDebounce(keywords, { wait: APP_LIST_SEARCH_DEBOUNCE_MS })const dropZoneRef = useRef<HTMLDivElement>(null)const scrollViewportRef = useRef<HTMLDivElement>(null)@@ -106,7 +105,7 @@ export function List({ onCreateLearnDify, onTryLearnDify }: Props) {}const changeSortBy = (nextSortBy: AppListSortBy) => {resetCatalogScroll()- setSortBy(nextSortBy)+ void setUrlQuery({ sort_by: nextSortBy })}const openCreateBlankModal = useCallback(() => {diff --git a/web/app/components/apps/query-params.ts b/web/app/components/apps/query-params.tsindex fd3864628bf..ab38f4c5fe3 100644--- a/web/app/components/apps/query-params.ts+++ b/web/app/components/apps/query-params.ts@@ -1,7 +1,7 @@import type { GetAppsData } from '@dify/contracts/api/console/apps/types.gen'import type { inferParserType } from 'nuqs'import { zGetAppsQuery } from '@dify/contracts/api/console/apps/zod.gen'-import { createParser, debounce, parseAsString } from 'nuqs'+import { createParser, debounce, parseAsString, parseAsStringLiteral } from 'nuqs'import { APP_LIST_SEARCH_DEBOUNCE_MS } from './constants'type AppListMode = NonNullable<NonNullable<GetAppsData['query']>['mode']>@@ -32,6 +32,9 @@ const parseAsAppListCategory = createParser({export const appListQueryParsers = {category: parseAsAppListCategory,+ sort_by: parseAsStringLiteral(zGetAppsQuery.shape.sort_by.unwrap().unwrap().options).withDefault(+ zGetAppsQuery.shape.sort_by.parse(undefined),+ ),keywords: parseAsString.withDefault('').withOptions({limitUrlUpdates: debounce(APP_LIST_SEARCH_DEBOUNCE_MS),}),diff --git a/web/app/components/header/account-setting/model-provider-page/model-selector/popup.tsx b/web/app/components/header/account-setting/model-provider-page/model-selector/popup.tsxindex a5de2b71f36..cb408a43478 100644--- a/web/app/components/header/account-setting/model-provider-page/model-selector/popup.tsx+++ b/web/app/components/header/account-setting/model-provider-page/model-selector/popup.tsx@@ -85,10 +85,7 @@ function Popup({const { t } = useTranslation(['common', 'modelProvider'])const { theme } = useTheme()const language = useLanguage()- const previewCardHandle = useMemo(- () => createPreviewCardHandle<ModelSelectorPreviewPayload>(),- [],- )+ const [previewCardHandle] = useState(() => createPreviewCardHandle<ModelSelectorPreviewPayload>())const [marketplaceCollapsed, setMarketplaceCollapsed] = useState(false)const [showIncompatibleModels, setShowIncompatibleModels] = useState(false)const { data: providerSummary } = useQuery(diff --git a/web/features/agent-v2/roster/components/__tests__/roster-toolbar.spec.tsx b/web/features/agent-v2/roster/components/__tests__/roster-toolbar.spec.tsxindex 89471ad692f..57def70118f 100644--- a/web/features/agent-v2/roster/components/__tests__/roster-toolbar.spec.tsx+++ b/web/features/agent-v2/roster/components/__tests__/roster-toolbar.spec.tsx@@ -171,6 +171,17 @@ describe('RosterToolbar', () => {)})+ it.each([+ ['earliest_created', 'agentRoster.roster.sort.earliestCreated'],+ ['invalid', 'agentRoster.roster.sort.lastModified'],+ ])('resolves URL sort %s to its selected label', (sortBy, label) => {+ renderToolbar({ searchParams: `?sort_by=${sortBy}` })++ expect(+ screen.getByRole('combobox', { name: 'agentRoster.roster.sort.label' }),+ ).toHaveTextContent(label)+ })+it('renders sort options and emits the selected sort strategy', async () => {const user = userEvent.setup()const { onUrlUpdate } = renderToolbar()@@ -189,5 +200,7 @@ describe('RosterToolbar', () => {queryString: '?sort_by=recently_created',}),)+ expect(sortSelect).toHaveAccessibleName('agentRoster.roster.sort.label')+ expect(sortSelect).toHaveTextContent('agentRoster.roster.sort.recentlyCreated')})})diff --git a/web/features/agent-v2/roster/components/roster-sort-select.tsx b/web/features/agent-v2/roster/components/roster-sort-select.tsxindex b12893d315c..7f32415b4e8 100644--- a/web/features/agent-v2/roster/components/roster-sort-select.tsx+++ b/web/features/agent-v2/roster/components/roster-sort-select.tsx@@ -1,5 +1,6 @@'use client'+import type { inferParserType } from 'nuqs'import {Select,SelectContent,@@ -7,45 +8,60 @@ import {SelectItemIndicator,SelectItemText,SelectTrigger,+ SelectValue,} from '@langgenius/dify-ui/select'import { useQueryState } from 'nuqs'+import { useId } from 'react'import { useTranslation } from 'react-i18next'import { rosterQueryParamNames, rosterSortByQueryParser } from '../query-params'-import { DEFAULT_ROSTER_SORT_BY, rosterSortOptions } from './roster-sort'++type RosterSortBy = inferParserType<typeof rosterSortByQueryParser>export function RosterSortSelect() {const { t } = useTranslation(['agentRoster'])+ const sortLabelId = useId()const [value, setValue] = useQueryState(rosterQueryParamNames.sortBy, rosterSortByQueryParser)- const selectedOption =- rosterSortOptions.find((option) => option.value === value) ??- rosterSortOptions.find((option) => option.value === DEFAULT_ROSTER_SORT_BY)!+ const options = [+ {+ value: 'last_modified',+ label: t(($) => $['roster.sort.lastModified'], { ns: 'agentRoster' }),+ },+ {+ value: 'recently_created',+ label: t(($) => $['roster.sort.recentlyCreated'], { ns: 'agentRoster' }),+ },+ {+ value: 'earliest_created',+ label: t(($) => $['roster.sort.earliestCreated'], { ns: 'agentRoster' }),+ },+ ] satisfies Array<{ value: RosterSortBy; label: string }>+ const sortByLabel = t(($) => $['roster.sort.label'], { ns: 'agentRoster' })return (- <Select+ <Select<RosterSortBy>+ items={options}value={value}onValueChange={(nextValue) => {- void setValue(nextValue)+ if (nextValue !== null) void setValue(nextValue)}}>- <SelectTrigger- aria-label={t(($) => $['roster.sort.label'], { ns: 'agentRoster' })}- className="h-8 w-fit max-w-45 min-w-0 gap-0 py-1 pr-2.5 pl-2"- >- <span className="flex min-w-0 items-center gap-1 px-1">- <span className="shrink-0 system-sm-regular text-text-tertiary">- {t(($) => $['roster.sort.label'], { ns: 'agentRoster' })}- </span>- <span className="truncate system-sm-medium text-text-secondary">- {t(($) => $[selectedOption.labelKey], { ns: 'agentRoster' })}- </span>+ <SelectTrigger aria-labelledby={sortLabelId} className="w-auto max-w-45 min-w-0">+ <span className="flex min-w-0 items-center gap-1 whitespace-nowrap">+ {/* aria-labelledby names the control; exclude this prefix from its accessible value. */}+ <span+ id={sortLabelId}+ aria-hidden="true"+ className="shrink-0 font-normal text-text-tertiary"+ >+ {sortByLabel}+ </span>{' '}+ <SelectValue className="min-w-0 truncate font-medium text-text-secondary" /></span></SelectTrigger>- <SelectContent placement="bottom-start" sideOffset={4} className="w-60">- {rosterSortOptions.map((option) => (- <SelectItem key={option.value} value={option.value}>- <SelectItemText title={t(($) => $[option.labelKey], { ns: 'agentRoster' })}>- {t(($) => $[option.labelKey], { ns: 'agentRoster' })}- </SelectItemText>+ <SelectContent>+ {options.map((option) => (+ <SelectItem<RosterSortBy> key={option.value} value={option.value}>+ <SelectItemText>{option.label}</SelectItemText><SelectItemIndicator /></SelectItem>))}diff --git a/web/features/agent-v2/roster/components/roster-sort.ts b/web/features/agent-v2/roster/components/roster-sort.tsdeleted file mode 100644index 68389c59121..00000000000--- a/web/features/agent-v2/roster/components/roster-sort.ts+++ /dev/null@@ -1,23 +0,0 @@-import type { GetAgentData } from '@dify/contracts/api/console/agent/types.gen'--export type RosterSortBy = NonNullable<NonNullable<GetAgentData['query']>['sort_by']>--export const DEFAULT_ROSTER_SORT_BY = 'last_modified' satisfies RosterSortBy--export const ROSTER_SORT_BY_VALUES = [- DEFAULT_ROSTER_SORT_BY,- 'recently_created',- 'earliest_created',-] as const satisfies readonly RosterSortBy[]--export const rosterSortOptions: Array<{- value: RosterSortBy- labelKey:- | 'roster.sort.lastModified'- | 'roster.sort.recentlyCreated'- | 'roster.sort.earliestCreated'-}> = [- { value: 'last_modified', labelKey: 'roster.sort.lastModified' },- { value: 'recently_created', labelKey: 'roster.sort.recentlyCreated' },- { value: 'earliest_created', labelKey: 'roster.sort.earliestCreated' },-]diff --git a/web/features/agent-v2/roster/query-params.ts b/web/features/agent-v2/roster/query-params.tsindex b47ac742b49..9f45e965560 100644--- a/web/features/agent-v2/roster/query-params.ts+++ b/web/features/agent-v2/roster/query-params.ts@@ -1,6 +1,6 @@+import { zGetAgentQuery } from '@dify/contracts/api/console/agent/zod.gen'import { debounce, parseAsBoolean, parseAsString, parseAsStringLiteral } from 'nuqs'import { ROSTER_FILTER_VALUES } from './components/roster-filter'-import { DEFAULT_ROSTER_SORT_BY, ROSTER_SORT_BY_VALUES } from './components/roster-sort'export const rosterQueryParamNames = {keyword: 'keyword',@@ -17,5 +17,6 @@ export const rosterFilterQueryParser = parseAsStringLiteral(ROSTER_FILTER_VALUESexport const rosterCreatedByMeQueryParser = parseAsBoolean.withDefault(false)-export const rosterSortByQueryParser =- parseAsStringLiteral(ROSTER_SORT_BY_VALUES).withDefault(DEFAULT_ROSTER_SORT_BY)+export const rosterSortByQueryParser = parseAsStringLiteral(+ zGetAgentQuery.shape.sort_by.unwrap().unwrap().options,+).withDefault(zGetAgentQuery.shape.sort_by.parse(undefined))