-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
729 additions
and
106 deletions.
There are no files selected for viewing
92 changes: 13 additions & 79 deletions
92
...end/src/Designer/EventHandlers/ProcessTaskIdChanged/ProcessTaskIdChangedLayoutsHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,35 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.Json.Nodes; | ||
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.ProcessTaskIdChanged; | ||
|
||
public class ProcessTaskIdChangedLayoutsHandler : INotificationHandler<ProcessTaskIdChangedEvent> | ||
{ | ||
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory; | ||
private readonly IFileSyncHandlerExecutor _fileSyncHandlerExecutor; | ||
private readonly IAppDevelopmentService _appDevelopmentService; | ||
|
||
public ProcessTaskIdChangedLayoutsHandler(IAltinnGitRepositoryFactory altinnGitRepositoryFactory, | ||
IFileSyncHandlerExecutor fileSyncHandlerExecutor) | ||
public ProcessTaskIdChangedLayoutsHandler(IFileSyncHandlerExecutor fileSyncHandlerExecutor, IAppDevelopmentService appDevelopmentService) | ||
{ | ||
_altinnGitRepositoryFactory = altinnGitRepositoryFactory; | ||
_fileSyncHandlerExecutor = fileSyncHandlerExecutor; | ||
_appDevelopmentService = appDevelopmentService; | ||
} | ||
|
||
public async Task Handle(ProcessTaskIdChangedEvent notification, CancellationToken cancellationToken) | ||
{ | ||
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) | ||
await _fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification( | ||
notification.EditingContext, | ||
SyncErrorCodes.LayoutTaskIdSyncError, | ||
"layouts", | ||
async () => | ||
{ | ||
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; | ||
List<Reference> referencesToUpdate = [new Reference("task", null, notification.OldId, notification.NewId)]; | ||
return await _appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToUpdate, cancellationToken); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...ttd/app-with-summary2-components-after-updating-references/App/ui/component/Settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"$schema": "https://altinncdn.no/schemas/json/layout/layoutSettings.schema.v1.json", | ||
"pages": { | ||
"order": [ | ||
"Side1", | ||
"Side2" | ||
] | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...pp-with-summary2-components-after-updating-references/App/ui/component/layouts/Side1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/layout/layout.schema.v1.json", | ||
"data": { | ||
"layout": [ | ||
{ | ||
"target": { | ||
"type": "layoutSet", | ||
"id": "", | ||
"taskId": "" | ||
}, | ||
"id": "Summary2-9iG1lB", | ||
"type": "Summary2" | ||
}, | ||
{ | ||
"target": { | ||
"type": "page", | ||
"id": "Side1", | ||
"taskId": "" | ||
}, | ||
"id": "Summary2-R8HsuB", | ||
"type": "Summary2" | ||
}, | ||
{ | ||
"target": { | ||
"type": "page", | ||
"id": "Side2", | ||
"taskId": "" | ||
}, | ||
"id": "Summary2-mL8NjJ", | ||
"type": "Summary2", | ||
"overrides": [ | ||
{ | ||
"componentId": "Input-Om7N3y-new", | ||
"displayType": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"target": { | ||
"type": "component", | ||
"id": "Input-qWr0oa", | ||
"taskId": "" | ||
}, | ||
"id": "Summary2-0BV88Q", | ||
"type": "Summary2" | ||
}, | ||
{ | ||
"target": { | ||
"type": "component", | ||
"id": "Input-Om7N3y-new", | ||
"taskId": "" | ||
}, | ||
"id": "Summary2-dTepe0", | ||
"type": "Summary2" | ||
}, | ||
{ | ||
"id": "NavigationButtons-DfcNol", | ||
"showBackButton": true, | ||
"textResourceBindings": {}, | ||
"type": "NavigationButtons" | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.