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

Add popup with choice of Accept or Won't Fix #5046

Merged
merged 6 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions src/Integration/Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@
<None Remove="Connection\UI\OrganizationSelectionWindow.xaml" />
<None Remove="Notifications\NotificationIndicator.xaml" />
<None Remove="Progress\ProgressControl.xaml" />
<None Remove="Transition\MuteWindowDialog.xaml" />

<Page Include="Connection\UI\ConnectionInfoDialogView.xaml" />
<Page Include="Connection\UI\OrganizationSelectionWindow.xaml" />
<Page Include="Notifications\NotificationIndicator.xaml" />
<Page Include="Progress\ProgressControl.xaml" />
<Page Include="Transition\MuteWindowDialog.xaml" />
</ItemGroup>

<ItemGroup>
Expand Down
91 changes: 91 additions & 0 deletions src/Integration/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/Integration/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,34 @@ This is the general format to use when writing errors to output window or when t
<data name="BindingUpdateFailedToCheckSettings" xml:space="preserve">
<value>[Binding check] Error checking bound project settings file: {0}</value>
</data>
<data name="MuteWindow_AcceptContent" xml:space="preserve">
<value>The issue is valid but does not need fixing. It represents accepted technical debt.</value>
</data>
<data name="MuteWindow_AcceptTitle" xml:space="preserve">
<value>Accept</value>
</data>
<data name="MuteWindow_CancelButton" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="MuteWindow_CommentLabel" xml:space="preserve">
<value>Add a comment (optional):</value>
</data>
<data name="MuteWindow_FalsePositiveContent" xml:space="preserve">
<value>The issue is raised unxpectedly on code that should not trigger an issue.</value>
</data>
<data name="MuteWindow_FalsePositiveTitle" xml:space="preserve">
<value>False Positive</value>
</data>
<data name="MuteWindow_SubmitButton" xml:space="preserve">
<value>Mark Issue as...</value>
</data>
<data name="MuteWindow_Title" xml:space="preserve">
<value>Mark Issue as Resolved on SonarQube</value>
</data>
<data name="MuteWindow_WontFixContent" xml:space="preserve">
<value>The issue is valid but does not need fixing. It represents accepted technical debt.</value>

Choose a reason for hiding this comment

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

Same content as Accept 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know I'll talk about it with Marco during the meet

</data>
<data name="MuteWindow_WontFixTitle" xml:space="preserve">
<value>Won't Fix</value>
</data>
</root>
62 changes: 62 additions & 0 deletions src/Integration/Transition/MuteWindowDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<vsui:DialogWindow x:Class="SonarLint.VisualStudio.Integration.Transition.MuteWindowDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:resx="clr-namespace:SonarLint.VisualStudio.Integration.Resources"
xmlns:local="clr-namespace:SonarLint.VisualStudio.Integration.Transition"
xmlns:vsui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
mc:Ignorable="d"
SizeToContent="WidthAndHeight"
Title="{x:Static resx:Strings.MuteWindow_Title}">
<Grid Height="350" Width="500">
<Border BorderBrush="Black" Name="BorderWontFix" BorderThickness="1" HorizontalAlignment="Left" Height="75" Margin="25,25,0,0" VerticalAlignment="Top" Width="450" Visibility="{Binding WontFixVisibility}">
<Grid>
<RadioButton Name="rbWontFix" GroupName="Transitions" Content="{x:Static resx:Strings.MuteWindow_WontFixTitle}" VerticalAlignment="Top" Margin="10,16,-10,0" FontWeight="Bold" Grid.ColumnSpan="2" Checked="RadioButton_Checked"/>
<Label Content="{x:Static resx:Strings.MuteWindow_WontFixContent}" HorizontalAlignment="Left" Margin="10,36,0,0" VerticalAlignment="Top" Grid.ColumnSpan="2"/>
</Grid>
</Border>

<Border BorderBrush="Black" Name="BorderAccept" BorderThickness="1" HorizontalAlignment="Left" Height="75" Margin="25,25,0,0" VerticalAlignment="Top" Width="450" Visibility="{Binding AcceptVisibility}">
<Grid>
<RadioButton Name="rbAccept" GroupName="Transitions" Content="{x:Static resx:Strings.MuteWindow_AcceptTitle}" VerticalAlignment="Top" Margin="10,16,-10,0" FontWeight="Bold" Grid.ColumnSpan="2" Checked="RadioButton_Checked"/>

