Skip to content

Commit 22e24ff

Browse files
committed
edit id in JSON and layer edit modifications - closes #6 closes #40
1 parent 1aeef21 commit 22e24ff

File tree

5 files changed

+62
-55
lines changed

5 files changed

+62
-55
lines changed

src/App.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ label .badge{position:relative;top:2px;}
6262
.exp-line-end{position:absolute;bottom:0;top:16px;left:-12px;
6363
background-color:#FFFFFF;width:4px;z-index:1;}
6464

65+
.edit-name{cursor:text;opacity:0.9;}
66+
.edit-name:hover{opacity:1;}
67+
6568
.field-border-bottom{border-bottom:1px solid #BDBDBD;}
6669
.focus .field-border-bottom{border-bottom:1px solid #0687D1;}
6770

src/view/Vlayer/VlayerEdit.jsx

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ export default class VlayerEdit extends React.Component {
3131
};
3232

3333
this.handle = {
34+
...handle,
3435
changeId:(newId)=>{
3536
// route to new id
3637
Mlayer.setIn(this.id,['id'],newId).then(()=>{
38+
this.setState({editId:false});
3739
handle.routeReplace('layer/'+newId);
3840
});
3941
},
42+
blurId:()=>{
43+
this.setState({editId:false});
44+
},
4045
jsonChange:(json)=>{
4146
Mlayer.set(this.id,json);
4247
},
@@ -48,6 +53,9 @@ export default class VlayerEdit extends React.Component {
4853
},
4954
clickOperation:()=>{
5055
this.setState({mode:'operation'});
56+
},
57+
editIdShow:()=>{
58+
this.setState({editId:true});
5159
}
5260
};
5361

@@ -63,6 +71,8 @@ export default class VlayerEdit extends React.Component {
6371

6472
const layer = Mlayer.get(this.id);
6573

74+
if (!layer) return <div/>
75+
6676
const layerError = error.getIn(['layers',Mlayer.getInd(this.id)]);
6777

6878
//console.log('layer err:',error);
@@ -76,7 +86,7 @@ export default class VlayerEdit extends React.Component {
7686
let section;
7787
switch (this.state.mode){
7888
case 'json':
79-
section = <VlayerEditJSON handle={{change:this.handle.jsonChange}} error={layerError} layer={layer}/>;
89+
section = <VlayerEditJSON handle={{...handle,change:this.handle.jsonChange}} error={layerError} layer={layer}/>;
8090
break;
8191
case 'edit':
8292
section = <VlayerEditor key={this.id} handle={handle} error={layerError} layer={layer}/>;
@@ -87,24 +97,24 @@ export default class VlayerEdit extends React.Component {
8797
}
8898

8999
return <div className="">
90-
{this.state.editId?
91-
<VlayerEditId handle={{change:this.handle.changeId}} style={style} error={layerError} layer={layer}/>
92-
:
93-
<h2 className="px-2 py-1 m-0 text-nav bg-light row">
94-
<div className="text-overflow-ellipsis flex-2">
95-
{layer.get('id')}
100+
<h2 className="px-2 py-1 m-0 text-nav bg-light row">
101+
<div className="text-overflow-ellipsis flex-2 edit-name mr-2" onClick={this.handle.editIdShow}>
102+
{this.state.editId ?
103+
<VlayerEditId handle={{change:this.handle.changeId,blur:this.handle.blurId}} style={style} error={layerError} layer={layer}/>
104+
:
105+
layer.get('id')
106+
}
107+
</div>
108+
<div className="text-right">
109+
<div onClick={this.handle.clickEdit} className={'d-inline-block layer-nav-link px-1 '+(this.state.mode === 'edit' ? 'active': '')}>
110+
<i className="material-icons md-18 icon-btn gray">mode_edit</i>
96111
</div>
97-
<div className="text-right">
98-
<div onClick={this.handle.clickEdit} className={'d-inline-block layer-nav-link px-1 '+(this.state.mode === 'edit' ? 'active': '')}>
99-
<i className="material-icons md-18 icon-btn gray">mode_edit</i>
100-
</div>
101-
<div onClick={this.handle.clickJson} className={'d-inline-block layer-nav-link px-1 '+(this.state.mode === 'json' ? 'active': '')}>
102-
<i className="material-icons md-18 icon-btn gray">code</i>
103-
</div>
104-
112+
<div onClick={this.handle.clickJson} className={'d-inline-block layer-nav-link px-1 '+(this.state.mode === 'json' ? 'active': '')}>
113+
<i className="material-icons md-18 icon-btn gray">code</i>
105114
</div>
106-
</h2>
107-
}
115+
116+
</div>
117+
</h2>
108118
<div>
109119
{section}
110120
</div>

src/view/Vlayer/VlayerEditId.jsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@ export default class Vsource extends React.Component {
66
constructor(props) {
77
super(props);
88

9-
const {handle} = this.props;
9+
const {handle,layer} = this.props;
1010

11-
this.state = {};
11+
this.state = {
12+
value:layer.get('id')
13+
};
1214

1315
this.handle = {
14-
change:(val)=>{
16+
change:(f)=>{
1517
//this.setState({value:e.target.value});
1618
//handle.change(e.target.value);
17-
if (handle.change) handle.change(val);
19+
this.setState({value:f.value})
20+
},
21+
enter:(f)=>{
22+
if (handle.change) handle.change(this.state.value);
23+
},
24+
blur:()=>{
25+
if (handle.blur) handle.blur();
1826
}
1927
};
2028

@@ -29,10 +37,12 @@ export default class Vsource extends React.Component {
2937
//console.log('active layer:',layer);
3038

3139
const idField = {
32-
label:'ID',
40+
type:'string',
3341
name:'id',
34-
value:layer.get('id'),
35-
placeholder:'Unique ID for layer'
42+
value:this.state.value,
43+
placeholder:'Unique ID for layer',
44+
controlled:false,
45+
autoFocus:true
3646
};
3747
return <div>
3848
<Vfield type="string" handle={this.handle} field={idField} />

src/view/Vlayer/VlayerEditJSON.jsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import MapboxError from '../../utility/MapboxError';
77
import Vfield from '../Vfield';
88
import Valert from '../Valert';
99

10+
import Mlayer from '../../model/Mlayer';
1011

1112
export default class VlayerEditJSON extends React.Component {
1213
static propTypes = {
@@ -17,10 +18,21 @@ export default class VlayerEditJSON extends React.Component {
1718
constructor(props) {
1819
super(props);
1920

20-
const {handle} = this.props;
21+
const {layer, handle} = this.props;
22+
23+
this.layerId = layer.get('id');
2124

2225
this.handle = {
2326
change(code){
27+
//check if id was changed, if so navigate to page that matches id
28+
console.log('change code:',code,this.layerId);
29+
if (this.layerId !== code.id){
30+
Mlayer.set(this.layerId,code).then(()=>{
31+
this.layerId = code.id;
32+
handle.routeReplace('layer/'+code.id);
33+
});
34+
return;
35+
}
2436
handle.change(code);
2537
}
2638
};
@@ -33,6 +45,8 @@ export default class VlayerEditJSON extends React.Component {
3345
render (){
3446
const {layer, error} = this.props;
3547

48+
this.layerId = layer.get('id');
49+
3650
// convert error to JSON position
3751
//console.log('json error:',error);
3852

src/view/Vproperty/index.jsx

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -282,35 +282,5 @@ export default class Vproperty extends React.Component {
282282

283283
</div>;
284284

285-
286-
287-
288-
289-
290-
291-
292-
293-
294-
/*
295-
if (List.isList(property.value)){
296-
// render an expression field
297-
return <Vfield field={{
298-
type:'expression',
299-
name:'type',
300-
label:'Type',
301-
value:property.value,
302-
placeholder:spec.doc,
303-
controlled:false
304-
}} key="type" handle={handle}/>
305-
}
306-
307-
// if value is an ary, use the expression field
308-
309-
// else use the spec type
310-
311-
312-
return <div className="">
313-
</div>;
314-
*/
315285
}
316286
};

0 commit comments

Comments
 (0)