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

Property folderInfo is undefined if folder is loaded directly #9674

Open
5 of 9 tasks
aalkousheh opened this issue May 7, 2024 · 1 comment
Open
5 of 9 tasks

Property folderInfo is undefined if folder is loaded directly #9674

aalkousheh opened this issue May 7, 2024 · 1 comment
Labels
type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.

Comments

@aalkousheh
Copy link

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Developer environment

Windows

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

i have tried it with 2 versions

  • SPFx version 1.18.2
  • Node.js version 16.20.2
  • Npm version 8.19.4

AND

  • SPFx version 1.16.1
  • Node.js version 14.18.3
  • Npm version 6.14.15

Describe the bug / error

this.context.listView.folderInfo is undefined when the folder is loaded directly.

Steps to reproduce

1.Create a List Command Set Extension

2.Deploy

  1. Open a document library folder directly e.g
    https://yourdomain.sharepoint.com/sites/spfx-test/Shared%20Documents/Forms/AllItems.aspx?id=%2Fsites%2Fspfx-test%2FShared%20Documents%2FSubFolder

  2. output this.context.listView.folderInfo.folderPath e.g. onExecute

public async onExecute(event: IListViewCommandSetExecuteEventParameters) { console.log(this.context.listView.folderInfo) .... }

  1. Observe that it is undefined.
    Note: When you navigate to the subfolder within the document library the folderInfo property is not undefined and contains the folderPath property.

Expected behavior

this.context.listView.folderInfo should contain the folderPath property even when you load the folder directly in the browser.

This is important e.g. in Teams when you use the files tab and click on "Open in SharePoint".
It will directly open a subfolder which contains the files of the current channel. In this case folderInfo is set to undefined and cannot be used.

@aalkousheh aalkousheh added the type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs. label May 7, 2024
@aalkousheh
Copy link
Author

aalkousheh commented May 9, 2024

I found workaround for this as below.

`private getFolderUrlFromQueryString(): string {
const id = this.getQueryStringParameter("Id");
const rootFolder = this.getQueryStringParameter("RootFolder");

var url = id != null ? id : rootFolder;
if (url === undefined) {
// in case of root folder
url = this.context.pageContext.list.serverRelativeUrl;
}

return decodeURIComponent(url);
}

private getQueryStringParameter(paramToRetrieve: string) {
if (document.URL.indexOf("?") == -1)
return null;

var params = document.URL.split("?")[1].split("&");
var strParams = "";
for (var i = 0; i < params.length; i = i + 1) {
var singleParam = params[i].split("=");
if (singleParam[0].toLowerCase() == paramToRetrieve.toLowerCase())
return singleParam[1];
}
}

public async onExecute(event: IListViewCommandSetExecuteEventParameters): Promise {
switch (event.itemId) {
case 'cmd_NewButton':
{
let folderServerRelativeUrl = this.context.listView.folderInfo.folderPath || "";
if (folderServerRelativeUrl === "") {
let folderServerRelativeUrlFromURLQuery =this.getFolderUrlFromQueryString();
if (folderServerRelativeUrlFromURLQuery === "") {
alert("something went wrong, please refresh the page try again.");
break;
} else {
folderServerRelativeUrl = folderServerRelativeUrlFromURLQuery;
}
}
....
break;
}
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.
Projects
None yet
Development

No branches or pull requests

1 participant