Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 44 additions & 7 deletions DBChatPro.UI/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@inject IConfiguration config
@inject AIService aiService
@inject IJSRuntime JS
@inject IDialogService DialogService

<PageTitle>Home</PageTitle>
<MudContainer MaxWidth="MaxWidth.ExtraExtraLarge" Fixed="false">
Expand Down Expand Up @@ -237,16 +238,30 @@
@if (Favorites.Count > 0)
{
<p class="mb-6">Your saved queries for <b>@ActiveConnection.Name</b></p>
<MudTextField @bind-Value="FavoritesFilter"
Label="Filter favorites"
Placeholder="Search by name or tag..."
Adornment="Adornment.Start"
AdornmentIcon="Icons.Material.Filled.Search"
Class="mb-4" />
<MudPaper>

@foreach (var item in Favorites)
@foreach (var item in FilteredFavorites)
{
<MudList Clickable="true">
<MudListItem OnClick="() => LoadQuery(item.Query)" Text="@item.Name" />
<MudListItem OnClick="() => LoadQuery(item.Query)">
<div>
<MudText Typo="Typo.body1">@item.Name</MudText>
@if (!string.IsNullOrEmpty(item.Tags))
{
<MudText Typo="Typo.caption" Class="mt-1">
Tags: @item.Tags
</MudText>
}
</div>
</MudListItem>
</MudList>
}
</MudPaper>

}
else
{
Expand Down Expand Up @@ -274,6 +289,16 @@
public string aiModel = "";
public string aiPlatform = "";
public string activeDatabase = "";

// Favorites filter
public string FavoritesFilter = "";
private List<HistoryItem> 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;
Expand Down Expand Up @@ -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<SaveFavoriteDialog>
{
{ x => x.Query, FmModel.Prompt }
};

var dialog = await DialogService.ShowAsync<SaveFavoriteDialog>("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()
Expand Down
54 changes: 54 additions & 0 deletions DBChatPro.UI/Components/SaveFavoriteDialog.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
@using MudBlazor

<MudDialog>
<DialogContent>
<MudContainer Style="max-height: 300px; overflow-y: scroll">
<MudTextField @bind-Value="FavoriteName" Label="Favorite Name"
HelperText="Give your favorite query a meaningful name"
Variant="Variant.Outlined" />
<MudTextField @bind-Value="Tags" Label="Tags"
HelperText="Add comma-separated tags (e.g., reporting, analytics, users)"
Variant="Variant.Outlined" Class="mt-4" />
</MudContainer>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit">Save Favorite</MudButton>
</DialogActions>
</MudDialog>

@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;
}
}
1 change: 1 addition & 0 deletions DbChatPro.Core/Models/HistoryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
8 changes: 7 additions & 1 deletion DbChatPro.Core/Services/Queries/AzureTableQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions DbChatPro.Core/Services/Queries/IQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public interface IQueryService
{
Task<List<HistoryItem>> 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);
}
}
10 changes: 8 additions & 2 deletions DbChatPro.Core/Services/Queries/InMemoryQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ public Task<List<HistoryItem>> 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;
Expand Down