Skip to content

Commit

Permalink
fix: application history did not include change reasons with 0 diffs …
Browse files Browse the repository at this point in the history
…(hl-1484) (#3413)

* fix: do not display amount of changes if the it's is merely a edit comment

* refactor: rename confusing change history variables

* fix: expose empty changes with a change reason to the response
  • Loading branch information
sirtawast authored Oct 9, 2024
1 parent ecdde64 commit 031d5bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
23 changes: 14 additions & 9 deletions backend/benefit/applications/services/change_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _get_change_set_base(new_record: ModelChange):
}


merge_threshold_in_seconds = 0.25
look_up_for_application_save_in_seconds = 0.25


def _filter_and_format_changes(
Expand All @@ -215,7 +215,7 @@ def _filter_and_format_changes(
and (
delta_time
is None # We'll ignore this check for application changes as delta_time's not present
or 0 <= delta_time <= merge_threshold_in_seconds
or 0 <= delta_time <= look_up_for_application_save_in_seconds
),
changes,
),
Expand Down Expand Up @@ -255,14 +255,14 @@ def get_application_change_history_made_by_handler(application: Application) ->

app_diff_dates = [diff.new_record.history_date for diff in application_diffs]

# create Q objects for each datetime in the list
q_objects = Q()
# fetch employee history changes that occured during the saving of application
employee_q_objects = Q()
for dt in app_diff_dates:
start_date = dt - timedelta(seconds=merge_threshold_in_seconds)
end_date = dt + timedelta(seconds=merge_threshold_in_seconds)
q_objects |= Q(history_date__range=(start_date, end_date))
start_date = dt - timedelta(seconds=look_up_for_application_save_in_seconds)
end_date = dt + timedelta(seconds=look_up_for_application_save_in_seconds)
employee_q_objects |= Q(history_date__range=(start_date, end_date))

employee_history = application.employee.history.filter(q_objects)
employee_history = application.employee.history.filter(employee_q_objects)
employee_diffs = []
for i in range(0, len(employee_history) - 1):
diff = employee_history[i].diff_against(employee_history[i + 1])
Expand All @@ -282,7 +282,12 @@ def create_change_set(app_diff, employee_diffs):
employee_diff.changes, EXCLUDED_EMPLOYEE_FIELDS, True, delta_time
)

return change_set if len(change_set["changes"]) > 0 else None
return (
change_set
if len(change_set["changes"]) > 0
or (change_set["reason"] and len(change_set["reason"]) > 0)
else None
)

change_sets = list(
filter(
Expand Down
12 changes: 7 additions & 5 deletions frontend/benefit/handler/src/components/sidebar/ChangeSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ const ChangeSet: React.FC<ChangeSetProps> = ({ data }: ChangeSetProps) => {
))}
</dl>
<$ChangeSetFooter>
<p>
{t('common:changes.header.amountOfChanges', {
amount: changes.length,
})}
</p>
{changes.length > 0 && (
<p>
{t('common:changes.header.amountOfChanges', {
amount: changes.length,
})}
</p>
)}
<hr />
<$ViewFieldBold>
{t('common:applications.sections.fields.changeReason.placeholder')}
Expand Down

0 comments on commit 031d5bf

Please sign in to comment.