Skip to content

Commit

Permalink
Page does not render if optional descriptor is missing #10268 (#10269)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashklianko authored Sep 18, 2023
1 parent ac50f8f commit 7bed4fe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private PageResolverResult buildPageWithRegionsFromController( final Page effect

if ( pageDescriptor == null || pageDescriptor.getModifiedTime() == null )
{
return new PageResolverResult( effectivePage, controller, null );
return new PageResolverResult( effectivePage, controller, pageDescriptor );
}

final Page resultingPage = buildPageWithRegions( effectivePage, pageDescriptor );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,37 +141,6 @@ private Component resolveComponent( final PortalRequest portalRequest, final Com
return component;
}

private LayoutComponent buildLayoutWithRegions( final LayoutComponent existingLayout, final LayoutComponent layoutFromDescriptor )
{
final LayoutComponent.Builder layoutBuilder = LayoutComponent.create( existingLayout );
final LayoutRegions.Builder regionsBuilder = LayoutRegions.create();

layoutFromDescriptor.getRegions().forEach( region -> {
final Region existingRegion = existingLayout.getRegion( region.getName() );
final Region regionToAdd = existingRegion == null ? Region.create().name( region.getName() ).build() : existingRegion;
regionsBuilder.add( regionToAdd );
} );

return layoutBuilder.regions( regionsBuilder.build() ).build();
}

private void setParentRegionOnLayout( final Page page, final LayoutComponent existingLayout, final LayoutComponent resultingLayout )
{
if ( page == null || page.getRegions() == null )
{
return;
}

page.getRegions().forEach( region -> {
final int index = region.getIndex( existingLayout );

if ( index > -1 )
{
Region.create( region ).set( index, resultingLayout ).build(); // The only way to set layout's parent region
}
} );
}

private Component resolveComponentInFragment( final Content content, final ComponentPath path )
{
final Component fragmentComponent = content.getPage().getFragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,27 @@ public void given_Content_with_Page_without_regions_then_effective_Page_gets_reg
{
// setup
final Site site = createSite();
final DescriptorKey descriptor = DescriptorKey.from( "myapp:my-descriptor" );

PageTemplate template = PageTemplate.newPageTemplate()
final PageTemplate template = PageTemplate.newPageTemplate()
.key( PageTemplateKey.from( "t-1" ) )
.parentPath( site.getPath() )
.name( "my-template" )
.page( Page.create().descriptor( DescriptorKey.from( "myapp:my-descriptor" ) ).config( configA ).regions( regionsA ).build() )
.page( Page.create().descriptor( descriptor ).config( configA ).regions( regionsA ).build() )
.canRender( ContentTypeNames.from( ContentTypeName.templateFolder() ) )
.build();

Content content = Content.create()
final Content content = Content.create()
.parentPath( site.getPath() )
.name( "my-content" )
.type( ContentTypeName.templateFolder() )
.page( Page.create().template( template.getKey() ).config( configB ).build() )
.build();

final PageDescriptor defaultPageDescriptor =
PageDescriptor.create().config( Form.create().build() ).regions( RegionDescriptors.create().build() ).key( descriptor ).build();

when( pageDescriptorService.getByKey( descriptor ) ).thenReturn( defaultPageDescriptor );
when( pageTemplateService.getByKey( template.getKey() ) ).thenReturn( template );

// exercise
Expand All @@ -238,7 +243,8 @@ public void given_Content_with_Page_without_regions_then_effective_Page_gets_reg
assertEquals( configB, effectivePage.getConfig() );
assertEquals( template.getKey(), effectivePage.getTemplate() );
assertNull( effectivePage.getDescriptor() );
assertEquals( DescriptorKey.from( "myapp:my-descriptor" ), result.getController() );
assertEquals( descriptor, result.getController() );
assertEquals( defaultPageDescriptor, result.getPageDescriptor() );
}

@Test
Expand Down

0 comments on commit 7bed4fe

Please sign in to comment.