Browse Source

Fixed problem with built in filters not being refreshed properly

Kenric Nugteren 1 week ago
parent
commit
47c62ff165

+ 19 - 0
InABox.Core/CoreUtils.cs

@@ -3044,6 +3044,25 @@ namespace InABox.Core
             Task.WaitAll(nonNull);
         }
 
+        /// <summary>
+        /// Ensures that once this task is finished, any error will be logged.
+        /// </summary>
+        public static Task LogIfFail(this Task task)
+        {
+            return task.ContinueWith(task =>
+            {
+                var exception = task.Exception;
+                if(exception is AggregateException e && e.InnerException != null)
+                {
+                    LogException("", e.InnerException);
+                }
+                else if (exception != null)
+                {
+                    LogException("", task.Exception);
+                }
+            });
+        }
+
         #endregion
 
     }

+ 2 - 1
InABox.Core/Objects/Editors/DateTimeEditor.cs

@@ -1,4 +1,5 @@
-namespace InABox.Core
+
+namespace InABox.Core
 {
     public class DateTimeEditor : BaseEditor
     {

+ 15 - 3
inabox.wpf/DynamicGrid/DynamicGridFilterButtonComponent.cs

@@ -56,7 +56,7 @@ public class DynamicGridFilterComponentBuiltInFilter<T>(string name, Func<Filter
 
     public Filter<T1>? AsFilter<T1>()
     {
-        return GetFilter() as Filter<T1>;
+        return null;
     }
 }
 
@@ -78,6 +78,18 @@ public abstract class DynamicGridFilterComponent<T>
             Filter = filter;
             Definition = definition;
         }
+
+        public Filter<T>? GetFilter()
+        {
+            if(Definition is DynamicGridFilterComponentBuiltInFilter<T> definition)
+            {
+                return definition.GetFilter();
+            }
+            else
+            {
+                return Filter;
+            }
+        }
     }
 
     private List<FilterItem> SelectedFilters = new();
@@ -357,7 +369,7 @@ public abstract class DynamicGridFilterComponent<T>
             var builtIn = BuiltInFilters.FirstOrDefault(x => x.Name == filter.Name);
             if(builtIn is not null)
             {
-                SelectedFilters.Add(new(filter.Name, builtIn.AsFilter<T>(), builtIn));
+                SelectedFilters.Add(new(filter.Name, null, builtIn));
             }
             else
             {
@@ -421,7 +433,7 @@ public abstract class DynamicGridFilterComponent<T>
     public Filter<T>? GetFilter()
     {
         var filters = new Filters<T>();
-        filters.AddRange(SelectedFilters.Select(x => x.Filter));
+        filters.AddRange(SelectedFilters.Select(x => x.GetFilter()));
         filters.Add(TemporaryFilter);
         return filters.Combine();
     }