Skip to content

Commit

Permalink
Be able to use a server relative folder path.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlingstuyl committed Nov 19, 2024
1 parent 5eb14c9 commit 99e15fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/documentation/docs/controls/DynamicForm.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The `DynamicForm` can be configured with the following properties:
| validationErrorDialogProps | IValidationErrorDialogProps | no | Specifies validation error dialog properties |
| customIcons | { [ columnInternalName: string ]: string } | no | Specifies custom icons for the form. The key of this dictionary is the column internal name, the value is the Fluent UI icon name. |
| storeLastActiveTab | boolean | no | When uploading files: Specifies if last active tab will be stored after the Upload panel has been closed. Note: the value of selected tab is stored in the queryString hash. Default - `true` |
| folderPath | string | no | Library relative folder to create the item in. This option is only available for document libraries and works only when the contentTypeId is specified and has a base type of type Document or Folder. Defaults to the root folder. |
| folderPath | string | no | Server relative or library relative folder to create the item in. This option is only available for document libraries and works only when the contentTypeId is specified and has a base type of type Document or Folder. Defaults to the root folder of the library. |

## Validation Error Dialog Properties `IValidationErrorDialogProps`
| Property | Type | Required | Description |
Expand Down
22 changes: 19 additions & 3 deletions src/controls/dynamicForm/DynamicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1478,10 +1478,26 @@ export class DynamicForm extends React.Component<
return 'Document';
}
}

private getFolderByPath = async (listRelativeFolderPath: string, rootFolder: IFolder): Promise<IFolder> => {

/**
* Returns a pnp/sp folder object based on the folderPath and the library the folder is in.
* The folderPath can be a server relative path, but should be in the same library.
* @param folderPath The path to the folder coming from the component properties
* @param rootFolder The rootFolder object of the library
* @returns
*/
private getFolderByPath = async (folderPath: string, rootFolder: IFolder): Promise<IFolder> => {
const libraryFolder = await rootFolder();
const folder = sp.web.getFolderByServerRelativePath(`${libraryFolder.ServerRelativeUrl}/${listRelativeFolderPath}`);
const normalizedFolderPath = decodeURIComponent(folderPath).toLowerCase().replace(/\/$/, "");
const serverRelativeLibraryPath = libraryFolder.ServerRelativeUrl.toLowerCase().replace(/\/$/, "");

// In case of a server relative path in the same library, return the folder
if (`${normalizedFolderPath}/`.startsWith(`${serverRelativeLibraryPath}/`)) {
return sp.web.getFolderByServerRelativePath(normalizedFolderPath);
}

// In other cases, expect a list-relative path and return the folder
const folder = sp.web.getFolderByServerRelativePath(`${serverRelativeLibraryPath}/${normalizedFolderPath}`);
return folder;
};
}

0 comments on commit 99e15fd

Please sign in to comment.