Skip to content

Commit

Permalink
fix(#369):Fixes watches to modify attributes to watch correctly (#370)
Browse files Browse the repository at this point in the history
* fix(#369):Fixes watches to modify attributes to watch correctly

* fix(#369): Remove console.log
  • Loading branch information
joshiraez committed Jun 22, 2023
1 parent 4d4a2c7 commit a906aaa
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export const WatchableAttributesForm = ({
onAttributesToWatchUpdate: (newAttributes: AttributesToWatch) => void
}) => {
const [modalAttributesToWatch, setModalAttributesToWatch] = useState<AttributesToWatch>(attributesToWatch)
// Take care when switching the text prop. As right now it's used to identify the key in attributes to watch prop.
// Because the key needs to be unique across all trees (or else there is a bug where the check selection applies to
// any element in any tree with the same key), I had to change the keys and no longer can use that prop for storing the key
// to the original attributes to watch.
// There is a way around this building a dictionary storing attribute names - keys, but it seemed too overengineered
// when the text is currently the same attribute name as the key in attributes to watch

return (
<Modal
Expand Down Expand Up @@ -67,14 +73,14 @@ export const WatchableAttributesForm = ({
) => {
const newWatches: AttributesToWatch = {}
newWatchedAttributes.forEach(newWatchedAttribute => {
newWatches[newWatchedAttribute.id] = {
...Object.fromEntries(newWatchedAttribute.children?.map(({ id }) => [id, true]) || []),
newWatches[newWatchedAttribute.text] = {
...Object.fromEntries(newWatchedAttribute.children?.map(({ text }) => [text, true]) || []),
}
})
newUnwatchedAttributes.forEach(newUnwatchedAttribute => {
newWatches[newUnwatchedAttribute.id] = {
...(newWatches[newUnwatchedAttribute.id] || {}),
...Object.fromEntries(newUnwatchedAttribute.children?.map(({ id }) => [id, false]) || []),
newWatches[newUnwatchedAttribute.text] = {
...(newWatches[newUnwatchedAttribute.text] || {}),
...Object.fromEntries(newUnwatchedAttribute.children?.map(({ text }) => [text, false]) || []),
}
})

Expand Down

0 comments on commit a906aaa

Please sign in to comment.