Sp-dev-docs: propertyPaneSettings should return a Promise

Created on 6 Oct 2016  路  7Comments  路  Source: SharePoint/sp-dev-docs

Category

  • [ ] Question
  • [ ] Typo
  • [ ] Bug
  • [X] Enhancement / Suggestion
  • [ ] Additional article idea

    Expected or Desired Behavior

To be able to dynamically populate fields and to dynamically create pages, groups and fields in the property pane, I would like the propertyPaneSettings method to return Promise<IPropertyPaneSettings>, or have the option to return either a promise or the object directly.

Observed Behavior

Currently it returns just IPropertyPaneSettings.

spfx-general fixed-next-drop tracked bug-suspected

All 7 comments

So, I've been thinking a bit about this. I would rather not return a promise from the propertyPaneSettings, as promises are a tricky thing for people to wrap their heads around, and I would like to try and keep the common case simple. However, I wonder if something similar to the OnInit flow, only for the property pane, would make sense.

So we would introduce a method like OnPropertyPaneInit() : Promse - basically the same signature as OnInit. We would call this method each time we render the property pane, and we would wait until the promise is complete before rendering it. Maybe we get fancy and throw up a spinner if it is taking > 2 seconds or something.

Now here is where it could get interesting. In the event of cascading data fields (say first you pick a list, then you pick a list item) your OnInit would get called a couple of times - once when you open the property pane, and then once when you select the list. The first OnPropertyPaneInit() returns a promise for the list of lists to be fetched, then when a list is selected, OnPropertyPaneInit() is called again, and this time you return a promise for the query to fetch the items in the list. When the promise is fulfilled, we call propertyPaneSettings(), your data will be available, and you can return the right config each time.

@srideshpande , @manishgarg1 - seem straight forward?

That sounds like a great way to do it! I also like the simplicity approach and that only if you ever need this then you override this method. Also, showing a spinner in the property pane while loading is a great idea/UX.

Cool. I don't think I could have written that in 140 characters. :) We'll see what we can do.

How about this was implemented per control? That way you wouldn't introduce any overhead on paged panes, if the particular page doesn't show any control with external data. Each control could then decide for itself where it gets its data from. The particular control could remain disabled until ready.

As I was looking for a similar solution I ran across Pat's update in the wiki https://github.com/SharePoint/sp-dev-docs/wiki/Async-data-fetch-in-the-property-pane in case others stumble upon this issue and are looking for a solution that may work now.

This issue is fixed as per Pat's comment.

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

Was this page helpful?
0 / 5 - 0 ratings

Related issues

christianbueschi picture christianbueschi  路  3Comments

waldekmastykarz picture waldekmastykarz  路  3Comments

zerovectorspace picture zerovectorspace  路  3Comments

nanddeepn picture nanddeepn  路  3Comments

thechriskent picture thechriskent  路  3Comments