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

Custom render callbacks for the "Upload" and "Link" tabs #751

Merged
merged 1 commit into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/documentation/docs/controls/FilePicker.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ The FilePicker component can be configured with the following properties:
| hideLocalUploadTab | boolean | no | Specifies if LocalUploadTab should be hidden. |
| hideLinkUploadTab | boolean | no | Specifies if LinkUploadTab should be hidden. |
| storeLastActiveTab | boolean | no | 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` |
| renderCustomUploadTabContent | (filePickerResult: IFilePickerResult) => JSX.Element | null | no | Optional renderer to add custom user-defined fields to "Upload" tab |
| renderCustomLinkTabContent | (filePickerResult: IFilePickerResult) => JSX.Element | null | no | Optional renderer to add custom user-defined fields to "Link" tab |

interface `IFilePickerResult`

Expand Down
2 changes: 2 additions & 0 deletions src/controls/filePicker/FilePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ export class FilePicker extends React.Component<IFilePickerProps, IFilePickerSta
this.state.selectedTab === "keyLink" &&
<LinkFilePickerTab
fileSearchService={this.fileSearchService}
renderCustomLinkTabContent={this.props.renderCustomLinkTabContent}
allowExternalTenantLinks={true}
{...linkTabProps}
/>
}
{
this.state.selectedTab === "keyUpload" &&
<UploadFilePickerTab
renderCustomUploadTabContent={this.props.renderCustomUploadTabContent}
{...linkTabProps}
onChange={this._handleOnChange}
/>
Expand Down
8 changes: 8 additions & 0 deletions src/controls/filePicker/IFilePickerProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,12 @@ export interface IFilePickerProps {
* Handler when file picker has been cancelled.
*/
onCancel?: () => void;
/**
* Optional additional renderer for Link tab
*/
renderCustomLinkTabContent?: (filePickerResult: IFilePickerResult) => JSX.Element | null;
/**
* Optional additional renderer for Upload tab
*/
renderCustomUploadTabContent?: (filePickerResult: IFilePickerResult) => JSX.Element | null;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { IFilePickerTab } from "../FilePicker.types";
import { IFilePickerTab, IFilePickerResult } from "../FilePicker.types";
import { FilesSearchService } from "../../../services/FilesSearchService";

export interface ILinkFilePickerTabProps extends IFilePickerTab {
allowExternalTenantLinks: boolean;
fileSearchService: FilesSearchService;
renderCustomLinkTabContent: (filePickerResult: IFilePickerResult) => JSX.Element | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class LinkFilePickerTab extends React.Component<ILinkFilePickerTa
value={fileUrl}
onChanged={(newValue: string) => this._handleChange(newValue)}
/>
{this.props.renderCustomLinkTabContent && this.props.renderCustomLinkTabContent(this.state.filePickerResult)}
</div>

<div className={styles.actionButtonsContainer}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import { IFilePickerResult, IFilePickerTab } from "../FilePicker.types";

export interface IUploadFilePickerTabProps extends IFilePickerTab {
onChange: (value: IFilePickerResult) => void;
renderCustomUploadTabContent: (filePickerResult: IFilePickerResult) => JSX.Element | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default class UploadFilePickerTab extends React.Component<IUploadFilePick
<label className={styles.localTabLabel} htmlFor="fileInput">{
(fileName ? strings.ChangeFileLinkLabel : strings.ChooseFileLinkLabel)
}</label>
{this.props.renderCustomUploadTabContent && this.props.renderCustomUploadTabContent(this.state.filePickerResult)}
</div>
<div className={styles.actionButtonsContainer}>
<div className={styles.actionButtons}>
Expand Down
29 changes: 28 additions & 1 deletion src/webparts/controlsTest/components/ControlsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import {
import { ImageFit } from 'office-ui-fabric-react/lib/Image';
import { FilePicker, IFilePickerResult } from '../../../FilePicker';
import { FolderPicker } from '../../../FolderPicker';
import { FolderExplorer, IFolder, IBreadcrumbItem } from '../../../FolderExplorer';
import { FolderExplorer, IBreadcrumbItem, IFolder } from '../../../FolderExplorer';
import { Pagination } from '../../../controls/pagination';
import CarouselImage from '../../../controls/carousel/CarouselImage';
import { FieldCollectionData, CustomCollectionFieldType } from '../../../FieldCollectionData';
Expand Down Expand Up @@ -522,6 +522,11 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
}
}

private rootFolder: IFolder = {
Name: "Site",
ServerRelativeUrl: this.props.context.pageContext.web.serverRelativeUrl
};

private _onFolderSelect = (folder: IFolder): void => {
console.log('selected folder', folder);

Expand Down Expand Up @@ -1275,6 +1280,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
</div>

<div>
<h3>File Picker</h3>
<FilePicker
bingAPIKey="<BING API KEY>"
//accepts={[".gif", ".jpg", ".jpeg", ".bmp", ".dib", ".tif", ".tiff", ".ico", ".png", ".jxr", ".svg"]}
Expand All @@ -1298,6 +1304,27 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
}
</div>

<div>
<h3>File Picker with target folder browser</h3>
<FilePicker
bingAPIKey="<BING API KEY>"
//accepts={[".gif", ".jpg", ".jpeg", ".bmp", ".dib", ".tif", ".tiff", ".ico", ".png", ".jxr", ".svg"]}
buttonLabel="Upload image"
buttonIcon="FileImage"
onSave={this._onFilePickerSave}
onChange={(filePickerResult: IFilePickerResult) => { console.log(filePickerResult.fileName); }}
context={this.props.context}
hideRecentTab={false}
renderCustomUploadTabContent={() => (
<FolderExplorer context={this.props.context}
rootFolder={this.rootFolder}
defaultFolder={this.rootFolder}
onSelect={this._onFolderSelect}
canCreateFolders={true}
/>)}
/>
</div>

<p><a href="javascript:;" onClick={this.deleteItem}>Deletes second item</a></p>
<div>
<Progress title={'Progress Test'}
Expand Down