Skip to content

Commit

Permalink
Remove update changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mlqn committed Jan 7, 2025
1 parent 3d2a84f commit f91bdbd
Show file tree
Hide file tree
Showing 31 changed files with 94 additions and 881 deletions.
42 changes: 13 additions & 29 deletions backend/src/Designer/Controllers/AppDevelopmentController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -123,27 +124,24 @@ public async Task<ActionResult> SaveFormLayout(string org, string app, [FromQuer

if (formLayoutPayload.ComponentIdsChange is not null && !string.IsNullOrEmpty(layoutSetName))
{
foreach (var componentIdChange in formLayoutPayload.ComponentIdsChange)
foreach (var componentIdChange in formLayoutPayload.ComponentIdsChange.Where((componentIdChange) => componentIdChange.OldComponentId != componentIdChange.NewComponentId))
{
if (componentIdChange.OldComponentId != componentIdChange.NewComponentId)
if (componentIdChange.NewComponentId == null)
{
if (componentIdChange.NewComponentId == null)
await _mediator.Publish(new ComponentDeletedEvent
{
await _mediator.Publish(new ComponentDeletedEvent
{
ComponentId = componentIdChange.OldComponentId,
LayoutSetName = layoutSetName,
EditingContext = editingContext
}, cancellationToken);
}
await _mediator.Publish(new ComponentIdChangedEvent
{
OldComponentId = componentIdChange.OldComponentId,
NewComponentId = componentIdChange.NewComponentId,
ComponentId = componentIdChange.OldComponentId,
LayoutSetName = layoutSetName,
EditingContext = editingContext
}, cancellationToken);
}
await _mediator.Publish(new ComponentIdChangedEvent
{
OldComponentId = componentIdChange.OldComponentId,
NewComponentId = componentIdChange.NewComponentId,
LayoutSetName = layoutSetName,
EditingContext = editingContext
}, cancellationToken);
}
}
if (!formLayouts.ContainsKey(layoutName))
Expand Down Expand Up @@ -207,24 +205,16 @@ 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 async Task<ActionResult> UpdateFormLayoutName(string org, string app, [FromQuery] string layoutSetName, [FromRoute] string layoutName, [FromBody] string newName, CancellationToken cancellationToken)
public ActionResult UpdateFormLayoutName(string org, string app, [FromQuery] string layoutSetName, [FromRoute] string layoutName, [FromBody] string newName)
{
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 @@ -415,12 +405,6 @@ 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
@@ -1,11 +1,9 @@
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 @@ -15,15 +13,13 @@ public class ComponentIdChangedLayoutsHandler : INotificationHandler<ComponentId
{
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory;
private readonly IFileSyncHandlerExecutor _fileSyncHandlerExecutor;
private readonly IAppDevelopmentService _appDevelopmentService;

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

public async Task Handle(ComponentIdChangedEvent notification, CancellationToken cancellationToken)
Expand All @@ -50,10 +46,6 @@ 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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,35 +1,101 @@
using System.Collections.Generic;
using System.IO;
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;

namespace Altinn.Studio.Designer.EventHandlers.ProcessTaskIdChanged;

public class ProcessTaskIdChangedLayoutsHandler : INotificationHandler<ProcessTaskIdChangedEvent>
{
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory;
private readonly IFileSyncHandlerExecutor _fileSyncHandlerExecutor;
private readonly IAppDevelopmentService _appDevelopmentService;

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

public async Task Handle(ProcessTaskIdChangedEvent notification, CancellationToken cancellationToken)
{
await _fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification(
notification.EditingContext,
SyncErrorCodes.LayoutTaskIdSyncError,
"layouts",
async () =>
var repository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(
notification.EditingContext.Org,
notification.EditingContext.Repo,
notification.EditingContext.Developer);

if (!repository.AppUsesLayoutSets())
{
return;
}

var layoutSetsFile = await repository.GetLayoutSetsFile(cancellationToken);

foreach (string layoutSetName in layoutSetsFile.Sets.Select(layoutSet => layoutSet.Id))
{
string[] layoutNames;
try
{
layoutNames = repository.GetLayoutNames(layoutSetName);
}
catch (FileNotFoundException)
{
List<Reference> referencesToUpdate = [new Reference("task", null, notification.OldId, notification.NewId)];
return await _appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToUpdate, cancellationToken);
});
continue;
}

await _fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification(
notification.EditingContext,
SyncErrorCodes.LayoutTaskIdSyncError,
$"App/ui/{layoutSetName}/layouts",
async () =>
{
bool hasChanged = false;

foreach (string layoutName in layoutNames)
{
var layout = await repository.GetLayout(layoutSetName, layoutName, cancellationToken);
if (TryChangeLayoutTaskIds(layout, notification.OldId, notification.NewId))
{
await repository.SaveLayout(layoutSetName, layoutName, layout, cancellationToken);
hasChanged = true;
}
}

return hasChanged;
});
}
}

private static bool TryChangeLayoutTaskIds(JsonNode node, string oldId, string newId)
{
bool hasChanged = false;

if (node is JsonObject jsonObject)
{
foreach (var property in jsonObject.ToList())
{
if (property.Key == "taskId" && property.Value?.ToString() == oldId)
{
jsonObject["taskId"] = newId;
hasChanged = true;
}

hasChanged |= TryChangeLayoutTaskIds(property.Value, oldId, newId);
}
}
else if (node is JsonArray jsonArray)
{
foreach (var element in jsonArray)
{
hasChanged |= TryChangeLayoutTaskIds(element, oldId, newId);
}
}

return hasChanged;
}
}
12 changes: 0 additions & 12 deletions backend/src/Designer/Events/LayoutPageIdChangedEvent.cs

This file was deleted.

11 changes: 0 additions & 11 deletions backend/src/Designer/Events/LayoutSetIdChangedEvent.cs

This file was deleted.

2 changes: 0 additions & 2 deletions backend/src/Designer/Hubs/SyncHub/SyncErrorCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ 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);
}
Loading

0 comments on commit f91bdbd

Please sign in to comment.