mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 11:04:27 +08:00
feat: can show notes
This commit is contained in:
parent
a362114486
commit
ad0e79372f
@ -10,7 +10,7 @@ import Badge from '@/app/components/base/badge'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import ActionButton from '@/app/components/base/action-button'
|
import ActionButton from '@/app/components/base/action-button'
|
||||||
import { RiCloseLine } from '@remixicon/react'
|
import { RiCloseLine } from '@remixicon/react'
|
||||||
import { Variable, rehypeNotes, rehypeVariable } from './variable-in-markdown'
|
import { Note, Variable, rehypeNotes, rehypeVariable } from './variable-in-markdown'
|
||||||
|
|
||||||
const i18nPrefix = 'workflow.nodes.humanInput'
|
const i18nPrefix = 'workflow.nodes.humanInput'
|
||||||
|
|
||||||
@ -43,9 +43,20 @@ const FormContentPreview: FC<Props> = ({
|
|||||||
content={content}
|
content={content}
|
||||||
rehypePlugins={[rehypeVariable, rehypeNotes]}
|
rehypePlugins={[rehypeVariable, rehypeNotes]}
|
||||||
customComponents={{
|
customComponents={{
|
||||||
variable: ({ node, ...props }: any) => (
|
variable: ({ node }: any) => (
|
||||||
<Variable path={node.properties?.path as string} />
|
<Variable path={node.properties?.['data-path'] as string} />
|
||||||
),
|
),
|
||||||
|
section: ({ node }: any) => (() => {
|
||||||
|
const name = node.properties?.['data-name'] as string
|
||||||
|
const input = formInputs.find(i => i.output_variable_name === name)
|
||||||
|
if(!input) {
|
||||||
|
return (
|
||||||
|
<div>Can't find note: {name}</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const placeholder = input.placeholder
|
||||||
|
return <Note placeholder={placeholder!} />
|
||||||
|
})(),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div className='mt-3 flex flex-wrap gap-1 py-1'>
|
<div className='mt-3 flex flex-wrap gap-1 py-1'>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import type React from 'react'
|
import type React from 'react'
|
||||||
|
import type { FormInputItemPlaceholder } from '../types'
|
||||||
|
|
||||||
const variableRegex = /\{\{#(.+?)#\}\}/g
|
const variableRegex = /\{\{#(.+?)#\}\}/g
|
||||||
const noteRegex = /\{\{#\$(.+?)#\}\}/g
|
const noteRegex = /\{\{#\$(.+?)#\}\}/g
|
||||||
@ -21,7 +22,7 @@ export function rehypeVariable() {
|
|||||||
parts.push({
|
parts.push({
|
||||||
type: 'element',
|
type: 'element',
|
||||||
tagName: 'variable',
|
tagName: 'variable',
|
||||||
properties: { path: m[0].trim() },
|
properties: { 'data-path': m[0].trim() },
|
||||||
children: [],
|
children: [],
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -79,10 +80,11 @@ export function rehypeNotes() {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
const name = m[0].split('.').slice(-1)[0].replace('#}}', '')
|
||||||
parts.push({
|
parts.push({
|
||||||
type: 'element',
|
type: 'element',
|
||||||
tagName: 'note', // choose a right tag
|
tagName: 'section',
|
||||||
properties: { path: m[0].trim() },
|
properties: { 'data-name': name },
|
||||||
children: [],
|
children: [],
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -121,3 +123,12 @@ export const Variable: React.FC<{ path: string }> = ({ path }) => {
|
|||||||
.replace('{{#', '{{')
|
.replace('{{#', '{{')
|
||||||
.replace('#}}', '}}')}</span>
|
.replace('#}}', '}}')}</span>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const Note: React.FC<{ placeholder: FormInputItemPlaceholder }> = ({ placeholder }) => {
|
||||||
|
const isVariable = placeholder.type === 'variable'
|
||||||
|
return (
|
||||||
|
<div className='mt-3 rounded-[10px] bg-components-input-bg-normal px-2.5 py-2'>
|
||||||
|
{isVariable ? <Variable path={`{{${placeholder.selector.join('.')}}}`} /> : <span>{placeholder.value}</span>}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user