Skip to content

Commit

Permalink
feat: FieldEditor 不能修改非空的数组和对象类型
Browse files Browse the repository at this point in the history
  • Loading branch information
秋逢 committed Dec 8, 2019
1 parent ede3a27 commit 3521cf4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/react-schema-editor/src/components/FieldEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
getInputType,
getPropertyValue,
getExpressionValue,
getRuleMessage
getRuleMessage,
fieldTypeDisabled
} from '../utils/fieldEditorHelpers'
import { InputTypes, ComponentPropsTypes } from '../utils/types'
import './FieldEditor.css'
Expand Down Expand Up @@ -434,6 +435,7 @@ const FieldEditor: React.FC<IFieldEditorProps> = ({
type: value
})
}}
disabled={fieldTypeDisabled(schema)}
>
{_.map(fieldTypeData.options, ({ label, value }) => (
<SelectOption value={value} key={value}>
Expand Down
11 changes: 11 additions & 0 deletions packages/react-schema-editor/src/utils/fieldEditorHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const getExpressionValue = value => {
}
return value
}

export const getInputType = value => {
if (typeof value === 'object' || isExpression(value)) {
return InputTypes.TEXT_AREA
Expand All @@ -148,3 +149,13 @@ export const getInputType = value => {
return InputTypes.CHECKBOX
}
}

export const fieldTypeDisabled = schema => {
if (schema.type === 'object' && !_.isEmpty(schema.properties)) {
return true
}
if (schema.type === 'array' && !_.isEmpty(schema.items)) {
return true
}
return false
}

0 comments on commit 3521cf4

Please sign in to comment.