Skip to content

Commit

Permalink
MBS-12839: Allow searching for edits by kind of edit type
Browse files Browse the repository at this point in the history
Rather than having to select all add / merge / whatnot edits
one by one by type, this allows us to search for all types of merges
or whatnot in one quick click.

This will also eventually help us to split the lumped
historic relationships that all share the same edit name,
since instead of needing to use a grouped "Edit release" name,
we will be able to select "kind is edit, entity type is release".
  • Loading branch information
reosarevok committed Dec 1, 2023
1 parent 0f8271a commit a36c51d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
12 changes: 9 additions & 3 deletions lib/MusicBrainz/Server/Controller/Edit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,18 @@ sub search : Path('/search/edits')
{
my ($self, $c) = @_;
my $coll = $c->get_collator();
my %grouped = MusicBrainz::Server::EditRegistry->grouped_by_name;
my %grouped_by_kind = MusicBrainz::Server::EditRegistry->grouped_by_kind;
my %grouped_by_name = MusicBrainz::Server::EditRegistry->grouped_by_name;
$c->stash(
edit_kinds => [
map [
join(q(,), sort { $a <=> $b } map { $_->edit_type } @{ $grouped_by_kind{$_} }) => $_
], sort_by { $coll->getSortKey($_) } keys %grouped_by_kind
],
edit_types => [
map [
join(q(,), sort { $a <=> $b } map { $_->edit_type } @{ $grouped{$_} }) => $_
], sort_by { $coll->getSortKey($_) } keys %grouped
join(q(,), sort { $a <=> $b } map { $_->edit_type } @{ $grouped_by_name{$_} }) => $_
], sort_by { $coll->getSortKey($_) } keys %grouped_by_name
],
status => status_names(),
quality => [ [$QUALITY_LOW => N_l('Low')], [$QUALITY_NORMAL => N_l('Normal')], [$QUALITY_HIGH => N_l('High')], [$QUALITY_UNKNOWN => N_l('Default')] ],
Expand Down
13 changes: 13 additions & 0 deletions lib/MusicBrainz/Server/EditRegistry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ sub _register_default_types
$_registered = 1;
}

sub grouped_by_kind
{
my $class = shift;
my %grouped;
foreach my $class ($class->get_all_classes) {
my $name = $class->l_edit_kind;
$grouped{ $name } ||= [];
push @{ $grouped{ $name } }, $class;
}

return %grouped;
}

sub grouped_by_name
{
my $class = shift;
Expand Down
6 changes: 5 additions & 1 deletion lib/MusicBrainz/Server/EditSearch/Predicate/Set.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ sub valid {
sub combine_with_query {
my ($self, $query) = @_;
return unless $self->arguments;

# Edit kind grouping is based on the edit type column
my $column = $self->field_name eq 'kind' ? 'type' : $self->field_name;

$query->add_where([
join(' ', 'edit.'.$self->field_name, $self->operator,
join(' ', 'edit.'.$column, $self->operator,
$self->operator eq '=' ? 'any(?)' :
$self->operator eq '!=' ? 'all(?)' : die 'Shouldnt get here'),
$self->sql_arguments
Expand Down
1 change: 1 addition & 0 deletions lib/MusicBrainz/Server/EditSearch/Query.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ my %field_map = (
open_time => 'MusicBrainz::Server::EditSearch::Predicate::Date',
close_time => 'MusicBrainz::Server::EditSearch::Predicate::Date',
expire_time => 'MusicBrainz::Server::EditSearch::Predicate::Date',
kind => 'MusicBrainz::Server::EditSearch::Predicate::EditIDSet',
type => 'MusicBrainz::Server::EditSearch::Predicate::EditIDSet',
status => 'MusicBrainz::Server::EditSearch::Predicate::Set',
vote_count => 'MusicBrainz::Server::EditSearch::Predicate::VoteCount',
Expand Down
12 changes: 12 additions & 0 deletions lib/MusicBrainz/Server/Form/Search/Edits.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ has_field 'status' => (
type => 'Multiple'
);

sub options_kind
{
my $self = shift;
my %grouped = MusicBrainz::Server::EditRegistry->grouped_by_kind;
return [
_sort_hash_value(map {
# edit types => edit name
join(q(,), map { $_->edit_type } @{ $grouped{$_} }) => $_
} keys %grouped)
];
}

sub options_type
{
my $self = shift;
Expand Down
9 changes: 8 additions & 1 deletion root/edit/search_macros.tt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@
CASE 'MusicBrainz::Server::EditSearch::Predicate::VoteCount';
predicate_vote_count(field.field_name, field);
CASE 'MusicBrainz::Server::EditSearch::Predicate::EditIDSet';
predicate_set(field.field_name, edit_types, field, 15, 1);
SWITCH field.field_name;
CASE 'kind';
predicate_set(field.field_name, edit_kinds, field, 5, 1);
CASE 'type';
predicate_set(field.field_name, edit_types, field, 15, 1);
END;
CASE 'MusicBrainz::Server::EditSearch::Predicate::Set';
predicate_set(field.field_name, status, field, 8);
CASE 'MusicBrainz::Server::EditSearch::Predicate::EditNoteContent';
Expand Down Expand Up @@ -425,6 +430,7 @@
[ 'expire_time', l('Voting closed') ],
[ 'close_time', l('Closed') ],
[ 'status', lp('Status', 'edit status') ],
[ 'kind', lp('Kind', 'kind of edit') ],
[ 'type', l('Type') ],
[ 'vote_count', l('Vote tally') ],
[ 'edit_note_author', l('Edit Note Authors'), {requires_login => 1} ],
Expand Down Expand Up @@ -466,6 +472,7 @@
<div id="fields">
[% predicate_id('id') %]
[% predicate_date(field_name) FOR field_name=['open_time', 'expire_time', 'close_time'] %]
[% predicate_set('kind', edit_kinds, [], 5) %]
[% predicate_set('type', edit_types, [], 15) %]
[% predicate_set('status', status, [], 8) %]
[% predicate_set('release_quality', quality) %]
Expand Down

0 comments on commit a36c51d

Please sign in to comment.