Added container, sample.json, nvmrc

This commit is contained in:
Hugo Bernier 2023-10-17 11:23:45 -04:00
parent 5a58f4f414
commit 1bc45d2ad7
8 changed files with 181 additions and 24 deletions

View File

@ -0,0 +1,39 @@
// For more information on how to run this SPFx project in a VS Code Remote Container, please visit https://aka.ms/spfx-devcontainer
{
"name": "SPFx 1.17.4",
"image": "docker.io/m365pnp/spfx:1.17.4",
// Set *default* container specific settings.json values on container create.
"settings": {},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
4321,
35729
],
"portsAttributes": {
"4321": {
"protocol": "https",
"label": "Manifest",
"onAutoForward": "silent",
"requireLocalPort": true
},
// Not needed for SPFx>= 1.12.1
// "5432": {
// "protocol": "https",
// "label": "Workbench",
// "onAutoForward": "silent"
// },
"35729": {
"protocol": "https",
"label": "LiveReload",
"onAutoForward": "silent",
"requireLocalPort": true
}
},
"postCreateCommand": "bash .devcontainer/spfx-startup.sh",
"remoteUser": "node"
}

View File

@ -0,0 +1,33 @@
echo
echo -e "\e[1;94mInstalling Node dependencies\e[0m"
npm install
## commands to create dev certificate and copy it to the root folder of the project
echo
echo -e "\e[1;94mGenerating dev certificate\e[0m"
gulp trust-dev-cert
# Convert the generated PEM certificate to a CER certificate
openssl x509 -inform PEM -in ~/.rushstack/rushstack-serve.pem -outform DER -out ./spfx-dev-cert.cer
# Copy the PEM ecrtificate for non-Windows hosts
cp ~/.rushstack/rushstack-serve.pem ./spfx-dev-cert.pem
## add *.cer to .gitignore to prevent certificates from being saved in repo
if ! grep -Fxq '*.cer' ./.gitignore
then
echo "# .CER Certificates" >> .gitignore
echo "*.cer" >> .gitignore
fi
## add *.pem to .gitignore to prevent certificates from being saved in repo
if ! grep -Fxq '*.pem' ./.gitignore
then
echo "# .PEM Certificates" >> .gitignore
echo "*.pem" >> .gitignore
fi
echo
echo -e "\e[1;92mReady!\e[0m"
echo -e "\n\e[1;94m**********\nOptional: if you plan on using gulp serve, don't forget to add the container certificate to your local machine. Please visit https://aka.ms/spfx-devcontainer for more information\n**********"

View File

@ -0,0 +1 @@
v16.13.0

View File

