New Sample - React- MyFlows web Part

This commit is contained in:
João Mendes 2019-08-24 19:13:03 +01:00
parent 13dd132767
commit 8fe540c226
30 changed files with 20259 additions and 0 deletions

View File

@ -0,0 +1,25 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
# change these settings to your own preference
indent_style = space
indent_size = 2
# we recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
[{package,bower}.json]
indent_style = space
indent_size = 2

32
samples/js-myflows/.gitignore vendored Normal file
View File

@ -0,0 +1,32 @@
# Logs
logs
*.log
npm-debug.log*
# Dependency directories
node_modules
# Build generated files
dist
lib
solution
temp
*.sppkg
# 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

View File

@ -0,0 +1,12 @@
{
"@microsoft/generator-sharepoint": {
"version": "1.8.2",
"libraryName": "myflows",
"libraryId": "80eca57a-37fc-4b0c-a893-3ff4c0e5b9ae",
"environment": "spo",
"packageManager": "npm",
"isCreatingSolution": true,
"isDomainIsolated": false,
"componentType": "webpart"
}
}

77
samples/js-myflows/README.md Executable file
View File

@ -0,0 +1,77 @@
# SPFx My Flows Web Part
## Summary
Manage current user flows in SharePoint or Teams Tab, this web part use the msflowsdk-1.1.js
##
![directory](/samples/js-myflows/assets/MyFlows.gif)
![directory](/samples/js-myflows/assets/Screenshot1.png)
![directory](/samples/js-myflows/assets/Screenshot2.png)
![directory](/samples/js-myflows/assets/Screenshot3.png)
![directory](/samples/js-myflows/assets/Screenshot4.png)
## Used SharePoint Framework Version
![drop](https://img.shields.io/badge/version-1.8.2-green.svg)
## Applies to
* [SharePoint Online](https:/dev.office.com/sharepoint)
* [Microsoft Teams](https://products.office.com/en-US/microsoft-teams/group-chat-software)
* [Office 365 tenant](https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment)
## WebPart Properties
Property |Type|Required| comments
--------------------|----|--------|----------
Web Part Title | Text| no|
## Solution
The web part Use msflowsdk-1.1.js library
Solution|Author(s)
--------|---------
My FLows Web Part|João Mendes
## Version history
Version|Date|Comments
-------|----|--------
1.0.0|August 13, 2019|Initial release
## 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
- Clone this repository
- in the command line run:
- `npm install`
- `gulp build`
- `gulp bundle --ship`
- `gulp package-solution --ship`
- `Add to AppCatalog and deploy`
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/MyFlows" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 624 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 574 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 KiB

View File

@ -0,0 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"my-flows-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/myFlows/MyFlowsWebPart.js",
"manifest": "./src/webparts/myFlows/MyFlowsWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"MyFlowsWebPartStrings": "lib/webparts/myFlows/loc/{locale}.js"
}
}

View File

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
"deployCdnPath": "temp/deploy"
}

View File

@ -0,0 +1,7 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
"workingDir": "./temp/deploy/",
"account": "<!-- STORAGE ACCOUNT NAME -->",
"container": "myflows",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -0,0 +1,14 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "myflows-client-side-solution",
"id": "80eca57a-37fc-4b0c-a893-3ff4c0e5b9ae",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false
},
"paths": {
"zippedPackage": "solution/myflows.sppkg"
}
}

View File

@ -0,0 +1,10 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
"port": 4321,
"https": true,
"initialPage": "https://localhost:5432/workbench",
"api": {
"port": 5432,
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
}
}

View File

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->"
}

View File

@ -0,0 +1,7 @@
'use strict';
const gulp = require('gulp');
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.initialize(gulp);

17406
samples/js-myflows/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
{
"name": "myflows",
"version": "0.0.1",
"private": true,
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@microsoft/sp-core-library": "1.8.2",
"@microsoft/sp-property-pane": "1.8.2",
"@microsoft/sp-webpart-base": "1.8.2",
"@microsoft/sp-lodash-subset": "1.8.2",
"@microsoft/sp-office-ui-fabric-core": "1.8.2",
"@types/webpack-env": "1.13.1",
"@types/es6-promise": "0.0.33"
},
"devDependencies": {
"@microsoft/sp-build-web": "1.8.2",
"@microsoft/sp-tslint-rules": "1.8.2",
"@microsoft/sp-module-interfaces": "1.8.2",
"@microsoft/sp-webpart-workbench": "1.8.2",
"@microsoft/rush-stack-compiler-2.9": "0.7.7",
"gulp": "~3.9.1",
"@types/chai": "3.4.34",
"@types/mocha": "2.2.38",
"ajv": "~5.2.2"
}
}

View File

@ -0,0 +1 @@
// A file is required to be in the root of the /src directory by the TypeScript compiler

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,39 @@
import "./msflowsdk-1.1.js";
import {
SPHttpClient,
SPHttpClientResponse,
ISPHttpClientOptions
} from "@microsoft/sp-http";
import { WebPartContext } from "@microsoft/sp-webpart-base";
/**
* Services
*/
export default class services {
private _context: WebPartContext;
constructor(private context: WebPartContext) {
this._context = this.context;
}
/**
* Gets access token
* @returns access token
*/
public async getAccessToken():Promise<string> {
const body: ISPHttpClientOptions = {
body: JSON.stringify({
resource: "https://service.flow.microsoft.com/"
})
};
let token: SPHttpClientResponse = await this._context.spHttpClient.post(
`${this._context.pageContext.web.absoluteUrl}/_api/SP.OAuth.Token/Acquire`,
SPHttpClient.configurations.v1,
body
);
let tokenJson = await token.json();
return tokenJson.access_token;
}
}

View File

@ -0,0 +1,27 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "69105900-a016-43cb-9e28-9a16bb92cb87",
"alias": "MyFlowsWebPart",
"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","SharePointFullPage","TeamsTab"],
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "SPFx Apps" },
"title": { "default": "My Flows" },
"description": { "default": "My Flows" },
"officeFabricIconFontName": "MicrosoftFlowLogo",
"properties": {
"title": "My Flows"
}
}]
}

View File

@ -0,0 +1,42 @@
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
iframe {
width:100%;
min-height: 800px;
padding: 10px;
overflow: hidden;
border-width: 0px;
border-style: solid;
border-color: $ms-color-white;
margin-top: 20px;
}
.label {
font-size: $ms-font-size-l;
height: 32px;
line-height: 32px;
margin: 0 4px;
vertical-align: top;
display: inline-block;
}
.sdk{
width:100%;
}
.titleTheme{
@include ms-font-xl;
@include ms-fontSize-24;
}
.titleWhite{
@include ms-font-xl;
@include ms-fontSize-24;
color: white;
}
.error{
@include ms-font-xl;
@include ms-fontSize-24;
color: red;
margin: 15px;
}

View File

@ -0,0 +1,148 @@
import { Version, Guid } from "@microsoft/sp-core-library";
import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base";
import {
IPropertyPaneConfiguration,
PropertyPaneTextField
} from "@microsoft/sp-property-pane";
import { escape } from "@microsoft/sp-lodash-subset";
import styles from "./MyFlowsWebPart.module.scss";
import * as strings from "MyFlowsWebPartStrings";
import service from "./../../services/services";
export interface IMyFlowsWebPartProps {
title: string;
}
export default class MyFlowsWebPart extends BaseClientSideWebPart<
IMyFlowsWebPartProps
> {
private _msFlowSdk: any = null;
private _services: service = null;
private _guid = Guid.newGuid();
public constructor(props: IMyFlowsWebPartProps) {
super();
// Initialize flow SDK
this._msFlowSdk = window["MsFlowSdk"];
}
/**
* Gets context
* @returns context
*/
private getContext(): Promise<string> {
return new Promise((resolve, reject) => {
let classColor = styles.titleTheme;
if (this.context.microsoftTeams) {
this.context.microsoftTeams.getContext(teamsContext => {
classColor =
teamsContext.theme !== "default"
? styles.titleWhite
: styles.titleTheme;
resolve(classColor);
});
} else {
resolve(classColor);
}
});
}
/**
* Renders my flows web part
*/
public async render(): Promise<void> {
this.domElement.setAttribute("Id", `"${this._guid}"`);
this.domElement.setAttribute("class", `"${styles.sdk}"`);
const classColor = await this.getContext();
this.domElement.innerHTML = `<div><label class=${classColor}>${
this.properties.title
}</label></div>`;
//
this._services = new service(this.context);
try {
const token: string = await this._services.getAccessToken();
const flowSDK = new this._msFlowSdk({
hostName: "https://flow.microsoft.com",
locale: this.context.pageContext.cultureInfo.currentCultureName
});
// Render Flow widget
let widget: any = flowSDK.renderWidget("flows", {
container: `"${this._guid}"`,
sdkVersion: "1.1",
enableOnBehalfOfTokens: true,
debugMode: false,
allowOptionalEvents: true,
flowsSettings: {
createFromBlankTemplateId: "05ed784f63df4ac7b8cbb465005d6068",
encodedFlowsFilter: "",
isMini: false,
enableBusinessProcessFlow: true
},
templatesSettings: {
defaultParams: "",
category: "PowerAppsButton",
destination: "new",
metadataSortProperty: "",
pageSize: 6,
searchTerm: "",
useServerSideProvisioning: false,
showGoBack: true,
enableWidgetCloseOnFlowSave: false,
showCreateFromBlank: false,
enableDietDesigner: false,
showHiddenTemplates: false,
allowCustomFlowName: false,
oneClickCategory: "",
dietCategory: ""
},
widgetStyleSettings: {
backgroundColor: "",
themeName: ""
}
});
// Register handler
widget.listen("GET_ACCESS_TOKEN", (requestParam, widgetDoneCallback) => {
widgetDoneCallback(null, { token: token });
});
// Register handler
widget.listen("WIDGET_READY", () => {
console.log("The flow widget is now ready.");
});
} catch (error) {
// error
this.domElement.innerHTML = `<div><label class=${classColor}>${
this.properties.title
}</label></div>
<div ><label class=${styles.error}>${error}</label></div>
`;
}
}
protected get dataVersion(): Version {
return Version.parse("1.0");
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField("title", {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,7 @@
define([], function() {
return {
"PropertyPaneDescription": "Manage My Flows in SharePoint ",
"BasicGroupName": "Properties",
"DescriptionFieldLabel": "Title"
}
});

View File

@ -0,0 +1,10 @@
declare interface IMyFlowsWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'MyFlowsWebPartStrings' {
const strings: IMyFlowsWebPartStrings;
export = strings;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,38 @@
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-2.9/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,
"typeRoots": [
"./node_modules/@types",
"./node_modules/@microsoft"
],
"types": [
"es6-promise",
"webpack-env"
],
"lib": [
"es5",
"dom",
"es2015.collection"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"lib"
]
}

View File

@ -0,0 +1,30 @@
{
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
"rules": {
"class-name": false,
"export-name": false,
"forin": false,
"label-position": false,
"member-access": true,
"no-arg": false,
"no-console": false,
"no-construct": false,
"no-duplicate-variable": true,
"no-eval": false,
"no-function-expression": true,
"no-internal-module": true,
"no-shadowed-variable": true,
"no-switch-case-fall-through": true,
"no-unnecessary-semicolons": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-with-statement": true,
"semicolon": true,
"trailing-comma": false,
"typedef": false,
"typedef-whitespace": false,
"use-named-parameter": true,
"variable-name": false,
"whitespace": false
}
}