Merge pull request #1821 from aaclage/reactonedrivefinder
This commit is contained in:
commit
88aa6d1f9f
|
@ -0,0 +1,25 @@
|
|||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
|
||||
[*]
|
||||
|
||||
# change these settings to your own preference
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
# we recommend you to keep these unchanged
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[{package,bower}.json]
|
||||
indent_style = space
|
||||
indent_size = 2
|
|
@ -0,0 +1,32 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
|
||||
# Build generated files
|
||||
dist
|
||||
lib
|
||||
solution
|
||||
temp
|
||||
*.sppkg
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# OSX
|
||||
.DS_Store
|
||||
|
||||
# Visual Studio files
|
||||
.ntvs_analysis.dat
|
||||
.vs
|
||||
bin
|
||||
obj
|
||||
|
||||
# Resx Generated Code
|
||||
*.resx.ts
|
||||
|
||||
# Styles Generated Code
|
||||
*.scss.ts
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"@microsoft/generator-sharepoint": {
|
||||
"isCreatingSolution": true,
|
||||
"environment": "spo",
|
||||
"version": "1.11.0",
|
||||
"libraryName": "react-onedrive-finder",
|
||||
"libraryId": "63bcee97-4373-4a30-9c62-a1369b4d08ba",
|
||||
"packageManager": "npm",
|
||||
"isDomainIsolated": true,
|
||||
"componentType": "webpart"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
|
@ -0,0 +1,75 @@
|
|||
# OneDrive finder
|
||||
|
||||
## Summary
|
||||
|
||||
This sample access drives from OneDrive and navigate between his content using **Graph OneDrive and Site API and [Microsoft Graph Toolkit](https://github.com/microsoftgraph/microsoft-graph-toolkit) react controls "@microsoft/mgt-react**" with the addition of new control **[FileList](https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/f8b8aa81d00bf426b94ee5016d511bc78b36e152/stories/components/fileList.stories.js#L136) "still preview version"** . This new control provides the ability to retrieve the Drive Library with associated Files and folders making easier to develop and navigate between tenant content and access to file.
|
||||
|
||||
**[FileList](https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/f8b8aa81d00bf426b94ee5016d511bc78b36e152/stories/components/fileList.stories.js#L136)** control allow to load files base on graph querys or parameters ids.
|
||||
|
||||
### Retrieve Sites with drives associate
|
||||
![Demo](./Assets/OneDrivefinderSample1.PNG)
|
||||
### Navigate between folders and Breadcrumb
|
||||
![Demo](./Assets/OneDrivefinderSample2.PNG)
|
||||
|
||||
## Used SharePoint Framework Version
|
||||
|
||||
![version](https://img.shields.io/badge/version-1.11-green.svg)
|
||||
|
||||
## Applies to
|
||||
|
||||
- [SharePoint Framework](https://aka.ms/spfx)
|
||||
- [Microsoft 365 tenant](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)
|
||||
|
||||
|
||||
## Solution
|
||||
|
||||
Solution|Author(s)
|
||||
--------|---------
|
||||
react-onedrive-finder | [André Lage](http://aaclage.blogspot.com) ([@aaclage](https://twitter.com/aaclage))
|
||||
|
||||
## Version history
|
||||
|
||||
Version|Date|Comments
|
||||
-------|----|--------
|
||||
1.0|April 16, 2021|Initial release
|
||||
|
||||
## Disclaimer
|
||||
|
||||
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
|
||||
|
||||
---
|
||||
|
||||
## Minimal Path to Awesome
|
||||
|
||||
- Clone this repository
|
||||
- Ensure that you are at the solution folder
|
||||
- in the command-line run:
|
||||
- **npm install**
|
||||
- **gulp serve**
|
||||
- **gulp bundle --ship**
|
||||
- **gulp package-solution --ship**
|
||||
- Add to AppCatalog and deploy
|
||||
|
||||
## Grant the service principal permission to the Microsoft Graph API
|
||||
|
||||
Once installed, the solution will request the required permissions via the **Office 365 admin portal > SharePoint > Advanced > API access**.
|
||||
If you prefer to approve the permissions in advance, for example when testing the solution in the Workbench page without installing it, you can do so using Office 365 CLI:
|
||||
|
||||
```bash
|
||||
o365 spo login https://contoso-admin.sharepoint.com
|
||||
o365 spo serviceprincipal grant add --resource 'Microsoft Graph' --scope 'Files.Read'
|
||||
o365 spo serviceprincipal grant add --resource 'Microsoft Graph' --scope 'Files.Read.All'
|
||||
o365 spo serviceprincipal grant add --resource 'Microsoft Graph' --scope 'Sites.Read.All'
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
Description of the extension that expands upon high-level summary above.
|
||||
|
||||
This extension illustrates the following concepts:
|
||||
|
||||
- Easy to navigate between shared Drives using **Graph API and Breadcrumb**
|
||||
- **[FileList](https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/f8b8aa81d00bf426b94ee5016d511bc78b36e152/stories/components/fileList.stories.js#L136)** control allow to load documents base on graph querys or parameters ids.
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||
"version": "2.0",
|
||||
"bundles": {
|
||||
"one-drive-finder-web-part": {
|
||||
"components": [
|
||||
{
|
||||
"entrypoint": "./lib/webparts/oneDriveFinder/OneDriveFinderWebPart.js",
|
||||
"manifest": "./src/webparts/oneDriveFinder/OneDriveFinderWebPart.manifest.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"externals": {},
|
||||
"localizedResources": {
|
||||
"OneDriveFinderWebPartStrings": "lib/webparts/oneDriveFinder/loc/{locale}.js"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
|
||||
"deployCdnPath": "temp/deploy"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||
"workingDir": "./temp/deploy/",
|
||||
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||
"container": "react-onedrive-finder",
|
||||
"accessKey": "<!-- ACCESS KEY -->"
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||
"solution": {
|
||||
"name": "react-onedrive-finder-client-side-solution",
|
||||
"id": "63bcee97-4373-4a30-9c62-a1369b4d08ba",
|
||||
"version": "1.0.0.0",
|
||||
"includeClientSideAssets": true,
|
||||
"skipFeatureDeployment": true,
|
||||
"isDomainIsolated": false,
|
||||
"developer": {
|
||||
"name": "",
|
||||
"websiteUrl": "",
|
||||
"privacyUrl": "",
|
||||
"termsOfUseUrl": "",
|
||||
"mpnId": ""
|
||||
},
|
||||
"webApiPermissionRequests": [{
|
||||
"resource": "Microsoft Graph",
|
||||
"scope": "Files.Read"
|
||||
}, {
|
||||
"resource": "Microsoft Graph",
|
||||
"scope": "Files.Read.All"
|
||||
}, {
|
||||
"resource": "Microsoft Graph",
|
||||
"scope": "Sites.Read.All"
|
||||
}]
|
||||
},
|
||||
"paths": {
|
||||
"zippedPackage": "solution/react-onedrive-finder.sppkg"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
|
||||
"port": 4321,
|
||||
"https": true,
|
||||
"initialPage": "https://localhost:5432/workbench",
|
||||
"api": {
|
||||
"port": 5432,
|
||||
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const build = require('@microsoft/sp-build-web');
|
||||
|
||||
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||
|
||||
build.initialize(require('gulp'));
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"name": "react-onedrive-finder",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"main": "lib/index.js",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp bundle",
|
||||
"clean": "gulp clean",
|
||||
"test": "gulp test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@microsoft/mgt": "^2.2.0-next.file.0e80deb",
|
||||
"@microsoft/mgt-react": "^2.2.0-next.file.0e80deb",
|
||||
"@microsoft/sp-core-library": "1.11.0",
|
||||
"@microsoft/sp-lodash-subset": "1.11.0",
|
||||
"@microsoft/sp-office-ui-fabric-core": "1.11.0",
|
||||
"@microsoft/sp-property-pane": "1.11.0",
|
||||
"@microsoft/sp-webpart-base": "1.11.0",
|
||||
"office-ui-fabric-react": "6.214.0",
|
||||
"react": "16.8.5",
|
||||
"react-dom": "16.8.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@microsoft/rush-stack-compiler-3.3": "0.3.5",
|
||||
"@microsoft/rush-stack-compiler-3.7": "^0.6.43",
|
||||
"@microsoft/sp-build-web": "1.11.0",
|
||||
"@microsoft/sp-module-interfaces": "1.11.0",
|
||||
"@microsoft/sp-tslint-rules": "1.11.0",
|
||||
"@microsoft/sp-webpart-workbench": "1.11.0",
|
||||
"@types/chai": "3.4.34",
|
||||
"@types/es6-promise": "0.0.33",
|
||||
"@types/mocha": "2.2.38",
|
||||
"@types/react": "16.8.8",
|
||||
"@types/react-dom": "16.8.3",
|
||||
"@types/webpack-env": "1.13.1",
|
||||
"ajv": "~5.2.2",
|
||||
"gulp": "~3.9.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||
"id": "88e1b1fd-d39d-4194-966c-9bc1c307bcdf",
|
||||
"alias": "OneDriveFinderWebPart",
|
||||
"componentType": "WebPart",
|
||||
|
||||
// The "*" signifies that the version should be taken from the package.json
|
||||
"version": "*",
|
||||
"manifestVersion": 2,
|
||||
|
||||
// If true, the component can only be installed on sites where Custom Script is allowed.
|
||||
// Components that allow authors to embed arbitrary script code should set this to true.
|
||||
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
|
||||
"requiresCustomScript": false,
|
||||
"supportedHosts": ["SharePointWebPart"],
|
||||
|
||||
"preconfiguredEntries": [{
|
||||
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
|
||||
"group": { "default": "Other" },
|
||||
"title": { "default": "OneDrive finder" },
|
||||
"description": { "default": "OneDrive finder description" },
|
||||
"officeFabricIconFontName": "Page",
|
||||
"properties": {
|
||||
"description": "OneDrive finder"
|
||||
}
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
import * as React from 'react';
|
||||
import * as ReactDom from 'react-dom';
|
||||
import { Version } from '@microsoft/sp-core-library';
|
||||
import {
|
||||
IPropertyPaneConfiguration,
|
||||
PropertyPaneTextField
|
||||
} from '@microsoft/sp-property-pane';
|
||||
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
|
||||
import { Providers, SharePointProvider } from '@microsoft/mgt';
|
||||
|
||||
import * as strings from 'OneDriveFinderWebPartStrings';
|
||||
import OneDriveFinder from './components/OneDriveFinder';
|
||||
import { IOneDriveFinderProps } from './components/IOneDriveFinderProps';
|
||||
|
||||
export interface IOneDriveFinderWebPartProps {
|
||||
description: string;
|
||||
}
|
||||
|
||||
export default class OneDriveFinderWebPart extends BaseClientSideWebPart<IOneDriveFinderWebPartProps> {
|
||||
protected onInit() {
|
||||
Providers.globalProvider = new SharePointProvider(this.context);
|
||||
return super.onInit();
|
||||
}
|
||||
public render(): void {
|
||||
const element: React.ReactElement<IOneDriveFinderProps> = React.createElement(
|
||||
OneDriveFinder,
|
||||
{
|
||||
description: this.properties.description,
|
||||
context: this.context
|
||||
}
|
||||
);
|
||||
|
||||
ReactDom.render(element, this.domElement);
|
||||
}
|
||||
|
||||
protected onDispose(): void {
|
||||
ReactDom.unmountComponentAtNode(this.domElement);
|
||||
}
|
||||
|
||||
protected get dataVersion(): Version {
|
||||
return Version.parse('1.0');
|
||||
}
|
||||
|
||||
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||
return {
|
||||
pages: [
|
||||
{
|
||||
header: {
|
||||
description: strings.PropertyPaneDescription
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
groupName: strings.BasicGroupName,
|
||||
groupFields: [
|
||||
PropertyPaneTextField('description', {
|
||||
label: strings.DescriptionFieldLabel
|
||||
})
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
import { WebPartContext } from "@microsoft/sp-webpart-base";
|
||||
|
||||
export interface IOneDriveFinderProps {
|
||||
description: string;
|
||||
context: WebPartContext;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
import { IBreadcrumbItem } from 'office-ui-fabric-react/lib/Breadcrumb';
|
||||
import { IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
|
||||
|
||||
|
||||
export interface IOneDriveFinderState {
|
||||
breadcrumbItem: IBreadcrumbItem[];
|
||||
pageSize: number;
|
||||
siteID:string;
|
||||
itemID:string;
|
||||
siteItems: IDropdownOption[];
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
.some-page-wrapper {
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-basis: 100%;
|
||||
flex: 1;
|
||||
}
|
|
@ -0,0 +1,364 @@
|
|||
import * as React from 'react';
|
||||
import styles from './OneDriveFinder.module.scss';
|
||||
import { IOneDriveFinderProps } from './IOneDriveFinderProps';
|
||||
import { IOneDriveFinderState } from './IOneDriveFinderState';
|
||||
import { FileList } from '@microsoft/mgt-react';
|
||||
import { Breadcrumb, IBreadcrumbItem } from 'office-ui-fabric-react/lib/Breadcrumb';
|
||||
import { Dropdown, IDropdownOption, IDropdownProps } from 'office-ui-fabric-react/lib/Dropdown';
|
||||
import { AadHttpClient } from "@microsoft/sp-http";
|
||||
import { ITheme, mergeStyleSets, getTheme } from 'office-ui-fabric-react/lib/Styling';
|
||||
import { Icon } from 'office-ui-fabric-react/lib/Icon';
|
||||
|
||||
const theme: ITheme = getTheme();
|
||||
const { palette, fonts } = theme;
|
||||
const iconStyles = { marginRight: '8px' };
|
||||
const classNames = mergeStyleSets({
|
||||
itemIndex: {
|
||||
fontSize: fonts.small.fontSize,
|
||||
color: palette.neutralTertiary,
|
||||
marginBottom: 5,
|
||||
},
|
||||
});
|
||||
const dropdownStyles = {
|
||||
dropdown: { width: 300 },
|
||||
root: {
|
||||
}
|
||||
};
|
||||
const dropdownFilterStyles = {
|
||||
dropdown: {
|
||||
width: 130
|
||||
},
|
||||
label: {
|
||||
},
|
||||
root: {
|
||||
paddingLeft: 90
|
||||
}
|
||||
};
|
||||
|
||||
const onRenderCaretDown = (): JSX.Element => {
|
||||
return <Icon iconName="PageRight" />;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param option
|
||||
* Render dropdown list of sites.
|
||||
*/
|
||||
const onRenderOption = (option: IDropdownOption): JSX.Element => {
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
{option.data && option.data.icon && (
|
||||
<Icon style={iconStyles} iconName={option.data.icon} aria-hidden="true" title={option.data.icon} />
|
||||
)}
|
||||
<span>{option.text}</span>
|
||||
</div>
|
||||
<div className={classNames.itemIndex}>{option.data.webUrl}</div>
|
||||
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Render Selected dropdown
|
||||
*/
|
||||
const onRenderTitle = (options: IDropdownOption[]): JSX.Element => {
|
||||
const option = options[0];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
{option.data && option.data.icon && (
|
||||
<Icon style={iconStyles} iconName={option.data.icon} aria-hidden="true" title={option.data.icon} />
|
||||
)}
|
||||
<span>{option.text}</span>
|
||||
</div>
|
||||
<div className={classNames.itemIndex}>{option.data.webUrl}</div>
|
||||
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const onRenderPlaceholder = (props: IDropdownProps): JSX.Element => {
|
||||
return (
|
||||
<div className="dropdownExample-placeholder">
|
||||
<span>{props.placeholder}</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default class OneDriveFinder extends React.Component<IOneDriveFinderProps, IOneDriveFinderState> {
|
||||
public _domain: string;
|
||||
public _itemID: string;
|
||||
public _siteID: string;
|
||||
public _pageSize: number;
|
||||
public _breadcrumbItem: IBreadcrumbItem[] = [];
|
||||
constructor(props: IOneDriveFinderProps, state: IOneDriveFinderState) {
|
||||
super(props);
|
||||
|
||||
// Initialize the state of the component
|
||||
this.state = {
|
||||
breadcrumbItem: [],
|
||||
pageSize: 50,
|
||||
siteID: "",
|
||||
siteItems: [],
|
||||
itemID: ""
|
||||
};
|
||||
this.getDomainData();
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<IOneDriveFinderProps> {
|
||||
const { siteID, itemID, pageSize, breadcrumbItem, siteItems, } = this.state;
|
||||
this._itemID = itemID;
|
||||
this._siteID = siteID;
|
||||
this._breadcrumbItem = breadcrumbItem;
|
||||
return (
|
||||
<div>
|
||||
<div className={styles['some-page-wrapper']}>
|
||||
<div className={styles.row}>
|
||||
<div className={styles.column}>
|
||||
<Dropdown
|
||||
placeholder="Select an Site"
|
||||
label="List of Drives"
|
||||
ariaLabel="Custom dropdown example"
|
||||
onRenderPlaceholder={onRenderPlaceholder}
|
||||
onRenderOption={onRenderOption}
|
||||
onRenderTitle={onRenderTitle}
|
||||
onRenderCaretDown={onRenderCaretDown}
|
||||
styles={dropdownStyles}
|
||||
options={siteItems}
|
||||
onChange={(e, selectedOption) => {
|
||||
if (selectedOption.data.root == undefined) {
|
||||
this._siteID = selectedOption.key.toString();
|
||||
this.setState({
|
||||
siteID: this._siteID,
|
||||
breadcrumbItem: this._breadcrumbItem
|
||||
});
|
||||
} else {
|
||||
this._siteID = "";
|
||||
this.setState({
|
||||
siteID: this._siteID,
|
||||
itemID: "",
|
||||
breadcrumbItem: this._breadcrumbItem
|
||||
});
|
||||
}
|
||||
this.getDrives(selectedOption);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.column}>
|
||||
<Dropdown
|
||||
placeholder="50 Items"
|
||||
label="Filter Items"
|
||||
defaultValue={'50 Items'}
|
||||
styles={dropdownFilterStyles}
|
||||
options={[
|
||||
{ key: 5, text: '5 Items' },
|
||||
{ key: 10, text: '10 Items' },
|
||||
{ key: 50, text: '50 Items' },
|
||||
{ key: 100, text: '100 Items' },
|
||||
{ key: 500, text: '500 Items' },
|
||||
{ key: 1000, text: '1000 Items' },
|
||||
]}
|
||||
onChange={(e, selectedOption) => {
|
||||
let _pageSize: number = +selectedOption.key;
|
||||
this._pageSize = _pageSize;
|
||||
this.setState({
|
||||
pageSize: _pageSize
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Breadcrumb
|
||||
items={this._breadcrumbItem}
|
||||
maxDisplayedItems={10}
|
||||
ariaLabel="Breadcrumb with items rendered as buttons"
|
||||
overflowAriaLabel="More links"
|
||||
/>
|
||||
{(this.state.itemID != "" || this.state.itemID != "") &&
|
||||
<FileList
|
||||
pageSize={pageSize}
|
||||
siteId={this._siteID}
|
||||
itemId={this._itemID}
|
||||
itemClick={this.manageFolder}
|
||||
></FileList>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param e
|
||||
* Capture file or folder and manages breadcrumb
|
||||
*/
|
||||
private manageFolder = (e: any) => {
|
||||
if (e.detail.folder != undefined) {
|
||||
this._breadcrumbItem.push({
|
||||
text: e.detail.name,
|
||||
key: e.detail.id,
|
||||
onClick: (event, item) => {
|
||||
let _cleanBreadcrumbItems: IBreadcrumbItem[] = [];
|
||||
var i = 0;
|
||||
this._breadcrumbItem.some((value) => {
|
||||
if (i == 0) {
|
||||
_cleanBreadcrumbItems.push(value);
|
||||
if (value.key === item.key) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
});
|
||||
this._itemID = e.detail.id;
|
||||
this.setState({
|
||||
itemID: item.key,
|
||||
breadcrumbItem: _cleanBreadcrumbItems
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.setState({
|
||||
itemID: e.detail.id,
|
||||
breadcrumbItem: this._breadcrumbItem
|
||||
});
|
||||
} else {
|
||||
window.open(e.detail.webUrl, '_blank');
|
||||
}
|
||||
}
|
||||
private getRootDriveFolderID = async (siteID) => {
|
||||
let graphData: any = await this.getGraphContent("https://graph.microsoft.com/v1.0/sites/" + siteID + "/drive/root://:/?$select=id");
|
||||
return graphData.id;
|
||||
}
|
||||
|
||||
private getOneDriveRootFolderID = async (key) => {
|
||||
let graphData: any = await this.getGraphContent("https://graph.microsoft.com/v1.0/me/drive/items/" + key + "?$select=id");
|
||||
return graphData.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves Folder item ID from Site or OneDrive
|
||||
*/
|
||||
private getDrives = async (selectedOption: IDropdownOption) => {
|
||||
let itemID: any;
|
||||
if (selectedOption.data.root != undefined) {
|
||||
itemID = await this.getOneDriveRootFolderID(selectedOption.key)
|
||||
} else {
|
||||
itemID = await this.getRootDriveFolderID(selectedOption.key)
|
||||
}
|
||||
|
||||
this._breadcrumbItem = [];
|
||||
this._breadcrumbItem.push({
|
||||
text: selectedOption.text,
|
||||
key: itemID,
|
||||
onClick: (e, item) => {
|
||||
let _cleanBreadcrumbItems: IBreadcrumbItem[] = [];
|
||||
var i = 0;
|
||||
this._breadcrumbItem.some((value) => {
|
||||
if (i == 0) {
|
||||
_cleanBreadcrumbItems.push(value);
|
||||
if (value.key === item.key) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
});
|
||||
this._itemID = itemID;
|
||||
this.setState({
|
||||
itemID: itemID,
|
||||
breadcrumbItem: _cleanBreadcrumbItems
|
||||
});
|
||||
}
|
||||
});
|
||||
this.setState(
|
||||
{
|
||||
breadcrumbItem: this._breadcrumbItem,
|
||||
itemID: itemID
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Retrieve domain name
|
||||
*/
|
||||
private getDomainData = async () => {
|
||||
let graphData: any = await this.getGraphContent("https://graph.microsoft.com/v1.0/sites/root?$select=siteCollection");
|
||||
this.getSiteData(graphData);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param DomainData
|
||||
* Retrieves sites from domain
|
||||
*/
|
||||
private getSiteData = async (DomainData) => {
|
||||
|
||||
let MyDriveData: any = await this.getGraphContent("https://graph.microsoft.com/v1.0/me/drive/root/?$Select=id,name,displayName,webUrl");
|
||||
|
||||
let graphData: any = await this.getGraphContent("https://graph.microsoft.com/v1.0/sites?search=" + escape(DomainData.siteCollection.hostname.split(".")[0]) + ".sharepoint&$Select=id,name,displayName,webUrl");
|
||||
var sharedSitesOptions: Array<IDropdownOption> = new Array<IDropdownOption>();
|
||||
|
||||
// Map the JSON response to the output array
|
||||
graphData.value.map((item: any) => {
|
||||
|
||||
sharedSitesOptions.push({
|
||||
key: item.id,
|
||||
text: item.displayName,
|
||||
data: { icon: 'Globe', webUrl: item.webUrl.split("sharepoint.com")[1] }
|
||||
});
|
||||
});
|
||||
|
||||
//Sort by Web url
|
||||
sharedSitesOptions = sharedSitesOptions.sort((Option1, Option2) => {
|
||||
if (Option1.data.webUrl > Option2.data.webUrl) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (Option1.data.webUrl < Option2.data.webUrl) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
//OneDrive Folder is added as First on List
|
||||
sharedSitesOptions.unshift({
|
||||
key: MyDriveData.id,
|
||||
text: MyDriveData.name,
|
||||
data: { icon: 'OneDriveFolder16', webUrl: MyDriveData.webUrl.split("sharepoint.com")[1], root: true }
|
||||
});
|
||||
|
||||
// Update the component state accordingly to the result
|
||||
this.setState(
|
||||
{
|
||||
siteItems: sharedSitesOptions,
|
||||
}
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Method to Connect Graph
|
||||
*/
|
||||
private getGraphContent = (graphQuery: string) => {
|
||||
|
||||
// Using Graph here, but any 1st or 3rd party REST API that requires Azure AD auth can be used here.
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
this.props.context.aadHttpClientFactory
|
||||
.getClient("https://graph.microsoft.com")
|
||||
.then((client: AadHttpClient) => {
|
||||
// Querys to Graph base on url
|
||||
return client
|
||||
.get(
|
||||
`${graphQuery}`,
|
||||
AadHttpClient.configurations.v1
|
||||
);
|
||||
})
|
||||
.then(response => {
|
||||
return response.json();
|
||||
})
|
||||
.then(json => {
|
||||
resolve(json);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"PropertyPaneDescription": "Description",
|
||||
"BasicGroupName": "Group Name",
|
||||
"DescriptionFieldLabel": "Description Field"
|
||||
}
|
||||
});
|
10
samples/react-onedrive-finder/src/webparts/oneDriveFinder/loc/mystrings.d.ts
vendored
Normal file
10
samples/react-onedrive-finder/src/webparts/oneDriveFinder/loc/mystrings.d.ts
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
declare interface IOneDriveFinderWebPartStrings {
|
||||
PropertyPaneDescription: string;
|
||||
BasicGroupName: string;
|
||||
DescriptionFieldLabel: string;
|
||||
}
|
||||
|
||||
declare module 'OneDriveFinderWebPartStrings' {
|
||||
const strings: IOneDriveFinderWebPartStrings;
|
||||
export = strings;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 383 B |
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.7/includes/tsconfig-web.json",
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"jsx": "react",
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": true,
|
||||
"outDir": "lib",
|
||||
"inlineSources": false,
|
||||
"strictNullChecks": false,
|
||||
"noUnusedLocals": false,
|
||||
"typeRoots": [
|
||||
"./node_modules/@types",
|
||||
"./node_modules/@microsoft"
|
||||
],
|
||||
"types": [
|
||||
"es6-promise",
|
||||
"webpack-env"
|
||||
],
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.collection"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.tsx"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"lib"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
|
||||
"rules": {
|
||||
"class-name": false,
|
||||
"export-name": false,
|
||||
"forin": false,
|
||||
"label-position": false,
|
||||
"member-access": true,
|
||||
"no-arg": false,
|
||||
"no-console": false,
|
||||
"no-construct": false,
|
||||
"no-duplicate-variable": true,
|
||||
"no-eval": false,
|
||||
"no-function-expression": true,
|
||||
"no-internal-module": true,
|
||||
"no-shadowed-variable": true,
|
||||
"no-switch-case-fall-through": true,
|
||||
"no-unnecessary-semicolons": true,
|
||||
"no-unused-expression": true,
|
||||
"no-with-statement": true,
|
||||
"semicolon": true,
|
||||
"trailing-comma": false,
|
||||
"typedef": false,
|
||||
"typedef-whitespace": false,
|
||||
"use-named-parameter": true,
|
||||
"variable-name": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue