Skip to content

Commit

Permalink
Fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren committed Jul 10, 2024
1 parent c081616 commit f34bd70
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ await _fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotific
var layout = await repository.GetLayout(notification.LayoutSetName, layoutName, cancellationToken);
if (TryChangeComponentId(layout, notification.OldComponentId, notification.NewComponentId))
{
await repository.SaveLayout(notification.LayoutSetName, layoutName, layout, false, cancellationToken);
await repository.SaveLayout(notification.LayoutSetName, layoutName, layout, cancellationToken);
hasChanges = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,36 +547,15 @@ public async Task SaveLayoutSettings(string layoutSetName, JsonNode layoutSettin
/// <param name="layoutSetName">The name of the layout set where the layout belong</param>
/// <param name="layoutFileName">The name of layout file</param>
/// <param name="layout">The actual layout that is saved</param>
/// <param name="layoutIsInitialForPaymentTask">Boolean value indicating if the layout to add is initial for a payment task</param>
/// <param name="cancellationToken">An <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
public async Task SaveLayout(string layoutSetName, string layoutFileName, JsonNode layout, bool layoutIsInitialForPaymentTask = false, CancellationToken cancellationToken = default)
public async Task SaveLayout(string layoutSetName, string layoutFileName, JsonNode layout, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
string layoutFilePath = GetPathToLayoutFile(layoutSetName, layoutFileName);
if (layoutIsInitialForPaymentTask)
{
AddPaymentComponentToInitialLayoutForPaymentTask(layout);
}

string serializedLayout = layout.ToJsonString(JsonOptions);
await WriteTextByRelativePathAsync(layoutFilePath, serializedLayout, true, cancellationToken);
}

private void AddPaymentComponentToInitialLayoutForPaymentTask(JsonNode layout)
{
var layoutArray = layout["data"]["layout"] as JsonArray;
if (layoutArray != null)
{
var defaultComponent = new JsonObject
{
["id"] = "PaymentComponentId",
["type"] = "Payment",
["renderAsSummary"] = true
};
layoutArray.Add(defaultComponent);
}
}

public void UpdateFormLayoutName(string layoutSetName, string layoutFileName, string newFileName)
{
string currentFilePath = GetPathToLayoutFile(layoutSetName, layoutFileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task SaveFormLayout(AltinnRepoEditingContext altinnRepoEditingConte
"This app uses layout sets, but no layout set name was provided for this request");
}

await altinnAppGitRepository.SaveLayout(layoutSetName, layoutFileName, formLayout, false, cancellationToken);
await altinnAppGitRepository.SaveLayout(layoutSetName, layoutFileName, formLayout, cancellationToken);
}

/// <inheritdoc />
Expand Down Expand Up @@ -379,14 +379,33 @@ private static async Task<LayoutSets> DeleteExistingLayoutSet(AltinnAppGitReposi
private static async Task<LayoutSets> AddNewLayoutSet(AltinnAppGitRepository altinnAppGitRepository, LayoutSets layoutSets, LayoutSetConfig layoutSet, bool layoutIsInitialForPaymentTask = false)
{
layoutSets.Sets.Add(layoutSet);
if (layoutIsInitialForPaymentTask)
{
AddPaymentComponentToInitialLayoutForPaymentTask(altinnAppGitRepository.InitialLayout);
}
await altinnAppGitRepository.SaveLayout(layoutSet.Id, AltinnAppGitRepository.InitialLayoutFileName,
altinnAppGitRepository.InitialLayout, layoutIsInitialForPaymentTask);
altinnAppGitRepository.InitialLayout);
await altinnAppGitRepository.SaveLayoutSettings(layoutSet.Id,
altinnAppGitRepository.InitialLayoutSettings);
await altinnAppGitRepository.SaveLayoutSets(layoutSets);
return layoutSets;
}

private static void AddPaymentComponentToInitialLayoutForPaymentTask(JsonNode layout)
{
var layoutArray = layout["data"]["layout"] as JsonArray;
if (layoutArray != null)
{
var defaultComponent = new JsonObject
{
["id"] = "PaymentComponentId",
["type"] = "Payment",
["renderAsSummary"] = true
};
layoutArray.Add(defaultComponent);
}
}

private async Task<LayoutSets> UpdateLayoutSetName(AltinnAppGitRepository altinnAppGitRepository, LayoutSets layoutSets, string oldLayoutSetName, string newLayoutSetName)
{
layoutSets.Sets.Find(set => set.Id == oldLayoutSetName).Id = newLayoutSetName;
Expand Down

0 comments on commit f34bd70

Please sign in to comment.