-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
12993 change default name on nav button from nextback to nesteforrige (…
…#13249) * Add syncevent for navigation button texts when adding new page * Invalidate TextResource query for `resource.nb.json` sync success * Reload preview when TextResourcesQuery refetches with new data Remove accidental staged change * Remove unnecessary using directive * Add PreviewContextProvider to ux-editor app test * Remove queryinvalidator config for resource file as it is not needed * Add backend test for navbutton syncevent
- Loading branch information
Showing
7 changed files
with
160 additions
and
28 deletions.
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
65 changes: 65 additions & 0 deletions
65
backend/src/Designer/EventHandlers/LayoutPageAdded/LayoutPageAddedHandler.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,65 @@ | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
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.LayoutPageAdded; | ||
|
||
public class LayoutPageAddedHandler(IAltinnGitRepositoryFactory altinnGitRepositoryFactory, | ||
IFileSyncHandlerExecutor fileSyncHandlerExecutor) : INotificationHandler<LayoutPageAddedEvent> | ||
{ | ||
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory = altinnGitRepositoryFactory; | ||
private readonly IFileSyncHandlerExecutor _fileSyncHandlerExecutor = fileSyncHandlerExecutor; | ||
|
||
public async Task Handle(LayoutPageAddedEvent notification, CancellationToken cancellationToken) | ||
{ | ||
await _fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification( | ||
notification.EditingContext, | ||
SyncErrorCodes.LayoutPageAddSyncError, | ||
"App/config/texts/resource.nb.json", | ||
async () => | ||
{ | ||
AltinnAppGitRepository repository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository( | ||
notification.EditingContext.Org, | ||
notification.EditingContext.Repo, | ||
notification.EditingContext.Developer); | ||
if (!repository.AppUsesLayoutSets()) | ||
{ | ||
return false; | ||
} | ||
TextResource jsonTexts = await repository.GetTextV1("nb"); | ||
int initialCount = jsonTexts.Resources.Count; | ||
AddTextResourceIfNotExists(jsonTexts.Resources, "next", "neste"); | ||
AddTextResourceIfNotExists(jsonTexts.Resources, "back", "tilbake"); | ||
if (jsonTexts.Resources.Count != initialCount) | ||
{ | ||
await repository.SaveTextV1("nb", jsonTexts); | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a new TextResourceElement to the provided list if an element with the same id does not already exist. | ||
/// </summary> | ||
/// <param name="resources">The list of TextResourceElement to which the new element will be added.</param> | ||
/// <param name="id">The id of the TextResourceElement to be added.</param> | ||
/// <param name="value">The value of the TextResourceElement to be added.</param> | ||
private static void AddTextResourceIfNotExists(List<TextResourceElement> resources, string id, string value) | ||
{ | ||
if (!resources.Any(x => x.Id == id)) | ||
{ | ||
resources.Add(new TextResourceElement() { Id = id, Value = value }); | ||
} | ||
} | ||
} |
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 @@ | ||
using Altinn.Studio.Designer.Models; | ||
using MediatR; | ||
|
||
namespace Altinn.Studio.Designer.Events; | ||
|
||
public class LayoutPageAddedEvent : INotification | ||
{ | ||
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
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