Commit d5c3a9cc5dab65b88c46a4db6af00a054ddc223f
Committed by
GitHub
1 parent
1540f086
fixed: focus on fullscreen for react schema grouped forms (#2400)
Showing
3 changed files
with
21 additions
and
13 deletions
... | ... | @@ -83,9 +83,9 @@ class ThingsboardAceEditor extends React.Component { |
83 | 83 | fixAceEditor(editor); |
84 | 84 | } |
85 | 85 | |
86 | - onToggleFull() { | |
86 | + onToggleFull(groupId) { | |
87 | 87 | this.setState({ isFull: !this.state.isFull }); |
88 | - this.props.onToggleFullscreen(); | |
88 | + this.props.onToggleFullscreen(groupId); | |
89 | 89 | this.updateAceEditorSize = true; |
90 | 90 | } |
91 | 91 | |
... | ... | @@ -140,7 +140,7 @@ class ThingsboardAceEditor extends React.Component { |
140 | 140 | <div className="title-panel"> |
141 | 141 | <label>{this.props.mode}</label> |
142 | 142 | <FlatButton style={ styles.tidyButtonStyle } className="tidy-button" label={'Tidy'} onTouchTap={this.onTidy}/> |
143 | - <FlatButton style={ styles.tidyButtonStyle } className="tidy-button" label={this.state.isFull ? 'Exit fullscreen' : 'Fullscreen'} onTouchTap={this.onToggleFull}/> | |
143 | + <FlatButton style={ styles.tidyButtonStyle } className="tidy-button" label={this.state.isFull ? 'Exit fullscreen' : 'Fullscreen'} onTouchTap={() => this.onToggleFull(this.props.groupId)}/> | |
144 | 144 | </div> |
145 | 145 | <AceEditor mode={this.props.mode} |
146 | 146 | height={this.state.isFull ? "100%" : "150px"} | ... | ... |
... | ... | @@ -40,6 +40,9 @@ class ThingsboardSchemaForm extends React.Component { |
40 | 40 | |
41 | 41 | constructor(props) { |
42 | 42 | super(props); |
43 | + this.state = { | |
44 | + groupId: null, | |
45 | + }; | |
43 | 46 | |
44 | 47 | this.mapper = { |
45 | 48 | 'number': ThingsboardNumber, |
... | ... | @@ -71,7 +74,6 @@ class ThingsboardSchemaForm extends React.Component { |
71 | 74 | } |
72 | 75 | |
73 | 76 | onChange(key, val) { |
74 | - //console.log('SchemaForm.onChange', key, val); | |
75 | 77 | this.props.onModelChange(key, val); |
76 | 78 | if (this.hasConditions) { |
77 | 79 | this.forceUpdate(); |
... | ... | @@ -86,12 +88,15 @@ class ThingsboardSchemaForm extends React.Component { |
86 | 88 | this.props.onIconClick(event); |
87 | 89 | } |
88 | 90 | |
89 | - onToggleFullscreen() { | |
91 | + onToggleFullscreen(groupId) { | |
92 | + this.setState({ | |
93 | + groupId: groupId | |
94 | + }); | |
90 | 95 | this.props.onToggleFullscreen(); |
91 | 96 | } |
92 | 97 | |
93 | - | |
94 | - builder(form, model, index, onChange, onColorClick, onIconClick, onToggleFullscreen, mapper) { | |
98 | + | |
99 | + builder(form, groupId, model, index, onChange, onColorClick, onIconClick, onToggleFullscreen, mapper) { | |
95 | 100 | var type = form.type; |
96 | 101 | let Field = this.mapper[type]; |
97 | 102 | if(!Field) { |
... | ... | @@ -104,21 +109,21 @@ class ThingsboardSchemaForm extends React.Component { |
104 | 109 | return null; |
105 | 110 | } |
106 | 111 | } |
107 | - return <Field model={model} form={form} key={index} onChange={onChange} onColorClick={onColorClick} onIconClick={onIconClick} onToggleFullscreen={onToggleFullscreen} mapper={mapper} builder={this.builder}/> | |
112 | + return <Field model={model} groupId={groupId} form={form} key={index} onChange={onChange} onColorClick={onColorClick} onIconClick={onIconClick} onToggleFullscreen={onToggleFullscreen} mapper={mapper} builder={this.builder}/> | |
108 | 113 | } |
109 | 114 | |
110 | - createSchema(theForm) { | |
115 | + createSchema(theForm, groupId) { | |
111 | 116 | let merged = utils.merge(this.props.schema, theForm, this.props.ignore, this.props.option); |
112 | 117 | let mapper = this.mapper; |
113 | 118 | if(this.props.mapper) { |
114 | 119 | mapper = _.merge(this.mapper, this.props.mapper); |
115 | 120 | } |
116 | 121 | let forms = merged.map(function(form, index) { |
117 | - return this.builder(form, this.props.model, index, this.onChange, this.onColorClick, this.onIconClick, this.onToggleFullscreen, mapper); | |
122 | + return this.builder(form, groupId, this.props.model, index, this.onChange, this.onColorClick, this.onIconClick, this.onToggleFullscreen, mapper); | |
118 | 123 | }.bind(this)); |
119 | 124 | |
120 | 125 | let formClass = 'SchemaForm'; |
121 | - if (this.props.isFullscreen) { | |
126 | + if (this.props.isFullscreen && groupId === this.state.groupId) { | |
122 | 127 | formClass += ' SchemaFormFullscreen'; |
123 | 128 | } |
124 | 129 | |
... | ... | @@ -131,7 +136,7 @@ class ThingsboardSchemaForm extends React.Component { |
131 | 136 | if(this.props.groupInfoes&&this.props.groupInfoes.length>0){ |
132 | 137 | let content=[]; |
133 | 138 | for(let info of this.props.groupInfoes){ |
134 | - let forms = this.createSchema(this.props.form[info.formIndex]); | |
139 | + let forms = this.createSchema(this.props.form[info.formIndex], info.formIndex); | |
135 | 140 | let item = <ThingsboardSchemaGroup key={content.length} forms={forms} info={info}></ThingsboardSchemaGroup>; |
136 | 141 | content.push(item); |
137 | 142 | } |
... | ... | @@ -165,4 +170,4 @@ class ThingsboardSchemaGroup extends React.Component{ |
165 | 170 | <div style={{padding: '20px'}} className={this.state.showGroup?"":"invisible"}>{this.props.forms}</div> |
166 | 171 | </section>); |
167 | 172 | } |
168 | -} | |
173 | +} | ... | ... |
... | ... | @@ -24,12 +24,15 @@ $input-label-float-scale: .75 !default; |
24 | 24 | .tb-fullscreen { |
25 | 25 | [name="ReactSchemaForm"] { |
26 | 26 | .SchemaForm { |
27 | + display: none; | |
28 | + | |
27 | 29 | &.SchemaFormFullscreen { |
28 | 30 | position: absolute; |
29 | 31 | top: 0; |
30 | 32 | right: 0; |
31 | 33 | bottom: 0; |
32 | 34 | left: 0; |
35 | + display: block; | |
33 | 36 | |
34 | 37 | > div:not(.fullscreen-form-field) { |
35 | 38 | display: none !important; | ... | ... |