Skip to content

Commit fcdf20a

Browse files
Merge pull request #203 from erikdarlingdata/feature/183-connection-dropdown
Add server name dropdown for saved connections
2 parents ebb12d2 + a97f581 commit fcdf20a

2 files changed

Lines changed: 44 additions & 10 deletions

File tree

src/PlanViewer.App/Dialogs/ConnectionDialog.axaml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,33 @@
1313
<!-- Server Name -->
1414
<TextBlock Grid.Row="0" Text="Server name" Foreground="{DynamicResource ForegroundBrush}"
1515
FontSize="12" Margin="0,0,0,4"/>
16-
<AutoCompleteBox Grid.Row="1" x:Name="ServerNameBox"
17-
Watermark="e.g. sql2022 or server.database.windows.net"
18-
FontSize="13" Height="32" Margin="0,0,0,12"
19-
FilterMode="ContainsOrdinal"
20-
SelectionChanged="ServerName_SelectionChanged"/>
16+
<Grid Grid.Row="1" x:Name="ServerNameGrid" ColumnDefinitions="*,Auto" Margin="0,0,0,12" ColumnSpacing="0">
17+
<TextBox x:Name="ServerNameBox"
18+
Watermark="e.g. sql2022 or server.database.windows.net"
19+
FontSize="13" Height="32"/>
20+
<Button Grid.Column="1" Click="DropdownButton_Click"
21+
Height="32" Width="32" Padding="0"
22+
Background="Black" CornerRadius="0,4,4,0"
23+
BorderBrush="White" BorderThickness="1">
24+
<Path Data="M 0,0 L 4,4 L 8,0"
25+
Stroke="{DynamicResource ForegroundBrush}"
26+
StrokeThickness="1.5"
27+
VerticalAlignment="Center"
28+
HorizontalAlignment="Center"/>
29+
</Button>
30+
<Popup x:Name="ServerDropdown"
31+
PlacementTarget="{Binding #ServerNameGrid}"
32+
Placement="BottomEdgeAlignedLeft"
33+
IsLightDismissEnabled="True"
34+
MaxHeight="200">
35+
<Border Background="{DynamicResource BackgroundBrush}"
36+
BorderBrush="#555" BorderThickness="1" CornerRadius="4">
37+
<ListBox x:Name="ServerList"
38+
SelectionChanged="ServerList_SelectionChanged"
39+
FontSize="13"/>
40+
</Border>
41+
</Popup>
42+
</Grid>
2143

2244
<!-- Authentication -->
2345
<TextBlock Grid.Row="2" Text="Authentication" Foreground="{DynamicResource ForegroundBrush}"

src/PlanViewer.App/Dialogs/ConnectionDialog.axaml.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ public ConnectionDialog(ICredentialService credentialService, ConnectionStore co
3434
private void PopulateSavedServers()
3535
{
3636
_savedConnections = _connectionStore.Load();
37-
var serverNames = _savedConnections.Select(s => s.ServerName).Distinct().ToList();
38-
ServerNameBox.ItemsSource = serverNames;
37+
var serverNames = _savedConnections
38+
.OrderByDescending(s => s.LastConnected)
39+
.Select(s => s.ServerName)
40+
.Distinct()
41+
.ToList();
42+
ServerList.ItemsSource = serverNames;
3943

4044
// Pre-fill the most recently used connection
4145
var mostRecent = _savedConnections
@@ -84,12 +88,14 @@ private void ApplySavedConnection(ServerConnection saved)
8488
}
8589
}
8690

87-
// When the user picks a saved server from the autocomplete dropdown
88-
private void ServerName_SelectionChanged(object? sender, SelectionChangedEventArgs e)
91+
private void ServerList_SelectionChanged(object? sender, SelectionChangedEventArgs e)
8992
{
90-
var serverName = ServerNameBox.SelectedItem?.ToString();
93+
var serverName = ServerList.SelectedItem?.ToString();
9194
if (string.IsNullOrEmpty(serverName)) return;
9295

96+
ServerNameBox.Text = serverName;
97+
ServerDropdown.IsOpen = false;
98+
9399
var saved = _savedConnections.FirstOrDefault(s =>
94100
s.ServerName.Equals(serverName, StringComparison.OrdinalIgnoreCase));
95101

@@ -190,6 +196,12 @@ private void Connect_Click(object? sender, RoutedEventArgs e)
190196
Close(true);
191197
}
192198

199+
private void DropdownButton_Click(object? sender, RoutedEventArgs e)
200+
{
201+
ServerDropdown.MinWidth = ServerNameGrid.Bounds.Width;
202+
ServerDropdown.IsOpen = !ServerDropdown.IsOpen;
203+
}
204+
193205
private void Cancel_Click(object? sender, RoutedEventArgs e)
194206
{
195207
Close(false);

0 commit comments

Comments
 (0)