Browse Source

Fix to filter predicates

Kenric Nugteren 7 months ago
parent
commit
9734373755

+ 6 - 2
InABox.Core/CoreTreeNodes.cs

@@ -129,8 +129,7 @@ namespace InABox.Core
         
         public TKey DefaultKey { get; set; }
 
-        public ObservableCollection<CoreTreeNode<TKey>> Nodes => new ObservableCollection<CoreTreeNode<TKey>>(_nodes.Where(x => Equals(x.Parent, DefaultKey)));
-        
+        public ObservableCollection<CoreTreeNode<TKey>> Nodes { get; } = new ObservableCollection<CoreTreeNode<TKey>>();
         public CoreTreeNode<TKey>? this[TKey id] => _nodeMap.GetValueOrDefault(id);
         
         public CoreTreeNodes(TKey defaultKey)
@@ -145,6 +144,10 @@ namespace InABox.Core
             var node = new CoreTreeNode<TKey>(this, id, parent, row);
             _nodes.Add(node);
             _nodeMap[id] = node;
+            if(Equals(node.Parent, DefaultKey))
+            {
+                Nodes.Add(node);
+            }
             return node;
         }
 
@@ -152,6 +155,7 @@ namespace InABox.Core
         {
             _nodes.Clear();
             _nodeMap.Clear();
+            Nodes.Clear();
         }
 
         public CoreTreeNode<TKey> Find(TKey id) => _nodeMap.GetValueOrDefault(id);

+ 17 - 7
inabox.wpf/DynamicGrid/UIComponent/DynamicGridGridUIComponent.cs

@@ -628,23 +628,33 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         {
             var colIndex = DataGrid.Columns.IndexOf(column);
             var col = ColumnList[colIndex];
+            var filter = Parent.GetColumnFilter(col);
+
             if (col is DynamicGridColumn gridColumn)
             {
                 var rowPredicate = DynamicGridGridUIComponentExtension.ConvertColumnPredicates(gridColumn, column.FilterPredicates);
+                if(filter is not null)
+                {
+                    var oldPred = rowPredicate;
+                    if(oldPred is not null)
+                    {
+                        rowPredicate = row => oldPred(row) && filter.FilterRow(row);
+                    }
+                    else
+                    {
+                        rowPredicate = filter.FilterRow;
+                    }
+                }
                 if(rowPredicate is not null)
                 {
                     list.Add(new(gridColumn.ColumnName, rowPredicate));
                 }
             }
-            else if(col is DynamicActionColumn dac && dac.FilterRecord is not null)
+            else if(col is DynamicActionColumn dac)
             {
-                if(dac.SelectedFilters is not null && dac.SelectedFilters.Length > 0)
-                {
-                    list.Add(new(column.MappingName, (row) => dac.FilterRecord(row, dac.SelectedFilters)));
-                }
-                if(dac.ExcludeFilters is not null && dac.ExcludeFilters.Length > 0)
+                if(filter is not null)
                 {
-                    list.Add(new(column.MappingName, (row) => !dac.FilterRecord(row, dac.ExcludeFilters)));
+                    list.Add(new(column.MappingName, filter.FilterRow));
                 }
             }
         }

+ 17 - 7
inabox.wpf/DynamicGrid/UIComponent/DynamicGridTreeUIComponent.cs

@@ -604,23 +604,33 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
         {
             var colIndex = _tree.Columns.IndexOf(column);
             var col = ColumnList[colIndex];
+            var filter = Parent.GetColumnFilter(col);
+
             if (col is DynamicGridColumn gridColumn)
             {
                 var rowPredicate = DynamicGridGridUIComponentExtension.ConvertColumnPredicates(gridColumn, column.FilterPredicates);
+                if(filter is not null)
+                {
+                    var oldPred = rowPredicate;
+                    if(oldPred is not null)
+                    {
+                        rowPredicate = row => oldPred(row) && filter.FilterRow(row);
+                    }
+                    else
+                    {
+                        rowPredicate = filter.FilterRow;
+                    }
+                }
                 if(rowPredicate is not null)
                 {
                     list.Add(new(gridColumn.ColumnName, rowPredicate));
                 }
             }
-            else if(col is DynamicActionColumn dac && dac.FilterRecord is not null)
+            else if(col is DynamicActionColumn dac)
             {
-                if(dac.SelectedFilters is not null && dac.SelectedFilters.Length > 0)
-                {
-                    list.Add(new(column.MappingName, (row) => dac.FilterRecord(row, dac.SelectedFilters)));
-                }
-                if(dac.ExcludeFilters is not null && dac.ExcludeFilters.Length > 0)
+                if(filter is not null)
                 {
-                    list.Add(new(column.MappingName, (row) => !dac.FilterRecord(row, dac.ExcludeFilters)));
+                    list.Add(new(column.MappingName, filter.FilterRow));
                 }
             }
         }