Skip to content

Conversation

EinLama
Copy link
Contributor

@EinLama EinLama commented Oct 2, 2025

Ticket

https://community.openproject.org/wp/64524

Important

This branch is based on #20454. Either merge that one first - or merge this branch into it instead of dev.

What are you trying to accomplish?

When the score of a scored list is changed within the administration, all Calculated Values that are using the scored list should be recalculated.

  • Recalculate when item score is updated in the administration
  • Recalculate when an hierarchy item is deleted in the administration

Notes

In case I have to take my parental leave in the near future, here are some notes on the current state of this PR:

  • The general workflow of updating a score and seeing the recalculation happening works.
  • The same goes for deleting an item from a scored list.
    • There was a "visual bug" here where we would render a "not found" message that did not make much sense on the project overview. So I removed that (see hierarchy_strategy.rb). But I did not yet double check if that broke the UI somewhere else. Please be aware that the strategy is not only used by Scored Lists, but also by Hierarchies. If Hierarchies need the error string, we could simply include a type check and render a different formatted value.
  • I have provided a handful of "functional" specs (see hierarchical_item_service_spec.rb) - but I am not happy with them. They utilize the database quite a lot. I feel like it should be possible without doing so - but then, I had to mock too much for my taste. Maybe you have a better idea of how to do this.
  • I have also provided a small amount of feature specs that update a scored list or delete an item from it while inspecting what happens with Calculated Values in that case. See: scored_lists_and_calculated_values_spec.rb
  • Lastly, I might have missed some cases in which we have to recalculate, please double check.

TL;DR: Everything should work. Specs ugly. Please double-check if there are other cases in which recalculation might be needed for Scored Lists. Thank you!

Screenshots

scored.lists.update.when.score.changes.mov

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@EinLama EinLama force-pushed the implementation/64524-recalculate-when-a-score-of-a-scored-list-is-changed-within-the-administration branch from a69cd9f to eeb3263 Compare October 2, 2025 12:50
@toy toy changed the base branch from dev to implementation/64523-allow-usage-of-custom-fields-of-type-hierarchy-with-a-value-within-a-calculated-values-formula October 2, 2025 17:22

return unless custom_field.field_format_scored_list?

custom_field.projects.each do |project|
Copy link
Contributor

Choose a reason for hiding this comment

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

This explicitly binds to projects maybe better to do it like in CustomFields::UpdateService.

Or maybe even go through custom values of this field that have value set to the deleted/updated item id

item = cached_typed_value

item.score.presence || item
item&.score.presence || item
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 be in #20454 :)


if item.nil?
"#{value} #{I18n.t(:label_not_found)}"
""
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

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

Successfully merging this pull request may close these issues.

2 participants