Skip to content

Commit

Permalink
TestViewer: Better search and other minor tweaks (#7353)
Browse files Browse the repository at this point in the history
  • Loading branch information
chausner committed Oct 15, 2023
1 parent ab16dbd commit b2064f6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
34 changes: 12 additions & 22 deletions src/MudBlazor.UnitTests.Viewer/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
</MudAppBar>
<MudDrawer Open="@drawerOpen" DisableOverlay="true" Variant="DrawerVariant.Responsive" ClipMode="DrawerClipMode.Always" Breakpoint="Breakpoint.Sm">
<MudDrawerHeader>
<MudText Typo="Typo.h6">TestComponents</MudText>
<MudText Typo="Typo.h6">Test Components</MudText>
</MudDrawerHeader>
<MudList>
<MudNavMenu>
@foreach (var type in availableComponentTypes)
{
<MudListItem OnClick="@(() => selectedType = type)" @key="type.Name">@type.Name</MudListItem>
<MudNavLink OnClick="@(() => selectedType = type)" @key="type.Name">@type.Name</MudNavLink>
}
</MudList>
</MudNavMenu>
</MudDrawer>
<MudMainContent Class="mt-4">

Expand Down Expand Up @@ -66,17 +66,16 @@
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
availableComponentTypes = getTestComponenTypes().ToArray();
availableComponentTypes = getTestComponentTypes().ToArray();
}

RenderFragment TestComponent() => builder =>
{
builder.OpenComponent(0, selectedType);
//builder.AddAttribute(1, "Title", "Some title");
builder.CloseComponent();
};

IEnumerable<Type> getTestComponenTypes()
IEnumerable<Type> getTestComponentTypes()
{
foreach (var type in typeof(Program).Assembly.GetTypes().OrderBy(x => x.Name))
{
Expand All @@ -102,28 +101,19 @@
{
if (type == null)
return "";
try
{
var field = type.GetField("__description__", BindingFlags.Public | BindingFlags.Static | BindingFlags.GetField);
return (string)field.GetValue(null);
}
catch (Exception)
{
return "public static string __description__ = \"...\"; not found in this component.";
}
var field = type.GetField("__description__", BindingFlags.Public | BindingFlags.Static | BindingFlags.GetField);
if (field == null || field.FieldType != typeof(string))
return "This test component does not have a description. Field \"public static string __description__\" not found in this component.";
return (string)field.GetValue(null);
}

private Task<IEnumerable<Type>> Search(string text)
{
if (string.IsNullOrWhiteSpace(text))
{
// the user just clicked the autocomplete open, show the most popular pages as search result according to our analytics data
// ordered by popularity
return Task.FromResult<IEnumerable<Type>>(new Type[0]);
}
var lowerText = text.ToLowerInvariant();

return Task.FromResult<IEnumerable<Type>>(
availableComponentTypes.Where(type => type.Name.ToLowerInvariant().StartsWith(lowerText))
availableComponentTypes.Where(type => type.Name.Contains(text, StringComparison.OrdinalIgnoreCase))
);
}

Expand Down
12 changes: 11 additions & 1 deletion src/MudBlazor.UnitTests.Viewer/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
@inherits LayoutComponentBase

<MudThemeProvider/>
<MudThemeProvider Theme="@customTheme"/>
<MudDialogProvider/>
<MudSnackbarProvider/>

@Body

@code {
MudTheme customTheme = new MudTheme()
{
LayoutProperties = new LayoutProperties()
{
DrawerWidthLeft = "350px"
}
};
}

0 comments on commit b2064f6

Please sign in to comment.