🎉 - Added tenant wide extension manager sample

This commit is contained in:
Dan Toft 2023-07-10 21:30:10 +02:00
parent b129d5e8ac
commit 23cfe88c22
36 changed files with 59581 additions and 0 deletions

View File

@ -0,0 +1,352 @@
require('@rushstack/eslint-config/patch/modern-module-resolution');
module.exports = {
extends: ['@microsoft/eslint-config-spfx/lib/profiles/react'],
parserOptions: { tsconfigRootDir: __dirname },
overrides: [
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
'parserOptions': {
'project': './tsconfig.json',
'ecmaVersion': 2018,
'sourceType': 'module'
},
rules: {
// Prevent usage of the JavaScript null value, while allowing code to access existing APIs that may require null. https://www.npmjs.com/package/@rushstack/eslint-plugin
'@rushstack/no-new-null': 1,
// Require Jest module mocking APIs to be called before any other statements in their code block. https://www.npmjs.com/package/@rushstack/eslint-plugin
'@rushstack/hoist-jest-mock': 1,
// Require regular expressions to be constructed from string constants rather than dynamically building strings at runtime. https://www.npmjs.com/package/@rushstack/eslint-plugin-security
'@rushstack/security/no-unsafe-regexp': 1,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/adjacent-overload-signatures': 1,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
//
// CONFIGURATION: By default, these are banned: String, Boolean, Number, Object, Symbol
'@typescript-eslint/ban-types': [
1,
{
'extendDefaults': false,
'types': {
'String': {
'message': 'Use \'string\' instead',
'fixWith': 'string'
},
'Boolean': {
'message': 'Use \'boolean\' instead',
'fixWith': 'boolean'
},
'Number': {
'message': 'Use \'number\' instead',
'fixWith': 'number'
},
'Object': {
'message': 'Use \'object\' instead, or else define a proper TypeScript type:'
},
'Symbol': {
'message': 'Use \'symbol\' instead',
'fixWith': 'symbol'
},
'Function': {
'message': 'The \'Function\' type accepts any function-like value.\nIt provides no type safety when calling the function, which can be a common source of bugs.\nIt also accepts things like class declarations, which will throw at runtime as they will not be called with \'new\'.\nIf you are expecting the function to accept certain arguments, you should explicitly define the function shape.'
}
}
}
],
// RATIONALE: Code is more readable when the type of every variable is immediately obvious.
// Even if the compiler may be able to infer a type, this inference will be unavailable
// to a person who is reviewing a GitHub diff. This rule makes writing code harder,
// but writing code is a much less important activity than reading it.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/explicit-function-return-type': [
1,
{
'allowExpressions': true,
'allowTypedFunctionExpressions': true,
'allowHigherOrderFunctions': false
}
],
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
// Rationale to disable: although this is a recommended rule, it is up to dev to select coding style.
// Set to 1 (warning) or 2 (error) to enable.
'@typescript-eslint/explicit-member-accessibility': 0,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-array-constructor': 1,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
//
// RATIONALE: The "any" keyword disables static type checking, the main benefit of using TypeScript.
// This rule should be suppressed only in very special cases such as JSON.stringify()
// where the type really can be anything. Even if the type is flexible, another type
// may be more appropriate such as "unknown", "{}", or "Record<k,V>".
'@typescript-eslint/no-explicit-any': 1,
// RATIONALE: The #1 rule of promises is that every promise chain must be terminated by a catch()
// handler. Thus wherever a Promise arises, the code must either append a catch handler,
// or else return the object to a caller (who assumes this responsibility). Unterminated
// promise chains are a serious issue. Besides causing errors to be silently ignored,
// they can also cause a NodeJS process to terminate unexpectedly.
'@typescript-eslint/no-floating-promises': 0,
// RATIONALE: Catches a common coding mistake.
'@typescript-eslint/no-for-in-array': 2,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-misused-new': 2,
// RATIONALE: The "namespace" keyword is not recommended for organizing code because JavaScript lacks
// a "using" statement to traverse namespaces. Nested namespaces prevent certain bundler
// optimizations. If you are declaring loose functions/variables, it's better to make them
// static members of a class, since classes support property getters and their private
// members are accessible by unit tests. Also, the exercise of choosing a meaningful
// class name tends to produce more discoverable APIs: for example, search+replacing
// the function "reverse()" is likely to return many false matches, whereas if we always
// write "Text.reverse()" is more unique. For large scale organization, it's recommended
// to decompose your code into separate NPM packages, which ensures that component
// dependencies are tracked more conscientiously.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-namespace': [
1,
{
'allowDeclarations': false,
'allowDefinitionFiles': false
}
],
// RATIONALE: Parameter properties provide a shorthand such as "constructor(public title: string)"
// that avoids the effort of declaring "title" as a field. This TypeScript feature makes
// code easier to write, but arguably sacrifices readability: In the notes for
// "@typescript-eslint/member-ordering" we pointed out that fields are central to
// a class's design, so we wouldn't want to bury them in a constructor signature
// just to save some typing.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
// Set to 1 (warning) or 2 (error) to enable the rule
'@typescript-eslint/parameter-properties': 0,
// RATIONALE: When left in shipping code, unused variables often indicate a mistake. Dead code
// may impact performance.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-unused-vars': [
1,
{
'vars': 'all',
// Unused function arguments often indicate a mistake in JavaScript code. However in TypeScript code,
// the compiler catches most of those mistakes, and unused arguments are fairly common for type signatures
// that are overriding a base class method or implementing an interface.
'args': 'none'
}
],
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-use-before-define': [
2,
{
'functions': false,
'classes': true,
'variables': true,
'enums': true,
'typedefs': true
}
],
// Disallows require statements except in import statements.
// In other words, the use of forms such as var foo = require("foo") are banned. Instead use ES6 style imports or import foo = require("foo") imports.
'@typescript-eslint/no-var-requires': 'error',
// RATIONALE: The "module" keyword is deprecated except when describing legacy libraries.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/prefer-namespace-keyword': 1,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
// Rationale to disable: it's up to developer to decide if he wants to add type annotations
// Set to 1 (warning) or 2 (error) to enable the rule
'@typescript-eslint/no-inferrable-types': 0,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
// Rationale to disable: declaration of empty interfaces may be helpful for generic types scenarios
'@typescript-eslint/no-empty-interface': 0,
// RATIONALE: This rule warns if setters are defined without getters, which is probably a mistake.
'accessor-pairs': 1,
// RATIONALE: In TypeScript, if you write x["y"] instead of x.y, it disables type checking.
'dot-notation': [
1,
{
'allowPattern': '^_'
}
],
// RATIONALE: Catches code that is likely to be incorrect
'eqeqeq': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'for-direction': 1,
// RATIONALE: Catches a common coding mistake.
'guard-for-in': 2,
// RATIONALE: If you have more than 2,000 lines in a single source file, it's probably time
// to split up your code.
'max-lines': ['warn', { max: 2000 }],
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-async-promise-executor': 2,
// RATIONALE: Deprecated language feature.
'no-caller': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-compare-neg-zero': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-cond-assign': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-constant-condition': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-control-regex': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-debugger': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-delete-var': 2,
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-duplicate-case': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-empty': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-empty-character-class': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-empty-pattern': 1,
// RATIONALE: Eval is a security concern and a performance concern.
'no-eval': 1,
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-ex-assign': 2,
// RATIONALE: System types are global and should not be tampered with in a scalable code base.
// If two different libraries (or two versions of the same library) both try to modify
// a type, only one of them can win. Polyfills are acceptable because they implement
// a standardized interoperable contract, but polyfills are generally coded in plain
// JavaScript.
'no-extend-native': 1,
// Disallow unnecessary labels
'no-extra-label': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-fallthrough': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-func-assign': 1,
// RATIONALE: Catches a common coding mistake.
'no-implied-eval': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-invalid-regexp': 2,
// RATIONALE: Catches a common coding mistake.
'no-label-var': 2,
// RATIONALE: Eliminates redundant code.
'no-lone-blocks': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-misleading-character-class': 2,
// RATIONALE: Catches a common coding mistake.
'no-multi-str': 2,
// RATIONALE: It's generally a bad practice to call "new Thing()" without assigning the result to
// a variable. Either it's part of an awkward expression like "(new Thing()).doSomething()",
// or else implies that the constructor is doing nontrivial computations, which is often
// a poor class design.
'no-new': 1,
// RATIONALE: Obsolete language feature that is deprecated.
'no-new-func': 2,
// RATIONALE: Obsolete language feature that is deprecated.
'no-new-object': 2,
// RATIONALE: Obsolete notation.
'no-new-wrappers': 1,
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-octal': 2,
// RATIONALE: Catches code that is likely to be incorrect
'no-octal-escape': 2,
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-regex-spaces': 2,
// RATIONALE: Catches a common coding mistake.
'no-return-assign': 2,
// RATIONALE: Security risk.
'no-script-url': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-self-assign': 2,
// RATIONALE: Catches a common coding mistake.
'no-self-compare': 2,
// RATIONALE: This avoids statements such as "while (a = next(), a && a.length);" that use
// commas to create compound expressions. In general code is more readable if each
// step is split onto a separate line. This also makes it easier to set breakpoints
// in the debugger.
'no-sequences': 1,
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-shadow-restricted-names': 2,
// RATIONALE: Obsolete language feature that is deprecated.
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-sparse-arrays': 2,
// RATIONALE: Although in theory JavaScript allows any possible data type to be thrown as an exception,
// such flexibility adds pointless complexity, by requiring every catch block to test
// the type of the object that it receives. Whereas if catch blocks can always assume
// that their object implements the "Error" contract, then the code is simpler, and
// we generally get useful additional information like a call stack.
'no-throw-literal': 2,
// RATIONALE: Catches a common coding mistake.
'no-unmodified-loop-condition': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-unsafe-finally': 2,
// RATIONALE: Catches a common coding mistake.
'no-unused-expressions': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-unused-labels': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-useless-catch': 1,
// RATIONALE: Avoids a potential performance problem.
'no-useless-concat': 1,
// RATIONALE: The "var" keyword is deprecated because of its confusing "hoisting" behavior.
// Always use "let" or "const" instead.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'no-var': 2,
// RATIONALE: Generally not needed in modern code.
'no-void': 1,
// RATIONALE: Obsolete language feature that is deprecated.
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-with': 2,
// RATIONALE: Makes logic easier to understand, since constants always have a known value
// @typescript-eslint\eslint-plugin\dist\configs\eslint-recommended.js
'prefer-const': 1,
// RATIONALE: Catches a common coding mistake where "resolve" and "reject" are confused.
'promise/param-names': 2,
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'require-atomic-updates': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'require-yield': 1,
// "Use strict" is redundant when using the TypeScript compiler.
'strict': [
2,
'never'
],
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'use-isnan': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
// Set to 1 (warning) or 2 (error) to enable.
// Rationale to disable: !!{}
'no-extra-boolean-cast': 0,
// ====================================================================
// @microsoft/eslint-plugin-spfx
// ====================================================================
'@microsoft/spfx/import-requires-chunk-name': 1,
'@microsoft/spfx/no-require-ensure': 2,
'@microsoft/spfx/pair-react-dom-render-unmount': 1
}
},
{
// For unit tests, we can be a little bit less strict. The settings below revise the
// defaults specified in the extended configurations, as well as above.
files: [
// Test files
'*.test.ts',
'*.test.tsx',
'*.spec.ts',
'*.spec.tsx',
// Facebook convention
'**/__mocks__/*.ts',
'**/__mocks__/*.tsx',
'**/__tests__/*.ts',
'**/__tests__/*.tsx',
// Microsoft convention
'**/test/*.ts',
'**/test/*.tsx'
],
rules: {}
}
]
};

View File

@ -0,0 +1,35 @@
# Logs
logs
*.log
npm-debug.log*
# Dependency directories
node_modules
# Build generated files
dist
lib
release
solution
temp
*.sppkg
.heft
# Coverage directory used by tools like istanbul
coverage
# OSX
.DS_Store
# Visual Studio files
.ntvs_analysis.dat
.vs
bin
obj
# Resx Generated Code
*.resx.ts
# Styles Generated Code
*.scss.ts
*.scss.d.ts

View File

@ -0,0 +1,16 @@
!dist
config
gulpfile.js
release
src
temp
tsconfig.json
tslint.json
*.log
.yo-rc.json
.vscode

View File

@ -0,0 +1,21 @@
{
"@microsoft/generator-sharepoint": {
"plusBeta": false,
"isCreatingSolution": true,
"nodeVersion": "16.20.0",
"sdksVersions": {
"@microsoft/microsoft-graph-client": "3.0.2",
"@microsoft/teams-js": "2.9.1"
},
"version": "1.17.2",
"libraryName": "tenant-wide-extension-manager",
"libraryId": "6306e257-de7e-4884-b27f-9338b86b15fd",
"environment": "spo",
"packageManager": "npm",
"solutionName": "Tenant Wide Extension Manager",
"solutionShortDescription": "Tenant Wide Extension Manager description",
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"componentType": "webpart"
}
}

View File

@ -0,0 +1,89 @@
# Tenant wide extensions manager
## Summary
This idea came about after years of hating updating the properties of a tenant wide deployed extension, and thinking I was just bad a classic SharePoint, then during a community call I saw [Vesa](https://twitter.com/vesajuvonen) struggle as well and I thought "We have a modern app catalog, why can't we have a modern extension managing experience?".
Here it is, a modern extension manager, that allows you to easily enable/disable extensions, and update the properties of the extension.
![Sample gif](./assets/Demo.gif)
## Compatibility
| :warning: Important |
| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Every SPFx version is only compatible with specific version(s) of Node.js. In order to be able to build this sample, please ensure that the version of Node on your workstation matches one of the versions listed in this section. This sample will not work on a different version of Node. |
| Refer to <https://aka.ms/spfx-matrix> for more information on SPFx compatibility. |
This sample is optimally compatible with the following environment configuration:
![SPFx 1.17.2](https://img.shields.io/badge/SPFx-1.17.2-green.svg)
![Node.js v16](https://img.shields.io/badge/Node.js-v16-green.svg)
![Compatible with SharePoint Online](https://img.shields.io/badge/SharePoint%20Online-Compatible-green.svg)
![Does not work with SharePoint 2019](https://img.shields.io/badge/SharePoint%20Server%202019-Incompatible-red.svg "SharePoint Server 2019 requires SPFx 1.4.1 or lower")
![Does not work with SharePoint 2016 (Feature Pack 2)](https://img.shields.io/badge/SharePoint%20Server%202016%20(Feature%20Pack%202)-Incompatible-red.svg "SharePoint Server 2016 Feature Pack 2 requires SPFx 1.1")
![Local Workbench Unsupported](https://img.shields.io/badge/Local%20Workbench-Unsupported-red.svg "Local workbench is no longer available as of SPFx 1.13 and above")
![Hosted Workbench Compatible](https://img.shields.io/badge/Hosted%20Workbench-Compatible-green.svg)
![Compatible with Remote Containers](https://img.shields.io/badge/Remote%20Containers-Not%20Tested-yellow.svg)
For more information about SPFx compatibility, please refer to https://aka.ms/spfx-matrix
## Applies to
* [SharePoint Framework](https://learn.microsoft.com/sharepoint/dev/spfx/sharepoint-framework-overview)
* [Microsoft 365 tenant](https://learn.microsoft.com/sharepoint/dev/spfx/set-up-your-development-environment)
> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/m365devprogram)
## Contributors
* [Dan Toft](https://github.com/Tanddant)
## Version history
| Version | Date | Comments |
| ------- | ------------- | --------------- |
| 1.0 | July 10, 2023 | Initial release |
## Prerequisites
You'll need a document library to store the responses
## 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-extension-manager) then unzip it)
* From your command line, change your current directory to the directory containing this sample (`react-extension-manager`, located under `samples`)
* 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.
## Features
- Manage your tenant wide extensions
- Easily enable/disable extensions
- Easily update the extension properties
## Help
We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues.
If you're having issues building the solution, please run [spfx doctor](https://pnp.github.io/cli-microsoft365/cmd/spfx/spfx-doctor/) from within the solution folder to diagnose incompatibility issues with your environment.
You can try looking at [issues related to this sample](https://github.com/pnp/sp-dev-fx-webparts/issues?q=label%3A%22sample%3A%20react-extension-manager%22) to see if anybody else is having the same issues.
You can also try looking at [discussions related to this sample](https://github.com/pnp/sp-dev-fx-webparts/discussions?discussions_q=react-extension-manager) and see what the community is saying.
If you encounter any issues using this sample, [create a new issue](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected%2Csample%3A%20react-extension-manager&template=bug-report.yml&sample=react-extension-manager&authors=@Tanddant&title=react-extension-manager%20-%20).
For questions regarding this sample, [create a new question](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Aquestion%2Csample%3A%20react-extension-manager&template=question.yml&sample=react-extension-manager&authors=@Tanddant&title=react-extension-manager%20-%20).
Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Aenhancement%2Csample%3A%20react-extension-manager&template=suggestion.yml&sample=react-extension-manager&authors=@Tanddant&title=react-extension-manager%20-%20).
## Disclaimer
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
<img src="https://m365-visitor-stats.azurewebsites.net/sp-dev-fx-webparts/samples/react-extension-manager" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 MiB

View File

@ -0,0 +1,50 @@
[
{
"name": "pnp-sp-dev-spfx-web-parts-react-extension-manager",
"source": "pnp",
"title": "Tenant wide extension manager",
"shortDescription": "Manage those tenant wide extensions",
"url": "https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-extension-manager",
"downloadUrl": "https://pnp.github.io/download-partial/?url=https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-extension-manager",
"longDescription": [
"Here it is, a modern extension manager, that allows you to easily enable/disable, and update the properties of the globally deployed extensions in your environment."
],
"creationDateTime": "2023-07-10",
"updateDateTime": "2023-07-10",
"products": [
"SharePoint"
],
"metadata": [
{
"key": "CLIENT-SIDE-DEV",
"value": "React"
},
{
"key": "SPFX-VERSION",
"value": "1.17.2"
}
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://github.com/pnp/sp-dev-fx-webparts/raw/main/samples/react-extension-manager/assets/Demo.gif",
"alt": "Web Part Preview"
}
],
"authors": [
{
"gitHubAccount": "Tanddant",
"pictureUrl": "https://github.com/Tanddant.png",
"name": "Dan Toft"
}
],
"references": [
{
"name": "Build your first SharePoint client-side web part",
"description": "Client-side web parts are client-side components that run in the context of a SharePoint page. Client-side web parts can be deployed to SharePoint environments that support the SharePoint Framework. You can also use modern JavaScript web frameworks, tools, and libraries to build them.",
"url": "https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part"
}
]
}
]

View File

@ -0,0 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"tenant-wide-extension-manager-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/tenantWideExtensionManager/TenantWideExtensionManagerWebPart.js",
"manifest": "./src/webparts/tenantWideExtensionManager/TenantWideExtensionManagerWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"TenantWideExtensionManagerWebPartStrings": "lib/webparts/tenantWideExtensionManager/loc/{locale}.js"
}
}

View File

@ -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": "tenant-wide-extension-manager",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -0,0 +1,40 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "tenant-wide-extension-manager-client-side-solution",
"id": "6306e257-de7e-4884-b27f-9338b86b15fd",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"developer": {
"name": "",
"websiteUrl": "",
"privacyUrl": "",
"termsOfUseUrl": "",
"mpnId": "Undefined-1.17.2"
},
"metadata": {
"shortDescription": {
"default": "Tenant Wide Extension Manager description"
},
"longDescription": {
"default": "Tenant Wide Extension Manager description"
},
"screenshotPaths": [],
"videoUrl": "",
"categories": []
},
"features": [
{
"title": "tenant-wide-extension-manager Feature",
"description": "The feature that activates elements of the tenant-wide-extension-manager solution.",
"id": "ea8b7725-3b09-4a82-bdcb-6d6af31137a1",
"version": "1.0.0.0"
}
]
},
"paths": {
"zippedPackage": "solution/tenant-wide-extension-manager.sppkg"
}
}

View File

@ -0,0 +1,3 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/sass.schema.json"
}

View File

@ -0,0 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json",
"port": 4321,
"https": true,
"initialPage": "https://{tenantDomain}/_layouts/workbench.aspx"
}

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,17 @@
'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

View File

@ -0,0 +1,48 @@
{
"name": "tenant-wide-extension-manager",
"version": "0.0.1",
"private": true,
"engines": {
"node": ">=16.13.0 <17.0.0"
},
"main": "lib/index.js",
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test",
"serve": "gulp bundle"
},
"dependencies": {
"@fluentui/react": "^7.199.1",
"@microsoft/sp-component-base": "1.17.2",
"@microsoft/sp-core-library": "1.17.2",
"@microsoft/sp-lodash-subset": "1.17.2",
"@microsoft/sp-office-ui-fabric-core": "1.17.2",
"@microsoft/sp-property-pane": "1.17.2",
"@microsoft/sp-webpart-base": "1.17.2",
"@pnp/graph": "^3.16.0",
"@pnp/sp": "^3.16.0",
"office-ui-fabric-react": "^7.199.1",
"react": "17.0.1",
"react-code-editor-editable": "^0.6.3",
"react-dom": "17.0.1",
"tslib": "2.3.1"
},
"devDependencies": {
"@fluentui/react": "^7.199.1",
"@microsoft/eslint-config-spfx": "1.17.2",
"@microsoft/eslint-plugin-spfx": "1.17.2",
"@microsoft/rush-stack-compiler-4.5": "0.5.0",
"@microsoft/sp-build-web": "1.17.2",
"@microsoft/sp-module-interfaces": "1.17.2",
"@rushstack/eslint-config": "2.5.1",
"@types/react": "17.0.45",
"@types/react-dom": "17.0.17",
"@types/webpack-env": "~1.15.2",
"ajv": "^6.12.5",
"eslint": "8.7.0",
"eslint-plugin-react-hooks": "4.3.0",
"gulp": "4.0.2",
"typescript": "4.5.5"
}
}

View File

@ -0,0 +1,12 @@
import { createContext } from 'react'
import { BaseComponentContext } from '@microsoft/sp-component-base';
import { SPFI } from '@pnp/sp/presets/all';
import { IAppCatalogProvider } from '../Providers/AppCatalogProvider';
export interface IApplicationContext {
context: BaseComponentContext;
PnPjs: SPFI
Provider: IAppCatalogProvider;
}
export const ApplicationContext = createContext<IApplicationContext>(null);

View File

@ -0,0 +1,31 @@
import { useState, useEffect, useContext } from 'react';
import { IExtension } from '../Models/Extension';
import { ApplicationContext } from '../Contexsts/ApplicationContext';
export default function useExtension(Id: number): { extension: IExtension, isLoading: boolean, update: (update: Partial<IExtension>) => void, changes: Partial<IExtension> } {
const { Provider } = useContext(ApplicationContext);
const [currentValue, setCurrentValue] = useState<IExtension>(null);
const [updates, setUpdates] = useState<Partial<IExtension>>({});
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
async function fetchData(): Promise<void> {
setIsLoading(true);
const ext: IExtension = await Provider.getExtensionById(Id);
setCurrentValue(ext);
setUpdates({});
setIsLoading(false);
}
if (Id !== null) {
fetchData();
} else {
setCurrentValue(null);
setUpdates({});
}
}, [Id]);
return {
extension: { ...currentValue, ...updates }, isLoading, update: setUpdates, changes: updates
};
}

View File

@ -0,0 +1,13 @@
import * as React from "react";
import { IColumn, Toggle } from "@fluentui/react";
import { IExtension } from "../Models/Extension";
import { ListTypeStrings } from "../Models/ListType";
import { LocationStrings } from "../Models/Location";
const DefaultColumn: (key: string) => IColumn = (key: string) => ({ key: key, fieldName: key, name: key, minWidth: 125, isResizable: true });
export const Columns: IColumn[] = [
{ ...DefaultColumn("TenantWideExtensionDisabled"), name: "Enabled", maxWidth: 60, onRender: (item: IExtension) => <Toggle disabled checked={!item.TenantWideExtensionDisabled} /> },
{ ...DefaultColumn("Title") },
{ ...DefaultColumn("TenantWideExtensionLocation"), name: "Location", minWidth: 250, onRender: (item: IExtension) => <span>{LocationStrings[item.TenantWideExtensionLocation]}</span> },
{ ...DefaultColumn('TenantWideExtensionListTemplate'), name: "List type", minWidth: 250, onRender: (item: IExtension) => <span>{ListTypeStrings[item.TenantWideExtensionListTemplate]}</span> },
]

View File

@ -0,0 +1,26 @@
import { ListType } from "./ListType"
import { ExtensionLocation } from "./Location";
export interface IExtension {
Id: number;
Title: string;
TenantWideExtensionComponentId: string;
TenantWideExtensionComponentProperties: string;
TenantWideExtensionListTemplate: ListType;
TenantWideExtensionLocation: ExtensionLocation;
TenantWideExtensionSequence: number;
TenantWideExtensionDisabled: boolean;
}
export const CleanExtension: (item: Partial<IExtension>) => IExtension = (item: Partial<IExtension>) => ({
Id: item.Id,
Title: item.Title,
TenantWideExtensionComponentId: item.TenantWideExtensionComponentId,
TenantWideExtensionComponentProperties: item.TenantWideExtensionComponentProperties,
TenantWideExtensionListTemplate: item.TenantWideExtensionListTemplate,
TenantWideExtensionLocation: item.TenantWideExtensionLocation,
TenantWideExtensionSequence: item.TenantWideExtensionSequence,
TenantWideExtensionDisabled: item.TenantWideExtensionDisabled
})
export const ExtensionSelects = ["Id", "Title", "TenantWideExtensionComponentId", "TenantWideExtensionComponentProperties", "TenantWideExtensionListTemplate", "TenantWideExtensionLocation", "TenantWideExtensionSequence", "TenantWideExtensionDisabled"]

View File

@ -0,0 +1,60 @@
// https://learn.microsoft.com/en-us/openspecs/sharepoint_protocols/ms-wssts/8bf797af-288c-4a1d-a14b-cf5394e636cf
export enum ListType {
None = 0,
CustomList = 100,
DocumentLibrary = 101,
Survey = 102,
Links = 103,
Announcements = 104,
Contacts = 105,
Calendar = 106,
Tasks = 107,
DiscussionBoard = 108,
PictureLibrary = 109,
DataSources = 110,
FormLibrary = 115,
NoCodeWorkflows = 117,
CustomWorkflowProcess = 118,
WikiPageLibrary = 119,
CustomGrid = 120,
NoCodePublicWorkflows = 122,
WorkflowHistory = 140,
ProjectTasks = 150,
PublicWorkflowsExternalList = 600,
IssueTracking = 1100,
//Undocumented, but needed for this solution
TenantWideExtensions = 337
}
export const ListTypeStrings = {
[ListType.None]: "N/A",
[ListType.CustomList]: "Custom List",
[ListType.DocumentLibrary]: "Document Library",
[ListType.Survey]: "Survey",
[ListType.Links]: "Links",
[ListType.Announcements]: "Announcements",
[ListType.Contacts]: "Contacts",
[ListType.Calendar]: "Calendar",
[ListType.Tasks]: "Tasks",
[ListType.DiscussionBoard]: "Discussion Board",
[ListType.PictureLibrary]: "Picture Library",
[ListType.DataSources]: "Data Sources",
[ListType.FormLibrary]: "Form Library",
[ListType.NoCodeWorkflows]: "No Code Workflows",
[ListType.CustomWorkflowProcess]: "Custom Workflow Process",
[ListType.WikiPageLibrary]: "Wiki Page Library",
[ListType.CustomGrid]: "Custom Grid",
[ListType.NoCodePublicWorkflows]: "No Code Public Workflows",
[ListType.WorkflowHistory]: "Workflow History",
[ListType.ProjectTasks]: "Project Tasks",
[ListType.PublicWorkflowsExternalList]: "Public Workflows External List",
[ListType.IssueTracking]: "Issue Tracking",
[ListType.TenantWideExtensions]: "Tenant Wide Extensions",
}
export const ListTypes: ListType[] = Object.keys(ListTypeStrings).map(x => parseInt(x)) as ListType[];
export const OFFICIALLY_SUPPORTED_LIST_TYPES = [ListType.CustomList, ListType.DocumentLibrary];

View File

@ -0,0 +1,15 @@
export enum ExtensionLocation {
ApplicationCustomizer = "ClientSideExtension.ApplicationCustomizer",
ContextMenu = "ClientSideExtension.ListViewCommandSet.ContextMenu",
CommandBar = "ClientSideExtension.ListViewCommandSet.CommandBar",
ListViewCommandSet = "ClientSideExtension.ListViewCommandSet",
}
export const LocationStrings = {
[ExtensionLocation.ApplicationCustomizer]: "Application Customizer",
[ExtensionLocation.ContextMenu]: "Context Menu",
[ExtensionLocation.CommandBar]: "Command Bar",
[ExtensionLocation.ListViewCommandSet]: "List View Command Set",
}
export const Locations: ExtensionLocation[] = Object.keys(LocationStrings) as ExtensionLocation[];

View File

@ -0,0 +1,67 @@
import { SPFI } from "@pnp/sp";
import { IWeb } from "@pnp/sp/webs";
import { ListType } from "../Models/ListType";
import { CleanExtension, ExtensionSelects, IExtension } from "../Models/Extension";
export interface IAppCatalogProvider {
getExtension(): Promise<IExtension[]>;
getExtensionById(Id: number): Promise<IExtension>;
updateExtension(Id: number, extension: Partial<IExtension>): Promise<void>;
}
export class AppCatalogProvider implements IAppCatalogProvider {
private SP: SPFI = null;
private _appCatalog: IWeb = null;
private _tenantWideExtensionsListId: string = null;
private async getAppCatalog(): Promise<IWeb> {
if (this._appCatalog === null) {
const res = await this.SP.getTenantAppCatalogWeb();
this._appCatalog = res;
}
return this._appCatalog;
}
private async getTenantWideExtensionsListId(): Promise<string> {
if (this._tenantWideExtensionsListId === null) {
const appCatalog = await this.getAppCatalog();
const lists = await appCatalog.lists.filter(`BaseTemplate eq ${ListType.TenantWideExtensions}`).select("ID").top(1)();
this._tenantWideExtensionsListId = lists[0].Id;
}
return this._tenantWideExtensionsListId;
}
constructor(sp: SPFI) {
this.SP = sp;
}
public async getExtension(): Promise<IExtension[]> {
const appCatalog = await this.getAppCatalog();
const LIST_ID = await this.getTenantWideExtensionsListId();
const result: Partial<IExtension[]> = await appCatalog.lists.getById(LIST_ID).items.select(...ExtensionSelects)();
const items: IExtension[] = result.map((item) => CleanExtension(item));
return items;
}
public async getExtensionById(Id: number): Promise<IExtension> {
const appCatalog = await this.getAppCatalog();
const LIST_ID = await this.getTenantWideExtensionsListId();
const result: Partial<IExtension> = await appCatalog.lists.getById(LIST_ID).items.getById(Id).select(...ExtensionSelects)();
const item: IExtension = CleanExtension(result);
return item;
}
public async updateExtension(Id: number, extension: Partial<IExtension>): Promise<void> {
const appCatalog = await this.getAppCatalog();
const LIST_ID = await this.getTenantWideExtensionsListId();
try {
await appCatalog.lists.getById(LIST_ID).items.getById(Id).update(extension);
} catch (error) {
alert(error);
}
}
}

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,24 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "257e3d3e-1470-4a26-b394-2c1087b28cae",
"alias": "TenantWideExtensionManagerWebPart",
"componentType": "WebPart",
"version": "*",
"manifestVersion": 2,
"requiresCustomScript": false,
"supportedHosts": ["SharePointWebPart", "TeamsPersonalApp", "TeamsTab", "SharePointFullPage"],
"supportsThemeVariants": true,
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70",
"group": { "default": "Advanced" },
"title": { "default": "Tenant Wide Extension Manager" },
"description": { "default": "Tenant Wide Extension Manager description" },
"officeFabricIconFontName": "ProductVariant",
"properties": {
"description": "Tenant Wide Extension Manager"
}
}]
}

