Skip to content

Commit

Permalink
Initialize command defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Feb 7, 2025
1 parent a94b586 commit 7f07ebc
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/settings/components/BaseCommandView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,29 @@ const BaseCommandView = ({ deviceId, item, setItem }) => {
}
}, [availableAttributes, item]);

const updateType = (type) => {
const defaults = {};
availableAttributes[type]?.forEach((attribute) => {
switch (attribute.type) {
case 'boolean':
defaults[attribute.key] = false;
break;
case 'number':
defaults[attribute.key] = 0;
break;
default:
defaults[attribute.key] = '';
break;
}
});
setItem({ ...item, type, attributes: defaults });
};

return (
<>
<SelectField
value={item.type}
onChange={(e) => setItem({ ...item, type: e.target.value, attributes: {} })}
onChange={(e) => updateType(e.target.value)}
endpoint={deviceId ? `/api/commands/types?${new URLSearchParams({ deviceId }).toString()}` : '/api/commands/types'}
keyGetter={(it) => it.type}
titleGetter={(it) => t(prefixString('command', it.type))}
Expand Down

0 comments on commit 7f07ebc

Please sign in to comment.