mirror of
				https://github.com/langgenius/dify.git
				synced 2025-10-31 02:42:59 +00:00 
			
		
		
		
	feat: enhance dataset icon handling by making icon background and URL optional
This commit is contained in:
		
							parent
							
								
									c480c3d881
								
							
						
					
					
						commit
						12c060b795
					
				| @ -3,7 +3,6 @@ import type { AppIconSelection } from '@/app/components/base/app-icon-picker' | |||||||
| import AppIconPicker from '@/app/components/base/app-icon-picker' | import AppIconPicker from '@/app/components/base/app-icon-picker' | ||||||
| import Input from '@/app/components/base/input' | import Input from '@/app/components/base/input' | ||||||
| import Textarea from '@/app/components/base/textarea' | import Textarea from '@/app/components/base/textarea' | ||||||
| import type { AppIconType } from '@/types/app' |  | ||||||
| import { RiCloseLine } from '@remixicon/react' | import { RiCloseLine } from '@remixicon/react' | ||||||
| import React, { useCallback, useRef, useState } from 'react' | import React, { useCallback, useRef, useState } from 'react' | ||||||
| import Button from '@/app/components/base/button' | import Button from '@/app/components/base/button' | ||||||
| @ -103,7 +102,7 @@ const EditPipelineInfo = ({ | |||||||
|             size='xxl' |             size='xxl' | ||||||
|             onClick={handleOpenAppIconPicker} |             onClick={handleOpenAppIconPicker} | ||||||
|             className='cursor-pointer' |             className='cursor-pointer' | ||||||
|             iconType={appIcon.type as AppIconType} |             iconType={appIcon.type} | ||||||
|             icon={appIcon.type === 'image' ? appIcon.fileId : appIcon.icon} |             icon={appIcon.type === 'image' ? appIcon.fileId : appIcon.icon} | ||||||
|             background={appIcon.type === 'image' ? undefined : appIcon.background} |             background={appIcon.type === 'image' ? undefined : appIcon.background} | ||||||
|             imageUrl={appIcon.type === 'image' ? appIcon.url : undefined} |             imageUrl={appIcon.type === 'image' ? appIcon.url : undefined} | ||||||
|  | |||||||
| @ -1,19 +1,21 @@ | |||||||
| 'use client' | 'use client' | ||||||
| 
 | 
 | ||||||
| import type { MouseEventHandler } from 'react' | import type { MouseEventHandler } from 'react' | ||||||
| import { useState } from 'react' | import { useCallback, useRef, useState } from 'react' | ||||||
| import { RiCloseLine } from '@remixicon/react' | import { RiCloseLine } from '@remixicon/react' | ||||||
| import { useContext } from 'use-context-selector' |  | ||||||
| import { useTranslation } from 'react-i18next' | import { useTranslation } from 'react-i18next' | ||||||
| import cn from '@/utils/classnames' | import cn from '@/utils/classnames' | ||||||
| import Button from '@/app/components/base/button' | import Button from '@/app/components/base/button' | ||||||
| import Input from '@/app/components/base/input' | import Input from '@/app/components/base/input' | ||||||
| import Textarea from '@/app/components/base/textarea' | import Textarea from '@/app/components/base/textarea' | ||||||
| import Modal from '@/app/components/base/modal' | import Modal from '@/app/components/base/modal' | ||||||
| import { ToastContext } from '@/app/components/base/toast' |  | ||||||
| import type { DataSet } from '@/models/datasets' | import type { DataSet } from '@/models/datasets' | ||||||
| import { updateDatasetSetting } from '@/service/datasets' | import { updateDatasetSetting } from '@/service/datasets' | ||||||
| import { noop } from 'lodash-es' | import { noop } from 'lodash-es' | ||||||
|  | import AppIcon from '../../base/app-icon' | ||||||
|  | import type { AppIconSelection } from '../../base/app-icon-picker' | ||||||
|  | import AppIconPicker from '../../base/app-icon-picker' | ||||||
|  | import Toast from '../../base/toast' | ||||||
| 
 | 
 | ||||||
| type RenameDatasetModalProps = { | type RenameDatasetModalProps = { | ||||||
|   show: boolean |   show: boolean | ||||||
| @ -24,16 +26,41 @@ type RenameDatasetModalProps = { | |||||||
| 
 | 
 | ||||||
| const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDatasetModalProps) => { | const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDatasetModalProps) => { | ||||||
|   const { t } = useTranslation() |   const { t } = useTranslation() | ||||||
|   const { notify } = useContext(ToastContext) |  | ||||||
|   const [loading, setLoading] = useState(false) |   const [loading, setLoading] = useState(false) | ||||||
|   const [name, setName] = useState<string>(dataset.name) |   const [name, setName] = useState<string>(dataset.name) | ||||||
|   const [description, setDescription] = useState<string>(dataset.description) |   const [description, setDescription] = useState<string>(dataset.description) | ||||||
|   const [externalKnowledgeId, setExternalKnowledgeId] = useState<string>(dataset.external_knowledge_info.external_knowledge_id) |   const [externalKnowledgeId] = useState<string>(dataset.external_knowledge_info.external_knowledge_id) | ||||||
|   const [externalKnowledgeApiId, setExternalKnowledgeApiId] = useState<string>(dataset.external_knowledge_info.external_knowledge_api_id) |   const [externalKnowledgeApiId] = useState<string>(dataset.external_knowledge_info.external_knowledge_api_id) | ||||||
|  |   const [appIcon, setAppIcon] = useState<AppIconSelection>( | ||||||
|  |     dataset.icon_info?.icon_type === 'image' | ||||||
|  |       ? { type: 'image' as const, url: dataset.icon_info?.icon_url || '', fileId: dataset.icon_info?.icon || '' } | ||||||
|  |       : { type: 'emoji' as const, icon: dataset.icon_info?.icon || '', background: dataset.icon_info?.icon_background || '' }, | ||||||
|  |   ) | ||||||
|  |   const [showAppIconPicker, setShowAppIconPicker] = useState(false) | ||||||
|  |   const previousAppIcon = useRef<AppIconSelection>( | ||||||
|  |     dataset.icon_info?.icon_type === 'image' | ||||||
|  |       ? { type: 'image' as const, url: dataset.icon_info?.icon_url || '', fileId: dataset.icon_info?.icon || '' } | ||||||
|  |       : { type: 'emoji' as const, icon: dataset.icon_info?.icon || '', background: dataset.icon_info?.icon_background || '' }, | ||||||
|  |   ) | ||||||
| 
 | 
 | ||||||
|   const onConfirm: MouseEventHandler = async () => { |   const handleOpenAppIconPicker = useCallback(() => { | ||||||
|  |     setShowAppIconPicker(true) | ||||||
|  |     previousAppIcon.current = appIcon | ||||||
|  |   }, [appIcon]) | ||||||
|  | 
 | ||||||
|  |   const handleSelectAppIcon = useCallback((icon: AppIconSelection) => { | ||||||
|  |     setAppIcon(icon) | ||||||
|  |     setShowAppIconPicker(false) | ||||||
|  |   }, []) | ||||||
|  | 
 | ||||||
|  |   const handleCloseAppIconPicker = useCallback(() => { | ||||||
|  |     setAppIcon(previousAppIcon.current) | ||||||
|  |     setShowAppIconPicker(false) | ||||||
|  |   }, []) | ||||||
|  | 
 | ||||||
|  |   const onConfirm: MouseEventHandler = useCallback(async () => { | ||||||
|     if (!name.trim()) { |     if (!name.trim()) { | ||||||
|       notify({ type: 'error', message: t('datasetSettings.form.nameError') }) |       Toast.notify({ type: 'error', message: t('datasetSettings.form.nameError') }) | ||||||
|       return |       return | ||||||
|     } |     } | ||||||
|     try { |     try { | ||||||
| @ -41,6 +68,12 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDataset | |||||||
|       const body: Partial<DataSet> & { external_knowledge_id?: string; external_knowledge_api_id?: string } = { |       const body: Partial<DataSet> & { external_knowledge_id?: string; external_knowledge_api_id?: string } = { | ||||||
|         name, |         name, | ||||||
|         description, |         description, | ||||||
|  |         icon_info: { | ||||||
|  |           icon: appIcon.type === 'image' ? appIcon.fileId : appIcon.icon, | ||||||
|  |           icon_type: appIcon.type, | ||||||
|  |           icon_background: appIcon.type === 'image' ? undefined : appIcon.background, | ||||||
|  |           icon_url: appIcon.type === 'image' ? appIcon.url : undefined, | ||||||
|  |         }, | ||||||
|       } |       } | ||||||
|       if (externalKnowledgeId && externalKnowledgeApiId) { |       if (externalKnowledgeId && externalKnowledgeApiId) { | ||||||
|         body.external_knowledge_id = externalKnowledgeId |         body.external_knowledge_id = externalKnowledgeId | ||||||
| @ -50,18 +83,18 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDataset | |||||||
|         datasetId: dataset.id, |         datasetId: dataset.id, | ||||||
|         body, |         body, | ||||||
|       }) |       }) | ||||||
|       notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) |       Toast.notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) | ||||||
|       if (onSuccess) |       if (onSuccess) | ||||||
|         onSuccess() |         onSuccess() | ||||||
|       onClose() |       onClose() | ||||||
|     } |     } | ||||||
|     catch { |     catch { | ||||||
|       notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) |       Toast.notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) | ||||||
|     } |     } | ||||||
|     finally { |     finally { | ||||||
|       setLoading(false) |       setLoading(false) | ||||||
|     } |     } | ||||||
|   } |   }, [appIcon, description, dataset.id, externalKnowledgeApiId, externalKnowledgeId, name, onClose, onSuccess, t]) | ||||||
| 
 | 
 | ||||||
