React Check Flows associated to a SharePoint List

This commit is contained in:
Aakash Bhardwaj 2019-09-17 13:51:09 +05:30
parent c08e6ea941
commit ff2a0e0238
25 changed files with 18836 additions and 0 deletions

View File

@ -0,0 +1,35 @@
# React Check Flows
## Summary
This web part lists all the automated Flows associated with a SharePoint List/ Library. Basic flow information like Flow Name, Flow Trigger, Flow shared Type and Flow URL are displayed.
![Check List Flows](./assets/CheckFlows.gif)
**Note:**
The web part only displays the flows which are shared with the current user and reside in the default environment.
## Used SharePoint Framework Version
![version](https://img.shields.io/badge/version-1.9.1-green.svg)
## Minimal Path to Awesome
- git clone the repo
- npm i
- gulp bundle --ship
- gulp package-solution --ship
- Add to Site Collection App Catalog and Install the App
- Add the web part to any page in the Site Collection
## Solution
Solution|Author(s)
--------|---------
react-check-flows|Aakash Bhardwaj
## 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.**
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 MiB

View File

@ -0,0 +1,19 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"check-list-flows-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/checkListFlows/CheckListFlowsWebPart.js",
"manifest": "./src/webparts/checkListFlows/CheckListFlowsWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"CheckListFlowsWebPartStrings": "lib/webparts/checkListFlows/loc/{locale}.js",
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/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": "react-check-flows",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -0,0 +1,13 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "react-check-flows",
"id": "fa0d5606-da19-4ba2-b47d-058d0594272d",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"isDomainIsolated": false
},
"paths": {
"zippedPackage": "solution/react-check-flows.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 -->"
}

7
samples/react-check-flows/gulpfile.js vendored Normal file
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);

18216
samples/react-check-flows/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,46 @@
{
"name": "react-check-flows",
"version": "0.0.1",
"private": true,
"main": "lib/index.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@microsoft/sp-core-library": "1.9.1",
"@microsoft/sp-lodash-subset": "1.9.1",
"@microsoft/sp-office-ui-fabric-core": "1.9.1",
"@microsoft/sp-webpart-base": "1.9.1",
"@pnp/common": "^1.3.5",
"@pnp/logging": "^1.3.5",
"@pnp/odata": "^1.3.5",
"@pnp/sp": "^1.3.5",
"@pnp/spfx-controls-react": "^1.14.0",
"@types/es6-promise": "0.0.33",
"@types/react": "16.8.8",
"@types/react-dom": "16.8.3",
"@types/webpack-env": "1.13.1",
"office-ui-fabric-react": "6.189.2",
"react": "16.8.5",
"react-dom": "16.8.5"
},
"resolutions": {
"@types/react": "16.8.8"
},
"devDependencies": {
"@microsoft/sp-build-web": "1.9.1",
"@microsoft/sp-tslint-rules": "1.9.1",
"@microsoft/sp-module-interfaces": "1.9.1",
"@microsoft/sp-webpart-workbench": "1.9.1",
"@microsoft/rush-stack-compiler-2.9": "0.7.16",
"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

View File

@ -0,0 +1,27 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "ef548472-a8f3-4fe4-b4b9-c57c3a3cc721",
"alias": "CheckListFlowsWebPart",
"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"],
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" },
"title": { "default": "CheckListFlows" },
"description": { "default": "CheckListFlows description" },
"officeFabricIconFontName": "Page",
"properties": {
"description": "CheckListFlows"
}
}]
}

View File

