-
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
View licence summary abstraction periods #721
Conversation
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'm around if you need to ping me about any of this!
.withGraphFetched('licenceDocumentHeader') | ||
.withGraphFetched('licenceVersions.[licenceVersionPurposes, purposes]') |
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.
This is less a convention and more a stipulation of mine! 😁
Where we are extracting data from the DB we never have a SELECT *
even if it means listing out a dozen fields separately. I believe it's handy to be explicit about what data is needed. IMHO it also keeps the right side of performance because you are not pulling data across the network you don't need.
In Objection.js terms, a withGraphFetched()
without a following .modifyGraph('licenceDocumentHeader', builder => { builder.select([]) }) is the equivalent of a
SELECT * FROM licence_document_header`.
Would you mind adding in for both of these a modifyGraph()
that lists out what fields we need from both tables?
if (!licenceVersions || licenceVersions.length === 0 || licenceVersions[0]?.licenceVersionPurposes === undefined || | ||
licenceVersions[0]?.licenceVersionPurposes?.length === 0) { | ||
return null | ||
} |
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.
The first thing I was going to ask was that if we have to put one of the clauses on a newline could we put all the clauses on a new line?
if (!licenceVersions || licenceVersions.length === 0 || licenceVersions[0]?.licenceVersionPurposes === undefined || | |
licenceVersions[0]?.licenceVersionPurposes?.length === 0) { | |
return null | |
} | |
if ( | |
!licenceVersions || | |
licenceVersions.length === 0 || | |
!licenceVersions[0]?.purposes || | |
licenceVersions[0]?.purposes?.length === 0 | |
) { | |
return null | |
} |
Then spotted we have the exact same logic in _generatePurposes()
. I don't normally worry about some duplication but as this is quite involved and within the same module should we also look to move this to its own method? For example
function _extractPurposes (licenceVersions) {
if (
!licenceVersions ||
licenceVersions.length === 0 ||
!licenceVersions[0]?.purposes ||
licenceVersions[0]?.purposes?.length === 0
) {
return null
}
return licenceVersions[0].purposes
}
Then I got to thinking did we need to check all the different states? Could we shortcut it? So, I threw this test together.
A bunch of stuff here I know so I'll try to summarise.
- Putting clauses on distinct lines if we have to wrap is a change I would wish applied
- Moving the logic to a helper function in the module is a strong suggestion but I can be argued out of it
- Using the short-cut version of helper function is merely an idea. A part of me quite likes we get a distinct
null || [{}]
if we use what you have
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.
it's not the same check. it's licenceVersions[0]?.licenceVersionPurposes
vs licenceVersions[0]?.purposes === undefined
I had started to pull everything into one large function called _generateAbstractionPeriodsAndPurposes and returned an object with the purposes and abstractionPeriods on it. perhaps that would be a better way to go?
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.
My bad! Just putting each constraint on a separate line then (and I'll slink away)
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-4329
Migrating the licence summary page from the water-abstraction-ui to the water-abstraction-system.
Show periods of abstraction