-
Notifications
You must be signed in to change notification settings - Fork 9
Pages MetaData Editing Mode Support #29
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
bb946a5
MetaData Config & Render calls configured
robearlam 3c023f6
Configured metadata render method to correctly render page using new …
robearlam 5a1d70d
Moved GQL logic out of LC.CLient and back into Pages logic. Introduce…
robearlam 1c8752e
Wired up Placeholder and Rendering chromes
robearlam bd0dcde
Metadata editing now working
robearlam 2b99fc6
Wired up EditingDictionaryQuery requests
robearlam 5f34722
Fixed failing unit tests
robearlam 5494e8e
Added UnitTests for EditingScriptsTagHelper
robearlam d007e5b
Added UnitTests for Pages GQL Factory, and RenderingEngine TagHelpers
robearlam b92f31d
ComponentName is now persisted in rendering collection, to be returne…
robearlam 01a9228
Added UnitTests for Pages Config Middleware
robearlam 5be1780
Added Unit Tests for Pages Setup Render Middleware call
robearlam 4ea37ae
Added UniTests for GraphQLEditingServiceHandler
robearlam ddb0716
Added UniTests for EditingChromes being added to response for Pages r…
robearlam 328561f
Restructured test for Pages config middleware
robearlam c2851cb
Fixed bug with ImageTagHelper and ViewCompponent
robearlam 4d1c1dd
Moved PagesSetupMiddleware in a Controller, other small fixes
robearlam 9e5608e
Moved log messages into Resources RESX
robearlam fb2f772
Added Resources RESX to Pages project
robearlam d0938ba
Refactored PlaceHolder processing to use Stack approach instead of re…
robearlam d380f8e
Improved logic controlling when Pages middleware executes
robearlam 4570f44
Moved Dictionary functionality out of PagesGQLHandler into dedicated …
robearlam fa5202e
Removed GraphQlClient used for EditingHandler, added GraphQLClient wi…
robearlam f8eee28
Changed to no longer persist component names for predicate registrati…
robearlam ac8a933
Code TidyUp, fixed all warnings
robearlam 1af1068
Removed ID property from EdtiableField as didnt need to be added
robearlam af13261
Created Integration tests for PagesSetupController
robearlam 8109f8b
Added Integration test for succesful call to get editing layout with …
robearlam 0a08769
Added csproj missing from previous commit
robearlam 17e0b09
Improved logic for when to enable editing of Fields in MetaData editi…
robearlam 21f0e77
Added handling for /config route OPTIONS request
robearlam 4371c24
Fixed correct component naming for ViewComponents and PartialViews
robearlam 17e6f29
Aligned empty placeholder classname with jss
robearlam 8fd259f
Fixed issue with rendering of empty nested placeholders due to incorr…
robearlam 0bc23b7
Style refactor
IvanLieckens 64cb3d7
Fixed incorrect error being thrown from Config call
robearlam 8cfecbf
Changes from PR Review
robearlam 7e2b893
Moved MetaData Queries back from constants to improve readability
robearlam 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 hidden or 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
30 changes: 30 additions & 0 deletions
30
src/Sitecore.AspNetCore.SDK.LayoutService.Client/Response/Model/DataSource.cs
This file contains hidden or 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,30 @@ | ||
| using System.Runtime.Serialization; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model; | ||
|
|
||
| /// <summary> | ||
| /// Class used to define an items datasource information. | ||
| /// </summary> | ||
| public class DataSource | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the Id. | ||
| /// </summary> | ||
| public string Id { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the Language. | ||
| /// </summary> | ||
| public string Language { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the Revision. | ||
| /// </summary> | ||
| public string Revision { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the Version. | ||
| /// </summary> | ||
| public int Version { get; set; } | ||
| } |
This file contains hidden or 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 hidden or 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
33 changes: 33 additions & 0 deletions
33
src/Sitecore.AspNetCore.SDK.LayoutService.Client/Response/Model/MetaData.cs
This file contains hidden or 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,33 @@ | ||
| namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model; | ||
|
|
||
| /// <summary> | ||
| /// Class used to define an items metadata information. | ||
| /// </summary> | ||
| public class MetaData | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the title. | ||
| /// </summary> | ||
| public string Title { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the FieldId. | ||
| /// </summary> | ||
| public string FieldId { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the FieldType. | ||
| /// </summary> | ||
| public string FieldType { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the RawValue. | ||
| /// </summary> | ||
| public string RawValue { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the DataSource. | ||
| /// </summary> | ||
| public DataSource? DataSource { get; set; } | ||
|
|
||
| } |
This file contains hidden or 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
6 changes: 6 additions & 0 deletions
6
src/Sitecore.AspNetCore.SDK.Pages/Configuration/PagesMarkerService.cs
This file contains hidden or 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,6 @@ | ||
| namespace Sitecore.AspNetCore.SDK.Pages.Configuration; | ||
|
|
||
| /// <summary> | ||
| /// Marker service used to identify when Pages services have been registered. | ||
| /// </summary> | ||
| internal class PagesMarkerService; |
32 changes: 32 additions & 0 deletions
32
src/Sitecore.AspNetCore.SDK.Pages/Configuration/PagesOptions.cs
This file contains hidden or 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,32 @@ | ||
| namespace Sitecore.AspNetCore.SDK.Pages.Configuration; | ||
|
|
||
| /// <summary> | ||
| /// The options to configure the Pages middleware. | ||
| /// </summary> | ||
| public class PagesOptions | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the config endpoint for Pages MetaData mode. | ||
| /// </summary> | ||
| public string? ConfigEndpoint { get; set; } = "/api/editing/config"; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the render endpoint for Pages MetaData mode. | ||
| /// </summary> | ||
| public string? RenderEndpoint { get; set; } = "/api/editing/render"; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the valid editing origin for all editing requests. | ||
| /// </summary> | ||
| public string? ValidEditingOrigin { get; set; } = "https://pages.sitecorecloud.io"; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the valid origins for the head to run under. | ||
| /// </summary> | ||
| public string? ValidOrigins { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the Editing Secret. | ||
| /// </summary> | ||
| public string? EditingSecret { get; set; } = string.Empty; | ||
| } |
This file contains hidden or 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,30 @@ | ||
| namespace Sitecore.AspNetCore.SDK.Pages | ||
| { | ||
| /// <summary> | ||
| /// Class used to stored constants referenced throughout the Pages project. | ||
| /// </summary> | ||
| public static class Constants | ||
| { | ||
| /// <summary> | ||
| /// Class used to hold the names of different Layout Clients used by the Pages project. | ||
| /// </summary> | ||
| public static class LayoutClients | ||
| { | ||
| /// <summary> | ||
| /// Name of the Pages Editing Layout Client. | ||
| /// </summary> | ||
| public const string Pages = "pages"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Class used to hold the names of the different tag helpers defined in the Pages project. | ||
| /// </summary> | ||
| public static class SitecoreTagHelpers | ||
| { | ||
| /// <summary> | ||
| /// The HTML tag used to render the Editing Scripts tag helper. | ||
| /// </summary> | ||
| public const string EditScriptsHtmlTag = "sc-editingscripts"; | ||
| } | ||
| } | ||
| } |
122 changes: 122 additions & 0 deletions
122
src/Sitecore.AspNetCore.SDK.Pages/Extensions/PagesAppConfigurationExtensions.cs
This file contains hidden or 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,122 @@ | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Logging; | ||
| using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; | ||
| using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces; | ||
| using Sitecore.AspNetCore.SDK.LayoutService.Client.Request; | ||
| using Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization; | ||
| using Sitecore.AspNetCore.SDK.Pages.Configuration; | ||
| using Sitecore.AspNetCore.SDK.Pages.GraphQL; | ||
| using Sitecore.AspNetCore.SDK.Pages.Middleware; | ||
| using Sitecore.AspNetCore.SDK.Pages.Request.Handlers.GraphQL; | ||
| using Sitecore.AspNetCore.SDK.RenderingEngine.Configuration; | ||
| using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; | ||
| using Sitecore.AspNetCore.SDK.RenderingEngine.Interfaces; | ||
|
|
||
| namespace Sitecore.AspNetCore.SDK.Pages.Extensions; | ||
|
|
||
| /// <summary> | ||
| /// Configuration helpers for Pages functionality. | ||
| /// </summary> | ||
| public static class PagesAppConfigurationExtensions | ||
| { | ||
| /// <summary> | ||
| /// Registers the Sitecore Experience Editor middleware into the <see cref="IApplicationBuilder"/>. | ||
| /// </summary> | ||
| /// <param name="app">The instance of the <see cref="IApplicationBuilder"/> to extend.</param> | ||
| /// <returns>The <see cref="IApplicationBuilder"/> so that additional calls can be chained.</returns> | ||
| public static IApplicationBuilder UseSitecorePages(this IApplicationBuilder app) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(app); | ||
|
|
||
| object? experienceEditorMarker = app.ApplicationServices.GetService(typeof(PagesMarkerService)); | ||
| if (experienceEditorMarker != null) | ||
| { | ||
| app.UseMiddleware<PageSetupMiddleware>(); | ||
| app.UseMiddleware<PagesRenderMiddleware>(); | ||
| } | ||
|
|
||
| return app; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds the Sitecore Experience Editor support services to the <see cref="IServiceCollection" />. | ||
| /// </summary> | ||
| /// <param name="serviceBuilder">The <see cref="ISitecoreRenderingEngineBuilder" /> to add services to.</param> | ||
| /// <param name="contextId">The ContextId for the environment being used.</param> | ||
| /// <param name="options">Configures the <see cref="PagesOptions" /> options.</param> | ||
| /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | ||
| public static ISitecoreRenderingEngineBuilder WithSitecorePages(this ISitecoreRenderingEngineBuilder serviceBuilder, string contextId, Action<PagesOptions>? options = null) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(serviceBuilder); | ||
|
|
||
| IServiceCollection services = serviceBuilder.Services; | ||
| if (services.Any(s => s.ServiceType == typeof(PagesMarkerService))) | ||
| { | ||
| return serviceBuilder; | ||
| } | ||
|
|
||
| services.AddSingleton<PagesMarkerService>(); | ||
| services.AddSingleton<IGraphQLClientFactory>(new GraphQLClientFactory(contextId)); | ||
|
|
||
| if (options != null) | ||
| { | ||
| services.Configure(options); | ||
| } | ||
|
|
||
| services.Configure((Action<RenderingEngineOptions>)(renderingOptions => | ||
| { | ||
| renderingOptions.MapToRequest((httpRequest, layoutRequest) => | ||
| { | ||
| MapRequest(httpRequest, layoutRequest, "mode"); | ||
| MapRequest(httpRequest, layoutRequest, "sc_itemid"); | ||
| MapRequest(httpRequest, layoutRequest, "sc_version"); | ||
| MapRequest(httpRequest, layoutRequest, "sc_lang"); | ||
| MapRequest(httpRequest, layoutRequest, "sc_site"); | ||
| MapRequest(httpRequest, layoutRequest, "sc_layoutKind"); | ||
| MapRequest(httpRequest, layoutRequest, "secret"); | ||
| MapRequest(httpRequest, layoutRequest, "tenant_id"); | ||
| MapRequest(httpRequest, layoutRequest, "route"); | ||
| }); | ||
| })); | ||
|
|
||
| return serviceBuilder; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Registers an HTTP request handler for the Sitecore layout service client. | ||
| /// </summary> | ||
| /// <param name="builder">The <see cref="ISitecoreLayoutClientBuilder"/> to configure.</param> | ||
| /// <returns>The <see cref="ILayoutRequestHandlerBuilder{HttpLayoutRequestHandler}"/> so that additional calls can be chained.</returns> | ||
|
|
||
| public static ISitecoreLayoutClientBuilder AddSitecorePagesHandler( | ||
| this ISitecoreLayoutClientBuilder builder) | ||
| { | ||
| string name = Constants.LayoutClients.Pages; | ||
| builder.AddHandler(name, sp | ||
| => ActivatorUtilities.CreateInstance<GraphQLEditingServiceHandler>( | ||
| sp, | ||
| sp.GetRequiredService<IGraphQLClientFactory>(), | ||
| sp.GetRequiredService<ISitecoreLayoutSerializer>(), | ||
| sp.GetRequiredService<ILogger<GraphQLEditingServiceHandler>>())); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| private static void MapRequest(HttpRequest httpRequest, SitecoreLayoutRequest layoutRequest, string paramName) | ||
| { | ||
| if (httpRequest.Query == null || !httpRequest.Query.ContainsKey(paramName)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| string[]? modeQueryValue = httpRequest.Query[paramName]; | ||
| if (modeQueryValue == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| layoutRequest.AddHeader(paramName, modeQueryValue); | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
src/Sitecore.AspNetCore.SDK.Pages/GraphQL/GraphQLClientFactory.cs
This file contains hidden or 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,34 @@ | ||
| using GraphQL.Client.Abstractions; | ||
| using GraphQL.Client.Http; | ||
| using GraphQL.Client.Serializer.SystemTextJson; | ||
| using Sitecore.AspNetCore.SDK.GraphQL.Extensions; | ||
|
|
||
| namespace Sitecore.AspNetCore.SDK.Pages.GraphQL; | ||
|
|
||
| /// <summary> | ||
| /// GraphQLClientFactory used to generate instances of of GraphQLClients authenticated using a ContextId. | ||
| /// <param name="contextId">The contextId for the envionment being used.</param> | ||
| /// </summary> | ||
| public class GraphQLClientFactory(string contextId) | ||
| : IGraphQLClientFactory | ||
| { | ||
| private readonly string contextId = contextId ?? throw new ArgumentNullException(nameof(contextId)); | ||
|
|
||
| /// <inheritdoc /> | ||
| public IGraphQLClient GenerateClient(Uri? uri, string layoutKind, bool editMode) | ||
| { | ||
| uri ??= new Uri("https://edge-platform.sitecorecloud.io/v1/content/api/graphql/v1"); | ||
| uri = uri.AddQueryString("sitecoreContextId", contextId)!; | ||
|
|
||
| GraphQLHttpClient client = new(uri, new SystemTextJsonSerializer()); | ||
| client.HttpClient.DefaultRequestHeaders.Add("sc_layoutKind", layoutKind); | ||
| client.HttpClient.DefaultRequestHeaders.Add("sc_editmode", editMode.ToString()); | ||
| return client; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public IGraphQLClient GenerateClient(string layoutKind, bool editMode) | ||
| { | ||
| return GenerateClient(null, layoutKind, editMode); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.