Merge pull request #3089 from DonKirkham/to-v1.15.2

fixes https://github.com/pnp/sp-dev-fx-webparts/issues/3053
This commit is contained in:
Hugo Bernier 2022-11-08 14:10:18 -05:00 committed by GitHub
commit 3c4484912e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 48110 additions and 10409 deletions

View File

@ -1,7 +1,7 @@
// For more information on how to run this SPFx project in a VS Code Remote Container, please visit https://aka.ms/spfx-devcontainer
{
"name": "SPFx 1.9.1",
"image": "docker.io/m365pnp/spfx:1.9.1",
"name": "SPFx 1.15.2",
"image": "docker.io/m365pnp/spfx:1.15.0",
// Set *default* container specific settings.json values on container create.
"settings": {},
// Add the IDs of extensions you want installed when the container is created.
@ -36,4 +36,4 @@
},
"postCreateCommand": "bash .devcontainer/spfx-startup.sh",
"remoteUser": "node"
}
}

View File

@ -7,9 +7,11 @@ echo
echo -e "\e[1;94mGenerating dev certificate\e[0m"
gulp trust-dev-cert
# Convert the generated PEM certificate to a CER certificate
openssl x509 -inform PEM -in ~/.rushstack/rushstack-serve.pem -outform DER -out ./spfx-dev-cert.cer
cp ~/.gcb-serve-data/gcb-serve.cer ./spfx-dev-cert.cer
cp ~/.gcb-serve-data/gcb-serve.cer ./spfx-dev-cert.pem
# Copy the PEM ecrtificate for non-Windows hosts
cp ~/.rushstack/rushstack-serve.pem ./spfx-dev-cert.pem
## add *.cer to .gitignore to prevent certificates from being saved in repo
if ! grep -Fxq '*.cer' ./.gitignore
@ -28,4 +30,4 @@ fi
echo
echo -e "\e[1;92mReady!\e[0m"
echo -e "\n\e[1;94m**********\nOptional: if you plan on using gulp serve, don't forget to add the container certificate to your local machine. Please visit https://aka.ms/spfx-devcontainer for more information\n**********"
echo -e "\n\e[1;94m**********\nOptional: if you plan on using gulp serve, don't forget to add the container certificate to your local machine. Please visit https://aka.ms/spfx-devcontainer for more information\n**********"

View File

@ -0,0 +1,378 @@
/* eslint-disable no-undef */
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": [
0,
{
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": 0,
// 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": 2,
// 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/no-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": 0,
// 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: {
"no-new": 0,
"class-name": 0,
"export-name": 0,
forin: 0,
"label-position": 0,
"member-access": 2,
"no-arg": 0,
"no-console": 0,
"no-construct": 0,
"no-duplicate-variable": 2,
"no-eval": 0,
"no-function-expression": 2,
"no-internal-module": 2,
"no-shadowed-variable": 2,
"no-switch-case-fall-through": 2,
"no-unnecessary-semicolons": 2,
"no-unused-expression": 2,
"no-with-statement": 2,
semicolon: 2,
"trailing-comma": 0,
typedef: 0,
"typedef-whitespace": 0,
"use-named-parameter": 2,
"variable-name": 0,
whitespace: 0,
},
},
],
};

View File

@ -11,6 +11,8 @@ dist
lib
solution
temp
.heft
release
*.sppkg
# Coverage directory used by tools like istanbul

View File

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

View File

@ -2,11 +2,11 @@
"@microsoft/generator-sharepoint": {
"isCreatingSolution": false,
"environment": "spo",
"version": "1.9.1",
"version": "1.15.2",
"libraryName": "react-add-js-css-ref",
"libraryId": "d9c30e1a-bf06-46fa-807d-ce5182d9c91c",
"packageManager": "npm",
"isDomainIsolated": false,
"componentType": "webpart"
}
}
}

View File

@ -41,8 +41,8 @@ Path can be `/sites/mysc/style library/js/custom.js` or `/sites/mysc/style libra
## Compatibility
![SPFx 1.9.1](https://img.shields.io/badge/SPFx-1.9.1-green.svg)
![Node.js v10 | v8](https://img.shields.io/badge/Node.js-v10%20%7C%20v8-green.svg)
![SPFx 1.15.2](https://img.shields.io/badge/SPFx-1.15.2-green.svg)
![Node.js v16 | v14 | v12](https://img.shields.io/badge/Node.js-v16%20%7C%20v14%20%7C%20v12-green.svg)
![Compatible with SharePoint Online](https://img.shields.io/badge/SharePoint%20Online-Compatible-green.svg)
![Does not work with SharePoint 2019](https://img.shields.io/badge/SharePoint%20Server%202019-Incompatible-red.svg "SharePoint Server 2019 requires SPFx 1.4.1 or lower")
![Does not work with SharePoint 2016 (Feature Pack 2)](https://img.shields.io/badge/SharePoint%20Server%202016%20(Feature%20Pack%202)-Incompatible-red.svg "SharePoint Server 2016 Feature Pack 2 requires SPFx 1.1")
@ -105,7 +105,7 @@ gulp package-solution --ship
Solution|Author(s)
--------|---------
react-add-js-css-ref | [Siddharth Vaghasia](https://github.com/siddharth-vaghasia) (https://www.linkedin.com/in/siddharthvaghasia/)
react-add-js-css-ref | [Siddharth Vaghasia](https://github.com/siddharth-vaghasia) (https://www.linkedin.com/in/siddharthvaghasia/) [Don Kirkham](https://github.com/donkirkham) (https://www.linkedin.com/in/donkirkham/)
## Version history
@ -113,6 +113,7 @@ Version|Date|Comments
-------|----|--------
1.0.0|Apr 24, 2020|Initial release
2.0.0|June 09, 2020|Displaying access denied message, added spinner to display on page load, fix edit, delete icons not displaying.
2.1.0|Oct 20, 2022|Upgrade solution to SPFx v1.15.2 and PnPJs 3.8.0
## Video

View File

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

View File

@ -3,15 +3,33 @@
"solution": {
"name": "react-add-js-css-ref-client-side-solution",
"id": "d9c30e1a-bf06-46fa-807d-ce5182d9c91c",
"version": "1.0.0.0",
"version": "2.1.0",
"includeClientSideAssets": true,
"isDomainIsolated": false,
"developer": {
"name": "",
"privacyUrl": "",
"termsOfUseUrl": "",
"websiteUrl": "",
"mpnId": "Undefined-1.14.0"
},
"metadata": {
"shortDescription": {
"default": "react-add-js-css-ref description"
},
"longDescription": {
"default": "react-add-js-css-ref description"
},
"screenshotPaths": [],
"videoUrl": "",
"categories": []
},
"features": [
{
"title": "Application Extension - Deployment of custom action.",
"description": "Deploys a custom action with ClientSideComponentId association",
"id": "201c7969-a60d-492a-83d2-db3088515c51",
"version": "1.0.0.0",
"version": "3.0.0.0",
"assets": {
"elementManifests": [
"elements.xml",

View File

@ -1,10 +1,10 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json",
"port": 4321,
"https": true,
"serveConfigurations": {
"default": {
"pageUrl": "https://contoso.sharepoint.com/sites/mysc/_layouts/15/viewlsts.aspx",
"pageUrl": "https://enter-your-SharePoint-site/_layouts/workbench.aspx",
"customActions": {
"38afa8d7-b498-4529-9f99-6279392f9309": {
"location": "ClientSideExtension.ApplicationCustomizer",
@ -15,7 +15,7 @@
}
},
"referenceInjector": {
"pageUrl": "https://contoso.sharepoint.com/sites/mysc/_layouts/15/viewlsts.aspx",
"pageUrl": "https://enter-your-SharePoint-site/_layouts/15/viewlsts.aspx",
"customActions": {
"38afa8d7-b498-4529-9f99-6279392f9309": {
"location": "ClientSideExtension.ApplicationCustomizer",
@ -25,10 +25,5 @@
}
}
}
},
"initialPage": "https://localhost:5432/workbench",
"api": {
"port": 5432,
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
}
}

View File

@ -5,4 +5,13 @@ const build = require('@microsoft/sp-build-web');
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
build.addSuppression(`Warning - [sass] The local CSS class 'ms-DetailsList' 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(gulp);

