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

Inherit from hmpo-date-controller #39

Closed
wants to merge 1 commit into from

Conversation

daniel-ac-martin
Copy link
Contributor

Changes the base controller to inherit from the new hmpo-date-controller
module instead of hmpo-form-wizard's controller.

This provides the base controller with support for dates input via
hmpo-template-mixin's 'input-date' mixin. Thus making the
date-controller redundant.

We should consider removing the date controller in a future release.

Note: As a part of reviewing this PR people should probably review
hmpo-date-controller itself. (Though I'm not sure how best we can do
that. - Suggestions?)

Changes the base controller to inherit from the new hmpo-date-controller
module instead of hmpo-form-wizard's controller.

This provides the base controller with support for dates input via
hmpo-template-mixin's 'input-date' mixin. Thus making the
date-controller redundant.

We should consider removing the date controller in a future release.
@easternbloc
Copy link
Collaborator

easternbloc commented May 9, 2016

💃 💃 LGTM 💃 💃

one point however, should we be es6ing all future things now that we've bumped to hof7 ?

@daniel-ac-martin
Copy link
Contributor Author

My hope is that hmpo-date-controller will be merged into hmpo-form-controller at some point so it shouldn't be written in ES6 unless hmpo-form-controller is converted to ES6.

@easternbloc
Copy link
Collaborator

Fair.

@easternbloc
Copy link
Collaborator

I'm happy with this could @JoeChapman or @joefitter please give this look 👓 👀

@daniel-ac-martin
Copy link
Contributor Author

See also: UKHomeOffice/passports-date-controller#1

And any other issues that get raised on the repo in case they are things that people decide should be addressed prior to use in HOF.

@daniel-ac-martin
Copy link
Contributor Author

UKHomeOffice/passports-date-controller#3 should address the only open issue on the new repo.
Is that the only barrier to this going in?

var util = require('util');
var _ = require('lodash');

// In HOF we are more lenient with date inputs than in vanilla
// hmpo-form-wizard and so must override some validators
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 remove the comments 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.

Happy to remove if others agree. My rationale was that it's a strange thing to do and so needed some explanation.

@JoeChapman
Copy link
Contributor

I'm not sure how I feel about extending base-controller from a date controller. It feels a bit backwards.

@JoeChapman
Copy link
Contributor

Does this also change the way one would configure their fields for a date?

@easternbloc
Copy link
Collaborator

I'm not sure how I feel about extending base-controller from a date controller. It feels a bit backwards.

It'd be the hof base controller vs the hmpo-date-controller though to it's not tooo bad.

@daniel-ac-martin
Copy link
Contributor Author

daniel-ac-martin commented May 11, 2016

The idea is that this stuff should really be supported out of the box. I'd like to get this functionality in the hmpo-form-controller if I can convince @gavboulton that this module is solid. i.e. "Date controllers" should never have been a thing.

@JoeChapman Yes is changes that. (i.e. Simplifies it.) It is explained in the README for the new repo.

@JoeChapman
Copy link
Contributor

It'd be the hof base controller vs the hmpo-date-controller though to it's not tooo bad.

Could hmpo-date-controller not be mixed into hmpo-form-controller, as opposed to extending from it? Otherwise we end up with a long chain of classes, where the functionality becomes broader, but the nomenclature becomes more and more specific, which doesn't suit the current architecture, i.e., HOF extends from HMPO.

@daniel-ac-martin
Copy link
Contributor Author

daniel-ac-martin commented May 11, 2016

I considered calling it "hmpo-date-base-controller" but it felt ugly. - Naming things is hard.

Re: Why is it a separate module, see HMPO/hmpo-form-wizard#35

@JoeChapman
Copy link
Contributor

Yeah, I think a separate module is a good idea, but I still wonder if it might be better if HMPO form controller require'd HMPO date controller and mix(ed)in it's functionality. That way, HOF-base controller could treat HMPO form/date controllers as the same entity, without concern for what particular class extends which class.

I considered calling it "hmpo-date-base-controller" but it felt ugly. - Naming things is hard.

^ yeah, agreed, a bit ugly, but although they are separate entities, I don't think they should be thought of as such by HOF.

@JoeChapman
Copy link
Contributor

@daniel-ac-martin the read me in HMPO date controller shows how include a date field in a step definition, but is the way a date field is composed different to how it once was, I thought it too was changing?
Also, a little pedantic, but if developers using HOF are never supposed to need to visit HMPO date controller how will they know about the new documentation? Can there be an update to the documentation in HOF and to the example form?

@daniel-ac-martin
Copy link
Contributor Author

I thought it too was changing?

Are we changing the input-date mixin then? Do you have a link to the PR?

As long as we pin to compatible versions of hmpo-date-controller and hmpo-template-mixins we should be fine.

@JoeChapman
Copy link
Contributor

JoeChapman commented May 11, 2016

@daniel-ac-martin

Are we changing the input-date mixin then? Do you have a link to the PR?

Not necessarily, however, I thought we might. Are date fields configuration unchanged?

@joefitter
Copy link
Contributor

@daniel-ac-martin @easternbloc @JoeChapman Just having another look at this PR - this does feel like a very strange way of doing things, I don't think our HOF base controller should extend a date-controller, very few of our steps actually require date functionality, and the ones that do use the HOF date controller.

I would suggest leaving the base controller to extend form-wizard controller as it currently does, and mixin the date functionality to the hof date controller.

We would end up with something like:

>----------------------------------------Linear Extension-------------------------------------------->
hmpo-form-controller --> hmpo-form-wizard/controller --> hof-controllers/base --> hof-controllers/date
                                                     \_> hmpo-date-controller -------------| mixin


@JoeChapman
Copy link
Contributor

I tend to agree. Ideally, hmpo-date-controller would be a part of hmpo-form-controller/hmpo-wizard(-)controller and would just be included for free, as per @daniel-ac-martin 's earlier comment. However, if that can't be done, I would ask that we mix in the date functionality or replace the hof-date-controller with the hmpo-date-controller. I.e, hmpo-date-controller extends hof-base-controller, as we currently do with hof-controller.

@daniel-ac-martin
Copy link
Contributor Author

@joefitter, @JoeChapman:The argument to eventually get the functionality into hmpo-form-controller is that this functionality should be provided out of the box. i.e. "Date controllers" should not be a thing!

If we retain HOF's date-controller we will be making the opposite argument.

Also, whilst we would be providing a better date controller that neither requires the programmer to extend it nor to provide it with the date component fields in the options / step definition, we would still be requiring the programmer to think about whether or not they need date functionality in a particular step. I would argue that is a small 'gotcha'. The 'input-date' mixin should just work.

@daniel-ac-martin
Copy link
Contributor Author

Another important issue is this: UKHomeOffice/passports-date-controller#4

@joefitter
Copy link
Contributor

@daniel-ac-martin @JoeChapman OK I have changed my view on this slightly from looking more at what this controller is actually achieving. IMO this logic should be tied to the input-date mixin. I think we should stop thinking of things as separate controller, separate view etc, but instead be packaging up fully functional components. I believe these should live within hof as a set of components, each one with their repo etc.

This example would be hof-component-date or similar, and contain the rendering logic (3 inputs, all meta etc), as well as the process logic to save the processed date to the model. The developer would simply use the input-date mixin and all the boilerplate including error messages etc would be hidden, much like they are for input-text etc. I would suggest these would be a superset of template mixins, with any hof components taking precedence.

@easternbloc
Copy link
Collaborator

@daniel-ac-martin @JoeChapman OK I have changed my view on this slightly from looking more at what this controller is actually achieving. IMO this logic should be tied to the input-date mixin. I think we should stop thinking of things as separate controller, separate view etc, but instead be packaging up fully functional components. I believe these should live within hof as a set of components, each one with their repo etc.

Feels like a nice idea to me. Moving into a more composable state seems like a more scalable approach. 👍

@daniel-ac-martin
Copy link
Contributor Author

After further thought I would like to reinforce my last comment to say that this PR should not be merged until UKHomeOffice/passports-date-controller#4 is addressed, as it makes it possible for a malicious user to break the form until the instance is restarted.

As for how we structure the modules (see the last two comments) I think that work should be done at a later date and should not block this going in. (Once the issue I mentioned is properly addressed of course!)

@JoeChapman
Copy link
Contributor

@daniel-ac-martin

As for how we structure the modules (see the last two comments) I think that work should be done at a later date and should not block this going in. (Once the issue I mentioned is properly addressed of course!)

If we are going to address components at a later date, then why is it better that this controller goes in at this point and not at a hof-controller level?

@joefitter
Copy link
Contributor

joefitter commented Jun 3, 2016

@JoeChapman @daniel-ac-martin I agree that having something called "date-controller" and our "base-controller" extending from it is not the way to go, it just seems wrong. We have a date-controller which extends base-controller in this lib and we use this for steps which include a date - can't we apply your fix/change here? If we apply it further up the architecture, and extend base controller from it, then doesn't that defy the point of us having a hof-controllerS lib, it would just be a controller that inherits everything, including confirm page and any other functionality - aka a framework

@JoeChapman
Copy link
Contributor

While we wait to implement a "component" like architecture, please can the date-controller be worked into the HOF-controllers?

@daniel-ac-martin
Copy link
Contributor Author

Sounds like we can now get this functionality into the form-controller itself.
So let's do that.

@gavboulton
Copy link

@daniel-ac-martin I thought you were just talking about the template mixins?

@JoeChapman
Copy link
Contributor

@daniel-ac-martin I'm still not convinced the date functionality should be core to the form controller. IMHumbleO, the date functionality is a feature, not an explicit requirement of any form request handler and should therefore be an opt in feature. Just my two cents, anyone else, @easternbloc @gavboulton @joefitter

@joefitter
Copy link
Contributor

joefitter commented Jun 17, 2016

The functionality is for formatting/validating dates so we wouldn't be able to handle it just in template mixins. Ideally we would package it up into a component, but in the meantime can't we use the date-controller in hof-controllers?

@daniel-ac-martin
Copy link
Contributor Author

@gavboulton: No I mean support for processing the data that comes from someone filling in input-date mixin from template mixins.

@joefitter
Copy link
Contributor

@JoeChapman If we are offering an input-date mixin in template mixins, then we should have some kind of processing at that level, in hmpo-form-controller or wizard controller, to handle the new mixin so I agree with @daniel-ac-martin about this part. But saying that I don't think the input-date mixin should be part of template-mixins at all for the reasons you highlighted above.

In the interim I have no problem using the hof date controller, but I really think we shouldn't have to use a custom controller just for a date - it should be handled by the component itself. But not mixed in to every controller.

@daniel-ac-martin
Copy link
Contributor Author

daniel-ac-martin commented Jun 17, 2016

@joefitter: Just wanted to point out that the mixin isn't new. It's been there ages without any support for actually processing it. IMO it's basically a massive 'gotcha' for any dev new to this stack.

Regarding components, I have a few ideas. One is to have a new concept to sit alongside formatters and validators probably called 'processors' (unless someone can think of a better name). These would have the power to amalgamate request body parameters prior to being validated. (Which is basically how my current implementation works.)

The other idea, which is a long shot, would be to change the input-date mixin itself. That might mean that we don't need any of this and instead can do everything with a validator. I need to experiment to see whether this is feasible.

@joefitter
Copy link
Contributor

I know and I agree, the input-date mixin is not useful out of the box, and that is why I think it should be removed.

To replace it we would have an input-date component which would consist of a template mixin, processing/formatting/validation packaged within a middleware which then hands off the formatted input-date field to the standard controller

@joefitter
Copy link
Contributor

we are going to have a bunch more of these - postcode-lookup, file upload etc etc, if the processing/validation etc for all of these is added to the base controller it will get unmaintainable very quickly, which is why we were looking at components

@daniel-ac-martin
Copy link
Contributor Author

@joefitter: I agree. In the meantime though, I think we should get input-date working in the base packages and take it out when we are ready to change the architecture.

It's better to have a complete implementation in there that can be taken out as one, rather than an incomplete one. (The form controller already has validators that look like they are designed for input-date.)

@JoeChapman
Copy link
Contributor

@daniel-ac-martin @joefitter I agree with Dan's last point. It needs to work. We don't have the capacity to build components immediately. So long as this is chalked up as tech debt in the appropriate repos and we continue to work at a solution when we have the appropriate resource, which is soon.

@joefitter
Copy link
Contributor

