Skip to content
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

Merged
merged 4 commits into from
Mar 5, 2024

Conversation

robertparkinson
Copy link
Collaborator

https://eaflood.atlassian.net/browse/WATER-4331

View licence summary monitoring stations

View licence summary monitoring stations
@robertparkinson robertparkinson self-assigned this Feb 29, 2024
@robertparkinson robertparkinson marked this pull request as ready for review March 5, 2024 09:04
Copy link
Member

@Cruikshanks Cruikshanks left a 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.

app/models/gauging-station.model.js Show resolved Hide resolved
Comment on lines +114 to +115
const jsonArray = stations.map(JSON.stringify)
monitoringStations = Array.from(new Set(jsonArray)).map(JSON.parse)
Copy link
Member

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?

Suggested change
const jsonArray = stations.map(JSON.stringify)
monitoringStations = Array.from(new Set(jsonArray)).map(JSON.parse)
const monitoringStations = [...new Set(stations)]

Worth a try?

Copy link
Collaborator Author

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

Copy link
Member

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.

Copy link
Member

@Cruikshanks Cruikshanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robertparkinson robertparkinson merged commit 0d2ca82 into main Mar 5, 2024
6 checks passed
@robertparkinson robertparkinson deleted the view-licence-summary-monitoring-stations branch March 5, 2024 14:14
@Beckyrose200 Beckyrose200 added the enhancement New feature or request label Mar 25, 2024
Cruikshanks added a commit that referenced this pull request Jun 13, 2024
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.
Cruikshanks added a commit that referenced this pull request Jun 14, 2024
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 😁.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants