FolderPicker - Improvment to automatically detect URL type
Category
[x] Enhancement
[ ] Bug
[ ] Question
Version
Please specify what version of the library you are using: [3.15.0]
Expected / Desired Behavior / Question
Raised by #1379, the idea is to enhance the rootFolder.ServerRelativeUrl to automatically detect if it's absolute or not
Observed Behavior
Current version of the control only works with server relative URL. Some additional work has to be done when working with another site collection than the context's one.
Steps to Reproduce
- Add the FolderPicker control in a SPFx project
- Set the
siteAbsoluteUrlprop to another site collection - Try to set the site collection's library with server relative URL
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
@stevebeauge, if you would like to give a hand on this one, let us know 🙂
Edit: of course, if I've mistakenly wrote the improvment idea, please let me know.
I think the improvement can be broader than just the folder picker. Let me reformulate my vision
Basically, SharePoint has three kind of URL:
- Absolute URL:
https://contoso.sharepoint.com/sites/somesite/shared documents/mydoc.pdf - Server relative URL:
/sites/somesite/shared documents/mydoc.pdf - Web relative URL:
shared documents/mydoc.pdf
Most of the SharePoint API require one specific form of URL (server relative is the most used I'd say).
This leads the developer to need an understanding of which form of url is required, and convert from another form (ex: type the url of a site collection in a textbox and query data inside it).
My proposal is to integrate a utility module that can convert any url to the desired form. Whenever a component or a service requires a specific form of url which is dependent on external input, such utility may ensure the correctness of the application.
For example, regarding the FolderPicker, we could replace siteAbsoluteUrl by simply siteUrl. The developer does not need to worry about the form of the url. He may pass https://contoso.sharepoint.com/sites/somesite or /sites/somesite. Both would work.
This is only an example. Once the utility is present in the code, progressive inclusion of the helper could be added to existing controls.
Such utility is already in place in our spfx code base. I should be able to port it (the code is actually quite simple). These functions are available:
export declare const toServerRelativeUrl: (url: string) => string;
export declare const toAbsoluteUrl: (url: string) => string;
export declare const toWebRelativeUrl: (webUrl: string, objectUrl: string) => string;
If you think this idea has its place, I can try to apply on the folder picker as a try