Choose a reason for hiding this comment

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

Radio button stye (and possibly others) is duplicated.

<Label Content="{x:Static resx:Strings.MuteWindow_AcceptContent}" HorizontalAlignment="Left" Margin="10,36,0,0" VerticalAlignment="Top" Grid.ColumnSpan="2"/>
</Grid>
</Border>

<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="75" Margin="25
,115,0,0" VerticalAlignment="Top" Width="450">
<Grid>
<RadioButton x:Name="rbFalsePositive" GroupName="Transitions" Content="{x:Static resx:Strings.MuteWindow_FalsePositiveTitle}" VerticalAlignment="Top" Margin="10,16,-10,0" FontWeight="Bold" Grid.ColumnSpan="2" Checked="RadioButton_Checked"/>
<Label Content="{x:Static resx:Strings.MuteWindow_FalsePositiveContent}" HorizontalAlignment="Left" Margin="10,36,0,0" VerticalAlignment="Top" Grid.ColumnSpan="2"/>

Choose a reason for hiding this comment

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

Style duplication

</Grid>
</Border>
<Label Content="{x:Static resx:Strings.MuteWindow_CommentLabel}" HorizontalAlignment="Left" Margin="25,200,0,0" VerticalAlignment="Top"/>
<TextBox Name="txtComment" HorizontalAlignment="Center" Height="60" Margin="0,225,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="450"/>

Choose a reason for hiding this comment

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

Styles in the layout

<Button Name="Cancel" Content="{x:Static resx:Strings.MuteWindow_CancelButton}" Padding="5,1" HorizontalAlignment="Left" Margin="300,300,0,0" VerticalAlignment="Top" Click="Cancel_Click"/>
<Button Name="Submit" Content="{x:Static resx:Strings.MuteWindow_SubmitButton}" Padding="5,1" HorizontalAlignment="Left" Margin="360,300,0,0" VerticalAlignment="Top" Click="Submit_Click">

Choose a reason for hiding this comment

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

This style is not duplicated, however, it's hard to read

Choose a reason for hiding this comment

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

Ah, actually it is duplicated from the Cancel button

<Button.Style>
<Style TargetType="Button">

<Setter Property="IsEnabled" Value="False"/>

<Style.Triggers>

<DataTrigger Binding="{Binding Path=IsChecked, ElementName=rbWontFix}" Value="True">
<Setter Property="IsEnabled" Value="True"/>
</DataTrigger>

<DataTrigger Binding="{Binding Path=IsChecked, ElementName=rbAccept}" Value="True">
<Setter Property="IsEnabled" Value="True"/>
</DataTrigger>

<DataTrigger Binding="{Binding Path=IsChecked, ElementName=rbFalsePositive}" Value="True">
<Setter Property="IsEnabled" Value="True"/>
</DataTrigger>

</Style.Triggers>
</Style>
</Button.Style>
</Button>
</Grid>
</vsui:DialogWindow>
81 changes: 81 additions & 0 deletions src/Integration/Transition/MuteWindowDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Windows.Markup;
using Microsoft.VisualStudio.PlatformUI;
using SonarQube.Client.Models;

namespace SonarLint.VisualStudio.Integration.Transition
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
[ContentProperty(nameof(MuteWindowDialog))]
[ExcludeFromCodeCoverage]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

UI Code not testable

public partial class MuteWindowDialog : DialogWindow
{
public MuteWindowDialog(bool showAccept)
{
InitializeComponent();

SetVisibility(showAccept);
}

private void SetVisibility(bool showAccept)
{
BorderWontFix.Visibility = showAccept ? Visibility.Hidden : Visibility.Visible;
BorderAccept.Visibility = showAccept ? Visibility.Visible : Visibility.Hidden;
}

private void Cancel_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}

private void Submit_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}

public SonarQubeIssueTransition SelectedIssueTransition { get; private set; }

public string Comment => txtComment.Text;

private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
switch (sender)
{
case var value when value == rbWontFix:

Choose a reason for hiding this comment

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

Non-blocker: Could be replaced with a dictionary that would look nicer

SelectedIssueTransition = SonarQubeIssueTransition.WontFix;
break;

case var value when value == rbAccept:
SelectedIssueTransition = SonarQubeIssueTransition.Accept;
break;

case var value when value == rbFalsePositive:
SelectedIssueTransition = SonarQubeIssueTransition.FalsePositive;
break;
}
}
}
}