From 19ef5a514956b95432d95caa9767c416fc0a3be7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Sep 2025 19:27:17 +0000 Subject: [PATCH 1/3] Initial plan From 1b04d80084e9f1ddadf8875dbfeb29d2c11a42be Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Sep 2025 19:33:08 +0000 Subject: [PATCH 2/3] Implement named favorites with dialog and filtering Co-authored-by: alex-wolf-ps <33110774+alex-wolf-ps@users.noreply.github.com> --- DBChatPro.UI/Components/Pages/Home.razor | 51 +++++++++++++++--- .../Components/SaveFavoriteDialog.razor | 54 +++++++++++++++++++ DbChatPro.Core/Models/HistoryItem.cs | 1 + .../Queries/AzureTableQueryService.cs | 8 ++- .../Services/Queries/IQueryService.cs | 1 + .../Services/Queries/InMemoryQueryService.cs | 10 +++- 6 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 DBChatPro.UI/Components/SaveFavoriteDialog.razor 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..189b58c --- /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; From 8ef0f93b3320d8452a1df66c06cc08391193bfa8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Sep 2025 19:35:20 +0000 Subject: [PATCH 3/3] Fix nullable MudDialogInstance in SaveFavoriteDialog Co-authored-by: alex-wolf-ps <33110774+alex-wolf-ps@users.noreply.github.com> --- DBChatPro.UI/Components/SaveFavoriteDialog.razor | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DBChatPro.UI/Components/SaveFavoriteDialog.razor b/DBChatPro.UI/Components/SaveFavoriteDialog.razor index 189b58c..a01043e 100644 --- a/DBChatPro.UI/Components/SaveFavoriteDialog.razor +++ b/DBChatPro.UI/Components/SaveFavoriteDialog.razor @@ -18,7 +18,7 @@ @code { - [CascadingParameter] MudDialogInstance MudDialog { get; set; } + [CascadingParameter] MudDialogInstance? MudDialog { get; set; } [Parameter] public string Query { get; set; } = string.Empty; @@ -41,10 +41,10 @@ Name = FavoriteName, Tags = Tags }; - MudDialog.Close(DialogResult.Ok(result)); + MudDialog?.Close(DialogResult.Ok(result)); } - void Cancel() => MudDialog.Cancel(); + void Cancel() => MudDialog?.Cancel(); public class SaveFavoriteResult {