Skip to content

Commit 0dfac6e

Browse files
authored
Merge pull request #216 from thingsdb/infinite_loop
Fix on type change
2 parents 0c8e240 + 5991ee1 commit 0dfac6e

File tree

7 files changed

+91
-20
lines changed

7 files changed

+91
-20
lines changed

react/package-lock.json

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

react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@mui/lab": "5.0.0-alpha.82",
3636
"@mui/material": "5.8.0",
3737
"babel-loader": "8.2.5",
38-
"css-loader": "6.7.1",
38+
"css-loader": "5.2.7",
3939
"deep-equal": "2.0.5",
4040
"file-loader": "6.2.0",
4141
"moment": "2.29.3",

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ const TypeEnumNetwork = ({collection, customTypes, enums}) => {
153153

154154
return (
155155
<SimpleModal
156-
button={(_customTypes.length > 0 || _enums.length > 0) &&
156+
button={(_customTypes.length > 0 || _enums.length > 0) ?
157157
<Button variant="outlined" color="primary" onClick={handleClickOpen}>
158158
{'Type and Enum network'}
159159
</Button>
160+
: null
160161
}
161162
open={show}
162163
onClose={handleClickClose}

react/src/Components/Utils/ContextInput/InputField.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React from 'react';
55

66
import {EditProvider, useEdit} from './Context';
77
import {THINGS_DOC_COLLECTION, THINGS_DOC_DATETIME, THINGS_DOC_TIMEVAL, THINGS_DOC_TYPES} from '../../../Constants/Links';
8-
import {AddArray, AddBlob, AddBool, AddClosure, AddEnum, AddError, AddFloat, AddInt, AddCode, AddRegex, AddRoom, AddNil, AddStr, AddThing, AddVariable} from './Utils';
8+
import {AddArray, AddBlob, AddBool, AddClosure, AddEnum, AddError, AddFloat, AddInt, AddCode, AddRegex, AddRoom, AddNil, AddStr, AddThing, AddType, AddVariable} from './Utils';
99
import {BOOL, BYTES, CLOSURE, CODE, DATETIME, ERROR, FLOAT, INT, LIST, NIL, REGEX, ROOM,
1010
SET, STR, THING, TIMEVAL, VARIABLE} from '../../../Constants/ThingTypes';
1111

@@ -50,7 +50,7 @@ const InputField = ({customTypes, childTypes, dataTypes, dataType, enums, identi
5050
);
5151
default: return(
5252
[...customTypes.map(c=>c.name)].includes(dataType) ? (
53-
<AddCode identifier={identifier} init={`${dataType}()`} label="Value" link={THINGS_DOC_TYPES} numLines="1" parent={parent} />
53+
<AddType identifier={identifier} type={dataType} label="Value" link={THINGS_DOC_TYPES} numLines="1" parent={parent} />
5454
) : <AddEnum identifier={identifier} enumName={dataType} enums={enums} init={init} parent={parent} {...props} />
5555
);
5656
}

react/src/Components/Utils/ContextInput/Utils/AddCode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const AddCode = ({identifier, init, label, link, numLines, parent}) => {
5050

5151
AddCode.defaultProps = {
5252
identifier: null,
53-
init:'',
53+
init: '',
5454
},
5555

5656
AddCode.propTypes = {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* eslint-disable react-hooks/exhaustive-deps */
2+
import PropTypes from 'prop-types';
3+
import React from 'react';
4+
5+
import {EditActions, useEdit} from '../Context';
6+
import AddCode from './AddCode';
7+
8+
9+
const AddType = ({identifier, label, link, numLines, parent, type}) => {
10+
const [, dispatch] = useEdit();
11+
12+
React.useEffect(()=>{
13+
if (type) {
14+
EditActions.update(dispatch, 'val', `${type}()`, identifier, parent);
15+
}
16+
}, [type]);
17+
18+
return(
19+
<AddCode identifier={identifier} label={label} link={link} numLines={numLines} parent={parent} />
20+
);
21+
};
22+
23+
AddType.defaultProps = {
24+
identifier: null,
25+
type: '',
26+
},
27+
28+
AddType.propTypes = {
29+
identifier: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
30+
type: PropTypes.string,
31+
label: PropTypes.string.isRequired,
32+
link: PropTypes.string.isRequired,
33+
numLines: PropTypes.string.isRequired,
34+
parent: PropTypes.string.isRequired,
35+
};
36+
37+
export default AddType;

react/src/Components/Utils/ContextInput/Utils/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import AddRegex from './AddRegex';
1212
import AddRoom from './AddRoom';
1313
import AddStr from './AddStr';
1414
import AddThing from './AddThing';
15+
import AddType from './AddType';
1516
import AddVariable from './AddVariable';
1617

1718
export {
@@ -29,5 +30,6 @@ export {
2930
AddRoom,
3031
AddStr,
3132
AddThing,
33+
AddType,
3234
AddVariable
3335
};

0 commit comments

Comments
 (0)