Path: redb/redb.PropsEditor/Components/PropsGrid.razor Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.PropsEditor/Components/PropsGrid.razor ---- @using redb.Core @using redb.Core.Models.Entities @using redb.PropsEditor.Services @using Microsoft.FluentUI.AspNetCore.Components @inject IRedbService Redb @inject PropsMetadataService MetadataService @typeparam TProps where TProps : class, new() @* Grid view with CRUD operations for any Props type *@

@GetTypeName()

+ New Refresh
@if (loading) {

Loading...

} else if (items.Count == 0) {
No items found. Click "+ New" to create one.
} else { @foreach (var prop in GetDisplayProperties().Take(3)) { @GetDisplayValue(context, prop) } }
@* Edit Dialog *@ @code { private List> items = []; private List> filteredItems = []; private bool loading = true; private bool dialogHidden = true; private bool saving; private string searchText = ""; private FluentDialog? editDialog; private RedbObject? editingItem; protected override async Task OnInitializedAsync() { await LoadData(); } private async Task LoadData() { loading = true; try { items = await Redb.Query() .OrderByDescendingRedb(x => x.DateModify) .Take(1000) .ToListAsync(); ApplyFilter(); } catch (Exception ex) { Console.WriteLine($"Error loading data: {ex.Message}"); items = []; } finally { loading = false; } } private void HandleSearch() { ApplyFilter(); } private void ApplyFilter() { if (string.IsNullOrWhiteSpace(searchText)) { filteredItems = items; } else { var search = searchText.ToLowerInvariant(); filteredItems = items .Where(x => x.name?.ToLowerInvariant().Contains(search) == true) .ToList(); } } private string GetTypeName() => typeof(TProps).Name; private IEnumerable GetDisplayProperties() { return MetadataService.GetProperties() .Where(p => p.EditorType is EditorType.Text or EditorType.Checkbox or EditorType.Integer or EditorType.Decimal) .Take(5); } private string GetDisplayValue(RedbObject item, PropertyMetadata prop) { var val = prop.GetValue(item.Props); if (val == null) return "-"; if (val is bool b) return b ? "Yes" : "No"; var str = val.ToString() ?? ""; return str.Length > 50 ? str[..50] + "..." : str; } private void ShowCreateDialog() { editingItem = new RedbObject { Props = new TProps() }; dialogHidden = false; } private void ShowEditDialog(RedbObject item) { // Clone the entire object for editing var json = System.Text.Json.JsonSerializer.Serialize(item); editingItem = System.Text.Json.JsonSerializer.Deserialize>(json); dialogHidden = false; } private async Task SaveItem() { if (editingItem == null) return; saving = true; try { // Auto-set name from Name/Title property if not set if (string.IsNullOrEmpty(editingItem.name)) { var nameProperty = MetadataService.GetProperties() .FirstOrDefault(p => p.Name.Equals("Name", StringComparison.OrdinalIgnoreCase) || p.Name.Equals("Title", StringComparison.OrdinalIgnoreCase)); if (nameProperty != null) { editingItem.name = nameProperty.GetValue(editingItem.Props)?.ToString(); } } await Redb.SaveAsync(editingItem); dialogHidden = true; await LoadData(); } catch (Exception ex) { Console.WriteLine($"Error saving: {ex.Message}"); } finally { saving = false; } } private async Task DeleteItem(RedbObject item) { try { await Redb.DeleteAsync(item); await LoadData(); } catch (Exception ex) { Console.WriteLine($"Error deleting: {ex.Message}"); } } private void CloseDialog() { dialogHidden = true; editingItem = null; } }