Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve backwards compatibility for apps that use LayoutEvaluator.RemoveHiddenData #1053

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Altinn.App.Core/Helpers/DataModel/RowRemovalOption.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Altinn.App.Core.Helpers.DataModel;
// ReSharper disable once CheckNamespace // Namespace is kept after refactoring
namespace Altinn.App.Core.Helpers;

/// <summary>
/// Option for how to handle row removal
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.App.Core/Internal/App/IAppResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public interface IAppResources
/// <summary>
/// Gets the full layout model for the optional set
/// </summary>
[Obsolete("Use GetLayoutModelForTask instead", true)]
[Obsolete("Use GetLayoutModelForTask instead", false)]
LayoutModel GetLayoutModel(string? layoutSetId = null);

/// <summary>
Expand Down
13 changes: 11 additions & 2 deletions src/Altinn.App.Core/Internal/Expressions/LayoutEvaluator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Altinn.App.Core.Helpers.DataModel;
using Altinn.App.Core.Helpers;
using Altinn.App.Core.Models.Expressions;
using Altinn.App.Core.Models.Layout;
using Altinn.App.Core.Models.Layout.Components;
Expand Down Expand Up @@ -122,7 +122,16 @@ await HiddenFieldsForRemovalRecurs(
/// <summary>
/// Remove fields that are only referenced from hidden fields from the data object in the state.
/// </summary>
public static async Task RemoveHiddenData(LayoutEvaluatorState state, RowRemovalOption rowRemovalOption)
[Obsolete("Use the async version of this method RemoveHiddenDataAsync")]
public static void RemoveHiddenData(LayoutEvaluatorState state, RowRemovalOption rowRemovalOption)
{
RemoveHiddenDataAsync(state, rowRemovalOption).Wait();
}
ivarne marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Remove fields that are only referenced from hidden fields from the data object in the state.
/// </summary>
public static async Task RemoveHiddenDataAsync(LayoutEvaluatorState state, RowRemovalOption rowRemovalOption)
{
var fields = await GetHiddenFieldsForRemoval(state);
foreach (var dataReference in fields)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Altinn.App.Core.Configuration;
using Altinn.App.Core.Features;
using Altinn.App.Core.Helpers;
using Altinn.App.Core.Helpers.DataModel;
using Altinn.App.Core.Models;
using Altinn.App.Core.Models.Expressions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,18 @@ public DataElement GetDataElement(DataElementIdentifier dataElementIdentifier)
/// <summary>
/// Initialize LayoutEvaluatorState with given Instance, data object and layoutSetId
/// </summary>
[Obsolete("Use the overload with ILayoutEvaluatorStateInitializer instead")]
//[Obsolete("Use the overload with ILayoutEvaluatorStateInitializer instead")]
// We don't yet have a good alternative for this method
public async Task<LayoutEvaluatorState> Init(
Instance instance,
object data,
string? layoutSetId,
string? gatewayAction = null
)
{
#pragma warning disable CS0618 // Type or member is obsolete
var layouts = _appResources.GetLayoutModel(layoutSetId);
#pragma warning restore CS0618 // Type or member is obsolete
var dataElement = instance.Data.Find(d => d.DataType == layouts.DefaultDataType.Id);
Debug.Assert(dataElement is not null);
var appMetadata = await _appMetadata.GetApplicationMetadata();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json;
using Altinn.App.Core.Configuration;
using Altinn.App.Core.Helpers;
using Altinn.App.Core.Helpers.DataModel;
using Altinn.App.Core.Helpers.Serialization;
using Altinn.App.Core.Internal.App;
using Altinn.App.Core.Internal.AppModel;
Expand Down Expand Up @@ -105,7 +104,7 @@ private async Task RemoveFieldsOnTaskComplete(
gatewayAction: null,
language
);
await LayoutEvaluator.RemoveHiddenData(evaluationState, RowRemovalOption.DeleteRow);
await LayoutEvaluator.RemoveHiddenDataAsync(evaluationState, RowRemovalOption.DeleteRow);
}

// Remove shadow fields
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text.Json.Serialization;
using Altinn.App.Core.Helpers.DataModel;
using Altinn.App.Core.Helpers;
using Altinn.App.Core.Internal.Expressions;
using Altinn.App.Core.Models.Layout;
using FluentAssertions;
Expand Down Expand Up @@ -88,7 +88,7 @@ public async Task RemoveWholeGroup()
data.Some.Data[0].Binding2.Should().Be(0); // binding is not nullable, but will be reset to zero
data.Some.Data[1].Binding.Should().Be("binding");
data.Some.Data[1].Binding2.Should().Be(2);
await LayoutEvaluator.RemoveHiddenData(state, RowRemovalOption.DeleteRow);
await LayoutEvaluator.RemoveHiddenDataAsync(state, RowRemovalOption.DeleteRow);

// Verify data was removed
data.Some.Data[0].Binding.Should().BeNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text.Json.Serialization;
using Altinn.App.Core.Helpers.DataModel;
using Altinn.App.Core.Helpers;
using Altinn.App.Core.Internal.Expressions;
using Altinn.App.Core.Models.Layout;
using FluentAssertions;
Expand Down Expand Up @@ -73,7 +73,7 @@ public async Task RemoveRowDataFromGroup()
data.Some.Data[2].Binding.Should().Be("hideRow");
data.Some.Data[2].Binding2.Should().Be(3);
data.Some.Data[2].Binding3.Should().Be("text");
await LayoutEvaluator.RemoveHiddenData(state, RowRemovalOption.SetToNull);
await LayoutEvaluator.RemoveHiddenDataAsync(state, RowRemovalOption.SetToNull);

// Verify row not deleted but fields null
data.Some.Data.Should().HaveCount(3);
Expand Down Expand Up @@ -142,7 +142,7 @@ public async Task RemoveRowFromGroup()
data.Some.Data[2].Binding3.Should().Be("text");

// Verify rows deleted
await LayoutEvaluator.RemoveHiddenData(state, RowRemovalOption.DeleteRow);
await LayoutEvaluator.RemoveHiddenDataAsync(state, RowRemovalOption.DeleteRow);
data.Some.Data.Should().HaveCount(2);
data.Some.Data[0].Binding.Should().BeNull();
data.Some.Data[0].Binding2.Should().Be(0); // binding is not nullable, but will be reset to zero
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections;
using System.Text.Json;
using System.Text.Json.Serialization;
using Altinn.App.Core.Helpers;
using Altinn.App.Core.Helpers.DataModel;
using Altinn.App.Core.Tests.LayoutExpressions.TestUtilities;
using Altinn.Platform.Storage.Interface.Models;
Expand Down
Loading