Skip to content

Commit

Permalink
Update Summary2 and Subform when updating component id
Browse files Browse the repository at this point in the history
  • Loading branch information
mlqn committed Dec 20, 2024
1 parent 1739b58 commit f837897
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 86 deletions.
16 changes: 15 additions & 1 deletion backend/src/Designer/Controllers/AppDevelopmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,24 @@ await _mediator.Publish(new LayoutPageDeletedEvent
/// <param name="app">Application identifier which is unique within an organisation.</param>
/// <param name="layoutSetName">Name of the layout set the specific layout belongs to</param>
/// <param name="layoutName">The current name of the form layout</param>
/// <param name="cancellationToken">An <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
/// <returns>A success message if the save was successful</returns>
[HttpPost]
[Route("form-layout-name/{layoutName}")]
public ActionResult UpdateFormLayoutName(string org, string app, [FromQuery] string layoutSetName, [FromRoute] string layoutName, [FromBody] string newName)
public async Task<ActionResult> UpdateFormLayoutName(string org, string app, [FromQuery] string layoutSetName, [FromRoute] string layoutName, [FromBody] string newName, CancellationToken cancellationToken)
{
try
{
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer);
_appDevelopmentService.UpdateFormLayoutName(editingContext, layoutSetName, layoutName, newName);
await _mediator.Publish(new LayoutPageIdChangedEvent
{
EditingContext = editingContext,
LayoutSetName = layoutSetName,
LayoutName = layoutName,
NewLayoutName = newName,
}, cancellationToken);
return Ok();
}
catch (FileNotFoundException exception)
Expand Down Expand Up @@ -407,6 +415,12 @@ public async Task<ActionResult> UpdateLayoutSetName(string org, string app, [Fro
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer);
LayoutSets layoutSets = await _appDevelopmentService.UpdateLayoutSetName(editingContext, layoutSetIdToUpdate, newLayoutSetName, cancellationToken);
await _mediator.Publish(new LayoutSetIdChangedEvent
{
EditingContext = editingContext,
LayoutSetName = layoutSetIdToUpdate,
NewLayoutSetName = newLayoutSetName,
}, cancellationToken);
return Ok(layoutSets);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ await fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotifica
async () =>
{
List<Reference> referencesToDelete = [new Reference("component", notification.LayoutSetName, notification.ComponentId)];
return await appDevelopmentService.DeleteReferencesFromLayouts(notification.EditingContext, referencesToDelete, cancellationToken);
return await appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToDelete, cancellationToken);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Events;
using Altinn.Studio.Designer.Hubs.SyncHub;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Services.Interfaces;
using MediatR;

Expand All @@ -13,12 +15,15 @@ public class ComponentIdChangedLayoutsHandler : INotificationHandler<ComponentId
{
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory;
private readonly IFileSyncHandlerExecutor _fileSyncHandlerExecutor;
private readonly IAppDevelopmentService _appDevelopmentService;

public ComponentIdChangedLayoutsHandler(IAltinnGitRepositoryFactory altinnGitRepositoryFactory,
IFileSyncHandlerExecutor fileSyncHandlerExecutor)
IFileSyncHandlerExecutor fileSyncHandlerExecutor,
IAppDevelopmentService appDevelopmentService)
{
_altinnGitRepositoryFactory = altinnGitRepositoryFactory;
_fileSyncHandlerExecutor = fileSyncHandlerExecutor;
_appDevelopmentService = appDevelopmentService;
}

public async Task Handle(ComponentIdChangedEvent notification, CancellationToken cancellationToken)
Expand All @@ -45,6 +50,10 @@ await _fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotific
hasChanges = true;
}
}

List<Reference> referencesToUpdate = [new Reference("component", notification.LayoutSetName, notification.OldComponentId, notification.NewComponentId)];
hasChanges = await _appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToUpdate, cancellationToken);

return hasChanges;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ await fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotifica
async () =>
{
List<Reference> referencesToDelete = [new Reference("page", notification.LayoutSetName, notification.LayoutName)];
return await appDevelopmentService.DeleteReferencesFromLayouts(notification.EditingContext, referencesToDelete, cancellationToken);
return await appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToDelete, cancellationToken);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Events;
using Altinn.Studio.Designer.Hubs.SyncHub;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Services.Interfaces;
using MediatR;

namespace Altinn.Studio.Designer.EventHandlers.LayoutPageDeleted;

