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

[DNM] Edit multiple measures #724

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

eadpearce
Copy link
Contributor

TP-2000-553: Edit multiple measures

Why

  • Users want to be able to edit many measures at a time with the same data e.g. end dates

What

  • Measures in the measures list page are selectable and can be edited by clicking the Edit measures button
  • Reuses code from the measure create wizard and the current measure edit page to allow edits of multiple measures in a multi-step form
  • Steps displayed in the form depends on which are checked in the first step

Checklist

  • Requires migrations? ❌
  • Requires dependency updates? ❌

Screenshot 2022-11-15 at 14 52 40

Screenshot 2022-11-15 at 14 51 43

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2022

Codecov Report

Base: 93.52% // Head: 93.50% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (6042d51) compared to base (a012b66).
Patch coverage: 92.85% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #724      +/-   ##
==========================================
- Coverage   93.52%   93.50%   -0.02%     
==========================================
  Files         345      349       +4     
  Lines       23095    23366     +271     
  Branches     1787     1819      +32     
==========================================
+ Hits        21600    21849     +249     
- Misses       1160     1177      +17     
- Partials      335      340       +5     
Impacted Files Coverage Δ
common/session_store.py 85.18% <ø> (ø)
measures/forms.py 95.29% <81.48%> (-2.80%) ⬇️
measures/views.py 95.48% <91.75%> (-2.01%) ⬇️
measures/helpers.py 96.42% <96.42%> (ø)
measures/conditions.py 100.00% <100.00%> (ø)
measures/constants.py 100.00% <100.00%> (ø)
measures/tests/test_forms.py 100.00% <100.00%> (ø)
measures/tests/test_helpers.py 100.00% <100.00%> (ø)
measures/tests/test_views.py 100.00% <100.00%> (ø)
measures/urls.py 100.00% <100.00%> (ø)
... and 3 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

return constants.CONDITIONS in cleaned_data.get("fields_to_edit")


def show_step_footnotes(wizard):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could these be refactored into one generic method?

Copy link
Contributor

Choose a reason for hiding this comment

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

After refactoring it might be worth considering whether these belong in their own file or whether they should sit on/above a class somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree it'd be nice to be able to parametrise these with the different step names but due to how formtools is expecting them to be passed to the view (as a dictionary in urls.py) I don't think this is an easy fix. Maybe a future tech debt ticket?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yeah that's a bit awkward. I feel like there's a way to do it with lambdas, but might be worth creating ticket, as you say

from measures.util import diff_components


def update_measure(instance, transaction, current_workbasket, cleaned_data, defaults):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if these methods should live on a class, perhaps a MeasureUpdatePattern or MeasureEditPattern, in patterns.py. I think they're all part of a similar process

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that would be good. I'll see if I can get that done before I go on leave at the end of the week

@eadpearce eadpearce force-pushed the TP2000-553-edit-multiple-measures branch from 7ad54e3 to 6042d51 Compare November 30, 2022 11:23
]
conditions_data = cleaned_data.get("formset-conditions", [])
for condition in conditions_data:
condition["update_type"] = UpdateType.CREATE
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens when we want to update existing conditions on the measure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This form currently only supports adding additional conditions.

Copy link

Choose a reason for hiding this comment

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

I've been thinking about this as a separate ticket - and we need to support editing/removing geo area exclusions - I wonder if a small interim addition would be a "Remove" button to remove Geo Areas and Measure Conditions for now. And then (in the same form) to re-enter the correct information

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that the ability to add additional conditions is useful without the ability to remove or reorder the existing ones

@eadpearce eadpearce changed the title Edit multiple measures [DNM] Edit multiple measures Dec 5, 2022
"component_measure",
)

return instance.new_version(current_workbasket)
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to pass the the fields you want to update to this method. i.e. instance.new_version(current_workbasket, **cleaned_data)

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll see:
TypeError: Measure() got an unexpected keyword argument 'fields_to_edit'
and then I imagine it will complain about M2M fields like conditions and duties, so you'll need to find a way to filter those out before passing the dict

# 1 condition
# 1 footnote
assert workbasket.tracked_models.count() == 6

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 test is already long, but it would be good if you could loop over both measures and make assertions about individual fields (e.g. valid_between.upper)

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.

5 participants