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