Added react-flow-button
This commit is contained in:
parent
fa0c6059d0
commit
c6a81e0ea3
|
@ -0,0 +1,33 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
|
||||
# Build generated files
|
||||
dist
|
||||
lib
|
||||
release
|
||||
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
|
|
@ -0,0 +1,16 @@
|
|||
!dist
|
||||
config
|
||||
|
||||
gulpfile.js
|
||||
|
||||
release
|
||||
src
|
||||
temp
|
||||
|
||||
tsconfig.json
|
||||
tslint.json
|
||||
|
||||
*.log
|
||||
|
||||
.yo-rc.json
|
||||
.vscode
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"@microsoft/generator-sharepoint": {
|
||||
"plusBeta": false,
|
||||
"isCreatingSolution": true,
|
||||
"environment": "spo",
|
||||
"version": "1.13.1",
|
||||
"libraryName": "react-flow-button",
|
||||
"libraryId": "0745b06d-baee-4075-8634-c871750e9951",
|
||||
"packageManager": "npm",
|
||||
"isDomainIsolated": false,
|
||||
"componentType": "webpart"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
# Flow Button
|
||||
|
||||
## Summary
|
||||
|
||||
This web part demonstrates displaying the list of flow button of Power Automate.
|
||||
|
||||
![](./assets/react-flow-button.gif)
|
||||
|
||||
## Compatibility
|
||||
|
||||
![SPFx 1.13.1](https://img.shields.io/badge/SPFx-1.13.1-green.svg)
|
||||
![Node.js v14 | v12](https://img.shields.io/badge/Node.js-v14%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 (with permissions)](https://img.shields.io/badge/Hosted%20Workbench-Compatible-yellow.svg "Requires API permissions")
|
||||
|
||||
## Prerequisites
|
||||
|
||||
This web part uses *Microsoft Graph* API and *Microsoft Flow Service* API. You need to approve the API request after deploying the package.
|
||||
|
||||
- Microsoft Graph
|
||||
- `User.ReadBasic.All`
|
||||
- Microsoft Flow Service
|
||||
- `Flows.Read.All`
|
||||
|
||||
## 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-my-approvals) then unzip it)
|
||||
- Ensure that you are at the solution folder
|
||||
- in the command-line run:
|
||||
- `npm install`
|
||||
- `gulp serve`
|
||||
|
||||
> This sample can also be opened with [VS Code Remote Development](https://code.visualstudio.com/docs/remote/remote-overview). Visit https://aka.ms/spfx-devcontainer for further instructions.
|
||||
|
||||
## Solution
|
||||
|
||||
Solution|Author(s)
|
||||
--------|---------
|
||||
react-my-approvals|[Takashi Shinohara](https://github.com/karamem0) ([@karamem0](https://twitter.com/karamem0))
|
||||
|
||||
## Version history
|
||||
|
||||
Version|Date|Comments
|
||||
-------|----|--------
|
||||
1.1|January 22, 2022|Updated to allow multiple environments to be selected
|
||||
1.0|January 11, 2022|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.**
|
Binary file not shown.
After Width: | Height: | Size: 7.8 MiB |
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||
"version": "2.0",
|
||||
"bundles": {
|
||||
"flow-button-web-part": {
|
||||
"components": [
|
||||
{
|
||||
"entrypoint": "./lib/webparts/flowButton/FlowButtonWebPart.js",
|
||||
"manifest": "./src/webparts/flowButton/FlowButtonWebPart.manifest.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"externals": {},
|
||||
"localizedResources": {
|
||||
"FlowButtonWebPartStrings": "lib/webparts/flowButton/loc/{locale}.js",
|
||||
"PropertyControlStrings": "node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js",
|
||||
"ControlStrings": "node_modules/@pnp/spfx-controls-react/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-flow-button",
|
||||
"accessKey": "<!-- ACCESS KEY -->"
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||
"solution": {
|
||||
"name": "flow-button",
|
||||
"id": "0745b06d-baee-4075-8634-c871750e9951",
|
||||
"version": "1.0.0.0",
|
||||
"includeClientSideAssets": true,
|
||||
"skipFeatureDeployment": true,
|
||||
"isDomainIsolated": false,
|
||||
"developer": {
|
||||
"name": "",
|
||||
"websiteUrl": "",
|
||||
"privacyUrl": "",
|
||||
"termsOfUseUrl": "",
|
||||
"mpnId": ""
|
||||
},
|
||||
"webApiPermissionRequests": [
|
||||
{
|
||||
"resource": "Microsoft Graph",
|
||||
"scope": "User.ReadBasic.All"
|
||||
},
|
||||
{
|
||||
"resource": "Microsoft Flow Service",
|
||||
"scope": "Flows.Read.All"
|
||||
}
|
||||
]
|
||||
},
|
||||
"paths": {
|
||||
"zippedPackage": "solution/flow-button.sppkg"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
|
||||
"port": 4321,
|
||||
"https": true,
|
||||
"initialPage": "https://enter-your-SharePoint-site/_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,33 @@
|
|||
{
|
||||
"name": "react-flow-button",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build": "gulp bundle",
|
||||
"clean": "gulp clean",
|
||||
"test": "gulp test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@microsoft/sp-core-library": "1.13.1",
|
||||
"@microsoft/sp-lodash-subset": "1.13.1",
|
||||
"@microsoft/sp-office-ui-fabric-core": "1.13.1",
|
||||
"@microsoft/sp-webpart-base": "1.13.1",
|
||||
"@pnp/spfx-controls-react": "^3.5.0",
|
||||
"@pnp/spfx-property-controls": "^3.3.0",
|
||||
"office-ui-fabric-react": "7.174.1",
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@microsoft/rush-stack-compiler-3.9": "0.4.47",
|
||||
"@microsoft/sp-build-web": "1.13.1",
|
||||
"@microsoft/sp-module-interfaces": "1.13.1",
|
||||
"@microsoft/sp-tslint-rules": "1.13.1",
|
||||
"@types/react": "16.9.51",
|
||||
"@types/react-dom": "16.9.8",
|
||||
"@types/webpack-env": "1.13.1",
|
||||
"ajv": "~5.2.2",
|
||||
"gulp": "~4.0.2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||
"id": "6f5baf5e-9be1-42cc-ac7f-651d3ccf53a6",
|
||||
"alias": "FlowButtonWebPart",
|
||||
"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"
|
||||
],
|
||||
"supportsThemeVariants": true,
|
||||
"preconfiguredEntries": [
|
||||
{
|
||||
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
|
||||
"group": {
|
||||
"default": "Other"
|
||||
},
|
||||
"title": {
|
||||
"default": "Flow Button"
|
||||
},
|
||||
"description": {
|
||||
"default": "Trigger the Power Automate flow."
|
||||
},
|
||||
"officeFabricIconFontName": "Touch",
|
||||
"properties": {
|
||||
"environments": null
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
import * as React from 'react';
|
||||
import * as ReactDom from 'react-dom';
|
||||
import { Version } from '@microsoft/sp-core-library';
|
||||
import { IPropertyPaneConfiguration } from '@microsoft/sp-property-pane';
|
||||
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
|
||||
import { PropertyFieldMultiSelect } from '@pnp/spfx-property-controls';
|
||||
|
||||
import * as strings from 'FlowButtonWebPartStrings';
|
||||
import FlowButton from './components/FlowButton';
|
||||
import { IFlowButtonProps } from './components/IFlowButtonProps';
|
||||
import FlowClientService from './services/FlowClientService';
|
||||
import GraphClientService from './services/GraphClientService';
|
||||
|
||||
export interface IFlowButtonWebPartProps {
|
||||
title: string;
|
||||
environments: string[] | null;
|
||||
}
|
||||
|
||||
export default class FlowButtonWebPart extends BaseClientSideWebPart<IFlowButtonWebPartProps> {
|
||||
|
||||
private flowService: FlowClientService;
|
||||
private graphService: GraphClientService;
|
||||
private environments: string[];
|
||||
|
||||
public render(): void {
|
||||
const element: React.ReactElement<IFlowButtonProps> = React.createElement(
|
||||
FlowButton,
|
||||
{
|
||||
flowService: this.flowService,
|
||||
graphService: this.graphService,
|
||||
displayMode: this.displayMode,
|
||||
environments: this.properties.environments,
|
||||
title: this.properties.title,
|
||||
setTitle: (value: string) => {
|
||||
this.properties.title = value;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
ReactDom.render(element, this.domElement);
|
||||
}
|
||||
|
||||
protected async onInit(): Promise<void> {
|
||||
this.flowService = await FlowClientService.create(this.context);
|
||||
this.graphService = await GraphClientService.create(this.context);
|
||||
this.environments = await this.flowService
|
||||
.getEnvironments()
|
||||
.then((values) => values.map((value) => value.name));
|
||||
if (!this.properties.environments) {
|
||||
this.properties.environments = this.environments;
|
||||
}
|
||||
}
|
||||
|
||||
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: [
|
||||
{
|
||||
groupFields: [
|
||||
PropertyFieldMultiSelect(
|
||||
'environments',
|
||||
{
|
||||
key: 'environments',
|
||||
label: strings.EnvironmentLabel,
|
||||
options: this.environments.map((value) => ({
|
||||
key: value,
|
||||
text: value
|
||||
})),
|
||||
selectedKeys: this.properties.environments
|
||||
}
|
||||
)
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
@import '~office-ui-fabric-react/dist/sass/References.scss';
|
||||
|
||||
.root {
|
||||
width: 100%;
|
||||
.buttons {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, calc(50% - 0.5rem));
|
||||
grid-template-rows: auto;
|
||||
gap: 1rem;
|
||||
.button {
|
||||
height: inherit;
|
||||
.content {
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
grid-template-rows: auto auto;
|
||||
gap: 0.25rem;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: left;
|
||||
.icon {
|
||||
grid-column: 1 / 2;
|
||||
grid-row: 1 / 3;
|
||||
font-size: 2rem;
|
||||
}
|
||||
.title {
|
||||
grid-column: 2 / 3;
|
||||
grid-row: 1 / 2;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.author {
|
||||
grid-column: 2 / 3;
|
||||
grid-row: 2 / 3;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
import * as React from 'react';
|
||||
import styles from './FlowButton.module.scss';
|
||||
import {
|
||||
ActionButton,
|
||||
FontIcon,
|
||||
MessageBar,
|
||||
MessageBarType,
|
||||
Text
|
||||
} from 'office-ui-fabric-react';
|
||||
import { WebPartTitle } from '@pnp/spfx-controls-react';
|
||||
import * as strings from 'FlowButtonWebPartStrings';
|
||||
|
||||
import { IFlowButtonProps } from './IFlowButtonProps';
|
||||
import { IFlowButtonState } from './IFlowButtonState';
|
||||
|
||||
export const FlowButton = ({
|
||||
flowService,
|
||||
graphService,
|
||||
displayMode,
|
||||
environments,
|
||||
title,
|
||||
setTitle
|
||||
}: IFlowButtonProps) => {
|
||||
|
||||
const [states, setStates] = React.useState<IFlowButtonState[]>([]);
|
||||
|
||||
const onButtonClick = React.useCallback((state: IFlowButtonState) => {
|
||||
window.open(`https://flow.microsoft.com/manage/environments/${state.environment}/flows/${state.id}/run`, '_blank');
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!flowService) return;
|
||||
if (!graphService) return;
|
||||
if (!environments.length) return;
|
||||
(async () => {
|
||||
for (const environment of environments) {
|
||||
const flows = await flowService.getFlows(environment);
|
||||
await Promise.all(flows.map(async (item) => {
|
||||
const flow = await flowService.getFlow(item.id);
|
||||
const author = await graphService.getUser(flow.properties.creator.objectId);
|
||||
if (flow.properties.flowTriggerUri) {
|
||||
setStates((values) => [
|
||||
...values,
|
||||
{
|
||||
environment: flow.properties.environment.name,
|
||||
id: flow.name,
|
||||
title: flow.properties.displayName,
|
||||
author: author.displayName
|
||||
}]);
|
||||
}
|
||||
}));
|
||||
}
|
||||
})();
|
||||
}, [
|
||||
flowService,
|
||||
graphService,
|
||||
environments
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className={styles.root}>
|
||||
{
|
||||
environments.length
|
||||
? (
|
||||
<React.Fragment>
|
||||
<WebPartTitle
|
||||
displayMode={displayMode}
|
||||
title={title}
|
||||
updateProperty={setTitle} />
|
||||
<div className={styles.buttons}>
|
||||
{
|
||||
states.map((state) => (
|
||||
<ActionButton
|
||||
className={styles.button}
|
||||
onClick={() => onButtonClick(state)}>
|
||||
<div className={styles.content}>
|
||||
<FontIcon
|
||||
className={styles.icon}
|
||||
iconName='Touch' />
|
||||
<Text className={styles.title}>{state.title}</Text>
|
||||
<Text className={styles.author}>{state.author}</Text>
|
||||
</div>
|
||||
</ActionButton>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
</React.Fragment>
|
||||
)
|
||||
: (
|
||||
<MessageBar messageBarType={MessageBarType.error}>
|
||||
{strings.EnvironmentEmptyError}
|
||||
</MessageBar>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
export default FlowButton;
|
|
@ -0,0 +1,12 @@
|
|||
import { DisplayMode } from '@microsoft/sp-core-library';
|
||||
import FlowClientService from '../services/FlowClientService';
|
||||
import GraphClientService from '../services/GraphClientService';
|
||||
|
||||
export interface IFlowButtonProps {
|
||||
flowService: FlowClientService;
|
||||
graphService: GraphClientService;
|
||||
displayMode: DisplayMode;
|
||||
environments: string[];
|
||||
title: string;
|
||||
setTitle: (value: string) => void;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
export interface IFlowButtonState {
|
||||
environment: string;
|
||||
id: string;
|
||||
title: string;
|
||||
author: string;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"PropertyPaneDescription": "Trigger the Power Automate flow.",
|
||||
"EnvironmentLabel": "Environment",
|
||||
"EnvironmentEmptyError": "The environment is not selected. Please edit the web part and select the environment.",
|
||||
"RunButtonText": "Run"
|
||||
}
|
||||
});
|
|
@ -0,0 +1,8 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"PropertyPaneDescription": "Power Automate のフローをトリガーします。",
|
||||
"EnvironmentLabel": "環境",
|
||||
"EnvironmentEmptyError": "環境が選択されていません。Web パーツを編集して環境を選択してください。",
|
||||
"RunButtonText": "実行"
|
||||
}
|
||||
});
|
|
@ -0,0 +1,11 @@
|
|||
declare interface IFlowButtonWebPartStrings {
|
||||
PropertyPaneDescription: string;
|
||||
EnvironmentLabel: string;
|
||||
EnvironmentEmptyError: string;
|
||||
RunButtonText: string;
|
||||
}
|
||||
|
||||
declare module 'FlowButtonWebPartStrings' {
|
||||
const strings: IFlowButtonWebPartStrings;
|
||||
export = strings;
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
import { WebPartContext } from '@microsoft/sp-webpart-base';
|
||||
import { AadHttpClient } from '@microsoft/sp-http';
|
||||
|
||||
interface IEnvironment {
|
||||
name: string;
|
||||
location: string;
|
||||
id: string;
|
||||
type: string;
|
||||
properties: any;
|
||||
}
|
||||
|
||||
interface IFlow {
|
||||
name: string;
|
||||
id: string;
|
||||
type: string;
|
||||
properties: any;
|
||||
}
|
||||
|
||||
export default class FlowClientService {
|
||||
|
||||
private static readonly endpoint: string = 'https://service.flow.microsoft.com';
|
||||
|
||||
public static async create(context: WebPartContext): Promise<FlowClientService> {
|
||||
return new FlowClientService(await context.aadHttpClientFactory.getClient(FlowClientService.endpoint));
|
||||
}
|
||||
|
||||
private httpClient: AadHttpClient;
|
||||
|
||||
private constructor(httpClient: AadHttpClient) {
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
public async getEnvironments(): Promise<IEnvironment[]> {
|
||||
const response = await this.httpClient.get(
|
||||
'https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/environments' +
|
||||
'?api-version=2016-11-01',
|
||||
AadHttpClient.configurations.v1);
|
||||
const json = await response.json();
|
||||
if (json.error) {
|
||||
throw new Error(json.error);
|
||||
}
|
||||
return json.value as IEnvironment[];
|
||||
}
|
||||
|
||||
public async getFlows(environment: string): Promise<IFlow[]> {
|
||||
const response = await this.httpClient.get(
|
||||
`https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/environments/${environment}/flows` +
|
||||
'?api-version=2016-11-01',
|
||||
AadHttpClient.configurations.v1);
|
||||
const json = await response.json();
|
||||
if (json.error) {
|
||||
throw new Error(json.error);
|
||||
}
|
||||
return json.value as IFlow[];
|
||||
}
|
||||
|
||||
public async getFlow(id: string): Promise<IFlow> {
|
||||
const response = await this.httpClient.get(
|
||||
`https://api.flow.microsoft.com/${id}` +
|
||||
'?api-version=2016-11-01',
|
||||
AadHttpClient.configurations.v1);
|
||||
const json = await response.json();
|
||||
if (json.error) {
|
||||
throw new Error(json.error);
|
||||
}
|
||||
return json as IFlow;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
import { WebPartContext } from '@microsoft/sp-webpart-base';
|
||||
import { AadHttpClient } from '@microsoft/sp-http';
|
||||
|
||||
interface IUser {
|
||||
id: string;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
export default class GraphClientService {
|
||||
|
||||
private static readonly endpoint: string = 'https://graph.microsoft.com';
|
||||
|
||||
public static async create(context: WebPartContext): Promise<GraphClientService> {
|
||||
return new GraphClientService(await context.aadHttpClientFactory.getClient(GraphClientService.endpoint));
|
||||
}
|
||||
|
||||
private httpClient: AadHttpClient;
|
||||
|
||||
private constructor(httpClient: AadHttpClient) {
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
public async getUser(id: string): Promise<IUser> {
|
||||
const response = await this.httpClient.get(
|
||||
`https://graph.microsoft.com/v1.0/users/${id}`,
|
||||
AadHttpClient.configurations.v1);
|
||||
const json = await response.json();
|
||||
if (json.error) {
|
||||
throw new Error(json.error);
|
||||
}
|
||||
return json as IUser;
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
After Width: | Height: | Size: 542 B |
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.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": [
|
||||
"webpack-env"
|
||||
],
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.collection",
|
||||
"es2015.promise"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.tsx"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"extends": "./node_modules/@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-with-statement": true,
|
||||
"semicolon": true,
|
||||
"trailing-comma": false,
|
||||
"typedef": false,
|
||||
"typedef-whitespace": false,
|
||||
"use-named-parameter": true,
|
||||
"variable-name": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue