pnp / pnpjs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs
https://pnp.github.io/pnpjs/
Other
750 stars 306 forks source link

Client-Side Pages publishes changes instead of creating a draft version #2884

Closed Cypherspeed closed 8 months ago

Cypherspeed commented 8 months ago

Major Version

3.x

Minor Version Number

3.17

Target environment

SharePoint Framework

Additional environment details

Sharepoint Online

Expected or Desired Behavior

I have written a code that aims to assist users with changes to bannerImageUrl and thumbnailUrl. From what I noticed those changes require save action to be executed as well to work. I am expecting save action to create a minor version of the page that is currently being edited.

Observed Behavior

Instead of creating a minor version page is published.

Steps to Reproduce

Here is a function that I am calling to update banner image export const setBannerImageUrl = async ( pageUrl: string, pictureUrl: string ): Promise => { const sp: SPFI = getSP(); const page: IClientsidePage = await sp.web.loadClientsidePage(pageUrl); page.bannerImageUrl = pictureUrl; await page.save(); };

juliemturner commented 8 months ago

Please check out our documentation on the save function and see if that doesn't solve your issue? I believe you want to pass false?

Cypherspeed commented 8 months ago

Oh snap, I must have missed that. Gonna try it now. Thanks for pointing this out!

Cypherspeed commented 8 months ago

I just had a chance to try it out but found a little different problem. While saving as draft works as extected my changes are being overwritten.

My scenario is that I am allowing editors to use custom control in edit mode that allows them to update banner and thumbnail images. Code only runs against current page.

I think that the issue is with sharepoint itself not recognizing the change and when editor saves the page as draft manually it overwrites banner image back to the original. One solution I can think of is moving this functionality and showing it also in regular display mode but it seems counterproductive. Any ideas?

Thanks

Cypherspeed commented 8 months ago

This is the scenario to consider:

  1. User navigates to a page that is hosting custom web part with my control
  2. User opens edit mode to access the control that allows him to update banned image url for current page
  3. Banner gets updated, executed through page.save(false)
  4. User clicks Save as draft in SP UI

Following this scenario will cause banner to get reverted back to its original value. I've had similiar problems when I was trying to update page properties through property pane and ended up giving up on that idea completly.

If there is a change in user workflow to just refresh the page instead of clicking sp ui action it works as expected so it must be an issue with not being able to get sp to update its values before saving the page.

Also going back to the original question - I think I was misguided by the method name a bit. First thing I check is whether there was a separate publish method available.

bcameron1231 commented 8 months ago

If I'm understanding correctly, ya I would think you would have a problem doing this. As the page itself doesn't have the updated values from the control yet, so when it saves, it overwrites it.

I personally don't know the best way to handle that. You could potentially force save and refresh the page after updating these values so they don't have to manually click save. But of course, you could have issues with other pending changes not from your custom component that get removed.

I am curious, why are you using a custom component for this and not just the out of the box properties?

Also going back to the original question - I think I was misguided by the method name a bit. First thing I check is whether there was a separate publish method available.

Yea we have combined the two methods (save and publish) into a single method for simplicity, as you can't publish an unmodified page. However if you need to call the /publish method individually, that can be done as well.

Cypherspeed commented 8 months ago

Alright thanks for your insight. I will close this as this is not an issue with the library itself. Sorry for the hassle

Cypherspeed commented 8 months ago

I missed your question where you asked why: we are using a bunch of home pages copied all over the place. Those pages do not have banner visible at all. I am having a custom control to render it and also to allow for editing. Having a regular image coming from a different place was also an option, but we decided to stick with banner so that it works nicely with search.

github-actions[bot] commented 8 months ago

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.