aboutsummaryrefslogtreecommitdiff
path: root/modern/src/attributes/EditAttributesView.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/attributes/EditAttributesView.js')
-rw-r--r--modern/src/attributes/EditAttributesView.js57
1 files changed, 29 insertions, 28 deletions
diff --git a/modern/src/attributes/EditAttributesView.js b/modern/src/attributes/EditAttributesView.js
index 5ca7cad1..e8d427bf 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 }) => {