Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Tests and server/ projects are outside src/ and are unaffected.
-->
<PropertyGroup>
<Version>1.15.0</Version>
<Version>1.16.0</Version>
<Authors>Erik Darling</Authors>
<Company>Darling Data LLC</Company>
<Product>Performance Studio</Product>
Expand Down
5 changes: 4 additions & 1 deletion src/PlanViewer.App/Controls/ColumnFilterPopup.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="PlanViewer.App.Controls.ColumnFilterPopup"
Width="220">
Width="280">
<Border Background="{DynamicResource BackgroundDarkBrush}"
BorderBrush="{DynamicResource BorderBrush}"
BorderThickness="1" CornerRadius="6">
Expand All @@ -20,6 +20,9 @@
Height="28" FontSize="12" Margin="0,0,0,12"
KeyDown="ValueTextBox_KeyDown"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8">
<Button x:Name="SearchServerButton" Content="Search server" IsVisible="False" Height="28"
Click="SearchServerButton_Click"
Theme="{StaticResource AppButton}"/>
<Button Content="Clear" Width="65" Height="28"
Click="ClearButton_Click"
Theme="{StaticResource AppButton}"/>
Expand Down
24 changes: 19 additions & 5 deletions src/PlanViewer.App/Controls/ColumnFilterPopup.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public partial class ColumnFilterPopup : UserControl
{
public event EventHandler<FilterAppliedEventArgs>? FilterApplied;
public event EventHandler? FilterCleared;
public event EventHandler<FilterAppliedEventArgs>? SearchServerRequested;

private string _currentColumnName = "";

Expand All @@ -35,10 +36,11 @@ public ColumnFilterPopup()
OperatorComboBox.SelectedIndex = 0;
}

