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

FolderExplorer and FolderPicker do not seem to work for document libraries #741

Closed
nbelyh opened this issue Nov 25, 2020 · 9 comments
Closed
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:bug
Milestone

Comments

@nbelyh
Copy link
Contributor

nbelyh commented Nov 25, 2020

FolderExplorer and FolderPicker controls do not seem to work for the document libraries

Category

[ ] Enhancement

[x] Bug

[ ] Question

Version

Please specify what version of the library you are using: [2.1.0]

Description

Create a sample project with FolderExplorer, as specified in the documentation:
https://pnp.github.io/sp-dev-fx-controls-react/controls/FolderExplorer/

<FolderExplorer context={this.props.context}
                rootFolder={{
                  Name: 'Documents',
                  ServerRelativeUrl: `/sites/TestSite/Shared Documents`
                }}
                defaultFolder={{
                  Name: 'Documents',
                  ServerRelativeUrl: `/sites/TestSite/Shared Documents`
                }}
                onSelect={this._onFolderSelect}
                canCreateFolders={true} />

Expected

You see the folder explorer in the UI, showing corresponding folders/libraries.

Observed Behavior

The FolderExplorer does not work, it always shows "there are no folders" and throws this exception in console:

Error loading folders TypeError: Cannot read property 'filter' of undefined
    at FolderExplorerService.<anonymous> (FolderExplorerService.js:68)
    at step (FolderExplorerService.js:31)
    at Object.next (FolderExplorerService.js:12)
    at FolderExplorerService.js:6
    at new Promise (<anonymous>)
    at xI2j.__awaiter (FolderExplorerService.js:2)
    at FolderExplorerService._getDocumentLibraries (FolderExplorerService.js:58)
    at FolderExplorerService.<anonymous> (FolderExplorerService.js:51)
    at step (FolderExplorerService.js:31)
    at Object.next (FolderExplorerService.js:12)

Reasons (most probably pnpjs library modified after the FolderExplorer was last verified?)
1.
@pnp/sp/lists is not included in the FileExplorerService.ts, here:

import { ServiceKey, ServiceScope } from "@microsoft/sp-core-library";
import { PageContext } from "@microsoft/sp-page-context";
import { IFolderExplorerService } from "./IFolderExplorerService";
import { IFolder } from "./IFolderExplorerService";
import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import { Web } from "@pnp/sp/webs";
import "@pnp/sp/folders";
import { IFolderAddResult } from "@pnp/sp/folders";

But is used here:

const libraries: any[] = await web.lists.filter('BaseTemplate eq 101 and Hidden eq false').expand('RootFolder').select('Title', 'RootFolder/ServerRelativeUrl').orderBy('Title').get();

The result is, web.lists is undefined and that result in the exception.

  1. double encoding of folder paths (of the "%" symbol). This causes the list of folders to be always empty even after the change above.

let foldersResult: IFolder[] = await web.getFolderByServerRelativePath(encodeURIComponent(folderRelativeUrl)).folders.select('Name', 'ServerRelativeUrl').orderBy('Name').get();

pnpjs (getFolderByServerRelativePath) also encodes it, in the referenced version 2.0.6 as well:
https://github.com/pnp/pnpjs/blob/183dc11edb65aa67f6e053e03fb28c5dbdb8a9a5/packages/sp/folders/web.ts#L58

@ghost
Copy link

ghost commented Nov 25, 2020

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@nbelyh
Copy link
Contributor Author

nbelyh commented Nov 26, 2020

Checked the history, seems to be broken recently by this commit actually:
fc7d9fb

@gautamdsheth Don't understand the reason for this change - pnpjs already does the encoding - check here? This commit seems to introduce the bug with double-encoding?

@gautamdsheth
Copy link
Contributor

I did test with normal as well as some folders with special chars like % and # and it worked well, but it looks like I missed something. My bad. Sorry :(

@nbelyh
Copy link
Contributor Author

nbelyh commented Nov 27, 2020

@gautamdsheth My guess is that pnpjs version might have been updated and this part not re-checked? But the point is now it seems that FolderExplorer and FolderPicker are simply not working 😄 Would be great if maintainers could look at this in the upcoming release.

@nbelyh
Copy link
Contributor Author

nbelyh commented Nov 28, 2020

Reaplced the PR with another to dev branch

@nbelyh
Copy link
Contributor Author

nbelyh commented Nov 28, 2020

Sorry for the messed up PR (would be great if the maintainers can delete them 😅
Have read the submission guidelines after creating PR. Now the branch is from dev and trargets dev.

@AJIXuMuK
Copy link
Collaborator

Hi @nbelyh, @gautamdsheth - I've merged the PR.

@gautamdsheth - could you please check beta version and confirm that it works correctly for the use-cases you were addressing in your previous PR?

Thank you!

@AJIXuMuK AJIXuMuK added status:fixed-next-drop Issue will be fixed in upcoming release. type:bug and removed Needs: Triage 🔍 labels Nov 28, 2020
@AJIXuMuK AJIXuMuK added this to the 2.2.0 milestone Nov 28, 2020
@gautamdsheth
Copy link
Contributor

@AJIXuMuK - works fine with the latest beta. Thanks

@nbelyh
Copy link
Contributor Author

nbelyh commented Nov 30, 2020

Thank you guys, then I'm closing the issue

@nbelyh nbelyh closed this as completed Nov 30, 2020
@estruyf estruyf mentioned this issue Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants