mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 14:55:54 +08:00
feat: param schema support readonly
This commit is contained in:
parent
f2a8af0680
commit
9adda90227
@ -113,9 +113,7 @@ const SchemaModal: FC<Props> = ({
|
||||
<VisualEditorContextProvider>
|
||||
<VisualEditor
|
||||
schema={testSchema}
|
||||
onChange={(schema: SchemaRoot) => {
|
||||
console.log('Schema changed:', schema)
|
||||
}}
|
||||
readOnly
|
||||
></VisualEditor>
|
||||
</VisualEditorContextProvider>
|
||||
</MittProvider>
|
||||
|
@ -6,6 +6,7 @@ import type { EditData } from './edit-card'
|
||||
import { ArrayType, type Field, Type } from '../../../types'
|
||||
import Toast from '@/app/components/base/toast'
|
||||
import { findPropertyWithPath } from '../../../utils'
|
||||
import _ from 'lodash'
|
||||
|
||||
type ChangeEventParams = {
|
||||
path: string[],
|
||||
@ -19,7 +20,8 @@ type AddEventParams = {
|
||||
}
|
||||
|
||||
export const useSchemaNodeOperations = (props: VisualEditorProps) => {
|
||||
const { schema: jsonSchema, onChange } = props
|
||||
const { schema: jsonSchema, onChange: doOnChange } = props
|
||||
const onChange = doOnChange || _.noop
|
||||
const backupSchema = useVisualEditorStore(state => state.backupSchema)
|
||||
const setBackupSchema = useVisualEditorStore(state => state.setBackupSchema)
|
||||
const isAddingNewField = useVisualEditorStore(state => state.isAddingNewField)
|
||||
|
@ -5,11 +5,12 @@ import { useSchemaNodeOperations } from './hooks'
|
||||
|
||||
export type VisualEditorProps = {
|
||||
schema: SchemaRoot
|
||||
onChange: (schema: SchemaRoot) => void
|
||||
readOnly?: boolean
|
||||
onChange?: (schema: SchemaRoot) => void
|
||||
}
|
||||
|
||||
const VisualEditor: FC<VisualEditorProps> = (props) => {
|
||||
const { schema } = props
|
||||
const { schema, readOnly } = props
|
||||
useSchemaNodeOperations(props)
|
||||
|
||||
return (
|
||||
@ -20,6 +21,7 @@ const VisualEditor: FC<VisualEditorProps> = (props) => {
|
||||
required={false}
|
||||
path={[]}
|
||||
depth={0}
|
||||
readOnly={readOnly}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
@ -19,6 +19,7 @@ type SchemaNodeProps = {
|
||||
path: string[]
|
||||
parentPath?: string[]
|
||||
depth: number
|
||||
readOnly?: boolean
|
||||
}
|
||||
|
||||
// Support 10 levels of indentation
|
||||
@ -57,6 +58,7 @@ const SchemaNode: FC<SchemaNodeProps> = ({
|
||||
path,
|
||||
parentPath,
|
||||
depth,
|
||||
readOnly,
|
||||
}) => {
|
||||
const [isExpanded, setIsExpanded] = useState(true)
|
||||
const hoveringProperty = useVisualEditorStore(state => state.hoveringProperty)
|
||||
@ -77,11 +79,13 @@ const SchemaNode: FC<SchemaNodeProps> = ({
|
||||
}
|
||||
|
||||
const handleMouseEnter = () => {
|
||||
if(!readOnly) return
|
||||
if (advancedEditing || isAddingNewField) return
|
||||
setHoveringPropertyDebounced(path.join('.'))
|
||||
}
|
||||
|
||||
const handleMouseLeave = () => {
|
||||
if(!readOnly) return
|
||||
if (advancedEditing || isAddingNewField) return
|
||||
setHoveringPropertyDebounced(null)
|
||||
}
|
||||
@ -183,7 +187,7 @@ const SchemaNode: FC<SchemaNodeProps> = ({
|
||||
)}
|
||||
|
||||
{
|
||||
depth === 0 && !isAddingNewField && (
|
||||
!readOnly && depth === 0 && !isAddingNewField && (
|
||||
<AddField />
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user