Skip to content

Commit

Permalink
Make sure category shown in all its groups.
Browse files Browse the repository at this point in the history
When compiling the reporting category dropdown, only one instance of
each value was used. But if a value appears twice, from two different
bodies, in different groups, it would then not appear in all the groups
it would be expected to. Make sure we update the list of groups of the
category if we come across another with the same value.
  • Loading branch information
dracos committed May 26, 2020
1 parent 2f34019 commit 78ba186
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Unreleased
- Bugfixes:
- Fix issue with dashboard report CSV export. #3026
- Make sure category shown in all its groups when reporting.
- Admin improvements:
- Display user name/email for contributed as reports. #2990
- Interface for enabling anonymous reports for certain categories. #2989
Expand Down
1 change: 0 additions & 1 deletion perllib/FixMyStreet/App/Controller/JSON.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ BEGIN { extends 'Catalyst::Controller'; }
use JSON::MaybeXS;
use DateTime;
use DateTime::Format::ISO8601;
use List::MoreUtils 'uniq';
use FixMyStreet::DateRange;

=head1 NAME
Expand Down
13 changes: 9 additions & 4 deletions perllib/FixMyStreet/App/Controller/Report/New.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ BEGIN { extends 'Catalyst::Controller'; }

use utf8;
use Encode;
use List::MoreUtils qw(uniq);
use List::Util 'first';
use List::Util qw(first uniq);
use HTML::Entities;
use Path::Class;
use Utils;
Expand Down Expand Up @@ -759,8 +758,14 @@ sub setup_categories_and_bodies : Private {
if !$c->stash->{unresponsive}{ALL} &&
($contact->email =~ /^REFUSED$/i || $body_send_method eq 'Refused');

push @category_options, $contact unless $seen{$contact->category};
$seen{$contact->category} = $contact;
if (my $cat = $seen{$contact->category}) {
# Make sure the category is listed in all its groups, not just the first set
my @groups = uniq @{$cat->groups}, @{$contact->groups};
$cat->set_extra_metadata(group => \@groups);
} else {
push @category_options, $contact;
$seen{$contact->category} = $contact;
}
}

if (@category_options) {
Expand Down
4 changes: 2 additions & 2 deletions t/app/controller/report_new.t
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,10 @@ subtest "category groups" => sub {
}
}, sub {
$contact2->update( { extra => { group => ['Roads','Pavements'] } } );
$contact9->update( { extra => { group => 'Roads' } } );
$contact9->update( { extra => { group => 'Pavements' } } );
$contact10->update( { extra => { group => 'Roads' } } );
$mech->get_ok("/report/new?lat=$saved_lat&lon=$saved_lon");
$mech->content_like(qr{<optgroup label="Pavements">\s*<option value='Potholes'>Potholes</option></optgroup>});
$mech->content_like(qr{<optgroup label="Pavements">\s*<option value='Potholes'>Potholes</option>\s*<option value='Street lighting'>Street lighting</option></optgroup>});
$mech->content_like(qr{<optgroup label="Roads">\s*<option value='Potholes'>Potholes</option>\s*<option value='Street lighting'>Street lighting</option></optgroup>});
};
};
Expand Down

0 comments on commit 78ba186

Please sign in to comment.