Skip to content

Commit

Permalink
Fix for sub dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
tznind committed Apr 14, 2024
1 parent 32317ed commit fa211d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions nfirestore-cli/TableFromCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Google.Cloud.Firestore;
using Newtonsoft.Json;
using System.Collections;
using Terminal.Gui;

namespace nfirestore_cli
Expand All @@ -15,7 +17,9 @@ public TableFromCollection(CollectionReference cr, IEnumerable<DocumentReference
{
Collection = cr;
_snaps = docs.ToDictionary(k => k, d => d.GetSnapshotAsync().Result.ToDictionary()).ToList();
_columns = _snaps.SelectMany(k=>k.Value.Keys).ToArray();
var cols = _snaps.SelectMany(k=>k.Value.Keys).Distinct().Order().ToList();
cols.Insert(0, "Id");
_columns = cols.ToArray();
}

public int Rows => _snaps.Count;
Expand All @@ -26,11 +30,22 @@ public TableFromCollection(CollectionReference cr, IEnumerable<DocumentReference

public object this[int row, int col] {
get {
var colName = _columns[col];
var colName = _columns[col];

return _snaps[row].Value.ContainsKey(colName) ? _snaps[row].Value[colName] : null;
}
}
if(col == 0)
{
return _snaps[row].Key.Id;
}

var val = _snaps[row].Value.ContainsKey(colName) ? _snaps[row].Value[colName] : null;

if (val is IDictionary)
{
val = JsonConvert.SerializeObject(val);
}

return val;
}
}
}
}
2 changes: 1 addition & 1 deletion nfirestore-cli/TabsPane.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa211d6

Please sign in to comment.