public void Initialize(string columnName, ColumnFilterState? existingFilter)
public void Initialize(string columnName, ColumnFilterState? existingFilter, bool canSearchServer)
{
_currentColumnName = columnName;
HeaderText.Text = $"Filter: {columnName}";
SearchServerButton.IsVisible = canSearchServer;

if (existingFilter?.IsActive == true)
{
Expand Down Expand Up @@ -70,24 +72,36 @@ private void OperatorComboBox_SelectionChanged(object? sender, SelectionChangedE
UpdateValueVisibility();
}

private void ApplyFilter()
private FilterAppliedEventArgs? BuildFilterArgs()
{
var idx = OperatorComboBox.SelectedIndex;
if (idx < 0 || idx >= Operators.Length) return;
if (idx < 0 || idx >= Operators.Length) return null;

FilterApplied?.Invoke(this, new FilterAppliedEventArgs
return new FilterAppliedEventArgs
{
FilterState = new ColumnFilterState
{
ColumnName = _currentColumnName,
Operator = Operators[idx].Op,
Value = ValueTextBox.Text ?? "",
}
});
};
}

private void ApplyFilter()
{
if (BuildFilterArgs() is { } args)
FilterApplied?.Invoke(this, args);
}

private void ApplyButton_Click(object? sender, RoutedEventArgs e) => ApplyFilter();

private void SearchServerButton_Click(object? sender, RoutedEventArgs e)
{
if (BuildFilterArgs() is { } args)
SearchServerRequested?.Invoke(this, args);
}

private void ClearButton_Click(object? sender, RoutedEventArgs e)
{
FilterApplied?.Invoke(this, new FilterAppliedEventArgs
Expand Down
7 changes: 6 additions & 1 deletion src/PlanViewer.App/Controls/QueryStoreGridControl.Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public partial class QueryStoreGridControl : UserControl
{
private async void Fetch_Click(object? sender, RoutedEventArgs e)
{
// Commit any pending toolbar "Search by" entry into the server-filter state first,
// then refresh the chip strip, before running the fetch.
CommitSearchByCriterion();
RebuildChips();

_fetchCts?.Cancel();
_fetchCts?.Dispose();
_fetchCts = new CancellationTokenSource();
Expand Down Expand Up @@ -69,7 +74,7 @@ private async System.Threading.Tasks.Task FetchPlansForRangeAsync()

var topN = (int)(TopNBox.Value ?? 25);
var orderBy = _lastFetchedOrderBy;
var filter = BuildSearchFilter();
var filter = _serverFilterState.BuildFilter();

FetchButton.IsEnabled = false;
LoadButton.IsEnabled = false;
Expand Down
64 changes: 41 additions & 23 deletions src/PlanViewer.App/Controls/QueryStoreGridControl.Filters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,60 +35,70 @@ private void SearchType_SelectionChanged(object? sender, SelectionChangedEventAr
ExecutionTypePanel.IsVisible = isExecutionType;
}

private QueryStoreFilter? BuildSearchFilter()
/// <summary>
/// Commits the toolbar "Search by" selection into <see cref="_serverFilterState"/>.
/// No-ops when no search type is chosen or the value is empty; sets StatusText and does
/// not commit on a malformed query-id/plan-id. On a successful commit the toolbar inputs
/// are reset (the criterion now lives as a chip).
/// </summary>
private void CommitSearchByCriterion()
{
var searchType = (SearchTypeBox.SelectedItem as ComboBoxItem)?.Tag?.ToString();

if (string.IsNullOrEmpty(searchType))
return null;
return;

if (searchType == "execution-type")
{
var tag = (ExecutionTypeBox.SelectedItem as ComboBoxItem)?.Tag?.ToString();
// "any" tag (first item) means no filter
if (string.IsNullOrEmpty(tag) || tag == "any")
return null;
// "Failed" bundles Aborted + Exception into an IN predicate
if (tag == "Failed")
return new QueryStoreFilter { ExecutionTypeDescs = ["Aborted", "Exception"] };
return new QueryStoreFilter { ExecutionTypeDescs = [tag] };
_serverFilterState.SetExecutionType(QueryStoreFilter.ParseExecutionType(tag));
ResetSearchInputs();
return;
}

var searchValue = SearchValueBox.Text?.Trim();
if (string.IsNullOrEmpty(searchValue))
return null;

var filter = new QueryStoreFilter();
return;

switch (searchType)
{
case "query-id" when long.TryParse(searchValue, out var qid):
filter.QueryId = qid;
_serverFilterState.SetQueryId(qid);
break;
case "query-id":
StatusText.Text = "Invalid Query ID";
return null;
return;
case "plan-id" when long.TryParse(searchValue, out var pid):
filter.PlanId = pid;
_serverFilterState.SetPlanId(pid);
break;
case "plan-id":
StatusText.Text = "Invalid Plan ID";
return null;
return;
case "query-hash":
filter.QueryHash = searchValue;
_serverFilterState.SetQueryHash(searchValue);
break;
case "plan-hash":
filter.QueryPlanHash = searchValue;
_serverFilterState.SetQueryPlanHash(searchValue);
break;
case "module":
// Default to dbo schema if no schema specified, following sp_QuickieStore pattern
filter.ModuleName = searchValue.Contains('.') ? searchValue : $"dbo.{searchValue}";
_serverFilterState.SetModule(searchValue.Contains('.') ? searchValue : $"dbo.{searchValue}");
break;
case "query-text":
_serverFilterState.SetQueryTextSearch(searchValue);
break;
default:
return null;
return;
}

return filter;
ResetSearchInputs();
}

/// <summary>Resets the toolbar search inputs after a criterion is committed.</summary>
private void ResetSearchInputs()
{
SearchTypeBox.SelectedIndex = 0;
SearchValueBox.Text = "";
}

private void SearchValue_KeyDown(object? sender, Avalonia.Input.KeyEventArgs e)
Expand All @@ -100,12 +110,18 @@ private void SearchValue_KeyDown(object? sender, Avalonia.Input.KeyEventArgs e)
}
}

private void ClearSearch_Click(object? sender, RoutedEventArgs e)
private async void ClearSearch_Click(object? sender, RoutedEventArgs e)
{
SearchTypeBox.SelectedIndex = 0;
SearchValueBox.Text = "";
// Resetting SearchTypeBox triggers SearchType_SelectionChanged which hides ExecutionTypePanel.
ExecutionTypeBox.SelectedIndex = 0;

// Also clear every accumulated server filter and its panel input, then re-fetch.
_serverFilterState.Clear();
ResetServerFilterPanelInputs();
RebuildChips();
await FetchPlansForRangeAsync();
}

private void SetupColumnHeaders()
Expand Down Expand Up @@ -190,14 +206,16 @@ private void EnsureFilterPopup()
((Grid)Content!).Children.Add(_filterPopup);
_filterPopupContent.FilterApplied += OnFilterApplied;
_filterPopupContent.FilterCleared += OnFilterCleared;
_filterPopupContent.SearchServerRequested += OnSearchServerRequested;
}

private void ColumnFilter_Click(object? sender, RoutedEventArgs e)
{
if (sender is not Button button || button.Tag is not string columnId) return;
EnsureFilterPopup();
_activeFilters.TryGetValue(columnId, out var existing);
_filterPopupContent!.Initialize(columnId, existing);
var canSearchServer = MapColumnToServerKind(columnId) is not null;
_filterPopupContent!.Initialize(columnId, existing, canSearchServer);
_filterPopup!.PlacementTarget = button;
_filterPopup.IsOpen = true;
}
Expand Down
Loading
Loading