Skip to content
Merged
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
53 changes: 45 additions & 8 deletions src/PlanViewer.App/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,43 @@ private async Task GetActualPlanFromFile(PlanViewerControl viewer)
dialog.ResultConnection.ServerName.Contains(".database.azure.com",
StringComparison.OrdinalIgnoreCase);

// Create a loading placeholder tab immediately
var loadingPanel = new StackPanel
{
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
Width = 300
};

var progressBar = new ProgressBar
{
IsIndeterminate = true,
Height = 4,
Margin = new Avalonia.Thickness(0, 0, 0, 12)
};

var statusText = new TextBlock
{
Text = "Executing query...",
FontSize = 14,
Foreground = new SolidColorBrush(Color.Parse("#B0B6C0")),
HorizontalAlignment = HorizontalAlignment.Center
};

loadingPanel.Children.Add(progressBar);
loadingPanel.Children.Add(statusText);

var loadingContainer = new Grid
{
Background = new SolidColorBrush(Color.Parse("#1A1D23")),
Children = { loadingPanel }
};

var tab = CreateTab("Actual Plan", loadingContainer);
MainTabControl.Items.Add(tab);
MainTabControl.SelectedItem = tab;
UpdateEmptyOverlay();

try
{
// Fetch server metadata for advice and Plan Insights
Expand All @@ -1035,6 +1072,8 @@ private async Task GetActualPlanFromFile(PlanViewerControl viewer)
}
catch { /* Non-fatal — advice will just lack server context */ }

statusText.Text = "Capturing actual plan...";

var cts = new System.Threading.CancellationTokenSource();
var sw = System.Diagnostics.Stopwatch.StartNew();

Expand All @@ -1047,24 +1086,22 @@ private async Task GetActualPlanFromFile(PlanViewerControl viewer)

if (string.IsNullOrEmpty(actualPlanXml))
{
ShowError($"No actual plan returned ({sw.Elapsed.TotalSeconds:F1}s).");
statusText.Text = $"No actual plan returned ({sw.Elapsed.TotalSeconds:F1}s).";
progressBar.IsVisible = false;
return;
}

// Add a new tab with the actual plan
// Replace loading content with the actual plan
var actualViewer = new PlanViewerControl();
actualViewer.Metadata = metadata;
actualViewer.LoadPlan(actualPlanXml, "Actual Plan", queryText);

var content = CreatePlanTabContent(actualViewer);
var tab = CreateTab("Actual Plan", content);
MainTabControl.Items.Add(tab);
MainTabControl.SelectedItem = tab;
UpdateEmptyOverlay();
tab.Content = CreatePlanTabContent(actualViewer);
}
catch (Exception ex)
{
ShowError($"Error capturing actual plan:\n\n{ex.Message}");
statusText.Text = $"Error: {ex.Message}";
progressBar.IsVisible = false;
}
}

Expand Down
Loading