Skip to content

Commit c6cae96

Browse files
committed
fix of #724
1 parent 613fa6f commit c6cae96

File tree

10 files changed

+21
-20
lines changed

10 files changed

+21
-20
lines changed

src/controls/filePicker/OneDriveFilesTab/IOneDriveFilesTabState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IFilePickerResult } from "../FilePicker.types";
44
export interface IOneDriveFilesTabState {
55
filePickerResult: IFilePickerResult;
66
libraryAbsolutePath: string;
7-
libraryTitle: string;
7+
libraryUrl: string;
88
folderPath: string;
99
folderName: string;
1010

src/controls/filePicker/OneDriveFilesTab/OneDriveFilesTab.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class OneDriveFilesTab extends React.Component<IOneDriveFilesTabProps, IO
1919
this.state = {
2020
filePickerResult: null,
2121
libraryAbsolutePath: undefined,
22-
libraryTitle: strings.DocumentLibraries,
22+
libraryUrl: '/Documents',
2323
folderPath: undefined,
2424
folderName: strings.DocumentLibraries,
2525
breadcrumbItems: []
@@ -56,8 +56,7 @@ export class OneDriveFilesTab extends React.Component<IOneDriveFilesTabProps, IO
5656

5757
this.setState({
5858
libraryAbsolutePath: libraryAbsolutePath,
59-
folderName: folderPath,
60-
libraryTitle
59+
folderName: folderPath
6160
});
6261
}
6362

@@ -73,7 +72,7 @@ export class OneDriveFilesTab extends React.Component<IOneDriveFilesTabProps, IO
7372
onChange={(filePickerResult: IFilePickerResult) => this._handleSelectionChange(filePickerResult)}
7473
onOpenFolder={(folder: IFile) => this._handleOpenFolder(folder, true)}
7574
fileBrowserService={this.props.oneDriveService}
76-
libraryName={this.state.libraryTitle}
75+
libraryUrl={this.state.libraryUrl}
7776
folderPath={this.state.folderPath}
7877
accepts={this.props.accepts} />}
7978
</div>

src/controls/filePicker/SiteFilePickerTab/ISiteFilePickerTabState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IFilePickerResult , FilePickerBreadcrumbItem} from "../FilePicker.types
33
export interface ISiteFilePickerTabState {
44
filePickerResult: IFilePickerResult;
55
libraryAbsolutePath: string;
6-
libraryTitle: string;
6+
libraryUrl: string;
77
libraryPath: string;
88
folderName: string;
99

src/controls/filePicker/SiteFilePickerTab/SiteFilePickerTab.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default class SiteFilePickerTab extends React.Component<ISiteFilePickerTa
2626
this.state = {
2727
filePickerResult: null,
2828
libraryAbsolutePath: undefined,
29-
libraryTitle: strings.DocumentLibraries,
29+
libraryUrl: '/Shared%20Documents',
3030
libraryPath: undefined,
3131
folderName: strings.DocumentLibraries,
3232
breadcrumbItems: [breadcrumbSiteNode]
@@ -49,7 +49,7 @@ export default class SiteFilePickerTab extends React.Component<ISiteFilePickerTa
4949
onChange={(filePickerResult: IFilePickerResult) => this._handleSelectionChange(filePickerResult)}
5050
onOpenFolder={(folder: IFile) => this._handleOpenFolder(folder, true)}
5151
fileBrowserService={this.props.fileBrowserService}
52-
libraryName={this.state.libraryTitle}
52+
libraryUrl={this.state.libraryUrl}
5353
folderPath={this.state.libraryPath}
5454
accepts={this.props.accepts} />}
5555
</div>
@@ -180,7 +180,7 @@ export default class SiteFilePickerTab extends React.Component<ISiteFilePickerTa
180180
}
181181
this.setState({
182182
libraryAbsolutePath: library.absoluteUrl,
183-
libraryTitle: library.title,
183+
libraryUrl: library.webRelativeUrl,
184184
libraryPath: library.serverRelativeUrl,
185185
breadcrumbItems
186186
});

src/controls/filePicker/controls/FileBrowser/FileBrowser.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ export class FileBrowser extends React.Component<IFileBrowserProps, IFileBrowser
461461
* Gets all files in a library with a matchihg path
462462
*/
463463
private async _getListItems(concatenateResults: boolean = false) {
464-
const { libraryName, folderPath, accepts } = this.props;
464+
const { libraryUrl, folderPath, accepts } = this.props;
465465
let { items, nextPageQueryString } = this.state;
466466

467467
let filesQueryResult: FilesQueryResult = { items: [], nextHref: null };
@@ -475,7 +475,7 @@ export class FileBrowser extends React.Component<IFileBrowserProps, IFileBrowser
475475
nextPageQueryString
476476
});
477477
// Load files in the folder
478-
filesQueryResult = await this.props.fileBrowserService.getListItems(libraryName, folderPath, accepts, nextPageQueryString);
478+
filesQueryResult = await this.props.fileBrowserService.getListItems(libraryUrl, folderPath, accepts, nextPageQueryString);
479479
} catch (error) {
480480
filesQueryResult.items = null;
481481
console.error(error.message);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IFilePickerResult } from "../../FilePicker.types";
44

