-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Delete all Summary 2.0 components that has a reference to deleted component #14126
Draft
mlqn
wants to merge
6
commits into
main
Choose a base branch
from
13525-automatically-delete-all-summary-20-components-that-has-a-reference-to-deleted-element-component-page-or-layout-set
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f3c047d
Delete all Summary 2.0 components that has a reference to deleted com…
mlqn c1e2922
dotnet format
mlqn dd249f7
Fix SaveFormLayout
mlqn ab6681a
Merge remote-tracking branch 'origin/main' into 13525-automatically-d…
mlqn 1920a7b
Add backend tests
mlqn 8cbebb7
Cleanup
mlqn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
94 changes: 94 additions & 0 deletions
94
backend/src/Designer/EventHandlers/ComponentDeleted/ComponentDeletedSummaryRefHandler.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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System.Linq; | ||
using System.Text.Json.Nodes; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Altinn.App.Core.Helpers; | ||
using Altinn.Studio.Designer.Events; | ||
using Altinn.Studio.Designer.Hubs.SyncHub; | ||
using Altinn.Studio.Designer.Infrastructure.GitRepository; | ||
using Altinn.Studio.Designer.Models; | ||
using Altinn.Studio.Designer.Services.Interfaces; | ||
using MediatR; | ||
|
||
namespace Altinn.Studio.Designer.EventHandlers.ComponentDeleted; | ||
|
||
public class ComponentDeletedSummaryRefHandler : INotificationHandler<ComponentDeletedEvent> | ||
{ | ||
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory; | ||
private readonly IFileSyncHandlerExecutor _fileSyncHandlerExecutor; | ||
|
||
public ComponentDeletedSummaryRefHandler(IAltinnGitRepositoryFactory altinnGitRepositoryFactory, IFileSyncHandlerExecutor fileSyncHandlerExecutor) | ||
{ | ||
_altinnGitRepositoryFactory = altinnGitRepositoryFactory; | ||
_fileSyncHandlerExecutor = fileSyncHandlerExecutor; | ||
} | ||
|
||
public async Task Handle(ComponentDeletedEvent notification, CancellationToken cancellationToken) | ||
{ | ||
bool hasChanges = false; | ||
await _fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification( | ||
notification.EditingContext, | ||
SyncErrorCodes.ComponentDeletedSummaryRefSyncError, | ||
"layouts", | ||
async () => | ||
{ | ||
AltinnAppGitRepository repository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository( | ||
notification.EditingContext.Org, | ||
notification.EditingContext.Repo, | ||
notification.EditingContext.Developer); | ||
|
||
if (!repository.AppUsesLayoutSets()) | ||
{ | ||
return hasChanges; | ||
} | ||
|
||
return await DeleteSummaryComponents(repository, notification.LayoutSetName, notification.ComponentId, cancellationToken); | ||
}); | ||
|
||
} | ||
|
||
private async Task<bool> DeleteSummaryComponents(AltinnAppGitRepository altinnAppGitRepository, string deletedComponentLayoutSetId, string deletedComponentId, CancellationToken cancellationToken) | ||
{ | ||
bool hasChanged = false; | ||
|
||
LayoutSets layoutSets = await altinnAppGitRepository.GetLayoutSetsFile(cancellationToken); | ||
|
||
foreach (LayoutSetConfig layoutSetConfig in layoutSets.Sets) | ||
{ | ||
string[] layoutNames = altinnAppGitRepository.GetLayoutNames(layoutSetConfig.Id); | ||
foreach (string layoutName in layoutNames) | ||
{ | ||
JsonNode layout = await altinnAppGitRepository.GetLayout(layoutSetConfig.Id, layoutName); | ||
|
||
if (layout?["data"]?["layout"] is not JsonArray layoutArray) | ||
{ | ||
continue; | ||
} | ||
|
||
int initialCount = layoutArray.Count; | ||
layoutArray.RemoveAll(layoutObject => | ||
{ | ||
if (layoutObject["type"]?.GetValue<string>() != "Summary2" || layoutObject["target"] is not JsonObject targetObject) | ||
{ | ||
return false; | ||
} | ||
|
||
string summaryType = targetObject["type"]?.GetValue<string>(); | ||
string id = targetObject["id"]?.GetValue<string>(); | ||
string taskId = targetObject["taskId"]?.GetValue<string>(); | ||
string layouSetId = string.IsNullOrEmpty(taskId) ? layoutSetConfig.Id : layoutSets.Sets.FirstOrDefault(item => item.Tasks.Contains(taskId))?.Id; | ||
|
||
return summaryType == "component" && layouSetId == deletedComponentLayoutSetId && id == deletedComponentId; | ||
}); | ||
|
||
if (layoutArray.Count != initialCount) | ||
{ | ||
await altinnAppGitRepository.SaveLayout(layoutSetConfig.Id, layoutName, layout, cancellationToken); | ||
hasChanged = true; | ||
} | ||
} | ||
} | ||
|
||
return hasChanged; | ||
} | ||
} |
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,11 @@ | ||
using Altinn.Studio.Designer.Models; | ||
using MediatR; | ||
|
||
namespace Altinn.Studio.Designer.Events; | ||
|
||
public class ComponentDeletedEvent : INotification | ||
{ | ||
public string ComponentId { get; set; } | ||
public string LayoutSetName { get; set; } | ||
public AltinnRepoEditingContext EditingContext { get; set; } | ||
} |
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
13 changes: 13 additions & 0 deletions
13
...es/testUser/ttd/deleted-component-after-delete/App/ui/Activity_0z4cgvm/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,13 @@ | ||
{ | ||
"$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/layout/layout.schema.v1.json", | ||
"data": { | ||
"layout": [ | ||
{ | ||
"id": "NavigationButtons-DfcNol", | ||
"showBackButton": true, | ||
"textResourceBindings": {}, | ||
"type": "NavigationButtons" | ||
} | ||
] | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...es/testUser/ttd/deleted-component-after-delete/App/ui/Activity_0z4cgvm/layouts/Side2.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,13 @@ | ||
{ | ||
"$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/layout/layout.schema.v1.json", | ||
"data": { | ||
"layout": [ | ||
{ | ||
"id": "NavigationButtons-GAW8Dx", | ||
"showBackButton": true, | ||
"textResourceBindings": {}, | ||
"type": "NavigationButtons" | ||
} | ||
] | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...es/testUser/ttd/deleted-component-after-delete/App/ui/Activity_0z4cgvm/layouts/Side3.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,31 @@ | ||
{ | ||
"$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/layout/layout.schema.v1.json", | ||
"data": { | ||
"layout": [ | ||
{ | ||
"target": { | ||
"type": "component", | ||
"id": "Input-1GAVAE", | ||
"taskId": "Task_1" | ||
}, | ||
"id": "Summary2-PBrjWH", | ||
"type": "Summary2" | ||
}, | ||
{ | ||
"target": { | ||
"type": "component", | ||
"id": "", | ||
"taskId": "" | ||
}, | ||
"id": "Summary2-WokR5T", | ||
"type": "Summary2" | ||
}, | ||
{ | ||
"id": "NavigationButtons-Knkbt3", | ||
"showBackButton": true, | ||
"textResourceBindings": {}, | ||
"type": "NavigationButtons" | ||
} | ||
] | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...a/Repositories/testUser/ttd/deleted-component-after-delete/App/ui/form/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,21 @@ | ||
{ | ||
"$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/layout/layout.schema.v1.json", | ||
"data": { | ||
"hidden": false, | ||
"layout": [ | ||
{ | ||
"dataModelBindings": { | ||
"simpleBinding": "" | ||
}, | ||
"id": "Input-1GAVAE", | ||
"type": "Input" | ||
}, | ||
{ | ||
"id": "NavigationButtons-C2O3bE", | ||
"showBackButton": true, | ||
"textResourceBindings": {}, | ||
"type": "NavigationButtons" | ||
} | ||
] | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...a/Repositories/testUser/ttd/deleted-component-after-delete/App/ui/form/layouts/Side2.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,13 @@ | ||
{ | ||
"$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/layout/layout.schema.v1.json", | ||
"data": { | ||
"layout": [ | ||
{ | ||
"id": "NavigationButtons-TFHw9D", | ||
"showBackButton": true, | ||
"textResourceBindings": {}, | ||
"type": "NavigationButtons" | ||
} | ||
] | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...a/Repositories/testUser/ttd/deleted-component-after-delete/App/ui/form/layouts/Side3.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,31 @@ | ||
{ | ||
"$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/layout/layout.schema.v1.json", | ||
"data": { | ||
"layout": [ | ||
{ | ||
"target": { | ||
"type": "component", | ||
"id": "Input-1GAVAE", | ||
"taskId": "" | ||
}, | ||
"id": "Summary2-GcK8zp", | ||
"type": "Summary2" | ||
}, | ||
{ | ||
"target": { | ||
"type": "component", | ||
"id": "", | ||
"taskId": "" | ||
}, | ||
"id": "Summary2-3TdVTp", | ||
"type": "Summary2" | ||
}, | ||
{ | ||
"id": "NavigationButtons-tIAlCU", | ||
"showBackButton": true, | ||
"textResourceBindings": {}, | ||
"type": "NavigationButtons" | ||
} | ||
] | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...s/testUser/ttd/deleted-component-before-delete/App/ui/Activity_0z4cgvm/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,22 @@ | ||
{ | ||
"$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/layout/layout.schema.v1.json", | ||
"data": { | ||
"layout": [ | ||
{ | ||
"target": { | ||
"type": "component", | ||
"id": "Input-XDDxRp", | ||
"taskId": "Task_1" | ||
}, | ||
"id": "Summary2-QN78Y8", | ||
"type": "Summary2" | ||
}, | ||
{ | ||
"id": "NavigationButtons-DfcNol", | ||
"showBackButton": true, | ||
"textResourceBindings": {}, | ||
"type": "NavigationButtons" | ||
} | ||
] | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...s/testUser/ttd/deleted-component-before-delete/App/ui/Activity_0z4cgvm/layouts/Side2.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,22 @@ | ||
{ | ||
"$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/layout/layout.schema.v1.json", | ||
"data": { | ||
"layout": [ | ||
{ | ||
"target": { | ||
"type": "component", | ||
"id": "Input-XDDxRp", | ||
"taskId": "Task_1" | ||
}, | ||
"id": "Summary2-9OFVzC", | ||
"type": "Summary2" | ||
}, | ||
{ | ||
"id": "NavigationButtons-GAW8Dx", | ||
"showBackButton": true, | ||
"textResourceBindings": {}, | ||
"type": "NavigationButtons" | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Dereferenced variable may be null Warning test