feat: the frontend part of mcp (#22131)
Co-authored-by: jZonG <jzongcode@gmail.com> Co-authored-by: Novice <novice12185727@gmail.com> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: Hanqing Zhao <sherry9277@gmail.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -2,24 +2,29 @@ import type { FC } from 'react'
|
||||
import type { SchemaRoot } from '../../../types'
|
||||
import SchemaNode from './schema-node'
|
||||
import { useSchemaNodeOperations } from './hooks'
|
||||
import cn from '@/utils/classnames'
|
||||
|
||||
export type VisualEditorProps = {
|
||||
className?: string
|
||||
schema: SchemaRoot
|
||||
onChange: (schema: SchemaRoot) => void
|
||||
rootName?: string
|
||||
readOnly?: boolean
|
||||
onChange?: (schema: SchemaRoot) => void
|
||||
}
|
||||
|
||||
const VisualEditor: FC<VisualEditorProps> = (props) => {
|
||||
const { schema } = props
|
||||
const { className, schema, readOnly } = props
|
||||
useSchemaNodeOperations(props)
|
||||
|
||||
return (
|
||||
<div className='h-full overflow-auto rounded-xl bg-background-section-burn p-1 pl-2'>
|
||||
<div className={cn('h-full overflow-auto rounded-xl bg-background-section-burn p-1 pl-2', className)}>
|
||||
<SchemaNode
|
||||
name='structured_output'
|
||||
name={props.rootName || 'structured_output'}
|
||||
schema={schema}
|
||||
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 />
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user