Skip to content

Commit

Permalink
Merge pull request #18246 from unoplatform/dev/mazi/samples-search
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund authored Jan 31, 2025
2 parents e5deea5 + 69df36f commit d1fc1c7
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using Private.Infrastructure;
using System.Reflection.Metadata;
using UITests.Shared.Helpers;
using System.Runtime.CompilerServices;

namespace SampleControl.Presentation
{
Expand Down Expand Up @@ -437,6 +438,11 @@ internal void OpenPlayground()
SetSelectedSample(CancellationToken.None, "Playground", "Playground");
}

internal async Task OpenSample(CancellationToken ct, SampleChooserContent content)
{
await SetSelectedSample(ct, content.ControlType.FullName);
}

internal async Task OpenRuntimeTests(CancellationToken ct)
{
IsSplitVisible = false;
Expand Down Expand Up @@ -629,13 +635,16 @@ private async Task<List<SampleChooserContent>> SearchAsync(string search, List<S
});
}

public void TryOpenSample()
public bool TryOpenSingleSearchResult()
{
if (FilteredSamples is { } samples
&& samples.Count is 1)
{
SelectedSearchSample = samples[0];
return true;
}

return false;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:ub="using:Uno.UI.Samples.Behaviors"
xmlns:uc="using:Uno.UI.Samples.Converters"
xmlns:helper="using:Uno.UI.Samples.Behaviors"
xmlns:entities="using:SampleControl.Entities"
xmlns:ios="http://umbrella/ios"
xmlns:not_win="http://uno.ui/not_win"
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Expand All @@ -31,18 +32,19 @@
<x:Double x:Key="TitleContainerHeight">45</x:Double>

<uc:FromNullableBoolToReverseBoolConverter x:Key="reverseBoolConverter" />

<!-- Styles -->
<Style x:Key="BaseTitleGridContainerStyle"
TargetType="Grid">
<Setter Property="BorderBrush"
Value="{ThemeResource Color05Brush}" />
<Setter Property="BorderThickness"
Value="0,0,0,1" />
Value="0,0,0,0" />
<Setter Property="Margin" Value="4" />
<Setter Property="Background"
Value="{ThemeResource ApplicationPageBackgroundThemeBrush}" />
<Setter Property="Height"
Value="50" />
Value="36" />
</Style>

<Style x:Key="BaseTitleContainerStyle"
Expand Down Expand Up @@ -245,14 +247,14 @@
toolkit:VisibleBoundsPadding.PaddingMask="All">

<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<!-- LIBRARY (Categories)-->
<Grid Style="{StaticResource BaseTitleGridContainerStyle}"
Height="80"
Visibility="{Binding CategoryVisibility, Converter={StaticResource TrueToVisible}}">

<Grid.ColumnDefinitions>
Expand All @@ -276,7 +278,7 @@
<u:PathControl Style="{StaticResource Icon_RuntimeTests}"
Margin="5,0" />
</Button>

<!-- Playground button -->
<Button Style="{StaticResource IconButtonStyle}"
Foreground="{ThemeResource AccentFillColorDefaultBrush}"
Expand Down Expand Up @@ -314,12 +316,11 @@
<u:PathControl Style="{StaticResource Icon_RunAll}"
Margin="5,0" />
</Button>

<CheckBox Grid.Row="1" Grid.ColumnSpan="5" HorizontalAlignment="Center"
IsChecked="{Binding ManualTestsOnly, Mode=TwoWay}" Content="Manual tests only" />
</Grid>


<ContentControl ContentTemplate="{StaticResource CategoriesList}"
Grid.Row="1"
Grid.Row="2"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Visibility="{Binding CategoryVisibility, Converter={StaticResource TrueToVisible}}" />
Expand All @@ -329,9 +330,11 @@
VerticalContentAlignment="Stretch"
Visibility="{Binding SampleVisibility, Converter={StaticResource TrueToVisible}}"
ContentTemplate="{StaticResource SamplesTitle}" />


<ContentControl HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Grid.Row="1"
Grid.Row="2"
Visibility="{Binding SampleVisibility, Converter={StaticResource TrueToVisible}}"
ContentTemplate="{StaticResource SamplesList}" />

Expand All @@ -345,7 +348,7 @@
</Grid>
<ContentControl HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Grid.Row="1"
Grid.Row="2"
Visibility="{Binding FavoritesVisibility, Converter={StaticResource TrueToVisible}}"
ContentTemplate="{StaticResource FavoritesList}" />

Expand All @@ -359,33 +362,42 @@
</Grid>
<ContentControl HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Grid.Row="1"
Grid.Row="2"
Visibility="{Binding RecentsVisibility, Converter={StaticResource TrueToVisible}}"
ContentTemplate="{StaticResource RecentSamplesList}" />

<!--SEARCH-->
<Grid Style="{StaticResource BaseTitleGridContainerStyle}"
Visibility="{Binding SearchVisibility, Converter={StaticResource TrueToVisible}}">
<TextBlock Style="{StaticResource Typo03}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Text="Search" />
</Grid>
<ContentControl HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Grid.Row="1"
Visibility="{Binding SearchVisibility, Converter={StaticResource TrueToVisible}}"
ContentTemplate="{StaticResource SearchList}" />
<StackPanel Grid.Row="1" Spacing="4" Padding="4" BorderThickness="0,0,0,1"
BorderBrush="{StaticResource Color05Brush}">
<!-- Search -->
<AutoSuggestBox PlaceholderText="Search..."
TextChanged="SearchBox_TextChanged"
TextMemberPath="ControlName"
QueryIcon="Find"
ItemsSource="{Binding FilteredSamples}"
HorizontalAlignment="Stretch"
QuerySubmitted="SearchBox_QuerySubmitted"
SuggestionChosen="SearchBox_SuggestionChosen">
<AutoSuggestBox.ItemTemplate>
<DataTemplate x:DataType="entities:SampleChooserContent">
<TextBlock Text="{x:Bind ControlName}" />
</DataTemplate>
</AutoSuggestBox.ItemTemplate>
</AutoSuggestBox>


<CheckBox Grid.Row="1" Grid.ColumnSpan="5" HorizontalAlignment="Center"
IsChecked="{Binding ManualTestsOnly, Mode=TwoWay}" Content="Manual tests only" />
</StackPanel>

<!--NAVIGATION BUTTONS-->
<Border Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"

BorderThickness="0,1,0,0"
BorderBrush="{StaticResource Color05Brush}"
Height="50"
Grid.Row="2">
Grid.Row="3">
<u:StarStackPanel VerticalAlignment="Stretch"
Sizes="*,*,*,*"
Sizes="*,*,*"
Orientation="Horizontal">
<!--Button foreground has to be set by converter instead of Button's visual state
because path foreground doesn't change through visual states.-->
Expand Down Expand Up @@ -427,20 +439,6 @@
Text="Recents" />
</StackPanel>
</RadioButton>

<RadioButton GroupName="SelectedSectionPhone"
Style="{StaticResource SampleChooserNavRadioButtonStyle}"
VerticalContentAlignment="Stretch"
IsChecked="{Binding SearchSelected, Mode=TwoWay}"
Command="{Binding ShowNewSectionCommand}"
CommandParameter="Search">
<StackPanel VerticalAlignment="Center" Orientation="Vertical">
<FontIcon Glyph="&#xE721;" />
<TextBlock Style="{StaticResource Typo06}"
VerticalAlignment="Bottom"
Text="Search" />
</StackPanel>
</RadioButton>
</u:StarStackPanel>
</Border>
</Grid>
Expand Down Expand Up @@ -540,7 +538,7 @@
<FontIcon Glyph="&#xE734;" Visibility="{Binding CurrentSelectedSample.IsFavorite, Mode=OneWay, Converter={StaticResource TrueToCollapsed}}" />
<FontIcon Foreground="{ThemeResource AccentFillColorDefaultBrush}" Glyph="&#xE735;" Visibility="{Binding CurrentSelectedSample.IsFavorite, Mode=OneWay, Converter={StaticResource TrueToVisible}}" />
</Grid>

</Button>

<!-- Dark theme check box -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
using Microsoft.UI.Xaml;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.UI.Xaml.Input;
using System.Threading;
using SampleControl.Entities;


#if WINAPPSDK
using Windows.Foundation.Collections;
using Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -63,7 +67,31 @@ private void OnSearchEnterKey_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
((SampleChooserViewModel)DataContext).TryOpenSample();
((SampleChooserViewModel)DataContext).TryOpenSingleSearchResult();
}
}

