farmOS / field-kit

A modular, offline-first companion app to farmOS.
https://farmOS.org
GNU General Public License v3.0
60 stars 39 forks source link

Make assets available to Field Module widgets via the assets prop. #396

Closed paul121 closed 4 years ago

paul121 commented 4 years ago

Would like to display the current number of sensors in the Sensors Field Module widget! This seems to make that possible; @jgaehring let me know if there is a better way? Curious about making other things such as areas available as well.

I'm trying to see how this is done for the main Field Module component as it seems like all props are made available to those components, but its not as obvious. Does this happen in createRoutes when the Field Module is created?

jgaehring commented 4 years ago

Oh cool! Yea, that makes sense you'd want to display them.

Looks good to me. The one thing I might do is pass down assets: this.assets || []. This can lead to a safer and cleaner UI because you can just iterate over the assets in your templates w/o having to perform a null check each time. There shouldn't be nulls passed down regardless, but I've definitely run into it happening on occasion and then everything goes to crap.

I'm trying to see how this is done for the main Field Module component as it seems like all props are made available to those components, but its not as obvious. Does this happen in createRoutes when the Field Module is created?

App.vue is responsible for handing them down through the <router-view> component.

paul121 commented 4 years ago

The one thing I might do is pass down assets: this.assets || []. This can lead to a safer and cleaner UI because you can just iterate over the assets in your templates w/o having to perform a null check each time. There shouldn't be nulls passed down regardless, but I've definitely run into it happening on occasion and then everything goes to crap.

Cool, yeah, I thought that shouldn't happen but better safe than sorry! Added a commit for that.

App.vue is responsible for handing them down through the component.

Ah, I missed that! Pretty obvious. Thanks!