-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature/as 1157 spocs and inspectors #70
Conversation
pages/common/helpers/index.js
Outdated
@@ -0,0 +1,10 @@ | |||
const getInspectors = req => | |||
req.api(`/search/profiles`) |
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 should have a specific endpoint created to get the list of ASRU users. Using search will either only return a subset of the data (because paginated) or return all the data, which is worse (because 27,000 people in prod)
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.
done.
pages/inspectors/index.js
Outdated
return res.redirect(req.buildRoute('establishment.dashboard', { establishmentId: req.establishment.id })); | ||
// return res.redirect(req.buildRoute('dashboard')); | ||
}) | ||
.catch(next); |
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.
These two endpoints (post('/')
and post('/delete')
) are basically identical except the API method. I'd extract them into a single parameterised function.
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.
We have an extra parameter we get from the request, which makes this extraction very difficult.
05026db
to
226e846
Compare
pages/asru/index.js
Outdated
...settings | ||
}); | ||
|
||
app.use(bodyParser.urlencoded({ extended: true })); |
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 form router attached the bodyParser middleware on POST - do we need it here too? Also the form uses extended: false
to allow string/array values - is there a reason it is true here?
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.
removed it.
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.
actually, it does not seem to be case ... I mean , I can see the attachment in https://github.com/UKHomeOffice/asl-pages/blob/e676092c4a6f01dc48ad63e534ecd06e5f9c2f6d/pages/common/routers/form.js#L172 , but if I remove app.use(bodyParser.urlencoded({ extended: false })); parameters are not found in req.body ...
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.
aah - that's because we are parsing the body on POST /
but not POST /delete
. In that case I would add the middleware in the post handler that needs it -
app.post('/delete', bodyParser.urlencoded({ extended: false }), (req, res, next) => {
// your code
})
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.
TBH, I'd probably move body-parsing to a global level. There's basically never going to be a context in which we're doing a POST and don't want to parse the body.
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.
done
pages/asru/views/index.jsx
Outdated
<Fragment> | ||
{ | ||
asru.map(profile => ( | ||
<p key={`${profile.id}`}>{profile.firstName} {profile.lastName} |
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.
key={profile.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.
done
pages/asru/views/index.jsx
Outdated
{ | ||
asru.map(profile => ( | ||
<p key={`${profile.id}`}>{profile.firstName} {profile.lastName} | ||
<form method='POST' action={`${baseUrl}/delete`}> |
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.
pretty sure you can't have a form
as a child of a p
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.
in Fragment ?
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 don't need to wrap it in anything if its single element - just return the <form>
. You might need to add display: block
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 <p>
is still necessary for structural reasons.
You need to reorder the tags so that the <form>
wraps the <p>
. Otherwise React will throw an error when run in production mode.
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.
done
pages/search/views/index.jsx
Outdated
@@ -25,7 +25,7 @@ const formatters = { | |||
return establishments.map((establishment, i) => [ | |||
// separate links with line breaks #hack |
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 know this isn't part of this PR but.... 🤢
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.
done
7f9b06d
to
b4e0453
Compare
Can you rename the page to something more specific than
|
p => p.asruInspector | ||
) : res.locals.static.asru = req.establishment.asru.filter( | ||
p => p.asruLicensing | ||
); |
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 you use an if
statement here please? Ternaries for "not assignment" break my brain.
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.
done
lib/urls.js
Outdated
read: '/establishments/:establishmentId/details', | ||
asru: '/establishments/:establishmentId/asru/:asruUser', | ||
inspectors: '/establishments/:establishmentId/asru/inspectors', | ||
spocs: '/establishments/:establishmentId/asru/spocs' |
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.
We seem to have the same URL defined 3 times here. If we're mounting onto the parameterised URL then any link builders should use the parameterised version, with the parameter defined.
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.
done
}) | ||
.then(() => next()) | ||
.catch(next); | ||
} |
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.
As above. Use an if
statement unless doing assignment please.
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.
done
This is failing for reasons that seem to be outside of the scope of this PR, so I am going to merge and then attempt to fix the memory usage issues in Drone. |
Please do not merge this, I am getting Error: There is an existing open task for this record on delete ( yes, this comes from the resolver) and I need to reuse this functionality for PoCs