@ -0,0 +1,86 @@
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import * as strings from 'CheckListFlowsWebPartStrings';
import CheckListFlows from './components/CheckListFlows';
import { ICheckListFlowsProps } from './components/ICheckListFlowsProps';
import { IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
import { sp } from '@pnp/sp';
export interface ICheckListFlowsWebPartProps {
description: string;
title: string;
}
export default class CheckListFlowsWebPart extends BaseClientSideWebPart<ICheckListFlowsWebPartProps> {
private listOptions: IDropdownOption[];
public render(): void {
const element: React.ReactElement<ICheckListFlowsProps> = React.createElement(
CheckListFlows,
{
title: this.properties.title,
displayMode: this.displayMode,
updateProperty: (value: string) => {
this.properties.title = value;
},
description: this.properties.description,
context: this.context,
listOptions: this.listOptions
}
);
ReactDom.render(element, this.domElement);
}
protected onInit(): Promise<void> {
return super.onInit().then(async _ => {
sp.setup({
spfxContext: this.context
});
//Get Title and EntityTypeName for all lists in the site
let listOptions: IDropdownOption[] = [];
let lists = await sp.web.lists.select('EntityTypeName', 'Title').filter('Hidden eq false').get();
lists.map((list) => {
listOptions.push({ key: list.EntityTypeName, text: list.Title });
});
this.listOptions = listOptions;
});
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: 'Description'
})
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,29 @@
@import '~office-ui-fabric-react/dist/sass/References.scss';
.checkListFlows {
.container {
padding: 10px;
}
.row {
@include ms-Grid-row;
}
.column {
@include ms-Grid-col;
@include ms-lg12;
}
.title {
@include ms-font-xl;
}
.subTitle {
@include ms-font-l;
}
.description {
@include ms-font-l;
}
}

View File

@ -0,0 +1,221 @@
import * as React from 'react';
import styles from './CheckListFlows.module.scss';
import { ICheckListFlowsProps } from './ICheckListFlowsProps';
import { SPHttpClient } from '@microsoft/sp-http';
import { Dropdown, IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
import { WebPartTitle } from "@pnp/spfx-controls-react/lib/WebPartTitle";
import { DetailsList, DetailsListLayoutMode, IColumn } from 'office-ui-fabric-react/lib/DetailsList';
import { unescape } from '@microsoft/sp-lodash-subset';
import { Shimmer, ShimmerElementType } from 'office-ui-fabric-react/lib/Shimmer';
import { Link } from 'office-ui-fabric-react/lib/Link';
import { ICheckListFlowsState } from './ICheckListFlowsState';
import { IFlowDetails } from './IFlowDetails';
export default class CheckListFlows extends React.Component<ICheckListFlowsProps, ICheckListFlowsState> {
constructor(props: ICheckListFlowsProps) {
super(props);
const columns: IColumn[] = [
{
key: 'flowName',
name: 'Flow Name',
isRowHeader: true,
ariaLabel: 'Flow name',
fieldName: 'flowName',
onColumnClick: this._onColumnClick,
isResizable: true,
minWidth: 180,
maxWidth: 250
},
{
key: 'flowTrigger',
name: 'Flow Trigger',
ariaLabel: 'Flow trigger',
fieldName: 'flowTrigger',
onColumnClick: this._onColumnClick,
isResizable: true,
minWidth: 180,
maxWidth: 230
},
{
key: 'flowSharedType',
name: 'Flow Shared Type',
ariaLabel: 'Flow Shared Type',
fieldName: 'flowSharedType',
onColumnClick: this._onColumnClick,
isResizable: true,
minWidth: 150,
maxWidth: 200
},
{
key: 'flowUrl',
name: 'Flow URL',
ariaLabel: 'Flow URL',
fieldName: 'flowUrl',
onColumnClick: this._onColumnClick,
isResizable: true,
minWidth: 150,
maxWidth: 200,
onRender: (item) => {
return <Link href={item.flowUrl} target='_blank'>Go To Flow</Link>;
}
}
];
this.state = {
flowItems: [],
columns: columns,
dataLoaded: true
};
this._getListFlows = this._getListFlows.bind(this);
this._listSelected = this._listSelected.bind(this);
this._onColumnClick = this._onColumnClick.bind(this);
this._copyAndSort = this._copyAndSort.bind(this);
this._getCustomElements = this._getCustomElements.bind(this);
}
/** Sort items on column click */
private _onColumnClick = (ev: React.MouseEvent<HTMLElement>, column: IColumn): void => {
const { columns, flowItems } = this.state;
const newColumns: IColumn[] = columns.slice();
const currColumn: IColumn = newColumns.filter(currCol => column.key === currCol.key)[0];
newColumns.forEach((newCol: IColumn) => {
if (newCol === currColumn) {
currColumn.isSortedDescending = !currColumn.isSortedDescending;
currColumn.isSorted = true;
} else {
newCol.isSorted = false;
newCol.isSortedDescending = true;
}
});
const newItems = this._copyAndSort(flowItems, currColumn.fieldName!, currColumn.isSortedDescending);
this.setState({
columns: newColumns,
flowItems: newItems
});
}
private _copyAndSort<T>(items: T[], columnKey: string, isSortedDescending?: boolean): T[] {
const key = columnKey as keyof T;
return items.slice(0).sort((a: T, b: T) => ((isSortedDescending ? a[key] < b[key] : a[key] > b[key]) ? 1 : -1));
}
/** Custom Shimmer elements */
private _getCustomElements = (): JSX.Element => {
return (
<div>
<Shimmer
shimmerElements={[
{ type: ShimmerElementType.circle, height: 24 },
{ type: ShimmerElementType.gap, width: '2%' },
{ type: ShimmerElementType.line, height: 16, width: '20%' },
{ type: ShimmerElementType.gap, width: '5%' },
{ type: ShimmerElementType.line, height: 16, width: '20%' },
{ type: ShimmerElementType.gap, width: '5%' },
{ type: ShimmerElementType.line, height: 16, width: '20%' },
{ type: ShimmerElementType.gap, width: '5%' },
{ type: ShimmerElementType.line, height: 16, width: '20%' }
]}
/>
<Shimmer
shimmerElements={[
{ type: ShimmerElementType.circle, height: 24 },
{ type: ShimmerElementType.gap, width: '2%' },
{ type: ShimmerElementType.line, height: 16, width: '20%' },
{ type: ShimmerElementType.gap, width: '5%' },
{ type: ShimmerElementType.line, height: 16, width: '20%' },
{ type: ShimmerElementType.gap, width: '5%' },
{ type: ShimmerElementType.line, height: 16, width: '20%' },
{ type: ShimmerElementType.gap, width: '5%' },
{ type: ShimmerElementType.line, height: 16, width: '20%' }
]}
/>
</div>
);
}
/** Selected list updated */
private _listSelected(event: React.FormEvent<HTMLDivElement>, option: IDropdownOption) {
this.setState({ dataLoaded: false });
let listEntityName: string = option.key.toString();
listEntityName = unescape(listEntityName.replace("_x", "%u").replace("_", ""));
let listUrl: string;
if (listEntityName.substr(listEntityName.length - 4, 4) === 'List') {
listEntityName = listEntityName.substring(0, listEntityName.length - 4);
listUrl = `${this.props.context.pageContext.web.serverRelativeUrl}/Lists/${listEntityName}`;
} else {
listUrl = `${this.props.context.pageContext.web.serverRelativeUrl}/${listEntityName}`;
}
this._getListFlows(listUrl);
}
/**
* Retrieve the flow instances running on the selected list
* @param listUrl The List URL for which the flow instances would be retrieved
*/
private _getListFlows(listUrl: string) {
this.props.context.spHttpClient.post(`${this.props.context.pageContext.web.absoluteUrl}/_api/web/GetList(@url)/SyncFlowInstances?@url='${listUrl}'`, SPHttpClient.configurations.v1, {})
.then((response) => {
response.json().then((val) => {
let flowItems: IFlowDetails[] = [];
JSON.parse(val.SynchronizationData).value.map((flow) => {
flowItems.push({
flowName: flow.properties.displayName,
flowTrigger: flow.properties.definitionSummary.triggers[0].swaggerOperationId,
flowUrl: `https://flow.microsoft.com/manage/${flow.id.substring(flow.id.indexOf('environments'))}/details`,
flowSharedType: (flow.properties.sharingType && (flow.properties.sharingType === 'Coauthor')) ? 'Team Flow' : 'My Flow'
});
});
this.setState({ flowItems, dataLoaded: true });
});
}).catch((error) => {
console.log("Some error occurred: ", error);
});
}
public render(): React.ReactElement<ICheckListFlowsProps> {
return (
<div className={styles.checkListFlows}>
<div className={styles.container}>
<div className={styles.row}>
<div className={styles.column}>
<WebPartTitle displayMode={this.props.displayMode}
title={this.props.title}
updateProperty={this.props.updateProperty}
/>
<p className={styles.description}>Select List</p>
<Dropdown placeHolder='Select List'
options={this.props.listOptions}
onChange={this._listSelected}
/>
<br />
<Shimmer customElementsGroup={this._getCustomElements()} isDataLoaded={this.state.dataLoaded}>
{this.state.dataLoaded && this.state.flowItems.length === 0 &&
<p className={styles.description}>There are no flows associated with this list</p>
}
{this.state.dataLoaded && this.state.flowItems.length > 0 &&
<DetailsList
items={this.state.flowItems}
columns={this.state.columns}
setKey="set"
layoutMode={DetailsListLayoutMode.justified}
isHeaderVisible={true}
selectionPreservedOnEmptyClick={true}
enterModalSelectionOnTouch={true}
ariaLabelForSelectionColumn="Toggle selection"
ariaLabelForSelectAllCheckbox="Toggle selection for all items"
checkButtonAriaLabel="Row checkbox"
/>
}
</Shimmer>
</div>
</div>
</div>
</div>
);
}
}

View File

@ -0,0 +1,12 @@
import { WebPartContext } from '@microsoft/sp-webpart-base';
import { IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
import { DisplayMode } from '@microsoft/sp-core-library';
export interface ICheckListFlowsProps {
description: string;
context: WebPartContext;
listOptions: IDropdownOption[];
title: string;
displayMode: DisplayMode;
updateProperty: (value: string) => void;
}

View File

@ -0,0 +1,8 @@
import { IFlowDetails } from './IFlowDetails';
import { IColumn } from 'office-ui-fabric-react/lib/DetailsList';
export interface ICheckListFlowsState {
flowItems: IFlowDetails[];
columns: IColumn[];
dataLoaded: boolean;
}

View File

@ -0,0 +1,6 @@
export interface IFlowDetails {
flowName: string;
flowTrigger: string;
flowUrl: string;
flowSharedType: string;
}

View File

@ -0,0 +1,7 @@
define([], function() {
return {
"PropertyPaneDescription": "Description",
"BasicGroupName": "Group Name",
"DescriptionFieldLabel": "Description Field"
}
});

View File

@ -0,0 +1,10 @@
declare interface ICheckListFlowsWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'CheckListFlowsWebPartStrings' {
const strings: ICheckListFlowsWebPartStrings;
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
}
}