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
refactor(web): colocate icon picker entries and editing sessions (#43523)
yyh8c72fd0a43af
diff --git a/web/app/components/app/configuration/tools/external-data-tool-modal.tsx b/web/app/components/app/configuration/tools/external-data-tool-modal.tsxindex 73c792e14e1..cfa2c4bff0a 100644--- a/web/app/components/app/configuration/tools/external-data-tool-modal.tsx+++ b/web/app/components/app/configuration/tools/external-data-tool-modal.tsx@@ -16,9 +16,13 @@ import { useState } from 'react'import { useTranslation } from 'react-i18next'import { useLocale } from '#i18n'import { toast } from '@/app/components/app/configuration/toast'-import AppIcon from '@/app/components/base/app-icon'import FormGeneration from '@/app/components/base/features/new-feature-panel/moderation/form-generation'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import { ApiBasedExtensionSelector } from '@/app/components/header/account-setting/api-based-extension-page/selector'import { useDocLink } from '@/context/i18n'import { useCodeBasedExtensions } from '@/service/use-common'@@ -45,7 +49,6 @@ const ExternalDataToolModal: FC<ExternalDataToolModalProps> = ({const docLink = useDocLink()const locale = useLocale()const [localeData, setLocaleData] = useState(data.type ? data : { ...data, type: 'api' })- const [showEmojiPicker, setShowEmojiPicker] = useState(false)const { data: codeBasedExtensionList } = useCodeBasedExtensions('external_data_tool')const providers = buildProviders({@@ -156,20 +159,33 @@ const ExternalDataToolModal: FC<ExternalDataToolModalProps> = ({t(($) => $['feature.tools.modal.name.placeholder'], { ns: 'appDebug' }) || ''}/>- <button- type="button"- aria-label={t(($) => $['iconPicker.title'], { ns: 'app' })}- className="shrink-0 cursor-pointer rounded-lg focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"- onClick={() => setShowEmojiPicker(true)}+ <IconPicker+ value={+ localeData.icon+ ? {+ type: 'emoji',+ icon: localeData.icon,+ background: localeData.icon_background,+ }+ : undefined+ }+ onValueChange={(value) => {+ if (value.type !== 'emoji') return+ const { icon, background: icon_background } = value+ handleValueChange({ icon, icon_background })+ }}>- <AppIcon- decorative- size="large"- className="h-9! w-9! rounded-lg border-[0.5px] border-components-panel-border"- icon={localeData.icon}- background={localeData.icon_background}- />- </button>+ <IconPickerTrigger+ aria-label={t(($) => $['iconPicker.title'], { ns: 'app' })}+ className="shrink-0 cursor-pointer rounded-lg"+ >+ <IconPickerIcon+ size="large"+ className="h-9! w-9! rounded-lg border-[0.5px] border-components-panel-border"+ />+ </IconPickerTrigger>+ <IconPickerContent enableImageUpload={false} />+ </IconPicker></div></div><div className="py-2">@@ -223,25 +239,6 @@ const ExternalDataToolModal: FC<ExternalDataToolModalProps> = ({{t(($) => $['operation.save'], { ns: 'common' })}</Button></div>- <IconPickerDialog- enableImageUpload={false}- defaultValue={- localeData.icon- ? {- type: 'emoji',- icon: localeData.icon,- background: localeData.icon_background,- }- : undefined- }- open={showEmojiPicker}- onOpenChange={setShowEmojiPicker}- onConfirm={(value) => {- if (value.type !== 'emoji') return- const { icon, background: icon_background } = value- handleValueChange({ icon, icon_background })- }}- /></DialogContent></Dialog>)diff --git a/web/app/components/app/create-app-modal/__tests__/index.spec.tsx b/web/app/components/app/create-app-modal/__tests__/index.spec.tsxindex fe8ba1f4cb8..220fd22dca5 100644--- a/web/app/components/app/create-app-modal/__tests__/index.spec.tsx+++ b/web/app/components/app/create-app-modal/__tests__/index.spec.tsx@@ -1,5 +1,6 @@import type { AppDetail } from '@dify/contracts/api/console/apps/types.gen'import type { ReactElement } from 'react'+import { HotkeyManager } from '@tanstack/react-hotkeys'import { fireEvent, screen, waitFor } from '@testing-library/react'import userEvent from '@testing-library/user-event'import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'@@ -124,6 +125,7 @@ function render(ui: ReactElement) {describe('CreateAppModal', () => {beforeEach(() => {vi.clearAllMocks()+ HotkeyManager.resetInstance()mockUseRouter.mockReturnValue({ push: mockPush } as unknown as ReturnType<typeof useRouter>)appQuota = { size: 0, limit: 1 }mockConsoleStateReader.mockReturnValue({@@ -242,45 +244,91 @@ describe('CreateAppModal', () => {expect(onCreateFromTemplate).toHaveBeenCalled()})- it('creates a beginner chat app with the keyboard shortcut and selected icon style', async () => {- mockCreateApp.mockResolvedValue(- createAppDetailFixture({ id: 'chat-app', mode: AppModeEnum.CHAT }),- )- renderModal()-- fireEvent.click(screen.getByText('app.newApp.forBeginners'))- fireEvent.click(screen.getByText('app.types.chatbot'))- fireEvent.click(screen.getByRole('button', { name: 'app.iconPicker.title' }))- await waitFor(() => {- expect(screen.getByPlaceholderText('app.iconPicker.search')).toBeInTheDocument()- })- fireEvent.click(screen.getByRole('radio', { name: 'app.iconPicker.color.green' }))- fireEvent.click(screen.getByRole('button', { name: /iconPicker\.ok/ }))- await waitFor(() => {- expect(screen.queryByPlaceholderText('app.iconPicker.search')).not.toBeInTheDocument()- })- fireEvent.change(screen.getByPlaceholderText('app.newApp.appNamePlaceholder'), {- target: { value: 'Keyboard App' },- })- fireEvent.change(screen.getByPlaceholderText('app.newApp.appDescriptionPlaceholder'), {- target: { value: 'Created from shortcut' },- })+ it.each([+ { platform: 'Win32', modifier: { ctrlKey: true } },+ { platform: 'MacIntel', modifier: { metaKey: true } },+ ])(+ 'creates a beginner chat app from its scoped $platform shortcut and selected icon style',+ async ({ platform, modifier }) => {+ vi.spyOn(navigator, 'platform', 'get').mockReturnValue(platform)+ mockCreateApp.mockResolvedValue(+ createAppDetailFixture({ id: 'chat-app', mode: AppModeEnum.CHAT }),+ )+ renderModal()- const nameInput = screen.getByPlaceholderText('app.newApp.appNamePlaceholder')- fireEvent.keyDown(nameInput, { key: 'Enter', code: 'Enter', ctrlKey: true })- fireEvent.keyUp(nameInput, { key: 'Enter', code: 'Enter', ctrlKey: true })+ fireEvent.click(screen.getByText('app.newApp.forBeginners'))+ fireEvent.click(screen.getByText('app.types.chatbot'))+ fireEvent.change(screen.getByPlaceholderText('app.newApp.appNamePlaceholder'), {+ target: { value: 'Keyboard App' },+ })+ fireEvent.click(screen.getByRole('button', { name: 'app.iconPicker.title' }))+ await waitFor(() => {+ expect(screen.getByPlaceholderText('app.iconPicker.search')).toBeInTheDocument()+ })+ const pickerSearch = screen.getByPlaceholderText('app.iconPicker.search')+ fireEvent.keyDown(pickerSearch, { key: 'Enter', code: 'Enter', ...modifier })+ fireEvent.keyUp(pickerSearch, { key: 'Enter', code: 'Enter', ...modifier })+ expect(mockCreateApp).not.toHaveBeenCalled()+ fireEvent.click(screen.getByRole('radio', { name: 'app.iconPicker.color.green' }))+ fireEvent.click(screen.getByRole('button', { name: /iconPicker\.ok/ }))+ await waitFor(() => {+ expect(screen.queryByPlaceholderText('app.iconPicker.search')).not.toBeInTheDocument()+ })+ fireEvent.change(screen.getByPlaceholderText('app.newApp.appDescriptionPlaceholder'), {+ target: { value: 'Created from shortcut' },+ })- await waitFor(() => {- expect(mockCreateApp).toHaveBeenCalledWith({- name: 'Keyboard App',- description: 'Created from shortcut',- icon_type: 'emoji',- icon: '🤖',- icon_background: '#F3FEE7',- mode: AppModeEnum.CHAT,+ const nameInput = screen.getByPlaceholderText('app.newApp.appNamePlaceholder')+ fireEvent.keyDown(nameInput, { key: 'Enter', code: 'Enter', ...modifier })+ fireEvent.keyUp(nameInput, { key: 'Enter', code: 'Enter', ...modifier })++ await waitFor(() => {+ expect(mockCreateApp).toHaveBeenCalledWith({+ name: 'Keyboard App',+ description: 'Created from shortcut',+ icon_type: 'emoji',+ icon: '🤖',+ icon_background: '#F3FEE7',+ mode: AppModeEnum.CHAT,+ })})- })- })+ },+ )++ it.each([+ { platform: 'Win32', modifier: { ctrlKey: true } },+ { platform: 'MacIntel', modifier: { metaKey: true } },+ ])(+ 're-registers the $platform shortcut after the outer dialog remounts its content',+ async ({ platform, modifier }) => {+ vi.spyOn(navigator, 'platform', 'get').mockReturnValue(platform)+ mockCreateApp.mockResolvedValue(+ createAppDetailFixture({ id: 'reopened-app', mode: AppModeEnum.ADVANCED_CHAT }),+ )+ const onClose = vi.fn()+ const modal = (show: boolean) => (+ <CreateAppModal+ show={show}+ onClose={onClose}+ onCreateFromTemplate={vi.fn()}+ defaultAppMode={AppModeEnum.ADVANCED_CHAT}+ />+ )+ const { rerender } = render(modal(true))+ await userEvent.setup().click(screen.getByRole('button', { name: 'app.iconPicker.title' }))+ const picker = screen.getByRole('dialog', { name: 'app.iconPicker.title' })+ rerender(modal(false))+ await waitFor(() => expect(picker).not.toBeInTheDocument())+ rerender(modal(true))+ const nameInput = screen.getByPlaceholderText('app.newApp.appNamePlaceholder')+ fireEvent.change(nameInput, { target: { value: 'Reopened App' } })+ fireEvent.keyDown(nameInput, { key: 'Enter', code: 'Enter', ...modifier })+ fireEvent.keyUp(nameInput, { key: 'Enter', code: 'Enter', ...modifier })+ await waitFor(() => expect(mockCreateApp).toHaveBeenCalledOnce())+ expect(mockCreateApp).toHaveBeenCalledWith(expect.objectContaining({ name: 'Reopened App' }))+ expect(onClose).toHaveBeenCalledOnce()+ },+ )it('keeps creation unavailable from both the button and shortcut without a name', () => {renderModal()diff --git a/web/app/components/app/create-app-modal/index.tsx b/web/app/components/app/create-app-modal/index.tsxindex dbfa05c8fc4..fec05b110f9 100644--- a/web/app/components/app/create-app-modal/index.tsx+++ b/web/app/components/app/create-app-modal/index.tsx@@ -15,8 +15,12 @@ import { useDebounceFn } from 'ahooks'import { useAtomValue } from 'jotai'import { useCallback, useId, useRef, useState } from 'react'import { useTranslation } from 'react-i18next'-import AppIcon from '@/app/components/base/app-icon'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import AppsFull from '@/app/components/billing/apps-full-in-dialog'import { toast } from '@/app/notifications'import { workspacePermissionKeysAtom } from '@/context/permission-state'@@ -60,7 +64,6 @@ function CreateApp({ onClose, onCreateFromTemplate, defaultAppMode }: CreateAppPicon: '🤖',background: '#FFEAD5',})- const [showIconPicker, setShowIconPicker] = useState(false)const [name, setName] = useState('')const [description, setDescription] = useState('')const [isAppTypeExpanded, setIsAppTypeExpanded] = useState(() =>@@ -178,7 +181,7 @@ function CreateApp({ onClose, onCreateFromTemplate, defaultAppMode }: CreateAppP},{target: contentRef,- enabled: !createDisabled && !isCreating && !showIconPicker,+ enabled: !createDisabled && !isCreating,ignoreInputs: false,preventDefault: false,stopPropagation: false,@@ -324,30 +327,15 @@ function CreateApp({ onClose, onCreateFromTemplate, defaultAppMode }: CreateAppPplaceholder={t(($) => $['newApp.appNamePlaceholder'], { ns: 'app' }) || ''}/></div>- <button- type="button"- aria-label={t(($) => $['iconPicker.title'], { ns: 'app' })}- className="shrink-0 cursor-pointer rounded-2xl focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"- onClick={() => setShowIconPicker(true)}- >- <AppIcon- decorative- iconType={appIcon.type}- icon={appIcon.type === 'emoji' ? appIcon.icon : appIcon.fileId}- background={appIcon.type === 'emoji' ? appIcon.background : undefined}- imageUrl={appIcon.type === 'image' ? appIcon.url : undefined}- size="xxl"- className="rounded-2xl"- />- </button>- <IconPickerDialog- open={showIconPicker}- defaultValue={appIcon}- onOpenChange={setShowIconPicker}- onConfirm={(payload) => {- setAppIcon(payload)- }}- />+ <IconPicker value={appIcon} onValueChange={setAppIcon}>+ <IconPickerTrigger+ aria-label={t(($) => $['iconPicker.title'], { ns: 'app' })}+ className="shrink-0 cursor-pointer rounded-2xl"+ >+ <IconPickerIcon size="xxl" className="rounded-2xl" />+ </IconPickerTrigger>+ <IconPickerContent />+ </IconPicker></div><div><div className="mb-1 flex h-6 items-center">diff --git a/web/app/components/app/duplicate-modal/__tests__/index.spec.tsx b/web/app/components/app/duplicate-modal/__tests__/index.spec.tsxindex b6423b53604..7620b09356a 100644--- a/web/app/components/app/duplicate-modal/__tests__/index.spec.tsx+++ b/web/app/components/app/duplicate-modal/__tests__/index.spec.tsx@@ -7,8 +7,11 @@ import {renderWithConsoleQuery,seedFeatures,} from '@/test/console/query-data'+import { mockEmojiData } from '@/test/emoji-picker'import DuplicateAppModal from '../index'+mockEmojiData()+const { mockAppQuota, toastErrorMock } = vi.hoisted(() => ({mockAppQuota: { size: 0, limit: 1 },toastErrorMock: vi.fn(),@@ -20,56 +23,10 @@ vi.mock('@/app/notifications', () => ({},}))-vi.mock('@/app/components/base/app-icon', () => ({- default: () => <span>app-icon</span>,-}))-vi.mock('@/app/components/billing/apps-full-in-dialog', () => ({default: () => <div>apps-full</div>,}))-vi.mock('@/app/components/base/icon-picker', () => ({- IconPickerDialog: ({- open,- onOpenChange,- onConfirm,- }: {- open: boolean- onOpenChange: (open: boolean) => void- onConfirm: (payload: { type: 'emoji'; icon: string; background: string }) => void- }) => {- if (!open) return null- let selectedBackground = '#FFEAD5'- return (- <div>- <input placeholder="Search emojis..." />- <button type="button" onClick={() => {}}>- <span>😀</span>- </button>- <button- type="button"- aria-label="#E4FBCC"- onClick={() => {- selectedBackground = '#E4FBCC'- }}- />- <button- type="button"- onClick={() => {- onConfirm({ type: 'emoji', icon: '🤖', background: selectedBackground })- onOpenChange(false)- }}- >- iconPicker.ok- </button>- <button type="button" onClick={() => onOpenChange(false)}>- iconPicker.cancel- </button>- </div>- )- },-}))-function render(ui: ReactElement) {return renderWithConsoleQuery(ui, {systemFeatures: { deployment_edition: 'CLOUD' },@@ -161,7 +118,7 @@ describe('DuplicateAppModal', () => {expect(onHide).not.toHaveBeenCalled()})- it('should update the selected icon before confirming the duplicate', async () => {+ it('keeps the picker independent of the name field and submits only its confirmed icon', async () => {const onConfirm = vi.fn()const onHide = vi.fn()const user = userEvent.setup()@@ -180,20 +137,22 @@ describe('DuplicateAppModal', () => {await user.click(getIconButton())await waitFor(() => {- expect(screen.getByPlaceholderText('Search emojis...')).toBeInTheDocument()+ expect(screen.getByPlaceholderText('app.iconPicker.search')).toBeInTheDocument()})- await user.click(screen.getByRole('button', { name: '#E4FBCC', hidden: true }))+ await user.click(screen.getByRole('radio', { name: 'app.iconPicker.color.green' }))await user.click(screen.getByRole('button', { name: /iconPicker\.ok/, hidden: true }))await waitFor(() => {- expect(screen.queryByPlaceholderText('Search emojis...')).not.toBeInTheDocument()+ expect(screen.queryByPlaceholderText('app.iconPicker.search')).not.toBeInTheDocument()})+ expect(onConfirm).not.toHaveBeenCalled()+ expect(screen.getByRole('textbox', { name: /appCustomize\.subTitle/ })).toHaveValue('Demo App')await user.click(screen.getByRole('button', { name: /(?:^|\.)duplicate(?=$|:)/ }))expect(onConfirm).toHaveBeenCalledWith({name: 'Demo App',icon_type: 'emoji',icon: '🤖',- icon_background: '#E4FBCC',+ icon_background: '#F3FEE7',})expect(onHide).toHaveBeenCalled()})@@ -280,33 +239,16 @@ describe('DuplicateAppModal', () => {)await user.click(getIconButton())- await waitFor(() => {- expect(screen.getByPlaceholderText('Search emojis...')).toBeInTheDocument()- })- const emojiButton = screen.getByText('😀').closest('button')- expect(emojiButton).toBeTruthy()- await user.click(emojiButton!)- await user.click(screen.getByRole('button', { name: '#E4FBCC', hidden: true }))- await user.click(screen.getByRole('button', { name: /iconPicker\.ok/, hidden: true }))- await waitFor(() => {- expect(screen.queryByPlaceholderText('Search emojis...')).not.toBeInTheDocument()- })- await user.click(getIconButton())- await waitFor(() => {- expect(screen.getByPlaceholderText('Search emojis...')).toBeInTheDocument()- })- await user.click(screen.getByRole('button', { name: /iconPicker\.cancel/, hidden: true }))- await waitFor(() => {- expect(screen.queryByPlaceholderText('Search emojis...')).not.toBeInTheDocument()- })+ const picker = screen.getByRole('dialog', { name: 'app.iconPicker.title' })+ await user.keyboard('{Escape}')+ await waitFor(() => expect(picker).not.toBeInTheDocument())await user.click(screen.getByRole('button', { name: /(?:^|\.)duplicate(?=$|:)/ }))expect(onConfirm).toHaveBeenCalledWith(expect.objectContaining({name: 'Image App',- icon_type: 'emoji',- icon: expect.any(String),- icon_background: '#E4FBCC',+ icon_type: 'image',+ icon: 'original-file',}),)})diff --git a/web/app/components/app/duplicate-modal/index.tsx b/web/app/components/app/duplicate-modal/index.tsxindex a25bc75aedf..4ee5a5cd019 100644--- a/web/app/components/app/duplicate-modal/index.tsx+++ b/web/app/components/app/duplicate-modal/index.tsx@@ -1,6 +1,6 @@'use client'import type { AppDetailWithSite, CopyAppPayload } from '@dify/contracts/api/console/apps/types.gen'-import type { IconPickerDefaultValue, IconPickerValue } from '@/app/components/base/icon-picker'+import type { IconPickerInputValue, IconPickerValue } from '@/app/components/base/icon-picker'import { Button } from '@langgenius/dify-ui/button'import { Dialog, DialogContent, DialogTitle } from '@langgenius/dify-ui/dialog'import { Field, FieldLabel } from '@langgenius/dify-ui/field'@@ -11,8 +11,12 @@ import { useAtomValue } from 'jotai'import * as React from 'react'import { useState } from 'react'import { useTranslation } from 'react-i18next'-import AppIcon from '@/app/components/base/app-icon'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import AppsFull from '@/app/components/billing/apps-full-in-dialog'import { toast } from '@/app/notifications'import { deploymentEditionAtom } from '@/features/system-features/state'@@ -43,15 +47,16 @@ const DuplicateAppModal = ({const [name, setName] = React.useState(appName)- const [showIconPicker, setShowIconPicker] = useState(false)const [selectedIcon, setSelectedIcon] = useState<IconPickerValue | null>(null)- const pickerDefaultValue: IconPickerDefaultValue | undefined =+ const pickerValue: IconPickerInputValue | undefined =selectedIcon ??(icon_type === 'image' && icon? { type: 'image', url: icon_url ?? '', fileId: icon }: icon_type === 'emoji' && icon? { type: 'emoji', icon, background: icon_background }- : undefined)+ : icon_type === 'link' && icon+ ? { type: 'link', url: icon }+ : undefined)const currentIcon = selectedIcon? {icon_type: selectedIcon.type,@@ -119,38 +124,29 @@ const DuplicateAppModal = ({}}><div className="mb-9 system-sm-regular text-text-secondary">- <Field name="name">- <FieldLabel className="system-md-medium">- {t(($) => $['appCustomize.subTitle'], { ns: 'explore' })}- </FieldLabel>- <div className="flex items-center justify-between space-x-2">- <button- type="button"- aria-label={`${t(($) => $['operation.edit'], { ns: 'common' })} ${t(($) => $['appCustomize.subTitle'], { ns: 'explore' })}`}- onClick={() => {- setShowIconPicker(true)- }}- className="shrink-0 cursor-pointer rounded-[10px] focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"- >- <AppIcon- size="large"- iconType={currentIcon.icon_type === 'link' ? 'image' : currentIcon.icon_type}- icon={currentIcon.icon ?? undefined}- background={currentIcon.icon_background}- imageUrl={- currentIcon.icon_type === 'link' ? currentIcon.icon : currentIcon.icon_url- }+ <IconPicker value={pickerValue} onValueChange={setSelectedIcon}>+ <Field name="name">+ <FieldLabel className="system-md-medium">+ {t(($) => $['appCustomize.subTitle'], { ns: 'explore' })}+ </FieldLabel>+ <div className="flex items-center justify-between space-x-2">+ <IconPickerTrigger+ aria-label={`${t(($) => $['operation.edit'], { ns: 'common' })} ${t(($) => $['appCustomize.subTitle'], { ns: 'explore' })}`}+ className="shrink-0 cursor-pointer rounded-[10px]"+ >+ <IconPickerIcon size="large" />+ </IconPickerTrigger>+ <Input+ autoComplete="off"+ value={name}+ onChange={(e) => setName(e.target.value)}+ className="h-10"+ placeholder={t(($) => $['placeholder.input'], { ns: 'common' }) || ''}/>- </button>- <Input- autoComplete="off"- value={name}- onChange={(e) => setName(e.target.value)}- className="h-10"- placeholder={t(($) => $['placeholder.input'], { ns: 'common' }) || ''}- />- </div>- </Field>+ </div>+ </Field>+ <IconPickerContent />+ </IconPicker>{isAppsFull && <AppsFull className="mt-4" loc="app-duplicate-create" />}</div><div className="flex flex-row-reverse">@@ -169,12 +165,6 @@ const DuplicateAppModal = ({</form></DialogContent></Dialog>- <IconPickerDialog- open={showIconPicker}- defaultValue={pickerDefaultValue}- onOpenChange={setShowIconPicker}- onConfirm={setSelectedIcon}- /></>)}diff --git a/web/app/components/app/overview/settings/index.tsx b/web/app/components/app/overview/settings/index.tsxindex 38b83b2b116..848885f672d 100644--- a/web/app/components/app/overview/settings/index.tsx+++ b/web/app/components/app/overview/settings/index.tsx@@ -40,8 +40,12 @@ import { useQueryState } from 'nuqs'import * as React from 'react'import { useCallback, useState } from 'react'import { Trans, useTranslation } from 'react-i18next'-import AppIcon from '@/app/components/base/app-icon'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import { PremiumBadgeButton } from '@/app/components/base/premium-badge'import {pricingQueryParamName,@@ -193,7 +197,6 @@ const SettingsModal: FC<ISettingsModalProps> = ({const [saveLoading, setSaveLoading] = useState(false)const { t } = useTranslation(['app', 'appOverview', 'billing', 'common'])- const [showIconPicker, setShowIconPicker] = useState(false)const [appIcon, setAppIcon] = useState<SettingsAppIconSelection>(nextAppIcon)const [previousIsShow, setPreviousIsShow] = useState(isShow)const [previousSettingsResetKey, setPreviousSettingsResetKey] = useState(settingsResetKey)@@ -441,39 +444,27 @@ const SettingsModal: FC<ISettingsModalProps> = ({placeholder={t(($) => $.appNamePlaceholder, { ns: 'app' }) || ''}/></Field>- <button- type="button"- aria-label={t(($) => $['iconPicker.title'], { ns: 'app' })}- className="mt-2 shrink-0 cursor-pointer rounded-2xl focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"- onClick={() => setShowIconPicker(true)}+ <IconPicker+ value={+ appIcon ??+ (appInfo.site.icon_type === 'emoji' && appInfo.site.icon+ ? {+ type: 'emoji',+ icon: appInfo.site.icon,+ background: appInfo.site.icon_background,+ }+ : undefined)+ }+ onValueChange={setAppIcon}>- <AppIcon- decorative- size="xxl"- iconType={- appIcon- ? appIcon.type === 'link'- ? 'image'- : appIcon.type- : appInfo.site.icon_type- }- icon={- appIcon- ? appIcon.type === 'image'- ? appIcon.fileId- : appIcon.icon- : (appInfo.site.icon ?? undefined)- }- background={- appIcon?.type === 'emoji'- ? appIcon.background- : appInfo.site.icon_background- }- imageUrl={- appIcon && appIcon.type !== 'emoji' ? appIcon.url : appInfo.site.icon_url- }- />- </button>+ <IconPickerTrigger+ aria-label={t(($) => $['iconPicker.title'], { ns: 'app' })}+ className="mt-2 shrink-0 cursor-pointer rounded-2xl"+ >+ <IconPickerIcon size="xxl" />+ </IconPickerTrigger>+ <IconPickerContent />+ </IconPicker></div>{/* description */}<Field name="description">@@ -826,12 +817,6 @@ const SettingsModal: FC<ISettingsModalProps> = ({</Form></DialogContent></Dialog>- <IconPickerDialog- open={showIconPicker}- defaultValue={appIcon?.type === 'link' ? undefined : (appIcon ?? undefined)}- onOpenChange={setShowIconPicker}- onConfirm={setAppIcon}- /></>)}diff --git a/web/app/components/app/switch-app-modal/__tests__/index.spec.tsx b/web/app/components/app/switch-app-modal/__tests__/index.spec.tsxindex 96e16a1c575..b411c7a3261 100644--- a/web/app/components/app/switch-app-modal/__tests__/index.spec.tsx+++ b/web/app/components/app/switch-app-modal/__tests__/index.spec.tsx@@ -74,12 +74,6 @@ vi.mock('@/app/components/billing/apps-full-in-dialog', () => ({),}))-vi.mock('@/app/components/base/app-icon', () => ({- default: ({ onClick }: { onClick: () => void }) => (- <button onClick={onClick}>open-icon-picker</button>- ),-}))-const createMockApp = (overrides: Partial<AppPartial> = {}): AppPartial => ({id: 'app-123',name: 'Demo App',@@ -288,7 +282,7 @@ describe('SwitchAppModal', () => {permission_keys: ['app.acl.view_layout'],})- await user.click(screen.getByText('open-icon-picker'))+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.title' }))await waitFor(() => {expect(screen.getByPlaceholderText('app.iconPicker.search')).toBeInTheDocument()})@@ -318,7 +312,7 @@ describe('SwitchAppModal', () => {const user = userEvent.setup()renderComponent()- await user.click(screen.getByText('open-icon-picker'))+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.title' }))await waitFor(() => {expect(screen.getByPlaceholderText('app.iconPicker.search')).toBeInTheDocument()})diff --git a/web/app/components/app/switch-app-modal/index.tsx b/web/app/components/app/switch-app-modal/index.tsxindex 4748e896125..b42516c4db9 100644--- a/web/app/components/app/switch-app-modal/index.tsx+++ b/web/app/components/app/switch-app-modal/index.tsx@@ -19,8 +19,12 @@ import { Input } from '@langgenius/dify-ui/input'import { useMutation, useQuery, useSuspenseQuery } from '@tanstack/react-query'import { useId, useState } from 'react'import { useTranslation } from 'react-i18next'-import AppIcon from '@/app/components/base/app-icon'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import AppsFull from '@/app/components/billing/apps-full-in-dialog'import { toast } from '@/app/notifications'import { systemFeaturesQueryOptions } from '@/features/system-features/client'@@ -60,7 +64,6 @@ const SwitchAppModal = ({ show, sourceApp, onClose }: SwitchAppModalProps) => {appQuota.limit > 0 &&appQuota.size >= appQuota.limit- const [showIconPicker, setShowIconPicker] = useState(false)const appIconType = zIconType.safeParse(sourceApp.icon_type).dataconst [appIcon, setAppIcon] = useState(appIconType === 'image'@@ -165,21 +168,15 @@ const SwitchAppModal = ({ show, sourceApp, onClose }: SwitchAppModalProps) => {{t(($) => $.switchLabel, { ns: 'app' })}</label><div className="flex items-center justify-between space-x-2">- <button- type="button"- aria-label={t(($) => $['iconPicker.title'], { ns: 'app' })}- className="shrink-0 cursor-pointer rounded-[10px] focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"- onClick={() => setShowIconPicker(true)}- >- <AppIcon- decorative- size="large"- iconType={appIcon.type}- icon={appIcon.type === 'image' ? appIcon.fileId : appIcon.icon}- background={appIcon.type === 'image' ? undefined : appIcon.background}- imageUrl={appIcon.type === 'image' ? appIcon.url : undefined}- />- </button>+ <IconPicker value={appIcon} onValueChange={setAppIcon}>+ <IconPickerTrigger+ aria-label={t(($) => $['iconPicker.title'], { ns: 'app' })}+ className="shrink-0 cursor-pointer rounded-[10px]"+ >+ <IconPickerIcon size="large" />+ </IconPickerTrigger>+ <IconPickerContent />+ </IconPicker><Inputid={nameInputId}value={name}@@ -188,14 +185,6 @@ const SwitchAppModal = ({ show, sourceApp, onClose }: SwitchAppModalProps) => {className="h-10 grow"/></div>- <IconPickerDialog- open={showIconPicker}- defaultValue={appIcon}- onOpenChange={setShowIconPicker}- onConfirm={(payload) => {- setAppIcon(payload)- }}- /></div>{isAppsFull && <AppsFull loc="app-switch" />}<div className="flex items-center justify-between pt-6">diff --git a/web/app/components/base/icon-picker/__tests__/async-session.browser.spec.tsx b/web/app/components/base/icon-picker/__tests__/async-session.browser.spec.tsxnew file mode 100644index 00000000000..89cea94e4e0--- /dev/null+++ b/web/app/components/base/icon-picker/__tests__/async-session.browser.spec.tsx@@ -0,0 +1,168 @@+import type { PostFilesUploadResponse } from '@dify/contracts/api/console/files/types.gen'+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'+import { userEvent } from 'vite-plus/test/browser'+import { render } from 'vitest-browser-react'+import { emojiCatalogOptions } from '../emoji-data'+import { IconPickerDialog } from './harness'++const { cropImage, uploadImage } = vi.hoisted(() => ({+ cropImage: vi.fn<() => Promise<Blob>>(),+ uploadImage: vi.fn<() => Promise<PostFilesUploadResponse>>(),+}))++vi.mock('../image-crop', async (importOriginal) => ({+ ...(await importOriginal<typeof import('../image-crop')>()),+ default: cropImage,+}))+vi.mock('@/service/console', () => ({+ consoleQuery: {+ files: { upload: { post: { mutationOptions: () => ({ mutationFn: uploadImage }) } } },+ },+}))+vi.mock('@/next/navigation', () => ({ useParams: () => ({}) }))++async function createImageFile() {+ const canvas = document.createElement('canvas')+ canvas.width = 100+ canvas.height = 100+ canvas.getContext('2d')!.fillRect(0, 0, 100, 100)+ const blob = await new Promise<Blob>((resolve) =>+ canvas.toBlob((value) => resolve(value!), 'image/png'),+ )+ return new File([blob], 'icon.png', { type: 'image/png' })+}++async function openImageSession() {+ const client = new QueryClient()+ client.setQueryData(emojiCatalogOptions.queryKey, [])+ const onConfirm = vi.fn()+ const screen = await render(+ <QueryClientProvider client={client}>+ <IconPickerDialog+ aria-label="Choose icon"+ value={{ type: 'emoji', icon: '😀', background: '#FEF3F2' }}+ onConfirm={onConfirm}+ />+ </QueryClientProvider>,+ )+ const trigger = screen.getByRole('button', { name: 'Choose icon' })+ await trigger.click()+ const dialog = screen.getByRole('dialog', { name: 'app.iconPicker.title' })+ await dialog.getByRole('tab', { name: 'app.iconPicker.image' }).click()+ const file = await createImageFile()+ await dialog.getByTestId('image-input').upload(file)+ await expect.element(dialog.getByRole('group', { name: 'app.iconPicker.crop' })).toBeVisible()+ const save = dialog.getByRole('button', { name: 'app.iconPicker.ok' })+ await expect.element(save).toBeEnabled()+ return { screen, client, trigger, dialog, save, file, onConfirm }+}++beforeEach(() => {+ vi.clearAllMocks()+ vi.stubGlobal('BASE_UI_ANIMATIONS_DISABLED', false)+})+afterEach(() => {+ vi.restoreAllMocks()+ vi.unstubAllGlobals()+})++it('ignores crop completion during the closing animation while Cancel remains available', async () => {+ let finishCrop!: (blob: Blob) => void+ cropImage.mockReturnValueOnce(+ new Promise<Blob>((resolve) => {+ finishCrop = resolve+ }),+ )+ const { client, trigger, dialog, save, file, onConfirm } = await openImageSession()+ const popup = dialog.element()+ await expect.poll(() => getComputedStyle(popup).opacity).toBe('1')+ await save.click()+ await expect.poll(() => cropImage.mock.calls.length).toBe(1)+ const cancel = dialog.getByRole('button', { name: 'app.iconPicker.cancel' })+ await expect.element(cancel).toBeEnabled()+ const exitFrame = new Promise<number>((resolve) => {+ const onTransition = (event: Event) => {+ if (event.target !== popup || (event as TransitionEvent).propertyName !== 'opacity') return+ popup.removeEventListener('transitionrun', onTransition)+ finishCrop(file)+ resolve(Number(getComputedStyle(popup).opacity))+ }+ popup.addEventListener('transitionrun', onTransition)+ })+ await cancel.click()+ expect(await exitFrame).toBeGreaterThan(0)+ await expect.element(dialog).not.toBeInTheDocument()+ expect(uploadImage).not.toHaveBeenCalled()+ expect(onConfirm).not.toHaveBeenCalled()+ await expect.element(trigger).toHaveFocus()+ await userEvent.keyboard('{Enter}')+ await expect+ .element(dialog.getByRole('combobox', { name: 'app.iconPicker.search' }))+ .toHaveFocus()+ await expect+ .element(dialog.getByRole('radio', { name: 'app.iconPicker.color.red' }))+ .toBeChecked()+ client.clear()+})++it('ignores a preview read that completes after cancellation and a new session opens', async () => {+ const { client, trigger, dialog, save, file, onConfirm } = await openImageSession()+ cropImage.mockResolvedValueOnce(file)+ const originalRead = FileReader.prototype.readAsDataURL+ let finishRead!: () => Promise<void>+ const read = vi.spyOn(FileReader.prototype, 'readAsDataURL').mockImplementationOnce(function (+ this: FileReader,+ blob: Blob,+ ) {+ finishRead = () =>+ new Promise<void>((resolve) => {+ this.addEventListener('loadend', () => resolve(), { once: true })+ originalRead.call(this, blob)+ })+ })+ await save.click()+ await expect.poll(() => read.mock.calls.length).toBe(1)+ await dialog.getByRole('button', { name: 'app.iconPicker.cancel' }).click()+ await expect.element(trigger).toHaveFocus()+ await userEvent.keyboard('{Enter}')+ const search = dialog.getByRole('combobox', { name: 'app.iconPicker.search' })+ await expect.element(search).toHaveFocus()+ await search.fill('new session')+ await finishRead()+ await userEvent.keyboard('{End}')+ expect(uploadImage).not.toHaveBeenCalled()+ expect(onConfirm).not.toHaveBeenCalled()+ await expect.element(dialog).toBeVisible()+ await expect.element(search).toHaveValue('new session')+ client.clear()+})++it('ignores an old upload when reopened as soon as keyboard focus returns', async () => {+ let finishUpload!: (response: PostFilesUploadResponse) => void+ const pendingUpload = new Promise<PostFilesUploadResponse>((resolve) => {+ finishUpload = resolve+ })+ uploadImage.mockReturnValueOnce(pendingUpload)+ const { client, trigger, dialog, save, file, onConfirm } = await openImageSession()+ cropImage.mockResolvedValueOnce(file)+ await save.click()+ await expect.poll(() => uploadImage.mock.calls.length).toBe(1)+ await expect.element(dialog.getByRole('button', { name: 'app.iconPicker.cancel' })).toBeEnabled()+ await userEvent.keyboard('{Escape}')+ await expect.element(trigger).toHaveFocus()+ await userEvent.keyboard('{Enter}')+ const search = dialog.getByRole('combobox', { name: 'app.iconPicker.search' })+ await expect.element(search).toHaveFocus()+ await dialog.getByRole('radio', { name: 'app.iconPicker.color.green' }).click()+ finishUpload({ id: 'old-upload', name: 'icon.png', size: file.size })+ await pendingUpload+ await search.fill('new session')+ expect(onConfirm).not.toHaveBeenCalled()+ expect(uploadImage).toHaveBeenCalledTimes(1)+ await expect.element(dialog).toBeVisible()+ await expect.element(search).toHaveValue('new session')+ await expect+ .element(dialog.getByRole('radio', { name: 'app.iconPicker.color.green' }))+ .toBeChecked()+ client.clear()+})diff --git a/web/app/components/base/icon-picker/__tests__/harness.tsx b/web/app/components/base/icon-picker/__tests__/harness.tsxnew file mode 100644index 00000000000..5df4db30071--- /dev/null+++ b/web/app/components/base/icon-picker/__tests__/harness.tsx@@ -0,0 +1,26 @@+import type { IconPickerInputValue, IconPickerValue } from '..'+import { IconPicker, IconPickerContent, IconPickerIcon, IconPickerTrigger } from '..'++type IconPickerDialogProps = {+ value?: IconPickerInputValue+ onConfirm: (value: IconPickerValue) => void+ enableImageUpload?: boolean+ 'aria-label'?: string+}++/** The picker composed as one element, for specs that exercise its session rather than its anatomy. */+export function IconPickerDialog({+ value,+ onConfirm,+ enableImageUpload,+ 'aria-label': label = 'app.iconPicker.title',+}: IconPickerDialogProps) {+ return (+ <IconPicker value={value} onValueChange={onConfirm}>+ <IconPickerTrigger aria-label={label}>+ <IconPickerIcon />+ </IconPickerTrigger>+ <IconPickerContent enableImageUpload={enableImageUpload} />+ </IconPicker>+ )+}diff --git a/web/app/components/base/icon-picker/__tests__/image-confirmation.spec.tsx b/web/app/components/base/icon-picker/__tests__/image-confirmation.spec.tsxindex 1430e18d652..6a63ee2aa97 100644--- a/web/app/components/base/icon-picker/__tests__/image-confirmation.spec.tsx+++ b/web/app/components/base/icon-picker/__tests__/image-confirmation.spec.tsx@@ -2,12 +2,12 @@ import type {PostFilesUploadData,PostFilesUploadResponse,} from '@dify/contracts/api/console/files/types.gen'-import type { IconPickerDefaultValue } from '..'+import type { IconPickerInputValue } from '..'import { QueryClient, QueryClientProvider } from '@tanstack/react-query'import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'import userEvent from '@testing-library/user-event'-import { IconPickerDialog } from '..'import { emojiCatalogOptions } from '../emoji-data'+import { IconPickerDialog } from './harness'const { uploadImage } = vi.hoisted(() => ({uploadImage:@@ -28,35 +28,30 @@ beforeEach(() => {afterEach(() => vi.restoreAllMocks())-async function selectImage(defaultValue?: IconPickerDefaultValue) {+async function selectImage(defaultValue?: IconPickerInputValue) {const user = userEvent.setup()const client = new QueryClient()client.setQueryData(emojiCatalogOptions.queryKey, [])const onConfirm = vi.fn()- const onOpenChange = vi.fn()const view = render(<QueryClientProvider client={client}>- <IconPickerDialog- open- defaultValue={defaultValue}- onConfirm={onConfirm}- onOpenChange={onOpenChange}- />+ <IconPickerDialog value={defaultValue} onConfirm={onConfirm} /></QueryClientProvider>,)+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.title' }))await user.click(screen.getByRole('tab', { name: 'app.iconPicker.image' }))if (defaultValue?.type === 'image')await user.click(screen.getByRole('button', { name: 'common.operation.change' }))const file = new File(['GIF89a'], 'icon.gif', { type: 'image/gif' })await user.upload(screen.getByTestId('image-input'), file)const confirm = await screen.findByRole('button', { name: 'app.iconPicker.ok' })- return { ...view, user, client, file, confirm, onConfirm, onOpenChange }+ return { ...view, user, client, file, confirm, onConfirm }}it('keeps the image draft after an upload failure and confirms the retried upload', async () => {uploadImage.mockRejectedValueOnce(new Error('Upload failed'))uploadImage.mockResolvedValueOnce({ id: 'uploaded-image', name: 'icon.gif', size: 6 })- const { user, client, file, confirm, onConfirm, onOpenChange } = await selectImage()+ const { user, client, file, confirm, onConfirm } = await selectImage()await user.click(confirm)await waitFor(() => expect(uploadImage).toHaveBeenCalledOnce())expect(uploadImage.mock.calls[0]![0].body.file).toBe(file)@@ -72,7 +67,7 @@ it('keeps the image draft after an upload failure and confirms the retried uploafileId: 'uploaded-image',url: expect.stringContaining('data:image/gif;base64,'),})- expect(onOpenChange).toHaveBeenCalledExactlyOnceWith(false)+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())client.clear()})@@ -83,7 +78,7 @@ it('does not confirm an upload that finishes after the picker is unmounted', asyfinishUpload = resolve}),)- const { user, client, confirm, onConfirm, onOpenChange, unmount } = await selectImage()+ const { user, client, confirm, onConfirm, unmount } = await selectImage()await user.click(confirm)await waitFor(() => expect(uploadImage).toHaveBeenCalledOnce())unmount()@@ -91,7 +86,6 @@ it('does not confirm an upload that finishes after the picker is unmounted', asyfinishUpload({ id: 'late-image', name: 'icon.gif', size: 6 })})expect(onConfirm).not.toHaveBeenCalled()- expect(onOpenChange).not.toHaveBeenCalled()expect(URL.revokeObjectURL).toHaveBeenCalledWith('blob:preview')client.clear()})@@ -104,9 +98,10 @@ it('opens the file input directly and preserves the existing image on cancellaticonst value = { type: 'image' as const, fileId: 'existing', url: '/existing.png' }render(<QueryClientProvider client={client}>- <IconPickerDialog open defaultValue={value} onConfirm={onConfirm} onOpenChange={() => {}} />+ <IconPickerDialog value={value} onConfirm={onConfirm} /></QueryClientProvider>,)+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.title' }))const input = screen.getByTestId('image-input')const openFilePicker = vi.spyOn(input, 'click')await user.click(screen.getByRole('button', { name: 'common.operation.change' }))@@ -159,14 +154,10 @@ it.each([undefined, null])(const onConfirm = vi.fn()render(<QueryClientProvider client={client}>- <IconPickerDialog- open- defaultValue={{ type: 'emoji', icon: '😀', background }}- onConfirm={onConfirm}- onOpenChange={() => {}}- />+ <IconPickerDialog value={{ type: 'emoji', icon: '😀', background }} onConfirm={onConfirm} /></QueryClientProvider>,)+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.title' }))expect(onConfirm).not.toHaveBeenCalled()await user.click(screen.getByRole('button', { name: 'app.iconPicker.ok' }))expect(onConfirm).toHaveBeenCalledExactlyOnceWith({@@ -183,25 +174,20 @@ it('keeps open-session edits and reads the latest default when reopened', asyncconst client = new QueryClient()client.setQueryData(emojiCatalogOptions.queryKey, [])const onConfirm = vi.fn()- const picker = (open: boolean, defaultValue: IconPickerDefaultValue) => (+ const picker = (value: IconPickerInputValue) => (<QueryClientProvider client={client}>- <IconPickerDialog- open={open}- defaultValue={defaultValue}- onConfirm={onConfirm}- onOpenChange={() => {}}- />+ <IconPickerDialog value={value} onConfirm={onConfirm} /></QueryClientProvider>)- const view = render(picker(true, { type: 'emoji', icon: '😀', background: '#FEF3F2' }))+ const view = render(picker({ type: 'emoji', icon: '😀', background: '#FEF3F2' }))+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.title' }))await user.click(screen.getByRole('radio', { name: 'app.iconPicker.color.green' }))const nextDefault = { type: 'image' as const, fileId: 'new-image', url: '/new-image.png' }- view.rerender(picker(true, nextDefault))+ view.rerender(picker(nextDefault))await user.click(screen.getByRole('button', { name: 'app.iconPicker.ok' }))expect(onConfirm).toHaveBeenLastCalledWith({ type: 'emoji', icon: '😀', background: '#F3FEE7' })- view.rerender(picker(false, nextDefault))await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())- view.rerender(picker(true, nextDefault))+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.title' }))await user.click(screen.getByRole('button', { name: 'app.iconPicker.ok' }))expect(onConfirm).toHaveBeenLastCalledWith(nextDefault)expect(uploadImage).not.toHaveBeenCalled()@@ -289,3 +275,57 @@ it('replaces an existing image only after selecting a file and confirms the new)client.clear()})++it('preserves a linked icon on cancellation and only replaces it after confirmation', async () => {+ const user = userEvent.setup()+ const client = new QueryClient()+ client.setQueryData(emojiCatalogOptions.queryKey, [])+ const onConfirm = vi.fn()+ const value = { type: 'link' as const, url: '/linked-icon.png' }+ render(+ <QueryClientProvider client={client}>+ <IconPickerDialog value={value} onConfirm={onConfirm} />+ </QueryClientProvider>,+ )+ const trigger = screen.getByRole('button', { name: 'app.iconPicker.title' })+ expect(trigger.querySelector('img')).toHaveAttribute('src', value.url)+ await user.click(trigger)+ expect(screen.getByRole('tab', { name: 'app.iconPicker.emoji' })).toHaveAttribute(+ 'aria-selected',+ 'true',+ )+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.tryYourLuck' }))+ await user.keyboard('{Escape}')+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())+ expect(onConfirm).not.toHaveBeenCalled()+ expect(trigger.querySelector('img')).toHaveAttribute('src', value.url)+ await user.click(trigger)+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.tryYourLuck' }))+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.ok' }))+ expect(onConfirm).toHaveBeenCalledWith(expect.objectContaining({ type: 'emoji' }))+ expect(uploadImage).not.toHaveBeenCalled()+ client.clear()+})++it('keeps emoji-only consumers out of image upload', async () => {+ const user = userEvent.setup()+ const client = new QueryClient()+ client.setQueryData(emojiCatalogOptions.queryKey, [])+ const onConfirm = vi.fn()+ render(+ <QueryClientProvider client={client}>+ <IconPickerDialog+ enableImageUpload={false}+ value={{ type: 'emoji', icon: '😀', background: '#FEF3F2' }}+ onConfirm={onConfirm}+ />+ </QueryClientProvider>,+ )+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.title' }))+ expect(screen.queryByRole('tab', { name: 'app.iconPicker.image' })).not.toBeInTheDocument()+ expect(screen.queryByTestId('image-input')).not.toBeInTheDocument()+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.ok' }))+ expect(onConfirm).toHaveBeenCalledWith(expect.objectContaining({ type: 'emoji' }))+ expect(uploadImage).not.toHaveBeenCalled()+ client.clear()+})diff --git a/web/app/components/base/icon-picker/__tests__/ownership.browser.spec.tsx b/web/app/components/base/icon-picker/__tests__/ownership.browser.spec.tsxnew file mode 100644index 00000000000..049bf3eca09--- /dev/null+++ b/web/app/components/base/icon-picker/__tests__/ownership.browser.spec.tsx@@ -0,0 +1,144 @@+import type { EmojiIcon } from '..'+import { Dialog, DialogContent, DialogTitle, DialogTrigger } from '@langgenius/dify-ui/dialog'+import {+ Drawer,+ DrawerBackdrop,+ DrawerContent,+ DrawerPopup,+ DrawerPortal,+ DrawerTitle,+ DrawerTrigger,+ DrawerViewport,+} from '@langgenius/dify-ui/drawer'+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'+import { useState } from 'react'+import { userEvent } from 'vite-plus/test/browser'+import { render } from 'vitest-browser-react'+import { emojiCatalogOptions } from '../emoji-data'+import { IconPickerDialog } from './harness'++vi.mock('@/service/console', () => ({+ consoleQuery: {+ files: { upload: { post: { mutationOptions: () => ({ mutationFn: vi.fn() }) } } },+ },+}))+vi.mock('@/next/navigation', () => ({ useParams: () => ({}) }))++const initial: EmojiIcon = { type: 'emoji', icon: '😀', background: '#FEF3F2' }++function createClient() {+ const client = new QueryClient()+ client.setQueryData(emojiCatalogOptions.queryKey, [+ {+ id: 'faces',+ label: 'Faces',+ items: [{ emoji: '😎', label: 'Cool face', version: 1 }],+ },+ ])+ return client+}++function NestedOwner({ kind, onSubmit }: { kind: 'dialog' | 'drawer'; onSubmit: () => void }) {+ const [value, setValue] = useState(initial)+ const content = (+ <form+ onSubmit={(event) => {+ event.preventDefault()+ onSubmit()+ }}+ >+ <label>+ Owner name+ <input defaultValue="Untouched" />+ </label>+ <IconPickerDialog+ aria-label="Choose icon"+ value={value}+ enableImageUpload={false}+ onConfirm={(next) => {+ if (next.type === 'emoji') setValue(next)+ }}+ />+ <output aria-label="Saved icon">{value.icon}</output>+ <button type="submit">Save owner</button>+ </form>+ )+ if (kind === 'drawer') {+ return (+ <Drawer swipeDirection="right">+ <DrawerTrigger>Open owner</DrawerTrigger>+ <DrawerPortal>+ <DrawerBackdrop />+ <DrawerViewport>+ <DrawerPopup>+ <DrawerContent>+ <DrawerTitle>Owner</DrawerTitle>+ {content}+ </DrawerContent>+ </DrawerPopup>+ </DrawerViewport>+ </DrawerPortal>+ </Drawer>+ )+ }+ return (+ <Dialog>+ <DialogTrigger>Open owner</DialogTrigger>+ <DialogContent>+ <DialogTitle>Owner</DialogTitle>+ {content}+ </DialogContent>+ </Dialog>+ )+}++it.each(['dialog', 'drawer'] as const)(+ 'confirms and dismisses only the nested picker inside a %s',+ async (kind) => {+ const client = createClient()+ const onSubmit = vi.fn()+ const screen = await render(+ <QueryClientProvider client={client}>+ <NestedOwner kind={kind} onSubmit={onSubmit} />+ </QueryClientProvider>,+ )+ const ownerTrigger = screen.getByRole('button', { name: 'Open owner' })+ await ownerTrigger.click()+ const owner = screen.getByRole('dialog', { name: 'Owner', exact: true })+ if (kind === 'drawer') {+ await expect.element(owner).toHaveFocus()+ await userEvent.tab()+ }+ await expect.element(owner.getByRole('textbox', { name: 'Owner name' })).toHaveFocus()+ await userEvent.tab()+ const trigger = screen.getByRole('button', { name: 'Choose icon' })+ await expect.element(trigger).toHaveFocus()+ await userEvent.keyboard('{Enter}')+ const picker = screen.getByRole('dialog', { name: 'app.iconPicker.title' })+ const search = picker.getByRole('combobox', { name: 'app.iconPicker.search' })+ await expect.element(search).toHaveFocus()+ await search.fill('Cool')+ await userEvent.keyboard('{ArrowDown}{Enter}')+ expect(onSubmit).not.toHaveBeenCalled()+ await picker.getByRole('button', { name: 'app.iconPicker.ok' }).click()+ await expect.element(picker).not.toBeInTheDocument()+ await expect.element(owner).toBeVisible()+ await expect.element(trigger).toHaveFocus()+ await expect.element(owner.getByRole('status', { name: 'Saved icon' })).toHaveTextContent('😎')+ await expect+ .element(owner.getByRole('textbox', { name: 'Owner name' }))+ .toHaveValue('Untouched')+ expect(onSubmit).not.toHaveBeenCalled()++ await userEvent.keyboard(' ')+ await expect.element(picker).toBeVisible()+ await userEvent.keyboard('{Escape}')+ await expect.element(picker).not.toBeInTheDocument()+ await expect.element(owner).toBeVisible()+ await expect.element(trigger).toHaveFocus()+ await userEvent.keyboard('{Escape}')+ await expect.element(owner).not.toBeInTheDocument()+ await expect.element(ownerTrigger).toHaveFocus()+ client.clear()+ },+)diff --git a/web/app/components/base/icon-picker/__tests__/picker.browser.spec.tsx b/web/app/components/base/icon-picker/__tests__/picker.browser.spec.tsxindex bd110a07634..ec17270b01f 100644--- a/web/app/components/base/icon-picker/__tests__/picker.browser.spec.tsx+++ b/web/app/components/base/icon-picker/__tests__/picker.browser.spec.tsx@@ -4,8 +4,8 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'import { useState } from 'react'import { page, userEvent } from 'vite-plus/test/browser'import { render } from 'vitest-browser-react'-import { IconPickerDialog } from '..'import { emojiCatalogOptions } from '../emoji-data'+import { IconPickerDialog } from './harness'const { uploadImage } = vi.hoisted(() => ({uploadImage: vi.fn<() => Promise<PostFilesUploadResponse>>(),@@ -44,18 +44,13 @@ const emojis = [const initial: EmojiIcon = { type: 'emoji', icon: '😀', background: '#FEF3F2' }function Harness() {- const [open, setOpen] = useState(false)const [value, setValue] = useState(initial)return (<>- <button type="button" onClick={() => setOpen(true)}>- Choose- </button><output aria-label="Saved icon">{value.icon}</output><IconPickerDialog- open={open}- onOpenChange={setOpen}- defaultValue={value}+ aria-label="Choose"+ value={value}onConfirm={(next) => {if (next.type === 'emoji') setValue(next)}}@@ -158,17 +153,17 @@ it('focuses the visible image action when reopening an existing image icon', asyawait render(<QueryClientProvider client={client}><IconPickerDialog- open- defaultValue={{+ aria-label="Choose image"+ value={{type: 'image',fileId: 'image-id',url: 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"/>',}}- onOpenChange={() => {}}onConfirm={() => {}}/></QueryClientProvider>,)+ await page.getByRole('button', { name: 'Choose image' }).click()await expect.element(page.getByRole('tab', { name: 'app.iconPicker.image' })).toHaveAttribute('aria-selected', 'true')diff --git a/web/app/components/base/icon-picker/index.stories.tsx b/web/app/components/base/icon-picker/index.stories.tsxindex 4165486a081..87ec1cc1dd2 100644--- a/web/app/components/base/icon-picker/index.stories.tsx+++ b/web/app/components/base/icon-picker/index.stories.tsx@@ -1,11 +1,11 @@import type { Meta, StoryObj } from '@storybook/nextjs-vite'import type { IconPickerValue } from '.'import { useState } from 'react'-import { IconPickerDialog } from '.'+import { IconPicker, IconPickerContent, IconPickerIcon, IconPickerTrigger } from '.'const meta = {- title: 'Base/Data Entry/IconPickerDialog',- component: IconPickerDialog,+ title: 'Base/Data Entry/IconPicker',+ component: IconPicker,parameters: {layout: 'fullscreen',docs: {@@ -23,24 +23,22 @@ const meta = {},},tags: ['autodocs'],-} satisfies Meta<typeof IconPickerDialog>+} satisfies Meta<typeof IconPicker>export default metatype Story = StoryObj<typeof meta>-const IconPickerDialogDemo = () => {- const [open, setOpen] = useState(false)- const [selection, setSelection] = useState<IconPickerValue | null>(null)+const IconPickerDemo = () => {+ const [selection, setSelection] = useState<IconPickerValue>()return (<div className="flex min-h-80 flex-col items-start gap-4 px-6 py-8 md:px-12">- <button- type="button"- className="rounded-md bg-primary-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-primary-700"- onClick={() => setOpen(true)}- >- Choose icon…- </button>+ <IconPicker value={selection} onValueChange={setSelection}>+ <IconPickerTrigger aria-label="Choose icon" className="cursor-pointer rounded-[10px]">+ <IconPickerIcon size="large" />+ </IconPickerTrigger>+ <IconPickerContent />+ </IconPicker><div className="rounded-lg border border-divider-subtle bg-components-panel-bg p-4 text-sm text-text-secondary shadow-sm"><div className="font-medium text-text-primary">Selection preview</div>@@ -48,36 +46,30 @@ const IconPickerDialogDemo = () => {{selection ? JSON.stringify(selection, null, 2) : 'No icon selected yet.'}</pre></div>-- <IconPickerDialog open={open} onOpenChange={setOpen} onConfirm={setSelection} /></div>)}export const Playground: Story = {args: {- open: false,- onOpenChange: () => {},- onConfirm: () => {},+ onValueChange: () => {},+ children: null,},- render: () => <IconPickerDialogDemo />,+ render: () => <IconPickerDemo />,parameters: {docs: {source: {language: 'tsx',code: `-const [open, setOpen] = useState(false)-const [selection, setSelection] = useState<IconPickerValue | null>(null)+const [selection, setSelection] = useState<IconPickerValue>()return (- <>- <button onClick={() => setOpen(true)}>Choose icon…</button>- <IconPickerDialog- open={open}- onOpenChange={setOpen}- onConfirm={setSelection}- />- </>+ <IconPicker value={selection} onValueChange={setSelection}>+ <IconPickerTrigger aria-label="Choose icon">+ <IconPickerIcon size="large" />+ </IconPickerTrigger>+ <IconPickerContent />+ </IconPicker>)`.trim(),},diff --git a/web/app/components/base/icon-picker/index.tsx b/web/app/components/base/icon-picker/index.tsxindex 967a51a72ec..081c7563acb 100644--- a/web/app/components/base/icon-picker/index.tsx+++ b/web/app/components/base/icon-picker/index.tsx@@ -1,15 +1,15 @@'use client'-import type { DialogContentProps } from '@langgenius/dify-ui/dialog'-import type { RefCallback } from 'react'+import type { ComponentProps, ReactNode, RefCallback } from 'react'import type { ImageIconInputValue } from './image-input'import { Button } from '@langgenius/dify-ui/button'import { cn } from '@langgenius/dify-ui/cn'-import { Dialog, DialogContent, DialogTitle } from '@langgenius/dify-ui/dialog'+import { Dialog, DialogContent, DialogTitle, DialogTrigger } from '@langgenius/dify-ui/dialog'import { Tabs, TabsList, TabsPanel, TabsTab } from '@langgenius/dify-ui/tabs'import { useMutation } from '@tanstack/react-query'-import { useCallback, useLayoutEffect, useRef, useState } from 'react'+import { createContext, use, useCallback, useLayoutEffect, useRef, useState } from 'react'import { useTranslation } from 'react-i18next'+import AppIcon from '@/app/components/base/app-icon'import { DISABLE_UPLOAD_IMAGE_AS_ICON } from '@/config'import { consoleQuery } from '@/service/console'import { resolveEmoji } from '@/utils/emoji'@@ -33,62 +33,101 @@ export type ImageIcon = {export type IconPickerValue = EmojiIcon | ImageIcon-export type IconPickerDefaultValue =+/** The committed icon. A link is display-only: the picker shows it and never returns one. */+export type IconPickerInputValue =| (Omit<EmojiIcon, 'background'> & { background?: EmojiIcon['background'] | null })| ImageIcon+ | { type: 'link'; url: string }-export type IconPickerDialogProps = Pick<DialogContentProps, 'initialFocus' | 'finalFocus'> & {- open: boolean- onOpenChange: (open: boolean) => void- /** Initial draft for each mounted dialog session; changes while open do not replace edits. */- defaultValue?: IconPickerDefaultValue+type IconPickerProps = {+ /** Committed icon; changes while open do not replace the popup draft. */+ value?: IconPickerInputValue/** Receives the confirmed value after any image upload; does not await consumer persistence. */- onConfirm: (value: IconPickerValue) => void+ onValueChange: (value: IconPickerValue) => void+ children: ReactNode+}++type IconPickerContextValue = Omit<IconPickerProps, 'children'> & {+ open: boolean+ setOpen: (open: boolean) => void+}++const IconPickerContext = createContext<IconPickerContextValue | null>(null)++function useIconPicker(part: string) {+ const context = use(IconPickerContext)+ if (!context) throw new Error(`${part} must be used within IconPicker`)+ return context+}++/** Owns the committed icon and the open state for `IconPickerTrigger`, `IconPickerIcon` and `IconPickerContent`. */+export function IconPicker({ value, onValueChange, children }: IconPickerProps) {+ const [open, setOpen] = useState(false)+ return (+ <IconPickerContext value={{ value, onValueChange, open, setOpen }}>+ <Dialog open={open} onOpenChange={setOpen}>+ {children}+ </Dialog>+ </IconPickerContext>+ )+}++/** Opens the picker. The caller owns its appearance. */+export const IconPickerTrigger = DialogTrigger++type IconPickerIconProps = Pick<+ ComponentProps<typeof AppIcon>,+ 'size' | 'rounded' | 'showEditIcon' | 'innerIcon' | 'className'+>++/** Shows the committed icon, usually inside `IconPickerTrigger`. */+export function IconPickerIcon(props: IconPickerIconProps) {+ const { value } = useIconPicker('IconPickerIcon')+ return (+ <AppIcon+ decorative+ {...props}+ iconType={value?.type === 'emoji' ? 'emoji' : 'image'}+ icon={value?.type === 'emoji' ? value.icon : undefined}+ background={value?.type === 'emoji' ? value.background : undefined}+ imageUrl={value && value.type !== 'emoji' ? value.url : undefined}+ />+ )+}++type IconPickerContentProps = {enableImageUpload?: boolean- className?: string}-export function IconPickerDialog({- open,- onOpenChange,- className,- initialFocus,- finalFocus,- ...props-}: IconPickerDialogProps) {+export function IconPickerContent({ enableImageUpload }: IconPickerContentProps) {const { t } = useTranslation(['app'])+ const { value, onValueChange, open, setOpen } = useIconPicker('IconPickerContent')const popupRef = useRef<HTMLDivElement>(null)const focusTargetRef = useRef<HTMLElement | null>(null)const setFocusTarget = useCallback((element: HTMLElement | null) => {focusTargetRef.current = element}, [])return (- <Dialog open={open} onOpenChange={onOpenChange}>- <DialogContent- ref={popupRef}- backdropProps={{ forceRender: true }}- initialFocus={- initialFocus ??- ((interaction) =>- interaction === 'touch' ? popupRef.current : (focusTargetRef.current ?? true))- }- finalFocus={finalFocus}- className={cn(- 'flex max-h-[calc(100dvh-2rem)] w-80.5 flex-col overflow-hidden p-0 text-left',- className,- )}- >- <DialogTitle className="sr-only">- {t(($) => $['iconPicker.title'], { ns: 'app' })}- </DialogTitle>- <IconPickerSession- {...props}- open={open}- onOpenChange={onOpenChange}- initialFocusRef={setFocusTarget}- />- </DialogContent>- </Dialog>+ <DialogContent+ ref={popupRef}+ backdropProps={{ forceRender: true }}+ initialFocus={(interaction) =>+ interaction === 'touch' ? popupRef.current : (focusTargetRef.current ?? true)+ }+ className="flex max-h-[calc(100dvh-2rem)] w-80.5 flex-col overflow-hidden p-0 text-left"+ >+ <DialogTitle className="sr-only">+ {t(($) => $['iconPicker.title'], { ns: 'app' })}+ </DialogTitle>+ <IconPickerSession+ defaultValue={value?.type === 'link' ? undefined : value}+ onConfirm={onValueChange}+ enableImageUpload={enableImageUpload}+ open={open}+ onOpenChange={setOpen}+ initialFocusRef={setFocusTarget}+ />+ </DialogContent>)}@@ -99,10 +138,14 @@ function IconPickerSession({onOpenChange,enableImageUpload = true,initialFocusRef,-}: Pick<- IconPickerDialogProps,- 'open' | 'defaultValue' | 'onConfirm' | 'onOpenChange' | 'enableImageUpload'-> & { initialFocusRef: RefCallback<HTMLElement> }) {+}: IconPickerContentProps & {+ /** Initial draft for each mounted dialog session; changes while open do not replace edits. */+ defaultValue?: Exclude<IconPickerInputValue, { type: 'link' }>+ onConfirm: (value: IconPickerValue) => void+ open: boolean+ onOpenChange: (open: boolean) => void+ initialFocusRef: RefCallback<HTMLElement>+}) {const { t } = useTranslation(['app', 'common'])const imageEnabled = enableImageUpload && !DISABLE_UPLOAD_IMAGE_AS_ICONconst [activeTab, setActiveTab] = useState<IconPickerValue['type']>(diff --git a/web/app/components/datasets/create-from-pipeline/list/template-card/edit-pipeline-info.tsx b/web/app/components/datasets/create-from-pipeline/list/template-card/edit-pipeline-info.tsxindex 48f431133a4..dbee82070c1 100644--- a/web/app/components/datasets/create-from-pipeline/list/template-card/edit-pipeline-info.tsx+++ b/web/app/components/datasets/create-from-pipeline/list/template-card/edit-pipeline-info.tsx@@ -9,8 +9,12 @@ import { Textarea } from '@langgenius/dify-ui/textarea'import * as React from 'react'import { useCallback, useState } from 'react'import { useTranslation } from 'react-i18next'-import AppIcon from '@/app/components/base/app-icon'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import { toast } from '@/app/notifications'import { useInvalidCustomizedTemplateList, useUpdateTemplateInfo } from '@/service/use-pipeline'@@ -33,17 +37,12 @@ const EditPipelineInfo = ({ onClose, pipeline }: EditPipelineInfoProps) => {},)const [description, setDescription] = useState(pipeline.description)- const [showIconPicker, setShowIconPicker] = useState(false)const handleAppNameChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {const value = event.target.valuesetName(value)}, [])- const handleOpenAppIconPicker = useCallback(() => {- setShowIconPicker(true)- }, [])-const handleSelectAppIcon = useCallback((icon: IconPickerValue) => {setAppIcon(icon)}, [])@@ -122,22 +121,15 @@ const EditPipelineInfo = ({ onClose, pipeline }: EditPipelineInfoProps) => {placeholder={t(($) => $.knowledgeNameAndIconPlaceholder, { ns: 'datasetPipeline' })}/></Field>- <button- type="button"- aria-label={`${t(($) => $['operation.edit'], { ns: 'common' })} ${t(($) => $.pipelineNameAndIcon, { ns: 'datasetPipeline' })}`}- onClick={handleOpenAppIconPicker}- className="group/edit-icon shrink-0 cursor-pointer rounded-2xl focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"- >- <AppIcon- decorative- size="xxl"- iconType={appIcon.type}- icon={appIcon.type === 'image' ? appIcon.fileId : appIcon.icon}- background={appIcon.type === 'image' ? undefined : appIcon.background}- imageUrl={appIcon.type === 'image' ? appIcon.url : undefined}- showEditIcon- />- </button>+ <IconPicker value={appIcon} onValueChange={handleSelectAppIcon}>+ <IconPickerTrigger+ aria-label={`${t(($) => $['operation.edit'], { ns: 'common' })} ${t(($) => $.pipelineNameAndIcon, { ns: 'datasetPipeline' })}`}+ className="group/edit-icon shrink-0 cursor-pointer rounded-2xl"+ >+ <IconPickerIcon size="xxl" showEditIcon />+ </IconPickerTrigger>+ <IconPickerContent />+ </IconPicker></div><Field name="description"><FieldLabel>{t(($) => $.knowledgeDescription, { ns: 'datasetPipeline' })}</FieldLabel>@@ -158,12 +150,6 @@ const EditPipelineInfo = ({ onClose, pipeline }: EditPipelineInfoProps) => {{t(($) => $['operation.save'], { ns: 'common' })}</Button></div>- <IconPickerDialog- open={showIconPicker}- defaultValue={appIcon}- onOpenChange={setShowIconPicker}- onConfirm={handleSelectAppIcon}- /></form>)}diff --git a/web/app/components/datasets/rename-modal/__tests__/index.spec.tsx b/web/app/components/datasets/rename-modal/__tests__/index.spec.tsxindex 8ba219127d5..6d838b5d08e 100644--- a/web/app/components/datasets/rename-modal/__tests__/index.spec.tsx+++ b/web/app/components/datasets/rename-modal/__tests__/index.spec.tsx@@ -28,56 +28,6 @@ vi.mock('@/service/datasets', () => ({updateDatasetSetting: (params: unknown) => mockUpdateDatasetSetting(params),}))-vi.mock('../../../base/app-icon', () => ({- default: () => <span data-testid="app-icon">Icon</span>,-}))--vi.mock('@/app/components/base/icon-picker', () => ({- IconPickerDialog: ({- open,- onOpenChange,- onConfirm,- }: {- open: boolean- onOpenChange: (open: boolean) => void- onConfirm: (payload: { type: 'emoji'; icon: string; background: string }) => void- }) => {- if (!open) return null- let selectedBackground = '#FFEAD5'- return (- <div>- <input placeholder="common.operation.search" />- <button- type="button"- aria-label="#E4FBCC"- onClick={() => {- selectedBackground = '#E4FBCC'- }}- />- <button- type="button"- aria-label="#E0F2FE"- onClick={() => {- selectedBackground = '#E0F2FE'- }}- />- <button- type="button"- onClick={() => {- onConfirm({ type: 'emoji', icon: '📊', background: selectedBackground })- onOpenChange(false)- }}- >- iconPicker.ok- </button>- <button type="button" onClick={() => onOpenChange(false)}>- iconPicker.cancel- </button>- </div>- )- },-}))-// The mock returns 'ns.key' format, e.g., 'common.operation.cancel'describe('RenameDatasetModal', () => {@@ -807,7 +757,7 @@ describe('RenameDatasetModal', () => {screen.getByRole('button', {name: 'common.operation.edit datasetSettings.form.nameAndIcon',}),- ).toContainElement(screen.getByTestId('app-icon'))+ ).toContainElement(screen.getByRole('button', { name: /form.nameAndIcon/ }))})it('should initialize icon state from dataset', () => {@@ -882,47 +832,15 @@ describe('RenameDatasetModal', () => {it('should open icon picker when app icon is clicked (handleOpenAppIconPicker)', async () => {render(<RenameDatasetModal {...defaultProps} />)- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- // Initially picker should not be visible- expect(screen.queryByPlaceholderText('common.operation.search')).not.toBeInTheDocument()-- const appIcon = screen.getByTestId('app-icon')+ expect(screen.queryByPlaceholderText('app.iconPicker.search')).not.toBeInTheDocument()++ const appIcon = screen.getByRole('button', { name: /form.nameAndIcon/ })await act(async () => {fireEvent.click(appIcon)})await waitFor(() => {- expect(screen.getByPlaceholderText('common.operation.search')).toBeInTheDocument()+ expect(screen.getByPlaceholderText('app.iconPicker.search')).toBeInTheDocument()})})@@ -930,16 +848,21 @@ describe('RenameDatasetModal', () => {const user = userEvent.setup()render(<RenameDatasetModal {...defaultProps} />)- await user.click(screen.getByTestId('app-icon'))+ expect(screen.getByRole('textbox', { name: 'datasetSettings.form.name' })).toHaveValue(+ 'Test Dataset',+ )+ await user.click(screen.getByRole('button', { name: /form.nameAndIcon/ }))await waitFor(() => {- expect(screen.getByPlaceholderText('common.operation.search')).toBeInTheDocument()+ expect(screen.getByPlaceholderText('app.iconPicker.search')).toBeInTheDocument()})- await user.click(screen.getByRole('button', { name: '#E4FBCC' }))+ await user.click(screen.getByRole('radio', { name: 'app.iconPicker.color.green' }))await user.click(screen.getByRole('button', { name: /iconPicker\.ok/ }))await waitFor(() => {- expect(screen.queryByPlaceholderText('common.operation.search')).not.toBeInTheDocument()+ expect(screen.queryByPlaceholderText('app.iconPicker.search')).not.toBeInTheDocument()})+ expect(mockUpdateDatasetSetting).not.toHaveBeenCalled()+// Save and verify new icon is usedconst saveButton = screen.getByText('common.operation.save')await act(async () => {@@ -953,7 +876,7 @@ describe('RenameDatasetModal', () => {icon_info: {icon: '📊',icon_type: 'emoji',- icon_background: '#E4FBCC',+ icon_background: '#F3FEE7',icon_url: undefined,},}),@@ -965,14 +888,14 @@ describe('RenameDatasetModal', () => {const user = userEvent.setup()render(<RenameDatasetModal {...defaultProps} />)- await user.click(screen.getByTestId('app-icon'))+ await user.click(screen.getByRole('button', { name: /form.nameAndIcon/ }))await waitFor(() => {- expect(screen.getByPlaceholderText('common.operation.search')).toBeInTheDocument()+ expect(screen.getByPlaceholderText('app.iconPicker.search')).toBeInTheDocument()})- await user.click(screen.getByRole('button', { name: '#E0F2FE' }))+ await user.click(screen.getByRole('radio', { name: 'app.iconPicker.color.blue' }))await user.click(screen.getByRole('button', { name: /iconPicker\.ok/ }))await waitFor(() => {- expect(screen.queryByPlaceholderText('common.operation.search')).not.toBeInTheDocument()+ expect(screen.queryByPlaceholderText('app.iconPicker.search')).not.toBeInTheDocument()})const saveButton = screen.getByText('common.operation.save')@@ -987,7 +910,7 @@ describe('RenameDatasetModal', () => {icon_info: {icon: '📊',icon_type: 'emoji',- icon_background: '#E0F2FE',+ icon_background: '#E9F0FF',icon_url: undefined,},}),@@ -999,18 +922,18 @@ describe('RenameDatasetModal', () => {render(<RenameDatasetModal {...defaultProps} />)// Open picker- const appIcon = screen.getByTestId('app-icon')+ const appIcon = screen.getByRole('button', { name: /form.nameAndIcon/ })await act(async () => {fireEvent.click(appIcon)})const user = userEvent.setup()await waitFor(() => {- expect(screen.getByPlaceholderText('common.operation.search')).toBeInTheDocument()+ expect(screen.getByPlaceholderText('app.iconPicker.search')).toBeInTheDocument()})- await user.click(screen.getByRole('button', { name: /iconPicker\.cancel/ }))+ await user.keyboard('{Escape}')await waitFor(() => {- expect(screen.queryByPlaceholderText('common.operation.search')).not.toBeInTheDocument()+ expect(screen.queryByPlaceholderText('app.iconPicker.search')).not.toBeInTheDocument()})// Save and verify original icon is preserveddiff --git a/web/app/components/datasets/rename-modal/index.tsx b/web/app/components/datasets/rename-modal/index.tsxindex c4867b8e7f2..927c203a734 100644--- a/web/app/components/datasets/rename-modal/index.tsx+++ b/web/app/components/datasets/rename-modal/index.tsx@@ -9,10 +9,14 @@ import { Input } from '@langgenius/dify-ui/input'import { Textarea } from '@langgenius/dify-ui/textarea'import { useCallback, useState } from 'react'import { useTranslation } from 'react-i18next'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import { toast } from '@/app/notifications'import { updateDatasetSetting } from '@/service/datasets'-import AppIcon from '../../base/app-icon'type RenameDatasetModalProps = {show: boolean@@ -40,10 +44,6 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDatasetbackground: dataset.icon_info?.icon_background || '',},)- const [showIconPicker, setShowIconPicker] = useState(false)- const handleOpenAppIconPicker = useCallback(() => {- setShowIconPicker(true)- }, [])const handleSelectAppIcon = useCallback((icon: IconPickerValue) => {setAppIcon(icon)}, [])@@ -120,35 +120,28 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDataset<span aria-hidden="true" className="i-ri-close-line size-4" /></IconButton></div>- <Field name="name" className="gap-0 py-4">- <FieldLabel className="w-full shrink-0 py-2 text-sm leading-5 font-medium text-text-primary">- {t(($) => $['form.name'], { ns: 'datasetSettings' })}- </FieldLabel>- <div className="flex items-center gap-x-2">- <button- type="button"- aria-label={`${t(($) => $['operation.edit'], { ns: 'common' })} ${t(($) => $['form.nameAndIcon'], { ns: 'datasetSettings' })}`}- className="group/edit-icon shrink-0 cursor-pointer rounded-[10px] border-0 bg-transparent p-0 focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"- onClick={handleOpenAppIconPicker}- >- <AppIcon- decorative- size="medium"- iconType={appIcon.type}- icon={appIcon.type === 'image' ? appIcon.fileId : appIcon.icon}- background={appIcon.type === 'image' ? undefined : appIcon.background}- imageUrl={appIcon.type === 'image' ? appIcon.url : undefined}- showEditIcon+ <IconPicker value={appIcon} onValueChange={handleSelectAppIcon}>+ <Field name="name" className="gap-0 py-4">+ <FieldLabel className="w-full shrink-0 py-2 text-sm leading-5 font-medium text-text-primary">+ {t(($) => $['form.name'], { ns: 'datasetSettings' })}+ </FieldLabel>+ <div className="flex items-center gap-x-2">+ <IconPickerTrigger+ aria-label={`${t(($) => $['operation.edit'], { ns: 'common' })} ${t(($) => $['form.nameAndIcon'], { ns: 'datasetSettings' })}`}+ className="group/edit-icon shrink-0 cursor-pointer rounded-[10px] border-0 bg-transparent p-0"+ >+ <IconPickerIcon size="medium" showEditIcon />+ </IconPickerTrigger>+ <Input+ value={name}+ onChange={(e) => setName(e.target.value)}+ className="h-9 grow"+ placeholder={t(($) => $['form.namePlaceholder'], { ns: 'datasetSettings' }) || ''}/>- </button>- <Input- value={name}- onChange={(e) => setName(e.target.value)}- className="h-9 grow"- placeholder={t(($) => $['form.namePlaceholder'], { ns: 'datasetSettings' }) || ''}- />- </div>- </Field>+ </div>+ </Field>+ <IconPickerContent />+ </IconPicker><Field name="description" className="gap-0 py-4"><FieldLabel className="w-full shrink-0 py-2 text-sm leading-5 font-medium text-text-primary">{t(($) => $['form.desc'], { ns: 'datasetSettings' })}@@ -169,12 +162,6 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDataset</Button></div></form>- <IconPickerDialog- open={showIconPicker}- defaultValue={appIcon}- onOpenChange={setShowIconPicker}- onConfirm={handleSelectAppIcon}- /></DialogContent></Dialog>)diff --git a/web/app/components/datasets/settings/form/components/__tests__/basic-info-section.spec.tsx b/web/app/components/datasets/settings/form/components/__tests__/basic-info-section.spec.tsxindex 1386f3f9fa1..efa26a02b89 100644--- a/web/app/components/datasets/settings/form/components/__tests__/basic-info-section.spec.tsx+++ b/web/app/components/datasets/settings/form/components/__tests__/basic-info-section.spec.tsx@@ -7,6 +7,7 @@ import userEvent from '@testing-library/user-event'import { ChunkingMode, DatasetPermission, DataSourceType } from '@/models/datasets'import { createConsoleQueryWrapper } from '@/test/console/query-data'import { render as renderWithConsoleState } from '@/test/console/render'+import { mockEmojiData } from '@/test/emoji-picker'import { RETRIEVE_METHOD } from '@/types/app'import { IndexingType } from '../../../../create/step-two'import BasicInfoSection from '../basic-info-section'@@ -168,10 +169,7 @@ describe('BasicInfoSection', () => {description: 'Test description',setDescription: vi.fn(),iconInfo: mockIconInfo,- showIconPicker: false,- handleOpenAppIconPicker: vi.fn(),handleSelectAppIcon: vi.fn(),- setShowIconPicker: vi.fn(),permission: DatasetPermission.onlyMe,setPermission: vi.fn(),selectedMemberIDs: ['user-1'],@@ -218,16 +216,13 @@ describe('BasicInfoSection', () => {it('names the icon action and opens it with the keyboard', async () => {const user = userEvent.setup()- const handleOpenAppIconPicker = vi.fn()- render(- <BasicInfoSection {...defaultProps} handleOpenAppIconPicker={handleOpenAppIconPicker} />,- )+ render(<BasicInfoSection {...defaultProps} />)const trigger = screen.getByRole('button', { name: 'datasetSettings.form.changeIcon' })await user.tab()expect(trigger).toHaveFocus()await user.keyboard('{Enter}')- expect(handleOpenAppIconPicker).toHaveBeenCalledOnce()+ expect(screen.getByRole('dialog', { name: 'app.iconPicker.title' })).toBeInTheDocument()})it('associates the permissions field label without losing the selected value', () => {@@ -242,19 +237,12 @@ describe('BasicInfoSection', () => {it('does not open the icon picker when settings are read-only', async () => {const user = userEvent.setup()- const handleOpenAppIconPicker = vi.fn()- render(- <BasicInfoSection- {...defaultProps}- readonly- handleOpenAppIconPicker={handleOpenAppIconPicker}- />,- )+ render(<BasicInfoSection {...defaultProps} readonly />)const trigger = screen.getByRole('button', { name: 'datasetSettings.form.changeIcon' })expect(trigger).toBeDisabled()await user.click(trigger)- expect(handleOpenAppIconPicker).not.toHaveBeenCalled()+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument()})})@@ -323,53 +311,12 @@ describe('BasicInfoSection', () => {})describe('App Icon', () => {- it('should call handleOpenAppIconPicker when icon is clicked', async () => {+ it('opens the icon picker from the fixed icon action', async () => {const user = userEvent.setup()- const handleOpenAppIconPicker = vi.fn()- render(- <BasicInfoSection {...defaultProps} handleOpenAppIconPicker={handleOpenAppIconPicker} />,- )+ render(<BasicInfoSection {...defaultProps} />)await user.click(screen.getByRole('button', { name: 'datasetSettings.form.changeIcon' }))- expect(handleOpenAppIconPicker).toHaveBeenCalledOnce()- })-- it('should not render IconPickerDialog when showIconPicker is false', () => {- const { container } = render(<BasicInfoSection {...defaultProps} showIconPicker={false} />)-- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- // Check that IconPickerDialog is not rendered- expect(container.querySelector('[data-testid="app-icon-picker"]')).not.toBeInTheDocument()+ expect(screen.getByRole('dialog', { name: 'app.iconPicker.title' })).toBeInTheDocument()})it('should render image icon when icon_type is image', () => {@@ -505,3 +452,5 @@ describe('BasicInfoSection', () => {})})})++mockEmojiData()diff --git a/web/app/components/datasets/settings/form/components/basic-info-section.tsx b/web/app/components/datasets/settings/form/components/basic-info-section.tsxindex 231bee8c690..2b99a9f5b67 100644--- a/web/app/components/datasets/settings/form/components/basic-info-section.tsx+++ b/web/app/components/datasets/settings/form/components/basic-info-section.tsx@@ -2,14 +2,17 @@import type { IconPickerValue } from '@/app/components/base/icon-picker'import type { Member } from '@/models/common'import type { DataSet, DatasetPermission, IconInfo } from '@/models/datasets'-import type { AppIconType } from '@/types/app'import { IconButton } from '@langgenius/dify-ui/icon-button'import { Input } from '@langgenius/dify-ui/input'import { Textarea } from '@langgenius/dify-ui/textarea'import { useId } from 'react'import { useTranslation } from 'react-i18next'-import AppIcon from '@/app/components/base/app-icon'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import PermissionSelector from '../../permission-selector'const rowClass = 'flex min-w-0 flex-col gap-2 @3xl/settings:flex-row @3xl/settings:gap-x-1'@@ -22,10 +25,7 @@ type BasicInfoSectionProps = {description: stringsetDescription: (value: string) => voidiconInfo: IconInfo- showIconPicker: boolean- handleOpenAppIconPicker: () => voidhandleSelectAppIcon: (icon: IconPickerValue) => void- setShowIconPicker: (show: boolean) => voidpermission: DatasetPermission | undefinedsetPermission: (value: DatasetPermission | undefined) => voidselectedMemberIDs: string[]@@ -41,10 +41,7 @@ const BasicInfoSection = ({description,setDescription,iconInfo,- showIconPicker,- handleOpenAppIconPicker,handleSelectAppIcon,- setShowIconPicker,permission,setPermission,selectedMemberIDs,@@ -65,23 +62,33 @@ const BasicInfoSection = ({</div></div><div className="flex min-w-0 grow items-center gap-x-2">- <IconButton- size="lg"- aria-label={t(($) => $['form.changeIcon'], { ns: 'datasetSettings' })}- disabled={readonly}- onClick={handleOpenAppIconPicker}+ <IconPicker+ value={+ iconInfo.icon_type === 'emoji'+ ? {+ type: 'emoji',+ icon: iconInfo.icon,+ background: iconInfo.icon_background,+ }+ : { type: 'image', fileId: iconInfo.icon, url: iconInfo.icon_url || '' }+ }+ onValueChange={handleSelectAppIcon}>- <span aria-hidden="true">- <AppIcon- size="small"- decorative- iconType={iconInfo.icon_type as AppIconType}- icon={iconInfo.icon}- background={iconInfo.icon_background}- imageUrl={iconInfo.icon_url}- />- </span>- </IconButton>+ <IconPickerTrigger+ disabled={readonly}+ render={+ <IconButton+ size="lg"+ aria-label={t(($) => $['form.changeIcon'], { ns: 'datasetSettings' })}+ >+ <span aria-hidden="true">+ <IconPickerIcon size="small" />+ </span>+ </IconButton>+ }+ />+ <IconPickerContent />+ </IconPicker><Inputaria-label={t(($) => $['form.name'], { ns: 'datasetSettings' })}disabled={!currentDataset?.embedding_available || readonly}@@ -129,21 +136,6 @@ const BasicInfoSection = ({/></div></div>-- <IconPickerDialog- open={showIconPicker}- defaultValue={- iconInfo.icon_type === 'emoji'- ? {- type: 'emoji',- icon: iconInfo.icon,- background: iconInfo.icon_background,- }- : { type: 'image', fileId: iconInfo.icon, url: iconInfo.icon_url || '' }- }- onOpenChange={setShowIconPicker}- onConfirm={handleSelectAppIcon}- /></>)}diff --git a/web/app/components/datasets/settings/form/hooks/__tests__/use-form-state.spec.ts b/web/app/components/datasets/settings/form/hooks/__tests__/use-form-state.spec.tsindex 34b942aaa91..57afe0a8d5e 100644--- a/web/app/components/datasets/settings/form/hooks/__tests__/use-form-state.spec.ts+++ b/web/app/components/datasets/settings/form/hooks/__tests__/use-form-state.spec.ts@@ -316,23 +316,9 @@ describe('useFormState', () => {})describe('Icon Handlers', () => {- it('should open app icon picker and save previous icon', () => {- const { result } = renderHook(() => useFormState())-- act(() => {- result.current.handleOpenAppIconPicker()- })-- expect(result.current.showIconPicker).toBe(true)- })-it('should select emoji icon without owning picker close state', () => {const { result } = renderHook(() => useFormState())- act(() => {- result.current.handleOpenAppIconPicker()- })-act(() => {result.current.handleSelectAppIcon({type: 'emoji',@@ -341,7 +327,6 @@ describe('useFormState', () => {})})- expect(result.current.showIconPicker).toBe(true)expect(result.current.iconInfo).toEqual({icon_type: 'emoji',icon: '🎉',@@ -353,10 +338,6 @@ describe('useFormState', () => {it('should select image icon without owning picker close state', () => {const { result } = renderHook(() => useFormState())- act(() => {- result.current.handleOpenAppIconPicker()- })-act(() => {result.current.handleSelectAppIcon({type: 'image',@@ -365,7 +346,6 @@ describe('useFormState', () => {})})- expect(result.current.showIconPicker).toBe(true)expect(result.current.iconInfo).toEqual({icon_type: 'image',icon: 'file-123',@@ -373,34 +353,6 @@ describe('useFormState', () => {icon_url: 'https://example.com/icon.png',})})-- it('should close picker through open state setter without changing icon', () => {- const { result } = renderHook(() => useFormState())-- act(() => {- result.current.handleOpenAppIconPicker()- })-- act(() => {- result.current.handleSelectAppIcon({- type: 'emoji',- icon: '🎉',- background: '#FF0000',- })- })-- act(() => {- result.current.setShowIconPicker(false)- })-- expect(result.current.showIconPicker).toBe(false)- expect(result.current.iconInfo).toEqual({- icon_type: 'emoji',- icon: '🎉',- icon_background: '#FF0000',- icon_url: undefined,- })- })})describe('External Retrieval Settings Handler', () => {diff --git a/web/app/components/datasets/settings/form/hooks/use-form-state.ts b/web/app/components/datasets/settings/form/hooks/use-form-state.tsindex c32c1e15c35..ea36e4af0f3 100644--- a/web/app/components/datasets/settings/form/hooks/use-form-state.ts+++ b/web/app/components/datasets/settings/form/hooks/use-form-state.ts@@ -64,7 +64,6 @@ export const useFormState = () => {// Icon stateconst [iconInfo, setIconInfo] = useState(currentDataset?.icon_info || DEFAULT_APP_ICON)- const [showIconPicker, setShowIconPicker] = useState(false)// Permission stateconst [permission, setPermission] = useState(currentDataset?.permission)@@ -125,11 +124,6 @@ export const useFormState = () => {return membersData?.accounts ?? []}, [membersData])- // Icon handlers- const handleOpenAppIconPicker = useCallback(() => {- setShowIconPicker(true)- }, [])-const handleSelectAppIcon = useCallback((icon: IconPickerValue) => {const newIconInfo: IconInfo = {icon_type: icon.type,@@ -274,9 +268,6 @@ export const useFormState = () => {// IconiconInfo,- showIconPicker,- setShowIconPicker,- handleOpenAppIconPicker,handleSelectAppIcon,// Permissiondiff --git a/web/app/components/datasets/settings/form/index.tsx b/web/app/components/datasets/settings/form/index.tsxindex 141c7cd14e4..543c529c0f5 100644--- a/web/app/components/datasets/settings/form/index.tsx+++ b/web/app/components/datasets/settings/form/index.tsx@@ -25,9 +25,6 @@ const Form = () => {// IconiconInfo,- showIconPicker,- setShowIconPicker,- handleOpenAppIconPicker,handleSelectAppIcon,// Permission@@ -77,9 +74,6 @@ const Form = () => {description={description}setDescription={setDescription}iconInfo={iconInfo}- showIconPicker={showIconPicker}- setShowIconPicker={setShowIconPicker}- handleOpenAppIconPicker={handleOpenAppIconPicker}handleSelectAppIcon={handleSelectAppIcon}permission={permission}setPermission={setPermission}diff --git a/web/app/components/explore/create-app-modal/__tests__/index.spec.tsx b/web/app/components/explore/create-app-modal/__tests__/index.spec.tsxindex 72b9fb52014..3d237a7df22 100644--- a/web/app/components/explore/create-app-modal/__tests__/index.spec.tsx+++ b/web/app/components/explore/create-app-modal/__tests__/index.spec.tsx@@ -64,10 +64,12 @@ function render(ui: ReactElement) {vi.mock('@/next/navigation', () => ({ useParams: () => ({}) }))-function submitWithKeyboard() {+function submitWithKeyboard(+ modifier: Pick<KeyboardEventInit, 'ctrlKey' | 'metaKey'> = { ctrlKey: true },+) {const target = screen.queryByPlaceholderText('app.newApp.appNamePlaceholder') ?? document.body- fireEvent.keyDown(target, { key: 'Enter', ctrlKey: true })- fireEvent.keyUp(target, { key: 'Enter', ctrlKey: true })+ fireEvent.keyDown(target, { key: 'Enter', ...modifier })+ fireEvent.keyUp(target, { key: 'Enter', ...modifier })}describe('CreateAppModal', () => {@@ -234,17 +236,81 @@ describe('CreateAppModal', () => {vi.useRealTimers()})- it('should submit when Mod+Enter is pressed while visible', async () => {- const { onConfirm, onHide } = await setup()+ it.each([+ { platform: 'Win32', modifier: { ctrlKey: true } },+ { platform: 'MacIntel', modifier: { metaKey: true } },+ ])(+ 'suspends Mod+Enter while the picker is open and resumes after it closes on $platform',+ async ({ platform, modifier }) => {+ vi.spyOn(navigator, 'platform', 'get').mockReturnValue(platform)+ const { onConfirm, onHide } = await setup()+ const picker = openAppIconPicker()+ const pickerSearch = within(picker).getByPlaceholderText('app.iconPicker.search')+ fireEvent.keyDown(pickerSearch, { key: 'Enter', ...modifier })+ fireEvent.keyUp(pickerSearch, { key: 'Enter', ...modifier })+ await act(async () => {+ vi.advanceTimersByTime(300)+ })+ expect(onConfirm).not.toHaveBeenCalled()+ expect(onHide).not.toHaveBeenCalled()+ fireEvent.keyDown(pickerSearch, { key: 'Escape' })+ await act(async () => {+ vi.advanceTimersByTime(300)+ })+ expect(picker).not.toBeInTheDocument()- submitWithKeyboard()- await act(async () => {- vi.advanceTimersByTime(300)- })+ submitWithKeyboard(modifier)+ await act(async () => {+ vi.advanceTimersByTime(300)+ })- expect(onConfirm).toHaveBeenCalledTimes(1)- expect(onHide).toHaveBeenCalledTimes(1)- })+ expect(onConfirm).toHaveBeenCalledTimes(1)+ expect(onHide).toHaveBeenCalledTimes(1)+ },+ )++ it.each([+ { platform: 'Win32', modifier: { ctrlKey: true } },+ { platform: 'MacIntel', modifier: { metaKey: true } },+ ])(+ 'keeps the shortcut available after the outer dialog is hidden with an open picker on $platform',+ async ({ platform, modifier }) => {+ vi.spyOn(navigator, 'platform', 'get').mockReturnValue(platform)+ const onConfirm = vi.fn().mockResolvedValue(undefined)+ const onHide = vi.fn()+ const modal = (show: boolean) => (+ <CreateAppModal+ show={show}+ appName="Reopened App"+ appDescription=""+ appIconType="emoji"+ appIcon="🤖"+ onConfirm={onConfirm}+ onHide={onHide}+ />+ )+ const { rerender } = render(modal(true))+ const picker = openAppIconPicker()++ rerender(modal(false))+ await act(async () => {+ vi.advanceTimersByTime(300)+ })+ expect(picker).not.toBeInTheDocument()+ rerender(modal(true))+ expect(+ screen.queryByRole('dialog', { name: 'app.iconPicker.title' }),+ ).not.toBeInTheDocument()+ submitWithKeyboard(modifier)+ await act(async () => {+ vi.advanceTimersByTime(300)+ })++ expect(onConfirm).toHaveBeenCalledOnce()+ expect(onConfirm).toHaveBeenCalledWith(expect.objectContaining({ name: 'Reopened App' }))+ expect(onHide).toHaveBeenCalledOnce()+ },+ )it('submits instead of opening the icon picker when Mod+Enter starts on its trigger', async () => {const { onConfirm } = await setup()diff --git a/web/app/components/explore/create-app-modal/index.tsx b/web/app/components/explore/create-app-modal/index.tsxindex 44bc724a0b1..47515936794 100644--- a/web/app/components/explore/create-app-modal/index.tsx+++ b/web/app/components/explore/create-app-modal/index.tsx@@ -4,7 +4,7 @@ import type {UpdateAppPayload,} from '@dify/contracts/api/console/apps/types.gen'import type { Hotkey } from '@tanstack/react-hotkeys'-import type { IconPickerDefaultValue, IconPickerValue } from '@/app/components/base/icon-picker'+import type { IconPickerInputValue, IconPickerValue } from '@/app/components/base/icon-picker'import { Button } from '@langgenius/dify-ui/button'import { Dialog, DialogClose, DialogContent, DialogTitle } from '@langgenius/dify-ui/dialog'import { IconButton } from '@langgenius/dify-ui/icon-button'@@ -19,8 +19,12 @@ import { useAtomValue } from 'jotai'import * as React from 'react'import { useCallback, useState } from 'react'import { useTranslation } from 'react-i18next'-import AppIcon from '@/app/components/base/app-icon'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import AppsFull from '@/app/components/billing/apps-full-in-dialog'import { toast } from '@/app/notifications'import { deploymentEditionAtom } from '@/features/system-features/state'@@ -71,13 +75,15 @@ const CreateAppModal = ({const [name, setName] = React.useState(appName)const [selectedIcon, setSelectedIcon] = useState<IconPickerValue | null>(null)- const pickerDefaultValue: IconPickerDefaultValue | undefined =+ const pickerValue: IconPickerInputValue | undefined =selectedIcon ??(appIconType === 'image' && _appIcon? { type: 'image', fileId: _appIcon, url: appIconUrl ?? '' }: appIconType === 'emoji' && _appIcon? { type: 'emoji', icon: _appIcon, background: appIconBackground }- : undefined)+ : appIconType === 'link' && _appIcon+ ? { type: 'link', url: _appIcon }+ : undefined)const currentIcon = selectedIcon? {icon_type: selectedIcon.type,@@ -96,7 +102,6 @@ const CreateAppModal = ({icon: currentIconValue,icon_background: currentIconBackground,} = currentIcon- const [showIconPicker, setShowIconPicker] = useState(false)const [description, setDescription] = useState(appDescription || '')const [useIconAsAnswerIcon, setUseIconAsAnswerIcon] = useState(appUseIconAsAnswerIcon || false)@@ -182,7 +187,6 @@ const CreateAppModal = ({!show ||submitDisabled ||confirmLoading ||- showIconPicker ||event.defaultPrevented ||event.nativeEvent.isComposing ||!(event.target instanceof Node) ||@@ -229,23 +233,15 @@ const CreateAppModal = ({{t(($) => $['newApp.captionName'], { ns: 'app' })}</label><div className="flex items-center justify-between space-x-2">- <button- type="button"- aria-label={t(($) => $['iconPicker.title'], { ns: 'app' })}- className="shrink-0 cursor-pointer rounded-[10px] focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"- onClick={() => setShowIconPicker(true)}- >- <AppIcon- decorative- size="large"- iconType={currentIcon.icon_type === 'link' ? 'image' : currentIcon.icon_type}- icon={currentIcon.icon ?? undefined}- background={currentIcon.icon_background}- imageUrl={- currentIcon.icon_type === 'link' ? currentIcon.icon : currentIcon.icon_url- }- />- </button>+ <IconPicker value={pickerValue} onValueChange={setSelectedIcon}>+ <IconPickerTrigger+ aria-label={t(($) => $['iconPicker.title'], { ns: 'app' })}+ className="shrink-0 cursor-pointer rounded-[10px]"+ >+ <IconPickerIcon size="large" />+ </IconPickerTrigger>+ <IconPickerContent />+ </IconPicker><Inputid={nameInputId}value={name}@@ -344,12 +340,6 @@ const CreateAppModal = ({</div></DialogContent></Dialog>- <IconPickerDialog- open={showIconPicker}- defaultValue={pickerDefaultValue}- onOpenChange={setShowIconPicker}- onConfirm={setSelectedIcon}- /></>)}diff --git a/web/app/components/rag-pipeline/components/publish-as-knowledge-pipeline-modal.tsx b/web/app/components/rag-pipeline/components/publish-as-knowledge-pipeline-modal.tsxindex 41d6f33f911..d6c973e8cae 100644--- a/web/app/components/rag-pipeline/components/publish-as-knowledge-pipeline-modal.tsx+++ b/web/app/components/rag-pipeline/components/publish-as-knowledge-pipeline-modal.tsx@@ -9,8 +9,12 @@ import { Input } from '@langgenius/dify-ui/input'import { Textarea } from '@langgenius/dify-ui/textarea'import { useCallback, useState } from 'react'import { useTranslation } from 'react-i18next'-import AppIcon from '@/app/components/base/app-icon'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import { useWorkflowStore } from '@/app/components/workflow/store'type PublishAsKnowledgePipelineModalProps = {@@ -28,7 +32,6 @@ const PublishAsKnowledgePipelineModal = ({const [pipelineName, setPipelineName] = useState(() => workflowStore.getState().knowledgeName!)const [pipelineIcon, setPipelineIcon] = useState(() => workflowStore.getState().knowledgeIcon!)const [description, setDescription] = useState('')- const [showIconPicker, setShowIconPicker] = useState(false)const handleSelectIcon = useCallback((item: IconPickerValue) => {if (item.type === 'image') {@@ -100,22 +103,30 @@ const PublishAsKnowledgePipelineModal = ({}/></Field>- <button- type="button"- aria-label={`${t(($) => $['operation.edit'], { ns: 'common' })} ${t(($) => $['common.publishAsPipeline.name'], { ns: 'pipeline' })}`}- onClick={() => {- setShowIconPicker(true)- }}- className="mt-2 shrink-0 cursor-pointer rounded-2xl focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"+ <IconPicker+ value={+ pipelineIcon.icon_type === 'emoji'+ ? {+ type: 'emoji',+ icon: pipelineIcon.icon,+ background: pipelineIcon.icon_background,+ }+ : {+ type: 'image',+ fileId: pipelineIcon.icon,+ url: pipelineIcon.icon_url || '',+ }+ }+ onValueChange={handleSelectIcon}>- <AppIcon- size="xxl"- iconType={pipelineIcon?.icon_type}- icon={pipelineIcon?.icon}- background={pipelineIcon?.icon_background}- imageUrl={pipelineIcon?.icon_url}- />- </button>+ <IconPickerTrigger+ aria-label={`${t(($) => $['operation.edit'], { ns: 'common' })} ${t(($) => $['common.publishAsPipeline.name'], { ns: 'pipeline' })}`}+ className="mt-2 shrink-0 cursor-pointer rounded-2xl"+ >+ <IconPickerIcon size="xxl" />+ </IconPickerTrigger>+ <IconPickerContent />+ </IconPicker></div><Field name="description"><FieldLabel>@@ -146,20 +157,6 @@ const PublishAsKnowledgePipelineModal = ({{t(($) => $['common.publish'], { ns: 'workflow' })}</Button></div>- <IconPickerDialog- open={showIconPicker}- defaultValue={- pipelineIcon.icon_type === 'emoji'- ? {- type: 'emoji',- icon: pipelineIcon.icon,- background: pipelineIcon.icon_background,- }- : { type: 'image', fileId: pipelineIcon.icon, url: pipelineIcon.icon_url || '' }- }- onOpenChange={setShowIconPicker}- onConfirm={handleSelectIcon}- /></form></DialogContent></Dialog>diff --git a/web/app/components/tools/edit-custom-collection-modal/__tests__/index.spec.tsx b/web/app/components/tools/edit-custom-collection-modal/__tests__/index.spec.tsxindex ee8217a3688..6651264328c 100644--- a/web/app/components/tools/edit-custom-collection-modal/__tests__/index.spec.tsx+++ b/web/app/components/tools/edit-custom-collection-modal/__tests__/index.spec.tsx@@ -1,4 +1,5 @@import type { ModalContextState } from '@/context/modal-context'+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'import {act,fireEvent,@@ -6,8 +7,10 @@ import {screen,waitFor,} from '@testing-library/react'+import userEvent from '@testing-library/user-event'import { NuqsTestingAdapter } from 'nuqs/adapters/testing'import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'+import { emojiCatalogOptions } from '@/app/components/base/icon-picker/emoji-data'import { AuthHeaderPrefix, AuthType } from '@/app/components/tools/types'import { toast } from '@/app/notifications'import { parseParamsSchema } from '@/service/tools'@@ -401,6 +404,39 @@ describe('EditCustomCollectionModal', () => {).toBeInTheDocument()})+ it('saves the confirmed icon without submitting the collection from the picker', async () => {+ const user = userEvent.setup()+ const client = new QueryClient()+ client.setQueryData(emojiCatalogOptions.queryKey, [])+ render(+ <QueryClientProvider client={client}>+ <EditCustomCollectionModal payload={undefined} onHide={mockOnHide} onAdd={mockOnAdd} />+ </QueryClientProvider>,+ )+ await user.type(+ screen.getByPlaceholderText('tools.createTool.toolNamePlaceHolder'),+ 'provider',+ )+ fireEvent.change(screen.getByPlaceholderText('tools.createTool.schemaPlaceHolder'), {+ target: { value: '{}' },+ })+ await waitFor(() => expect(parseParamsSchemaMock).toHaveBeenCalledWith('{}'))+ await user.click(screen.getByRole('button', { name: 'tools.createTool.changeIcon' }))+ await user.click(screen.getByRole('radio', { name: 'app.iconPicker.color.green' }))+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.ok' }))+ expect(mockOnAdd).not.toHaveBeenCalled()+ await waitFor(() =>+ expect(+ screen.queryByRole('dialog', { name: 'app.iconPicker.title' }),+ ).not.toBeInTheDocument(),+ )+ await user.click(screen.getByRole('button', { name: 'common.operation.save' }))+ expect(mockOnAdd).toHaveBeenCalledExactlyOnceWith(+ expect.objectContaining({ icon: { content: '🕵️', background: '#F3FEE7' } }),+ )+ client.clear()+ })+it('should render icon section', () => {renderModal()diff --git a/web/app/components/tools/edit-custom-collection-modal/index.tsx b/web/app/components/tools/edit-custom-collection-modal/index.tsxindex b15f5b18a53..3535c526fb9 100644--- a/web/app/components/tools/edit-custom-collection-modal/index.tsx+++ b/web/app/components/tools/edit-custom-collection-modal/index.tsx@@ -21,8 +21,12 @@ import { produce } from 'immer'import * as React from 'react'import { useEffect, useState } from 'react'import { useTranslation } from 'react-i18next'-import AppIcon from '@/app/components/base/app-icon'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import LabelSelector from '@/app/components/tools/labels/selector'import { toast } from '@/app/notifications'import { parseParamsSchema } from '@/service/tools'@@ -91,7 +95,6 @@ const EditCustomCollectionModal: FC<Props> = ({}}, [isEdit, payload])- const [showEmojiPicker, setShowEmojiPicker] = useState(false)const emoji = customCollection.iconconst setEmoji = (emoji: Emoji) => {const newCollection = produce(customCollection, (draft) => {@@ -256,20 +259,30 @@ const EditCustomCollectionModal: FC<Props> = ({<span className="ml-1 text-red-500">*</span></label><div className="flex items-center justify-between gap-3">- <IconButton- aria-label={t(($) => $['createTool.changeIcon'], { ns: 'tools' })}- className="size-10 rounded-[10px] p-0"- onClick={() => {- setShowEmojiPicker(true)+ <IconPicker+ value={{+ type: 'emoji',+ icon: emoji.content,+ background: emoji.background,+ }}+ onValueChange={(value) => {+ if (value.type !== 'emoji') return+ const { icon, background: icon_background } = value+ setEmoji({ content: icon, background: icon_background })}}>- <AppIcon- decorative- size="large"- icon={emoji.content}- background={emoji.background}+ <IconPickerTrigger+ render={+ <IconButton+ aria-label={t(($) => $['createTool.changeIcon'], { ns: 'tools' })}+ className="size-10 rounded-[10px] p-0"+ >+ <IconPickerIcon size="large" />+ </IconButton>+ }/>- </IconButton>+ <IconPickerContent enableImageUpload={false} />+ </IconPicker><Inputid={providerNameInputId}className="h-10 grow"@@ -487,21 +500,6 @@ const EditCustomCollectionModal: FC<Props> = ({</Button></div></div>- <IconPickerDialog- enableImageUpload={false}- defaultValue={{- type: 'emoji',- icon: emoji.content,- background: emoji.background,- }}- open={showEmojiPicker}- onOpenChange={setShowEmojiPicker}- onConfirm={(value) => {- if (value.type !== 'emoji') return- const { icon, background: icon_background } = value- setEmoji({ content: icon, background: icon_background })- }}- />{credentialsModalShow && (<ConfigCredentialspositionCenter={isAdd}diff --git a/web/app/components/tools/mcp/hooks/__tests__/use-mcp-modal-form.spec.ts b/web/app/components/tools/mcp/hooks/__tests__/use-mcp-modal-form.spec.tsindex 75ee8a0ade5..2396c324f06 100644--- a/web/app/components/tools/mcp/hooks/__tests__/use-mcp-modal-form.spec.ts+++ b/web/app/components/tools/mcp/hooks/__tests__/use-mcp-modal-form.spec.ts@@ -336,18 +336,6 @@ describe('useMCPModalForm', () => {expect(result.current.state.appIcon).toEqual(newIcon)})- it('should toggle showIconPicker', () => {- const { result } = renderHook(() => useMCPModalForm())-- expect(result.current.state.showIconPicker).toBe(false)-- act(() => {- result.current.actions.setShowIconPicker(true)- })-- expect(result.current.state.showIconPicker).toBe(true)- })-it('should reset icon to default', () => {const { result } = renderHook(() => useMCPModalForm())diff --git a/web/app/components/tools/mcp/hooks/use-mcp-modal-form.ts b/web/app/components/tools/mcp/hooks/use-mcp-modal-form.tsindex 5dadb013cdd..43b6e63e217 100644--- a/web/app/components/tools/mcp/hooks/use-mcp-modal-form.ts+++ b/web/app/components/tools/mcp/hooks/use-mcp-modal-form.ts@@ -47,7 +47,6 @@ type MCPModalFormState = {url: stringname: stringappIcon: IconPickerValue- showIconPicker: booleanserverIdentifier: stringtimeout: numbersseReadTimeout: number@@ -63,7 +62,6 @@ type MCPModalFormActions = {setUrl: (url: string) => voidsetName: (name: string) => voidsetAppIcon: (icon: IconPickerValue) => void- setShowIconPicker: (show: boolean) => voidsetServerIdentifier: (id: string) => voidsetTimeout: (timeout: number) => voidsetSseReadTimeout: (timeout: number) => void@@ -93,7 +91,6 @@ export const useMCPModalForm = (data?: ToolWithProvider) => {const [url, setUrl] = useState(() => data?.server_url || '')const [name, setName] = useState(() => data?.name || '')const [appIcon, setAppIcon] = useState<IconPickerValue>(() => getIcon(data))- const [showIconPicker, setShowIconPicker] = useState(false)const [serverIdentifier, setServerIdentifier] = useState(() => data?.server_identifier || '')const [timeout, setMcpTimeout] = useState(() => data?.configuration?.timeout || 30)const [sseReadTimeout, setSseReadTimeout] = useState(@@ -175,7 +172,6 @@ export const useMCPModalForm = (data?: ToolWithProvider) => {url,name,appIcon,- showIconPicker,serverIdentifier,timeout,sseReadTimeout,@@ -192,7 +188,6 @@ export const useMCPModalForm = (data?: ToolWithProvider) => {setUrl,setName,setAppIcon,- setShowIconPicker,setServerIdentifier,setTimeout: setMcpTimeout,setSseReadTimeout,diff --git a/web/app/components/tools/mcp/modal.tsx b/web/app/components/tools/mcp/modal.tsxindex 8764aa92d79..698e08cb45d 100644--- a/web/app/components/tools/mcp/modal.tsx+++ b/web/app/components/tools/mcp/modal.tsx@@ -13,8 +13,12 @@ import { Switch } from '@langgenius/dify-ui/switch'import { useSuspenseQuery } from '@tanstack/react-query'import { useId } from 'react'import { useTranslation } from 'react-i18next'-import AppIcon from '@/app/components/base/app-icon'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import { MCPAuthMethod } from '@/app/components/tools/types'import { toast } from '@/app/notifications'import { systemFeaturesQueryOptions } from '@/features/system-features/client'@@ -196,33 +200,34 @@ const MCPModalContent: FC<MCPModalContentProps> = ({ data, onConfirm, onHide })/></div><div className="pt-2">- <IconButton- aria-label={t(($) => $['mcp.modal.changeIcon'], { ns: 'tools' })}- className="group/edit-icon size-14 rounded-2xl p-0"- onClick={() => actions.setShowIconPicker(true)}- >- <AppIcon- decorative- iconType={state.appIcon.type}- icon={state.appIcon.type === 'emoji' ? state.appIcon.icon : state.appIcon.fileId}- background={state.appIcon.type === 'emoji' ? state.appIcon.background : undefined}- imageUrl={state.appIcon.type === 'image' ? state.appIcon.url : undefined}- innerIcon={- shouldUseMcpIconForAppIcon(- state.appIcon.type,- state.appIcon.type === 'emoji' ? state.appIcon.icon : '',- ) ? (- <span- aria-hidden- className="i-custom-vender-other-mcp size-8 text-text-primary-on-surface"+ <IconPicker value={state.appIcon} onValueChange={handleIconSelect}>+ <IconPickerTrigger+ render={+ <IconButton+ aria-label={t(($) => $['mcp.modal.changeIcon'], { ns: 'tools' })}+ className="group/edit-icon size-14 rounded-2xl p-0"+ >+ <IconPickerIcon+ innerIcon={+ shouldUseMcpIconForAppIcon(+ state.appIcon.type,+ state.appIcon.type === 'emoji' ? state.appIcon.icon : '',+ ) ? (+ <span+ aria-hidden+ className="i-custom-vender-other-mcp size-8 text-text-primary-on-surface"+ />+ ) : undefined+ }+ size="xxl"+ className="relative rounded-2xl"+ showEditIcon/>- ) : undefined+ </IconButton>}- size="xxl"- className="relative rounded-2xl"- showEditIcon/>- </IconButton>+ <IconPickerContent />+ </IconPicker></div></div>@@ -335,13 +340,6 @@ const MCPModalContent: FC<MCPModalContentProps> = ({ data, onConfirm, onHide })</Button><Button onClick={onHide}>{t(($) => $['mcp.modal.cancel'], { ns: 'tools' })}</Button></div>-- <IconPickerDialog- open={state.showIconPicker}- defaultValue={state.appIcon}- onOpenChange={actions.setShowIconPicker}- onConfirm={handleIconSelect}- /></>)}diff --git a/web/app/components/tools/workflow-tool/__tests__/index.spec.tsx b/web/app/components/tools/workflow-tool/__tests__/index.spec.tsxindex c42fc703a72..bfe652cc925 100644--- a/web/app/components/tools/workflow-tool/__tests__/index.spec.tsx+++ b/web/app/components/tools/workflow-tool/__tests__/index.spec.tsx@@ -1,17 +1,11 @@import type { WorkflowToolDrawerPayload } from '../index'+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'import { render, screen, waitFor, within } from '@testing-library/react'import userEvent from '@testing-library/user-event'import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'+import { emojiCatalogOptions } from '@/app/components/base/icon-picker/emoji-data'import { WorkflowToolDrawer } from '../index'-vi.mock('@/app/components/base/app-icon', () => ({- default: ({ onClick, icon }: { onClick?: () => void; icon: string }) => (- <button data-testid="app-icon" onClick={onClick}>- {icon}- </button>- ),-}))-vi.mock('@/app/components/tools/labels/selector', () => ({default: ({ value, onChange }: { value: string[]; onChange: (labels: string[]) => void }) => (<div data-testid="label-selector">@@ -115,6 +109,33 @@ describe('WorkflowToolDrawer', () => {expect(onCreate.mock.calls[0]![0]).not.toHaveProperty('outputParameters')})+ it('saves the confirmed icon without submitting the tool from the picker', async () => {+ const user = userEvent.setup()+ const client = new QueryClient()+ client.setQueryData(emojiCatalogOptions.queryKey, [])+ const onCreate = vi.fn()+ render(+ <QueryClientProvider client={client}>+ <WorkflowToolDrawer isAdd payload={createPayload()} onHide={vi.fn()} onCreate={onCreate} />+ </QueryClientProvider>,+ )++ await user.click(screen.getByRole('button', { name: 'tools.createTool.changeIcon' }))+ await user.click(screen.getByRole('radio', { name: 'app.iconPicker.color.green' }))+ await user.click(screen.getByRole('button', { name: 'app.iconPicker.ok' }))+ expect(onCreate).not.toHaveBeenCalled()+ await waitFor(() =>+ expect(+ screen.queryByRole('dialog', { name: 'app.iconPicker.title' }),+ ).not.toBeInTheDocument(),+ )+ await user.click(screen.getByRole('button', { name: 'common.operation.save' }))+ expect(onCreate).toHaveBeenCalledExactlyOnceWith(+ expect.objectContaining({ icon: { content: '🔧', background: '#F3FEE7' } }),+ )+ client.clear()+ })+it('should block invalid tool-call names before saving', async () => {const user = userEvent.setup()const onCreate = vi.fn()diff --git a/web/app/components/tools/workflow-tool/index.tsx b/web/app/components/tools/workflow-tool/index.tsxindex f3a8b09f499..29cddfa4d8f 100644--- a/web/app/components/tools/workflow-tool/index.tsx+++ b/web/app/components/tools/workflow-tool/index.tsx@@ -29,8 +29,12 @@ import { produce } from 'immer'import * as React from 'react'import { useMemo, useState } from 'react'import { useTranslation } from 'react-i18next'-import AppIcon from '@/app/components/base/app-icon'-import { IconPickerDialog } from '@/app/components/base/icon-picker'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'import LabelSelector from '@/app/components/tools/labels/selector'import ConfirmModal from '@/app/components/tools/workflow-tool/confirm-modal'import MethodSelector from '@/app/components/tools/workflow-tool/method-selector'@@ -239,7 +243,6 @@ export function WorkflowToolDrawer({const parameterId = React.useId()const toolNameLabelId = React.useId()- const [showEmojiPicker, setShowEmojiPicker] = useState<boolean>(false)const [emoji, setEmoji] = useState<Emoji>(payload.icon)const [label, setLabel] = useState<string>(payload.label)const [name, setName] = useState(payload.name)@@ -339,36 +342,41 @@ export function WorkflowToolDrawer({><div className="h-0 grow space-y-4 overflow-y-auto px-6 py-3">{/* name & icon */}- <Field name="label" className="gap-0">- <FieldLabel className="py-2 text-text-primary">- {t(($) => $['createTool.name'], { ns: 'tools' })}{' '}- <span aria-hidden className="ml-1 text-text-destructive">- *- </span>- </FieldLabel>- <div className="flex items-center justify-between gap-3">- <button- type="button"- aria-label={t(($) => $['createTool.changeIcon'], { ns: 'tools' })}- className="shrink-0 cursor-pointer rounded-[10px] focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"- onClick={() => setShowEmojiPicker(true)}- >- <AppIcon- decorative- size="large"- iconType="emoji"- icon={emoji.content}- background={emoji.background}+ <IconPicker+ value={{+ type: 'emoji',+ icon: emoji.content,+ background: emoji.background,+ }}+ onValueChange={(payload) => {+ if (payload.type === 'emoji')+ setEmoji({ content: payload.icon, background: payload.background })+ }}+ >+ <Field name="label" className="gap-0">+ <FieldLabel className="py-2 text-text-primary">+ {t(($) => $['createTool.name'], { ns: 'tools' })}{' '}+ <span aria-hidden className="ml-1 text-text-destructive">+ *+ </span>+ </FieldLabel>+ <div className="flex items-center justify-between gap-3">+ <IconPickerTrigger+ aria-label={t(($) => $['createTool.changeIcon'], { ns: 'tools' })}+ className="shrink-0 cursor-pointer rounded-[10px]"+ >+ <IconPickerIcon size="large" />+ </IconPickerTrigger>+ <Input+ className="h-10 min-w-0 flex-1"+ placeholder={t(($) => $['createTool.toolNamePlaceHolder'], { ns: 'tools' })!}+ value={label}+ onValueChange={(value) => setLabel(value)}/>- </button>- <Input- className="h-10 min-w-0 flex-1"- placeholder={t(($) => $['createTool.toolNamePlaceHolder'], { ns: 'tools' })!}- value={label}- onValueChange={(value) => setLabel(value)}- />- </div>- </Field>+ </div>+ </Field>+ <IconPickerContent enableImageUpload={false} />+ </IconPicker>{/* name for tool call */}<Field name="name" className="gap-0" invalid={!isWorkflowToolNameValid(name)}><div className="flex items-center py-2 system-sm-medium text-text-primary">@@ -590,20 +598,6 @@ export function WorkflowToolDrawer({</div></form></WorkflowToolDrawerFrame>- <IconPickerDialog- open={showEmojiPicker}- enableImageUpload={false}- defaultValue={{- type: 'emoji',- icon: emoji.content,- background: emoji.background,- }}- onOpenChange={setShowEmojiPicker}- onConfirm={(payload) => {- if (payload.type === 'emoji')- setEmoji({ content: payload.icon, background: payload.background })- }}- />{confirmModalOpen && (<ConfirmModalshow={confirmModalOpen}diff --git a/web/app/components/workflow/nodes/agent-v2/components/__tests__/save-inline-agent-to-roster-dialog.spec.tsx b/web/app/components/workflow/nodes/agent-v2/components/__tests__/save-inline-agent-to-roster-dialog.spec.tsxindex 9378644d469..fb4356bcc1f 100644--- a/web/app/components/workflow/nodes/agent-v2/components/__tests__/save-inline-agent-to-roster-dialog.spec.tsx+++ b/web/app/components/workflow/nodes/agent-v2/components/__tests__/save-inline-agent-to-roster-dialog.spec.tsx@@ -24,29 +24,7 @@ vi.mock('@/app/notifications', () => ({toast: toastMock,}))-vi.mock('@/app/components/base/icon-picker', () => ({- __esModule: true,- IconPickerDialog: ({- defaultValue,- onConfirm,- open,- }: {- defaultValue?: { icon: string; background: string }- onConfirm: (payload: { type: 'emoji'; icon: string; background: string }) => void- open: boolean- }) =>- open ? (- <div>- <span>{`${defaultValue?.icon}:${defaultValue?.background}`}</span>- <button- type="button"- onClick={() => onConfirm({ type: 'emoji', icon: '🧠', background: '#E0F2FE' })}- >- Select brain icon- </button>- </div>- ) : null,-}))+vi.mock('@/app/components/base/icon-picker', () => import('@/test/icon-picker-mock'))vi.mock('@/service/console', () => ({consoleQuery: {diff --git a/web/app/components/workflow/nodes/agent-v2/components/save-inline-agent-to-roster-dialog.tsx b/web/app/components/workflow/nodes/agent-v2/components/save-inline-agent-to-roster-dialog.tsxindex fc75362528e..65f68ad7d00 100644--- a/web/app/components/workflow/nodes/agent-v2/components/save-inline-agent-to-roster-dialog.tsx+++ b/web/app/components/workflow/nodes/agent-v2/components/save-inline-agent-to-roster-dialog.tsx@@ -21,7 +21,6 @@ import { IconButton } from '@langgenius/dify-ui/icon-button'import { useMutation } from '@tanstack/react-query'import { useRef, useState } from 'react'import { useTranslation } from 'react-i18next'-import { IconPickerDialog } from '@/app/components/base/icon-picker'import { createAgentIconSelection } from '@/features/agent-v2/roster/components/agent-form'import { AgentFormFields } from '@/features/agent-v2/roster/components/agent-form-fields'import { consoleQuery } from '@/service/console'@@ -63,7 +62,6 @@ function SaveInlineAgentToRosterFormSession({icon: createAgentIconSelection(initialAgent),}))const [agentIcon, setAgentIcon] = useState(initialValues.icon)- const [iconPickerOpen, setIconPickerOpen] = useState(false)return (<>@@ -84,7 +82,7 @@ function SaveInlineAgentToRosterFormSession({defaultValues={initialValues.fields}icon={agentIcon}iconAriaLabel={t(($) => $['roster.saveToRosterForm.changeIcon'], { ns: 'agentRoster' })}- onIconClick={() => setIconPickerOpen(true)}+ onIconChange={setAgentIcon}/><div className="flex shrink-0 justify-end gap-2 px-6 pt-5 pb-6"><Button type="button" className="min-w-18" onClick={onCancel} disabled={pending}>@@ -95,12 +93,6 @@ function SaveInlineAgentToRosterFormSession({</Button></div></Form>- <IconPickerDialog- open={iconPickerOpen}- defaultValue={agentIcon.type === 'link' ? undefined : agentIcon}- onOpenChange={setIconPickerOpen}- onConfirm={setAgentIcon}- /></>)}diff --git a/web/features/agent-v2/roster/components/__tests__/duplicate-agent-dialog.spec.tsx b/web/features/agent-v2/roster/components/__tests__/duplicate-agent-dialog.spec.tsxindex 4b81154e1cf..edb1d73ffe2 100644--- a/web/features/agent-v2/roster/components/__tests__/duplicate-agent-dialog.spec.tsx+++ b/web/features/agent-v2/roster/components/__tests__/duplicate-agent-dialog.spec.tsx@@ -16,16 +16,7 @@ vi.mock('@tanstack/react-query', () => ({}),}))-vi.mock('@/app/components/base/icon-picker', () => ({- __esModule: true,- IconPickerDialog: ({- defaultValue,- open,- }: {- defaultValue?: { icon: string; background: string }- open: boolean- }) => (open ? <span>{`${defaultValue?.icon}:${defaultValue?.background}`}</span> : null),-}))+vi.mock('@/app/components/base/icon-picker', () => import('@/test/icon-picker-mock'))vi.mock('@/service/console', () => ({consoleQuery: {diff --git a/web/features/agent-v2/roster/components/__tests__/edit-agent-dialog.spec.tsx b/web/features/agent-v2/roster/components/__tests__/edit-agent-dialog.spec.tsxindex ca36620d2d1..7726025bac1 100644--- a/web/features/agent-v2/roster/components/__tests__/edit-agent-dialog.spec.tsx+++ b/web/features/agent-v2/roster/components/__tests__/edit-agent-dialog.spec.tsx@@ -24,29 +24,7 @@ vi.mock('@/app/notifications', () => ({toast: toastMock,}))-vi.mock('@/app/components/base/icon-picker', () => ({- __esModule: true,- IconPickerDialog: ({- defaultValue,- onConfirm,- open,- }: {- defaultValue?: { icon: string; background: string }- onConfirm: (payload: { type: 'emoji'; icon: string; background: string }) => void- open: boolean- }) =>- open ? (- <div>- <span>{`${defaultValue?.icon}:${defaultValue?.background}`}</span>- <button- type="button"- onClick={() => onConfirm({ type: 'emoji', icon: '🧠', background: '#E0F2FE' })}- >- Select brain icon- </button>- </div>- ) : null,-}))+vi.mock('@/app/components/base/icon-picker', () => import('@/test/icon-picker-mock'))vi.mock('@/service/console', () => ({consoleQuery: {diff --git a/web/features/agent-v2/roster/components/__tests__/edit-agent-icon-session.spec.tsx b/web/features/agent-v2/roster/components/__tests__/edit-agent-icon-session.spec.tsxnew file mode 100644index 00000000000..17b9e209976--- /dev/null+++ b/web/features/agent-v2/roster/components/__tests__/edit-agent-icon-session.spec.tsx@@ -0,0 +1,102 @@+import type { AgentAppPartial } from '@dify/contracts/api/console/agent/types.gen'+import { screen, waitFor, within } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { mockEmojiData, renderWithEmoji } from '@/test/emoji-picker'+import { EditAgentDialog } from '../edit-agent-dialog'++const updateAgent = vi.hoisted(() => vi.fn().mockResolvedValue({}))++vi.mock('@/service/console', async (importOriginal) => {+ const actual = await importOriginal<typeof import('@/service/console')>()+ return {+ ...actual,+ consoleQuery: {+ ...actual.consoleQuery,+ files: actual.consoleQuery.files,+ agent: {+ ...actual.consoleQuery.agent,+ byAgentId: {+ ...actual.consoleQuery.agent.byAgentId,+ put: { mutationOptions: () => ({ mutationFn: updateAgent }) },+ },+ },+ },+ }+})++mockEmojiData()++const agent: AgentAppPartial = {+ id: 'agent-1',+ name: 'Research Agent',+ description: 'Find market materials.',+ role: 'Research Assistant',+ mode: 'agent',+ icon_type: 'emoji',+ icon: '🧸',+ icon_background: '#F5F3FF',+ icon_url: null,+ permission_keys: [],+}++it('keeps icon drafts out of form dirty state and submits only the confirmed icon with text edits', async () => {+ const user = userEvent.setup()+ renderWithEmoji(<EditAgentDialog agent={agent} open onOpenChange={vi.fn()} />)+ const formDialog = screen.getByRole('dialog', { name: 'agentRoster.roster.editDialog.title' })+ const save = within(formDialog).getByRole('button', { name: 'common.operation.save' })+ const iconTrigger = within(formDialog).getByRole('button', {+ name: 'agentRoster.roster.createForm.changeIcon',+ })+ expect(save).toBeDisabled()++ await user.click(iconTrigger)+ const picker = screen.getByRole('dialog', { name: 'app.iconPicker.title' })+ await user.type(within(picker).getByPlaceholderText('app.iconPicker.search'), 'bear')+ await user.click(within(picker).getByRole('radio', { name: 'app.iconPicker.color.green' }))+ await user.keyboard('{Escape}')+ await waitFor(() => expect(picker).not.toBeInTheDocument())+ expect(save).toBeDisabled()+ expect(updateAgent).not.toHaveBeenCalled()++ const name = within(formDialog).getByRole('textbox', {+ name: 'agentRoster.roster.createForm.nameLabel',+ })+ await user.clear(name)+ await user.type(name, 'Market Agent')+ expect(save).toBeEnabled()+ await user.click(iconTrigger)+ const reopenedPicker = screen.getByRole('dialog', { name: 'app.iconPicker.title' })+ await user.type(within(reopenedPicker).getByPlaceholderText('app.iconPicker.search'), 'bear')+ await user.click(+ within(reopenedPicker).getByRole('radio', { name: 'app.iconPicker.color.green' }),+ )+ await user.keyboard('{Escape}')+ await waitFor(() => expect(reopenedPicker).not.toBeInTheDocument())+ expect(save).toBeEnabled()++ await user.click(iconTrigger)+ const confirmingPicker = screen.getByRole('dialog', { name: 'app.iconPicker.title' })+ await user.click(+ within(confirmingPicker).getByRole('radio', { name: 'app.iconPicker.color.green' }),+ )+ await user.click(within(confirmingPicker).getByRole('button', { name: 'app.iconPicker.ok' }))+ await waitFor(() => expect(confirmingPicker).not.toBeInTheDocument())+ expect(updateAgent).not.toHaveBeenCalled()+ await user.click(save)+ await waitFor(() =>+ expect(updateAgent).toHaveBeenCalledWith(+ {+ params: { agent_id: 'agent-1' },+ body: {+ name: 'Market Agent',+ description: 'Find market materials.',+ role: 'Research Assistant',+ icon_type: 'emoji',+ icon: '🧸',+ icon_background: '#F3FEE7',+ },+ },+ expect.anything(),+ ),+ )+})diff --git a/web/features/agent-v2/roster/components/agent-form-fields.tsx b/web/features/agent-v2/roster/components/agent-form-fields.tsxindex 4bfe7af4e65..126d4ed9a42 100644--- a/web/features/agent-v2/roster/components/agent-form-fields.tsx+++ b/web/features/agent-v2/roster/components/agent-form-fields.tsx@@ -1,16 +1,22 @@import type { Ref } from 'react'import type { AgentFormValues, AgentIconSelection } from './agent-form'+import type { IconPickerValue } from '@/app/components/base/icon-picker'import { Field, FieldError, FieldLabel } from '@langgenius/dify-ui/field'import { Input } from '@langgenius/dify-ui/input'import { Textarea } from '@langgenius/dify-ui/textarea'import { useTranslation } from 'react-i18next'-import AppIcon from '@/app/components/base/app-icon'+import {+ IconPicker,+ IconPickerContent,+ IconPickerIcon,+ IconPickerTrigger,+} from '@/app/components/base/icon-picker'type AgentFormFieldsProps = {defaultValues: AgentFormValuesicon: AgentIconSelectioniconAriaLabel: string- onIconClick: () => void+ onIconChange: (value: IconPickerValue) => voidref: Ref<HTMLInputElement>}@@ -18,7 +24,7 @@ export function AgentFormFields({defaultValues,icon,iconAriaLabel,- onIconClick,+ onIconChange,ref,}: AgentFormFieldsProps) {const { t } = useTranslation(['agentRoster'])@@ -27,22 +33,12 @@ export function AgentFormFields({return (<div className="min-h-0 flex-1 space-y-5 overflow-y-auto overscroll-contain px-6 py-3"><div className="flex items-start gap-4">- <button- type="button"- aria-label={iconAriaLabel}- className="shrink-0 rounded-full focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"- onClick={onIconClick}- >- <AppIcon- size="xxl"- rounded- className="size-16 cursor-pointer"- iconType={icon.type === 'link' ? 'image' : icon.type}- icon={icon.type === 'emoji' ? icon.icon : undefined}- background={icon.type === 'emoji' ? icon.background : undefined}- imageUrl={icon.type === 'emoji' ? undefined : icon.url}- />- </button>+ <IconPicker value={icon} onValueChange={onIconChange}>+ <IconPickerTrigger aria-label={iconAriaLabel} className="shrink-0 rounded-full">+ <IconPickerIcon size="xxl" rounded className="size-16 cursor-pointer" />+ </IconPickerTrigger>+ <IconPickerContent />+ </IconPicker><div className="flex min-w-0 flex-1 flex-col items-start gap-3 pb-1 sm:flex-row"><Fieldname="name"diff --git a/web/features/agent-v2/roster/components/create-agent-dialog.tsx b/web/features/agent-v2/roster/components/create-agent-dialog.tsxindex 3596da59b80..1b8122cfa5e 100644--- a/web/features/agent-v2/roster/components/create-agent-dialog.tsx+++ b/web/features/agent-v2/roster/components/create-agent-dialog.tsx@@ -16,7 +16,6 @@ import { IconButton } from '@langgenius/dify-ui/icon-button'import { useMutation } from '@tanstack/react-query'import { useRef, useState } from 'react'import { useTranslation } from 'react-i18next'-import { IconPickerDialog } from '@/app/components/base/icon-picker'import { AgentScope } from '@/features/agent-v2/analytics'import { useRouter } from '@/next/navigation'import { consoleQuery } from '@/service/console'@@ -52,7 +51,6 @@ function CreateAgentFormSession({const { t } = useTranslation(['agentRoster'])const { t: tCommon } = useTranslation(['common'])const [agentIcon, setAgentIcon] = useState<AgentIconSelection>(defaultAgentIcon)- const [iconPickerOpen, setIconPickerOpen] = useState(false)return (<>@@ -73,7 +71,7 @@ function CreateAgentFormSession({defaultValues={createAgentDefaultValues}icon={agentIcon}iconAriaLabel={t(($) => $['roster.createForm.changeIcon'], { ns: 'agentRoster' })}- onIconClick={() => setIconPickerOpen(true)}+ onIconChange={setAgentIcon}/><div className="flex shrink-0 justify-end gap-2 px-6 pt-5 pb-6"><Button type="button" className="min-w-18" onClick={onCancel} disabled={pending}>@@ -84,12 +82,6 @@ function CreateAgentFormSession({</Button></div></Form>- <IconPickerDialog- open={iconPickerOpen}- defaultValue={agentIcon.type === 'link' ? undefined : agentIcon}- onOpenChange={setIconPickerOpen}- onConfirm={setAgentIcon}- /></>)}diff --git a/web/features/agent-v2/roster/components/duplicate-agent-dialog.tsx b/web/features/agent-v2/roster/components/duplicate-agent-dialog.tsxindex 683f02c5762..7bbdeb85634 100644--- a/web/features/agent-v2/roster/components/duplicate-agent-dialog.tsx+++ b/web/features/agent-v2/roster/components/duplicate-agent-dialog.tsx@@ -15,7 +15,6 @@ import { IconButton } from '@langgenius/dify-ui/icon-button'import { useMutation, useQueryClient } from '@tanstack/react-query'import { useRef, useState } from 'react'import { useTranslation } from 'react-i18next'-import { IconPickerDialog } from '@/app/components/base/icon-picker'import { toast } from '@/app/notifications'import { consoleQuery } from '@/service/console'import { createAgentIconSelection } from './agent-form'@@ -59,7 +58,6 @@ function DuplicateAgentFormSession({sourceName: agent.name,}))const [agentIcon, setAgentIcon] = useState(initialValues.icon)- const [iconPickerOpen, setIconPickerOpen] = useState(false)return (<>@@ -86,7 +84,7 @@ function DuplicateAgentFormSession({ns: 'agentRoster',name: initialValues.sourceName,})}- onIconClick={() => setIconPickerOpen(true)}+ onIconChange={setAgentIcon}/><div className="flex shrink-0 justify-end gap-2 px-6 pt-5 pb-6"><Button type="button" className="min-w-18" onClick={onCancel} disabled={pending}>@@ -97,12 +95,6 @@ function DuplicateAgentFormSession({</Button></div></Form>- <IconPickerDialog- open={iconPickerOpen}- defaultValue={agentIcon.type === 'link' ? undefined : agentIcon}- onOpenChange={setIconPickerOpen}- onConfirm={setAgentIcon}- /></>)}diff --git a/web/features/agent-v2/roster/components/edit-agent-dialog.tsx b/web/features/agent-v2/roster/components/edit-agent-dialog.tsxindex 88661b83134..e34b9631670 100644--- a/web/features/agent-v2/roster/components/edit-agent-dialog.tsx+++ b/web/features/agent-v2/roster/components/edit-agent-dialog.tsx@@ -15,7 +15,6 @@ import { IconButton } from '@langgenius/dify-ui/icon-button'import { useMutation } from '@tanstack/react-query'import { useRef, useState } from 'react'import { useTranslation } from 'react-i18next'-import { IconPickerDialog } from '@/app/components/base/icon-picker'import { consoleQuery } from '@/service/console'import { createAgentIconSelection, getAgentIconKey } from './agent-form'import { AgentFormFields } from './agent-form-fields'@@ -65,7 +64,6 @@ function EditAgentFormSession({icon: createAgentIconSelection(agent),}))const [agentIcon, setAgentIcon] = useState(initialValues.icon)- const [iconPickerOpen, setIconPickerOpen] = useState(false)const [hasTextChanges, setHasTextChanges] = useState(false)const hasIconChanges = getAgentIconKey(agentIcon) !== getAgentIconKey(initialValues.icon)const hasChanges = hasTextChanges || hasIconChanges@@ -102,7 +100,7 @@ function EditAgentFormSession({defaultValues={initialValues.fields}icon={agentIcon}iconAriaLabel={t(($) => $['roster.createForm.changeIcon'], { ns: 'agentRoster' })}- onIconClick={() => setIconPickerOpen(true)}+ onIconChange={setAgentIcon}/><div className="flex shrink-0 justify-end gap-2 px-6 pt-5 pb-6"><Button type="button" className="min-w-18" onClick={onCancel} disabled={pending}>@@ -119,12 +117,6 @@ function EditAgentFormSession({</Button></div></Form>- <IconPickerDialog- open={iconPickerOpen}- defaultValue={agentIcon.type === 'link' ? undefined : agentIcon}- onOpenChange={setIconPickerOpen}- onConfirm={setAgentIcon}- /></>)}diff --git a/web/test/icon-picker-mock.tsx b/web/test/icon-picker-mock.tsxnew file mode 100644index 00000000000..a57c5450c69--- /dev/null+++ b/web/test/icon-picker-mock.tsx@@ -0,0 +1,54 @@+import type { ComponentProps, ReactNode } from 'react'+import type { IconPickerInputValue, IconPickerValue } from '@/app/components/base/icon-picker'+import { createContext, use, useState } from 'react'++type PickerContextValue = {+ value?: IconPickerInputValue+ onValueChange: (value: IconPickerValue) => void+ open: boolean+ setOpen: (open: boolean) => void+}++const PickerContext = createContext<PickerContextValue | null>(null)++const usePicker = () => use(PickerContext)!++/**+ * Stand-in for the icon picker parts in specs that own a form around it:+ * `vi.mock('@/app/components/base/icon-picker', () => import('@/test/icon-picker-mock'))`.+ * The trigger shows the committed icon as text, and the content confirms a fixed emoji.+ */+export function IconPicker({+ value,+ onValueChange,+ children,+}: Pick<PickerContextValue, 'value' | 'onValueChange'> & { children: ReactNode }) {+ const [open, setOpen] = useState(false)+ return <PickerContext value={{ value, onValueChange, open, setOpen }}>{children}</PickerContext>+}++export function IconPickerTrigger(props: ComponentProps<'button'>) {+ const { setOpen } = usePicker()+ return <button type="button" {...props} onClick={() => setOpen(true)} />+}++export function IconPickerIcon() {+ const { value } = usePicker()+ return value?.type === 'emoji' ? `${value.icon}:${value.background}` : value?.type+}++export function IconPickerContent() {+ const { open, setOpen, onValueChange } = usePicker()+ if (!open) return null+ return (+ <button+ type="button"+ onClick={() => {+ onValueChange({ type: 'emoji', icon: '🧠', background: '#E0F2FE' })+ setOpen(false)+ }}+ >+ Select brain icon+ </button>+ )+}