|   return ( |   return ( | ||||||
|     <Modal |     <Modal | ||||||
| @ -74,18 +107,30 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDataset | |||||||
|         <RiCloseLine className='h-4 w-4 text-text-tertiary' /> |         <RiCloseLine className='h-4 w-4 text-text-tertiary' /> | ||||||
|       </div> |       </div> | ||||||
|       <div> |       <div> | ||||||
|         <div className={cn('flex flex-wrap items-center justify-between py-4')}> |         <div className={cn('flex flex-col py-4')}> | ||||||
|           <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'> |           <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'> | ||||||
|             {t('datasetSettings.form.name')} |             {t('datasetSettings.form.name')} | ||||||
|           </div> |           </div> | ||||||
|           <Input |           <div className='flex items-center gap-x-2'> | ||||||
|             value={name} |             <AppIcon | ||||||
|             onChange={e => setName(e.target.value)} |               size='medium' | ||||||
|             className='h-9' |               onClick={handleOpenAppIconPicker} | ||||||
|             placeholder={t('datasetSettings.form.namePlaceholder') || ''} |               className='cursor-pointer' | ||||||
|           /> |               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 | ||||||
|  |             /> | ||||||
|  |             <Input | ||||||
|  |               value={name} | ||||||
|  |               onChange={e => setName(e.target.value)} | ||||||
|  |               className='h-9 grow' | ||||||
|  |               placeholder={t('datasetSettings.form.namePlaceholder') || ''} | ||||||
|  |             /> | ||||||
|  |           </div> | ||||||
|         </div> |         </div> | ||||||
|         <div className={cn('flex flex-wrap items-center justify-between py-4')}> |         <div className={cn('flex flex-col py-4')}> | ||||||
|           <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'> |           <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'> | ||||||
|             {t('datasetSettings.form.desc')} |             {t('datasetSettings.form.desc')} | ||||||
|           </div> |           </div> | ||||||
| @ -103,6 +148,12 @@ const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDataset | |||||||
|         <Button className='mr-2' onClick={onClose}>{t('common.operation.cancel')}</Button> |         <Button className='mr-2' onClick={onClose}>{t('common.operation.cancel')}</Button> | ||||||
|         <Button disabled={loading} variant="primary" onClick={onConfirm}>{t('common.operation.save')}</Button> |         <Button disabled={loading} variant="primary" onClick={onConfirm}>{t('common.operation.save')}</Button> | ||||||
|       </div> |       </div> | ||||||
|  |       {showAppIconPicker && ( | ||||||
|  |         <AppIconPicker | ||||||
|  |           onSelect={handleSelectAppIcon} | ||||||
|  |           onClose={handleCloseAppIconPicker} | ||||||
|  |         /> | ||||||
|  |       )} | ||||||
|     </Modal> |     </Modal> | ||||||
|   ) |   ) | ||||||
| } | } | ||||||
|  | |||||||
| @ -37,9 +37,9 @@ export type DataSet = { | |||||||
|   indexing_status: DocumentIndexingStatus |   indexing_status: DocumentIndexingStatus | ||||||
|   icon_info: { |   icon_info: { | ||||||
|     icon: string |     icon: string | ||||||
|     icon_background: string |     icon_background?: string | ||||||
|     icon_type: AppIconType |     icon_type: AppIconType | ||||||
|     icon_url: string |     icon_url?: string | ||||||
|   } |   } | ||||||
|   description: string |   description: string | ||||||
|   permission: DatasetPermission |   permission: DatasetPermission | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 twwu
						twwu