SPFx webart to manage solution using ALM API (#1166)
This commit is contained in:
parent
fe7409419a
commit
c546903626
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"@pnp/generator-spfx": {
|
||||||
|
"framework": "react",
|
||||||
|
"pnpFramework": "reactjs.plus",
|
||||||
|
"pnp-libraries": [
|
||||||
|
"@pnp/pnpjs",
|
||||||
|
"rush@3.3"
|
||||||
|
],
|
||||||
|
"pnp-ci": "azure",
|
||||||
|
"pnp-vetting": [],
|
||||||
|
"spfxenv": "spo",
|
||||||
|
"pnp-testing": [
|
||||||
|
"jest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"@microsoft/generator-sharepoint": {
|
||||||
|
"environment": "spo",
|
||||||
|
"framework": "react",
|
||||||
|
"isCreatingSolution": true,
|
||||||
|
"version": "1.10.0",
|
||||||
|
"libraryName": "sp-fx-alm-webpart",
|
||||||
|
"libraryId": "0e22cfbc-16a8-4c0e-8ef8-888ecc691203",
|
||||||
|
"packageManager": "npm",
|
||||||
|
"isDomainIsolated": false,
|
||||||
|
"componentType": "webpart"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Manage SPFx solution using ALM APIs
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
This web part acts as a centralized place where admin can manage SPFx solutions present in their tenant using Application lifecycle Management(ALM) APIs and perform activities like Add, Deploy, Install, Retract, Uninstall & Remove apps.
|
||||||
|
|
||||||
|
### Tenant Appcatalog
|
||||||
|
|
||||||
|
![Application Lifecycle Management](./assets/SPFxALM.gif)
|
||||||
|
|
||||||
|
### Site Collection Appcatalog
|
||||||
|
|
||||||
|
![Application Lifecycle Management](./assets/SPFxALMSPAppcatalog.gif)
|
||||||
|
|
||||||
|
|
||||||
|
**Note:**
|
||||||
|
This webpart is mainly build for tenant and sharepoint admins, since most of the operation requires admininstrator privileges.
|
||||||
|
|
||||||
|
## Used SharePoint Framework Version
|
||||||
|
|
||||||
|
![version](https://img.shields.io/badge/version-1.10.0-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 or Tenant AppCatalog and Install the App
|
||||||
|
- Add the web part to any page in the Site Collection
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
|
||||||
|
Solution|Author(s)
|
||||||
|
--------|---------
|
||||||
|
React-Manage-SPFx-Solutions-ALM|Ramakrishnan Raman
|
||||||
|
|
||||||
|
## 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: 3.8 MiB |
Binary file not shown.
After Width: | Height: | Size: 2.6 MiB |
|
@ -0,0 +1,81 @@
|
||||||
|
resources:
|
||||||
|
- repo: self
|
||||||
|
trigger:
|
||||||
|
- master
|
||||||
|
- develop
|
||||||
|
pool:
|
||||||
|
vmImage: 'ubuntu-latest'
|
||||||
|
demands:
|
||||||
|
- npm
|
||||||
|
- node.js
|
||||||
|
variables:
|
||||||
|
npm_config_cache: $(Pipeline.Workspace)/.npm
|
||||||
|
|
||||||
|
steps:
|
||||||
|
#install node 10.x
|
||||||
|
- task: NodeTool@0
|
||||||
|
displayName: 'Use Node 10.x'
|
||||||
|
inputs:
|
||||||
|
versionSpec: 10.x
|
||||||
|
checkLatest: true
|
||||||
|
|
||||||
|
#cache files from previous run
|
||||||
|
- task: CacheBeta@1
|
||||||
|
inputs:
|
||||||
|
key: npm | $(Agent.OS) | package-lock.json
|
||||||
|
path: $(npm_config_cache)
|
||||||
|
cacheHitVar: CACHE_RESTORED
|
||||||
|
|
||||||
|
#install nodejs modules with npm
|
||||||
|
- script: npm ci
|
||||||
|
displayName: 'npm ci'
|
||||||
|
|
||||||
|
#bundle code with gulp
|
||||||
|
- task: Gulp@0
|
||||||
|
displayName: 'gulp bundle'
|
||||||
|
inputs:
|
||||||
|
gulpFile: '$(Build.SourcesDirectory)/gulpfile.js'
|
||||||
|
targets: bundle
|
||||||
|
arguments: '--ship'
|
||||||
|
continueOnError: true
|
||||||
|
|
||||||
|
#start unit tests
|
||||||
|
- script: npm test
|
||||||
|
displayName: 'npm test'
|
||||||
|
|
||||||
|
# Publish Test Results to Azure Pipelines/TFS
|
||||||
|
- task: PublishTestResults@2
|
||||||
|
displayName: Publish test results
|
||||||
|
inputs:
|
||||||
|
testResultsFiles: '**/junit.xml'
|
||||||
|
searchFolder: '$(Build.SourcesDirectory)'
|
||||||
|
testResultsFormat: JUnit
|
||||||
|
#failTaskOnFailedTests: true #if we want to fail the build on failed unit tests
|
||||||
|
|
||||||
|
# publish coverage test results
|
||||||
|
- task: PublishCodeCoverageResults@1
|
||||||
|
displayName: 'Publish Code Coverage Results'
|
||||||
|
inputs:
|
||||||
|
codeCoverageTool: Cobertura
|
||||||
|
summaryFileLocation: '$(Build.SourcesDirectory)/**/*coverage.xml'
|
||||||
|
|
||||||
|
#package solution with gulp
|
||||||
|
- task: Gulp@0
|
||||||
|
displayName: 'gulp package-solution'
|
||||||
|
inputs:
|
||||||
|
gulpFile: '$(Build.SourcesDirectory)/gulpfile.js'
|
||||||
|
targets: 'package-solution'
|
||||||
|
arguments: '--ship'
|
||||||
|
|
||||||
|
#copy files to artifact repository
|
||||||
|
- task: CopyFiles@2
|
||||||
|
displayName: 'Copy Files to: $(build.artifactstagingdirectory)/drop'
|
||||||
|
inputs:
|
||||||
|
Contents: '**/*.sppkg'
|
||||||
|
TargetFolder: '$(build.artifactstagingdirectory)/drop'
|
||||||
|
|
||||||
|
#publish artifacts
|
||||||
|
- task: PublishBuildArtifacts@1
|
||||||
|
displayName: 'Publish Artifact: drop'
|
||||||
|
inputs:
|
||||||
|
PathtoPublish: '$(build.artifactstagingdirectory)/drop'
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||||
|
"version": "2.0",
|
||||||
|
"bundles": {
|
||||||
|
"sp-fx-alm-web-part": {
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"entrypoint": "./lib/webparts/spFxAlm/SpFxAlmWebPart.js",
|
||||||
|
"manifest": "./src/webparts/spFxAlm/SpFxAlmWebPart.manifest.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"externals": {},
|
||||||
|
"localizedResources": {
|
||||||
|
"SpFxAlmWebPartStrings": "lib/webparts/spFxAlm/loc/{locale}.js"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
|
||||||
|
"deployCdnPath": "temp/deploy"
|
||||||
|
}
|
|
@ -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": "sp-fx-alm-webpart",
|
||||||
|
"accessKey": "<!-- ACCESS KEY -->"
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
{"preset":"@voitanos/jest-preset-spfx-react16","rootDir":"../src","collectCoverageFrom":["<rootDir>/**/*.{ts,tsx}","!<rootDir>/**/*.scss.*","!<rootDir>/loc/**/*.*"],"coverageReporters":["text","json","lcov","text-summary","cobertura"],"reporters":["default",["jest-junit",{"suiteName":"jest tests","outputDirectory":"temp/test/junit","outputName":"junit.xml"}]]}
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||||
|
"solution": {
|
||||||
|
"name": "sp-fx-alm-webpart-client-side-solution",
|
||||||
|
"id": "0e22cfbc-16a8-4c0e-8ef8-888ecc691203",
|
||||||
|
"version": "1.0.0.0",
|
||||||
|
"includeClientSideAssets": true,
|
||||||
|
"skipFeatureDeployment": true,
|
||||||
|
"isDomainIsolated": false
|
||||||
|
},
|
||||||
|
"paths": {
|
||||||
|
"zippedPackage": "solution/sp-fx-alm-webpart.sppkg"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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/"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||||
|
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// check if gulp dist was called
|
||||||
|
if (process.argv.indexOf('dist') !== -1) {
|
||||||
|
// add ship options to command call
|
||||||
|
process.argv.push('--ship');
|
||||||
|
}
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const gulp = require('gulp');
|
||||||
|
const build = require('@microsoft/sp-build-web');
|
||||||
|
const gulpSequence = require('gulp-sequence');
|
||||||
|
|
||||||
|
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||||
|
|
||||||
|
// Create clean distrubution package
|
||||||
|
gulp.task('dist', gulpSequence('clean', 'bundle', 'package-solution'));
|
||||||
|
// Create clean development package
|
||||||
|
gulp.task('dev', gulpSequence('clean', 'bundle', 'package-solution'));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom Framework Specific gulp tasks
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
build.initialize(gulp);
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,54 @@
|
||||||
|
{
|
||||||
|
"name": "sp-fx-alm-webpart",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "gulp bundle",
|
||||||
|
"clean": "gulp clean",
|
||||||
|
"preversion": "node ./tools/pre-version.js",
|
||||||
|
"postversion": "gulp dist",
|
||||||
|
"test": "./node_modules/.bin/jest --config ./config/jest.config.json",
|
||||||
|
"test:watch": "./node_modules/.bin/jest --config ./config/jest.config.json --watchAll"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@microsoft/sp-core-library": "1.10.0",
|
||||||
|
"@microsoft/sp-lodash-subset": "1.10.0",
|
||||||
|
"@microsoft/sp-office-ui-fabric-core": "1.10.0",
|
||||||
|
"@microsoft/sp-property-pane": "1.10.0",
|
||||||
|
"@microsoft/sp-webpart-base": "1.10.0",
|
||||||
|
"@pnp/pnpjs": "^2.0.2",
|
||||||
|
"@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/rush-stack-compiler-3.3": "0.3.5",
|
||||||
|
"@microsoft/sp-build-web": "1.10.0",
|
||||||
|
"@microsoft/sp-module-interfaces": "1.10.0",
|
||||||
|
"@microsoft/sp-tslint-rules": "1.10.0",
|
||||||
|
"@microsoft/sp-webpart-workbench": "1.10.0",
|
||||||
|
"@types/chai": "3.4.34",
|
||||||
|
"@types/mocha": "2.2.38",
|
||||||
|
"@voitanos/jest-preset-spfx-react16": "^1.3.2",
|
||||||
|
"ajv": "~5.2.2",
|
||||||
|
"gulp": "~3.9.1",
|
||||||
|
"gulp-sequence": "1.0.0",
|
||||||
|
"jest": "^23.6.0",
|
||||||
|
"jest-junit": "^10.0.0"
|
||||||
|
},
|
||||||
|
"jest-junit": {
|
||||||
|
"output": "temp/test/junit/junit.xml",
|
||||||
|
"usePathForSuiteName": "true"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||||
|
"id": "da7c20af-d821-4ceb-9542-5d25f36e950a",
|
||||||
|
"alias": "SpFxAlmWebPart",
|
||||||
|
"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": "SPFx ALM " },
|
||||||
|
"description": { "default": "A webpart to manage SPFx webpart lifecycle" },
|
||||||
|
"officeFabricIconFontName": "SharepointLogo",
|
||||||
|
"properties": {
|
||||||
|
"description": "SPFx ALM"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as ReactDom from 'react-dom';
|
||||||
|
import { Version } from '@microsoft/sp-core-library';
|
||||||
|
import {
|
||||||
|
IPropertyPaneConfiguration,
|
||||||
|
PropertyPaneTextField
|
||||||
|
} from '@microsoft/sp-property-pane';
|
||||||
|
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
|
||||||
|
|
||||||
|
import * as strings from 'SpFxAlmWebPartStrings';
|
||||||
|
import SpFxAlm from './components/SpFxAlm';
|
||||||
|
import { ISpFxAlmProps } from './components/ISpFxAlmProps';
|
||||||
|
import { sp } from '@pnp/sp';
|
||||||
|
import HttpService from '../spFxAlm/components/service';
|
||||||
|
|
||||||
|
|
||||||
|
export interface ISpFxAlmWebPartProps {
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class SpFxAlmWebPart extends BaseClientSideWebPart<ISpFxAlmWebPartProps> {
|
||||||
|
|
||||||
|
protected async onInit(): Promise<void> {
|
||||||
|
HttpService.Init(this.context.spHttpClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): void {
|
||||||
|
const element: React.ReactElement<ISpFxAlmProps> = React.createElement(
|
||||||
|
SpFxAlm,
|
||||||
|
{
|
||||||
|
url: this.context.pageContext.web.absoluteUrl,
|
||||||
|
rootSiteUrl: this.context.pageContext.web.serverRelativeUrl.length > 1 ? this.context.pageContext.web.absoluteUrl.replace(this.context.pageContext.web.serverRelativeUrl,"") : this.context.pageContext.web.absoluteUrl
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
ReactDom.render(element, this.domElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
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: strings.DescriptionFieldLabel
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
export interface ISpFxAlmProps {
|
||||||
|
url: string;
|
||||||
|
rootSiteUrl: string;
|
||||||
|
}
|
|
@ -0,0 +1,98 @@
|
||||||
|
@import '~office-ui-fabric-react/dist/sass/References.scss';
|
||||||
|
|
||||||
|
.spFxAlm {
|
||||||
|
.container {
|
||||||
|
max-width: 1030px;
|
||||||
|
margin: 0px auto;
|
||||||
|
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.errorMessage {
|
||||||
|
color: #a80000;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 400;
|
||||||
|
padding-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.customBorder
|
||||||
|
{
|
||||||
|
border-color: #c4c4c4;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin-bottom: 5px !important;
|
||||||
|
/* border-style : solid;*/
|
||||||
|
box-shadow: 0px 0px 15px #c4c4c4;
|
||||||
|
background-color: white !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row {
|
||||||
|
@include ms-Grid-row;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
/*background-color: $ms-color-themeDark;*/
|
||||||
|
padding: 20px;
|
||||||
|
background-color: white !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.column {
|
||||||
|
@include ms-Grid-col;
|
||||||
|
@include ms-lg10;
|
||||||
|
@include ms-xl8;
|
||||||
|
@include ms-xlPush2;
|
||||||
|
@include ms-lgPush1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
@include ms-font-xl;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subTitle {
|
||||||
|
@include ms-font-l;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
@include ms-font-l;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.autoComplete
|
||||||
|
{
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
// Our button
|
||||||
|
text-decoration: none;
|
||||||
|
height: 32px;
|
||||||
|
|
||||||
|
// Primary Button
|
||||||
|
min-width: 80px;
|
||||||
|
background-color: $ms-color-themePrimary;
|
||||||
|
border-color: $ms-color-themePrimary;
|
||||||
|
color: $ms-color-white;
|
||||||
|
|
||||||
|
// Basic Button
|
||||||
|
outline: transparent;
|
||||||
|
position: relative;
|
||||||
|
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
font-size: $ms-font-size-m;
|
||||||
|
font-weight: $ms-font-weight-regular;
|
||||||
|
border-width: 0;
|
||||||
|
text-align: center;
|
||||||
|
cursor: pointer;
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0 16px;
|
||||||
|
|
||||||
|
.label {
|
||||||
|
font-weight: $ms-font-weight-semibold;
|
||||||
|
font-size: $ms-font-size-m;
|
||||||
|
height: 32px;
|
||||||
|
line-height: 32px;
|
||||||
|
margin: 0 4px;
|
||||||
|
vertical-align: top;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,421 @@
|
||||||
|
|
||||||
|
import React, { useState, useEffect, useReducer } from 'react';
|
||||||
|
import styles from './SpFxAlm.module.scss';
|
||||||
|
import { ISpFxAlmProps } from './ISpFxAlmProps';
|
||||||
|
import { escape } from '@microsoft/sp-lodash-subset';
|
||||||
|
import { PrimaryButton } from 'office-ui-fabric-react/lib/Button';
|
||||||
|
import HttpService from './service';
|
||||||
|
import { Label, ILabelStyles } from 'office-ui-fabric-react/lib/Label';
|
||||||
|
import { Pivot, PivotItem } from 'office-ui-fabric-react/lib/Pivot';
|
||||||
|
import { IStyleSet } from 'office-ui-fabric-react/lib/Styling';
|
||||||
|
import { css } from "@uifabric/utilities/lib/css";
|
||||||
|
import { Dialog, DialogType, DialogFooter } from 'office-ui-fabric-react/lib/Dialog';
|
||||||
|
import { Spinner, SpinnerSize } from 'office-ui-fabric-react/lib/Spinner';
|
||||||
|
import { Dropdown, IDropdownStyles, IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
|
||||||
|
import { Toggle } from 'office-ui-fabric-react/lib/Toggle';
|
||||||
|
|
||||||
|
export default function SpFxAlm(props: ISpFxAlmProps) {
|
||||||
|
|
||||||
|
const [isSiteAppCatalog, setSiteAppCatalog] = useState(false);
|
||||||
|
const [file, setFile] = useState(null);
|
||||||
|
const [hideDialog, hideDialogBox] = useState(true);
|
||||||
|
const [operationInfo, setMessage] = useState("");
|
||||||
|
const [operationCompleted, setoperationStatus] = useState(false);
|
||||||
|
|
||||||
|
const [siteURL, setSiteURL] = useState("");
|
||||||
|
const [allSiteURL, setAllSiteURL] = useState([]);
|
||||||
|
const [tentantAppURL, setTenantAppURL] = useState("");
|
||||||
|
|
||||||
|
const [allSPFxApps, setAllApps] = useState([]);
|
||||||
|
const [appID, setAppID] = useState(null);
|
||||||
|
|
||||||
|
const [showaddremoveError, setShowUploadError] = useState({ addAppSelectSiteErr: false, addAppSelectAppErr: false, uploadAppSelectAppErr: false });
|
||||||
|
const [showDeployRetractError, setShoweployRetractError] = useState({ deployAppSelectSiteErr: false, deployAppSelectAppErr: false });
|
||||||
|
const [showunInstallError, setshowunInstallError] = useState({ appinstallSelectSiteErr: false, appinstallSelectAppErr: false });
|
||||||
|
|
||||||
|
const labelStyles: Partial<IStyleSet<ILabelStyles>> = {
|
||||||
|
root: { marginTop: 0 }
|
||||||
|
};
|
||||||
|
const dropdownStyles: Partial<IDropdownStyles> = {
|
||||||
|
dropdown: { width: 300 }
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadPrereqs();
|
||||||
|
}, [siteURL, isSiteAppCatalog, appID]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.spFxAlm} >
|
||||||
|
<div className={styles.container}>
|
||||||
|
<div className={css(styles.row, styles.customBorder)}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Pivot style={{ width: '100%' }} aria-label="Basic Pivot Example">
|
||||||
|
<PivotItem
|
||||||
|
headerText="Add or Remove App"
|
||||||
|
headerButtonProps={{
|
||||||
|
'data-order': 1,
|
||||||
|
'data-title': 'My Files Title'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className={styles.row}>
|
||||||
|
{isSiteAppCatalog && <Dropdown
|
||||||
|
placeholder="Select a site"
|
||||||
|
label="Select a site to perform the activity"
|
||||||
|
options={allSiteURL}
|
||||||
|
styles={{ dropdown: { width: '100%' }, root: { height: 100 } }}
|
||||||
|
onChange={_onSiteChange}
|
||||||
|
defaultSelectedKey={siteURL}
|
||||||
|
errorMessage={showaddremoveError.addAppSelectSiteErr ? 'Select Site' : undefined}
|
||||||
|
/>}
|
||||||
|
<Dropdown
|
||||||
|
placeholder="Select an app"
|
||||||
|
label="Select an app to perform the activity"
|
||||||
|
options={allSPFxApps}
|
||||||
|
styles={{ dropdown: { width: '100%' }, root: { height: 100 } }}
|
||||||
|
onChange={_onAppChange}
|
||||||
|
defaultSelectedKey={appID}
|
||||||
|
errorMessage={showaddremoveError.addAppSelectAppErr ? 'Select an App' : undefined}
|
||||||
|
/>
|
||||||
|
<div className='ms-Grid-col ms-u-sm6'>
|
||||||
|
<Label styles={labelStyles}>Upload solution package</Label>
|
||||||
|
</div>
|
||||||
|
<div className='ms-Grid-col ms-u-sm6'>
|
||||||
|
<input type='file' id='file' onChange={(e) => handleChange(e.target.files, e)} required accept='.sppkg' />
|
||||||
|
{showaddremoveError.uploadAppSelectAppErr && <div className={styles.errorMessage}>.sppkg file is required</div>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className={styles.row}>
|
||||||
|
<PrimaryButton text='Add an app' onClick={() => { addanApp() }} />
|
||||||
|
<PrimaryButton text='Remove App' onClick={() => { removeApp() }} ></PrimaryButton>
|
||||||
|
</div>
|
||||||
|
</PivotItem>
|
||||||
|
<PivotItem headerText="Deploy or Retract App">
|
||||||
|
<div className={styles.row}>
|
||||||
|
{isSiteAppCatalog && <Dropdown
|
||||||
|
placeholder="Select a site"
|
||||||
|
label="Select a site to perform the activity"
|
||||||
|
options={allSiteURL}
|
||||||
|
styles={{ dropdown: { width: '100%' }, root: { height: 100 } }}
|
||||||
|
onChange={_onSiteChange}
|
||||||
|
defaultSelectedKey={siteURL}
|
||||||
|
errorMessage={showDeployRetractError.deployAppSelectSiteErr ? 'Select Site' : undefined}
|
||||||
|
/>}
|
||||||
|
|
||||||
|
<Dropdown
|
||||||
|
placeholder="Select an app"
|
||||||
|
label="Select an app to perform the activity"
|
||||||
|
options={allSPFxApps}
|
||||||
|
styles={{ dropdown: { width: '100%' }, root: { height: 100 } }}
|
||||||
|
onChange={_onAppChange}
|
||||||
|
defaultSelectedKey={appID}
|
||||||
|
errorMessage={showDeployRetractError.deployAppSelectAppErr ? 'Select an App' : undefined}
|
||||||
|
/>
|
||||||
|
<PrimaryButton text='Deploy' onClick={() => { deployApp() }} ></PrimaryButton>
|
||||||
|
<PrimaryButton text='Retract' onClick={() => { retractApp() }} ></PrimaryButton>
|
||||||
|
</div>
|
||||||
|
</PivotItem>
|
||||||
|
<PivotItem headerText="Install or Uninstall App">
|
||||||
|
<div className={styles.row}>
|
||||||
|
<Dropdown
|
||||||
|
placeholder="Select a site"
|
||||||
|
label="Select a site to perform the activity"
|
||||||
|
options={allSiteURL}
|
||||||
|
styles={{ dropdown: { width: '100%' }, root: { height: 100 } }}
|
||||||
|
onChange={_onSiteChange}
|
||||||
|
defaultSelectedKey={siteURL}
|
||||||
|
errorMessage={showunInstallError.appinstallSelectSiteErr ? 'Select Site' : undefined}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Dropdown
|
||||||
|
placeholder="Select an app"
|
||||||
|
label="Select an app to perform the activity"
|
||||||
|
options={allSPFxApps}
|
||||||
|
styles={{ dropdown: { width: '100%' }, root: { height: 100 } }}
|
||||||
|
onChange={_onAppChange}
|
||||||
|
defaultSelectedKey={appID}
|
||||||
|
errorMessage={showunInstallError.appinstallSelectAppErr ? 'Select an App' : undefined}
|
||||||
|
/>
|
||||||
|
<PrimaryButton text='Install' onClick={() => { installApp() }} ></PrimaryButton>
|
||||||
|
<PrimaryButton text='Uninstall' onClick={() => { uninstallApp() }} ></PrimaryButton>
|
||||||
|
</div>
|
||||||
|
</PivotItem>
|
||||||
|
</Pivot>
|
||||||
|
<Toggle style={{ display: 'flex' }} label="For Site Collection App Catalog" onText="On" offText="Off" onChange={_ontoggleChange} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Dialog
|
||||||
|
hidden={hideDialog}
|
||||||
|
onDismiss={hideDialogWindow}
|
||||||
|
dialogContentProps={{
|
||||||
|
type: DialogType.normal,
|
||||||
|
title: '',
|
||||||
|
subText: ''
|
||||||
|
}}
|
||||||
|
modalProps={{
|
||||||
|
titleAriaId: 'myLabelId',
|
||||||
|
subtitleAriaId: 'mySubTextId',
|
||||||
|
isBlocking: true,
|
||||||
|
containerClassName: 'ms-dialogMainOverride'
|
||||||
|
}}
|
||||||
|
>{operationCompleted ? <span>{operationInfo}</span> : <Spinner size={SpinnerSize.large} label="Working on it..." ariaLive='assertive' />}
|
||||||
|
<DialogFooter>
|
||||||
|
{operationCompleted ? <PrimaryButton onClick={hideDialogWindow} text="Okay" /> : null}
|
||||||
|
</DialogFooter>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
|
</div >
|
||||||
|
);
|
||||||
|
|
||||||
|
function _onAppChange(event: React.FormEvent<HTMLDivElement>, item: IDropdownOption) {
|
||||||
|
setAppID(item.key);
|
||||||
|
};
|
||||||
|
|
||||||
|
function _onSiteChange(event: React.FormEvent<HTMLDivElement>, item: IDropdownOption) {
|
||||||
|
setSiteURL(item.text);
|
||||||
|
getAllApps();
|
||||||
|
};
|
||||||
|
|
||||||
|
function _ontoggleChange(ev: React.MouseEvent<HTMLElement>, checked: boolean) {
|
||||||
|
setSiteAppCatalog(checked);
|
||||||
|
getAllApps();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function hideDialogWindow() {
|
||||||
|
setAppID(null);
|
||||||
|
getAllApps();
|
||||||
|
hideDialogBox(true);
|
||||||
|
setoperationStatus(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayDialog() {
|
||||||
|
hideDialogBox(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleChange(selectorFiles: FileList, currentEvent: any) {
|
||||||
|
//Add only if .sppkg file
|
||||||
|
if (selectorFiles[0].name.substr(selectorFiles[0].name.length - 6).toLowerCase() === '.sppkg') {
|
||||||
|
setFile(selectorFiles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To load the prerequisite for this spfx app
|
||||||
|
*/
|
||||||
|
async function loadPrereqs() {
|
||||||
|
const tenanAppCatalogResponse = await HttpService.GetTenantAppcatalogUrl(props.url);
|
||||||
|
setTenantAppURL(tenanAppCatalogResponse.CorporateCatalogUrl);
|
||||||
|
getAllSites();
|
||||||
|
getAllApps();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all sites present on the tenant - brings 1000 sites
|
||||||
|
*/
|
||||||
|
async function getAllSites() {
|
||||||
|
const targetSite = isSiteAppCatalog ? siteURL : tentantAppURL;
|
||||||
|
const siteDetails = await HttpService.GetAllSites(targetSite, props.rootSiteUrl);
|
||||||
|
let allSiteCollectionURL: IDropdownOption[] = [];
|
||||||
|
await Promise.all(siteDetails.PrimaryQueryResult.RelevantResults.Table.Rows.map((currentSite) => {
|
||||||
|
allSiteCollectionURL.push({ key: currentSite.Cells[3].Value, text: currentSite.Cells[3].Value });
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (allSiteCollectionURL !== allSiteURL) {
|
||||||
|
setAllSiteURL(allSiteCollectionURL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all apps present on the tenant or site collection
|
||||||
|
*/
|
||||||
|
async function getAllApps() {
|
||||||
|
const targetSite = isSiteAppCatalog ? siteURL : tentantAppURL;
|
||||||
|
try {
|
||||||
|
const appDetails = await HttpService.GetApps(targetSite, isSiteAppCatalog);
|
||||||
|
let allApps: IDropdownOption[] = [];
|
||||||
|
|
||||||
|
// check if appcatalog available for the site
|
||||||
|
if (appDetails["error"] === undefined) {
|
||||||
|
appDetails.value.map((currentappDetail) => {
|
||||||
|
allApps.push({ key: currentappDetail.ID, text: currentappDetail.Title })
|
||||||
|
});
|
||||||
|
setAllApps(allApps);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setAllApps([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (exception) {
|
||||||
|
setMessage(exception);
|
||||||
|
setAllApps([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To Add an app in a site collection on tenant app catalog
|
||||||
|
*/
|
||||||
|
async function addanApp() {
|
||||||
|
try {
|
||||||
|
if (validate("AddApp")) {
|
||||||
|
setMessage("Working on it...");
|
||||||
|
displayDialog();
|
||||||
|
const targetSite = isSiteAppCatalog ? siteURL : tentantAppURL;
|
||||||
|
await HttpService.AddanApp(file, targetSite, isSiteAppCatalog);
|
||||||
|
setMessage("App added successfully !");
|
||||||
|
setoperationStatus(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (exception) {
|
||||||
|
setMessage(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To remove an app from site collection or tenant app catalog
|
||||||
|
*/
|
||||||
|
async function removeApp() {
|
||||||
|
try {
|
||||||
|
if (validate("RemoveApp")) {
|
||||||
|
setMessage("Working on it...");
|
||||||
|
displayDialog();
|
||||||
|
const targetSite = isSiteAppCatalog ? siteURL : tentantAppURL;
|
||||||
|
await HttpService.RemoveApp(targetSite, appID, isSiteAppCatalog);
|
||||||
|
setMessage("App removed successfully !");
|
||||||
|
setoperationStatus(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (exception) {
|
||||||
|
setMessage(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To install an app on a site
|
||||||
|
*/
|
||||||
|
async function installApp() {
|
||||||
|
try {
|
||||||
|
if (validate("InstallApp")) {
|
||||||
|
setMessage("Working on it...");
|
||||||
|
displayDialog();
|
||||||
|
const installAppResponse = await HttpService.InstallApp(siteURL, appID, isSiteAppCatalog);
|
||||||
|
setMessage("App installed successfully !");
|
||||||
|
setoperationStatus(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (exception) {
|
||||||
|
setMessage(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To Uninstall app from a site
|
||||||
|
*/
|
||||||
|
async function uninstallApp() {
|
||||||
|
try {
|
||||||
|
if (validate("UninstallApp")) {
|
||||||
|
setMessage("Working on it...");
|
||||||
|
displayDialog();
|
||||||
|
const uninstallAppResponse = await HttpService.UninstallApp(siteURL, appID, isSiteAppCatalog);
|
||||||
|
setMessage("App uninstalled successfully !");
|
||||||
|
setoperationStatus(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (exception) {
|
||||||
|
setMessage(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To deploy an app on tenant or site app catalog
|
||||||
|
*/
|
||||||
|
async function deployApp() {
|
||||||
|
try {
|
||||||
|
if (validate("DeployApp")) {
|
||||||
|
setMessage("Working on it...");
|
||||||
|
displayDialog();
|
||||||
|
const targetSite = isSiteAppCatalog ? siteURL : tentantAppURL;
|
||||||
|
await HttpService.DeployApp(targetSite, appID, isSiteAppCatalog);
|
||||||
|
setMessage("App deployed successfully !");
|
||||||
|
setoperationStatus(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (exception) {
|
||||||
|
setMessage(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To retract an app from tenant or site app catalog
|
||||||
|
*/
|
||||||
|
async function retractApp() {
|
||||||
|
try {
|
||||||
|
if (validate("RetractApp")) {
|
||||||
|
setMessage("Working on it...");
|
||||||
|
displayDialog();
|
||||||
|
const targetSite = isSiteAppCatalog ? siteURL : tentantAppURL;
|
||||||
|
await HttpService.RetractApp(targetSite, appID, isSiteAppCatalog);
|
||||||
|
setMessage("App retracted successfully !");
|
||||||
|
setoperationStatus(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (exception) {
|
||||||
|
setMessage(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* to validate the inputs are selected and show validations
|
||||||
|
*/
|
||||||
|
function validate(stage): boolean {
|
||||||
|
let isActionAllowed = true;
|
||||||
|
switch (stage) {
|
||||||
|
case 'AddApp':
|
||||||
|
if ((isSiteAppCatalog && siteURL.length === 0) || file === null) {
|
||||||
|
isActionAllowed = false;
|
||||||
|
}
|
||||||
|
setShowUploadError({ addAppSelectSiteErr: (siteURL.length > 0) ? false : true, addAppSelectAppErr: false, uploadAppSelectAppErr: file === null ? true : false });
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'RemoveApp':
|
||||||
|
if ((isSiteAppCatalog && siteURL.length === 0) || appID === null) {
|
||||||
|
isActionAllowed = false;
|
||||||
|
}
|
||||||
|
setShowUploadError({ addAppSelectSiteErr: (siteURL.length > 0) ? false : true, addAppSelectAppErr: appID === null ? true : false, uploadAppSelectAppErr: false });
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'DeployApp':
|
||||||
|
if ((isSiteAppCatalog && siteURL.length === 0) || appID === null) {
|
||||||
|
isActionAllowed = false;
|
||||||
|
}
|
||||||
|
setShoweployRetractError({ deployAppSelectSiteErr: (siteURL.length > 0) ? false : true, deployAppSelectAppErr: appID === null ? true : false });
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'RetractApp':
|
||||||
|
if ((isSiteAppCatalog && siteURL.length === 0) || appID === null) {
|
||||||
|
isActionAllowed = false;
|
||||||
|
}
|
||||||
|
setShoweployRetractError({ deployAppSelectSiteErr: (siteURL.length > 0) ? false : true, deployAppSelectAppErr: appID === null ? true : false });
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'InstallApp':
|
||||||
|
if ((isSiteAppCatalog && siteURL.length === 0) || appID === null) {
|
||||||
|
isActionAllowed = false;
|
||||||
|
}
|
||||||
|
setshowunInstallError({ appinstallSelectSiteErr: (siteURL.length > 0) ? false : true, appinstallSelectAppErr: appID === null ? true : false });
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'UninstallApp':
|
||||||
|
if ((isSiteAppCatalog && siteURL.length === 0) || appID === null) {
|
||||||
|
isActionAllowed = false;
|
||||||
|
}
|
||||||
|
setshowunInstallError({ appinstallSelectSiteErr: (siteURL.length > 0) ? false : true, appinstallSelectAppErr: appID === null ? true : false });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return isActionAllowed;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,136 @@
|
||||||
|
import { SPHttpClient, ISPHttpClientOptions, SPHttpClientResponse } from '@microsoft/sp-http';
|
||||||
|
|
||||||
|
export default class HttpService {
|
||||||
|
private static spHttpClient: SPHttpClient;
|
||||||
|
public static Init(spHttpClient: SPHttpClient) {
|
||||||
|
this.spHttpClient = spHttpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Get(url: string): Promise<any> {
|
||||||
|
var response = await this.spHttpClient.get(url, SPHttpClient.configurations.v1);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async GetTenantAppcatalogUrl(url): Promise<any> {
|
||||||
|
let requestUrl = url.concat("/_api/SP_TenantSettings_Current");
|
||||||
|
const response: SPHttpClientResponse = await this.spHttpClient.get(requestUrl, SPHttpClient.configurations.v1);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async GetAllSites(url, rootSiteUrl): Promise<any> {
|
||||||
|
let requestUrl = url.concat("/_api/search/query?querytext='contentclass:sts_site path:" + rootSiteUrl + "/sites/*'&selectproperties='SiteId,Path,Title'&trimduplicates=true&rowlimit=5000");
|
||||||
|
const response: SPHttpClientResponse = await this.spHttpClient.get(requestUrl, SPHttpClient.configurations.v1);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async GetApps(url: string, isSiteAppCatalog: boolean): Promise<any> {
|
||||||
|
const requestUrl = isSiteAppCatalog ? url.concat("/_api/web/sitecollectionappcatalog/AvailableApps")
|
||||||
|
: url.concat("/_api/web/tenantappcatalog/AvailableApps");
|
||||||
|
const response: SPHttpClientResponse = await this.spHttpClient.get(requestUrl, SPHttpClient.configurations.v1);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static async RetractApp(url: string, appid: string, isSiteAppCatalog: boolean): Promise<any> {
|
||||||
|
const requestUrl = isSiteAppCatalog ? url.concat("/_api/web/sitecollectionappcatalog/AvailableApps/GetById('" + appid + "')/Retract")
|
||||||
|
: url.concat("/_api/web/tenantappcatalog/AvailableApps/GetById('" + appid + "')/Retract");
|
||||||
|
const spOpts: ISPHttpClientOptions = {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json;odata=nometadata',
|
||||||
|
'Content-type': 'application/json;odata=verbose',
|
||||||
|
'odata-version': ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const response: SPHttpClientResponse = await this.spHttpClient.post(requestUrl, SPHttpClient.configurations.v1, spOpts);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async DeployApp(url: string, appid: string, isSiteAppCatalog: boolean): Promise<any> {
|
||||||
|
const requestUrl = isSiteAppCatalog ? url.concat("/_api/web/sitecollectionappcatalog/AvailableApps/GetById('" + appid + "')/Deploy")
|
||||||
|
: url.concat("/_api/web/tenantappcatalog/AvailableApps/GetById('" + appid + "')/Deploy");
|
||||||
|
const spOpts: ISPHttpClientOptions = {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json;odata=nometadata',
|
||||||
|
'Content-type': 'application/json;odata=verbose',
|
||||||
|
'odata-version': ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const response: SPHttpClientResponse = await this.spHttpClient.post(requestUrl, SPHttpClient.configurations.v1, spOpts);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static async InstallApp(url: string, appid: string, isSiteAppCatalog: boolean): Promise<any> {
|
||||||
|
const requestUrl = isSiteAppCatalog ? url.concat("/_api/web/sitecollectionappcatalog/AvailableApps/GetById('" + appid + "')/Install")
|
||||||
|
: url.concat("/_api/web/tenantappcatalog/AvailableApps/GetById('" + appid + "')/Install");
|
||||||
|
const spOpts: ISPHttpClientOptions = {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json;odata=nometadata',
|
||||||
|
'Content-type': 'application/json;odata=verbose',
|
||||||
|
'odata-version': ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const response: SPHttpClientResponse = await this.spHttpClient.post(requestUrl, SPHttpClient.configurations.v1, spOpts);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static async UpgradeApp(url: string, appid: string, isSiteAppCatalog: boolean): Promise<any> {
|
||||||
|
const requestUrl = isSiteAppCatalog ? url.concat("/_api/web/sitecollectionappcatalog/AvailableApps/GetById('" + appid + "')/Upgrade")
|
||||||
|
: url.concat("/_api/web/tenantappcatalog/AvailableApps/GetById('" + appid + "')/Upgrade");
|
||||||
|
|
||||||
|
const spOpts: ISPHttpClientOptions = {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json;odata=nometadata',
|
||||||
|
'Content-type': 'application/json;odata=verbose',
|
||||||
|
'odata-version': ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const response: SPHttpClientResponse = await this.spHttpClient.post(requestUrl, SPHttpClient.configurations.v1, spOpts);
|
||||||
|
return await response.json();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async UninstallApp(url: string, appid: string, isSiteAppCatalog: boolean): Promise<any> {
|
||||||
|
const requestUrl = isSiteAppCatalog ? url.concat("/_api/web/sitecollectionappcatalog/AvailableApps/GetById('" + appid + "')/Uninstall")
|
||||||
|
: url.concat("/_api/web/tenantappcatalog/AvailableApps/GetById('" + appid + "')/Uninstall");
|
||||||
|
|
||||||
|
const spOpts: ISPHttpClientOptions = {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json;odata=nometadata',
|
||||||
|
'Content-type': 'application/json;odata=verbose',
|
||||||
|
'odata-version': ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const response: SPHttpClientResponse = await this.spHttpClient.post(requestUrl, SPHttpClient.configurations.v1, spOpts);
|
||||||
|
return await response.json();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async AddanApp(file: File[], url: string, isSiteAppCatalog: boolean): Promise<any> {
|
||||||
|
const spOpts: ISPHttpClientOptions = {
|
||||||
|
body: new Blob(file)
|
||||||
|
};
|
||||||
|
|
||||||
|
const requestUrl = isSiteAppCatalog ? url.concat("/_api/web/sitecollectionappcatalog/Add(overwrite=true, url='" + file[0]["name"] + "')") : url.concat("/_api/web/tenantappcatalog/Add(overwrite=true, url='" + file[0]["name"] + "')");
|
||||||
|
const response: SPHttpClientResponse = await this.spHttpClient.post(requestUrl, SPHttpClient.configurations.v1, spOpts);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static async RemoveApp(url: string, appid: string, isSiteAppCatalog: boolean): Promise<any> {
|
||||||
|
const requestUrl = isSiteAppCatalog ? url.concat("/_api/web/sitecollectionappcatalog/AvailableApps/GetById('" + appid + "')/Remove")
|
||||||
|
: url.concat("/_api/web/tenantappcatalog/AvailableApps/GetById('" + appid + "')/Remove");
|
||||||
|
const spOpts: ISPHttpClientOptions = {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json;odata=nometadata',
|
||||||
|
'Content-type': 'application/json;odata=verbose',
|
||||||
|
'odata-version': ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const response: SPHttpClientResponse = await this.spHttpClient.post(requestUrl, SPHttpClient.configurations.v1, spOpts);
|
||||||
|
return await response.json();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
define([], function() {
|
||||||
|
return {
|
||||||
|
"PropertyPaneDescription": "Description",
|
||||||
|
"BasicGroupName": "Group Name",
|
||||||
|
"DescriptionFieldLabel": "Description Field"
|
||||||
|
}
|
||||||
|
});
|
10
samples/react-manage-spfx-solutions-alm/src/webparts/spFxAlm/loc/mystrings.d.ts
vendored
Normal file
10
samples/react-manage-spfx-solutions-alm/src/webparts/spFxAlm/loc/mystrings.d.ts
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
declare interface ISpFxAlmWebPartStrings {
|
||||||
|
PropertyPaneDescription: string;
|
||||||
|
BasicGroupName: string;
|
||||||
|
DescriptionFieldLabel: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'SpFxAlmWebPartStrings' {
|
||||||
|
const strings: ISpFxAlmWebPartStrings;
|
||||||
|
export = strings;
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
* This script updates the package-solution version analogue to the
|
||||||
|
* the package.json file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (process.env.npm_package_version === undefined) {
|
||||||
|
|
||||||
|
throw 'Package version cannot be evaluated';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// define path to package-solution file
|
||||||
|
const solution = './config/package-solution.json',
|
||||||
|
teams = './teams/manifest.json';
|
||||||
|
|
||||||
|
// require filesystem instance
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
// get next automated package version from process variable
|
||||||
|
const nextPkgVersion = process.env.npm_package_version;
|
||||||
|
|
||||||
|
// make sure next build version match
|
||||||
|
const nextVersion = nextPkgVersion.indexOf('-') === -1 ?
|
||||||
|
nextPkgVersion : nextPkgVersion.split('-')[0];
|
||||||
|
|
||||||
|
// Update version in SPFx package-solution if exists
|
||||||
|
if (fs.existsSync(solution)) {
|
||||||
|
|
||||||
|
// read package-solution file
|
||||||
|
const solutionFileContent = fs.readFileSync(solution, 'UTF-8');
|
||||||
|
// parse file as json
|
||||||
|
const solutionContents = JSON.parse(solutionFileContent);
|
||||||
|
|
||||||
|
// set property of version to next version
|
||||||
|
solutionContents.solution.version = nextVersion + '.0';
|
||||||
|
|
||||||
|
// save file
|
||||||
|
fs.writeFileSync(
|
||||||
|
solution,
|
||||||
|
// convert file back to proper json
|
||||||
|
JSON.stringify(solutionContents, null, 2),
|
||||||
|
'UTF-8');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update version in teams manifest if exists
|
||||||
|
if (fs.existsSync(teams)) {
|
||||||
|
|
||||||
|
// read package-solution file
|
||||||
|
const teamsManifestContent = fs.readFileSync(teams, 'UTF-8');
|
||||||
|
// parse file as json
|
||||||
|
const teamsContent = JSON.parse(teamsManifestContent);
|
||||||
|
|
||||||
|
// set property of version to next version
|
||||||
|
teamsContent.version = nextVersion;
|
||||||
|
|
||||||
|
// save file
|
||||||
|
fs.writeFileSync(
|
||||||
|
teams,
|
||||||
|
// convert file back to proper json
|
||||||
|
JSON.stringify(teamsContent, null, 2),
|
||||||
|
'UTF-8');
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.3/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"
|
||||||
|
],
|
||||||
|
"esModuleInterop": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*.ts"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"lib"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue