Merge pull request #3122 from pnp:react-azurefunction-northwind
Added sample from #3031
This commit is contained in:
commit
500f3a0158
|
@ -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.15.2",
|
||||
"image": "docker.io/m365pnp/spfx:1.15.2",
|
||||
// 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"
|
||||
}
|
|
@ -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**********"
|
|
@ -0,0 +1,34 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
|
||||
# Build generated files
|
||||
dist
|
||||
lib
|
||||
release
|
||||
solution
|
||||
temp
|
||||
*.sppkg
|
||||
.heft
|
||||
|
||||
# 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,16 @@
|
|||
!dist
|
||||
config
|
||||
|
||||
gulpfile.js
|
||||
|
||||
release
|
||||
src
|
||||
temp
|
||||
|
||||
tsconfig.json
|
||||
tslint.json
|
||||
|
||||
*.log
|
||||
|
||||
.yo-rc.json
|
||||
.vscode
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"@microsoft/generator-sharepoint": {
|
||||
"plusBeta": false,
|
||||
"isCreatingSolution": true,
|
||||
"version": "1.15.2",
|
||||
"libraryName": "react-azurefunction-sql",
|
||||
"libraryId": "dfceb4ae-e27d-4baf-be15-8c0d1e4966b3",
|
||||
"environment": "spo",
|
||||
"packageManager": "npm",
|
||||
"solutionName": "react-azurefunction-sql",
|
||||
"solutionShortDescription": "react-azurefunction-sql description",
|
||||
"skipFeatureDeployment": true,
|
||||
"isDomainIsolated": false,
|
||||
"componentType": "webpart"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace FunctionAppNW
|
||||
{
|
||||
|
||||
public class Customers
|
||||
{
|
||||
public string CustomerID { get; set; }
|
||||
public string CompanyName { get; set; }
|
||||
public string ContactName { get; set; }
|
||||
public string ContactTitle { get; set; }
|
||||
public string Address { get; set; }
|
||||
public string City { get; set; }
|
||||
public string Region { get; set; }
|
||||
public string PostalCode { get; set; }
|
||||
public string Country { get; set; }
|
||||
}
|
||||
|
||||
public static class ProcessCustomers
|
||||
{
|
||||
[FunctionName("GetCustomers")]
|
||||
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "customer")] HttpRequest req, ILogger log)
|
||||
{
|
||||
log.LogInformation("C# HTTP trigger function processed a request.");
|
||||
|
||||
|
||||
List<Customers> customersList = new List<Customers>();
|
||||
|
||||
try
|
||||
{
|
||||
using (SqlConnection connection = new SqlConnection(Environment.GetEnvironmentVariable("SqlConnectionString")))
|
||||
{
|
||||
connection.Open();
|
||||
var query = @"Select * from Customers";
|
||||
SqlCommand command = new SqlCommand(query, connection);
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
Customers customer = new Customers()
|
||||
{
|
||||
CustomerID = reader["CustomerID"].ToString(),
|
||||
CompanyName = reader["CompanyName"].ToString(),
|
||||
ContactName = reader["ContactName"].ToString(),
|
||||
ContactTitle = reader["ContactTitle"].ToString(),
|
||||
Address = reader["Address"].ToString(),
|
||||
City = reader["City"].ToString(),
|
||||
PostalCode = reader["PostalCode"].ToString(),
|
||||
Region = reader["Region"].ToString(),
|
||||
|
||||
};
|
||||
customersList.Add(customer);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.LogError(e.ToString());
|
||||
}
|
||||
if (customersList.Count > 0)
|
||||
{
|
||||
return new OkObjectResult(customersList);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2022 Joao Livio
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,107 @@
|
|||
# Consume Northwind Microsoft database from Azure using a Function App
|
||||
|
||||
## Summary
|
||||
|
||||
This web part consume an anonymous Function App from an HTTP Trigger using the templates from the Northwind Microsoft DBs
|
||||
You must create a database in azure and run the scripts
|
||||
|
||||
- [Here](https://github.com/microsoft/sql-server-samples/blob/master/samples/databases/northwind-pubs/readme.md)
|
||||
|
||||
![SAMPLE](./assets/FAPP.png)
|
||||
|
||||
## Compatibility
|
||||
|
||||
This sample is optimally compatible with the following environment configuration:
|
||||
|
||||
![SPFx 1.15.2](https://img.shields.io/badge/SPFx-1.15.2-green.svg)
|
||||
![Node.js v16 | v14 | v12](https://img.shields.io/badge/Node.js-v16%20%7C%20v14%20%7C%20v12-green.svg)
|
||||
![Compatible with SharePoint Online](https://img.shields.io/badge/SharePoint%20Online-Compatible-green.svg)
|
||||
![Does not work with SharePoint 2019](https://img.shields.io/badge/SharePoint%20Server%202019-Incompatible-red.svg "SharePoint Server 2019 requires SPFx 1.4.1 or lower")
|
||||
![Does not work with SharePoint 2016 (Feature Pack 2)](https://img.shields.io/badge/SharePoint%20Server%202016%20(Feature%20Pack%202)-Incompatible-red.svg "SharePoint Server 2016 Feature Pack 2 requires SPFx 1.1")
|
||||
![Local Workbench Unsupported](https://img.shields.io/badge/Local%20Workbench-Unsupported-red.svg "Local workbench is no longer available as of SPFx 1.13 and above")
|
||||
![Hosted Workbench Compatible](https://img.shields.io/badge/Hosted%20Workbench-Compatible-green.svg)
|
||||
![Compatible with Remote Containers](https://img.shields.io/badge/Remote%20Containers-Compatible-green.svg)
|
||||
|
||||
For more information about SPFx compatibility, please refer to <https://aka.ms/spfx-matrix>
|
||||
|
||||
## Applies to
|
||||
|
||||
- [SharePoint Framework](https://learn.microsoft.com/sharepoint/dev/spfx/sharepoint-framework-overview)
|
||||
- [Microsoft 365 tenant](https://learn.microsoft.com/sharepoint/dev/spfx/set-up-your-development-environment)
|
||||
|
||||
> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/m365devprogram)
|
||||
|
||||
## Solution
|
||||
|
||||
| Solution | Author(s) |
|
||||
| ----------- | ------------------------------------------------------- |
|
||||
| react-azurefunction-northwind | [Joao Livio](https://github.com/jtlivio) @jlivio |
|
||||
|
||||
## Version history
|
||||
|
||||
| Version | Date | Comments |
|
||||
| ------- | ---------------- | --------------- |
|
||||
| 1.0 | August 15, 2022 | Initial release |
|
||||
|
||||
|
||||
## Minimal Path to Awesome
|
||||
|
||||
- Clone this repository (or [download this solution as a .ZIP file](https://pnp.github.io/download-partial/?url=https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-azurefunction-northwind2) then unzip it)
|
||||
- From your command line, change your current directory to the directory containing this sample (`react-azurefunction-northwind2`, located under `samples`)
|
||||
- in the command line run:
|
||||
- `npm install`
|
||||
- `gulp serve`
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
- Consume a Function app from SQL Server
|
||||
- No Authentication is active, only the url code for the Function, must change
|
||||
- [Uses react controls (Listview)](https://pnp.github.io/sp-dev-fx-controls-react/)
|
||||
- [Uses react property controls](https://pnp.github.io/sp-dev-fx-property-controls/)
|
||||
|
||||
## References
|
||||
|
||||
- [Go and create a database in Azure](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/northwind-pubs)
|
||||
- [Create your first Function](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/build-for-teams-overview)
|
||||
- [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
|
||||
|
||||
## Function Code
|
||||
|
||||
- [Code for your Function](https://github.com/jtlivio/react-azurefunction-northwind/blob/master/FunctionCode.cs)
|
||||
|
||||
## Suggestion
|
||||
|
||||
- Use a Serverless Database
|
||||
- Use a Pay as You Go Model in your function
|
||||
- In Production use Key Vault for your Connection String
|
||||
|
||||
## Secure your Function with AAD
|
||||
- [Securing Azure Functions](https://docs.microsoft.com/en-us/azure/azure-functions/security-concepts?tabs=v4)
|
||||
- [Configure your App Service or Azure Functions app to use Azure AD login](https://docs.microsoft.com/en-us/azure/app-service/configure-authentication-provider-aad)
|
||||
|
||||
## aadHttpClientFactory
|
||||
|
||||
- [Connect to Azure AD applications using the AadHttpClient](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/use-aadhttpclient)
|
||||
|
||||
## 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-azurefunction-northwind2%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-azurefunction-northwind2) 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-azurefunction-northwind2&template=bug-report.yml&sample=react-azurefunction-northwind2&authors=@jtlivio&title=react-azurefunction-northwind2%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-azurefunction-northwind2&template=question.yml&sample=react-azurefunction-northwind2&authors=@jtlivio&title=react-azurefunction-northwind2%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-azurefunction-northwind2&template=suggestion.yml&sample=react-azurefunction-northwind2&authors=@jtlivio&title=react-azurefunction-northwind2%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://pnptelemetry.azurewebsites.net/sp-dev-fx-webparts/samples/react-azurefunction-northwind2" />
|
Binary file not shown.
After Width: | Height: | Size: 77 KiB |
|
@ -0,0 +1,56 @@
|
|||
[
|
||||
{
|
||||
"name": "pnp-sp-dev-spfx-web-parts-react-azurefunction-northwind2",
|
||||
"source": "pnp",
|
||||
"title": "Consume Northwind Microsoft database from Azure using a Function App ",
|
||||
"shortDescription": "This web part consume an anonymous Function App from an HTTP Trigger using the templates from the Northwind Microsoft DBs",
|
||||
"url": "https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-azurefunction-northwind2",
|
||||
"downloadUrl": "https://pnp.github.io/download-partial/?url=https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-azurefunction-northwind2",
|
||||
"longDescription": [
|
||||
"This web part consume an anonymous Function App from an HTTP Trigger using the templates from the Northwind Microsoft DBs"
|
||||
],
|
||||
"creationDateTime": "2022-08-15",
|
||||
"updateDateTime": "2022-08-15",
|
||||
"products": [
|
||||
"SharePoint"
|
||||
],
|
||||
"metadata": [
|
||||
{
|
||||
"key": "CLIENT-SIDE-DEV",
|
||||
"value": "React"
|
||||
},
|
||||
{
|
||||
"key": "SPFX-VERSION",
|
||||
"value": "1.15.2"
|
||||
}
|
||||
],
|
||||
"thumbnails": [
|
||||
{
|
||||
"type": "image",
|
||||
"order": 100,
|
||||
"url": "https://github.com/pnp/sp-dev-fx-webparts/raw/main/samples/react-azurefunction-northwind2/assets/YOUR-IMAGE-NAME-HERE",
|
||||
"alt": "Web Part Preview"
|
||||
},
|
||||
// {
|
||||
// "type": "video",
|
||||
// "order": 101,
|
||||
// "url": "https://www.youtube.com/embed/FS-_0KENJkI",
|
||||
// "alt": "Community demo of the web part"
|
||||
// }
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"gitHubAccount": "jtlivio",
|
||||
"pictureUrl": "https://github.com/jtlivio.png",
|
||||
"name": "Joao Livio"
|
||||
}
|
||||
],
|
||||
"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/en-us/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||
"version": "2.0",
|
||||
"bundles": {
|
||||
"react-azure-function-sql-web-part": {
|
||||
"components": [
|
||||
{
|
||||
"entrypoint": "./lib/webparts/reactAzureFunctionSql/ReactAzureFunctionSqlWebPart.js",
|
||||
"manifest": "./src/webparts/reactAzureFunctionSql/ReactAzureFunctionSqlWebPart.manifest.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"externals": {},
|
||||
"localizedResources": {
|
||||
"ReactAzureFunctionSqlWebPartStrings": "lib/webparts/reactAzureFunctionSql/loc/{locale}.js",
|
||||
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js",
|
||||
"PropertyControlStrings": "node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||
"workingDir": "./release/assets/",
|
||||
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||
"container": "react-azurefunction-sql",
|
||||
"accessKey": "<!-- ACCESS KEY -->"
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||
"solution": {
|
||||
"name": "react-azurefunction-sql-client-side-solution",
|
||||
"id": "dfceb4ae-e27d-4baf-be15-8c0d1e4966b3",
|
||||
"version": "1.0.0.0",
|
||||
"includeClientSideAssets": true,
|
||||
"skipFeatureDeployment": true,
|
||||
"isDomainIsolated": false,
|
||||
"developer": {
|
||||
"name": "",
|
||||
"websiteUrl": "",
|
||||
"privacyUrl": "",
|
||||
"termsOfUseUrl": "",
|
||||
"mpnId": "Undefined-1.15.2"
|
||||
},
|
||||
"metadata": {
|
||||
"shortDescription": {
|
||||
"default": "react-azurefunction-sql description"
|
||||
},
|
||||
"longDescription": {
|
||||
"default": "react-azurefunction-sql description"
|
||||
},
|
||||
"screenshotPaths": [],
|
||||
"videoUrl": "",
|
||||
"categories": []
|
||||
},
|
||||
"features": [
|
||||
{
|
||||
"title": "react-azurefunction-sql Feature",
|
||||
"description": "The feature that activates elements of the react-azurefunction-sql solution.",
|
||||
"id": "e0f2b630-e120-47bd-ae5f-0c35ee1ce5b9",
|
||||
"version": "1.0.0.0"
|
||||
}
|
||||
]
|
||||
},
|
||||
"paths": {
|
||||
"zippedPackage": "solution/react-azurefunction-sql.sppkg"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json",
|
||||
"port": 4321,
|
||||
"https": true,
|
||||
"initialPage": "https://{YOUR TENANT}/_layouts/workbench.aspx"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
'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.`);
|
||||
|
||||
var getTasks = build.rig.getTasks;
|
||||
build.rig.getTasks = function () {
|
||||
var result = getTasks.call(build.rig);
|
||||
|
||||
result.set('serve', result.get('serve-deprecated'));
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
build.initialize(require('gulp'));
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "react-azurefunction-sql",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build": "gulp bundle",
|
||||
"clean": "gulp clean",
|
||||
"test": "gulp test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@microsoft/sp-core-library": "1.15.2",
|
||||
"@microsoft/sp-lodash-subset": "1.15.2",
|
||||
"@microsoft/sp-office-ui-fabric-core": "1.15.2",
|
||||
"@microsoft/sp-property-pane": "1.15.2",
|
||||
"@microsoft/sp-webpart-base": "1.15.2",
|
||||
"@pnp/spfx-controls-react": "3.9.0",
|
||||
"@pnp/spfx-property-controls": "3.9.0",
|
||||
"office-ui-fabric-react": "7.185.7",
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1",
|
||||
"tslib": "2.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@microsoft/rush-stack-compiler-4.5": "0.2.2",
|
||||
"@rushstack/eslint-config": "2.5.1",
|
||||
"@microsoft/eslint-plugin-spfx": "1.15.2",
|
||||
"@microsoft/eslint-config-spfx": "1.15.2",
|
||||
"@microsoft/sp-build-web": "1.15.2",
|
||||
"@types/webpack-env": "~1.15.2",
|
||||
"ajv": "^6.12.5",
|
||||
"gulp": "4.0.2",
|
||||
"typescript": "4.5.5",
|
||||
"@types/react": "16.9.51",
|
||||
"@types/react-dom": "16.9.8",
|
||||
"eslint-plugin-react-hooks": "4.3.0",
|
||||
"@microsoft/sp-module-interfaces": "1.15.2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||
"id": "ee0d534c-a7ba-4443-9cc5-3e276466115f",
|
||||
"alias": "ReactAzureFunctionSqlWebPart",
|
||||
"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", "TeamsPersonalApp", "TeamsTab", "SharePointFullPage"],
|
||||
"supportsThemeVariants": true,
|
||||
|
||||
"preconfiguredEntries": [{
|
||||
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Advanced
|
||||
"group": { "default": "Advanced" },
|
||||
"title": { "default": "React Azure Function SQL" },
|
||||
"description": { "default": "React Azure Function SQL description" },
|
||||
"officeFabricIconFontName": "Page",
|
||||
"properties": {
|
||||
"description": "React Azure Function SQL"
|
||||
}
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
import * as React from 'react';
|
||||
import * as ReactDom from 'react-dom';
|
||||
import { Version } from '@microsoft/sp-core-library';
|
||||
import {
|
||||
IPropertyPaneConfiguration,
|
||||
PropertyPaneTextField,
|
||||
PropertyPaneDropdown
|
||||
} from '@microsoft/sp-property-pane';
|
||||
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
|
||||
import { IReadonlyTheme } from '@microsoft/sp-component-base';
|
||||
|
||||
import * as strings from 'ReactAzureFunctionSqlWebPartStrings';
|
||||
import ReactAzureFunctionSql from './components/ReactAzureFunctionSql';
|
||||
import { IReactAzureFunctionSqlProps } from './components/IReactAzureFunctionSqlProps';
|
||||
export interface IReactAzureFunctionSqlWebPartProps {
|
||||
description: string;
|
||||
authtype: string;
|
||||
functurl: string;
|
||||
}
|
||||
|
||||
export default class ReactAzureFunctionSqlWebPart extends BaseClientSideWebPart<IReactAzureFunctionSqlWebPartProps> {
|
||||
|
||||
private _isDarkTheme: boolean = false;
|
||||
private _environmentMessage: string = '';
|
||||
|
||||
public render(): void {
|
||||
const element: React.ReactElement<IReactAzureFunctionSqlProps> = React.createElement(
|
||||
ReactAzureFunctionSql,
|
||||
{
|
||||
description: this.properties.description,
|
||||
funcurl: this.properties.functurl,
|
||||
isDarkTheme: this._isDarkTheme,
|
||||
environmentMessage: this._environmentMessage,
|
||||
hasTeamsContext: !!this.context.sdks.microsoftTeams,
|
||||
userDisplayName: this.context.pageContext.user.displayName,
|
||||
httpclient:this.context.httpClient
|
||||
}
|
||||
);
|
||||
|
||||
ReactDom.render(element, this.domElement);
|
||||
}
|
||||
|
||||
protected onInit(): Promise<void> {
|
||||
this._environmentMessage = this._getEnvironmentMessage();
|
||||
|
||||
return super.onInit();
|
||||
}
|
||||
|
||||
private _getEnvironmentMessage(): string {
|
||||
if (!!this.context.sdks.microsoftTeams) { // running in Teams
|
||||
return this.context.isServedFromLocalhost ? strings.AppLocalEnvironmentTeams : strings.AppTeamsTabEnvironment;
|
||||
}
|
||||
|
||||
return this.context.isServedFromLocalhost ? strings.AppLocalEnvironmentSharePoint : strings.AppSharePointEnvironment;
|
||||
}
|
||||
|
||||
protected onThemeChanged(currentTheme: IReadonlyTheme | undefined): void {
|
||||
if (!currentTheme) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._isDarkTheme = !!currentTheme.isInverted;
|
||||
const {
|
||||
semanticColors
|
||||
} = currentTheme;
|
||||
|
||||
if (semanticColors) {
|
||||
this.domElement.style.setProperty('--bodyText', semanticColors.bodyText || null);
|
||||
this.domElement.style.setProperty('--link', semanticColors.link || null);
|
||||
this.domElement.style.setProperty('--linkHovered', semanticColors.linkHovered || null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected onDispose(): void {
|
||||
ReactDom.unmountComponentAtNode(this.domElement);
|
||||
}
|
||||
|
||||
protected get dataVersion(): Version {
|
||||
return Version.parse('1.0');
|
||||
}
|
||||
|
||||
protected get disableReactivePropertyChanges(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected onAfterPropertyPaneChangesApplied(): void {
|
||||
ReactDom.unmountComponentAtNode(this.domElement);
|
||||
this.render();
|
||||
}
|
||||
|
||||
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||
let authEnable: any;
|
||||
|
||||
if (this.properties.authtype !== "2") {
|
||||
authEnable = PropertyPaneTextField('functurl', {
|
||||
label: strings.FunctionUrl
|
||||
})
|
||||
} else {
|
||||
authEnable = PropertyPaneTextField('functurl', {
|
||||
disabled: true,
|
||||
label: strings.FunctionUrl,
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
pages: [
|
||||
{
|
||||
header: {
|
||||
description: strings.PropertyPaneDescription
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
groupName: strings.BasicGroupName,
|
||||
groupFields: [
|
||||
PropertyPaneTextField('description', {
|
||||
label: strings.DescriptionFieldLabel
|
||||
}),
|
||||
PropertyPaneDropdown('authtype', {
|
||||
label: strings.AuthLabel,
|
||||
options: [
|
||||
{ key: '1', text: 'No Authentication'},
|
||||
{ key: '2', text: 'aadHttpClientFactory' }
|
||||
],
|
||||
selectedKey: '1',
|
||||
}),
|
||||
authEnable
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,13 @@
|
|||
import { HttpClient } from "@microsoft/sp-http";
|
||||
|
||||
export interface IReactAzureFunctionSqlProps {
|
||||
description: string;
|
||||
isDarkTheme: boolean;
|
||||
environmentMessage: string;
|
||||
hasTeamsContext: boolean;
|
||||
userDisplayName: string;
|
||||
httpclient: HttpClient;
|
||||
|
||||
//Webpart Propreties
|
||||
funcurl: string;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
import { WebPartContext } from "@microsoft/sp-webpart-base";
|
||||
|
||||
export interface IReactAzureFunctionSqlState {
|
||||
customers: any;
|
||||
|
||||
context: WebPartContext;
|
||||
loading?: boolean;
|
||||
showPlaceholder?: boolean;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
@import '~office-ui-fabric-react/dist/sass/References.scss';
|
||||
|
||||
:global {
|
||||
#workbenchPageContent,
|
||||
.CanvasComponent.LCS .CanvasZone {
|
||||
max-width: 100% !important;
|
||||
}
|
||||
}
|
||||
|
||||
.reactAzureFunctionSql {
|
||||
overflow: hidden;
|
||||
padding: 1em;
|
||||
color: "[theme:bodyText, default: #323130]";
|
||||
color: var(--bodyText);
|
||||
&.teams {
|
||||
font-family: $ms-font-family-fallbacks;
|
||||
}
|
||||
}
|
||||
|
||||
.welcome {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.welcomeImage {
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
}
|
||||
|
||||
.links {
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: "[theme:link, default:#03787c]";
|
||||
color: var(--link); // note: CSS Custom Properties support is limited to modern browsers only
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
color: "[theme:linkHovered, default: #014446]";
|
||||
color: var(--linkHovered); // note: CSS Custom Properties support is limited to modern browsers only
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
import * as React from 'react';
|
||||
import styles from './ReactAzureFunctionSql.module.scss';
|
||||
import { IReactAzureFunctionSqlProps } from './IReactAzureFunctionSqlProps';
|
||||
import { IReactAzureFunctionSqlState } from './IReactAzureFunctionSqlState';
|
||||
import { escape } from '@microsoft/sp-lodash-subset';
|
||||
import { HttpClient, HttpClientResponse } from "@microsoft/sp-http";
|
||||
import { ListView, IViewField, SelectionMode } from '@pnp/spfx-controls-react/lib/controls/listView';
|
||||
|
||||
import { Spinner, SpinnerSize } from 'office-ui-fabric-react/lib/components/Spinner';
|
||||
import { Placeholder } from '@pnp/spfx-controls-react/lib/Placeholder';
|
||||
|
||||
let itemId;
|
||||
export default class ReactAzureFunctionSql extends React.Component<IReactAzureFunctionSqlProps, IReactAzureFunctionSqlState> {
|
||||
|
||||
constructor(props: IReactAzureFunctionSqlProps) {
|
||||
super(props);
|
||||
this.state = {
|
||||
customers: [],
|
||||
context: this.context,
|
||||
loading: false,
|
||||
showPlaceholder: (this.props.funcurl === null || this.props.funcurl === "")
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: for production use AAD
|
||||
|
||||
private _getCustomers(): Promise<any> {
|
||||
this.setState({
|
||||
loading: true
|
||||
});
|
||||
return this.props.httpclient
|
||||
.get(
|
||||
this.props.funcurl,
|
||||
HttpClient.configurations.v1
|
||||
)
|
||||
.then((response: HttpClientResponse) => {
|
||||
return response.json();
|
||||
})
|
||||
.then(jsonResponse => {
|
||||
return jsonResponse;
|
||||
}) as Promise<any>;
|
||||
}
|
||||
|
||||
private _viewFields: IViewField[] = [
|
||||
{
|
||||
name: "customerID",
|
||||
displayName: "Customer ID",
|
||||
maxWidth: 100,
|
||||
minWidth: 100,
|
||||
render: (item: any) => {
|
||||
const it = item["customerID"];
|
||||
if (it) {
|
||||
itemId = JSON.stringify(it);
|
||||
return <span>{itemId}</span>;
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "companyName",
|
||||
displayName: "Company Name",
|
||||
maxWidth: 500,
|
||||
render: (item: any) => {
|
||||
const it = item["companyName"];
|
||||
if (it) {
|
||||
itemId = JSON.stringify(it);
|
||||
return <span>{itemId}</span>;
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "contactName",
|
||||
displayName: "Contact Name",
|
||||
minWidth: 500,
|
||||
render: (item: any) => {
|
||||
const it = item["contactName"];
|
||||
if (it) {
|
||||
itemId = JSON.stringify(it);
|
||||
return <span>{itemId}</span>;
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
public componentDidMount() {
|
||||
if (this.props.funcurl !== null && this.props.funcurl !== "" && this.props.funcurl !== undefined) {
|
||||
this._getCustomers()
|
||||
.then(response => {
|
||||
this.setState({
|
||||
customers: response,
|
||||
loading: false
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public componentDidUpdate(prevProps: IReactAzureFunctionSqlProps, prevState: IReactAzureFunctionSqlState) {
|
||||
if (this.props.funcurl !== prevProps.funcurl) {
|
||||
if (this.props.funcurl !== null && this.props.funcurl !== "" && this.props.funcurl !== undefined) {
|
||||
this._getCustomers()
|
||||
.then(response => {
|
||||
this.setState({
|
||||
customers: response,
|
||||
loading: false
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<IReactAzureFunctionSqlProps> {
|
||||
const {
|
||||
description,
|
||||
funcurl,
|
||||
isDarkTheme,
|
||||
environmentMessage,
|
||||
hasTeamsContext,
|
||||
userDisplayName,
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<div>
|
||||
{
|
||||
this.state.loading ?
|
||||
(
|
||||
<Spinner size={SpinnerSize.large} label="Getting Results ..." />
|
||||
) : (
|
||||
this.state.customers.length === 0 ?
|
||||
(
|
||||
<Placeholder
|
||||
iconName="InfoSolid"
|
||||
iconText="You have to define the Function URL and Authentication Method"
|
||||
description="I'm not getting any Json" />
|
||||
) : (
|
||||
<section className={`${styles.reactAzureFunctionSql} ${hasTeamsContext ? styles.teams : ''}`}>
|
||||
<div className={styles.welcome}>
|
||||
<img alt="" src={isDarkTheme ? require('../assets/welcome-dark.png') : require('../assets/welcome-light.png')} className={styles.welcomeImage} />
|
||||
<h2>Well done, {escape(userDisplayName)}!</h2>
|
||||
<div>{environmentMessage}</div>
|
||||
<div>Web part property value: <strong>{escape(description)}</strong></div>
|
||||
</div>
|
||||
<div>
|
||||
<h3>Welcome to SharePoint Framework!</h3>
|
||||
<p>
|
||||
The SharePoint Framework (SPFx) is a extensibility model for Microsoft Viva, Microsoft Teams and SharePoint. It's the easiest way to extend Microsoft 365 with automatic Single Sign On, automatic hosting and industry standard tooling.
|
||||
</p>
|
||||
<h4>{funcurl}</h4>
|
||||
<ListView
|
||||
items={this.state.customers}
|
||||
viewFields={this._viewFields}
|
||||
compact={true}
|
||||
selectionMode={SelectionMode.none}
|
||||
filterPlaceHolder={"Search..."}
|
||||
showFilter={true}
|
||||
iconFieldName="File.ServerRelativeUrl">
|
||||
</ListView>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
)
|
||||
)
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
13
samples/react-azurefunction-northwind2/src/webparts/reactAzureFunctionSql/loc/en-us.js
vendored
Normal file
13
samples/react-azurefunction-northwind2/src/webparts/reactAzureFunctionSql/loc/en-us.js
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"PropertyPaneDescription": "Description",
|
||||
"AuthLabel": "Authentication Method",
|
||||
"FunctionUrl": "Function URL with code",
|
||||
"BasicGroupName": "Group Name",
|
||||
"DescriptionFieldLabel": "Description Field",
|
||||
"AppLocalEnvironmentSharePoint": "The app is running on your local environment as SharePoint web part",
|
||||
"AppLocalEnvironmentTeams": "The app is running on your local environment as Microsoft Teams app",
|
||||
"AppSharePointEnvironment": "The app is running on SharePoint page",
|
||||
"AppTeamsTabEnvironment": "The app is running in Microsoft Teams"
|
||||
}
|
||||
});
|
16
samples/react-azurefunction-northwind2/src/webparts/reactAzureFunctionSql/loc/mystrings.d.ts
vendored
Normal file
16
samples/react-azurefunction-northwind2/src/webparts/reactAzureFunctionSql/loc/mystrings.d.ts
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
declare interface IReactAzureFunctionSqlWebPartStrings {
|
||||
PropertyPaneDescription: string;
|
||||
BasicGroupName: string;
|
||||
DescriptionFieldLabel: string;
|
||||
AuthLabel: string;
|
||||
FunctionUrl: string;
|
||||
AppLocalEnvironmentSharePoint: string;
|
||||
AppLocalEnvironmentTeams: string;
|
||||
AppSharePointEnvironment: string;
|
||||
AppTeamsTabEnvironment: string;
|
||||
}
|
||||
|
||||
declare module 'ReactAzureFunctionSqlWebPartStrings' {
|
||||
const strings: IReactAzureFunctionSqlWebPartStrings;
|
||||
export = strings;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
After Width: | Height: | Size: 542 B |
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"extends": "./node_modules/@microsoft/rush-stack-compiler-4.5/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,
|
||||
"noImplicitAny": true,
|
||||
|
||||
"typeRoots": [
|
||||
"./node_modules/@types",
|
||||
"./node_modules/@microsoft"
|
||||
],
|
||||
"types": [
|
||||
"webpack-env"
|
||||
],
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.collection",
|
||||
"es2015.promise"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.tsx"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue