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

Feature/as 1157 spocs and inspectors #70

Merged
merged 8 commits into from
Apr 9, 2019

Conversation

lvnhmd
Copy link
Contributor

@lvnhmd lvnhmd commented Apr 3, 2019

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

@@ -0,0 +1,10 @@
const getInspectors = req =>
req.api(`/search/profiles`)
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

return res.redirect(req.buildRoute('establishment.dashboard', { establishmentId: req.establishment.id }));
// return res.redirect(req.buildRoute('dashboard'));
})
.catch(next);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@lvnhmd lvnhmd force-pushed the feature/AS-1157-SPoC-and-Inspectors branch from 05026db to 226e846 Compare April 5, 2019 11:34
...settings
});

app.use(bodyParser.urlencoded({ extended: true }));
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed it.

Copy link
Contributor Author

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 ...

Copy link
Contributor

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
})

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

<Fragment>
{
asru.map(profile => (
<p key={`${profile.id}`}>{profile.firstName} {profile.lastName}
Copy link
Contributor

Choose a reason for hiding this comment

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

key={profile.id}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

{
asru.map(profile => (
<p key={`${profile.id}`}>{profile.firstName} {profile.lastName}
<form method='POST' action={`${baseUrl}/delete`}>
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in Fragment ?

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -25,7 +25,7 @@ const formatters = {
return establishments.map((establishment, i) => [
// separate links with line breaks #hack
Copy link
Contributor

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.... 🤢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@lvnhmd lvnhmd force-pushed the feature/AS-1157-SPoC-and-Inspectors branch from 7f9b06d to b4e0453 Compare April 8, 2019 10:01
@lennym
Copy link
Contributor

lennym commented Apr 8, 2019

Can you rename the page to something more specific than asru please? It's really quite ambiguous.

asru-assignment perhaps?

@lvnhmd lvnhmd changed the title *WIP* Feature/as 1157 s po c and inspectors Feature/as 1157 s po c and inspectors Apr 8, 2019
@lvnhmd lvnhmd changed the title Feature/as 1157 s po c and inspectors Feature/as 1157 spocs and inspectors Apr 8, 2019
p => p.asruInspector
) : res.locals.static.asru = req.establishment.asru.filter(
p => p.asruLicensing
);
Copy link
Contributor

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.

Copy link
Contributor Author

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'
Copy link
Contributor

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.

Copy link
Contributor Author

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);
}
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@lennym
Copy link
Contributor

lennym commented Apr 9, 2019

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.

@lennym lennym merged commit ee9cd9d into master Apr 9, 2019
@wheelsandcogs wheelsandcogs deleted the feature/AS-1157-SPoC-and-Inspectors branch August 8, 2022 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants