Skip to content

Commit 876fb65

Browse files
author
AnjaBruls
committed
update
1 parent 17b46cb commit 876fb65

File tree

16 files changed

+119
-94
lines changed

16 files changed

+119
-94
lines changed

sockethandlers/collectionhandler.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,6 @@ func QueryBlob(client *Client, data Data, timeout uint16) (int, interface{}, uti
5353
return query(client, data, blob, timeout)
5454
}
5555

56-
// func QueryBlob(client *Client, data Data, timeout uint16) (int, interface{}, util.Message) {
57-
// decodedBlob, err := base64.StdEncoding.DecodeString(data.Blob)
58-
// if err != nil {
59-
// message := util.Message{Text: "Query error", Status: http.StatusInternalServerError, Log: err.Error()}
60-
// return message.Status, "", message
61-
// }
62-
63-
// blob := map[string]interface{}{
64-
// "blob": decodedBlob,
65-
// }
66-
67-
// return query(client, data, blob, timeout)
68-
// }
69-
7056
func QueryEditor(client *Client, data Data, timeout uint16) (int, interface{}, util.Message) {
7157
var collectionResp = make(map[string]interface{})
7258

sockethandlers/loginhandler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ func connect(client *Client, data LoginData) LoginResp {
5555
client.Connection = things.NewConn(host, uint16(port), client.Ssl)
5656
client.Connection.EventCh = client.EventCh
5757
client.Connection.LogCh = client.LogCh
58-
client.Connection.OnClose = func() {
58+
client.Connection.OnClose = func(err error) {
5959
go func() {
60+
fmt.Println("onClose", err)
6061
client.Closed <- true
6162
}()
6263
}

src/Components/Collections/Tree/TreeActions/BuildQueryString.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
22
import React from 'react';
33
import TextField from '@material-ui/core/TextField';
44

5-
const BuildQueryString = ({action, cb, child, customTypes, parent, showQuery, query}) => {
5+
const BuildQueryString = ({action, cb, child, customTypes, parent, showQuery, query, blob}) => {
66

77
React.useEffect(() => {
88
handleBuildQuery(action, child.val, child.type, child.index, child.id, child.name, parent.id, parent.name, parent.type);
@@ -45,8 +45,9 @@ const BuildQueryString = ({action, cb, child, customTypes, parent, showQuery, qu
4545
const setTypeInput = (name, type, customTypes, v) =>
4646
type[0]=='['? createArrayInput(name, type, customTypes, v)
4747
: type[0]=='{'? createSetInput(name, type, customTypes, v)
48-
: type=='str' || type=='utf8' || type=='raw' ? `'${v}'`
49-
: `${v}`;
48+
: type=='str' || type=='utf8' ? `'${v}'`
49+
: type=='raw' ? (blob[v] ? `${v}` : `'${v}'`)
50+
: `${v}`;
5051

5152
const mapTypeInput = (v, customTypes) => v.map(({name, type, val}) => `${name}: ${customTypeInput(name, type, customTypes, val)}`);
5253

@@ -68,7 +69,8 @@ const BuildQueryString = ({action, cb, child, customTypes, parent, showQuery, qu
6869
return parentType==='list' ? (childIndex===null ? `#${parentId}.${parentName}.push(${value});` : `#${parentId}.${parentName}[${childIndex}] = ${value};`)
6970
: parentType==='thing' ? `#${parentId}.${childName} = ${value};`
7071
: parentType==='set' ? `#${parentId}.${parentName}.add(${value});`
71-
: '';
72+
: customTypes.hasOwnProperty(parentType) ? `#${parentId}.${childName} = ${value};`
73+
: '';
7274
};
7375

7476
const buildQueryRemove = (parentId, parentName, parentType, childId, childName, childIndex) => {
@@ -108,10 +110,12 @@ const BuildQueryString = ({action, cb, child, customTypes, parent, showQuery, qu
108110

109111
BuildQueryString.defaultProps = {
110112
query: '',
113+
blob:{},
111114
};
112115

113116
BuildQueryString.propTypes = {
114117
action: PropTypes.string.isRequired,
118+
blob: PropTypes.object,
115119
cb: PropTypes.func.isRequired,
116120
child: PropTypes.object.isRequired,
117121
customTypes: PropTypes.object.isRequired,

src/Components/Collections/Tree/TreeActions/CustomChild.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,36 @@ const CustomChild = ({onVal, onBlob, customTypes, name, type, activeStep, stepId
6262
});
6363
};
6464

65-
const handleRemove = (t) => (i) => {
65+
const handleRemove = (t) => (i) => { //TODO test
6666
setVal(prevVal => {
6767
let update = [...prevVal];
6868
const index = prevVal.findIndex((v) => v && v.type == t);
6969
update[index].val.splice(i, 1);
7070
update.splice(index, 1, {name: update[index].name, type: update[index].type, val: update[index].val});
7171
return update;
7272
});
73+
if (Object.keys(blobArr).length>0) {
74+
console.log(blobArr, t);
75+
setBlob(prevBlob => {
76+
let copyState = JSON.parse(JSON.stringify(prevBlob));
77+
let k = Object.keys(blobArr[t])[i];
78+
delete copyState[k];
79+
console.log(copyState, k);
80+
return copyState;
81+
});
82+
}
7383
};
7484

75-
const handleRemoveOptional = (k) => () => {
85+
const handleRemoveOptional = (k) => () => { //TODO test potentially multiple un use blob can be stacked in the blob object. Because blob object is not removed in this case.
7686
setOptional({...optional, [k]: true});
7787
setVal(prevVal => {
7888
let update = [...prevVal];
7989
const index = update.findIndex((v) => v.name == k);
80-
update.splice(index, 1);
90+
if (index != -1) {
91+
update.splice(index, 1);
92+
}
8193
return update;
8294
});
83-
setBlob(prevBlob => {
84-
let copyState = JSON.parse(JSON.stringify(prevBlob));
85-
let k = Object.keys(blobArr[k]);
86-
k.map(i => delete copyState[i]);
87-
return {copyState};
88-
});
8995
};
9096

9197
const handleAddOptional = (k) => () => {
@@ -97,7 +103,10 @@ const CustomChild = ({onVal, onBlob, customTypes, name, type, activeStep, stepId
97103
};
98104

99105
const handleBlobArr = (t) => (b) => {
100-
setBlobArr({...blobArr, [t]: b});
106+
setBlobArr(prevBlob => {
107+
const updatedBlob = Object.assign({}, prevBlob[t], b);
108+
return {...prevBlob, [t]: updatedBlob};
109+
});
101110
setBlob({...blob, ...b});
102111
};
103112

src/Components/Collections/Tree/TreeActions/Edit.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ const Edit = ({child, customTypes, parent, thing, dataTypes, cb}) => {
4848
const [newProperty, setNewProperty] = React.useState('');
4949
const [dataType, setDataType] = React.useState(child.type=='list'||child.type=='thing' ? dataTypes[0]: child.type=='set' ? 'thing' : child.type);
5050

51-
console.log(value, dataType, blob);
52-
5351
React.useEffect(() => {
5452
cb(queryString, blob, error);
5553
},
@@ -81,7 +79,7 @@ const Edit = ({child, customTypes, parent, thing, dataTypes, cb}) => {
8179
};
8280

8381
const handleBlob = (b) => {
84-
setBlob({...blob, ...b});
82+
setBlob(b);
8583
};
8684

8785
const handleCustom = (c) => {
@@ -91,8 +89,8 @@ const Edit = ({child, customTypes, parent, thing, dataTypes, cb}) => {
9189
});
9290
};
9391

94-
const addNewProperty = Boolean(child.id);
95-
const canChangeType = child.type == 'thing' || child.type == 'list' || child.type == 'set';
92+
const addNewProperty = Boolean(child.id) && !(child.type.trim()[0] == '<');
93+
const canChangeType = child.type == 'thing' || child.type == 'list' || child.type == 'set' || child.type == 'nil';
9694
const isCustomType = customTypes.hasOwnProperty(dataType);
9795

9896
return(
@@ -118,6 +116,7 @@ const Edit = ({child, customTypes, parent, thing, dataTypes, cb}) => {
118116
}}
119117
showQuery
120118
query={queryString}
119+
blob={blob}
121120
/>
122121
</ListItem>
123122
</Collapse>

src/Components/Collections/Tree/TreeActions/StandardChild.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ const StandardChild = ({onVal, onBlob, name, type, arrayType}) => {
5959
const [val, setVal] = React.useState('');
6060
const [dataType, setDataType] = React.useState(arrayType||typeConv[type][0]);
6161

62-
console.log(type, arrayType);
63-
6462
React.useEffect(() => {
6563
onVal({name: name, type: type, val: val});
6664
onBlob(blob);

src/Components/Collections/Tree/TreeActions/ThingActionsDialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const ThingActionsDialog = ({open, onClose, child, parent, thing, scope}) => {
127127
const isChildCustom = customTypes.hasOwnProperty(realChildType);
128128
const isParentCustom = customTypes.hasOwnProperty(realParentType);
129129
const canRemove = !(child.name === '/' || parent.isTuple || isRoot || isParentCustom);
130-
const canEdit = !(parent.isTuple && child.type !== 'thing' || realChildType=='tuple' || isChildCustom || child.type==='nil' || child.type === 'bytes');
130+
const canEdit = !(parent.isTuple && child.type !== 'thing' || realChildType=='tuple' || isChildCustom || child.type === 'bytes');
131131
const canWatch = thing && thing.hasOwnProperty('#');
132132
const canDownload = child.type === 'bytes';
133133

src/Components/Collections/Tree/TreeView/Thing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const Thing = ({thing, collection, things, parent, child, watchIds}) => {
5151
const type = checkType(thing);
5252
const val = thingValue(type, thing);
5353

54-
const canToggle = (type === 'thing' && Object.keys(thing).length>1) || (type === 'array' && thing.length>0) || type === 'closure' || type === 'regex'|| type === 'error';
54+
const canToggle = type === 'thing' || (type === 'array' && thing.length>0) || type === 'closure' || type === 'regex'|| type === 'error';
5555

5656
const isTuple = type === 'array' && parent.type === 'array';
5757
const thingId = thing && thing['#'] || parent.id;

src/Components/Util/Add1DArray.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ const useStyles = makeStyles(theme => ({
2020

2121
const dataTypes = [ // Do not put array first; causes infinite loop
2222
'str',
23-
'number',
2423
'bool',
2524
'int',
2625
'float',
27-
// 'bytes',
26+
'bytes',
2827
'closure',
2928
'regex',
3029
'error',
@@ -36,6 +35,7 @@ const dataTypes = [ // Do not put array first; causes infinite loop
3635

3736
const Add1DArray = ({onBlob, onVal, type}) => {
3837
const classes = useStyles();
38+
const [preBlob, setPreBlob] = React.useState({});
3939
const [blob, setBlob] = React.useState({});
4040
const [state, setState] = React.useState({
4141
contentAdd: '',
@@ -63,21 +63,28 @@ const Add1DArray = ({onBlob, onVal, type}) => {
6363

6464
const typeControls = (type, input) => {
6565
return type === 'nil' ? 'nil'
66-
: `${input}`;
66+
: type === 'str' ? `'${input}'`
67+
: `${input}`;
6768
};
6869

6970
const handleAdd = () => {
70-
// let currentcontent = contentAdd.trim();
7171
const contentTypeChecked = typeControls(dataType, contentAdd);
7272
setMyItems(prevItems => {
7373
const newArray = [...prevItems];
7474
newArray.push(contentTypeChecked);
7575
return newArray;
7676
});
77+
setBlob({...blob, ...preBlob});
7778

7879
};
7980

8081
const handleClick = (index) => () => {
82+
setBlob(prevBlob => {
83+
let copyState = JSON.parse(JSON.stringify(prevBlob));
84+
let k = myItems[index];
85+
delete copyState[k];
86+
return copyState;
87+
});
8188
setMyItems(prevItems => {
8289
const newArray = [...prevItems];
8390
newArray.splice(index, 1);
@@ -101,7 +108,7 @@ const Add1DArray = ({onBlob, onVal, type}) => {
101108
};
102109

103110
const handleBlob = (b) => {
104-
setBlob({...blob, ...b});
111+
setPreBlob({...b});
105112
};
106113

107114
return (
@@ -132,6 +139,7 @@ const Add1DArray = ({onBlob, onVal, type}) => {
132139
variant="outlined"
133140
select
134141
SelectProps={{native: true}}
142+
fullWidth
135143
>
136144
{dataTypes.map((p) => (
137145
<option key={p} value={p} disabled={type==''?false:p!=type}>

src/Components/Util/AddBlob.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ const AddBlob = ({onVal, onBlob}) => {
1111
const [fileName, setFileName] = React.useState('');
1212

1313
React.useEffect(() => {
14-
onVal(fileName);
15-
onBlob({[fileName]: blob});
14+
let f = fileName;
15+
if (fileName.includes('.')) {
16+
f = fileName.split('.')[0];
17+
}
18+
if (f != '' && blob != '') {
19+
onVal(f);
20+
onBlob({[f]: blob});
21+
}
1622
},
17-
[blob, fileName],
23+
[fileName],
1824
);
1925

20-
console.log(fileName)
21-
2226
const handleDropzone = React.useCallback(acceptedFiles => {
2327
const reader = new FileReader();
2428
reader.onabort = () => console.log('file reading was aborted');

0 commit comments

Comments
 (0)