Skip to content

Conversation

BenWhite27
Copy link

Added IBlockPreviewRequestEnricher service that allows enrichment of the http context for runtime view and stylesheet location.

Modified BlockPreviewService to allow extensibility around CreateViewData and GetViewResult. Making use of a new BlockPreviewContext class to pass around the data needed to make decisions in custom logic. Also added BlockPreviewService.GetStylesheetPath to allow customisation of the stylesheet that is delivered at runtime.

Updated the Backoffice UI code to obtain the stylesheet via API call.

Also added some example implementations to the CMS project.

This is all in relation to #115 with the goal of allowing a package consumer to display theme specific views in the back office. In theory the theme could be specified as a property in the content node hierarchy or based on the domain configured on the root content node.

@BenWhite27 BenWhite27 marked this pull request as draft May 30, 2025 16:31
@BenWhite27 BenWhite27 marked this pull request as ready for review June 5, 2025 17:11
@rickbutterfield rickbutterfield requested a review from Copilot June 16, 2025 14:12
Copilot

This comment was marked as outdated.

@rickbutterfield
Copy link
Owner

Hey @BenWhite27! I haven't forgotten about this, hoping to get on to it very soon. In the meantime, please can you pull in the latest changes from v3/dev just to make sure it's up to date?

@BenWhite27
Copy link
Author

Hey @rickbutterfield, No worries, been tied up lately as well. I probably should have created a branch, still very new to contributing... especially in library code. I'll do a rebase locally in the next few days and update the fork asap.

@BenWhite27
Copy link
Author

Afternoon @rickbutterfield, hope you're well.
I've rebased this so it should be up to date now. I think there's still further improvements and some tidy up that can be done but I'd like to know if you're happy with the approach first.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds features that allow consumers to customise View Location and runtime stylesheet loading for block previews. The implementation introduces a new service interface IBlockPreviewRequestEnricher that enables enrichment of the HTTP context during block preview rendering, and modifies the BlockPreviewService to allow extensibility around view resolution and stylesheet path retrieval. The changes enable theme-specific views and stylesheets to be displayed in the back office based on content properties.

  • Added IBlockPreviewRequestEnricher service to allow HTTP context enrichment during block preview
  • Modified BlockPreviewService to support customizable view location and stylesheet paths through new BlockPreviewContext
  • Updated the Backoffice UI to obtain stylesheets via API calls instead of static configuration

Reviewed Changes

Copilot reviewed 45 out of 46 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
assets.js Updated JavaScript bundle with new API endpoints for stylesheet retrieval
NoopBlockPreviewRequestEnricher.cs Default no-op implementation of the request enricher interface
BlockPreviewService.cs Enhanced service with extensibility points for view resolution and stylesheet paths
BlockPreviewContext.cs New context class to pass block preview data between methods
IBlockPreviewService.cs Updated interface with new stylesheet path method
IBlockPreviewRequestEnricher.cs New interface for HTTP context enrichment
BlockPreviewApiController.cs Added API endpoints for retrieving stylesheets and integrated request enrichment
BlockPreviewComposer.cs Registered the default request enricher service
Various UI files Updated to use API calls for stylesheet retrieval instead of settings
Example CMS files Example implementation showing theme-based view resolution and styling

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


ViewDataDictionary viewData = CreateViewData(blockInstance, previewContext);
previewContext.ViewData = viewData;
return await GetMarkup(previewContext);
Copy link
Preview

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message "Insufficient data for block preview" doesn't provide enough context about which specific data is missing. Consider enhancing the error message to specify exactly what data is required.

Copilot uses AI. Check for mistakes.

{
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
{
Model = typedBlockInstance
};

if (blockType == BlockType.BlockGrid && matchingBlockConfig != null && matchingBlockConfig.Areas.Any())
if (context.BlockType == BlockType.BlockGrid && context.BlockGridBlockConfig != null && context.BlockGridBlockConfig.Areas.Length != 0)
Copy link
Preview

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Complex conditional statement with multiple null checks. Consider extracting this logic into a helper method like 'HasBlockGridAreas(context)' for better readability.

Suggested change
if (context.BlockType == BlockType.BlockGrid && context.BlockGridBlockConfig != null && context.BlockGridBlockConfig.Areas.Length != 0)
if (HasBlockGridAreas(context))

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants