Update OneDrive Finder to MGT 2.2.0

This commit is contained in:
aaclage 2021-05-21 00:20:02 +02:00
parent a40043f473
commit ffef72533d
7 changed files with 80 additions and 34 deletions

View File

@ -10,7 +10,7 @@
"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. " "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. "
], ],
"creationDateTime": "2021-04-16", "creationDateTime": "2021-04-16",
"updateDateTime": "2021-04-29", "updateDateTime": "2021-05-20",
"products": [ "products": [
"SharePoint", "SharePoint",
"Office" "Office"

View File

@ -2,11 +2,11 @@
## Summary ## 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 controls **Mgt-File-List [FileList](https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/next/file/stories/components/fileList.stories.js)** and **Mgt-File [File](https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/next/file/stories/components/file.stories.js) "Beta 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. 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 controls **Mgt-File-List [FileList](https://docs.microsoft.com/en-us/graph/toolkit/components/file-list)** and **Mgt-File [File](https://docs.microsoft.com/en-us/graph/toolkit/components/file)** . 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/next/file/specs/mgt-file-list.md)** control allow to load files base on graph querys or parameters ids. **[FileList](https://docs.microsoft.com/en-us/graph/toolkit/components/file-list)** control allow to load files base on graph querys or parameters ids.
**[File](https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/next/file/specs/mgt-file.md)** control allow to File component is used to represent an individual file/folder from OneDrive or SharePoint base on graph querys or parameters ids. **[File](https://docs.microsoft.com/en-us/graph/toolkit/components/file)** control allow to File component is used to represent an individual file/folder from OneDrive or SharePoint base on graph querys or parameters ids.
Below a draw resuming the custom query's made and what control uses to retrieve associated folders and files from different locations. Below a draw resuming the custom query's made and what control uses to retrieve associated folders and files from different locations.
![Demo](./Assets/OneDrivefinderSample4.PNG) ![Demo](./Assets/OneDrivefinderSample4.PNG)
@ -48,6 +48,7 @@ react-onedrive-finder | [André Lage](http://aaclage.blogspot.com) ([@aaclage](h
Version|Date|Comments Version|Date|Comments
-------|----|-------- -------|----|--------
2.0|May 20, 2021|Update MGT to version 2.2.0, include new Features (Localization, cache refresh).
1.2|April 30, 2021|Include content Search on Drive Library, file details and Minimal style change. 1.2|April 30, 2021|Include content Search on Drive Library, file details and Minimal style change.
1.1|April 24, 2021|Fixes, optimization, Styling and extension filter included 1.1|April 24, 2021|Fixes, optimization, Styling and extension filter included
1.0|April 16, 2021|Initial release 1.0|April 16, 2021|Initial release
@ -90,9 +91,10 @@ This extension illustrates the following concepts:
- Easy to navigate between shared Drives using **Graph API and Breadcrumb** - Easy to navigate between shared Drives using **Graph API and Breadcrumb**
- Search in OneDrive Library - Search in OneDrive Library
- Filter by File Extension - Filter by File Extension
- Change theme of control - Change theme of control and Localization
- **[FileList](https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/next/file/specs/mgt-file-list.md)** New mgt-file-list control. - Caching refresh
- **[File](https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/next/file/specs/mgt-file.md)** New mgt-file control. - **[FileList](https://docs.microsoft.com/en-us/graph/toolkit/components/file-list)** New mgt-file-list control.
- **[File](https://docs.microsoft.com/en-us/graph/toolkit/components/file)** New mgt-file control.
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/react-onedrive-finder" /> <img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/react-onedrive-finder" />

View File

@ -12,8 +12,8 @@
"test": "gulp test" "test": "gulp test"
}, },
"dependencies": { "dependencies": {
"@microsoft/mgt": "^2.2.0-next.file.0e80deb", "@microsoft/mgt": "^2.2.0",
"@microsoft/mgt-react": "^2.2.0-next.file.0e80deb", "@microsoft/mgt-react": "^2.2.0",
"@microsoft/sp-core-library": "1.11.0", "@microsoft/sp-core-library": "1.11.0",
"@microsoft/sp-lodash-subset": "1.11.0", "@microsoft/sp-lodash-subset": "1.11.0",
"@microsoft/sp-office-ui-fabric-core": "1.11.0", "@microsoft/sp-office-ui-fabric-core": "1.11.0",

View File

@ -1,13 +1,13 @@
import * as React from 'react'; import * as React from 'react';
import {IDialogFileProps } from './IDialogFileProps'; import { IDialogFileProps } from './IDialogFileProps';
import { Dialog, DialogFooter, DialogType } from 'office-ui-fabric-react/lib/Dialog'; import { Dialog, DialogFooter, DialogType } from 'office-ui-fabric-react/lib/Dialog';
import { Link } from 'office-ui-fabric-react/lib/Link'; import { Link } from 'office-ui-fabric-react/lib/Link';
import { DefaultButton } from 'office-ui-fabric-react/lib/Button'; import { DefaultButton } from 'office-ui-fabric-react/lib/Button';
import { File,ViewType } from '@microsoft/mgt-react'; import { File, ViewType, Person, PersonViewType } from '@microsoft/mgt-react';
export function DialogFile(props: IDialogFileProps) { export function DialogFile(props: IDialogFileProps) {
let _queryString= ""; let _queryString = "";
const { open, fileItem, onClose } = props; const { className, open, fileItem, onClose } = props;
const dialogStyles = { main: { maxWidth: 800 } }; const dialogStyles = { main: { maxWidth: 800 } };
@ -25,14 +25,13 @@ export function DialogFile(props: IDialogFileProps) {
}; };
const checkLink = () => { const checkLink = () => {
if(fileItem != null) if (fileItem != null) {
{
window.open(fileItem.webUrl, '_blank'); window.open(fileItem.webUrl, '_blank');
} }
}; };
if(fileItem != null) if (fileItem != null) {
{ _queryString = "/drives/" + fileItem.parentReference.driveId + "/items/" + fileItem.id;
_queryString = "/drives/"+fileItem.parentReference.driveId +"/items/"+ fileItem.id;
} }
return ( return (
@ -45,6 +44,7 @@ export function DialogFile(props: IDialogFileProps) {
<File <File
view={ViewType.threelines} view={ViewType.threelines}
fileQuery={_queryString} fileQuery={_queryString}
className={className}
></File> ></File>
<Link onClick={checkLink} >File link</Link> <Link onClick={checkLink} >File link</Link>
<DialogFooter> <DialogFooter>

View File

@ -1,4 +1,5 @@
export interface IDialogFileProps { export interface IDialogFileProps {
className: string;
open: boolean; open: boolean;
fileItem:any; fileItem:any;
onClose: () => void; onClose: () => void;

View File

@ -24,9 +24,13 @@
--file-list-box-shadow: none; --file-list-box-shadow: none;
--file-list-padding: 0px; --file-list-padding: 0px;
--file-list-margin: 0; --file-list-margin: 0;
--file-item-border-radius: 0px; --file-item-border-radius: 12px;
--file-item-margin: 0px 0px; --file-item-margin: 0px 0px;
--file-item-border-top: 1px solid #dddddd;
--file-item-border-left: 1px solid #dddddd;
--file-item-border-right: 1px solid #dddddd;
--file-item-border-bottom: 1px solid #dddddd; --file-item-border-bottom: 1px solid #dddddd;
--file-item-border-focused: 1px dashed red;
--show-more-button-background-color: #fef8dd; --show-more-button-background-color: #fef8dd;
--show-more-button-background-color--hover: #ffe7c7; --show-more-button-background-color--hover: #ffe7c7;
--show-more-button-font-size: 14px; --show-more-button-font-size: 14px;

View File

@ -9,8 +9,10 @@ import { Dropdown, IDropdownOption, IDropdownProps } from 'office-ui-fabric-reac
import { AadHttpClient } from "@microsoft/sp-http"; import { AadHttpClient } from "@microsoft/sp-http";
import { ITheme, mergeStyleSets, getTheme } from 'office-ui-fabric-react/lib/Styling'; import { ITheme, mergeStyleSets, getTheme } from 'office-ui-fabric-react/lib/Styling';
import { Icon } from 'office-ui-fabric-react/lib/Icon'; import { Icon } from 'office-ui-fabric-react/lib/Icon';
import { IconButton } from 'office-ui-fabric-react/lib/Button';
import { SearchBox } from 'office-ui-fabric-react/lib/SearchBox'; import { SearchBox } from 'office-ui-fabric-react/lib/SearchBox';
import { Stack, IStackTokens } from 'office-ui-fabric-react/lib/Stack'; import { Stack, IStackTokens } from 'office-ui-fabric-react/lib/Stack';
import { MgtFileList, LocalizationHelper } from '@microsoft/mgt';
const theme: ITheme = getTheme(); const theme: ITheme = getTheme();
const { palette, fonts } = theme; const { palette, fonts } = theme;
@ -99,12 +101,13 @@ export default class OneDriveFinder extends React.Component<IOneDriveFinderProps
public _pageSize: number; public _pageSize: number;
public _breadcrumbItem: IBreadcrumbItem[] = []; public _breadcrumbItem: IBreadcrumbItem[] = [];
public _customStyle: string; public _customStyle: string;
public _fileExtensions: string[] = null; public _fileExtensions: string[] = null;
public flref = React.createRef<MgtFileList>();
constructor(props: IOneDriveFinderProps, state: IOneDriveFinderState) { constructor(props: IOneDriveFinderProps, state: IOneDriveFinderState) {
super(props); super(props);
// Initialize the state of the component // Initialize the state of the component
this.state = { this.state = {
breadcrumbItem: [], breadcrumbItem: [],
pageSize: 50, pageSize: 50,
@ -115,7 +118,7 @@ export default class OneDriveFinder extends React.Component<IOneDriveFinderProps
customStyle: "", customStyle: "",
searchDrive: "", searchDrive: "",
dialogFileStatus: false, dialogFileStatus: false,
dialogFile: null dialogFile: null,
}; };
this.getDomainData(); this.getDomainData();
} }
@ -167,10 +170,30 @@ export default class OneDriveFinder extends React.Component<IOneDriveFinderProps
this.setState({ this.setState({
customStyle: styles.mgtfilelist customStyle: styles.mgtfilelist
}); });
LocalizationHelper.strings = {
_components: {
'file-list': {
showMoreSubtitle: 'Take a pause ☕ and show more'
},
'file': {
modifiedSubtitle: 'Once upon a time in this day ',
}
}
};
} else { } else {
this.setState({ this.setState({
customStyle: selectedOption.text customStyle: selectedOption.text
}); });
LocalizationHelper.strings = {
_components: {
'file-list': {
showMoreSubtitle: 'Show more items'
},
'file': {
modifiedSubtitle: 'Modified ',
}
}
};
} }
}; };
@ -210,6 +233,7 @@ export default class OneDriveFinder extends React.Component<IOneDriveFinderProps
else { else {
this._fileExtensions = null; this._fileExtensions = null;
} }
return ( return (
<div> <div>
<div className={styles.pageWrapper}> <div className={styles.pageWrapper}>
@ -273,10 +297,15 @@ export default class OneDriveFinder extends React.Component<IOneDriveFinderProps
onChange={checkFileExtensions} onChange={checkFileExtensions}
styles={dropdownFilterStyles} styles={dropdownFilterStyles}
/> />
</div> </div>
</div> </div>
</div> </div>
<div> <div>
<IconButton iconProps={{ iconName: 'Refresh' }} text="Refresh cache" onClick={this.refreshMGTControl} allowDisabledFocus disabled={false} checked={false} ></IconButton>
</div>
<div>
<Breadcrumb <Breadcrumb
items={this._breadcrumbItem} items={this._breadcrumbItem}
maxDisplayedItems={10} maxDisplayedItems={10}
@ -285,29 +314,35 @@ export default class OneDriveFinder extends React.Component<IOneDriveFinderProps
/> />
{(this.state.breadcrumbItem.length > 0) && {(this.state.breadcrumbItem.length > 0) &&
<Stack tokens={stackTokens}> <Stack tokens={stackTokens}>
<SearchBox placeholder="Search Drive" onSearch={checkSearchDrive} onClear={checkClear} /> <SearchBox style={{ width: "90%" }} placeholder="Search Drive" onSearch={checkSearchDrive} onClear={checkClear} />
</Stack> </Stack>
} }
{(this.state.itemID != "" && this.state.searchDrive == "") && {(this.state.itemID != "" && this.state.searchDrive == "") &&
<FileList <FileList
ref={this.flref}
className={this._customStyle} className={this._customStyle}
fileExtensions={this._fileExtensions} fileExtensions={this._fileExtensions}
pageSize={this._pageSize} pageSize={this._pageSize}
siteId={this._siteID} siteId={this._siteID}
itemId={this._itemID} itemId={this._itemID}
itemClick={this.manageFolder} itemClick={this.manageFolder}
></FileList> >
</FileList>
} }
{(this.state.searchDrive != "") && {(this.state.searchDrive != "") &&
<FileList <FileList
className={this._customStyle} className={this._customStyle}
fileExtensions={this._fileExtensions} fileExtensions={this._fileExtensions}
pageSize={this._pageSize} pageSize={this._pageSize}
fileListQuery={searchDrive} fileListQuery={searchDrive}
itemClick={selectFile} itemClick={selectFile}
></FileList> >
</FileList>
} }
<DialogFile <DialogFile
className={this._customStyle}
open={this.state.dialogFileStatus} open={this.state.dialogFileStatus}
fileItem={this.state.dialogFile} fileItem={this.state.dialogFile}
onClose={() => { onClose={() => {
@ -321,12 +356,17 @@ export default class OneDriveFinder extends React.Component<IOneDriveFinderProps
); );
} }
private refreshMGTControl = (): void => {
this.flref.current.reload(true);
}
/** /**
* *
* @param e * @param e
* Capture file or folder and manages breadcrumb * Capture file or folder and manages breadcrumb
*/ */
private manageFolder = (e: any) => { private manageFolder = (e: any) => {
console.log(e.detail);
if (e.detail.folder != undefined) { if (e.detail.folder != undefined) {
this._breadcrumbItem.push({ this._breadcrumbItem.push({
text: e.detail.name, text: e.detail.name,
@ -355,7 +395,6 @@ export default class OneDriveFinder extends React.Component<IOneDriveFinderProps
breadcrumbItem: this._breadcrumbItem breadcrumbItem: this._breadcrumbItem
}); });
} else { } else {
console.log(e.detail);
this.setState({ this.setState({
dialogFileStatus: true, dialogFileStatus: true,
dialogFile: e.detail, dialogFile: e.detail,
@ -367,8 +406,8 @@ export default class OneDriveFinder extends React.Component<IOneDriveFinderProps
return graphData.id; return graphData.id;
} }
private getOneDriveRootFolderID = async (key) => { private getOneDriveRootFolderID = async (ItemId) => {
let graphData: any = await this.getGraphContent("https://graph.microsoft.com/v1.0/me/drive/items/" + key + "?$select=id"); let graphData: any = await this.getGraphContent("https://graph.microsoft.com/v1.0/me/drive/items/" + ItemId + "?$select=id");
return graphData.id; return graphData.id;
} }