Skip to content

Commit f972238

Browse files
author
Piotr Siatka
committed
Replace accepts to string[].
Replace IconButton with Action button. Update documentation.
1 parent e948986 commit f972238

File tree

11 files changed

+31
-31
lines changed

11 files changed

+31
-31
lines changed

docs/documentation/docs/controls/FilePicker.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ Currently supported locations
1313
The control supports all types of file, however it also allows to specify list of extensions for the files that are going to be looked displayed. Currently, only single file selection is supported.
1414
![File Picker overview](../assets/FilePickerOverview.png)
1515

16-
### Contribution
17-
**File picker control has been developed based on the great SPFx project made by Hugo and presented in the [SP-Dev-Fx-WebParts Sample Repository](https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/react-comparer)**.
18-
1916

2017
## Different display types
2118
File picker support 3 types of views : List, Compact list and Tiles. In case Tiles view is selected, the control shows the thumbnail of the file.
@@ -61,11 +58,11 @@ The FilePicker component can be configured with the following properties:
6158
| ---- | ---- | ---- | ---- |
6259
| label | string | no | Specifies the text describing the file picker. |
6360
| buttonLabel | string | no | Specifies the label of the file picker button. |
64-
| buttonIcon | string | no | In case it is provided the file picker will be rendered as an Icon button. |
61+
| buttonIcon | string | no | In case it is provided the file picker will be rendered as an action button. |
6562
| onSave | (filePickerResult: IFilePickerResult) => void | yes | Handler when the file has been selected and picker has been closed. |
6663
| onChange | (filePickerResult: IFilePickerResult) => void | yes | Handler when the file selection has been changed. |
6764
| webPartContext | WebPartContext | yes | Current context. |
68-
| accepts | string | no | Comma separated list of file extensions that going to be displayed. E.g. ".gif,.jpg,.jpeg,.bmp,.dib,.tif,.tiff,.ico,.png,.jxr,.svg" |
65+
| accepts | string[] | no | Array of strings containing allowed files extensions. E.g. [".gif", ".jpg", ".jpeg", ".bmp", ".dib", ".tif", ".tiff", ".ico", ".png", ".jxr", ".svg"] |
6966
| required | boolean | no | Sets the label to inform that the value is required. |
7067
| bingAPIKey | string | no | Used to execute WebSearch. If not provided SearchTab will not be available. |
7168
| disabled | boolean | no | Specifies if the picker button is disabled |

src/controls/filePicker/FilePicker.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { IFilePickerProps } from './IFilePickerProps';
33
import { IFilePickerState } from './IFilePickerState';
44

5-
import { PrimaryButton, IconButton } from 'office-ui-fabric-react/lib/components/Button';
5+
import { PrimaryButton, IconButton, ActionButton } from 'office-ui-fabric-react/lib/components/Button';
66
import { Panel, PanelType } from 'office-ui-fabric-react/lib/components/Panel';
77
import { Label } from 'office-ui-fabric-react/lib/components/Label';
88
import { Nav, INavLink, INavLinkGroup } from 'office-ui-fabric-react/lib/Nav';
@@ -64,7 +64,7 @@ export class FilePicker extends React.Component<IFilePickerProps, IFilePickerSta
6464

6565
public render(): JSX.Element {
6666
// If no acceptable file type was passed, and we're expecting images, set the default image filter
67-
const accepts: string = this.props.accepts;
67+
const accepts: string[] = this.props.accepts;
6868

6969
const linkTabProps = {
7070
accepts: accepts,
@@ -73,6 +73,7 @@ export class FilePicker extends React.Component<IFilePickerProps, IFilePickerSta
7373
onSave: (value: IFilePickerResult) => { this._handleSave(value); }
7474
};
7575
const buttonProps = {
76+
text: this.props.buttonLabel,
7677
disabled: this.props.disabled,
7778
onClick: this._handleOpenPanel
7879
};
@@ -84,8 +85,8 @@ export class FilePicker extends React.Component<IFilePickerProps, IFilePickerSta
8485
}
8586
{
8687
this.props.buttonIcon ?
87-
<IconButton iconProps={{ iconName: this.props.buttonIcon }} {...buttonProps} /> :
88-
<PrimaryButton text={this.props.buttonLabel} {...buttonProps}/>
88+
<ActionButton iconProps={{ iconName: this.props.buttonIcon }} {...buttonProps} /> :
89+
<PrimaryButton {...buttonProps}/>
8990
}
9091

9192
<Panel isOpen={this.state.panelOpen}

src/controls/filePicker/FilePicker.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface FilePickerBreadcrumbItem extends IBreadcrumbItem {
99

1010
export interface IFilePickerTab {
1111
context: WebPartContext;
12-
accepts: string;
12+
accepts: string[];
1313
onSave: (value: IFilePickerResult) => void;
1414
onClose: () => void;
1515
}

src/controls/filePicker/IFilePickerProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface IFilePickerProps {
3434
/**
3535
* File extensions to be displayed.
3636
*/
37-
accepts?: string;
37+
accepts?: string[];
3838

3939
/**
4040
* Sets the label to inform that the value is required.

src/controls/filePicker/UploadFilePickerTab/UploadFilePickerTab.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default class UploadFilePickerTab extends React.Component<IUploadFilePick
2121
public render(): React.ReactElement<IUploadFilePickerTabProps> {
2222
const { filePickerResult } = this.state;
2323
const fileName: string = filePickerResult ? filePickerResult.fileName : null;
24+
const acceptedFilesExtensions = this.props.accepts ? this.props.accepts.join(",") : null;
2425

2526
return (
2627
<div className={styles.tabContainer}>
@@ -31,7 +32,7 @@ export default class UploadFilePickerTab extends React.Component<IUploadFilePick
3132
<input
3233
className={styles.localTabInput}
3334
type="file" id="fileInput"
34-
accept={this.props.accepts} multiple={false} onChange={(event: React.ChangeEvent<HTMLInputElement>) => this._handleFileUpload(event)}
35+
accept={acceptedFilesExtensions} multiple={false} onChange={(event: React.ChangeEvent<HTMLInputElement>) => this._handleFileUpload(event)}
3536
/>
3637
{
3738
fileName &&

src/controls/filePicker/controls/FileBrowser/IFileBrowserProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface IFileBrowserProps {
77
fileBrowserService: FileBrowserService;
88
libraryName: string;
99
folderPath: string;
10-
accepts: string;
10+
accepts: string[];
1111
onChange: (filePickerResult: IFilePickerResult) => void;
1212
onOpenFolder: (folder: IFile) => void;
1313
}

src/services/FileBrowserService.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export class FileBrowserService {
2222
* Gets files from current sites library
2323
* @param libraryName
2424
* @param folderPath
25-
* @param acceptedFilesExtensionsList
25+
* @param acceptedFilesExtensions
2626
*/
27-
public getListItems = async (libraryName: string, folderPath: string, acceptedFilesExtensionsList?: string, nextPageQueryStringParams?: string): Promise<FilesQueryResult> => {
27+
public getListItems = async (libraryName: string, folderPath: string, acceptedFilesExtensions?: string[], nextPageQueryStringParams?: string): Promise<FilesQueryResult> => {
2828
let filesQueryResult: FilesQueryResult = { items: [], nextHref: null };
2929
try {
3030
let restApi = `${this.context.pageContext.web.absoluteUrl}/_api/web/lists/GetByTitle('${libraryName}')/RenderListDataAsStream`;
@@ -36,7 +36,7 @@ export class FileBrowserService {
3636
folderPath = null;
3737
}
3838

39-
filesQueryResult = await this._getListDataAsStream(restApi, folderPath, acceptedFilesExtensionsList);
39+
filesQueryResult = await this._getListDataAsStream(restApi, folderPath, acceptedFilesExtensions);
4040
} catch (error) {
4141
filesQueryResult.items = null;
4242
console.error(error.message);
@@ -80,17 +80,17 @@ export class FileBrowserService {
8080
* Executes query to load files with possible extension filtering
8181
* @param restApi
8282
* @param folderPath
83-
* @param acceptedFilesExtensionsList
83+
* @param acceptedFilesExtensions
8484
*/
85-
protected _getListDataAsStream = async (restApi: string, folderPath: string, acceptedFilesExtensionsList?: string): Promise<FilesQueryResult> => {
85+
protected _getListDataAsStream = async (restApi: string, folderPath: string, acceptedFilesExtensions?: string[]): Promise<FilesQueryResult> => {
8686
let filesQueryResult: FilesQueryResult = { items: [], nextHref: null };
8787
try {
8888
const body = {
8989
parameters: {
9090
AllowMultipleValueFilterForTaxonomyFields: true,
9191
// ContextInfo (1), ListData (2), ListSchema (4), ViewMetadata (1024), EnableMediaTAUrls (4096), ParentInfo (8192)
9292
RenderOptions: 1 | 2 | 4 | 1024 | 4096 | 8192,
93-
ViewXml: this.getFilesCamlQueryViewXml(acceptedFilesExtensionsList)
93+
ViewXml: this.getFilesCamlQueryViewXml(acceptedFilesExtensions)
9494
}
9595
};
9696
if (folderPath) {
@@ -128,12 +128,12 @@ export class FileBrowserService {
128128
* Generates CamlQuery files filter.
129129
* @param accepts
130130
*/
131-
protected getFileTypeFilter(accepts: string) {
131+
protected getFileTypeFilter(accepts: string[]) {
132132
let fileFilter: string = "";
133133

134-
if (accepts && accepts != "") {
134+
if (accepts && accepts.length > 0) {
135135
fileFilter = "<Values>";
136-
accepts.split(",").forEach((fileType: string, index: number) => {
136+
accepts.forEach((fileType: string, index: number) => {
137137
fileType = fileType.replace(".", "");
138138
if (index >= 0) {
139139
fileFilter = fileFilter + `<Value Type="Text">${fileType}</Value>`;
@@ -148,7 +148,7 @@ export class FileBrowserService {
148148
/**
149149
* Generates Files CamlQuery ViewXml
150150
*/
151-
protected getFilesCamlQueryViewXml = (accepts: string) => {
151+
protected getFilesCamlQueryViewXml = (accepts: string[]) => {
152152
const fileFilter: string = this.getFileTypeFilter(accepts);
153153
let queryCondition = fileFilter && fileFilter != "" ?
154154
`<Query>

src/services/FilesSearchService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class FilesSearchService {
4141
}
4242
}
4343

44-
public executeRecentSearch = async (accepts?: string) => {
44+
public executeRecentSearch = async (accepts?: string[]) => {
4545
try {
4646
const webId = this.context.pageContext.web.id.toString();
4747
const siteId = this.context.pageContext.site.id.toString();
@@ -193,11 +193,11 @@ export class FilesSearchService {
193193
/**
194194
* Builds a file filter using the accepted file extensions
195195
*/
196-
private _getFileFilter(accepts?: string) {
196+
private _getFileFilter(accepts?: string[]) {
197197
let fileFilter: string = undefined;
198198
if (accepts) {
199199
fileFilter = " AND (";
200-
accepts.split(",").forEach((fileType: string, index: number) => {
200+
accepts.forEach((fileType: string, index: number) => {
201201
fileType = fileType.replace(".", "");
202202
if (index > 0) {
203203
fileFilter = fileFilter + " OR ";

src/services/OneDriveService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class OneDriveService extends FileBrowserService {
2626
/**
2727
* Gets files from OneDrive personal library
2828
*/
29-
public getListItems = async (libraryName: string, folderPath?: string, acceptedFilesExtensionsList?: string, nextPageQueryStringParams?: string): Promise<FilesQueryResult> => {
29+
public getListItems = async (libraryName: string, folderPath?: string, acceptedFilesExtensions?: string[], nextPageQueryStringParams?: string): Promise<FilesQueryResult> => {
3030
let filesQueryResult: FilesQueryResult = { items: [], nextHref: null };
3131
try {
3232
const oneDriveRootFolder = await this.getOneDriveRootFolderFullUrl();
@@ -47,7 +47,7 @@ export class OneDriveService extends FileBrowserService {
4747
}
4848

4949
const restApi = `${this.context.pageContext.web.absoluteUrl}/_api/SP.List.GetListDataAsStream?listFullUrl='${encodedListUrl}'&${queryStringParams}`;
50-
filesQueryResult = await this._getListDataAsStream(restApi, null, acceptedFilesExtensionsList);
50+
filesQueryResult = await this._getListDataAsStream(restApi, null, acceptedFilesExtensions);
5151
} catch (error) {
5252
filesQueryResult.items = null;
5353
console.error(error.message);

src/services/OrgAssetsService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class OrgAssetsService extends FileBrowserService {
1010
super(context, itemsToDownloadCount);
1111
}
1212

13-
public getListItems = async (libraryName: string, folderPath: string, acceptedFilesExtensionsList?: string, nextPageQueryStringParams?: string): Promise<FilesQueryResult> => {
13+
public getListItems = async (libraryName: string, folderPath: string, acceptedFilesExtensions?: string[], nextPageQueryStringParams?: string): Promise<FilesQueryResult> => {
1414
let filesQueryResult: FilesQueryResult = { items: [], nextHref: null };
1515
try {
1616
// Retrieve Lib path from folder path
@@ -37,7 +37,7 @@ export class OrgAssetsService extends FileBrowserService {
3737
}
3838
const restApi = `${this.context.pageContext.web.absoluteUrl}/_api/SP.List.GetListDataAsStream?listFullUrl='${libFullUrl}'&${queryStringParams}`;
3939

40-
filesQueryResult = await this._getListDataAsStream(restApi, null, acceptedFilesExtensionsList);
40+
filesQueryResult = await this._getListDataAsStream(restApi, null, acceptedFilesExtensions);
4141
} catch (error) {
4242
filesQueryResult.items = null;
4343
console.error(error.message);

0 commit comments

Comments
 (0)