pnp / pnpframework

PnP Framework is a .NET library targeting Microsoft 365 containing the PnP Provisioning engine and a ton of other useful extensions
https://pnp.github.io/pnpframework/
MIT License
211 stars 144 forks source link

Collapsible sections with webparts in ClientSidePages are not provisioned correctly #833

Open mmi-wp opened 1 year ago

mmi-wp commented 1 year ago

Category

Describe the bug

When extracting a ClientSidePage to provision on a different SharePoint site, the resulting ClientSidePage is different from the extracted one. Here is an image of the page I'm extracting:

image

And here is an image after the extracted page is provisioned on a different SharePoint site:

image

Problems:

The section containing a webpart is not collapsible. The vertical section gets the same collapsible settings as the top section.

Steps to reproduce

  1. Create a client side page with a vertical section, and a collapsible section containing a webpart
  2. Extract the ClientSidePage provisioning template using PnP.Framework ClientSidePageContentsHelper.ExtractClientSidePage();
  3. Apply the extracted provisioning template to a different sharepoint site.

Expected behavior

I am expecting the provisioned ClientSidePage to look the same as the extracted one. (See images above)

Environment details (development & target environment)

Additional context

I think the problem might be located in PageWebPart.cs. Here's a snippet of the code responsible for setting the section collapsible. Note that setting the Type = 1 renders the section as collapsible, as expected.

controlData.ZoneGroupMetadata = new SectionZoneGroupMetadata()
{
    // Set section type to 1 if it was not set (when new sections are added via code)
    Type = (Section as CanvasSection).SectionType,
    DisplayName = Section.DisplayName,
    IsExpanded = Section.IsExpanded,
    ShowDividerLine = Section.ShowDividerLine,
};

In PageText.cs that same snippet of code reads like this. I suspect maybe the PageWebPart.cs code should be the same.

controlData.ZoneGroupMetadata = new SectionZoneGroupMetadata()
{
    // Set section type to 1 if it was not set (when new sections are added via code)
    Type = (Section as CanvasSection).SectionType == 0 ? 1 : (Section as CanvasSection).SectionType,
    DisplayName = Section.DisplayName,
    IsExpanded = Section.IsExpanded,
    ShowDividerLine = Section.ShowDividerLine,
};

As for the issue with the vertical section taking the same collapsible settings as the first section, I think it should just not be possible to mark a vertical section as collapsible, since it's not possible in the editor. Checking if the section is a vertical section before setting ZoneGroupMetadata.

jansenbe commented 1 year ago

@mmi-wp : this feels like an issue with exporting the page to a template or with applying the template. When you inspect the extracted template is then everything configured correctly?

mmi-wp commented 1 year ago

@jansenbe as far as I can tell, everything is correct in the extracted template. When applying the template, the generated html and/or the sp-controldata JSON is not correct for a collapsible section. Further, the code does not seem to distinguish between "regular" sections and vertical section content.

I don't see any reason for the code to be different between PageWebPart.cs and PageText.cs

mmi-wp commented 1 year ago

@jansenbe We are still having this issue.

I don't understand why this is tagged as a question, when I filed it as a bug report. I also don't understand why it was moved from pnpcore to pnpframework, when the bug I'm describing seems to stem from pnpcore.

mmi-wp commented 1 year ago

@jansenbe Any update on this?