@ -2,13 +2,13 @@
## Summary ## Summary
This samples contains two SPFx web parts: This sample contains two SPFx web parts:
**User preferences web part:** ### User preferences web part
This web part allows users to save their preferences in the Microsoft Graph Open Extension. This means that users can access their preferences from any device or application that uses the Microsoft Graph. This web part allows users to save their preferences in the Microsoft Graph Open Extension. This means that users can access their preferences from any device or application that uses the Microsoft Graph.
**Curated news web part:** ### Curated news web part
This web part allows users to view news topics they care about based on the selected preferences. This is a great way to help users stay informed about the topics that are most important to them. This web part allows users to view news topics they care about based on the selected preferences. This is a great way to help users stay informed about the topics that are most important to them.
@ -56,7 +56,7 @@ Access to a SharePoint online site with various tenant users granted access to v
1. Provide name for Microsoft Graph Open Extension. 1. Provide name for Microsoft Graph Open Extension.
2. Provide Search managed property which you want to use to filter results. For example department or topic etc 2. Provide Search managed property which you want to use to filter results. For example department or topic, etc.
![User preferences web part](./assets/targted-news-config.jpg) ![User preferences web part](./assets/targted-news-config.jpg)
@ -76,34 +76,55 @@ Access to a SharePoint online site with various tenant users granted access to v
2. From your command line, change your current directory to the directory containing this sample (`react-news-extension`, located under `samples`) 2. From your command line, change your current directory to the directory containing this sample (`react-news-extension`, located under `samples`)
3. In the command line run: 3. In the command line run:
```cmd ```cmd
`npm install` `npm install`
`gulp bundle` `gulp bundle`
`gulp package-solution` `gulp package-solution`
``` ```
4. Deploy the package to your app catalog 4. Deploy the package to your app catalog
5. Approve the following API permission request from the SharePoint admin 5. Approve the following API permission request from the SharePoint admin
```JSON ```JSON
{ {
"resource": "Microsoft Graph", "resource": "Microsoft Graph",
"scope": "User.ReadWrite" "scope": "User.ReadWrite"
} }
``` ```
7. In the command-line run: 6. In the command-line run:
```cmd ```cmd
gulp serve --nobrowser gulp serve --nobrowser
``` ```
8. Open the hosted workbench on a SharePoint site - i.e. https://_tenant_.sharepoint.com/site/_sitename_/_layouts/workbench.aspx 7. Open the hosted workbench on a SharePoint site - i.e. https://_tenant_.sharepoint.com/site/_sitename_/_layouts/workbench.aspx
8. Configure user preferences and targeted news web parts as per above configurations
9. Configure user preferences and targeted news web parts as per above configurations
## Features ## Features
- User preferences web part allows users to save their preferences in the Microsoft Graph Open Extension. This means that users can access their preferences from any device or application that uses the Microsoft Graph. - User preferences web part allows users to save their preferences in the Microsoft Graph Open Extension. This means that users can access their preferences from any device or application that uses the Microsoft Graph.
- This web part allows users to view news topics they care about based on the selected preferences. This is a great way to help users stay informed about the topics that are most important to them. - This web part allows users to view news topics they care about based on the selected preferences. This is a great way to help users stay informed about the topics that are most important to them.
## Help
We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues.
If you're having issues building the solution, please run [spfx doctor](https://pnp.github.io/cli-microsoft365/cmd/spfx/spfx-doctor/) from within the solution folder to diagnose incompatibility issues with your environment.
You can try looking at [issues related to this sample](https://github.com/pnp/sp-dev-fx-webparts/issues?q=label%3A%22sample%3A%20react-news-extension%22) to see if anybody else is having the same issues.
You can also try looking at [discussions related to this sample](https://github.com/pnp/sp-dev-fx-webparts/discussions?discussions_q=react-news-extension) and see what the community is saying.
If you encounter any issues 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%2Csample%3A%20react-news-extension&template=bug-report.yml&sample=react-news-extension&authors=@ejazhussain&title=react-news-extension%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%3Aquestion%2Csample%3A%20react-news-extension&template=question.yml&sample=react-news-extension&authors=@ejazhussain&title=react-news-extension%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%3Aenhancement%2Csample%3A%20react-news-extension&template=suggestion.yml&sample=react-news-extension&authors=@ejazhussain&title=react-news-extension%20-%20).
## 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.**
<img src="https://m365-visitor-stats.azurewebsites.net/sp-dev-fx-webparts/samples/react-news-extension" />

View File

@ -0,0 +1,62 @@
[
{
"name": "pnp-sp-dev-spfx-web-parts-react-news-extension",
"source": "pnp",
"title": "Targeted News using Microsoft Graph Open Extension",
"shortDescription": "This sample contains two SPFx web parts: User preferences web part and Curated news web part",
"url": "https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-news-extension",
"downloadUrl": "https://pnp.github.io/download-partial/?url=https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-news-extension",
"longDescription": [
"This sample contains two SPFx web parts: User preferences web part and Curated news web part"
],
"creationDateTime": "2023-10-04",
"updateDateTime": "2023-10-04",
"products": [
"SharePoint"
],
"metadata": [
{
"key": "CLIENT-SIDE-DEV",
"value": "React"
},
{
"key": "SPFX-VERSION",
"value": "1.17.4"
}
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://github.com/pnp/sp-dev-fx-webparts/raw/main/samples/react-news-extension/assets/curated-news.png",
"alt": "Curated news"
},
{
"type": "image",
"order": 101,
"url": "https://github.com/pnp/sp-dev-fx-webparts/raw/main/samples/react-news-extension/assets/user-preferences-model.png",
"alt": "User preferences model"
},
{
"type": "image",
"order": 102,
"url": "https://github.com/pnp/sp-dev-fx-webparts/raw/main/samples/react-news-extension/assets/demo.gif",
"alt": "Web Part Preview"
}
],
"authors": [
{
"gitHubAccount": "ejazhussain",
"pictureUrl": "https://github.com/ejazhussain.png",
"name": "Ejaz Hussain"
}
],
"references": [
{
"name": "Build your first SharePoint client-side web part",
"description": "Client-side web parts are client-side components that run in the context of a SharePoint page. Client-side web parts can be deployed to SharePoint environments that support the SharePoint Framework. You can also use modern JavaScript web frameworks, tools, and libraries to build them.",
"url": "https://docs.microsoft.com/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part"
}
]
}
]

View File

@ -3,7 +3,7 @@
const build = require('@microsoft/sp-build-web'); 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.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
build.addSuppression(`Warning - [sass] The local CSS class 'news-container' is not camelCase and will not be type-safe.`);
var getTasks = build.rig.getTasks; var getTasks = build.rig.getTasks;
build.rig.getTasks = function () { build.rig.getTasks = function () {
var result = getTasks.call(build.rig); var result = getTasks.call(build.rig);

View File

@ -14,6 +14,7 @@ class CachingService {
} }
// Retrieve data from the cache by key. // Retrieve data from the cache by key.
// eslint-disable-next-line @rushstack/no-new-null
public static get<T>(key: string): T | null { public static get<T>(key: string): T | null {
const data = this._storage.getItem(key); const data = this._storage.getItem(key);
if (data !== null) { if (data !== null) {

View File

@ -207,7 +207,7 @@ export const Picker: React.FC<IPickerProps> = (props) => {
title="Success!" title="Success!"
color="green" color="green"
> >
Your preferences have been successfully updated. You're good to go! Your preferences have been successfully updated. You&apos;re good to go!
</Alert> </Alert>
)} )}
</Modal> </Modal>