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/stepper refinement #700

Open
wants to merge 29 commits into
base: major/4
Choose a base branch
from
Open

Conversation

EdoStorm96
Copy link
Contributor

@EdoStorm96 EdoStorm96 commented Sep 12, 2024

So I went a bit ham ... I think I've made some nice improvements to the stepper. It seems to work well, but I'm curious to hear your thoughts, @miggol.

I am now a lot more intimate with the new stepper, and also more appreciative of its utility. Kudos again :)

So, what I've done:

  • Firstly, I did get rid of the stepper for the first form page. This allowed me to simplify quite a bit, because the stepper is always working with a proposal of which the type is known. This is chill imo.
  • I've implemented the flows for the different proposal type (PreAss and PreAppr, as I refer to them.)
  • I've messed a lot with the WMOChecker ...:
    • Firstly I noticed that the WmoApplicationForm (different from WMOUpdate and such) was not implemented in the stepper, so I've incorporated that. (fixes Add stepper bubble for wmo application #699)
    • I've also done some work on the Wmo views and forms themselves, as I found some incorrect urls ...
    • I also figured I could make the WmoChecker into a ModelFormChecker, to also get rid of the WmoItem. This was quite the hassle ... I initially wanted to use an CreateOrUpdateChecker, but this did not quite work, so I took inspiration and made it into its own design. This seems to work fine now. However, I do think we need to look into the clean()'s of WMO related forms as these seem kindoff incomplete ...
  • So then the big one, I've overhauled the validation. (fixes Collect errors from stepper for Proposal validation #693) This was pretty simple luckily! A few bumps on the road:
    • many forms need form kwargs, so the ModelFormChecker now has a get_form_kwargs() method.
    • Then the other big thing: as individual sessions and tasks are not incorporated into the stepper (which I still think is good) these needed their own validation function. This is somewhat akin to the old validation system, but quite a lot simpler. I don't hate it.
    • To my great frustration, StudyDesignForm does not get clean()'ed during validation. #691 still persists. I don't know 😭 ....
  • Lastly I've made some simple implementations to get the correct css classes (incomplete, complete and disabled) This works ... but I feel like there might still be some bugs ... I think having this, mostly just really showcases inconsistencies/messiness in form's individual validation ... So it would be good to have a look at that ... (fixes More stepper styling #694, Collect errors from stepper for Proposal validation #693)

Sorry for the big PR ... One thing led to another and such. But overall I think this has improved the stepper quite a bit!

Copy link
Contributor

@miggol miggol left a comment

Choose a reason for hiding this comment

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

You got a lot done with this PR! We still need to double check that all stepper items actually add errors, for example the "Financing" modelform, but that is more of an issue with the forms.

Also, this smaller part of #692 is not addressed:

  • Remove the <a /> tags from disabled stepper items

@@ -7,6 +7,14 @@
{% trans "Algemene informatie over de aanvraag" %} - {{ block.super }}
{% endblock %}

{% block stepper %}
{% if create %}
Copy link
Contributor

Choose a reason for hiding this comment

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

A simple if stepper would be better IMO.

@@ -129,6 +129,14 @@ def is_current(self, request):
"""
return False

def css_classes(self):
css_classes = super().css_classes()
if self.children[0].get_errors():
Copy link
Contributor

@miggol miggol Sep 16, 2024

Choose a reason for hiding this comment

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

This only checks the first child for errors:

image

Because this trajectory still has some errors in it, I think it would make more sense to do something like:

child_errors = []
for child in self.children:
    child_errors += child.get_errors()
    if child_errors != []:
        css_classes += "incomplete"
        break

So that the parent still turns yellow in this case.

But we could also ask the secretary for a preference. Because the parents are forms themselves it might make sense to only have them turn yellow for children if they're collapsed i.e. their children are hidden.

{
"url": reverse("tasks:session_end", args=[session.pk]),
"page_name": _("{}: sessie {} overzicht").format(
study.name,
Copy link
Contributor

Choose a reason for hiding this comment

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

In the case that a proposal only has one trajectory, there is no study name.

if hasattr(item, "form_class") and item.form_class == SessionOverviewForm:
troublesome_pages.extend(validate_sessions_tasks(item.study))
if item.get_errors():
if item.parent and item.parent.title in study_titles:
Copy link
Contributor

Choose a reason for hiding this comment

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

If you try really hard and call your trajectory something like "Basisgegevens" you can get this if-statement to go down the wrong path, lol.

),
None,
)
def validate_sessions_tasks(study):
Copy link
Contributor

@miggol miggol Sep 16, 2024

Choose a reason for hiding this comment

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

I would really really prefer if we could somehow have this be part of the stepper/checker infrastructure, so that all we had to do was run a stepper.get_all_errors() to get list of errors with titles and URLs.

For example, calling this code from the SessionsChecker. Or otherwise a ModelFormItem for each of the task pages that is hidden but does collect errors.

That would keep everything in one place and allow us to turn the Sessions item yellow if its subpages had errors.

@EdoStorm96
Copy link
Contributor Author

Ok, So I've adressed your comments ... I guess this is fine for now, although I don´t love some aspects of the current design ... Mainly the validation of sessions and tasks ;p A small overview of what I've done:

  • ensure disabled items are no longer elements
  • ensure ContainerItems check all their children and represented errors thusly.
  • Mostly removed ContainerItems from the stepper, so that all major steps represent modelforms and the modelform's errors. ContainerItems are now only used for studies, when there are multiple studies.
  • This also led to some slight reordering. It used to be:
    • StudyEnd > TranslatedForms > Documents > DMP
      But now it's:
    • StudyEnd > Documents > TranslatedForms > DMP
  • Improved the working of validation and (mostly ...) moved it inside of the stepper. I have mixed feelings about this, as this also leads to a lot more imports on stepper.py. But maybe you have suggestions for improvements of Stepper.get_form_errors() ... I did ensure all the problems with validation you pointed out are fixed ... But this also made the design a bit more complicated.
  • I've added a possibility of providing a get_checker_errors function to ModelFormItem's in case we need to provide some more specific validation. I've implemented this on SessionsChecker, as an example.
  • And we're (for now) still stuck with this custom validator function for sessions and tasks ... Which gets called everytime the stepper gets rendered, just to give the Sessions stepper item the right color ... 💀

IMO this is fine for now though. Curious to hear your thoughts 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants