-
Notifications
You must be signed in to change notification settings - Fork 1
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
APS 889 - Add OOS bed update page #1980
Conversation
26555d8
to
acacbe2
Compare
7a326e3
to
742f091
Compare
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.
Really clear, thks!
A couple of suggestions:
- I think we ought to be explicit (even though verbose) when referring to an
OutOfServiceBed
as distinct from aBed
- it's worth considering modelling these updates as separate REST resources in your URL scheme. You've already recognised their difference with a separate controller, but with a separate url scheme we could drop the
bedId
(and even thepremisesId
) from the URL scheme. Not sure if that would be a "now" refactoring or not though!
@@ -13,8 +13,6 @@ CAS1_E2E_EMERGENCY_ASSESSOR_NAME_TO_ALLOCATE_TO="JIM SNOW" | |||
CAS1_E2E_FUTURE_MANAGER_PASSWORD=*REDACTED* | |||
CAS1_E2E_FUTURE_MANAGER_USERNAME=APPROVEDPREMISESTESTUSER | |||
CAS1_E2E_LEGACY_MANAGER_PASSWORD=secret | |||
CAS1_E2E_LEGACY_MANAGER_PASSWORD=secret | |||
CAS1_E2E_LEGACY_MANAGER_USERNAME=JIMSNOWLDAP |
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.
thks
|
||
expect(response.render).toHaveBeenCalledWith( | ||
'v2Manage/outOfServiceBeds/update', | ||
expect.objectContaining({ | ||
premisesId: request.params.premisesId, | ||
bedId: request.params.bedId, | ||
id: request.params.id, | ||
}), |
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.
another way to approach this would be to think of the update as a fresh resource rather than an additional action on an existing resource, e.g. with a url scheme like:
GET manage/out-of-service-beds/{outOfServiceBedId}/update/new
POST manage/out-of-service-beds/{outOfServiceBedId}/update
which services an OutOfServiceBedsUpdateController
I'm not sure how much of the deeply nested url information is necessary?
Currently we have manage/premises/{premisesId}/beds/{bedId}/out-of-service-beds/{outOfServiceBedId}/update
With the OOSB id we will have access to the IDs and names of the bed, room and premises:
"bed": {
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "string"
},
"room": {
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "string"
},
"premises": {
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "string"
},
see the Swagger docs
const { premisesId, bedId, id } = req.params | ||
|
||
const outOfServiceBedReasons = await this.outOfServiceBedService.getOutOfServiceBedReasons(req.user.token) | ||
const outOfServiceBed = await this.outOfServiceBedService.getOutOfServiceBed(req.user.token, premisesId, id) | ||
|
||
res.render('v2Manage/outOfServiceBeds/update', { | ||
pageHeading: 'updateOutOfServiceBedsController', | ||
premisesId, | ||
bedId, |
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 think bedId
is probably dangerous here? That outOfServiceBedId
is going to be more helpful, even though more verbose?
server/paths/manage.ts
Outdated
update: outOfServiceBedPath.path('/update'), | ||
cancel: singlePremisesPath.path('out-of-service-beds').path(':id').path('cancellations'), | ||
}, |
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 wondering whether more smaller things might be easier to manage? See my later question about whether an entirely new "resource" might be clearer? e.g. something like:
const outOfServiceBedsUpdatesPath = outOfServiceBedsIndexPath.path(':outOfServiceBedId')
// Path<"/manage/out-of-service-beds/:outOfServiceBedId">
outOfServiceBedUpdates: {
new: outOfServiceBedsUpdatesPath.path('new'),
create: outOfServiceBedsUpdatesPath,
},
@@ -30,7 +30,7 @@ | |||
items: [ | |||
{ | |||
text: "Update record", | |||
href: paths.v2Manage.outOfServiceBeds.update({premisesId: premisesId, id: id}) | |||
href: paths.v2Manage.outOfServiceBeds.update({premisesId: premisesId, id: id, bedId: bedId}) |
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.
Probably I'm missing something but I think we want to be using the OutOfServiceBed ID here rather than the Bed ID? When we're making a new OOSB then clearly the Bed is a key component, but when we are creating an OOSBUpdate, we are concerned with the OOSB ID and the bed id is no longer important?
shouldShowOutOfServiceBedDetails(bedDetails: OutOfServiceBed | OutOfServiceBedRevision) { | ||
if (bedDetails.startDate) { |
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.
Again I wonder if we should be a bit stricter with our terminology to avoid future confusion when reading this: i.e. this variable is more correctly an outOfServiceBedDetails
isn't it?
updatePage.shouldShowOutOfServiceBedDetails(outOfServiceBed) | ||
updatePage.formShouldBePrepopulated() |
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.
very nice!
@@ -71,6 +71,10 @@ export class OutOfServiceBedShowPage extends Page { | |||
}) | |||
} | |||
|
|||
shouldShowUpdateConfirmationMessage() { | |||
this.shouldShowBanner('The out of service bed has been updated') |
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 see this matches what we have in the 'create' action: https://github.com/ministryofjustice/hmpps-approved-premises-ui/blob/main/server/controllers/v2Manage/outOfServiceBedsController.test.ts#L95-L125
To my mind this does read better than "The out of service bed record has been updated" but we can see what others think...
paths.v2Manage.outOfServiceBeds.show({ | ||
premisesId, | ||
bedId: outOfServiceBed.bed.id, | ||
id: outOfServiceBed.id, | ||
tab: 'timeline', |
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.
👍
pageHeading is the name of the variable in the view
We will soon use this is multiple places so we should add a constant to reduce duplication
Previously we didn't use the update OoS bed path in v2Manage so the path wasn't updated. But now we need it to work.
This was copied over when the lost beds controller was. For new development, given the size of the out of service beds controller, I think it's best we start a new controller for the updating of OoS beds so these methods can be removed
We will need this on multiple Pages soon so to remove duplication I have extracted this method to the top level Page class. There's a lot of methods on the Page class and it would make things clearer if we used more inheritance, but this is out of scope for now.
We are using this same style of heading in multiple places so it makes sense to keep it DRY. Especially as we may soon link to the premises/bed from this heading.
There is a lot of boiler plate here but we are essentially adding a new controller that renders the form that allows the bed to be updated. We also add a test to verify that it loads
When the form loads initially we want to show the existing data in the fields for the user to edit and update rather than have to start from fresh
742f091
to
5d281d0
Compare
Now we allow the form to be submitted and the updated bed to be submitted to the API.
We need to handle errors provided by the API so that we show them in the UI
Before this change if the API threw an error when the page was loaded the inputs of the form would be populated with the data from the OoS bed not the erroneously inputted data. We want to show the erroneous data so the user can see where they've gone wrong and correct their mistake. I'm not happy with the amount of casting I've had to do here but time doesn't allow for type assertions currently.
5d281d0
to
300b5cd
Compare
Context
Users need to be able to update an Out of service bed record with revisions.
Jira
Changes in this PR
Screenshots of UI changes
Mock
Development