mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 12:37:20 +08:00
chore: fix placeholder ux
This commit is contained in:
parent
5392401e60
commit
62b9a20115
@ -2,8 +2,8 @@
|
|||||||
import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker'
|
import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker'
|
||||||
import type { ValueSelector } from '@/app/components/workflow/types'
|
import type { ValueSelector } from '@/app/components/workflow/types'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React from 'react'
|
import React, { useCallback, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
import Textarea from '../../../textarea'
|
import Textarea from '../../../textarea'
|
||||||
import TagLabel from './tag-label'
|
import TagLabel from './tag-label'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
@ -21,18 +21,24 @@ type Props = {
|
|||||||
|
|
||||||
const i18nPrefix = 'workflow.nodes.humanInput.insertInputField'
|
const i18nPrefix = 'workflow.nodes.humanInput.insertInputField'
|
||||||
|
|
||||||
const Placeholder = () => {
|
type PlaceholderProps = {
|
||||||
|
onTypeClick: (isVariable: boolean) => void
|
||||||
|
}
|
||||||
|
const Placeholder = ({
|
||||||
|
onTypeClick,
|
||||||
|
}: PlaceholderProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
return (
|
return (
|
||||||
<div className='system-sm-regular mt-1 px-3 text-text-tertiary'>
|
<div className='system-sm-regular mt-1 h-[80px] rounded-lg bg-components-input-bg-normal px-3 pt-2 text-text-tertiary'>
|
||||||
<div className="flex h-5 items-center space-x-1">
|
<div className='flex flex-wrap items-center leading-5'>
|
||||||
<span>{t(`${i18nPrefix}.add`)}</span>
|
<Trans
|
||||||
<TagLabel type='edit' text={t(`${i18nPrefix}.staticContent`)} />
|
i18nKey={`${i18nPrefix}.prePopulateFieldPlaceholder`}
|
||||||
<span>{t(`${i18nPrefix}.or`)}</span>
|
components={{
|
||||||
<TagLabel type='variable' text={t(`${i18nPrefix}.variable`)} />
|
staticContent: <TagLabel type='edit' className='mx-1' onClick={() => onTypeClick(false)}>{t(`${i18nPrefix}.staticContent`)}</TagLabel>,
|
||||||
<span>{t(`${i18nPrefix}.users`)}</span>
|
variable: <TagLabel type='variable' className='mx-1' onClick={() => onTypeClick(true)}>{t(`${i18nPrefix}.variable`)}</TagLabel>,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex h-5 items-center">{t(`${i18nPrefix}.prePopulateFieldPlaceholderEnd`)}</div>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -48,10 +54,17 @@ const PrePopulate: FC<Props> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
const [onPlaceholderClicked, setOnPlaceholderClicked] = useState(false)
|
||||||
|
const handlePlaceholderTypeClick = useCallback((isVar: boolean) => {
|
||||||
|
setOnPlaceholderClicked(true)
|
||||||
|
onIsVariableChange?.(isVar)
|
||||||
|
}, [onIsVariableChange])
|
||||||
|
|
||||||
|
const isShowPlaceholder = !onPlaceholderClicked && (isVariable ? (!valueSelector || valueSelector.length === 0) : !value)
|
||||||
|
if (isShowPlaceholder)
|
||||||
|
return <Placeholder onTypeClick={handlePlaceholderTypeClick} />
|
||||||
|
|
||||||
const main = (() => {
|
const main = (() => {
|
||||||
const isShowPlaceholder = isVariable ? (!valueSelector || valueSelector.length === 0) : !value
|
|
||||||
if (isShowPlaceholder)
|
|
||||||
return <Placeholder />
|
|
||||||
if (isVariable) {
|
if (isVariable) {
|
||||||
return (
|
return (
|
||||||
<VarReferencePicker
|
<VarReferencePicker
|
||||||
|
|||||||
@ -3,21 +3,28 @@ import { RiEditLine } from '@remixicon/react'
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Variable02 } from '../../../icons/src/vender/solid/development'
|
import { Variable02 } from '../../../icons/src/vender/solid/development'
|
||||||
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
type: 'edit' | 'variable'
|
type: 'edit' | 'variable'
|
||||||
text: string
|
children: string
|
||||||
|
className?: string
|
||||||
|
onClick?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const TagLabel: FC<Props> = ({
|
const TagLabel: FC<Props> = ({
|
||||||
type,
|
type,
|
||||||
text,
|
children,
|
||||||
|
className,
|
||||||
|
onClick,
|
||||||
}) => {
|
}) => {
|
||||||
const Icon = type === 'edit' ? RiEditLine : Variable02
|
const Icon = type === 'edit' ? RiEditLine : Variable02
|
||||||
return (
|
return (
|
||||||
<div className='flex h-5 items-center space-x-1 rounded-md bg-components-button-secondary-bg px-1 text-text-accent'>
|
<div
|
||||||
|
className={cn('inline-flex h-5 cursor-pointer items-center space-x-1 rounded-md bg-components-button-secondary-bg px-1 text-text-accent', className)}
|
||||||
|
onClick={onClick}>
|
||||||
<Icon className='size-3.5' />
|
<Icon className='size-3.5' />
|
||||||
<div className='system-xs-medium '>{text}</div>
|
<div className='system-xs-medium '>{children}</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -966,12 +966,9 @@ const translation = {
|
|||||||
saveResponseAs: 'Save Response As',
|
saveResponseAs: 'Save Response As',
|
||||||
saveResponseAsPlaceholder: 'Name this variable for later reference',
|
saveResponseAsPlaceholder: 'Name this variable for later reference',
|
||||||
prePopulateField: 'Pre-populate Field',
|
prePopulateField: 'Pre-populate Field',
|
||||||
add: 'Add',
|
prePopulateFieldPlaceholder: 'Add <staticContent/> or <variable/> users will see this content initially, or leave empty.',
|
||||||
staticContent: 'Static Content',
|
staticContent: 'Static Content',
|
||||||
or: 'or',
|
|
||||||
variable: 'variable',
|
variable: 'variable',
|
||||||
users: 'users',
|
|
||||||
prePopulateFieldPlaceholderEnd: 'will see initially, or leave empty.',
|
|
||||||
insert: 'Insert',
|
insert: 'Insert',
|
||||||
useVarInstead: 'Use Variable Instead',
|
useVarInstead: 'Use Variable Instead',
|
||||||
useConstantInstead: 'Use Constant Instead',
|
useConstantInstead: 'Use Constant Instead',
|
||||||
|
|||||||
@ -967,12 +967,9 @@ const translation = {
|
|||||||
saveResponseAs: '保存响应为',
|
saveResponseAs: '保存响应为',
|
||||||
saveResponseAsPlaceholder: '为此变量命名以便将来引用',
|
saveResponseAsPlaceholder: '为此变量命名以便将来引用',
|
||||||
prePopulateField: '预填充字段',
|
prePopulateField: '预填充字段',
|
||||||
add: '添加',
|
prePopulateFieldPlaceholder: '添加 <staticContent/> 或 <variable/> 用户将最初看到此内容,或留空。',
|
||||||
staticContent: '静态内容',
|
staticContent: '静态内容',
|
||||||
or: '或',
|
|
||||||
variable: '变量',
|
variable: '变量',
|
||||||
users: '用户',
|
|
||||||
prePopulateFieldPlaceholderEnd: '将最初看到,或留空。',
|
|
||||||
insert: '插入',
|
insert: '插入',
|
||||||
useVarInstead: '使用变量代替',
|
useVarInstead: '使用变量代替',
|
||||||
useConstantInstead: '使用常量代替',
|
useConstantInstead: '使用常量代替',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user