From f34bd701d0b8245cf5eb77f74bc5f5b315a4f2fc Mon Sep 17 00:00:00 2001 From: andreastanderen Date: Wed, 10 Jul 2024 15:02:48 +0200 Subject: [PATCH] Fix PR comments --- .../ComponentIdChangedLayoutsHandler.cs | 2 +- .../GitRepository/AltinnAppGitRepository.cs | 23 +------------------ .../Implementation/AppDevelopmentService.cs | 23 +++++++++++++++++-- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/backend/src/Designer/EventHandlers/ComponentIdChanged/ComponentIdChangedLayoutsHandler.cs b/backend/src/Designer/EventHandlers/ComponentIdChanged/ComponentIdChangedLayoutsHandler.cs index 1e54af60c35..74ea4ecde83 100644 --- a/backend/src/Designer/EventHandlers/ComponentIdChanged/ComponentIdChangedLayoutsHandler.cs +++ b/backend/src/Designer/EventHandlers/ComponentIdChanged/ComponentIdChangedLayoutsHandler.cs @@ -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; } } diff --git a/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs b/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs index 6710517ad80..5f06370e4bd 100644 --- a/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs +++ b/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs @@ -547,36 +547,15 @@ public async Task SaveLayoutSettings(string layoutSetName, JsonNode layoutSettin /// The name of the layout set where the layout belong /// The name of layout file /// The actual layout that is saved - /// Boolean value indicating if the layout to add is initial for a payment task /// An that observes if operation is cancelled. - 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); diff --git a/backend/src/Designer/Services/Implementation/AppDevelopmentService.cs b/backend/src/Designer/Services/Implementation/AppDevelopmentService.cs index 2d07177bbf9..6ae9eb117ff 100644 --- a/backend/src/Designer/Services/Implementation/AppDevelopmentService.cs +++ b/backend/src/Designer/Services/Implementation/AppDevelopmentService.cs @@ -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); } /// @@ -379,14 +379,33 @@ private static async Task DeleteExistingLayoutSet(AltinnAppGitReposi private static async Task 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 UpdateLayoutSetName(AltinnAppGitRepository altinnAppGitRepository, LayoutSets layoutSets, string oldLayoutSetName, string newLayoutSetName) { layoutSets.Sets.Find(set => set.Id == oldLayoutSetName).Id = newLayoutSetName;