File diff suppressed because it is too large Load Diff

View File

@ -3,42 +3,46 @@
"version": "0.0.1",
"private": true,
"main": "lib/index.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@microsoft/decorators": "1.9.1",
"@microsoft/sp-application-base": "1.9.1",
"@microsoft/sp-core-library": "1.9.1",
"@microsoft/sp-dialog": "1.9.1",
"@microsoft/sp-lodash-subset": "1.9.1",
"@microsoft/sp-office-ui-fabric-core": "1.9.1",
"@microsoft/sp-webpart-base": "1.9.1",
"@pnp/sp": "^2.0.3",
"@microsoft/decorators": "1.15.2",
"@microsoft/sp-adaptive-card-extension-base": "1.15.2",
"@microsoft/sp-application-base": "1.15.2",
"@microsoft/sp-core-library": "1.15.2",
"@microsoft/sp-dialog": "1.15.2",
"@microsoft/sp-lodash-subset": "1.15.2",
"@microsoft/sp-office-ui-fabric-core": "1.15.2",
"@microsoft/sp-property-pane": "1.15.2",
"@microsoft/sp-webpart-base": "1.15.2",
"@pnp/sp": "3.8.0",
"@pnp/spfx-controls-react": "1.16.0",
"@types/es6-promise": "0.0.33",
"@types/react": "16.8.8",
"@types/react-dom": "16.8.3",
"@types/webpack-env": "1.13.1",
"office-ui-fabric-react": "6.189.2",
"react": "16.8.5",
"react-dom": "16.8.5"
"office-ui-fabric-react": "7.185.7",
"react": "16.13.1",
"react-dom": "16.13.1",
"tslib": "2.3.1"
},
"devDependencies": {
"@microsoft/sp-build-web": "1.9.1",
"@microsoft/sp-tslint-rules": "1.9.1",
"@microsoft/sp-module-interfaces": "1.9.1",
"@microsoft/sp-webpart-workbench": "1.9.1",
"@microsoft/eslint-config-spfx": "1.15.2",
"@microsoft/eslint-plugin-spfx": "1.15.2",
"@microsoft/rush-stack-compiler-2.9": "0.7.16",
"gulp": "~3.9.1",
"@types/chai": "3.4.34",
"@types/mocha": "2.2.38",
"ajv": "~5.2.2"
"@microsoft/rush-stack-compiler-3.9": "0.4.47",
"@microsoft/rush-stack-compiler-4.5": "0.2.2",
"@microsoft/sp-build-web": "1.15.2",
"@microsoft/sp-module-interfaces": "1.15.2",
"@rushstack/eslint-config": "2.5.1",
"@types/es6-promise": "0.0.33",
"@types/react": "16.9.51",
"@types/react-dom": "16.9.8",
"@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"
},
"resolutions": {
"@types/react": "16.8.8"

View File

@ -3,11 +3,12 @@ import { Log } from '@microsoft/sp-core-library';
import {
BaseApplicationCustomizer
} from '@microsoft/sp-application-base';
import { Dialog } from '@microsoft/sp-dialog';
//import { Dialog } from '@microsoft/sp-dialog';
import * as strings from 'ReferenceInjectorApplicationCustomizerStrings';
import { IJsCssItem } from '../../models/IJsCssItem';
const LOG_SOURCE: string = 'ReferenceInjectorApplicationCustomizer';
const LOG_SOURCE = 'ReferenceInjectorApplicationCustomizer';
/**
* If your command set uses the ClientSideComponentProperties JSON input,
@ -15,9 +16,8 @@ const LOG_SOURCE: string = 'ReferenceInjectorApplicationCustomizer';
* You can define an interface to describe it.
*/
export interface IReferenceInjectorApplicationCustomizerProperties {
// This is an example; replace with your own property
jsfiles:any[];
cssfiles:any[];
jsfiles: IJsCssItem[];
cssfiles: IJsCssItem[];
}
/** A Custom Action which can be run during execution of a Client Side Application */
@ -31,25 +31,25 @@ export default class ReferenceInjectorApplicationCustomizer
if(this.properties.jsfiles)
{
this.properties.jsfiles.forEach(element => {
let JsTag: HTMLScriptElement = document.createElement("script");
const JsTag: HTMLScriptElement = document.createElement("script");
JsTag.src = element.FilePath;
JsTag.type = "text/javascript";
document.body.appendChild(JsTag);
document.body.appendChild(JsTag);
});
}
if(this.properties.cssfiles){
this.properties.cssfiles.forEach(element => {
let cssLink: HTMLLinkElement = document.createElement("link");
const cssLink: HTMLLinkElement = document.createElement("link");
cssLink.href = element.FilePath;
cssLink.type = "text/css";
cssLink.rel = "stylesheet";
document.body.appendChild(cssLink);
});
}
return Promise.resolve();
}

