Skip to content

Commit

Permalink
Fix issue with Removal of hidden data the way it is used for expressi…
Browse files Browse the repository at this point in the history
…on validation

* Add [DebuggerDisplay] for easier debugging
* Change ComponentContext.ChildContexts from IEnumerable to List<>
  • Loading branch information
ivarne committed Dec 13, 2024
1 parent 383c9e5 commit 92145ea
Show file tree
Hide file tree
Showing 7 changed files with 774 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Altinn.App.Core/Internal/Expressions/LayoutEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ ComponentContext context
// Ignore children of hidden rows if includeHiddenRowChildren is false
if (!includeHiddenRowChildren && childContext.Component is RepeatingGroupComponent)
{
if (childContext.ChildContexts.Count > 0)
{
continue;
}
var hiddenRows = await childContext.GetHiddenRows(state);
var currentRow = childContext.RowIndices?[^1];
var rowIsHidden = currentRow is not null && hiddenRows[currentRow.Value];
Expand Down
33 changes: 30 additions & 3 deletions src/Altinn.App.Core/Models/Expressions/ComponentContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using System.Diagnostics;
using Altinn.App.Core.Internal.Expressions;
using Altinn.App.Core.Models.Layout;
using Altinn.App.Core.Models.Layout.Components;
Expand All @@ -8,6 +9,8 @@ namespace Altinn.App.Core.Models.Expressions;
/// <summary>
/// Simple class for holding the context for <see cref="ExpressionEvaluator"/>
/// </summary>
[DebuggerDisplay("{_debuggerDisplay}", Name = "{_debuggerName}")]
[DebuggerTypeProxy(typeof(DebuggerProxy))]
public sealed class ComponentContext
{
private readonly int? _rowLength;
Expand All @@ -20,7 +23,7 @@ public ComponentContext(
int[]? rowIndices,
int? rowLength,
DataElementIdentifier dataElementIdentifier,
IEnumerable<ComponentContext>? childContexts = null
List<ComponentContext>? childContexts = null
)
{
DataElementIdentifier = dataElementIdentifier;
Expand Down Expand Up @@ -96,7 +99,7 @@ public async Task<BitArray> GetHiddenRows(LayoutEvaluatorState state)
rowIndices,
rowLength: hiddenRows.Length,
dataElementIdentifier: DataElementIdentifier,
childContexts: childContexts
childContexts: childContexts.ToList()
);
var rowHidden = await ExpressionEvaluator.EvaluateBooleanExpression(state, rowContext, "hiddenRow", false);

Expand All @@ -111,7 +114,7 @@ public async Task<BitArray> GetHiddenRows(LayoutEvaluatorState state)
/// <summary>
/// Contexts that logically belongs under this context (eg cell => row => group=> page)
/// </summary>
public IEnumerable<ComponentContext> ChildContexts { get; }
public List<ComponentContext> ChildContexts { get; }

/// <summary>
/// Parent context or null, if this is a root context, or a context created without setting parent
Expand Down Expand Up @@ -140,4 +143,28 @@ public IEnumerable<ComponentContext> Descendants
}
}
}

private string _debuggerName =>
$"{Component?.Type}" + (RowIndices is not null ? $"[{string.Join(',', RowIndices)}]" : "");
private string _debuggerDisplay =>
$"id:\"{Component?.Id}\"" + (ChildContexts.Count > 0 ? $"children:{ChildContexts.Count}" : "");

private class DebuggerProxy
{
private readonly ComponentContext _context;

[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public List<ComponentContext> ChildContexts => _context.ChildContexts;
public BaseComponent? Component => _context.Component;
public ComponentContext? Parent => _context.Parent;
public bool? IsHidden => _context._isHidden;
public string? HiddenRows =>
_context._hiddenRows is not null ? string.Join(',', _context._hiddenRows.GetEnumerator()) : null;
public Guid DataElementId => _context.DataElementIdentifier.Guid;

public DebuggerProxy(ComponentContext context)
{
_context = context;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public ComponentContext ToContext(LayoutModel? model, LayoutEvaluatorState state
rowLength: component is RepeatingGroupComponent ? 0 : null,
// TODO: get from data model, but currently not important for tests
state.GetDefaultDataElementId(),
ChildContexts.Select(c => c.ToContext(model, state))
ChildContexts.Select(c => c.ToContext(model, state)).ToList()
);
}

Expand Down
Loading

0 comments on commit 92145ea

Please sign in to comment.