diff --git a/DBChatPro.UI/Components/Pages/Home.razor b/DBChatPro.UI/Components/Pages/Home.razor index 388f3f7..4fe9865 100644 --- a/DBChatPro.UI/Components/Pages/Home.razor +++ b/DBChatPro.UI/Components/Pages/Home.razor @@ -13,6 +13,7 @@ @inject IConfiguration config @inject AIService aiService @inject IJSRuntime JS +@inject IDialogService DialogService Home @@ -237,16 +238,30 @@ @if (Favorites.Count > 0) { Your saved queries for @ActiveConnection.Name + - - @foreach (var item in Favorites) + @foreach (var item in FilteredFavorites) { - + + + @item.Name + @if (!string.IsNullOrEmpty(item.Tags)) + { + + Tags: @item.Tags + + } + + } - } else { @@ -274,6 +289,16 @@ public string aiModel = ""; public string aiPlatform = ""; public string activeDatabase = ""; + + // Favorites filter + public string FavoritesFilter = ""; + private List FilteredFavorites => + string.IsNullOrWhiteSpace(FavoritesFilter) + ? Favorites + : Favorites.Where(f => + f.Name.Contains(FavoritesFilter, StringComparison.OrdinalIgnoreCase) || + (!string.IsNullOrEmpty(f.Tags) && f.Tags.Contains(FavoritesFilter, StringComparison.OrdinalIgnoreCase)) + ).ToList(); // General UI data private bool Loading = false; @@ -324,9 +349,21 @@ private async Task SaveFavorite() { - await queryService.SaveQuery(FmModel.Prompt, ActiveConnection.Name, QueryType.Favorite); - Favorites = await queryService.GetQueries(ActiveConnection.Name, QueryType.Favorite); - Snackbar.Add("Saved favorite!", Severity.Success); + var parameters = new DialogParameters + { + { x => x.Query, FmModel.Prompt } + }; + + var dialog = await DialogService.ShowAsync("Save Favorite", parameters); + var result = await dialog.Result; + + if (!result.Canceled && result.Data is SaveFavoriteDialog.SaveFavoriteResult favoriteResult) + { + await queryService.SaveQuery(FmModel.Prompt, ActiveConnection.Name, QueryType.Favorite, + favoriteResult.Name, favoriteResult.Tags); + Favorites = await queryService.GetQueries(ActiveConnection.Name, QueryType.Favorite); + Snackbar.Add("Saved favorite!", Severity.Success); + } } private async Task EditQuery() diff --git a/DBChatPro.UI/Components/SaveFavoriteDialog.razor b/DBChatPro.UI/Components/SaveFavoriteDialog.razor new file mode 100644 index 0000000..a01043e --- /dev/null +++ b/DBChatPro.UI/Components/SaveFavoriteDialog.razor @@ -0,0 +1,54 @@ +@using MudBlazor + + + + + + + + + + Cancel + Save Favorite + + + +@code { + [CascadingParameter] MudDialogInstance? MudDialog { get; set; } + + [Parameter] public string Query { get; set; } = string.Empty; + + public string FavoriteName { get; set; } = string.Empty; + public string Tags { get; set; } = string.Empty; + + protected override void OnInitialized() + { + // Default the favorite name to a shortened version of the query + if (!string.IsNullOrEmpty(Query)) + { + FavoriteName = Query.Length > 50 ? Query.Substring(0, 50) + "..." : Query; + } + } + + void Submit() + { + var result = new SaveFavoriteResult + { + Name = FavoriteName, + Tags = Tags + }; + MudDialog?.Close(DialogResult.Ok(result)); + } + + void Cancel() => MudDialog?.Cancel(); + + public class SaveFavoriteResult + { + public string Name { get; set; } = string.Empty; + public string Tags { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/DbChatPro.Core/Models/HistoryItem.cs b/DbChatPro.Core/Models/HistoryItem.cs index 16fcd9f..75ed4a6 100644 --- a/DbChatPro.Core/Models/HistoryItem.cs +++ b/DbChatPro.Core/Models/HistoryItem.cs @@ -10,6 +10,7 @@ public class HistoryItem : ITableEntity public string Name { get; set; } public string ConnectionName { get; set; } public QueryType QueryType { get; set; } + public string Tags { get; set; } = string.Empty; public string PartitionKey { get; set; } public string RowKey { get; set; } public DateTimeOffset? Timestamp { get; set; } diff --git a/DbChatPro.Core/Services/Queries/AzureTableQueryService.cs b/DbChatPro.Core/Services/Queries/AzureTableQueryService.cs index 403e0c9..2dc6bc5 100644 --- a/DbChatPro.Core/Services/Queries/AzureTableQueryService.cs +++ b/DbChatPro.Core/Services/Queries/AzureTableQueryService.cs @@ -7,6 +7,11 @@ namespace DBChatPro public class AzureTableQueryService(TableServiceClient tableServiceClient) : IQueryService { public async Task SaveQuery(string query, string connectionName, QueryType queryType) + { + await SaveQuery(query, connectionName, queryType, query, string.Empty); + } + + public async Task SaveQuery(string query, string connectionName, QueryType queryType, string customName, string tags) { TableClient client = tableServiceClient.GetTableClient( tableName: "queries" @@ -16,9 +21,10 @@ public async Task SaveQuery(string query, string connectionName, QueryType query { Id = new Random().Next(0, 10000), Query = query, - Name = query, + Name = customName, ConnectionName = connectionName, QueryType = queryType, + Tags = tags, RowKey = Guid.NewGuid().ToString(), PartitionKey = Enum.GetName(queryType), Timestamp = DateTime.Now diff --git a/DbChatPro.Core/Services/Queries/IQueryService.cs b/DbChatPro.Core/Services/Queries/IQueryService.cs index fcb6a0d..5e55726 100644 --- a/DbChatPro.Core/Services/Queries/IQueryService.cs +++ b/DbChatPro.Core/Services/Queries/IQueryService.cs @@ -6,5 +6,6 @@ public interface IQueryService { Task> GetQueries(string connectionName, QueryType queryType); Task SaveQuery(string query, string connectionName, QueryType queryType); + Task SaveQuery(string query, string connectionName, QueryType queryType, string customName, string tags); } } \ No newline at end of file diff --git a/DbChatPro.Core/Services/Queries/InMemoryQueryService.cs b/DbChatPro.Core/Services/Queries/InMemoryQueryService.cs index 3fc604c..e9d6152 100644 --- a/DbChatPro.Core/Services/Queries/InMemoryQueryService.cs +++ b/DbChatPro.Core/Services/Queries/InMemoryQueryService.cs @@ -12,14 +12,20 @@ public Task> GetQueries(string connectionName, QueryType query } public Task SaveQuery(string query, string connectionName, QueryType queryType) + { + return SaveQuery(query, connectionName, queryType, query, string.Empty); + } + + public Task SaveQuery(string query, string connectionName, QueryType queryType, string customName, string tags) { queries.Add(new HistoryItem() { Id = new Random().Next(0, 10000), Query = query, - Name = query, + Name = customName, ConnectionName = connectionName, - QueryType = queryType + QueryType = queryType, + Tags = tags }); return Task.CompletedTask;
Your saved queries for @ActiveConnection.Name