View File

@ -0,0 +1,4 @@
export interface IJsCssItem {
FilePath: string;
Type: string;
}

View File

@ -1,34 +1,32 @@
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import * as strings from 'AddJsCssReferenceWebPartStrings';
import AddJsCssReference from './components/AddJsCssReference';
import { IAddJsCssReferenceProps } from './components/IAddJsCssReferenceProps';
import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base";
import { IPropertyPaneConfiguration } from "@microsoft/sp-property-pane";
import AddJsCssReference, { IAddJsCssReferenceProps } from './components/AddJsCssReference';
import { getSP } from './pnpjsConfig';
export interface IAddJsCssReferenceWebPartProps {
description: string;
}
export default class AddJsCssReferenceWebPart extends BaseClientSideWebPart<IAddJsCssReferenceWebPartProps> {
public render(): void {
const element: React.ReactElement<IAddJsCssReferenceProps > = React.createElement(
const element: React.ReactElement<IAddJsCssReferenceProps> = React.createElement(
AddJsCssReference,
{
description: this.properties.description,
context:this.context
context: this.context
}
);
ReactDom.render(element, this.domElement);
}
protected onInit(): Promise<void> {
getSP(this.context);
return super.onInit();
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
@ -42,16 +40,12 @@ export default class AddJsCssReferenceWebPart extends BaseClientSideWebPart<IAdd
pages: [
{
header: {
description: strings.PropertyPaneDescription
description: ""
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
groupName: "No properties available",
groupFields: []
}
]
}

View File

@ -1,23 +1,26 @@
import * as React from 'react';
import styles from './AddJsCssReference.module.scss';
import { IAddJsCssReferenceProps } from './IAddJsCssReferenceProps';
import { escape } from '@microsoft/sp-lodash-subset';
import { TextField, MaskedTextField } from 'office-ui-fabric-react/lib/TextField';
import { ListView, IViewField, SelectionMode} from "@pnp/spfx-controls-react/lib/ListView";
import {MessageBarType,Link,Separator, CommandBarButton,IStackStyles,Text,MessageBar,PrimaryButton,DefaultButton,Dialog,DialogFooter,DialogType,Stack, IStackTokens, updateA, Icon, Spinner } from 'office-ui-fabric-react';
import { sp} from "@pnp/sp";
import { TextField } from 'office-ui-fabric-react/lib/TextField';
import { ListView } from "@pnp/spfx-controls-react/lib/ListView";
import { MessageBarType, Link, Separator, CommandBarButton, IStackStyles, Text, MessageBar, PrimaryButton, DefaultButton, Dialog, DialogFooter, DialogType, Stack, IStackTokens, Icon, Spinner } from 'office-ui-fabric-react';
import { SPFI } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/user-custom-actions";
import "@pnp/sp/presets/all";
import {TypedHash} from "@pnp/common";
import { IUserCustomActionAddResult,IUserCustomActionUpdateResult,IUserCustomAction } from '@pnp/sp/user-custom-actions';
import "@pnp/sp/user-custom-actions";
import "@pnp/sp/presets/all";
import {
IUserCustomActionAddResult, IUserCustomActionUpdateResult
} from '@pnp/sp/user-custom-actions';
import { createTheme, ITheme } from 'office-ui-fabric-react/lib/Styling';
import { mergeStyleSets } from 'office-ui-fabric-react/lib/Styling';
//import { mergeStyleSets } from 'office-ui-fabric-react/lib/Styling';
import { PermissionKind } from '@pnp/sp/presets/all';
//import { render } from 'react-dom';
import { getSP } from '../pnpjsConfig';
import { IJsCssItem } from '../../../models/IJsCssItem';
import { WebPartContext } from '@microsoft/sp-webpart-base';
const stackTokens: IStackTokens = { childrenGap: 40 };
const CustomActionTitle = 'JSCssAppCustomizer';
const CustomActionTitle = 'JSCssAppCustomizer';
const ApplicationCustomizerComponentID = '38afa8d7-b498-4529-9f99-6279392f9309';
const description = 'This user action is of type application customizer to custom js and css file references via SFPx extension';
const theme: ITheme = createTheme({
@ -31,56 +34,60 @@ const theme: ITheme = createTheme({
const stackStyles: Partial<IStackStyles> = { root: { height: 30 } };
export interface IAddJsCssReferenceProps {
context: WebPartContext;
}
export interface IAddJsCssReferenceState {
disableRegisterButton: boolean;
disableRemoveButton: boolean;
jsfiles:any[];
cssfiles:any[];
currentjsRef:string;
currentcssRef:string;
hideJSDailog:boolean;
hideCSSDailog:boolean;
currentCustomAction:any;
isEdit:boolean;
editIndex:number;
showMesssage:boolean;
successmessage:string;
userHasPermission:boolean;
showspinner:boolean;
jsfiles: IJsCssItem[];
cssfiles: IJsCssItem[];
currentjsRef: string;
currentcssRef: string;
hideJSDailog: boolean;
hideCSSDailog: boolean;
currentCustomAction: any;
isEdit: boolean;
editIndex: number;
showMesssage: boolean;
successmessage: string;
userHasPermission: boolean;
showspinner: boolean;
}
export default class AddJsCssReference extends React.Component<IAddJsCssReferenceProps, IAddJsCssReferenceState> {
private _sp: SPFI;
private viewFields: any[] = [
{
name: "Type",
displayName: "Action",
minWidth: 60,
maxWidth:60,
render: (item,index) =>{
console.log(item);
return (
<React.Fragment>
<Stack horizontal tokens={{childrenGap:20}}>
<Icon iconName="Edit" className={"ms-IconExample" + styles.customicons} onClick={()=> this.editClicked(item,index)} />
<Icon iconName="Delete" className={"ms-IconExample" + styles.customicons} onClick={()=> this.deleteClicked(item,index)} />
{/* <i className={"ms-Icon ms-Icon--Edit " + styles.customicons} onClick={()=> this.editClicked(item,index)} aria-hidden="true"></i>
maxWidth: 60,
render: (item, index) => {
console.log(item);
return (
<React.Fragment>
<Stack horizontal tokens={{ childrenGap: 20 }}>
<Icon iconName="Edit" className={"ms-IconExample" + styles.customicons} onClick={() => this.editClicked(item, index)} />
<Icon iconName="Delete" className={"ms-IconExample" + styles.customicons} onClick={() => this.deleteClicked(item, index)} />
{/* <i className={"ms-Icon ms-Icon--Edit " + styles.customicons} onClick={()=> this.editClicked(item,index)} aria-hidden="true"></i>
<i className={"ms-Icon ms-Icon--Delete " + styles.customicons} onClick={()=> this.deleteClicked(item,index)} aria-hidden="true"></i> */}
</Stack>
</React.Fragment>
);
</React.Fragment>
);
},
className:"test"
className: "test"
},
{
name: "FilePath",
displayName: "FilePath",
minWidth:600,
render: (item,index) =>{
minWidth: 600,
render: (item, index) => {
console.log(item);
return (
<React.Fragment>
@ -89,106 +96,100 @@ export default class AddJsCssReference extends React.Component<IAddJsCssReferenc
</span>
</React.Fragment>
);
}
}
// maxWidth:800
}
];
constructor(props: IAddJsCssReferenceProps,state:IAddJsCssReferenceProps) {
constructor(props: IAddJsCssReferenceProps, state: IAddJsCssReferenceProps) {
super(props);
this.state = {
disableRegisterButton:false,
disableRemoveButton:false,
jsfiles:[],
cssfiles:[],
currentjsRef:"",
currentcssRef:"",
hideJSDailog:true,
hideCSSDailog:true,
currentCustomAction:null,
isEdit:false,
editIndex:-1,
showMesssage:false,
successmessage:"",
userHasPermission:false,
showspinner:true
this._sp = getSP();
this.state = {
disableRegisterButton: false,
disableRemoveButton: false,
jsfiles: [],
cssfiles: [],
currentjsRef: "",
currentcssRef: "",
hideJSDailog: true,
hideCSSDailog: true,
currentCustomAction: null,
isEdit: false,
editIndex: -1,
showMesssage: false,
successmessage: "",
userHasPermission: false,
showspinner: true
};
sp.setup(this.props.context);
}
}
public render(): React.ReactElement<IAddJsCssReferenceProps> {
return (
<React.Fragment>
<React.Fragment >
{this.state.showspinner &&
<Spinner label="Please wait..." ariaLive="assertive" labelPosition="top" />
}
{
this.state.showspinner &&
<Spinner label="Please wait..." ariaLive="assertive" labelPosition="top" />
}
{this.state.userHasPermission &&
<div className={styles.addJsCssReference}>
<div className={ styles.container }>
<div className={ styles.row }>
<div className={ styles.column }>
<span className={ styles.title }>SPFx JS CSS References WebPart</span>
<p className={ styles.subTitle }>This webpart can be used to add reference to custom js files and css files via SPFx extension application customizer.</p>
</div>
<div className={ styles.row }>
<div className={ styles.column }>
{this.state.showMesssage &&
<MessageBar dismissButtonAriaLabel="Close" onDismiss={()=>{ this.setState({showMesssage:false});}} messageBarType={MessageBarType.success}>
{this.state.successmessage}
</MessageBar>
}
{
this.state.userHasPermission &&
<div className={styles.addJsCssReference}>
<div className={styles.container}>
<div className={styles.row}>
<div className={styles.column}>
<span className={styles.title}>SPFx JS CSS References WebPart</span>
<p className={styles.subTitle}>This webpart can be used to add reference to custom js files and css files via SPFx extension application customizer.</p>
{this.state.currentCustomAction && this.state.showMesssage != true &&
<MessageBar >
We found you already have some custom js and css files references added via this customizer. Feel free to Edit or Remove references.
</MessageBar>
}
<div id="jsfiles">
<Separator></Separator>
<Stack horizontal styles={stackStyles} tokens={stackTokens}>
<Text theme={theme}>Javascript Files</Text>
<CommandBarButton iconProps={{iconName: 'Add'}} text="Add JS Link" onClick={()=>this.openAddJSDailog()} />
</Stack>
<Separator></Separator>
{/* <PrimaryButton text="Add New Item" } /> */}
</div>
<div className={styles.row}>
<div className={styles.column}>
{this.state.showMesssage &&
<MessageBar dismissButtonAriaLabel="Close" onDismiss={() => { this.setState({ showMesssage: false }); }} messageBarType={MessageBarType.success}>
{this.state.successmessage}
</MessageBar>
}
{this.state.jsfiles.length === 0 &&
<React.Fragment>
<MessageBar>
No References Found.
<Link href="#" onClick={()=>this.openAddJSDailog()}>
Click here
</Link>
<Text> to add new.</Text>
</MessageBar>
<br/>
</React.Fragment>
}
{this.state.currentCustomAction && this.state.showMesssage !== true &&
<MessageBar >
We found you already have some custom js and css files references added via this customizer. Feel free to Edit or Remove references.
</MessageBar>
}
{this.state.jsfiles.length >0 &&
<ListView
items={this.state.jsfiles}
viewFields={this.viewFields}
/>
}
<Dialog
minWidth={600}
maxWidth={900}
<div id="jsfiles">
<Separator />
<Stack horizontal styles={stackStyles} tokens={stackTokens}>
<Text theme={theme}>Javascript Files</Text>
<CommandBarButton iconProps={{ iconName: 'Add' }} text="Add JS Link" onClick={() => this.openAddJSDailog()} />
</Stack>
<Separator />
{/* <PrimaryButton text="Add New Item" } /> */}
{this.state.jsfiles.length === 0 &&
<React.Fragment>
<MessageBar>
No References Found.
<Link href="#" onClick={() => this.openAddJSDailog()}>
Click here
</Link>
<Text> to add new.</Text>
</MessageBar>
<br />
</React.Fragment>
}
{this.state.jsfiles.length > 0 &&
<ListView
items={this.state.jsfiles}
viewFields={this.viewFields}
/>
}
<Dialog
minWidth={600}
maxWidth={900}
hidden={this.state.hideJSDailog}
onDismiss={this._closeJSDialog}
dialogContentProps={{
@ -202,48 +203,48 @@ export default class AddJsCssReference extends React.Component<IAddJsCssReferenc
}}
>
<TextField required onChange={evt => this.updateJSValue(evt)} value={this.state.currentjsRef} label="URL" resizable={false} />
<TextField required onChange={evt => this.updateJSValue(evt)} value={this.state.currentjsRef} label="URL" resizable={false} />
<DialogFooter>
<PrimaryButton onClick={()=>this._addJsReference()} text="Add" />
<PrimaryButton onClick={() => this._addJsReference()} text="Add" />
<DefaultButton onClick={this._closeJSDialog} text="Cancel" />
</DialogFooter>
</Dialog>
</div>
<div id="cssfiles">
<br/>
<Stack horizontal styles={stackStyles} tokens={stackTokens}>
<Text theme={theme}>CSS Files</Text>
<CommandBarButton iconProps={{iconName: 'Add'}} text="Add CSS Link" onClick={()=>this.openAddCSSDailog()} />
</Stack>
{/* <PrimaryButton text="Add New Item" onClick={()=>this.openAddCSSDailog()} /> */}
<Separator></Separator>
{this.state.cssfiles.length === 0 &&
<React.Fragment>
<MessageBar>
No References Found.
<Link href="#" onClick={()=>this.openAddCSSDailog()}>
Click here
</Link>
<Text> to add new.</Text>
</MessageBar>
<br/>
</React.Fragment>
}
{this.state.cssfiles.length > 0 &&
<ListView
items={this.state.cssfiles}
viewFields={this.viewFields}
// iconFieldName="ServerRelativeUrl"
// selectionMode={SelectionMode.multiple}
// selection={this._getSelection}
/>
}
<Dialog
minWidth={600}
maxWidth={900}
</div>
<div id="cssfiles">
<br />
<Stack horizontal styles={stackStyles} tokens={stackTokens}>
<Text theme={theme}>CSS Files</Text>
<CommandBarButton iconProps={{ iconName: 'Add' }} text="Add CSS Link" onClick={() => this.openAddCSSDailog()} />
</Stack>
{/* <PrimaryButton text="Add New Item" onClick={()=>this.openAddCSSDailog()} /> */}
<Separator />
{this.state.cssfiles.length === 0 &&
<>
<MessageBar>
No References Found.
<Link href="#" onClick={() => this.openAddCSSDailog()}>
Click here
</Link>
<Text> to add new.</Text>
</MessageBar>
<br />
</>
}
{this.state.cssfiles.length > 0 &&
<ListView
items={this.state.cssfiles}
viewFields={this.viewFields}
// iconFieldName="ServerRelativeUrl"
// selectionMode={SelectionMode.multiple}
// selection={this._getSelection}
/>
}
<Dialog
minWidth={600}
maxWidth={900}
hidden={this.state.hideCSSDailog}
onDismiss={this._closeCSSDialog}
dialogContentProps={{
@ -257,189 +258,190 @@ export default class AddJsCssReference extends React.Component<IAddJsCssReferenc
}}
>
<TextField required onChange={evt => this.updateCSSValue(evt)} value={this.state.currentcssRef} label="URL" />
<TextField required onChange={evt => this.updateCSSValue(evt)} value={this.state.currentcssRef} label="URL" />
<DialogFooter>
<PrimaryButton onClick={()=>this._addCSSReference()} text="Add" />
<PrimaryButton onClick={() => this._addCSSReference()} text="Add" />
<DefaultButton onClick={this._closeCSSDialog} text="Cancel" />
</DialogFooter>
</Dialog>
</div>
</div>
<br/>
<Stack horizontal tokens={stackTokens}>
<PrimaryButton text="Activate" onClick={()=>this._registerClicked()} disabled={(this.state.jsfiles.length>0 || this.state.cssfiles.length>0 )?false:true} />
<DefaultButton text="Deactivate" onClick={()=> this._removeClicked()} disabled={this.state.currentCustomAction==null?true:false} />
</Stack>
<br />
<Stack horizontal tokens={stackTokens}>
<PrimaryButton text="Activate" onClick={() => this._registerClicked()} disabled={(this.state.jsfiles.length > 0 || this.state.cssfiles.length > 0) ? false : true} />
<DefaultButton text="Deactivate" onClick={() => this._removeClicked()} disabled={this.state.currentCustomAction === null ? true : false} />
</Stack>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
</div>
</div>
}
{!this.state.userHasPermission && !this.state.showspinner &&
<MessageBar messageBarType={MessageBarType.severeWarning}>
Access denied, you do not have permission to access this section. Please connect with your site admins.
</MessageBar>
}
}
{
!this.state.userHasPermission && !this.state.showspinner &&
<MessageBar messageBarType={MessageBarType.severeWarning}>
Access denied, you do not have permission to access this section. Please connect with your site admins.
</MessageBar>
}
</React.Fragment>
</React.Fragment >
);
}
public componentDidMount() {
this.checkPermisson();
void this.checkPermisson();
}
private async checkPermisson(){
const perms2 = await sp.web.currentUserHasPermissions(PermissionKind.ManageWeb);
this.setState({userHasPermission:perms2});
private async checkPermisson() {
const perms2 = await this._sp.web.currentUserHasPermissions(PermissionKind.ManageWeb);
console.log(perms2);
var temp = true;
this.setState({showspinner:false});
if(perms2){
this.getCustomAction();
this.setState({
userHasPermission: perms2,
showspinner: false
});
if (perms2) {
void this.getCustomAction();
}
}
private _registerClicked(): void {
this.setCustomAction();
private async _registerClicked() {
await this.setCustomAction();
}
private _removeClicked(): void {
const uca = sp.web.userCustomActions.getById(this.state.currentCustomAction.Id);
private _removeClicked(): void {
const uca = this._sp.web.userCustomActions.getById(this.state.currentCustomAction.Id);
const response = uca.delete();
console.log("removed custom action");
console.log(response);
this.setState({currentCustomAction:null,jsfiles:[],cssfiles:[],
showMesssage:true,successmessage:"Application Customizer deactivated sucessfully."});
this.setState({
currentCustomAction: null, jsfiles: [], cssfiles: [],
showMesssage: true, successmessage: "Application Customizer deactivated sucessfully."
});
}
private updateJSValue(evt) {
private updateJSValue(evt): void {
this.setState({
currentjsRef: evt.target.value
});
}
private updateCSSValue(evt) {
private updateCSSValue(evt): void {
this.setState({
currentcssRef: evt.target.value
});
}
private editClicked (item,index){
private editClicked(item: IJsCssItem, index: number): void {
if(item.Type == "js") {
this.setState({hideJSDailog:false,
currentjsRef:item.FilePath,
isEdit:true,
editIndex:index
});
}
if(item.Type == "css") {
this.setState({hideCSSDailog:false,
currentcssRef:item.FilePath,
isEdit:true,
editIndex:index
if (item.Type === "js") {
this.setState({
hideJSDailog: false,
currentjsRef: item.FilePath,
isEdit: true,
editIndex: index
});
}
}
private deleteClicked (item,index){
if(item.Type == "css") {
let currentitems = this.state.cssfiles.map((x) => x);
currentitems.splice(index,1);
this.setState({cssfiles:currentitems});
}
else if(item.Type == "js"){
let currentitems = this.state.jsfiles.map((x) => x);
currentitems.splice(index,1);
this.setState({jsfiles:currentitems});
if (item.Type === "css") {
this.setState({
hideCSSDailog: false,
currentcssRef: item.FilePath,
isEdit: true,
editIndex: index
});
}
}
private openAddJSDailog (){
this.setState({hideJSDailog:false});
private deleteClicked(item: IJsCssItem, index: number): void {
if (item.Type === "css") {
const currentitems = this.state.cssfiles.map((x) => x);
currentitems.splice(index, 1);
this.setState({ cssfiles: currentitems });
}
else if (item.Type === "js") {
const currentitems = this.state.jsfiles.map((x) => x);
currentitems.splice(index, 1);
this.setState({ jsfiles: currentitems });
}
}
private openAddCSSDailog (){
this.setState({hideCSSDailog:false});
private openAddJSDailog() {
this.setState({ hideJSDailog: false });
}
private _addJsReference (){
if(!this.state.isEdit){
var item = {
FilePath:this.state.currentjsRef,
private openAddCSSDailog() {
this.setState({ hideCSSDailog: false });
}
private _addJsReference() {
if (!this.state.isEdit) {
const item: IJsCssItem = {
FilePath: this.state.currentjsRef,
Type: "js"
};
let currentitems = this.state.jsfiles.map((x) => x);
const currentitems: IJsCssItem[] = this.state.jsfiles.map((x) => x);
currentitems.push(item);
currentitems[this.state.jsfiles.length] = item;
this.setState({jsfiles:currentitems,
hideJSDailog:true,currentjsRef:""});
this.setState({
jsfiles: currentitems,
hideJSDailog: true, currentjsRef: ""
});
}
else{
item = {
FilePath:this.state.currentjsRef,
else {
const item: IJsCssItem = {
FilePath: this.state.currentjsRef,
Type: "js"
};
let currentitems = this.state.jsfiles.map((x) => x);
const currentitems: IJsCssItem[] = this.state.jsfiles.map((x) => x);
currentitems[this.state.editIndex] = item;
this.setState({jsfiles:currentitems,
hideJSDailog:true,currentjsRef:"",
isEdit:false,editIndex:-1});
this.setState({
jsfiles: currentitems,
hideJSDailog: true, currentjsRef: "",
isEdit: false, editIndex: -1
});
}
}
private _addCSSReference (){
if(!this.state.isEdit){
console.log("add item to grid");
var item = {
FilePath:this.state.currentcssRef,
Type:"css"
};
let currentitems = this.state.cssfiles.map((x) => x);
currentitems.push(item);
currentitems[this.state.cssfiles.length] = item;
this.setState({cssfiles:currentitems,
hideCSSDailog:true,
currentcssRef:""});
}
else{
private _addCSSReference() {
if (!this.state.isEdit) {
console.log("add item to grid");
item = {
FilePath:this.state.currentcssRef,
Type:"css"
const item = {
FilePath: this.state.currentcssRef,
Type: "css"
};
let currentitems = this.state.cssfiles.map((x) => x);
currentitems[this.state.editIndex] = item;
this.setState({cssfiles:currentitems,
hideCSSDailog:true,
currentcssRef:"",
editIndex:-1,isEdit:false});
const currentitems: IJsCssItem[] = this.state.cssfiles.map((x) => x);
currentitems.push(item);
currentitems[this.state.cssfiles.length] = item;
this.setState({
cssfiles: currentitems,
hideCSSDailog: true,
currentcssRef: ""
});
}
else {
console.log("add item to grid");
const item: IJsCssItem = {
FilePath: this.state.currentcssRef,
Type: "css"
};
const currentitems: IJsCssItem[] = this.state.cssfiles.map((x) => x);
currentitems[this.state.editIndex] = item;
this.setState({
cssfiles: currentitems,
hideCSSDailog: true,
currentcssRef: "",
editIndex: -1, isEdit: false
});
}
}
private _closeJSDialog = (): void => {
this.setState({ hideJSDailog: true });
}
@ -447,56 +449,47 @@ export default class AddJsCssReference extends React.Component<IAddJsCssReferenc
this.setState({ hideCSSDailog: true });
}
private async getCustomAction(){
var web = await sp.web.get();
console.log(web);
var customactions:any = await sp.web.userCustomActions.get();
private async getCustomAction(): Promise<void> {
const customactions: any = await this._sp.web.userCustomActions();
console.log(customactions);
var found = customactions.filter(item => item.Title == CustomActionTitle);
const found = customactions.filter(item => item.Title === CustomActionTitle);
if (found.length > 0) {
this.setState({currentCustomAction:found[0]});
var jsonproperties = found[0].ClientSideComponentProperties;
this.setState({ currentCustomAction: found[0] });
const jsonproperties = found[0].ClientSideComponentProperties;
var jsfileArray = JSON.parse(jsonproperties).jsfiles;
var cssfileArray = JSON.parse(jsonproperties).cssfiles;
const jsfileArray = JSON.parse(jsonproperties).jsfiles;
const cssfileArray = JSON.parse(jsonproperties).cssfiles;
console.log(jsfileArray);
console.log(cssfileArray);
this.setState({jsfiles:jsfileArray,cssfiles:cssfileArray});
this.setState({ jsfiles: jsfileArray, cssfiles: cssfileArray });
}
}
protected async setCustomAction() {
protected async setCustomAction(): Promise<void> {
try {
const payload: TypedHash<string> = {
"Title": CustomActionTitle,
"Description": description,
"Location": 'ClientSideExtension.ApplicationCustomizer',
ClientSideComponentId:ApplicationCustomizerComponentID,
ClientSideComponentProperties: JSON.stringify({jsfiles:this.state.jsfiles,cssfiles:this.state.cssfiles }),
};
const payload: object = {
"Title": CustomActionTitle,
"Description": description,
"Location": 'ClientSideExtension.ApplicationCustomizer',
ClientSideComponentId: ApplicationCustomizerComponentID,
ClientSideComponentProperties: JSON.stringify({ jsfiles: this.state.jsfiles, cssfiles: this.state.cssfiles }),
};
if(this.state.currentCustomAction == null) {
const response : IUserCustomActionAddResult = await sp.web.userCustomActions.add(payload);
if (this.state.currentCustomAction === null) {
const response: IUserCustomActionAddResult = await this._sp.web.userCustomActions.add(payload);
console.log(response);
const uca = await sp.web.userCustomActions.getById(response.data.Id);
this.setState({currentCustomAction: uca,showMesssage:true,successmessage:"Application customizer activated sucessfully."});
}
else{
const uca = sp.web.userCustomActions.getById(this.state.currentCustomAction.Id);
const response: IUserCustomActionUpdateResult =await uca.update(payload);
const ucaupdated = await sp.web.userCustomActions.getById(response.data.Id);
this.setState({currentCustomAction: ucaupdated,showMesssage:true,successmessage:"Application customizer updated sucessfully."});
}
const uca = await this._sp.web.userCustomActions.getById(response.data.Id);
this.setState({ currentCustomAction: uca, showMesssage: true, successmessage: "Application customizer activated sucessfully." });
}
else {
const uca = this._sp.web.userCustomActions.getById(this.state.currentCustomAction.Id);
const response: IUserCustomActionUpdateResult = await uca.update(payload);
const ucaupdated = await this._sp.web.userCustomActions.getById(response.data.Id);
this.setState({ currentCustomAction: ucaupdated, showMesssage: true, successmessage: "Application customizer updated sucessfully." });
}
} catch (error) {
console.error(error);
console.error(error);
}
}
}

View File

@ -1,6 +0,0 @@
import { WebPartContext } from "@microsoft/sp-webpart-base";
export interface IAddJsCssReferenceProps {
description: string;
context:WebPartContext;
}

View File

@ -0,0 +1,13 @@
import { WebPartContext } from "@microsoft/sp-webpart-base";
// import pnp and pnp logging system
import { spfi, SPFI, SPFx } from "@pnp/sp";
let _sp: SPFI = null;
export const getSP = (context?: WebPartContext): SPFI => {
if (context) {
_sp = spfi().using(SPFx(context));
}
return _sp;
};

View File

@ -1,5 +1,5 @@
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-2.9/includes/tsconfig-web.json",
"extends": "./node_modules/@microsoft/rush-stack-compiler-4.5/includes/tsconfig-web.json",
"compilerOptions": {
"target": "es5",
"forceConsistentCasingInFileNames": true,
@ -9,6 +9,7 @@
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"skipLibCheck": true,
"outDir": "lib",
"inlineSources": false,
@ -19,20 +20,18 @@
"./node_modules/@microsoft"
],
"types": [
"es6-promise",
"webpack-env"
"webpack-env",
"es6-promise"
],
"lib": [
"es5",
"dom",
"es2015.collection"
"es2015.collection",
"es2015.promise"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"lib"
"src/**/*.ts",
"src/**/*.tsx"
]
}

View File

@ -1,30 +0,0 @@
{
"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
}
}

View File

@ -0,0 +1,443 @@
# Upgrade project react-add-js-css-ref to v1.15.2
Date: 10/20/2022
## Findings
Following is the list of steps required to upgrade your project to SharePoint Framework version 1.15.2. [Summary](#Summary) of the modifications is included at the end of the report.
### FN001001 @microsoft/sp-core-library | Required
Upgrade SharePoint Framework dependency package @microsoft/sp-core-library
Execute the following command:
```sh
npm i -SE @microsoft/sp-core-library@1.15.2
```
File: [./package.json:14:5](./package.json)
### FN001021 @microsoft/sp-property-pane | Required
Upgrade SharePoint Framework dependency package @microsoft/sp-property-pane
Execute the following command:
```sh
npm i -SE @microsoft/sp-property-pane@1.15.2
```
File: [./package.json:18:5](./package.json)
### FN001004 @microsoft/sp-webpart-base | Required
Upgrade SharePoint Framework dependency package @microsoft/sp-webpart-base
Execute the following command:
```sh
npm i -SE @microsoft/sp-webpart-base@1.15.2
```
File: [./package.json:19:5](./package.json)
### FN001002 @microsoft/sp-lodash-subset | Required
Upgrade SharePoint Framework dependency package @microsoft/sp-lodash-subset
Execute the following command:
```sh
npm i -SE @microsoft/sp-lodash-subset@1.15.2
```
File: [./package.json:16:5](./package.json)
### FN001003 @microsoft/sp-office-ui-fabric-core | Required
Upgrade SharePoint Framework dependency package @microsoft/sp-office-ui-fabric-core
Execute the following command:
```sh
npm i -SE @microsoft/sp-office-ui-fabric-core@1.15.2
```
File: [./package.json:17:5](./package.json)
### FN001034 @microsoft/sp-adaptive-card-extension-base | Optional
Install SharePoint Framework dependency package @microsoft/sp-adaptive-card-extension-base
Execute the following command:
```sh
npm i -SE @microsoft/sp-adaptive-card-extension-base@1.15.2
```
File: [./package.json:11:3](./package.json)
### FN001013 @microsoft/decorators | Required
Upgrade SharePoint Framework dependency package @microsoft/decorators
Execute the following command:
```sh
npm i -SE @microsoft/decorators@1.15.2
```
File: [./package.json:12:5](./package.json)
### FN001011 @microsoft/sp-dialog | Required
Upgrade SharePoint Framework dependency package @microsoft/sp-dialog
Execute the following command:
```sh
npm i -SE @microsoft/sp-dialog@1.15.2
```
File: [./package.json:15:5](./package.json)
### FN001012 @microsoft/sp-application-base | Required
Upgrade SharePoint Framework dependency package @microsoft/sp-application-base
Execute the following command:
```sh
npm i -SE @microsoft/sp-application-base@1.15.2
```
File: [./package.json:13:5](./package.json)
### FN002022 @microsoft/eslint-plugin-spfx | Required
Install SharePoint Framework dev dependency package @microsoft/eslint-plugin-spfx
Execute the following command:
```sh
npm i -DE @microsoft/eslint-plugin-spfx@1.15.2
```
File: [./package.json:26:3](./package.json)
### FN002023 @microsoft/eslint-config-spfx | Required
Install SharePoint Framework dev dependency package @microsoft/eslint-config-spfx
Execute the following command:
```sh
npm i -DE @microsoft/eslint-config-spfx@1.15.2
```
File: [./package.json:26:3](./package.json)
### FN002002 @microsoft/sp-module-interfaces | Required
Upgrade SharePoint Framework dev dependency package @microsoft/sp-module-interfaces
Execute the following command:
```sh
npm i -DE @microsoft/sp-module-interfaces@1.15.2
```
File: [./package.json:30:5](./package.json)
### FN002026 typescript | Required
Install SharePoint Framework dev dependency package typescript
Execute the following command:
```sh
npm i -DE typescript@4.5.5
```
File: [./package.json:26:3](./package.json)
### FN010001 .yo-rc.json version | Recommended
Update version in .yo-rc.json
```json
{
"@microsoft/generator-sharepoint": {
"version": "1.15.2"
}
}
```
File: [./.yo-rc.json:5:5](./.yo-rc.json)
### FN012020 tsconfig.json noImplicitAny | Required
Add noImplicitAny in tsconfig.json
```json
{
"compilerOptions": {
"noImplicitAny": true
}
}
```
File: [./tsconfig.json:3:22](./tsconfig.json)
### FN007001 serve.json schema | Required
Update serve.json schema URL
```json
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json"
}
```
File: [./config/serve.json:2:3](./config/serve.json)
### FN001022 office-ui-fabric-react | Required
Upgrade SharePoint Framework dependency package office-ui-fabric-react
Execute the following command:
```sh
npm i -SE office-ui-fabric-react@7.185.7
```
File: [./package.json:22:5](./package.json)
### FN001033 tslib | Required
Install SharePoint Framework dependency package tslib
Execute the following command:
```sh
npm i -SE tslib@2.3.1
```
File: [./package.json:11:3](./package.json)
### FN002007 ajv | Required
Upgrade SharePoint Framework dev dependency package ajv
Execute the following command:
```sh
npm i -DE ajv@6.12.5
```
File: [./package.json:36:5](./package.json)
### FN002009 @microsoft/sp-tslint-rules | Required
Remove SharePoint Framework dev dependency package @microsoft/sp-tslint-rules
Execute the following command:
```sh
npm un -D @microsoft/sp-tslint-rules
```
File: [./package.json:31:5](./package.json)
### FN002013 @types/webpack-env | Required
Upgrade SharePoint Framework dev dependency package @types/webpack-env
Execute the following command:
```sh
npm i -DE @types/webpack-env@1.15.2
```
File: [./package.json:35:5](./package.json)
### FN002020 @microsoft/rush-stack-compiler-4.5 | Required
Install SharePoint Framework dev dependency package @microsoft/rush-stack-compiler-4.5
Execute the following command:
```sh
npm i -DE @microsoft/rush-stack-compiler-4.5@0.2.2
```
File: [./package.json:26:3](./package.json)
### FN002021 @rushstack/eslint-config | Required
Install SharePoint Framework dev dependency package @rushstack/eslint-config
Execute the following command:
```sh
npm i -DE @rushstack/eslint-config@2.5.1
```
File: [./package.json:26:3](./package.json)
### FN002024 eslint | Required
Install SharePoint Framework dev dependency package eslint
Execute the following command:
```sh
npm i -DE eslint@8.7.0
```
File: [./package.json:26:3](./package.json)
### FN002025 eslint-plugin-react-hooks | Required
Install SharePoint Framework dev dependency package eslint-plugin-react-hooks
Execute the following command:
```sh
npm i -DE eslint-plugin-react-hooks@4.3.0
```
File: [./package.json:26:3](./package.json)
### FN012017 tsconfig.json extends property | Required
Update tsconfig.json extends property
```json
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-4.5/includes/tsconfig-web.json"
}
```
File: [./tsconfig.json:2:3](./tsconfig.json)
### FN015003 tslint.json | Required
Remove file tslint.json
Execute the following command:
```sh
rm "tslint.json"
```
File: [tslint.json](tslint.json)
### FN015008 .eslintrc.js | Required
Add file .eslintrc.js
Execute the following command:
```sh
cat > ".eslintrc.js" << EOF
require('@rushstack/eslint-config/patch/modern-module-resolution');
module.exports = {
extends: ['@microsoft/eslint-config-spfx/lib/profiles/react'],
parserOptions: { tsconfigRootDir: __dirname }
};
EOF
```
File: [.eslintrc.js](.eslintrc.js)
### FN023002 .gitignore '.heft' folder | Required
To .gitignore add the '.heft' folder
File: [./.gitignore](./.gitignore)
### FN017001 Run npm dedupe | Optional
If, after upgrading npm packages, when building the project you have errors similar to: "error TS2345: Argument of type 'SPHttpClientConfiguration' is not assignable to parameter of type 'SPHttpClientConfiguration'", try running 'npm dedupe' to cleanup npm packages.
Execute the following command:
```sh
npm dedupe
```
File: [./package.json](./package.json)
## Summary
### Execute script
```sh
npm un -D @microsoft/sp-tslint-rules
npm i -SE @microsoft/sp-core-library@1.15.2 @microsoft/sp-property-pane@1.15.2 @microsoft/sp-webpart-base@1.15.2 @microsoft/sp-lodash-subset@1.15.2 @microsoft/sp-office-ui-fabric-core@1.15.2 @microsoft/sp-adaptive-card-extension-base@1.15.2 @microsoft/decorators@1.15.2 @microsoft/sp-dialog@1.15.2 @microsoft/sp-application-base@1.15.2 office-ui-fabric-react@7.185.7 tslib@2.3.1
npm i -DE @microsoft/eslint-plugin-spfx@1.15.2 @microsoft/eslint-config-spfx@1.15.2 @microsoft/sp-module-interfaces@1.15.2 typescript@4.5.5 ajv@6.12.5 @types/webpack-env@1.15.2 @microsoft/rush-stack-compiler-4.5@0.2.2 @rushstack/eslint-config@2.5.1 eslint@8.7.0 eslint-plugin-react-hooks@4.3.0
npm dedupe
rm "tslint.json"
cat > ".eslintrc.js" << EOF
require('@rushstack/eslint-config/patch/modern-module-resolution');
module.exports = {
extends: ['@microsoft/eslint-config-spfx/lib/profiles/react'],
parserOptions: { tsconfigRootDir: __dirname }
};
EOF
```
### Modify files
#### [./.yo-rc.json](./.yo-rc.json)
Update version in .yo-rc.json:
```json
{
"@microsoft/generator-sharepoint": {
"version": "1.15.2"
}
}
```
#### [./tsconfig.json](./tsconfig.json)
Add noImplicitAny in tsconfig.json:
```json
{
"compilerOptions": {
"noImplicitAny": true
}
}
```
Update tsconfig.json extends property:
```json
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-4.5/includes/tsconfig-web.json"
}
```
#### [./config/serve.json](./config/serve.json)
Update serve.json schema URL:
```json
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json"
}
```
#### [./.gitignore](./.gitignore)
To .gitignore add the '.heft' folder:
```text
.heft
```