55
export interface IFileBrowserProps {
66
fileBrowserService: FileBrowserService;
7-
libraryName: string;
7+
libraryUrl: string;
88
folderPath: string;
99
accepts: string[];
1010
onChange: (filePickerResult: IFilePickerResult) => void;

src/services/FileBrowserService.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ export class FileBrowserService {
2121

2222
/**
2323
* Gets files from current sites library
24-
* @param libraryName
24+
* @param listUrl web-relative url of the list
2525
* @param folderPath
2626
* @param acceptedFilesExtensions
2727
*/
28-
public getListItems = async (libraryName: string, folderPath: string, acceptedFilesExtensions?: string[], nextPageQueryStringParams?: string): Promise<FilesQueryResult> => {
28+
public getListItems = async (listUrl: string, folderPath: string, acceptedFilesExtensions?: string[], nextPageQueryStringParams?: string): Promise<FilesQueryResult> => {
2929
let filesQueryResult: FilesQueryResult = { items: [], nextHref: null };
3030
try {
31-
let restApi = `${this.context.pageContext.web.absoluteUrl}/_api/web/lists/GetByTitle('${libraryName}')/RenderListDataAsStream`;
31+
let restApi = `${this.context.pageContext.web.absoluteUrl}/_api/web/GetList('${listUrl}')/RenderListDataAsStream`;
3232

3333
// Do not pass FolderServerRelativeUrl as query parameter
3434
// Attach passed nextPageQueryStringParams values to REST URL
@@ -72,7 +72,7 @@ export class FileBrowserService {
7272
throw new Error(`Cannot read data from the results.`);
7373
}
7474

75-
const result: ILibrary[] = libResults.value.map((libItem) => { return this.parseLibItem(libItem); });
75+
const result: ILibrary[] = libResults.value.map((libItem) => { return this.parseLibItem(libItem, absoluteUrl); });
7676
return result;
7777
} catch (error) {
7878
console.error(`[FileBrowserService.getSiteMediaLibraries]: Err='${error.message}'`);
@@ -253,11 +253,12 @@ export class FileBrowserService {
253253
return file;
254254
}
255255

256-
protected parseLibItem = (libItem: any): ILibrary => {
256+
protected parseLibItem = (libItem: any, webUrl: string): ILibrary => {
257257
const library: ILibrary = {
258258
title: libItem.Title,
259259
absoluteUrl: libItem.AbsoluteUrl,
260-
serverRelativeUrl: libItem.ServerRelativeUrl
260+
serverRelativeUrl: libItem.ServerRelativeUrl,
261+
webRelativeUrl: libItem.AbsoluteUrl.replace(webUrl, '')
261262
};
262263

263264
return library;

src/services/FileBrowserService.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface ILibrary {
3030
title: string;
3131
absoluteUrl: string;
3232
serverRelativeUrl: string;
33+
webRelativeUrl?: string;
3334
iconPath?: string;
3435
}
3536

src/services/OneDriveService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class OneDriveService extends FileBrowserService {
2525
/**
2626
* Gets files from OneDrive personal library
2727
*/
28-
public getListItems = async (libraryName: string, folderPath?: string, acceptedFilesExtensions?: string[], nextPageQueryStringParams?: string): Promise<FilesQueryResult> => {
28+
public getListItems = async (listUrl: string, folderPath?: string, acceptedFilesExtensions?: string[], nextPageQueryStringParams?: string): Promise<FilesQueryResult> => {
2929
let filesQueryResult: FilesQueryResult = { items: [], nextHref: null };
3030
try {
3131
const oneDriveRootFolder = await this.getOneDriveRootFolderFullUrl();

src/services/OrgAssetsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class OrgAssetsService extends FileBrowserService {
1111
super(context, itemsToDownloadCount);
1212
}
1313

14-
public getListItems = async (libraryName: string, folderPath: string, acceptedFilesExtensions?: string[], nextPageQueryStringParams?: string): Promise<FilesQueryResult> => {
14+
public getListItems = async (listUrl: string, folderPath: string, acceptedFilesExtensions?: string[], nextPageQueryStringParams?: string): Promise<FilesQueryResult> => {
1515
let filesQueryResult: FilesQueryResult = { items: [], nextHref: null };
1616
try {
1717
// Retrieve Lib path from folder path

0 commit comments

Comments
 (0)