Skip to content

Commit

Permalink
Merge pull request #602 from russgove/master
Browse files Browse the repository at this point in the history
added siteAbsoluteUrl to FOlderPicker
  • Loading branch information
joaojmendes authored Apr 17, 2024
2 parents 44b13de + b1dd483 commit 1436a68
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The `PropertyFieldFolderPicker` control can be configured with the following pro
| disabled | boolean | no | Is the control disabled. |
| canCreateFolders | boolean | no | Allow current user to create folders on the target location. If enabled, you need to ensure that the user has the required permissions. |
| onSelect | (folder: IFolder): void | no | Callback function called after a folder is selected. |

| siteAbsoluteUrl | string | no | The absolute url of the site you want to pick a folder from (if different than the site the webpart is installed on) |

interface `IFolder`

Expand Down
22 changes: 13 additions & 9 deletions src/propertyFields/folderPicker/IPropertyFieldFolderPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { BaseComponentContext } from '@microsoft/sp-component-base';
import { IFolder } from '../../services/IFolderExplorerService';

export interface IPropertyFieldFolderPickerProps {
/**
* Current context
*/
/**
* Current context
*/
siteAbsoluteUrl?: string;
/**
* Current context
*/
context: BaseComponentContext;

/**
Expand Down Expand Up @@ -63,10 +67,10 @@ export interface IPropertyFieldFolderPickerProps {
*/
key: string;

}
}

export interface IPropertyFieldFolderPickerPropsInternal extends IPropertyFieldFolderPickerProps {
targetProperty: string;
onRender(elem: HTMLElement): void;
onDispose(elem: HTMLElement): void;
}
export interface IPropertyFieldFolderPickerPropsInternal extends IPropertyFieldFolderPickerProps {
targetProperty: string;
onRender(elem: HTMLElement): void;
onDispose(elem: HTMLElement): void;
}
51 changes: 28 additions & 23 deletions src/propertyFields/folderPicker/PropertyFieldFolderPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class PropertyFieldFolderPickerBuilder implements IPropertyPaneField<IPropertyFi
private context: BaseComponentContext;
private label: string;

private siteAbsoluteUrl?: string;

private customProperties: any; // eslint-disable-line @typescript-eslint/no-explicit-any
private disabled: boolean = false;
private key: string;
Expand Down Expand Up @@ -61,17 +63,18 @@ class PropertyFieldFolderPickerBuilder implements IPropertyPaneField<IPropertyFi

this.onPropertyChange = _properties.onPropertyChange;
this.customProperties = _properties.properties;
this.siteAbsoluteUrl = this.properties.siteAbsoluteUrl;

if(_properties.required === true){
this.required = _properties.required;
if (_properties.required === true) {
this.required = _properties.required;
}

if (_properties.disabled === true) {
this.disabled = _properties.disabled;
}

if(_properties.canCreateFolders === true){
this.canCreateFolders = _properties.canCreateFolders;
if (_properties.canCreateFolders === true) {
this.canCreateFolders = _properties.canCreateFolders;
}
}

Expand All @@ -81,26 +84,27 @@ class PropertyFieldFolderPickerBuilder implements IPropertyPaneField<IPropertyFi
private render(elem: HTMLElement, ctx?: any, changeCallback?: (targetProperty?: string, newValue?: any) => void): void { // eslint-disable-line @typescript-eslint/no-explicit-any

const element: React.ReactElement<IPropertyFieldFolderPickerHostProps> = React.createElement(PropertyFieldFolderPickerHost, {
label: this.label,
targetProperty: this.targetProperty,
context: this.context,
rootFolder: this.rootFolder,
defaultFolder: this.defaultFolder,
onSelect: this.onSelect,
required: this.required,
canCreateFolders: this.canCreateFolders,
onDispose: this.dispose,
onRender: this.render,
onChange: changeCallback,
onPropertyChange: this.onPropertyChange,
properties: this.customProperties,
key: this.key,
disabled: this.disabled,
selectedFolder: this.selectedFolder
label: this.label,
targetProperty: this.targetProperty,
context: this.context,
rootFolder: this.rootFolder,
defaultFolder: this.defaultFolder,
onSelect: this.onSelect,
required: this.required,
canCreateFolders: this.canCreateFolders,
onDispose: this.dispose,
onRender: this.render,
onChange: changeCallback,
onPropertyChange: this.onPropertyChange,
properties: this.customProperties,
key: this.key,
disabled: this.disabled,
selectedFolder: this.selectedFolder,
siteAbsoluteUrl: this.siteAbsoluteUrl
});

// Calls the REACT content generator
ReactDom.render(element, elem);
// Calls the REACT content generator
ReactDom.render(element, elem);
}

/**
Expand Down Expand Up @@ -135,7 +139,8 @@ export function PropertyFieldFolderPicker(targetProperty: string, properties: IP
canCreateFolders: properties.canCreateFolders,
defaultFolder: properties.defaultFolder,
required: properties.required,
selectedFolder: properties.selectedFolder
selectedFolder: properties.selectedFolder,
siteAbsoluteUrl: properties.siteAbsoluteUrl
};
//Calls the PropertyFieldFolderPickerPicker builder object
//This object will simulate a PropertyFieldCustom to manage his rendering process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class PropertyFieldFolderPickerHost extends React.Component<IProp
const currentValue = getPropertyValue(this.props.properties, this.props.targetProperty);
const nextValue = getPropertyValue(nextProps.properties, nextProps.targetProperty);

if(currentValue !== nextValue){
if (currentValue !== nextValue) {
this.setState({
selectedFolder: nextValue
});
Expand Down Expand Up @@ -93,6 +93,7 @@ export default class PropertyFieldFolderPickerHost extends React.Component<IProp
defaultFolder={this.state.selectedFolder}
onSelect={this._onFolderSelect}
canCreateFolders={this.props.canCreateFolders}
siteAbsoluteUrl={this.props.siteAbsoluteUrl}
/>
</div>
</Panel>
Expand Down

0 comments on commit 1436a68

Please sign in to comment.