PnPjs Version 3 Sample

This commit is contained in:
Julie Turner 2022-02-22 19:57:47 +00:00
parent e7ac8f3a02
commit e63eaf76a5
4 changed files with 28493 additions and 39 deletions

View File

@ -3,7 +3,7 @@
"plusBeta": true, "plusBeta": true,
"isCreatingSolution": true, "isCreatingSolution": true,
"environment": "spo", "environment": "spo",
"version": "1.14.0-beta.4", "version": "1.14.0",
"libraryName": "spfx-pnp-js-example", "libraryName": "spfx-pnp-js-example",
"libraryId": "d20ceaf6-094b-4086-b7a0-85761bc8be23", "libraryId": "d20ceaf6-094b-4086-b7a0-85761bc8be23",
"packageManager": "npm", "packageManager": "npm",
@ -11,4 +11,4 @@
"isDomainIsolated": false, "isDomainIsolated": false,
"componentType": "webpart" "componentType": "webpart"
} }
} }

28449
samples/react-pnp-js-sample/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -14,8 +14,8 @@
"@microsoft/sp-office-ui-fabric-core": "1.14.0", "@microsoft/sp-office-ui-fabric-core": "1.14.0",
"@microsoft/sp-property-pane": "1.14.0", "@microsoft/sp-property-pane": "1.14.0",
"@microsoft/sp-webpart-base": "1.14.0", "@microsoft/sp-webpart-base": "1.14.0",
"@pnp/logging": "^3.0.0", "@pnp/logging": "^3.0.2",
"@pnp/sp": "^3.0.0", "@pnp/sp": "^3.0.2",
"office-ui-fabric-react": "7.174.1", "office-ui-fabric-react": "7.174.1",
"react": "16.13.1", "react": "16.13.1",
"react-dom": "16.13.1" "react-dom": "16.13.1"
@ -31,4 +31,4 @@
"ajv": "~5.2.2", "ajv": "~5.2.2",
"gulp": "~4.0.2" "gulp": "~4.0.2"
} }
} }

View File

@ -42,40 +42,45 @@ export default class PnPjsExample extends React.Component<IPnPjsExampleProps, II
} }
public render(): React.ReactElement<IAsyncAwaitPnPJsProps> { public render(): React.ReactElement<IAsyncAwaitPnPJsProps> {
// calculate total of file sizes try {
const totalDocs: number = this.state.items.length > 0 // calculate total of file sizes
? this.state.items.reduce<number>((acc: number, item: IFile) => { const totalDocs: number = this.state.items.length > 0
return (acc + Number(item.Size)); ? this.state.items.reduce<number>((acc: number, item: IFile) => {
}, 0) return (acc + Number(item.Size));
: 0; }, 0)
return ( : 0;
<div className={styles.pnPjsExample}> return (
<Label>Welcome to PnP JS Version 3 Demo!</Label> <div className={styles.pnPjsExample}>
<PrimaryButton onClick={this._updateTitles}>Update Item Titles</PrimaryButton> <Label>Welcome to PnP JS Version 3 Demo!</Label>
<Label>List of documents:</Label> <PrimaryButton onClick={this._updateTitles}>Update Item Titles</PrimaryButton>
<table width="100%"> <Label>List of documents:</Label>
<tr> <table width="100%">
<td><strong>Title</strong></td> <tr>
<td><strong>Name</strong></td> <td><strong>Title</strong></td>
<td><strong>Size (KB)</strong></td> <td><strong>Name</strong></td>
</tr> <td><strong>Size (KB)</strong></td>
{this.state.items.map((item, idx) => { </tr>
return ( {this.state.items.map((item, idx) => {
<tr key={idx}> return (
<td>{item.Title}</td> <tr key={idx}>
<td>{item.Name}</td> <td>{item.Title}</td>
<td>{(item.Size / 1024).toFixed(2)}</td> <td>{item.Name}</td>
</tr> <td>{(item.Size / 1024).toFixed(2)}</td>
); </tr>
})} );
<tr> })}
<td></td> <tr>
<td><strong>Total:</strong></td> <td></td>
<td><strong>{(totalDocs / 1024).toFixed(2)}</strong></td> <td><strong>Total:</strong></td>
</tr> <td><strong>{(totalDocs / 1024).toFixed(2)}</strong></td>
</table> </tr>
</div > </table>
); </div >
);
} catch (err) {
Logger.write(`${this.LOG_SOURCE} (render) - ${JSON.stringify(err)} - `, LogLevel.Error);
}
return null;
} }
private _readAllFilesSize = async (): Promise<void> => { private _readAllFilesSize = async (): Promise<void> => {