Skip to content

Commit

Permalink
fix: array schema init bug
Browse files Browse the repository at this point in the history
  • Loading branch information
苏文雄 committed Oct 27, 2019
1 parent 91b6dac commit ad2a14b
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 92 deletions.
22 changes: 22 additions & 0 deletions examples/adv-interaction-expressin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default {
type: "object",
required: ['name'],
properties: {
enable: {
title: 'Enable',
type: "boolean",
description: "Enable",
default: false
},
email: {
title: "Email",
type: "string",
enum: ["aa@qq.com", "zz@xx.com"],
ui: {
hander: "record.enable === true && (schema.ui.hide = false)",
hide: true
}
}

}
}
30 changes: 30 additions & 0 deletions examples/array/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default {
type: "array",
title: "Array",
items: {
type: "object",
advFields: ['code'],
properties: {
dataIndex: {
type: "string",
title: 'Field',
pattern: "[0-9]+"
},
title: {
type: "string",
title: 'Title'
},
enable: {
type: "boolean",
title: 'Enable'
},
code: {
type: "string",
title: "Script",
ui: {
type: 'CodeEditor'
}
}
}
}
}
27 changes: 17 additions & 10 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ import simple from './simple-case'
import {Select} from 'antd'
import AceEditor from '../src/widgets/ace-editor'
import './index.scss'
import advInteractionExpression from './adv-interaction-expressin'

const schema = {
simple
simple,
array: require('./array').default,
tabs: require('./tabs').default,
objectAndArray: require('./object-and-array').default,
advInteractionExpression: advInteractionExpression,
}


const defaultName = 'simple'

export default class App extends React.PureComponent {
state = {
data: {},
selectValue: 'simple',
jsonSchema: JSON.stringify(schema.simple,null,2)
data: schema[defaultName].type === 'object' ?{} : [],
selectValue: defaultName,
jsonSchema: JSON.stringify(schema[defaultName],null,2)
};

onChange =(value)=>{
Expand All @@ -29,10 +34,12 @@ export default class App extends React.PureComponent {
render(){
return <div className="container">
<div className="header-box">
{<Select value={this.state.selectValue} onChange={e=>{
<span>Select Schema: &nbsp;</span>
{<Select style={{width: 400}} value={this.state.selectValue} onChange={v=>{
this.setState({
selectValue: e.target.value,
jsonSchema: schema[e.target.value]
selectValue: v,
jsonSchema: JSON.stringify(schema[v],null,2),
data: schema[v].type === 'array' ? [] : {}
})
}}>
{Object.keys(schema).map(key=>{
Expand All @@ -54,7 +61,7 @@ export default class App extends React.PureComponent {
<h3>Form-Data</h3>
<AceEditor readOnly={true} className="json-editor" mode="json" value={JSON.stringify(this.state.data,null,2)} />
</div>
<div key={this.state.jsonSchema} className="body-right">
<div className="body-right">
<h3>FORM</h3>
{this.renderSchema(JSON.parse(this.state.jsonSchema))}
</div>
Expand All @@ -64,7 +71,7 @@ export default class App extends React.PureComponent {

renderSchema (data) {
return (
<JSF onChange={this.onChange} value={this.state.data} schema={data} />
<JSF key={this.state.jsonSchema} onChange={this.onChange} value={this.state.data} schema={data} />
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion examples/index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.container{
.header-box{

height: 40px;
line-height: 40px;
margin-bottom: 10px;
}

.body-box{
Expand Down
75 changes: 75 additions & 0 deletions examples/object-and-array/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
export default {
type: "object",
required: ['name'],
properties: {
name: {
title: 'User',
type: "string",
description: "zzzzzz",
pattern: "[0-9]+"
},
email: {
title: "Email",
type: "string",
enum: ["aa@qq.com", "zz@xx.com"]
},
script: {
type: "string",
title: "JsScript",
ui: {
type: 'CodeEditor'
}
},
number: {
title: 'Number',
type: 'number',
default: 10
},
testObject: {
title: 'testObject',
type: 'object',
properties: {
name: {
title: 'xxxx',
type: "string",
description: "xxxxxxx"
},
email: {
title: "yyyy",
type: "string"
},
}
},
xx: {
type: "array",
title: "TableConifg",
items: {
type: "object",
advFields: ['code'],
properties: {
dataIndex: {
type: "string",
title: 'Field',
pattern: "[0-9]+"
},
title: {
type: "string",
title: 'Title'
},
enable: {
type: "boolean",
title: 'Enable'
},
code: {
type: "string",
title: "Script",
ui: {
type: 'CodeEditor'
}
}
}
}
},

}
}
62 changes: 1 addition & 61 deletions examples/simple-case/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,67 +40,7 @@ export default {
},
}
},
xx: {
type: "array",
title: "TableConifg",
items: {
type: "object",
advFields: ['code'],
properties: {
dataIndex: {
type: "string",
title: 'Field',
pattern: "[0-9]+"
},
title: {
type: "string",
title: 'Title'
},
enable: {
type: "boolean",
title: 'Enable'
},
code: {
type: "string",
title: "Script",
ui: {
type: 'CodeEditor'
}
}
}
}
},

tabTest: {
type: "array",
title: "",
categoryName: "newTab",
items: {
type: "object",
advFields: ['code'],
properties: {
dataIndex: {
type: "string",
title: 'Field',
pattern: "[0-9]+"
},
title: {
type: "string",
title: 'Title'
},
enable: {
type: "boolean",
title: 'Enable'
},
code: {
type: "string",
title: "Script",
ui: {
type: 'CodeEditor'
}
}
}
}
}

}
}
106 changes: 106 additions & 0 deletions examples/tabs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
export default {
type: "object",
required: ['name'],
properties: {
name: {
title: 'User',
type: "string",
description: "zzzzzz",
pattern: "[0-9]+"
},
email: {
title: "Email",
type: "string",
enum: ["aa@qq.com", "zz@xx.com"]
},
script: {
type: "string",
title: "JsScript",
ui: {
type: 'CodeEditor'
}
},
number: {
title: 'Number',
type: 'number',
default: 10
},
testObject: {
title: 'testObject',
type: 'object',
properties: {
name: {
title: 'xxxx',
type: "string",
description: "xxxxxxx"
},
email: {
title: "yyyy",
type: "string"
},
}
},
xx: {
type: "array",
title: "TableConifg",
items: {
type: "object",
advFields: ['code'],
properties: {
dataIndex: {
type: "string",
title: 'Field',
pattern: "[0-9]+"
},
title: {
type: "string",
title: 'Title'
},
enable: {
type: "boolean",
title: 'Enable'
},
code: {
type: "string",
title: "Script",
ui: {
type: 'CodeEditor'
}
}
}
}
},

tabTest: {
type: "array",
title: "",
categoryName: "newTab",
items: {
type: "object",
advFields: ['code'],
properties: {
dataIndex: {
type: "string",
title: 'Field',
pattern: "[0-9]+"
},
title: {
type: "string",
title: 'Title'
},
enable: {
type: "boolean",
title: 'Enable'
},
code: {
type: "string",
title: "Script",
ui: {
type: 'CodeEditor'
}
}
}
}
}
}
}

0 comments on commit ad2a14b

Please sign in to comment.