Skip to content

Commit

Permalink
#98 add ability to filter by content types (#99)
Browse files Browse the repository at this point in the history
bump avalonia versions
  • Loading branch information
cricketthomas authored Nov 10, 2024
1 parent cb82df6 commit a151120
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Desktop/Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@


<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="11.1.4" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0-rc.1.24431.7" />
</ItemGroup>


Expand Down
13 changes: 7 additions & 6 deletions KeyVaultExplorer/KeyVaultExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
<ApplicationIcon>AppIcon.ico</ApplicationIcon>
<PackageIcon>AppIcon.png</PackageIcon>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>


Expand Down Expand Up @@ -53,20 +54,20 @@

<ItemGroup>
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.1.4" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.4" />
<PackageReference Include="Avalonia.Svg.Skia" Version="11.1.0.1" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.0" />
<PackageReference Include="Avalonia.Svg.Skia" Version="11.2.0" />
<PackageReference Include="DeviceId" Version="6.7.0" />
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0-rc.1.24431.7" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="9.0.0-rc.1.24451.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0-rc.1.24431.7" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.65.3-preview" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.66.1" />
<PackageReference Include="Azure.ResourceManager.KeyVault" Version="1.3.0" />
<PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.6.0" />
<PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.6.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.6.0" />
<PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.7.0" />
<PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.7.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.7.0" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.10" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion KeyVaultExplorer/Services/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace KeyVaultExplorer;

public static class StringExtensions
{
public static byte[] ToByteArray(this string s) => s.ToByteSpan().ToArray(); // heap allocation, use only when you cannot operate on spans
public static byte[] ToByteArray(this string s) => s.ToByteSpan().ToArray();

public static ReadOnlySpan<byte> ToByteSpan(this string s) => MemoryMarshal.Cast<char, byte>(s);
}
10 changes: 6 additions & 4 deletions KeyVaultExplorer/ViewModels/VaultPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public async Task FilterAndLoadVaultValueType(KeyVaultItemType item)
{
var contents = item == KeyVaultItemType.All ? _vaultContents : _vaultContents.Where(x => item == x.Type);

VaultContents = KeyVaultFilterHelper.FilterByQuery(contents, SearchQuery, item => item.Name, item => item.Tags);
VaultContents = KeyVaultFilterHelper.FilterByQuery(contents, SearchQuery, item => item.Name, item => item.Tags, item => item.ContentType);

await DelaySetIsBusy(false);
}
Expand Down Expand Up @@ -382,7 +382,7 @@ partial void OnSearchQueryChanged(string value)
return;
}

VaultContents = KeyVaultFilterHelper.FilterByQuery(item != KeyVaultItemType.All ? _vaultContents.Where(k => k.Type == item) : _vaultContents, value ?? SearchQuery, item => item.Name, item => item.Tags);
VaultContents = KeyVaultFilterHelper.FilterByQuery(item != KeyVaultItemType.All ? _vaultContents.Where(k => k.Type == item) : _vaultContents, value ?? SearchQuery, item => item.Name, item => item.Tags, item => item.ContentType);
}

[RelayCommand]
Expand All @@ -402,7 +402,7 @@ private async Task Refresh()
if (item.HasFlag(KeyVaultItemType.All))
_vaultContents = [];

VaultContents = KeyVaultFilterHelper.FilterByQuery(_vaultContents.Where(v => v.Type != item), SearchQuery, item => item.Name, item => item.Tags);
VaultContents = KeyVaultFilterHelper.FilterByQuery(_vaultContents.Where(v => v.Type != item), SearchQuery, item => item.Name, item => item.Tags, item => item.ContentType);

await FilterAndLoadVaultValueType(item);
}
Expand Down Expand Up @@ -467,7 +467,8 @@ public static ObservableCollection<T> FilterByQuery<T>(
IEnumerable<T> source,
string query,
Func<T, string> nameSelector,
Func<T, IDictionary<string, string>> tagsSelector)
Func<T, IDictionary<string, string>> tagsSelector,
Func<T, string> contentTypeSelector)
{
if (string.IsNullOrEmpty(query))
{
Expand All @@ -476,6 +477,7 @@ public static ObservableCollection<T> FilterByQuery<T>(

var filteredItems = source.Where(item =>
nameSelector(item).AsSpan().Contains(query.AsSpan(), StringComparison.OrdinalIgnoreCase)
|| contentTypeSelector(item).AsSpan().Contains(query.AsSpan(), StringComparison.OrdinalIgnoreCase)
|| (tagsSelector(item)?.Any(tag =>
tag.Key.AsSpan().Contains(query.AsSpan(), StringComparison.OrdinalIgnoreCase)
|| tag.Value.AsSpan().Contains(query.AsSpan(), StringComparison.OrdinalIgnoreCase)) ?? false));
Expand Down
2 changes: 1 addition & 1 deletion KeyVaultExplorer/Views/Pages/VaultPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
Text="{Binding SearchQuery, Mode=TwoWay}"
TextChanged="SearchBoxChanges"
TextWrapping="NoWrap"
Watermark="Search names, tags (Ctrl+F)">
Watermark="Search names, tags, content types (Ctrl+F)">
<TextBox.Styles>
<Style Selector="TextBox">
<Setter Property="Background" Value="Transparent" />
Expand Down

0 comments on commit a151120

Please sign in to comment.