diff options
author | Desmond Kyeremeh <elDekyfin@gmail.com> | 2021-07-11 23:39:30 +0000 |
---|---|---|
committer | Desmond Kyeremeh <elDekyfin@gmail.com> | 2021-07-11 23:39:30 +0000 |
commit | 004367fc1fd389b169821eb2d73266490f409999 (patch) | |
tree | 1b7e6f13c03326a957bdb78351853f429156b3ae /modern/src/attributes/EditAttributesView.js | |
parent | 1b93de84e2bf6a6532bdb03e1ae75e47061a4dca (diff) | |
parent | 702e674ecce7de1a4f4318ef8f30c572264a4560 (diff) | |
download | etbsa-traccar-web-004367fc1fd389b169821eb2d73266490f409999.tar.gz etbsa-traccar-web-004367fc1fd389b169821eb2d73266490f409999.tar.bz2 etbsa-traccar-web-004367fc1fd389b169821eb2d73266490f409999.zip |
Merge remote-tracking branch 'upstream/master' into group-config
Diffstat (limited to 'modern/src/attributes/EditAttributesView.js')
-rw-r--r-- | modern/src/attributes/EditAttributesView.js | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/modern/src/attributes/EditAttributesView.js b/modern/src/attributes/EditAttributesView.js index 5ca7cad..e8d427b 100644 --- a/modern/src/attributes/EditAttributesView.js +++ b/modern/src/attributes/EditAttributesView.js @@ -23,10 +23,37 @@ const EditAttributesView = ({ attributes, setAttributes, definitions }) => { const [addDialogShown, setAddDialogShown] = useState(false); + const updateAttribute = (key, value) => { + const updatedAttributes = { ...attributes }; + updatedAttributes[key] = value; + setAttributes(updatedAttributes); + }; + + const deleteAttribute = (key) => { + const updatedAttributes = { ...attributes }; + delete updatedAttributes[key]; + setAttributes(updatedAttributes); + }; + + const getAttributeName = (key) => { + const definition = definitions[key]; + return definition ? definition.name : key; + }; + + const getAttributeType = (value) => { + if (typeof value === 'number') { + return 'number'; + } + if (typeof value === 'boolean') { + return 'boolean'; + } + return 'string'; + }; + const convertToList = (attributes) => { const booleanList = []; const otherList = []; - for (const key in attributes) { + Object.keys(attributes).forEach((key) => { const value = attributes[key]; const type = getAttributeType(value); if (type === 'boolean') { @@ -34,7 +61,7 @@ const EditAttributesView = ({ attributes, setAttributes, definitions }) => { } else { otherList.push({ key, value, type }); } - } + }); return otherList.concat(booleanList); }; @@ -55,32 +82,6 @@ const EditAttributesView = ({ attributes, setAttributes, definitions }) => { } }; - const updateAttribute = (key, value) => { - const updatedAttributes = { ...attributes }; - updatedAttributes[key] = value; - setAttributes(updatedAttributes); - }; - - const deleteAttribute = (key) => { - const updatedAttributes = { ...attributes }; - delete updatedAttributes[key]; - setAttributes(updatedAttributes); - }; - - const getAttributeName = (key) => { - const definition = definitions[key]; - return definition ? definition.name : key; - }; - - const getAttributeType = (value) => { - if (typeof value === 'number') { - return 'number'; - } if (typeof value === 'boolean') { - return 'boolean'; - } - return 'string'; - }; - return ( <> {convertToList(attributes).map(({ key, value, type }) => { |