Skip to content
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

Fix ViewTypeKind property being ignored when provisioning views #816

Merged
merged 1 commit into from
Jan 5, 2023

Conversation

jackpoz
Copy link
Contributor

@jackpoz jackpoz commented Dec 14, 2022

Fix ViewTypeKind property being ignored by SPO when provisioning a new view and updating ListViewXml property during the same ExecuteQueryRetry() call. All views would have ViewType set to HTML before.

The code in this PR first creates the view, calls ExecuteQueryRetry(), then updates the ListViewXml property, then calls ExecuteQueryRetry(). This seems to be needed by serverside behavior of SPO, as ViewCreationInformation is filled with the same information in both cases.

Tests

The test was done with a view created from SPO List Settings with "Datasheet View" as base view and then exported with Get-PnPSiteTemplate. The xml template has these attributes:

<View Name="{221F9B40-A0A0-40AE-9AF6-8C109AD3C6B0}" Type="GRID" Personal="TRUE" DisplayName="Grid view" Url="{site}/Lists/TestList/PersonalViews.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/15/images/generic.png?rev=47">

Notice how the view provisioned before the fix has ViewType set to HTML and ListViewXml shows Type="HTML", even if the template has GRID
image

This is how the view looked on SPO, not grid view. A custom sorting by ID was added to test a different case than the standard view one:
image

This is the same view created using the same template after applying the fix from this PR. Notice how ViewType now is set to GRID and ListViewXml has Type="GRID":
image

SPO kept the same sorting by ID and the view is a grid view:
image

In an attempt to test it a bit deeper I created a few views, exported them as pnp template, deleted the list and re-applied the template.
Case with default "All items" plus a new custom field "Category":
image

Case grouping by custom field "Category", sorted by ID descending:
image

Case filtering by custom field "Category" set to "Choice 2":
image

Case with Grid view:
image

Template used for the test cases:
views.zip

Fix ViewTypeKind property being ignored by SPO when provisioning a new view and updating ListViewXml property during the same ExecuteQueryRetry() call.
jansenbe added a commit that referenced this pull request Jan 5, 2023
@jansenbe jansenbe merged commit 6b8550f into pnp:dev Jan 5, 2023
@jackpoz
Copy link
Contributor Author

jackpoz commented Jan 9, 2023

@jansenbe just a heads up that I'm getting an error "The target view cannot be configured as a mobile view." in some cases using latest nightly, most likely caused by this PR. I will check and let you know.

@jackpoz
Copy link
Contributor Author

jackpoz commented Jan 9, 2023

Somehow a pnp template created from an existing site ended up with a Grid view with Mobile view enabled

<View Name="{08538C78-51BA-4514-9E7D-46F45437F1EC}" MobileView="TRUE" Type="GRID" DisplayName="SomeView" Url="{site}/Lists/SomeList/SomeView.aspx" Level="1" ContentTypeID="0x">

No idea how that is even possible to do from the browser (the site was created by users manually). Opening the view from the browser and clicking "Ok" to save it without doing any change disabled the "Mobile view" setting.

Before this PR the view was not created as GRID so the error never showed up. Do you want this to be validated in PnP or should users fix their templates ?

@jansenbe
Copy link
Contributor

@jackpoz : if this will break existing templates then yes it would be needed to handle this in PnP. Would be great if you could help here.

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.

None yet

2 participants