-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display monitoring stations in view licence page summary tab #773
Display monitoring stations in view licence page summary tab #773
Conversation
View licence summary monitoring stations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few things mainly around how we attempt to 'clean up' the legacy tables via the views.
There are also some typos of 'guaging' in comments etc that need fixing.
db/migrations/public/20240229142857_create-water-gauging-stations-view.js
Outdated
Show resolved
Hide resolved
db/migrations/public/20240229150626_create-water-licence-gauging-stations-view.js
Outdated
Show resolved
Hide resolved
const jsonArray = stations.map(JSON.stringify) | ||
monitoringStations = Array.from(new Set(jsonArray)).map(JSON.parse) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not just pass stations directly into new Set()
and therefore get our results directly from it?
const jsonArray = stations.map(JSON.stringify) | |
monitoringStations = Array.from(new Set(jsonArray)).map(JSON.parse) | |
const monitoringStations = [...new Set(stations)] |
Worth a try?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that and sadly didn't work. I don't think it's built around doing sets of objects. or at least not that I could get working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are 💯 right! 🤦 It's that JavaScript thing of 2 objects even with the same properties and values are not equal, but 'foo' and 'foo' are.
Reminded myself of where we are using Set()
and it is always with strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://eaflood.atlassian.net/browse/WATER-4331 The `LicenceGaugingStationModel` was in [Display monitoring stations in view licence page summary tab](#773) as part of our work to replace the legacy view licence page. `water.licence_gauging_station` is simply the many-to-many table that links licences to gauging stations. When we get those we'll typically set the relationship up, for example, that `licences` links to `gauging_stations` _through_ `licence_gauging_stations`. That was what we did in this case. Only, we named the relationship `licenceGaugingStations`. This is incorrect because if we did do an [Objection.js withGraphFetched()](https://vincit.github.io/objection.js/api/query-builder/eager-methods.html#withgraphfetched) we'd get `GaugingStationModel`s back, _not_ `LicenceGaugingStationModel`s. Also, we never added any tests for the relationship! This change fixes the name of the relationship and adds the missing tests.
https://eaflood.atlassian.net/browse/WATER-4331 ** Where we started! The `LicenceGaugingStationModel` was added in [Display monitoring stations in view licence page summary tab](#773) as part of our work to replace the legacy view licence page. `water.licence_gauging_stations` links licences to gauging stations. When we get these, we'll typically setup the relationship, for example, as `licences` links to `gauging_stations` _through_ `licence_gauging_stations`. That was what we did in this case. Only we named the relationship `licenceGaugingStations`. This is incorrect because if we did do an [Objection.js withGraphFetched()](https://vincit.github.io/objection.js/api/query-builder/eager-methods.html#withgraphfetched) we'd get `GaugingStationModel`s back, _not_ `LicenceGaugingStationModel`s. But in this case, `water.licence_gauging_stations` also contains details about the abstraction periods that apply and the certain metrics (though, to be honest, we don't know why we record them!) We'll want that information as well at some point, so a _through_ relationship is not really appropriate. Also, we never added any tests for the relationship! ** Where we finished! Digging into this relationship and correcting it then meant needing to make changes to `FetchLicenceSummaryService`. But that brought to light that the fetch query was doing things in a way that could be simplified with knock-on effects for the presenter. Then in the presenter tests, we saw that there wasn't a test that covered a full response, and we'd split them based on the properties passed in and not what we get out. We also found that a number of these models didn't have unit tests themselves. Finally, the migration scripts didn't match up to what is actually in the real DB. SO, this became a major tidy up of fetching and presenting a licence for the view summary. There is still more we think can be done. But we've drawn a line at this point 😁.
https://eaflood.atlassian.net/browse/WATER-4331
View licence summary monitoring stations