mirror of
https://github.com/langgenius/dify.git
synced 2026-08-28 21:23:22 +08:00
feat: doc metadata can show edit and cancel
This commit is contained in:
parent
10fccd2b3f
commit
1a7de23864
@ -20,7 +20,7 @@ const InputCombined: FC<Props> = ({
|
|||||||
onChange,
|
onChange,
|
||||||
}) => {
|
}) => {
|
||||||
// TODO: configClassName...
|
// TODO: configClassName...
|
||||||
const className = cn('grow p-0.5 h-6 text-xs', configClassName)
|
const className = cn('grow p-0.5 h-6 text-xs')
|
||||||
if (type === DataType.time)
|
if (type === DataType.time)
|
||||||
return <div className='grow text-xs'>Datepicker placeholder</div>
|
return <div className='grow text-xs'>Datepicker placeholder</div>
|
||||||
|
|
||||||
@ -40,6 +40,7 @@ const InputCombined: FC<Props> = ({
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Input
|
<Input
|
||||||
|
wrapperClassName={configClassName}
|
||||||
className={cn(className, 'rounded-md')}
|
className={cn(className, 'rounded-md')}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={e => onChange(e.target.value)}
|
onChange={e => onChange(e.target.value)}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ const Field: FC<Props> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<div className='flex items-start space-x-2'>
|
<div className='flex items-start space-x-2'>
|
||||||
<div className='shrink-0 flex w-[128px] truncate pt-1 h-6 items-center text-text-tertiary system-xs-medium'>
|
<div className='shrink-0 w-[128px] truncate py-1 items-center text-text-tertiary system-xs-medium'>
|
||||||
{label}
|
{label}
|
||||||
</div>
|
</div>
|
||||||
<div className='shrink-0 w-[244px]'>
|
<div className='shrink-0 w-[244px]'>
|
||||||
|
|||||||
@ -26,6 +26,7 @@ const MetadataDocument: FC = () => {
|
|||||||
type: DataType.string,
|
type: DataType.string,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
const [tempList, setTempList] = useState<MetadataItemWithValue[]>(list)
|
||||||
const hasData = list.length > 0
|
const hasData = list.length > 0
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -33,18 +34,39 @@ const MetadataDocument: FC = () => {
|
|||||||
<InfoGroup
|
<InfoGroup
|
||||||
title='Metadata'
|
title='Metadata'
|
||||||
titleTooltip='Metadata serves as a critical filter that enhances the accuracy and relevance of information retrieval. You can modify and add metadata for this document here.'
|
titleTooltip='Metadata serves as a critical filter that enhances the accuracy and relevance of information retrieval. You can modify and add metadata for this document here.'
|
||||||
list={list}
|
list={isEdit ? tempList : list}
|
||||||
headerRight={isEdit ? <div>Save</div> : <Button variant='ghost' onClick={() => setIsEdit(true)}>
|
headerRight={isEdit ? (
|
||||||
<RiEditLine className='size-3.5 text-text-tertiary cursor-pointer' />
|
<div className='flex space-x-1'>
|
||||||
<div>{t('common.operation.edit')}</div>
|
<Button variant='ghost' size='small' onClick={() => {
|
||||||
</Button>}
|
setTempList(list)
|
||||||
|
setIsEdit(false)
|
||||||
|
}}>
|
||||||
|
<div>{t('common.operation.cancel')}</div>
|
||||||
|
</Button>
|
||||||
|
<Button variant='primary' size='small' onClick={() => {
|
||||||
|
setIsEdit(false)
|
||||||
|
setList(tempList)
|
||||||
|
}}>
|
||||||
|
<div>{t('common.operation.save')}</div>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<Button variant='ghost' size='small' onClick={() => {
|
||||||
|
setTempList(list)
|
||||||
|
setIsEdit(true)
|
||||||
|
}}>
|
||||||
|
<RiEditLine className='mr-1 size-3.5 text-text-tertiary cursor-pointer' />
|
||||||
|
<div>{t('common.operation.edit')}</div>
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
isEdit={isEdit}
|
isEdit={isEdit}
|
||||||
|
contentClassName='mt-5'
|
||||||
onChange={(item) => {
|
onChange={(item) => {
|
||||||
const newList = list.map(i => (i.name === item.name ? item : i))
|
const newList = tempList.map(i => (i.name === item.name ? item : i))
|
||||||
setList(newList)
|
setList(newList)
|
||||||
}}
|
}}
|
||||||
onDelete={(item) => {
|
onDelete={(item) => {
|
||||||
const newList = list.filter(i => i.name !== item.name)
|
const newList = tempList.filter(i => i.name !== item.name)
|
||||||
setList(newList)
|
setList(newList)
|
||||||
}}
|
}}
|
||||||
onAdd={() => {
|
onAdd={() => {
|
||||||
|
|||||||
@ -6,11 +6,13 @@ import Field from './field'
|
|||||||
import InputCombined from '../edit-metadata-batch/input-combined'
|
import InputCombined from '../edit-metadata-batch/input-combined'
|
||||||
import { RiDeleteBinLine } from '@remixicon/react'
|
import { RiDeleteBinLine } from '@remixicon/react'
|
||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
title: string
|
title: string
|
||||||
titleTooltip?: string
|
titleTooltip?: string
|
||||||
headerRight?: React.ReactNode
|
headerRight?: React.ReactNode
|
||||||
|
contentClassName?: string
|
||||||
list: MetadataItemWithValue[]
|
list: MetadataItemWithValue[]
|
||||||
isEdit?: boolean
|
isEdit?: boolean
|
||||||
onChange?: (item: MetadataItemWithValue) => void
|
onChange?: (item: MetadataItemWithValue) => void
|
||||||
@ -22,6 +24,7 @@ const InfoGroup: FC<Props> = ({
|
|||||||
title,
|
title,
|
||||||
titleTooltip,
|
titleTooltip,
|
||||||
headerRight,
|
headerRight,
|
||||||
|
contentClassName,
|
||||||
list,
|
list,
|
||||||
isEdit,
|
isEdit,
|
||||||
onChange,
|
onChange,
|
||||||
@ -41,7 +44,7 @@ const InfoGroup: FC<Props> = ({
|
|||||||
{/* <div className='flex px-1.5 rounded-md hover:bg-components-button-tertiary-bg-hover items-center h-6 space-x-1 cursor-pointer' onClick={() => setIsEdit(true)}>
|
{/* <div className='flex px-1.5 rounded-md hover:bg-components-button-tertiary-bg-hover items-center h-6 space-x-1 cursor-pointer' onClick={() => setIsEdit(true)}>
|
||||||
</div> */}
|
</div> */}
|
||||||
</div>
|
</div>
|
||||||
<div className='space-y-1'>
|
<div className={cn('mt-3 space-y-1', contentClassName)}>
|
||||||
{list.map((item, i) => (
|
{list.map((item, i) => (
|
||||||
<Field key={item.id || `${i}`} label={item.name}>
|
<Field key={item.id || `${i}`} label={item.name}>
|
||||||
{isEdit ? (
|
{isEdit ? (
|
||||||
@ -52,11 +55,11 @@ const InfoGroup: FC<Props> = ({
|
|||||||
value={item.value}
|
value={item.value}
|
||||||
onChange={value => onChange?.({ ...item, value })}
|
onChange={value => onChange?.({ ...item, value })}
|
||||||
/>
|
/>
|
||||||
<div className='shrink-0 p-1 rounded-md text-text-tertiary hover:text-text-destructive hover:bg-state-destructive-hover cursor-pointer'>
|
<div className='shrink-0 p-1 rounded-md text-text-tertiary hover:text-text-destructive hover:bg-state-destructive-hover cursor-pointer'>
|
||||||
<RiDeleteBinLine className='size-4' />
|
<RiDeleteBinLine className='size-4' />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (<div className='system-xs-regular text-text-secondary'>{item.value}</div>)}
|
) : (<div className='py-1 system-xs-regular text-text-secondary'>{item.value}</div>)}
|
||||||
</Field>
|
</Field>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user