@gavboulton @JoeChapman @easternbloc how do you feel about this? I guess its up to the HMPO guys whether or not they want this merged into the base controller. Also if it is working now is there any sense on changing it for an imperfect solution? Why don't we carry on as we have been until a better solution can be worked on?

@JoeChapman
Copy link
Contributor

Also if it is working now is there any sense on changing it for an imperfect solution? Why don't we carry on as we have been until a better solution can be worked on?

Is it working?

@joefitter
Copy link
Contributor

We use hof date controller in GRO which works fine

@daniel-ac-martin
Copy link
Contributor Author

No. The solution is incomplete. We are missing the bit that takes the data in req.body and gets it through to the validators.

@JoeChapman
Copy link
Contributor

@daniel-ac-martin that sounds straight-forward, is it? If so, could it be transplanted into hof date controller instead?

@daniel-ac-martin
Copy link
Contributor Author

Yes you can use a special controller, but that seems crazy to me just for date support.

Also some forms will need to run using their own custom controller on all steps. How are they supposed to handle dates? Should they maintain two custom controllers, identical but with one inheriting from HOF's date controller instead of HOF's base controller.

@daniel-ac-martin
Copy link
Contributor Author

@JoeChapman It could go into HOF's special date controller but you've lost a lot of the benefit in doing so.

@daniel-ac-martin
Copy link
Contributor Author

My preference would be the hmpo-form-controller, followed by hmpo-form-wizard's controller, followed by HOF's base controller followed by poking my eyes out with a blunt fork, followed by HOF's date controller.

@joefitter
Copy link
Contributor

To solve the problem of having a custom controller that needs both date and some other functionality, why don't we look at mixing in functionality rather than linear extension, in the interim anyway

@JoeChapman
Copy link
Contributor

Better because it fixes date controller, and there isn't a "direct" inheritance from date to hof base

My preference would be the hmpo-form-controller, followed by hmpo-form-wizard's controller, followed by HOF's base controller followed by poking my eyes out with a blunt fork, followed by HOF's date controller.

I like because we remove the linear inheritance. But how do we accomplish this, without engineering ths shit out of it?

To solve the problem of having a custom controller that needs both date and some other functionality, why don't we look at mixing in functionality rather than linear extension, in the interim anyway

We need to be pragmattic. I'm trying hard to understand both arguments. I want the date controller stuff fixed. @joe hof date-controller validators don't work properly, we need this code, but whether that code should be designated at the level we are proposing is my concern.

In conclusion, I will accept the proposition, but then I believe we should prioritise a component based architecture. But I don't want that to be an ad-hoc process. We need a discussion around the architecture so we don't end up in a mess pushing pr's based on a single opinion. Let's get concensus first

@daniel-ac-martin
Copy link
Contributor Author

I didn't think that HOF's date controller was particularly broken. Just that it was an ugly solution?

(Mind you I don't think it can handle more than one date per page.)

@easternbloc
Copy link
Collaborator

@daniel-ac-martin it's got bugs though. Leaps being one example.

@daniel-ac-martin
Copy link
Contributor Author

@easternbloc: Ah okay. It needs to die even more than I thought then.

@daniel-ac-martin
Copy link
Contributor Author

daniel-ac-martin commented Jun 17, 2016

Well I'm going to revamp this code at some point and either update this gigantic PR or close it and start a new one.

In the meantime you guys can have a think about whether you want to persist in the insanity that is the date controller or not. (But the idea of it living there is pretty demotivating to be honest.) And if you do I reserve the right to make fun of both you and HOF to anyone who will listen.

"HOF? Oh yeah, that thing that can't even handle dates unless you jump though some hoops and whisper some magical incantations. I remember that."

;-)

Seriously though there is a chance we can avoid all this stuff anyway. I need to have a play.

@JoeChapman
Copy link
Contributor

And we get to tell people you wanted HOF base controller to inherit from date controller

@joefitter
Copy link
Contributor

I wasn't aware it was broken, it works in our use case.

If we are offering an input-date mixin in template mixins, then we should have some kind of processing at that level, in hmpo-form-controller or wizard controller, to handle the new mixin so I agree with @daniel-ac-martin about this part.

As I mentioned earlier this solution would make the most sense based on templateMixins providing an input-date mixin - guess its up to @gavboulton and co if they are happy for it to live there

@lennym lennym closed this Feb 16, 2017
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.

6 participants