Replace sp-pnp-js with pnp/sp

This commit is contained in:
Ari Gunawan 2021-05-23 14:58:50 +07:00
parent 72f1b31b86
commit ff946c9f4b
7 changed files with 112 additions and 1862 deletions

View File

@ -22,42 +22,42 @@ Displays page contributors in reverse chronological order.
![Organisation Chart for the current user running in local Workbench](./assets/pagecontributors_mockup.PNG) ![Organisation Chart for the current user running in local Workbench](./assets/pagecontributors_mockup.PNG)
## Used SharePoint Framework Version
![drop](https://img.shields.io/badge/version-GA-green.svg) ## Compatibility
![SPFx 1.12.1](https://img.shields.io/badge/SPFx-1.12.1-green.svg)
![Node.js LTS 10.x](https://img.shields.io/badge/Node.js-LTS%2010.x-green.svg)
![SharePoint Online](https://img.shields.io/badge/SharePoint-Online-yellow.svg)
![Teams N/A: Untested with Microsoft Teams](https://img.shields.io/badge/Teams-N%2FA-lightgrey.svg "Untested with Microsoft Teams")
![Workbench Local | Hosted](https://img.shields.io/badge/Workbench-Local%20%7C%20Hosted-green.svg)
## Applies to ## Applies to
* [SharePoint Framework](https://docs.microsoft.com/sharepoint/dev/spfx/sharepoint-framework-overview) * [SharePoint Framework](https://docs.microsoft.com/sharepoint/dev/spfx/sharepoint-framework-overview)
* [Office 365 tenant](https://docs.microsoft.com/sharepoint/dev/spfx/set-up-your-development-environment) * [Microsoft 365 tenant](https://docs.microsoft.com/sharepoint/dev/spfx/set-up-your-development-environment)
## Prerequisites
PnP-JS-Core
## Solution ## Solution
Solution|Author(s) Solution|Author(s)
--------|--------- --------|---------
PageContributors | Stéphane Magne ([@SPParse](https://twitter.com/SPParse)) PageContributors | Stéphane Magne ([@SPParse](https://twitter.com/SPParse))
PageContributors | Ari Gunawan ([@arigunawan3023](https://twitter.com/arigunawan3023))
## Version history ## Version history
Version|Date|Comments Version|Date|Comments
-------|----|-------- -------|----|--------
1.0|July 27, 2017|Initial release 1.0.0|July 27, 2017|Initial release
1.1.0|May 23, 2021|Update SPFx (v1.12.1) version and replace sp-pnp-js with @pnp/sp (v2.5)
## 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 ## Minimal Path to Awesome
- Clone this repository * Clone this repository
- in the command line run: * in the command line run:
- `npm install` * `npm install`
- `gulp serve` * `gulp serve`
## Features ## Features
@ -70,6 +70,20 @@ This Web Part illustrates the following concepts on top of the SharePoint Framew
- Office UI Fabric - Office UI Fabric
- React - React
- Pnp JS Core - PNP JS
## 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.**
## Support
We do not support samples, but we do use GitHub to track issues and constantly want to improve these samples.
If you encounter any issues while using this sample, [create a new issue](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=bug-report.yml&sample=YOUR-SOLUTION-NAME&authors=@YOURGITHUBUSERNAME&title=YOUR-SOLUTION-NAME%20-%20).
For questions regarding this sample, [create a new question](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=question.yml&sample=YOUR-SOLUTION-NAME&authors=@YOURGITHUBUSERNAME&title=YOUR-SOLUTION-NAME%20-%20).
Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=suggestion.yml&sample=YOUR-SOLUTION-NAME&authors=@YOURGITHUBUSERNAME&title=YOUR-SOLUTION-NAME%20-%20).
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/react-pagecontributors" /> <img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/react-pagecontributors" />

View File

@ -3,7 +3,7 @@
"solution": { "solution": {
"name": "react-pagecontributors-client-side-solution", "name": "react-pagecontributors-client-side-solution",
"id": "1c18830a-4c18-4b82-a571-77863b19c66d", "id": "1c18830a-4c18-4b82-a571-77863b19c66d",
"version": "1.0.0.0", "version": "1.1.0.0",
"skipFeatureDeployment": true, "skipFeatureDeployment": true,
"developer": { "developer": {
"name": "", "name": "",

View File

@ -1673,11 +1673,6 @@
"isomorphic-fetch": "^2.2.1" "isomorphic-fetch": "^2.2.1"
} }
}, },
"@microsoft/microsoft-graph-types": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@microsoft/microsoft-graph-types/-/microsoft-graph-types-1.1.0.tgz",
"integrity": "sha1-CGRuRpJHpBRMcVFhoQgTh63nzTs="
},
"@microsoft/node-core-library": { "@microsoft/node-core-library": {
"version": "3.19.3", "version": "3.19.3",
"resolved": "https://registry.npmjs.org/@microsoft/node-core-library/-/node-core-library-3.19.3.tgz", "resolved": "https://registry.npmjs.org/@microsoft/node-core-library/-/node-core-library-3.19.3.tgz",
@ -2832,6 +2827,71 @@
"integrity": "sha512-hZNKjKOYsckoOEgBziGMnBcX0M7EtstnCmwz5jZUOUYwlZ+/xxX6z3jPu1XVO2Jivk0eLfuP9GP+vFD49CMetw==", "integrity": "sha512-hZNKjKOYsckoOEgBziGMnBcX0M7EtstnCmwz5jZUOUYwlZ+/xxX6z3jPu1XVO2Jivk0eLfuP9GP+vFD49CMetw==",
"dev": true "dev": true
}, },
"@pnp/common": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@pnp/common/-/common-2.5.0.tgz",
"integrity": "sha512-ea4zTNC3sjLolrHZXP+/2SrJM+yC8PygmPW/yRfgbErdvdwYMUSogT69dW+NUaqhkfYZfkkAoWn42irlLMSpdw==",
"requires": {
"tslib": "2.2.0"
},
"dependencies": {
"tslib": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.2.0.tgz",
"integrity": "sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w=="
}
}
},
"@pnp/logging": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@pnp/logging/-/logging-2.5.0.tgz",
"integrity": "sha512-SnmMCN6oADjiHKAIR23FfTqXeQZeXPBnWeVfyZAgzJfRn9uEQoUlkyET3jHjl9kkrFOVkiOD1CRI7TWMIxURbA==",
"requires": {
"tslib": "2.2.0"
},
"dependencies": {
"tslib": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.2.0.tgz",
"integrity": "sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w=="
}
}
},
"@pnp/odata": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@pnp/odata/-/odata-2.5.0.tgz",
"integrity": "sha512-AeP01jDvnkiUVn7V+4FT07chz+G/yzrJDH0Gk+qzujJ393ZO6FwJpJEiOCRh9cxF48gqSj/f7r/IIyDHe0+IpQ==",
"requires": {
"@pnp/common": "2.5.0",
"@pnp/logging": "2.5.0",
"tslib": "2.2.0"
},
"dependencies": {
"tslib": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.2.0.tgz",
"integrity": "sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w=="
}
}
},
"@pnp/sp": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@pnp/sp/-/sp-2.5.0.tgz",
"integrity": "sha512-4s2p+X5qvkXR72NViKb8DIfC+pvj/a3psZ3Im5PRIan2ErMtu9ch3Lb9nkSaMCF3NTJxWOhkUQ/R6tx8ApaUkg==",
"requires": {
"@pnp/common": "2.5.0",
"@pnp/logging": "2.5.0",
"@pnp/odata": "2.5.0",
"tslib": "2.2.0"
},
"dependencies": {
"tslib": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.2.0.tgz",
"integrity": "sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w=="
}
}
},
"@pnpm/error": { "@pnpm/error": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/@pnpm/error/-/error-1.4.0.tgz", "resolved": "https://registry.npmjs.org/@pnpm/error/-/error-1.4.0.tgz",
@ -3457,11 +3517,6 @@
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.117.tgz", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.117.tgz",
"integrity": "sha512-xyf2m6tRbz8qQKcxYZa7PA4SllYcay+eh25DN3jmNYY6gSTL7Htc/bttVdkqj2wfJGbeWlQiX8pIyJpKU+tubw==" "integrity": "sha512-xyf2m6tRbz8qQKcxYZa7PA4SllYcay+eh25DN3jmNYY6gSTL7Htc/bttVdkqj2wfJGbeWlQiX8pIyJpKU+tubw=="
}, },
"@types/microsoft-ajax": {
"version": "0.0.36",
"resolved": "https://registry.npmjs.org/@types/microsoft-ajax/-/microsoft-ajax-0.0.36.tgz",
"integrity": "sha512-aQIlZ0LXpOaxjl0qQt6BoKI9lVPud5z5zxTY1LQBmqmZziryX0rRTHT56WjWTJqVj1M3ZrC/iR606ReuvFs3zA=="
},
"@types/minimatch": { "@types/minimatch": {
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.4.tgz", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.4.tgz",
@ -3584,14 +3639,6 @@
"integrity": "sha512-0caWDWmpCp0uifxFh+FaqK3CuZ2SkRR/ZRxAV5+zNdC3QVUi6wyOJnefhPvtNt8NQWXB5OA93BUvZsXpWat2Xw==", "integrity": "sha512-0caWDWmpCp0uifxFh+FaqK3CuZ2SkRR/ZRxAV5+zNdC3QVUi6wyOJnefhPvtNt8NQWXB5OA93BUvZsXpWat2Xw==",
"dev": true "dev": true
}, },
"@types/sharepoint": {
"version": "2013.1.9",
"resolved": "https://registry.npmjs.org/@types/sharepoint/-/sharepoint-2013.1.9.tgz",
"integrity": "sha512-OP3D/vKnOnZcRwTu2jdt7gp8AGDKx3jFoBHudR7UUX4IIwDqOPEJdkfvIpz/KiQbbbyvWS0PtvDz3iQ1HH/rcw==",
"requires": {
"@types/microsoft-ajax": "*"
}
},
"@types/source-list-map": { "@types/source-list-map": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/@types/source-list-map/-/source-list-map-0.1.2.tgz", "resolved": "https://registry.npmjs.org/@types/source-list-map/-/source-list-map-0.1.2.tgz",
@ -18262,15 +18309,6 @@
"integrity": "sha512-cPiFOTLUKvJFIg4SKVScy4ilPPW6rFgMgfuZJPNoDuMs3nC1HbMUycBoJw77xFIp6z1UJQJOfx6C9GMH80DiTw==", "integrity": "sha512-cPiFOTLUKvJFIg4SKVScy4ilPPW6rFgMgfuZJPNoDuMs3nC1HbMUycBoJw77xFIp6z1UJQJOfx6C9GMH80DiTw==",
"dev": true "dev": true
}, },
"sp-pnp-js": {
"version": "3.0.10",
"resolved": "https://registry.npmjs.org/sp-pnp-js/-/sp-pnp-js-3.0.10.tgz",
"integrity": "sha1-Rm180DEgkNbEXTH20azoAgW9QjA=",
"requires": {
"@microsoft/microsoft-graph-types": "1.1.0",
"@types/sharepoint": "2013.1.9"
}
},
"sparkles": { "sparkles": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/sparkles/-/sparkles-1.0.1.tgz", "resolved": "https://registry.npmjs.org/sparkles/-/sparkles-1.0.1.tgz",

View File

@ -11,7 +11,7 @@
"office-ui-fabric-react": "7.156.0", "office-ui-fabric-react": "7.156.0",
"react": "16.9.0", "react": "16.9.0",
"react-dom": "16.9.0", "react-dom": "16.9.0",
"sp-pnp-js": "^3.0.10" "@pnp/sp": "^2.5.0"
}, },
"devDependencies": { "devDependencies": {
"@microsoft/rush-stack-compiler-3.7": "0.2.3", "@microsoft/rush-stack-compiler-3.7": "0.2.3",

View File

@ -13,12 +13,12 @@ import * as strings from 'pageContributorsStrings';
import PageContributors from './components/PageContributors'; import PageContributors from './components/PageContributors';
import { IPageContributorsWebPartProps } from './IPageContributorsWebPartProps'; import { IPageContributorsWebPartProps } from './IPageContributorsWebPartProps';
import { PersonaSize } from "office-ui-fabric-react/lib/index"; import { PersonaSize } from "office-ui-fabric-react/lib/index";
import pnp from 'sp-pnp-js'; import { sp } from "@pnp/sp/presets/all";
export default class PagecontributionWebPart extends BaseClientSideWebPart<IPageContributorsWebPartProps> { export default class PagecontributionWebPart extends BaseClientSideWebPart<IPageContributorsWebPartProps> {
public onInit(): Promise<void> { public onInit(): Promise<void> {
return super.onInit().then(_ => { return super.onInit().then(_ => {
pnp.setup({ sp.setup({
spfxContext: this.context spfxContext: this.context
}); });
}); });
@ -56,13 +56,13 @@ export default class PagecontributionWebPart extends BaseClientSideWebPart<IPage
PropertyPaneDropdown('personaSize', { PropertyPaneDropdown('personaSize', {
label: strings.PropertyPanePersonaSizeText, label: strings.PropertyPanePersonaSizeText,
options: [ options: [
{ key: PersonaSize.tiny, text: strings.PropertyPaneIconsSizeTiny }, { key: PersonaSize.size8, text: strings.PropertyPaneIconsSizeTiny },
{ key: PersonaSize.extraExtraSmall, text: strings.PropertyPaneIconsSizeEES }, { key: PersonaSize.size24, text: strings.PropertyPaneIconsSizeEES },
{ key: PersonaSize.extraSmall, text: strings.PropertyPaneIconsSizeES }, { key: PersonaSize.size32, text: strings.PropertyPaneIconsSizeES },
{ key: PersonaSize.small, text: strings.PropertyPaneIconsSizeS }, { key: PersonaSize.size40, text: strings.PropertyPaneIconsSizeS },
{ key: PersonaSize.regular, text: strings.PropertyPaneIconsSizeR }, { key: PersonaSize.size48, text: strings.PropertyPaneIconsSizeR },
{ key: PersonaSize.large, text: strings.PropertyPaneIconsSizeL }, { key: PersonaSize.size72, text: strings.PropertyPaneIconsSizeL },
{ key: PersonaSize.extraLarge, text: strings.PropertyPaneIconsSizeEL }, { key: PersonaSize.size100, text: strings.PropertyPaneIconsSizeEL },
], ],
selectedKey: this.properties.personaSize selectedKey: this.properties.personaSize
}), }),

View File

@ -5,7 +5,7 @@ import {
Environment, Environment,
EnvironmentType EnvironmentType
} from '@microsoft/sp-core-library'; } from '@microsoft/sp-core-library';
import pnp from 'sp-pnp-js'; import { sp } from '@pnp/sp';
import { IPageContributorsProps } from "./IPageContributorsProps"; import { IPageContributorsProps } from "./IPageContributorsProps";
export class PageContributor { export class PageContributor {
@ -56,12 +56,12 @@ export class PageContributorsMockData {
export class PageContributorsService { export class PageContributorsService {
public static getPageContributors(pageServerRelativeUrl: string): Promise<PageContributor[]> { public static getPageContributors(pageServerRelativeUrl: string): Promise<PageContributor[]> {
return new Promise<PageContributor[]>((resolve, reject) => { return new Promise<PageContributor[]>((resolve, reject) => {
pnp.sp.web.getFileByServerRelativeUrl(pageServerRelativeUrl) sp.web.getFileByServerRelativeUrl(pageServerRelativeUrl)
.select('ModifiedBy') .select('ModifiedBy')
.expand('ModifiedBy') .expand('ModifiedBy')
.get() .get()
.then(file => { .then(file => {
pnp.sp.web.getFileByServerRelativeUrl(pageServerRelativeUrl) sp.web.getFileByServerRelativeUrl(pageServerRelativeUrl)
.versions .versions
.orderBy('Created') .orderBy('Created')
.select('ID, Created, CreatedBy') .select('ID, Created, CreatedBy')
@ -71,7 +71,7 @@ export class PageContributorsService {
let history = versions.map((version) => { let history = versions.map((version) => {
return new PageContributor(version.CreatedBy); return new PageContributor(version.CreatedBy);
}); });
history.unshift(new PageContributor(file.ModifiedBy)); history.unshift(new PageContributor(file['ModifiedBy']));
history = RemoveDuplicates(history); history = RemoveDuplicates(history);
resolve(history); resolve(history);
}); });

File diff suppressed because it is too large Load Diff