Skip to content

Commit fee0032

Browse files
author
Piotr Siatka
committed
Fix bugs.
Add OrgAssets library support.
1 parent 6ada07a commit fee0032

14 files changed

+256
-113
lines changed

src/controls/filePicker/FilePicker.tsx

Lines changed: 95 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -23,93 +23,43 @@ import styles from './FilePicker.module.scss';
2323
import { FileBrowserService } from '../../services/FileBrowserService';
2424
import { OneDriveFilesTab } from './OneDriveFilesTab';
2525
import { OneDriveService } from '../../services/OneDriveService';
26+
import { OrgAssetsService } from '../../services/OrgAssetsService';
2627

2728
export class FilePicker extends React.Component<IFilePickerProps, IFilePickerState> {
2829
private fileBrowserService: FileBrowserService;
2930
private oneDriveService: OneDriveService;
31+
private orgAssetsService: OrgAssetsService;
32+
3033
constructor(props: IFilePickerProps) {
3134
super(props);
3235

3336
// Initialize file browser services
3437
this.fileBrowserService = new FileBrowserService(props.webPartContext);
3538
this.oneDriveService = new OneDriveService(props.webPartContext);
39+
this.orgAssetsService = new OrgAssetsService(props.webPartContext);
3640

3741
this.state = {
3842
panelOpen: false,
3943
selectedTab: 'keyRecent',
44+
organisationAssetsEnabled: false,
4045
showFullNav: true
4146
};
4247
}
4348

49+
public async componentDidMount() {
50+
// Load information about Organisation Assets Library
51+
const orgAssetsLibraries = await this.orgAssetsService.getSiteMediaLibraries();
52+
const organisationAssetsEnabled = orgAssetsLibraries ? true : false;
53+
54+
this.setState({
55+
organisationAssetsEnabled
56+
})
57+
}
58+
4459
public render(): JSX.Element {
4560
// If no acceptable file type was passed, and we're expecting images, set the default image filter
4661
const accepts: string = this.props.accepts;
4762

48-
// Get a list of groups to display
49-
let groups: INavLinkGroup[] = [
50-
{
51-
links: [
52-
{
53-
name: strings.RecentLinkLabel,
54-
url: '#recent',
55-
icon: 'Recent',
56-
key: 'keyRecent',
57-
},
58-
{
59-
name: strings.WebSearchLinkLabel,
60-
url: '#search',
61-
key: 'keyWeb',
62-
icon: 'Search',
63-
},
64-
{
65-
name: "OneDrive",
66-
url: '#onedrive',
67-
key: 'keyOneDrive',
68-
icon: 'OneDrive',
69-
},
70-
{
71-
name: strings.SiteLinkLabel,
72-
url: '#globe',
73-
key: 'keySite',
74-
icon: 'Globe',
75-
},
76-
{
77-
name: strings.UploadLinkLabel,
78-
url: '#upload',
79-
key: 'keyUpload',
80-
icon: 'System'
81-
},
82-
{
83-
name: strings.FromLinkLinkLabel,
84-
url: '#link',
85-
key: 'keyLink',
86-
icon: 'Link'
87-
}
88-
]
89-
}
90-
];
91-
92-
// Hide tabs we don't want. Start from bottom of the list
93-
// so we're not changing the relative position of items
94-
// as we remove them.
95-
96-
// I'm sure there is a better way to do this...
97-
98-
// If we don't want local uploads, remove it from the list
99-
if (this.props.disableLocalUpload) {
100-
groups[0].links.splice(4, 1);
101-
}
102-
103-
// If we don't want OneDrive, remove it from the list
104-
if (this.props.hasMySiteTab === false) {
105-
groups[0].links.splice(2, 1);
106-
}
107-
108-
// If we don't want web search, remove it from the list
109-
if (this.props.disableWebSearchTab) {
110-
groups[0].links.splice(1, 1);
111-
}
112-
11363
return (
11464
<div >
11565
<Label required={this.props.required}>{this.props.label}</Label>
@@ -132,7 +82,7 @@ export class FilePicker extends React.Component<IFilePickerProps, IFilePickerSta
13282

13383
<div className={styles.nav}>
13484
<Nav
135-
groups={groups}
85+
groups={this._getNavPanelOptions()}
13686
selectedKey={this.state.selectedTab}
13787
onLinkClick={(ev?: React.MouseEvent<HTMLElement>, item?: INavLink) => this._handleLinkClick(ev, item)}
13888
/>
@@ -167,6 +117,21 @@ export class FilePicker extends React.Component<IFilePickerProps, IFilePickerSta
167117
onSave={(value: string) => this._handleSave(value)}
168118
/>
169119
}
120+
{
121+
this.state.selectedTab === "keyOrgAssets" &&
122+
<SiteFilePickerTab
123+
breadcrumbFirstNode={{
124+
isCurrentItem: true,
125+
text: "Images and files provided by your organization",
126+
key: "keyOrgAssets"
127+
}}
128+
fileBrowserService={this.orgAssetsService}
129+
context={this.props.webPartContext}
130+
accepts={accepts}
131+
onClose={() => this._handleClosePanel()}
132+
onSave={(value: string) => this._handleSave(value)}
133+
/>
134+
}
170135
{
171136
this.state.selectedTab === "keyWeb" &&
172137
<WebSearchTab
@@ -245,4 +210,68 @@ export class FilePicker extends React.Component<IFilePickerProps, IFilePickerSta
245210
this.setState({ selectedTab: item.key });
246211
}
247212

213+
private _getNavPanelOptions = () => {
214+
let links = [];
215+
216+
if (!this.props.hideRecentTab) {
217+
links.push({
218+
name: strings.RecentLinkLabel,
219+
url: '#recent',
220+
icon: 'Recent',
221+
key: 'keyRecent',
222+
});
223+
}
224+
if (!this.props.hideWebSearchTab) {
225+
links.push({
226+
name: strings.WebSearchLinkLabel,
227+
url: '#search',
228+
key: 'keyWeb',
229+
icon: 'Search',
230+
});
231+
}
232+
if (!this.props.hideOrganisationalAssetTab && this.state.organisationAssetsEnabled) {
233+
links.push({
234+
name: 'Your organisation',
235+
url: '#orgAssets',
236+
icon: 'FabricFolderConfirm',
237+
key: 'keyOrgAssets',
238+
});
239+
}
240+
if (!this.props.hideOneDriveTab) {
241+
links.push({
242+
name: "OneDrive",
243+
url: '#onedrive',
244+
key: 'keyOneDrive',
245+
icon: 'OneDrive',
246+
});
247+
}
248+
if (!this.props.hideSiteFilesTab) {
249+
links.push({
250+
name: strings.SiteLinkLabel,
251+
url: '#globe',
252+
key: 'keySite',
253+
icon: 'Globe',
254+
});
255+
}
256+
if (!this.props.hideLocalUploadTab) {
257+
links.push({
258+
name: strings.UploadLinkLabel,
259+
url: '#upload',
260+
key: 'keyUpload',
261+
icon: 'System'
262+
});
263+
}
264+
if (!this.props.hideLinkUploadTab) {
265+
links.push({
266+
name: strings.FromLinkLinkLabel,
267+
url: '#link',
268+
key: 'keyLink',
269+
icon: 'Link'
270+
});
271+
}
272+
273+
let groups: INavLinkGroup[] = [ { links} ];
274+
return groups;
275+
}
276+
248277
}

src/controls/filePicker/IFilePickerProps.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ export interface IFilePickerProps {
3131
*/
3232
disabled?: boolean;
3333

34-
disableLocalUpload?: boolean;
35-
disableWebSearchTab?: boolean;
36-
disableCentralAssetRepo?: boolean; // not supported yet
37-
hasMySiteTab?: boolean;
34+
hideRecentTab?: boolean;
35+
hideWebSearchTab?: boolean;
36+
hideOrganisationalAssetTab?: boolean;
37+
hideOneDriveTab?: boolean;
38+
hideSiteFilesTab?: boolean;
39+
hideLocalUploadTab?: boolean;
40+
hideLinkUploadTab?: boolean;
41+
3842
required?: boolean;
3943
onChanged: (value: string) => void;
4044
}

src/controls/filePicker/IFilePickerState.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ export interface IFilePickerState {
22
showFullNav: boolean; // reserved for future use
33
panelOpen: boolean;
44
selectedTab: string;
5+
6+
organisationAssetsEnabled: boolean;
57
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { IFilePickerTab } from "..";
22
import { FileBrowserService } from "../../../services/FileBrowserService";
3+
import { IBreadcrumbItem } from "office-ui-fabric-react/lib/Breadcrumb";
34

45
export interface ISiteFilePickerTabProps extends IFilePickerTab {
56
fileBrowserService: FileBrowserService;
7+
8+
/**
9+
* Represents the base node in the breadrumb navigation
10+
*/
11+
breadcrumbFirstNode?: IBreadcrumbItem;
612
}

src/controls/filePicker/SiteFilePickerTab/SiteFilePickerTab.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ import styles from './SiteFilePickerTab.module.scss';
66

77
// Custom picker interface
88
import { ISiteFilePickerTabProps, ISiteFilePickerTabState, SiteFilePickerBreadcrumbItem } from '.';
9-
import { DocumentLibraryBrowser, FileBrowser, ILibrary } from '../controls';
9+
import { DocumentLibraryBrowser, FileBrowser } from '../controls';
1010

1111
// Office Fabric
1212
import { PrimaryButton, DefaultButton } from 'office-ui-fabric-react/lib/components/Button';
1313
import { Breadcrumb } from 'office-ui-fabric-react/lib/Breadcrumb';
1414

1515
// Localized strings
1616
import * as strings from 'ControlStrings';
17-
import { IFile } from '../../../services/FileBrowserService.types';
17+
import { IFile, ILibrary } from '../../../services/FileBrowserService.types';
1818

1919
export default class SiteFilePickerTab extends React.Component<ISiteFilePickerTabProps, ISiteFilePickerTabState> {
2020
constructor(props: ISiteFilePickerTabProps) {
2121
super(props);
2222

23-
// Add current site to the breadcrumb
24-
const breadcrumbSiteNode: SiteFilePickerBreadcrumbItem = {
23+
// Add current site to the breadcrumb or the provided node
24+
const breadcrumbSiteNode: SiteFilePickerBreadcrumbItem = this.props.breadcrumbFirstNode ? this.props. breadcrumbFirstNode : {
2525
isCurrentItem: true,
2626
text: props.context.pageContext.web.title,
2727
key: props.context.pageContext.web.id.toString()
@@ -42,12 +42,12 @@ export default class SiteFilePickerTab extends React.Component<ISiteFilePickerTa
4242
<div className={styles.tabContainer}>
4343
<div className={styles.tabHeaderContainer}>
4444
{ /** TODO: Fix breadcrumb styles */}
45-
<Breadcrumb items={this.state.breadcrumbItems} className={styles.tabHeader}/>
45+
<Breadcrumb items={this.state.breadcrumbItems} className={styles.tabHeader} />
4646
</div>
4747
<div className={styles.tabFiles}>
4848
{this.state.libraryAbsolutePath === undefined &&
4949
<DocumentLibraryBrowser
50-
context={this.props.context}
50+
fileBrowserService={this.props.fileBrowserService}
5151
onOpenLibrary={(selectedLibrary: ILibrary) => this._handleOpenLibrary(selectedLibrary, true)} />}
5252
{this.state.libraryAbsolutePath !== undefined &&
5353
<FileBrowser

src/controls/filePicker/SiteFilePickerTab/SiteFilePickerTab.types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { IBreadcrumbItem } from "office-ui-fabric-react/lib/Breadcrumb";
2-
import { ILibrary } from "../controls";
3-
import { IFile } from "../../../services/FileBrowserService.types";
2+
import { IFile, ILibrary } from "../../../services/FileBrowserService.types";
43

54
export interface SiteFilePickerBreadcrumbItem extends IBreadcrumbItem {
65
libraryData?: ILibrary;

src/controls/filePicker/controls/DocumentLibraryBrowser/DocumentLibraryBrowser.tsx

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { List } from 'office-ui-fabric-react/lib/List';
55
import { css } from "@uifabric/utilities/lib/css";
66
import { Spinner } from 'office-ui-fabric-react/lib/Spinner';
77

8-
import { IDocumentLibraryBrowserProps, IDocumentLibraryBrowserState, ILibrary } from '.';
8+
import { IDocumentLibraryBrowserProps, IDocumentLibraryBrowserState } from '.';
99
import * as strings from 'ControlStrings';
1010
import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http';
11+
import { ILibrary } from '../../../../services/FileBrowserService.types';
1112

1213
/**
1314
* This would have been better done as an Office Fabric TileList, but it isn't available yet for production use
@@ -22,29 +23,12 @@ export class DocumentLibraryBrowser extends React.Component<IDocumentLibraryBrow
2223
};
2324
}
2425

25-
public componentDidMount(): void {
26-
27-
const { absoluteUrl } = this.props.context.pageContext.web;
28-
29-
const apiUrl: string = `${absoluteUrl}/_api/SP.Web.GetDocumentAndMediaLibraries?webFullUrl='${encodeURIComponent(absoluteUrl)}'&includePageLibraries='false'`;
30-
this.props.context.spHttpClient.get(apiUrl,
31-
SPHttpClient.configurations.v1)
32-
.then((response: SPHttpClientResponse) => {
33-
response.json().then((responseJSON: any) => {
34-
const lists: ILibrary[] = responseJSON.value.map((item) => {
35-
const list: ILibrary = {
36-
title: item.Title,
37-
absoluteUrl: item.AbsoluteUrl,
38-
serverRelativeUrl: item.ServerRelativeUrl
39-
};
40-
return list;
41-
});
42-
this.setState({
43-
lists: lists,
44-
isLoading: false
45-
});
46-
});
47-
});
26+
public async componentDidMount() {
27+
const lists = await this.props.fileBrowserService.getSiteMediaLibraries();
28+
this.setState({
29+
lists: lists,
30+
isLoading: false
31+
});
4832
}
4933

5034
public render(): React.ReactElement<IDocumentLibraryBrowserProps> {
@@ -66,6 +50,9 @@ export class DocumentLibraryBrowser extends React.Component<IDocumentLibraryBrow
6650
* Renders a file folder cover
6751
*/
6852
private _onRenderCell = (item: ILibrary, index: number | undefined): JSX.Element => {
53+
// const folderBlackPlateIcon = item.iconPath ? item.iconPath : strings.FolderBackPlate;
54+
// const folderFrontPlateIcon = item.iconPath ? item.iconPath : strings.FolderFrontPlate;
55+
6956
return (
7057
<div className={styles.listCell} data-is-focusable={true}>
7158
<div className={styles.cell}>

src/controls/filePicker/controls/DocumentLibraryBrowser/DocumentLibraryBrowser.types.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ILibrary } from ".";
2-
import { WebPartContext } from "@microsoft/sp-webpart-base";
1+
import { FileBrowserService } from "../../../../services/FileBrowserService";
2+
import { ILibrary } from "../../../../services/FileBrowserService.types";
33

44
export interface IDocumentLibraryBrowserProps {
5-
context: WebPartContext;
5+
fileBrowserService: FileBrowserService;
66
onOpenLibrary: (selectedLibrary: ILibrary) => void;
77
}

src/controls/filePicker/controls/DocumentLibraryBrowser/IDocumentLibraryBrowserState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ILibrary } from ".";
1+
import { ILibrary } from "../../../../services/FileBrowserService.types";
22

33
export interface IDocumentLibraryBrowserState {
44
isLoading: boolean;

0 commit comments

Comments
 (0)