private void SearchBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
((SampleChooserViewModel)DataContext).SearchTerm = sender.Text;
}
}

private void SearchBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
if (args is not null)
{
((SampleChooserViewModel)DataContext).TryOpenSingleSearchResult();
}
}

private void SearchBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
if (args.SelectedItem is SampleChooserContent control)
{
_ = ((SampleChooserViewModel)DataContext).OpenSample(CancellationToken.None, control);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using SampleControl.Entities;

public class SampleSearchResult
{
private readonly SampleChooserContent _content;

public SampleSearchResult(SampleChooserContent content)
{
_content = content;
}

public string Title => _content.ControlName;

public override string ToString() => Title;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\UITests\Views\Converters\FromNullableToDefaultValueConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\UITests\Views\Converters\StringEmptyToVisibilityConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\UITests\Views\Converters\StringFormatConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\UITests\Views\Entities\SampleSearchResult.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\UITests\Views\Entities\Section.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\UITests\Views\Extensions\InputPanelExtensions.PanIntoView.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\UITests\Views\Helper\ContentNavigationBehavior.cs" />
Expand Down Expand Up @@ -132,4 +133,4 @@
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)SamplesApp.UnitTests.targets" />
</ItemGroup>
</Project>
</Project>

0 comments on commit d1fc1c7

Please sign in to comment.