Skip to content

Commit e388630

Browse files
authored
Merge pull request #229 from thingsdb/228
Fixed editing list item in tree
2 parents 7f102e7 + 82c58af commit e388630

File tree

8 files changed

+1182
-1111
lines changed

8 files changed

+1182
-1111
lines changed

react/package-lock.json

Lines changed: 1145 additions & 1092 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react/src/Components/Collections/EnumsTypes/TypeEnumNetwork.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { withVlow } from 'vlow';
44
import Grid from '@mui/material/Grid';
55
import PropTypes from 'prop-types';
66
import React from 'react';
7-
import Typography from '@mui/material/Typography';
87

98
import { COLLECTION_SCOPE } from '../../../Constants/Scopes';
109
import { EnumActions, EnumStore, TypeActions, TypeStore } from '../../../Stores';

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import TypeInit from './TypeInit';
1414

1515
const Edit = ({child, customTypes, dataTypes, enums, parent, scope, thing}) => {
1616
const [newProperty, setNewProperty] = React.useState('');
17-
const [dataType, setDataType] = React.useState(child.type==LIST||child.type==THING ? dataTypes[0]: child.type==SET ? THING : child.type);
17+
const [dataType, setDataType] = React.useState(child.type == LIST || child.type == THING ? dataTypes[0] : child.type == SET ? THING : child.type);
1818

1919
const handleOnChangeName = (p) => {
2020
setNewProperty(p);
@@ -40,13 +40,13 @@ const Edit = ({child, customTypes, dataTypes, enums, parent, scope, thing}) => {
4040
child={{
4141
id: null,
4242
index: child.index,
43-
name: child.type == THING?newProperty:child.name,
43+
name: child.type == THING ? newProperty : child.name,
4444
type: dataType,
4545
}}
4646
customTypes={customTypes}
4747
enums={enums}
4848
parent={{
49-
id: child.type == THING? child.id:parent.id,
49+
id: child.type == THING ? child.id : parent.id,
5050
name: child.type == THING || child.type == LIST || child.type == SET ? child.name : parent.name,
5151
type: child.type == THING || child.type == LIST || child.type == SET ? child.type : parent.type,
5252
}}

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ import { ROOM, THING, TUPLE } from '../../../../Constants/ThingTypes';
1313
import { ThingActionsDialogTAG } from '../../../../Constants/Tags';
1414
import {
1515
THING_QUERY,
16+
TYPE_INFO_CHILD_ARRAY_QUERY,
1617
TYPE_INFO_CHILD_THING_QUERY,
17-
TYPE_INFO_ELSE_QUERY,
18+
TYPE_INFO_PARENT_ARRAY_QUERY,
1819
TYPE_INFO_PARENT_THING_QUERY,
1920
TYPE_INFO_ROOT_THING_QUERY,
2021
} from '../../../../TiQueries/Queries';
2122
import {
23+
ID_ARGS,
24+
TYPE_INFO_CHILD_ARRAY_ARGS,
2225
TYPE_INFO_CHILD_THING_ARGS,
23-
TYPE_INFO_ELSE_ARGS,
26+
TYPE_INFO_PARENT_ARRAY_ARGS,
2427
TYPE_INFO_PARENT_THING_ARGS,
25-
ID_ARGS,
2628
} from '../../../../TiQueries/Arguments';
2729

2830
import DialogButtons from './DialogButtons';
@@ -59,17 +61,21 @@ const ThingActionsDialog = ({onClose, child, parent, thing, scope, isRoot}) => {
5961
let query = '';
6062
let jsonArgs = null;
6163
if (parent.id==null) {
62-
query = TYPE_INFO_ROOT_THING_QUERY; // check if custom type
64+
query = TYPE_INFO_ROOT_THING_QUERY;
6365
jsonArgs = ID_ARGS(child.id);
6466
} else if (parent.type == THING) {
65-
query = TYPE_INFO_PARENT_THING_QUERY; // check if custom type
67+
query = TYPE_INFO_PARENT_THING_QUERY;
6668
jsonArgs = TYPE_INFO_PARENT_THING_ARGS(parent.id, child.name);
6769
} else if (child.type == THING) {
6870
query = TYPE_INFO_CHILD_THING_QUERY; // in case parent is set than indexing is not supported. Therefore we need to check child type by id.
6971
jsonArgs = TYPE_INFO_CHILD_THING_ARGS(child.id, parent.id, parent.name);
72+
} else if (parent.index == null) {
73+
query = TYPE_INFO_CHILD_ARRAY_QUERY;
74+
jsonArgs = TYPE_INFO_CHILD_ARRAY_ARGS(parent.id, parent.pname, child.index);
7075
} else {
71-
query = TYPE_INFO_ELSE_QUERY; // check if custom type
72-
jsonArgs = TYPE_INFO_ELSE_ARGS(parent.id, parent.name, child.name);
76+
query = TYPE_INFO_PARENT_ARRAY_QUERY;
77+
// pname is the property name without any index indication; so `arr` instead of `arr[2]`
78+
jsonArgs = TYPE_INFO_PARENT_ARRAY_ARGS(parent.id, parent.index, parent.pname, child.index);
7379
}
7480
TypeActions.getType(query, scope, jsonArgs, tag, setType);
7581
EnumActions.getEnums(scope, tag, setEnums);
@@ -205,14 +211,16 @@ ThingActionsDialog.propTypes = {
205211
parent: PropTypes.shape({
206212
id: PropTypes.number,
207213
index: PropTypes.number,
214+
isTuple: PropTypes.bool,
208215
name: PropTypes.string,
216+
pname: PropTypes.string,
209217
type: PropTypes.string,
210-
isTuple: PropTypes.bool,
211218
}).isRequired,
212219
child: PropTypes.shape({
213220
id: PropTypes.number,
214221
index: PropTypes.number,
215222
name: PropTypes.string,
223+
pname: PropTypes.string,
216224
type: PropTypes.string,
217225
val: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
218226
}).isRequired,

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ const Thing = ({child, collection, parent, thing, things, inset}) => {
4040
thing={v}
4141
parent={{
4242
id: thingId,
43+
index: child.index,
44+
isTuple: isTuple,
4345
name: child.name,
46+
pname: child.pname,
4447
type: type,
45-
isTuple: isTuple,
4648
}}
4749
child={{
48-
name: fancyName(isArray?child.name:k, i),
4950
index: i,
51+
name: fancyName(isArray ? child.name : k, i),
52+
pname: isArray ? child.name : k,
5053
}}
5154
/>
5255
), [child.name, collection, isTuple, thingId, things, type]);
@@ -89,6 +92,7 @@ const Thing = ({child, collection, parent, thing, things, inset}) => {
8992
id: thing ? thing[THING_KEY] : null,
9093
index: child.index,
9194
name: child.name,
95+
pname: child.pname,
9296
type: type,
9397
val: val
9498
}}
@@ -113,13 +117,16 @@ Thing.propTypes = {
113117
collection: PropTypes.object.isRequired,
114118
parent: PropTypes.shape({
115119
id: PropTypes.number,
120+
index: PropTypes.number,
121+
isTuple: PropTypes.bool,
116122
name: PropTypes.string,
123+
pname: PropTypes.string,
117124
type: PropTypes.string,
118-
isTuple: PropTypes.bool,
119125
}).isRequired,
120126
child: PropTypes.shape({
121-
name: PropTypes.string,
122127
index: PropTypes.number,
128+
name: PropTypes.string,
129+
pname: PropTypes.string,
123130
}).isRequired,
124131
things: PropTypes.object.isRequired,
125132
inset: PropTypes.bool,

react/src/Components/Collections/Tree/TreeView/Things.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ const ThingRoot = ({things, collection}) => {
3737
name: 'root',
3838
type: THING,
3939
isTuple: false,
40+
index: null,
4041
}}
4142
child={{
42-
name: k,
4343
index: null,
44+
name: k,
45+
pname: k,
4446
}}
4547
/>
4648
), [collection, things]);

react/src/TiQueries/Arguments.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export const THING_SET_REMOVE_ARGS = (pid, name, cid) => ({ pid, name, cid });
2929

3030
// check types
3131
export const TYPE_INFO_CHILD_THING_ARGS = (cid, pid, name) => ({ cid, pid, name });
32-
export const TYPE_INFO_ELSE_ARGS = (pid, cname, pname) => ({ pid, cname, pname });
32+
export const TYPE_INFO_CHILD_ARRAY_ARGS = (pid, pname, cindex) => ({ pid, pname, cindex });
33+
export const TYPE_INFO_PARENT_ARRAY_ARGS = (pid, pindex, pname, cindex) => ({ pid, pindex, pname, cindex });
3334
export const TYPE_INFO_PARENT_THING_ARGS = (id, name) => ({ id, name });
3435

3536
// procedures

react/src/TiQueries/Queries.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ export const THING_SET_ADD_FORMAT_QUERY = (id, name, value) => `thing(${id}).${n
8383

8484
// check types
8585
export const TYPE_INFO_CHILD_THING_QUERY = '[type(thing(cid)), type(thing(pid).get(name)), types_info()];';
86-
export const TYPE_INFO_ELSE_QUERY = '[type(thing(pid).get(cname)), type(thing(pid).get(pname)), types_info()];';
86+
export const TYPE_INFO_CHILD_ARRAY_QUERY = '[type(thing(pid).get(pname)[cindex]), type(thing(pid).get(pname)), types_info()];';
87+
export const TYPE_INFO_PARENT_ARRAY_QUERY = '[type(thing(pid).get(pname)[pindex][cindex]), type(thing(pid).get(pname)[pindex]), types_info()];';
8788
export const TYPE_INFO_PARENT_THING_QUERY = '[type(thing(id).get(name)), type(thing(id)), types_info()];';
8889
export const TYPE_INFO_ROOT_THING_QUERY = '[type(thing(id)), "", types_info()];'; // child type, parent type, custom types
8990

0 commit comments

Comments
 (0)