public class LayoutPageIdChangedLayoutsHandler(IFileSyncHandlerExecutor fileSyncHandlerExecutor, IAppDevelopmentService appDevelopmentService) : INotificationHandler<LayoutPageIdChangedEvent>
{
public async Task Handle(LayoutPageIdChangedEvent notification, CancellationToken cancellationToken)
{
await fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification(
notification.EditingContext,
SyncErrorCodes.LayoutPageIdChangedLayoutsSyncError,
"layouts",
async () =>
{
List<Reference> referencesToUpdate = [new Reference("page", notification.LayoutSetName, notification.LayoutName, notification.NewLayoutName)];
return await appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToUpdate, cancellationToken);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ await fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotifica
async () =>
{
List<Reference> referencesToDelete = [new Reference("layoutSet", notification.LayoutSetName, notification.LayoutSetName)];
return await appDevelopmentService.DeleteReferencesFromLayouts(notification.EditingContext, referencesToDelete, cancellationToken);
return await appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToDelete, cancellationToken);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Events;
using Altinn.Studio.Designer.Hubs.SyncHub;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Services.Interfaces;
using MediatR;

namespace Altinn.Studio.Designer.EventHandlers.LayoutSetDeleted;

public class LayoutSetIdChangedLayoutsHandler(IFileSyncHandlerExecutor fileSyncHandlerExecutor, IAppDevelopmentService appDevelopmentService) : INotificationHandler<LayoutSetIdChangedEvent>
{
public async Task Handle(LayoutSetIdChangedEvent notification, CancellationToken cancellationToken)
{
await fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification(
notification.EditingContext,
SyncErrorCodes.LayoutSetIdChangedLayoutsSyncError,
"layouts",
async () =>
{
List<Reference> referencesToUpdate = [new Reference("layoutSet", notification.LayoutSetName, notification.LayoutSetName, notification.NewLayoutSetName)];
return await appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToUpdate, cancellationToken);
});
}
}
12 changes: 12 additions & 0 deletions backend/src/Designer/Events/LayoutPageIdChangedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Altinn.Studio.Designer.Models;
using MediatR;

namespace Altinn.Studio.Designer.Events;

public class LayoutPageIdChangedEvent : INotification
{
public AltinnRepoEditingContext EditingContext { get; set; }
public string LayoutSetName { get; set; }
public string LayoutName { get; set; }
public string NewLayoutName { get; set; }
}
11 changes: 11 additions & 0 deletions backend/src/Designer/Events/LayoutSetIdChangedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Altinn.Studio.Designer.Models;
using MediatR;

namespace Altinn.Studio.Designer.Events;

public class LayoutSetIdChangedEvent : INotification
{
public AltinnRepoEditingContext EditingContext { get; set; }
public string LayoutSetName { get; set; }
public string NewLayoutSetName { get; set; }
}
2 changes: 2 additions & 0 deletions backend/src/Designer/Hubs/SyncHub/SyncErrorCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ public static class SyncErrorCodes
public const string LayoutSetsDataTypeSyncError = nameof(LayoutSetsDataTypeSyncError);
public const string LayoutSetComponentIdSyncError = nameof(LayoutSetComponentIdSyncError);
public const string LayoutSetDeletedLayoutsSyncError = nameof(LayoutSetDeletedLayoutsSyncError);
public const string LayoutSetIdChangedLayoutsSyncError = nameof(LayoutSetIdChangedLayoutsSyncError);
public const string LayoutSetSubFormButtonSyncError = nameof(LayoutSetSubFormButtonSyncError);
public const string SettingsComponentIdSyncError = nameof(SettingsComponentIdSyncError);
public const string LayoutPageAddSyncError = nameof(LayoutPageAddSyncError);
public const string ComponentDeletedLayoutsSyncError = nameof(ComponentDeletedLayoutsSyncError);
public const string LayoutPageDeletedLayoutsSyncError = nameof(LayoutPageDeletedLayoutsSyncError);
public const string LayoutPageIdChangedLayoutsSyncError = nameof(LayoutPageIdChangedLayoutsSyncError);
}
14 changes: 1 addition & 13 deletions backend/src/Designer/Models/Reference.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
namespace Altinn.Studio.Designer.Models;

public class Reference
{
public string Type { get; }
public string LayoutSetName { get; }
public string Id { get; }

public Reference(string type, string layoutSetName, string id)
{
Type = type;
LayoutSetName = layoutSetName;
Id = id;
}
}
public record Reference(string Type, string LayoutSetName, string Id, string NewId = null);
Loading

0 comments on commit f837897

Please sign in to comment.