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

Bug 1823503 - After add comment, sometimes all status flags are changed to fixed by itself. #2042

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions extensions/BugModal/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ sub template_before_process {
file => 'bug/edit.html.tmpl', vars => $vars,
});

my $tracking_flags = Bugzilla::Extension::TrackingFlags::Flag->match({
product => $bug->product,
component => $bug->component,
bug_id => $bug->id,
is_active => 1,
});
$vars->{tracking_flags} = $tracking_flags;

if (any { $bug->product eq $_ } READABLE_BUG_STATUS_PRODUCTS) {
my @flags = map { {name => $_->name, status => $_->status} } @{$bug->flags};
$vars->{readable_bug_status_json} = encode_json({
Expand All @@ -212,7 +220,7 @@ sub template_before_process {
status => $bug->bug_status,
flags => \@flags,
target_milestone => $bug->target_milestone,
map { $_->name => $_->bug_flag($bug->id)->value } @{$vars->{tracking_flags}},
map { $_->name => $_->bug_flag($bug->id)->value } @{$tracking_flags},
});

# HTML4 attributes cannot be longer than this, so just skip it in this case.
Expand Down Expand Up @@ -273,24 +281,46 @@ sub template_before_process {

# group tracking flags by version to allow for a better tabular output
my @tracking_table;
my $tracking_flags = $vars->{tracking_flags};
foreach my $flag (@$tracking_flags) {
my $flag_type = $flag->flag_type;
my $type = 'status';
my $name = $flag->description;
if ($flag_type eq 'tracking' && $name =~ /^(tracking|status)-(.+)/) {
($type, $name) = ($1, $2);
foreach my $flag (@{$tracking_flags}) {
my $flag_type = $flag->flag_type;
my $type = 'status';
my $name = $flag->name;
my $description = $flag->description;
my $value = $flag->bug_flag($bug->id)->value;

# Use short version of tracking flag description for the UI description
if ($flag_type eq 'tracking' && $description =~ /^(tracking|status)-(.+)/) {
($type, $description) = ($1, $2);
}

# Only include values that are active and the current user can set
my @values = ();
foreach my $value (@{$flag->values}) {
next if !$value->is_active || !$flag->can_set_value($value->name);
push @values, {id => $value->id, name => $value->name};
}

# If we already have a similar description, then add this flag to the same row
# in the UI. Otherwise it will be on a different row.
my ($existing)
= grep { $_->{type} eq $flag_type && $_->{name} eq $name } @tracking_table;
= grep { $_->{type} eq $flag_type && $_->{description} eq $description }
@tracking_table;
if ($existing) {
$existing->{$type} = $flag;
$existing->{$type} = {name => $name, value => $value, values => \@values};
}
else {
push @tracking_table, {$type => $flag, name => $name, type => $flag_type,};
push @tracking_table,
{
$type => {name => $name, value => $value, values => \@values},
description => $description,
type => $flag_type,
};
}
}

# Sort by description
@tracking_table
= sort { $a->{description} cmp $b->{description} } @tracking_table;
$vars->{tracking_flags_table} = \@tracking_table;

# for the "View -> Hide Treeherder Comments" menu item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@
%]

[% javascript = BLOCK %]
[%# add tracking flags JSON if available %]
[% IF tracking_flags %]
[% javascript_urls.push("extensions/TrackingFlags/web/js/flags.js") %]
var tracking_flags_str = "[% tracking_flags_json FILTER js %]";
var TrackingFlags = $.parseJSON(tracking_flags_str);
[% END %]

[%# update last-visited %]
[% IF user.id %]
document.addEventListener('DOMContentLoaded', () => show_new_changes_indicator(), { once: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@
#%]

[%
flags = [];
set_flags = [];
FOREACH flag IN tracking_flags;
NEXT UNLESS flag.flag_type == type;
flags.push(flag);
NEXT IF flag.bug_flag(bug.id).value == "---";
set_flags.push(flag);
RETURN UNLESS tracking_flags_table.size;
set_flags = 0;
FOREACH row IN tracking_flags_table;
NEXT IF (!row.tracking || row.tracking.value == "---")
&& (!row.status || row.status.value == "---");
set_flags = 1;
END;
RETURN UNLESS flags.size;
%]

[%# view %]
[% IF set_flags.size %]
[% IF set_flags %]
<div class="flags edit-hide">
<table class="layout-table tracking-flags">
[% IF type == "tracking" %]
Expand All @@ -34,31 +32,30 @@
</tr>
[% END %]
[% FOREACH row IN tracking_flags_table %]
[%
[%
NEXT UNLESS row.type == type;
tracking_value = row.tracking.bug_flag(bug_id).value || "---";
status_value = row.status.bug_flag(bug_id).value || "---";
NEXT IF tracking_value == "---" && status_value == "---";
NEXT IF (!row.tracking || row.tracking.value == "---")
&& (!row.status || row.status.value == "---");
%]
<tr>
<td class="tracking-flag-name">[% row.name FILTER html %]</td>
<td class="tracking-flag-name">[% row.description FILTER html %]</td>
[% IF type == "tracking" %]
<td class="tracking-flag-tracking">
[% IF tracking_value != '---' %]
[% IF row.tracking.value != '---' %]
<a href="[% basepath FILTER none %]buglist.cgi?f1=[% row.tracking.name FILTER uri ~%]
&amp;o1=equals&amp;v1=[% tracking_value FILTER uri %]">
&amp;o1=equals&amp;v1=[% row.tracking.value FILTER uri %]">
[% END %]
[%~ tracking_value FILTER html ~%]
[% '</a>' IF tracking_value != '---' %]
[%~ row.tracking.value FILTER html ~%]
[% '</a>' IF row.tracking.value != '---' %]
</td>
[% END %]
<td class="tracking-flag-status">
[% IF status_value != '---' %]
[% IF row.status.value != '---' %]
<a href="[% basepath FILTER none %]buglist.cgi?f1=[% row.status.name FILTER uri ~%]
&amp;o1=equals&amp;v1=[% status_value FILTER uri %]">
&amp;o1=equals&amp;v1=[% row.status.value FILTER uri %]">
[% END %]
[%~ status_value FILTER html ~%]
[% '</a>' IF status_value != '---' %]
[%~ row.status.value FILTER html ~%]
[% '</a>' IF row.status.value != '---' %]
</td>
</tr>
[% END %]
Expand All @@ -79,7 +76,7 @@
[% FOREACH row IN tracking_flags_table %]
[% NEXT UNLESS row.type == type %]
<tr>
<td class="tracking-flag-name">[% row.name FILTER html %]</td>
<td class="tracking-flag-name">[% row.description FILTER html %]</td>
[% IF type == "tracking" %]
<td class="tracking-flag-tracking">[% INCLUDE tf_select flag=row.tracking %]</td>
[% END %]
Expand All @@ -94,15 +91,11 @@
<input type="hidden" id="[% flag.name FILTER html %]-dirty">
<select id="[% flag.name FILTER html %]" name="[% flag.name FILTER html %]">
[%
flag_bug_value = flag.bug_flag(bug_id).value;
FOREACH value IN flag.values;
IF value.name != flag_bug_value;
NEXT IF !value.is_active || !flag.can_set_value(value.name);
END;
%]
<option value="[% value.name FILTER html %]"
id="v[% value.id FILTER html %]_[% flag.name FILTER html %]"
[% " selected" IF flag_bug_value == value.name %]
[% " selected" IF flag.value == value.name %]
>
[% value.name FILTER html %]
</option>
Expand Down
6 changes: 0 additions & 6 deletions extensions/BugModal/web/bug_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,12 +960,6 @@ $(function() {
}
});

// tracking flags
$('.tracking-flags select')
.change(function(event) {
tracking_flag_change(event.target);
});

// take button
$('.take-btn')
.click(function(event) {
Expand Down
10 changes: 4 additions & 6 deletions extensions/TrackingFlags/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ sub template_before_process {
elsif ($file eq 'bug/edit.html.tmpl'
|| $file eq 'bug/show.xml.tmpl'
|| $file eq 'email/bugmail.html.tmpl'
|| $file eq 'email/bugmail.txt.tmpl')
|| $file eq 'email/bugmail.txt.tmpl'
|| $file eq 'bug_modal/edit.html/tmpl')
{
# note: bug/edit.html.tmpl doesn't support multiple bugs
my $bug = exists $vars->{'bugs'} ? $vars->{'bugs'}[0] : $vars->{'bug'};
Expand All @@ -112,7 +113,6 @@ sub template_before_process {
is_active => 1,
});

$vars->{tracking_flags} = $flags;
$vars->{tracking_flags_json} = _flags_to_json($flags);
}

Expand All @@ -129,15 +129,13 @@ sub template_before_process {
sub _flags_to_json {
my ($flags) = @_;

my $json = {flags => {}, types => [], comments => {},};
my $json = {types => [], comments => {}};

my %type_map = map { $_->{name} => $_ } @{FLAG_TYPES()};
foreach my $flag (@$flags) {
my $flag_type = $flag->flag_type;

$json->{flags}->{$flag_type}->{$flag->name} = $flag->bug_flag->value;

if ($type_map{$flag_type}->{collapsed} && !grep { $_ eq $flag_type }
if ($type_map{$flag_type}->{collapsed} && none { $_ eq $flag_type }
@{$json->{types}})
{
push @{$json->{types}}, $flag_type;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[%# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
#%]

[% javascript_urls.push('extensions/TrackingFlags/web/js/flags.js') %]

[% IF tracking_flags_json %]
<script [% script_nonce FILTER none %]>
var tracking_flags_str = "[% tracking_flags_json FILTER js %]";
var TrackingFlags = JSON.parse(tracking_flags_str);
</script>
[% END %]
Loading