View File

@ -0,0 +1,44 @@
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 { TenantWideExtensionManager, ITenantWideExtensionManagerProps } from './components/TenantWideExtensionManager';
import { ApplicationContext, IApplicationContext } from '../../Contexsts/ApplicationContext';
import { SPFI, SPFx, spfi } from '@pnp/sp/presets/all';
import { AppCatalogProvider } from '../../Providers/AppCatalogProvider';
export interface ITenantWideExtensionManagerWebPartProps {
}
export default class TenantWideExtensionManagerWebPart extends BaseClientSideWebPart<ITenantWideExtensionManagerWebPartProps> {
public render(): void {
const sp: SPFI = spfi().using(SPFx(this.context))
const element: React.ReactElement<ITenantWideExtensionManagerProps> = React.createElement(TenantWideExtensionManager, {});
const context = React.createElement(ApplicationContext.Provider, {
value: {
context: this.context,
PnPjs: sp,
Provider: new AppCatalogProvider(sp)
} as IApplicationContext
}, element)
ReactDom.render(context, this.domElement);
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: []
};
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -0,0 +1,59 @@
import * as React from 'react';
import useExtension from '../../../Hooks/UseExtension';
import { Icon, Panel, Spinner, SpinnerSize, Text, Toggle, Stack, Dropdown, TextField, PanelType, Label, DialogFooter, PrimaryButton, DefaultButton } from '@fluentui/react';
import { ExtensionLocation, LocationStrings } from '../../../Models/Location';
import { Locations } from '../../../Models/Location';
import { ListType, ListTypeStrings, ListTypes } from '../../../Models/ListType';
import { CodeEditorEditable } from 'react-code-editor-editable'
import 'highlight.js/styles/stackoverflow-light.css';
import { ApplicationContext } from '../../../Contexsts/ApplicationContext';
export interface IExtensionManagerProps {
ExtensionId: number;
OnSubmit: () => void;
OnClose: () => void;
}
export const ExtensionManager: React.FunctionComponent<IExtensionManagerProps> = (props: React.PropsWithChildren<IExtensionManagerProps>) => {
const { Provider } = React.useContext(ApplicationContext);
const { ExtensionId, OnClose, OnSubmit } = props;
const { isLoading, extension, update, changes } = useExtension(ExtensionId);
return (
<Panel
isOpen={ExtensionId !== null}
onDismiss={OnClose}
type={PanelType.medium}
>
{ExtensionId !== null && <>
{isLoading && <Spinner label='Loading...' size={SpinnerSize.large} />}
{!isLoading && <>
<Stack tokens={{ childrenGap: 10 }}>
<span><Icon styles={{ root: { fontSize: "3em" } }} iconName='ProductRelease' /><Text variant='large'>&nbsp;{extension.Title}</Text></span>
<Toggle offText='Disabled' onText='Enabled' checked={!extension.TenantWideExtensionDisabled} onChange={(_, val) => update({ TenantWideExtensionDisabled: !val })} />
<Dropdown label='Location/type' options={Locations.map(loc => ({ key: loc, text: LocationStrings[loc] }))} selectedKey={extension.TenantWideExtensionLocation} onChange={(_, val) => update({ TenantWideExtensionLocation: val.key as ExtensionLocation })} />
<Dropdown label='List type' options={ListTypes.map(listType => ({ key: parseInt(listType+""), text: ListTypeStrings[listType] }))} selectedKey={extension.TenantWideExtensionListTemplate} onChange={(_, val) => update({ TenantWideExtensionListTemplate: val.key as ListType })} />
<div>
<Label>Component properties</Label>
<CodeEditorEditable width='100%' height='20em' language="json" value={extension.TenantWideExtensionComponentProperties} setValue={(value: string) => { update({ TenantWideExtensionComponentProperties: value }) }} />
</div>
<TextField type='number' value={extension.TenantWideExtensionSequence + ""} label='Sequence' onChange={(_, val) => update({ TenantWideExtensionSequence: parseInt(val) })} />
<DialogFooter>
<PrimaryButton onClick={async () => {
await Provider.updateExtension(props.ExtensionId, changes);
OnSubmit();
}} text='Save' />
<DefaultButton onClick={OnClose} text='Close' />
</DialogFooter>
</Stack>
</>}
</>}
</Panel>
);
};

View File

@ -0,0 +1 @@
@import '~@fluentui/react/dist/sass/References.scss';

View File

@ -0,0 +1,52 @@
import * as React from 'react';
import { ApplicationContext } from '../../../Contexsts/ApplicationContext';
import { IExtension } from '../../../Models/Extension';
import { ShimmeredDetailsList, Selection, SelectionMode } from '@fluentui/react';
import { Columns } from '../../../Misc/DetailsListColumns';
import { ExtensionManager } from './ExtensionManger';
//import styles from './TenantWideExtensionManager.module.scss';
export interface ITenantWideExtensionManagerProps { }
export const TenantWideExtensionManager: React.FunctionComponent<ITenantWideExtensionManagerProps> = (props: React.PropsWithChildren<ITenantWideExtensionManagerProps>) => {
const { Provider } = React.useContext(ApplicationContext);
const [apps, setApps] = React.useState<IExtension[]>(null);
const [selectedExtensionId, setSelectedExtensionId] = React.useState<number>(null);
const selection = React.useMemo(() => new Selection({
selectionMode: SelectionMode.single,
onSelectionChanged: () => {
let id = null;
if (selection.getSelection()[0] as IExtension)
id = (selection.getSelection()[0] as IExtension).Id;
setSelectedExtensionId(id);
},
}), []);
const fetchData: () => void = async () => { Provider.getExtension().then((apps) => { setApps(apps); }).catch((error) => { alert(error); }) }
const clearSelection: () => void = () => { selection.setAllSelected(false); setSelectedExtensionId(null); }
React.useEffect(() => {
fetchData();
}, [])
return (
<>
<ExtensionManager
ExtensionId={selectedExtensionId}
OnSubmit={() => { clearSelection(); fetchData(); }}
OnClose={() => clearSelection()} />
<ShimmeredDetailsList
items={apps}
enableShimmer={apps === null}
columns={Columns}
selection={selection}
selectionMode={SelectionMode.single}
selectionPreservedOnEmptyClick={true}
/>
</>
);
};

View File

@ -0,0 +1,5 @@
define([], function() {
return {
}
});

View File

@ -0,0 +1,7 @@
declare interface ITenantWideExtensionManagerWebPartStrings {
}
declare module 'TenantWideExtensionManagerWebPartStrings' {
const strings: ITenantWideExtensionManagerWebPartStrings;
export = strings;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

View File

@ -0,0 +1,36 @@
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-4.5/includes/tsconfig-web.json",
"compilerOptions": {
"target": "es5",
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"jsx": "react",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"outDir": "lib",
"inlineSources": false,
"strictNullChecks": false,
"noImplicitAny": true,
"typeRoots": [
"./node_modules/@types",
"./node_modules/@microsoft"
],
"types": [
"webpack-env"
],
"lib": [
"es5",
"dom",
"es2015.collection",
"es2015.promise"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx"
]
}