Merge pull request #2941 from martinlingstuyl/react-copy-views
Add Copy Views sample solution
This commit is contained in:
commit
ee2f06b504
|
@ -0,0 +1,47 @@
|
|||
FROM mcr.microsoft.com/powershell:7.1.0-ubuntu-focal
|
||||
|
||||
ENV NPM_CONFIG_PREFIX=/home/copy-views-container/.npm-global \
|
||||
PATH=$PATH:/home/copy-views-container/.npm-global/bin
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
git \
|
||||
curl \
|
||||
sudo \
|
||||
zsh \
|
||||
jq \
|
||||
vim \
|
||||
&& curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - \
|
||||
&& apt-get install nodejs -y \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN useradd \
|
||||
--user-group \
|
||||
--system \
|
||||
--create-home \
|
||||
--no-log-init \
|
||||
copy-views-container
|
||||
|
||||
USER copy-views-container
|
||||
|
||||
EXPOSE 5432 4321 35729
|
||||
|
||||
WORKDIR /home/copy-views-container
|
||||
|
||||
# ********************************************************
|
||||
# * Anything else you want to do like clean up goes here *
|
||||
# ********************************************************
|
||||
|
||||
RUN npm install -g gulp-cli@latest yo@4 @microsoft/generator-sharepoint@1.15.x spfx-fast-serve@3 @pnp/cli-microsoft365 --unsafe-perm
|
||||
|
||||
RUN zsh -c "$(curl https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" --unattended \
|
||||
&& git clone https://github.com/denysdovhan/spaceship-prompt.git "$HOME/.oh-my-zsh/custom/themes/spaceship-prompt" --depth=1 \
|
||||
&& ln -s "$HOME/.oh-my-zsh/custom/themes/spaceship-prompt/spaceship.zsh-theme" "$HOME/.oh-my-zsh/custom/themes/spaceship.zsh-theme" \
|
||||
&& cp "$HOME/.oh-my-zsh/templates/zshrc.zsh-template" $HOME/.zshrc \
|
||||
&& git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting \
|
||||
&& git clone https://github.com/zsh-users/zsh-autosuggestions $HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions \
|
||||
&& sed -i "11s/ZSH_THEME=\"robbyrussell\"/ZSH_THEME=\"spaceship\"/" ~/.zshrc \
|
||||
&& sed -i "27s/# DISABLE_AUTO_UPDATE=\"true\"/DISABLE_AUTO_UPDATE=\"true\"/" ~/.zshrc \
|
||||
&& sed -i "73s/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/" ~/.zshrc \
|
||||
&& sed -i "50s/# COMPLETION_WAITING_DOTS/COMPLETION_WAITING_DOTS/" ~/.zshrc
|
||||
|
||||
CMD [ "/bin/zsh", "-l" ]
|
|
@ -0,0 +1,42 @@
|
|||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
||||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.194.0/containers/typescript-node
|
||||
{
|
||||
"name": "copy-views-container",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
// Update 'VARIANT' to pick a Node version: 12, 14, 16
|
||||
"args": {
|
||||
"VARIANT": "14"
|
||||
}
|
||||
},
|
||||
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {
|
||||
"terminal.integrated.profiles.linux": {
|
||||
"zsh": {
|
||||
"path": "/bin/zsh",
|
||||
"args": [
|
||||
"-l"
|
||||
]
|
||||
}
|
||||
},
|
||||
"terminal.integrated.defaultProfile.linux": "zsh"
|
||||
},
|
||||
|
||||
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"dbaeumer.vscode-eslint",
|
||||
"mhutchie.git-graph",
|
||||
"eamodio.gitlens"
|
||||
],
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
"forwardPorts": [5432, 4321, 35729],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
//"postCreateCommand": "npm install",
|
||||
|
||||
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
||||
"remoteUser": "copy-views-container"
|
||||
}
|
|
@ -0,0 +1,384 @@
|
|||
require('@rushstack/eslint-config/patch/modern-module-resolution');
|
||||
module.exports = {
|
||||
extends: ['@microsoft/eslint-config-spfx/lib/profiles/react'],
|
||||
parserOptions: { tsconfigRootDir: __dirname },
|
||||
rules: {
|
||||
"no-unused-vars": "error",
|
||||
"@microsoft/spfx/no-async-await": "off",
|
||||
"@typescript-eslint/typedef": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off"
|
||||
},
|
||||
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. It provides no type safety when calling the function, which can be a common source of bugs. It also accepts things like class declarations, which will throw at runtime as they will not be called with new. If 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': 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': 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-eslinteslint-plugindistconfigseslint-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
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
# 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
|
|
@ -0,0 +1,16 @@
|
|||
!dist
|
||||
config
|
||||
|
||||
gulpfile.js
|
||||
|
||||
release
|
||||
src
|
||||
temp
|
||||
|
||||
tsconfig.json
|
||||
tslint.json
|
||||
|
||||
*.log
|
||||
|
||||
.yo-rc.json
|
||||
.vscode
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"@microsoft/generator-sharepoint": {
|
||||
"plusBeta": false,
|
||||
"isCreatingSolution": false,
|
||||
"version": "1.15.2",
|
||||
"libraryName": "copy-views",
|
||||
"libraryId": "f9a94606-ce1c-487c-ab87-550b240421de",
|
||||
"environment": "spo",
|
||||
"packageManager": "npm",
|
||||
"solutionName": "copy-views",
|
||||
"solutionShortDescription": "copy-views description",
|
||||
"skipFeatureDeployment": true,
|
||||
"isDomainIsolated": false,
|
||||
"componentType": "webpart"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
# Copy Views
|
||||
|
||||
## Summary
|
||||
|
||||
This solution enables a user to copy views from one list/library to another across site collections. It can be used as a webpart on a page, or as a ListView Command Set extension. The user can select multiple views to copy to multiple target lists.
|
||||
|
||||
![Copy Views extension](./assets/copy-views-screenshot.png)
|
||||
|
||||
![Copy Views](./assets/copy-views.gif)
|
||||
|
||||
## Used Versions
|
||||
|
||||
![SPFx 1.15.2](https://img.shields.io/badge/SPFx-1.15.2-green.svg)
|
||||
![pnpjs](https://img.shields.io/badge/pnpjs-3.6-green.svg)
|
||||
![Node.js v14 | v12](https://img.shields.io/badge/Node.js-v14%20%7C%20v12-green.svg)
|
||||
![Compatible with SharePoint Online](https://img.shields.io/badge/SharePoint%20Online-Compatible-green.svg)
|
||||
![Does not work with SharePoint 2019](https://img.shields.io/badge/SharePoint%20Server%202019-Unknown-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)-Unknown-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-Compatible-green.svg)
|
||||
|
||||
## Applies to
|
||||
|
||||
- [SharePoint Framework](https://aka.ms/spfx)
|
||||
- [Microsoft 365 tenant](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)
|
||||
|
||||
> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram)
|
||||
|
||||
## Solution
|
||||
|
||||
| Solution | Author(s) |
|
||||
| ----------- | ------------------------------------------------------- |
|
||||
| Copy Views | [Martin Lingstuyl](https://github.com/martinlingstuyl) ([@martinlingstuyl](https://twitter.com/martinlingstuyl)), I4-YOU Business Solutions b.v. |
|
||||
|
||||
## Version history
|
||||
|
||||
| Version | Date | Comments |
|
||||
| ------- | ---------------- | --------------- |
|
||||
| 1.0 | August 29, 2022 | Initial release |
|
||||
|
||||
## Minimal Path to Awesome
|
||||
|
||||
- Clone this repository
|
||||
- Ensure that you are at the solution folder
|
||||
- in the command-line run:
|
||||
- `npm install`
|
||||
- `gulp serve`
|
||||
- To package and deploy:
|
||||
- Use `gulp bundle --ship` & `gulp package-solution --ship`
|
||||
- Add the `.sppkg` to your SharePoint App Catalog
|
||||
|
||||
> 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
|
||||
|
||||
- Views can be copied from one list or library to other lists or libraries across site collections.
|
||||
- List views can only be copied to other *lists* and library views can only be copied to other *libraries*.
|
||||
- When opening the component using the List view Command Set extension, the current site, list and view will be preselected. When opening the component from a webpart, the current site will be preselected.
|
||||
- When copying views, the following things will be included:
|
||||
- Field references.
|
||||
- Sort and filter settings.
|
||||
- Column formatting and view formatting.
|
||||
- Fields that are not available on the target list are excluded from the copied view. The view query is cleaned of these fields so as not to break the view when columns are used to filter on. *
|
||||
- Views of type 'Kanban board' and 'modern calendar' are currently **not** supported.
|
||||
- Views that are set to default on the source list will not automatically be set to default on the target list. The checkbox 'Set as default' will need to be used.
|
||||
|
||||
> *The component uses the DOM parser to parse the ViewQuery XML, and removes any filter conditions that reference fields that are not available on the target list. The component can even clean filter queries with multiple And/Or CAML-conditions.
|
||||
|
||||
## 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-copy-views%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-copy-views) 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-copy-views&template=bug-report.yml&sample=react-copy-views&authors=@martinlingstuyl&title=react-copy-views%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-copy-views&template=question.yml&sample=react-copy-views&authors=@martinlingstuyl&title=react-copy-views%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-copy-views&template=suggestion.yml&sample=react-copy-views&authors=@martinlingstuyl&title=react-copy-views%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://pnptelemetry.azurewebsites.net/sp-dev-fx-webparts/samples/react-copy-views" />
|
Binary file not shown.
After Width: | Height: | Size: 105 KiB |
Binary file not shown.
After Width: | Height: | Size: 593 KiB |
|
@ -0,0 +1,56 @@
|
|||
[
|
||||
{
|
||||
"name": "pnp-sp-dev-spfx-web-parts-react-copy-views",
|
||||
"source": "pnp",
|
||||
"title": "Copy Views",
|
||||
"shortDescription": "The Copy Views solution enables a user to copy views from one list/library to another across site collections.",
|
||||
"url": "https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-content-query-onprem",
|
||||
"longDescription": [
|
||||
"The Copy Views solution enables a user to copy views from one list/library to another across site collections. It can be used as a webpart on a page, or as a ListView Command Set extension. The user can select multiple views to copy to multiple target lists."
|
||||
],
|
||||
"creationDateTime": "2022-08-29",
|
||||
"updateDateTime": "2022-08-29",
|
||||
"products": [
|
||||
"SharePoint"
|
||||
],
|
||||
"metadata": [
|
||||
{
|
||||
"key": "CLIENT-SIDE-DEV",
|
||||
"value": "React"
|
||||
},
|
||||
{
|
||||
"key": "SPFX-VERSION",
|
||||
"value": "1.15.2"
|
||||
}
|
||||
],
|
||||
"thumbnails": [
|
||||
{
|
||||
"type": "image",
|
||||
"order": 100,
|
||||
"url": "https://github.com/pnp/sp-dev-fx-webparts/raw/main/samples/react-copy-views/assets/copy-views.gif",
|
||||
"alt": "Copy Views solution"
|
||||
},
|
||||
{
|
||||
"type": "image",
|
||||
"order": 101,
|
||||
"url": "https://github.com/pnp/sp-dev-fx-webparts/raw/main/samples/react-copy-views/assets/copy-views-screenshot.png",
|
||||
"alt": "Copy Views solution"
|
||||
}
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"gitHubAccount": "martinlingstuyl",
|
||||
"company": "I4-YOU Business Solutions b.v.",
|
||||
"pictureUrl": "https://avatars.githubusercontent.com/u/5267487?v=4",
|
||||
"name": "Martin Lingstuyl"
|
||||
}
|
||||
],
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||
"version": "2.0",
|
||||
"bundles": {
|
||||
"copy-views-web-part": {
|
||||
"components": [
|
||||
{
|
||||
"entrypoint": "./lib/webparts/copyViews/CopyViewsWebPart.js",
|
||||
"manifest": "./src/webparts/copyViews/CopyViewsWebPart.manifest.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
"copy-views-command-set": {
|
||||
"components": [
|
||||
{
|
||||
"entrypoint": "./lib/extensions/copyViews/CopyViewsCommandSet.js",
|
||||
"manifest": "./src/extensions/copyViews/CopyViewsCommandSet.manifest.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"externals": {},
|
||||
"localizedResources": {
|
||||
"CopyViewsSharedStrings": "lib/shared/loc/{locale}.js",
|
||||
"CopyViewsWebPartStrings": "lib/webparts/copyViews/loc/{locale}.js",
|
||||
"CopyViewsCommandSetStrings": "lib/extensions/copyViews/loc/{locale}.js"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||
"workingDir": "./release/assets/",
|
||||
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||
"container": "copy-views",
|
||||
"accessKey": "<!-- ACCESS KEY -->"
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||
"solution": {
|
||||
"name": "copy-views-client-side-solution",
|
||||
"id": "f9a94606-ce1c-487c-ab87-550b240421de",
|
||||
"version": "1.0.1.5",
|
||||
"includeClientSideAssets": true,
|
||||
"skipFeatureDeployment": true,
|
||||
"isDomainIsolated": false,
|
||||
"developer": {
|
||||
"name": "Martin Lingstuyl",
|
||||
"websiteUrl": "https://www.blimped.nl",
|
||||
"privacyUrl": "",
|
||||
"termsOfUseUrl": "",
|
||||
"mpnId": "Undefined-1.15.0"
|
||||
},
|
||||
"metadata": {
|
||||
"shortDescription": {
|
||||
"default": "Webpart and extension to copy views between lists and libraries."
|
||||
},
|
||||
"longDescription": {
|
||||
"default": "Webpart and extension to copy views between lists and libraries."
|
||||
},
|
||||
"screenshotPaths": [],
|
||||
"videoUrl": "",
|
||||
"categories": []
|
||||
},
|
||||
"features": [
|
||||
{
|
||||
"title": "copy-views Feature",
|
||||
"description": "The feature that activates elements of the copy-views solution.",
|
||||
"id": "13252aea-fba5-4919-b962-045954817a5b",
|
||||
"version": "1.0.0.0",
|
||||
"assets": {
|
||||
"elementManifests": [
|
||||
"elements.xml",
|
||||
"ClientSideInstance.xml"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"paths": {
|
||||
"zippedPackage": "solution/copy-views.sppkg"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json",
|
||||
"port": 4321,
|
||||
"https": true,
|
||||
"initialPage": "https://enter-your-SharePoint-site/_layouts/workbench.aspx",
|
||||
"serveConfigurations": {
|
||||
"default": {
|
||||
"pageUrl": "https://contoso.sharepoint.com/sites/mySite/SitePages/myPage.aspx",
|
||||
"customActions": {
|
||||
"8e99be83-ad7e-4706-a8e1-d72df435d7e9": {
|
||||
"location": "ClientSideExtension.ListViewCommandSet.CommandBar",
|
||||
"properties": {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"extension": {
|
||||
"pageUrl": "https://contoso.sharepoint.com/sites/mySite/Shared Documents",
|
||||
"customActions": {
|
||||
"8e99be83-ad7e-4706-a8e1-d72df435d7e9": {
|
||||
"location": "ClientSideExtension.ListViewCommandSet.CommandBar",
|
||||
"properties": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
'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;
|
||||
};
|
||||
|
||||
/* fast-serve */
|
||||
const { addFastServe } = require("spfx-fast-serve-helpers");
|
||||
addFastServe(build);
|
||||
/* end of fast-serve */
|
||||
|
||||
// disable eslint
|
||||
build.lintCmd.enabled = false;
|
||||
|
||||
build.initialize(require('gulp'));
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"name": "copy-views",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build": "gulp bundle",
|
||||
"clean": "gulp clean",
|
||||
"test": "gulp test",
|
||||
"serve": "gulp bundle --custom-serve --max_old_space_size=4096 && fast-serve"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluentui/react-icons-mdl2": "^1.3.16",
|
||||
"@microsoft/decorators": "1.15.2",
|
||||
"@microsoft/sp-adaptive-card-extension-base": "1.15.2",
|
||||
"@microsoft/sp-core-library": "1.15.2",
|
||||
"@microsoft/sp-dialog": "1.15.2",
|
||||
"@microsoft/sp-listview-extensibility": "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.6.0",
|
||||
"office-ui-fabric-react": "7.185.7",
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1",
|
||||
"tslib": "2.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@microsoft/eslint-config-spfx": "1.15.2",
|
||||
"@microsoft/eslint-plugin-spfx": "1.15.2",
|
||||
"@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/react": "16.9.51",
|
||||
"@types/react-dom": "16.9.8",
|
||||
"@types/webpack-env": "~1.15.2",
|
||||
"ajv": "^6.12.5",
|
||||
"eslint-plugin-react-hooks": "4.3.0",
|
||||
"gulp": "4.0.2",
|
||||
"spfx-fast-serve-helpers": "^1.15.3",
|
||||
"typescript": "4.5.5"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
|
||||
<ClientSideComponentInstance
|
||||
Title="CopyViews for lists"
|
||||
Location="ClientSideExtension.ListViewCommandSet.CommandBar"
|
||||
ListTemplateId="100"
|
||||
Properties="{}"
|
||||
ComponentId="8e99be83-ad7e-4706-a8e1-d72df435d7e9" />
|
||||
<ClientSideComponentInstance
|
||||
Title="CopyViews for libraries"
|
||||
Location="ClientSideExtension.ListViewCommandSet.CommandBar"
|
||||
ListTemplateId="101"
|
||||
Properties="{}"
|
||||
ComponentId="8e99be83-ad7e-4706-a8e1-d72df435d7e9" />
|
||||
</Elements>
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
|
||||
<CustomAction
|
||||
Title="CopyViews"
|
||||
RegistrationId="100"
|
||||
RegistrationType="List"
|
||||
Location="ClientSideExtension.ListViewCommandSet.CommandBar"
|
||||
ClientSideComponentId="8e99be83-ad7e-4706-a8e1-d72df435d7e9"
|
||||
ClientSideComponentProperties="{"sampleTextOne":"One item is selected in the list.", "sampleTextTwo":"This command is always visible."}">
|
||||
</CustomAction>
|
||||
</Elements>
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/command-set-extension-manifest.schema.json",
|
||||
"id": "8e99be83-ad7e-4706-a8e1-d72df435d7e9",
|
||||
"alias": "CopyViewsCommandSet",
|
||||
"componentType": "Extension",
|
||||
"extensionType": "ListViewCommandSet",
|
||||
"version": "*",
|
||||
"manifestVersion": 2,
|
||||
"requiresCustomScript": false,
|
||||
"items": {
|
||||
"COPYVIEWS": {
|
||||
"title": { "default": "Copy views", "nl-nl": "Weergaven kopiëren" },
|
||||
"iconImageUrl": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyMDQ4IDIwNDgiIGNsYXNzPSJzdmdfZGQ3OTBlZTMiIGZvY3VzYWJsZT0iZmFsc2UiPjxwYXRoIGQ9Ik0xOTIwIDgwNXYxMjQzSDY0MHYtMzg0SDEyOFYwaDg1OWwzODQgMzg0aDEyOGw0MjEgNDIxem0tMzg0LTM3aDE2NWwtMTY1LTE2NXYxNjV6TTY0MCAzODRoNTQ5TDkzMyAxMjhIMjU2djE0MDhoMzg0VjM4NHptMTE1MiA1MTJoLTM4NFY1MTJINzY4djE0MDhoMTAyNFY4OTZ6Ij48L3BhdGg+PC9zdmc+",
|
||||
"type": "command"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
import { Log } from '@microsoft/sp-core-library';
|
||||
import { BaseListViewCommandSet, IListViewCommandSetExecuteEventParameters } from '@microsoft/sp-listview-extensibility';
|
||||
import { IDefaults } from '../../shared/interfaces';
|
||||
import CopyViewsDialog from './CopyViewsDialog';
|
||||
|
||||
/**
|
||||
* If your command set uses the ClientSideComponentProperties JSON input,
|
||||
* it will be deserialized into the BaseExtension.properties object.
|
||||
* You can define an interface to describe it.
|
||||
*/
|
||||
export interface ICopyViewsCommandSetProperties {
|
||||
resultSourceId?: string;
|
||||
}
|
||||
|
||||
const LOG_SOURCE: string = 'CopyViewsCommandSet';
|
||||
|
||||
export default class CopyViewsCommandSet extends BaseListViewCommandSet<ICopyViewsCommandSetProperties> {
|
||||
|
||||
public onInit(): Promise<void> {
|
||||
Log.info(LOG_SOURCE, 'Initialized CopyViewsCommandSet');
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
|
||||
const defaultValues = {
|
||||
viewId: this.context.listView.view.id.toString(),
|
||||
listId: this.context.listView.list.guid.toString(),
|
||||
siteUrl: this.context.pageContext.site.absoluteUrl
|
||||
} as IDefaults;
|
||||
|
||||
const dialog = new CopyViewsDialog(this.context.serviceScope, defaultValues, this.properties.resultSourceId);
|
||||
|
||||
switch (event.itemId) {
|
||||
case 'COPYVIEWS':
|
||||
dialog.show().then(() => {
|
||||
|
||||
//
|
||||
|
||||
}, (error: Error) => {
|
||||
if (console && console.error && error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown command');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { ServiceScope } from '@microsoft/sp-core-library';
|
||||
import { BaseDialog, IDialogConfiguration } from '@microsoft/sp-dialog';
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import { CopyViewsContainer } from '../../shared/components';
|
||||
import { IDefaults } from '../../shared/interfaces';
|
||||
|
||||
export default class CopyViewsDialog extends BaseDialog {
|
||||
private _serviceScope: ServiceScope;
|
||||
private _resultSourceId?: string;
|
||||
private _defaultValues: IDefaults;
|
||||
|
||||
public constructor(serviceScope: ServiceScope, defaultValues: IDefaults, resultSourceId?: string) {
|
||||
super({ isBlocking: true });
|
||||
|
||||
this._serviceScope = serviceScope;
|
||||
this._resultSourceId = resultSourceId;
|
||||
this._defaultValues = defaultValues;
|
||||
}
|
||||
|
||||
public render(): void {
|
||||
|
||||
const element = <div style={{ width: 1000, padding: 20 }}>
|
||||
<CopyViewsContainer serviceScope={this._serviceScope} showCancel={true} defaultValues={this._defaultValues} resultSourceId={this._resultSourceId} onCopied={this._onCopied} onCancel={this.close} />
|
||||
</div>;
|
||||
|
||||
|
||||
ReactDOM.render(element, this.domElement);
|
||||
}
|
||||
|
||||
private _onCopied = async (): Promise<void> => {
|
||||
await this.close();
|
||||
}
|
||||
|
||||
public getConfig(): IDialogConfiguration {
|
||||
return { isBlocking: false };
|
||||
}
|
||||
|
||||
protected onAfterClose(): void {
|
||||
super.onAfterClose();
|
||||
|
||||
// Clean up the element for the next dialog
|
||||
ReactDOM.unmountComponentAtNode(this.domElement);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"Command1": "Command 1",
|
||||
"Command2": "Command 2"
|
||||
}
|
||||
});
|
|
@ -0,0 +1,9 @@
|
|||
declare interface ICopyViewsCommandSetStrings {
|
||||
Command1: string;
|
||||
Command2: string;
|
||||
}
|
||||
|
||||
declare module 'CopyViewsCommandSetStrings' {
|
||||
const strings: ICopyViewsCommandSetStrings;
|
||||
export = strings;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,89 @@
|
|||
@import '~office-ui-fabric-react/dist/sass/References.scss';
|
||||
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
|
||||
|
||||
.row {
|
||||
@include ms-Grid-row;
|
||||
}
|
||||
|
||||
.formHidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.column {
|
||||
@include ms-Grid-col;
|
||||
@include ms-sm12;
|
||||
@include ms-md12;
|
||||
@include ms-lg6;
|
||||
@include ms-xl6;
|
||||
}
|
||||
|
||||
.checkboxSetDefaultView {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.checkboxSelectionContainer {
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
border-color: #a19f9d;
|
||||
height: 300px;
|
||||
padding: 10px;
|
||||
overflow: auto;
|
||||
|
||||
&:hover {
|
||||
border-color: #323130;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.SiteSuggestion {
|
||||
padding: 5px 5px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.selectedSite {
|
||||
background: #f2f2f2;
|
||||
padding: 0px 5px;
|
||||
margin: 2px;
|
||||
line-height: 26px;
|
||||
}
|
||||
|
||||
.copyStatusContainer {
|
||||
height: 300px;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.copyTaskLine {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
|
||||
.copyTaskIcon {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.searchBox {
|
||||
height: 38.66px;
|
||||
|
||||
:global {
|
||||
.ms-SearchBox-iconContainer {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.sitePicker {
|
||||
visibility: inherit;
|
||||
// height: 38.66px;
|
||||
}
|
||||
|
||||
.title {
|
||||
color: "[theme:bodyText, default: #323130]";
|
||||
color: var(--bodyText);
|
||||
font-family: $ms-font-family-fallbacks;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/* eslint-disable react/jsx-no-bind */
|
||||
import { CheckMarkIcon, DecreaseIndentArrowMirroredIcon, ErrorBadgeIcon } from '@fluentui/react-icons-mdl2';
|
||||
import * as strings from 'CopyViewsSharedStrings';
|
||||
import { Link } from 'office-ui-fabric-react/lib/Link';
|
||||
import { MessageBar, MessageBarType } from 'office-ui-fabric-react/lib/MessageBar';
|
||||
import { ProgressIndicator } from 'office-ui-fabric-react/lib/ProgressIndicator';
|
||||
import { Spinner } from 'office-ui-fabric-react/lib/Spinner';
|
||||
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||
import * as React from 'react';
|
||||
import { CopyTaskState } from '../enums';
|
||||
import { ICopyTask } from '../interfaces';
|
||||
import styles from '../SharedStyles.module.scss';
|
||||
|
||||
interface ICopyStatusProps {
|
||||
copyTasks: ICopyTask[];
|
||||
onRetry: (copyTask: ICopyTask) => Promise<void>;
|
||||
}
|
||||
|
||||
interface ICopyStatusState {
|
||||
showErrors: number[];
|
||||
}
|
||||
|
||||
export class CopyStatus extends React.Component<ICopyStatusProps, ICopyStatusState> {
|
||||
|
||||
public constructor(props: ICopyStatusProps) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
showErrors: []
|
||||
};
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<ICopyStatusProps> {
|
||||
const { copyTasks } = this.props;
|
||||
const { showErrors } = this.state;
|
||||
|
||||
const busy = copyTasks.some(t => t.state === CopyTaskState.Busy);
|
||||
|
||||
return <div className={styles.copyStatusContainer}>
|
||||
{
|
||||
busy
|
||||
? <ProgressIndicator label={strings.BusyCopyingViews} />
|
||||
: <MessageBar messageBarType={MessageBarType.info}>
|
||||
{ strings.DoneCopyingViews }
|
||||
</MessageBar>
|
||||
}
|
||||
<br/>
|
||||
{
|
||||
copyTasks.map((copyTask) => {
|
||||
return <div key={copyTask.index} className={styles.copyTaskLine}>
|
||||
<Stack tokens={{ childrenGap: 5 }} horizontal>
|
||||
<span>{copyTask.index}.</span>
|
||||
<Link href={copyTask.sourceView.viewUrl} target='_blank'>{copyTask.sourceView.title}</Link>
|
||||
<DecreaseIndentArrowMirroredIcon style={{ fontSize: 25, marginRight: 15 }} />
|
||||
<Link href={copyTask.targetList.listUrl} target='_blank'>{copyTask.targetList.title}</Link>
|
||||
</Stack>
|
||||
|
||||
<div className={styles.copyTaskIcon}>
|
||||
{
|
||||
copyTask.state === CopyTaskState.Busy && <Spinner />
|
||||
}
|
||||
{
|
||||
copyTask.state === CopyTaskState.Done && <CheckMarkIcon style={{ color: 'green' }} />
|
||||
}
|
||||
{
|
||||
copyTask.state === CopyTaskState.Error && <ErrorBadgeIcon style={{ color: 'indianred' }} />
|
||||
}
|
||||
</div>
|
||||
|
||||
{copyTask.state === CopyTaskState.Error &&
|
||||
<MessageBar
|
||||
messageBarType={MessageBarType.error}
|
||||
isMultiline={false}
|
||||
actions={
|
||||
<div>
|
||||
<Link onClick={() => this._toggleErrorDetails(copyTask)}>{strings.SeeMore}</Link>
|
||||
<Link onClick={() => this._retry(copyTask)}>{strings.Retry}</Link>
|
||||
</div>
|
||||
}
|
||||
overflowButtonAriaLabel={strings.SeeMore}>
|
||||
{strings.ErrorOccurred}
|
||||
{ showErrors.some(i => copyTask.index === i) && <><br />{copyTask.error}</> }
|
||||
</MessageBar>
|
||||
}
|
||||
</div>
|
||||
})
|
||||
}
|
||||
|
||||
</div>;
|
||||
}
|
||||
|
||||
private _toggleErrorDetails = (copyTask: ICopyTask): void => {
|
||||
const { showErrors } = this.state;
|
||||
|
||||
if (showErrors.some(i => i === copyTask.index)) {
|
||||
const newShowErrors = showErrors.filter(i => i !== copyTask.index);
|
||||
this.setState({ showErrors: newShowErrors});
|
||||
}
|
||||
else {
|
||||
const newShowErrors = [...showErrors, copyTask.index];
|
||||
this.setState({ showErrors: newShowErrors});
|
||||
}
|
||||
}
|
||||
|
||||
private _retry = async (copyTask: ICopyTask): Promise<void> => {
|
||||
await this.props.onRetry(copyTask);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
/* eslint-disable react/jsx-no-bind */
|
||||
import * as React from 'react';
|
||||
import { IList, IListView, ICopyTask, IDefaults } from '../interfaces';
|
||||
import { CopyTaskState } from '../enums';
|
||||
import { ServiceScope } from '@microsoft/sp-core-library';
|
||||
import { IListViewsService, ListViewsService } from '../services';
|
||||
import * as strings from 'CopyViewsSharedStrings';
|
||||
import styles from './../SharedStyles.module.scss';
|
||||
import { SourceListViewForm, TargetListForm, CopyStatus } from '.';
|
||||
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||
import { DefaultButton, PrimaryButton } from 'office-ui-fabric-react/lib/Button';
|
||||
import { MessageBar, MessageBarType } from 'office-ui-fabric-react/lib/MessageBar';
|
||||
import { Link } from 'office-ui-fabric-react/lib/Link';
|
||||
import { Checkbox } from 'office-ui-fabric-react/lib/Checkbox';
|
||||
|
||||
interface ICopyViewsContainerProps {
|
||||
serviceScope: ServiceScope;
|
||||
resultSourceId?: string;
|
||||
showCancel?: boolean;
|
||||
defaultValues?: IDefaults;
|
||||
onCopied: () => void;
|
||||
onCancel?: () => void;
|
||||
}
|
||||
|
||||
interface ICopyViewsContainerState {
|
||||
sourceList?: IList;
|
||||
sourceViews?: IListView[];
|
||||
targetLists?: IList[];
|
||||
showCopyStatus: boolean;
|
||||
copyTasks?: ICopyTask[];
|
||||
error?: string;
|
||||
showErrorDetails: boolean;
|
||||
setAsDefaultView: boolean;
|
||||
}
|
||||
|
||||
export class CopyViewsContainer extends React.Component<ICopyViewsContainerProps, ICopyViewsContainerState> {
|
||||
private _listViewsService: IListViewsService;
|
||||
|
||||
public constructor(props: ICopyViewsContainerProps) {
|
||||
super(props);
|
||||
|
||||
this._listViewsService = props.serviceScope.consume(ListViewsService.serviceKey);
|
||||
|
||||
this.state = {
|
||||
showCopyStatus: false,
|
||||
showErrorDetails: false,
|
||||
setAsDefaultView: false,
|
||||
sourceViews: null
|
||||
}
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<ICopyViewsContainerProps> {
|
||||
const { serviceScope, resultSourceId, defaultValues, showCancel, onCancel } = this.props;
|
||||
const { sourceViews, targetLists, error, showErrorDetails, showCopyStatus, copyTasks, sourceList, setAsDefaultView } = this.state;
|
||||
|
||||
const copyingDisabled = !(targetLists?.length > 0 && sourceViews?.length > 0);
|
||||
|
||||
return <>
|
||||
<h2 className={styles.title}>{ !showCopyStatus ? strings.CopyViews : strings.CopyStatus }</h2>
|
||||
{
|
||||
error && <MessageBar
|
||||
messageBarType={MessageBarType.error}
|
||||
isMultiline={false}
|
||||
actions={
|
||||
<div>
|
||||
<Link onClick={() => this.setState({ showErrorDetails: !showErrorDetails })}>{strings.SeeMore}</Link>
|
||||
</div>
|
||||
}
|
||||
onDismiss={() => this.setState({ error: undefined })}
|
||||
overflowButtonAriaLabel={strings.SeeMore}>
|
||||
{strings.ErrorOccurred}
|
||||
{ showErrorDetails && <><br/>{error}</> }
|
||||
</MessageBar>
|
||||
}
|
||||
{
|
||||
<div className={showCopyStatus && styles.formHidden}>
|
||||
<div className={styles.row}>
|
||||
<div className={styles.column}>
|
||||
<SourceListViewForm serviceScope={serviceScope} defaultValues={defaultValues} resultSourceId={resultSourceId} onSelectionUpdate={this._onSelectionUpdate} onError={this._onError} />
|
||||
<Checkbox label={strings.SetAsDefaultView} disabled={sourceViews?.length > 1} checked={setAsDefaultView} onChange={() => this.setState({ setAsDefaultView: !setAsDefaultView})} className={styles.checkboxSetDefaultView} />
|
||||
</div>
|
||||
<div className={styles.column}>
|
||||
<TargetListForm serviceScope={serviceScope} baseType={sourceList?.type} exclude={sourceList} resultSourceId={resultSourceId} onSelectionUpdate={(lists: IList[]) => this.setState({ targetLists: lists })} onError={this._onError} />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Stack tokens={{ childrenGap: 10 }} horizontal reversed style={{marginTop: 10}}>
|
||||
<PrimaryButton disabled={copyingDisabled} text={strings.Copy} onClick={this._copyViews} />
|
||||
{ showCancel && <DefaultButton text={strings.CloseDialog} onClick={() => onCancel()} /> }
|
||||
</Stack>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
{
|
||||
showCopyStatus && <>
|
||||
<CopyStatus copyTasks={copyTasks} onRetry={this._retryCopyTask} />
|
||||
<div>
|
||||
<Stack tokens={{ childrenGap: 10 }} horizontal reversed style={{marginTop: 10}}>
|
||||
<PrimaryButton disabled={copyTasks.some(t => t.state === CopyTaskState.Busy)} text={strings.CopyAnotherView} onClick={() => this.setState({ showCopyStatus: false, copyTasks: [] })} />
|
||||
{ showCancel && <DefaultButton disabled={copyTasks.some(t => t.state === CopyTaskState.Busy)} text={strings.CloseDialog} onClick={() => onCancel()} /> }
|
||||
</Stack>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
</>;
|
||||
}
|
||||
|
||||
private _onSelectionUpdate = (listViews: IListView[], list: IList): void => {
|
||||
const { setAsDefaultView } = this.state;
|
||||
this.setState({ sourceViews: listViews, sourceList: list, setAsDefaultView: listViews?.length > 1 ? false : setAsDefaultView });
|
||||
}
|
||||
|
||||
private _copyViews = async (): Promise<void> => {
|
||||
const { sourceViews, targetLists } = this.state;
|
||||
|
||||
const copyingDisabled = !(targetLists?.length > 0 && sourceViews?.length > 0);
|
||||
|
||||
if (copyingDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const copyTasks: ICopyTask[] = [];
|
||||
let index = 0;
|
||||
|
||||
sourceViews.forEach(sourceView => {
|
||||
targetLists.forEach(targetList => {
|
||||
index++;
|
||||
copyTasks.push({ index, sourceView, targetList, state: CopyTaskState.Busy });
|
||||
});
|
||||
});
|
||||
|
||||
this.setState({ showCopyStatus: true, copyTasks }, async () => {
|
||||
await Promise.all(copyTasks.map(copyTask => this._copyView(copyTask)));
|
||||
});
|
||||
}
|
||||
|
||||
private _copyView = async (copyTask: ICopyTask): Promise<void> => {
|
||||
const { setAsDefaultView } = this.state;
|
||||
|
||||
try {
|
||||
await this._listViewsService.copy(copyTask.sourceView, copyTask.targetList.siteUrl, copyTask.targetList.id, setAsDefaultView);
|
||||
|
||||
const { copyTasks } = this.state;
|
||||
const currentCopyTask = copyTasks.filter(c => c.index === copyTask.index)[0];
|
||||
currentCopyTask.state = CopyTaskState.Done;
|
||||
|
||||
this.setState({ copyTasks });
|
||||
}
|
||||
catch (error) {
|
||||
if (console && console.error && error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
const { copyTasks } = this.state;
|
||||
const currentCopyTask = copyTasks.filter(c => c.index === copyTask.index)[0];
|
||||
currentCopyTask.state = CopyTaskState.Error;
|
||||
currentCopyTask.error = error?.message;
|
||||
|
||||
this.setState({ copyTasks });
|
||||
}
|
||||
}
|
||||
|
||||
private _onError = (error: Error): void => {
|
||||
if (console && console.error && error) {
|
||||
console.error(error);
|
||||
}
|
||||
this.setState({ error: error?.message, showErrorDetails: false });
|
||||
}
|
||||
|
||||
private _retryCopyTask = async (copyTask: ICopyTask): Promise<void> => {
|
||||
const { copyTasks } = this.state;
|
||||
|
||||
const currentCopyTask = copyTasks.filter(c => c.index === copyTask.index)[0];
|
||||
currentCopyTask.state = CopyTaskState.Busy;
|
||||
currentCopyTask.error = undefined;
|
||||
|
||||
this.setState({ copyTasks }, async () => {
|
||||
await this._copyView(currentCopyTask);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
import * as React from 'react';
|
||||
import { IList, ISite } from '../interfaces';
|
||||
import { ServiceScope } from '@microsoft/sp-core-library';
|
||||
import { IListsService, ListsService } from '../services';
|
||||
import * as strings from 'CopyViewsSharedStrings';
|
||||
import { ComboBox, IComboBox, IComboBoxOption, SelectableOptionMenuItemType } from 'office-ui-fabric-react/lib/ComboBox';
|
||||
import { uniq } from '@microsoft/sp-lodash-subset';
|
||||
import { BaseType } from '../enums';
|
||||
|
||||
interface ISourceListPickerProps {
|
||||
serviceScope: ServiceScope;
|
||||
site?: ISite;
|
||||
defaultValue?: string;
|
||||
onChange: (list?:IList) => void;
|
||||
onError: (error: Error) => void;
|
||||
}
|
||||
|
||||
interface ISourceListPickerState {
|
||||
availableLists?: IList[];
|
||||
selectedSourceList?: IList;
|
||||
loading: boolean;
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
export class SourceListPicker extends React.Component<ISourceListPickerProps, ISourceListPickerState> {
|
||||
private _listsService: IListsService;
|
||||
|
||||
public constructor(props: ISourceListPickerProps) {
|
||||
super(props);
|
||||
|
||||
this._listsService = props.serviceScope.consume(ListsService.serviceKey);
|
||||
|
||||
this.state = {
|
||||
loading: false
|
||||
}
|
||||
}
|
||||
|
||||
public componentDidUpdate(prevProps: Readonly<ISourceListPickerProps>): void {
|
||||
if (prevProps.site?.url !== this.props.site?.url) {
|
||||
if (this.props.site) {
|
||||
this._loadLists();
|
||||
}
|
||||
else {
|
||||
this.setState({ availableLists: null, selectedSourceList: null });
|
||||
this.props.onChange(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<ISourceListPickerProps> {
|
||||
const { site } = this.props;
|
||||
const { availableLists, selectedSourceList } = this.state;
|
||||
|
||||
return <>
|
||||
<ComboBox
|
||||
label={strings.SelectAList}
|
||||
selectedKey={selectedSourceList?.id}
|
||||
options={this._getListsAsOptions(availableLists)}
|
||||
disabled={!site || !availableLists}
|
||||
onChange={this._onChangeCombo}
|
||||
/>
|
||||
</>;
|
||||
}
|
||||
|
||||
private _getListsAsOptions = (lists: IList[]): IComboBoxOption[] => {
|
||||
if (!lists) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const options: IComboBoxOption[] = [];
|
||||
const listTypes = uniq(lists.map(l => l.type));
|
||||
|
||||
listTypes.forEach((type, index) => {
|
||||
|
||||
if (index > 0) {
|
||||
options.push({ itemType: SelectableOptionMenuItemType.Divider, key: `listsDivider_${type}`, text: null });
|
||||
}
|
||||
|
||||
options.push({ itemType: SelectableOptionMenuItemType.Header, key: `listsHeader_${type}`, text: type === BaseType.DocumentLibrary ? strings.LibraryHeader : strings.ListHeader });
|
||||
|
||||
lists.filter(l => l.type === type).forEach(list => {
|
||||
options.push({ id: list.id, key: list.id, text: list.title });
|
||||
});
|
||||
});
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
private _onChangeCombo = async (event: React.FormEvent<IComboBox>, option?: IComboBoxOption): Promise<void> => {
|
||||
const { availableLists } = this.state;
|
||||
|
||||
const selectedSourceList = availableLists.filter(l => l.id === option.id)[0];
|
||||
this.props.onChange(selectedSourceList);
|
||||
|
||||
this.setState({ selectedSourceList });
|
||||
}
|
||||
|
||||
private _loadLists = (): void => {
|
||||
const { site, defaultValue } = this.props;
|
||||
const { error } = this.state;
|
||||
|
||||
if (error) {
|
||||
this.props.onError(undefined);
|
||||
}
|
||||
this.setState({ loading: true, error: undefined });
|
||||
|
||||
this._listsService.get(site.url).then((availableLists) => {
|
||||
const selectedSourceList = availableLists && defaultValue ? availableLists.filter(l => l.id === defaultValue)[0] : null;
|
||||
this.setState({ loading: false, availableLists, selectedSourceList });
|
||||
this.props.onChange(selectedSourceList);
|
||||
|
||||
}, (error: Error) => {
|
||||
this.setState({ error });
|
||||
this.props.onError(error);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/* eslint-disable react/jsx-no-bind */
|
||||
import * as React from 'react';
|
||||
import { IDefaults, IList, IListView, ISite } from './../interfaces';
|
||||
import { ServiceScope } from '@microsoft/sp-core-library';
|
||||
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||
import { SourceSitePicker } from '.';
|
||||
import { SourceListPicker } from '.';
|
||||
import { SourceListViewPicker } from '.';
|
||||
|
||||
interface ISourceListViewFormProps {
|
||||
serviceScope: ServiceScope;
|
||||
defaultValues?: IDefaults;
|
||||
resultSourceId?: string;
|
||||
onSelectionUpdate: (listViews?:IListView[], list?: IList) => void;
|
||||
onError: (error: Error) => void;
|
||||
}
|
||||
|
||||
interface ISourceListViewFormState {
|
||||
selectedSourceSite?: ISite;
|
||||
selectedSourceList?: IList;
|
||||
selectedViews: IListView[];
|
||||
}
|
||||
|
||||
export class SourceListViewForm extends React.Component<ISourceListViewFormProps, ISourceListViewFormState> {
|
||||
|
||||
public constructor(props: ISourceListViewFormProps) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
selectedViews: []
|
||||
}
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<ISourceListViewFormProps> {
|
||||
const { serviceScope, resultSourceId, defaultValues, onError } = this.props;
|
||||
const { selectedSourceSite, selectedSourceList } = this.state;
|
||||
|
||||
return <>
|
||||
<Stack tokens={{ childrenGap: 5 }}>
|
||||
<SourceSitePicker serviceScope={serviceScope} defaultValue={defaultValues?.siteUrl} resultSourceId={resultSourceId} onChange={(site) => this.setState({ selectedSourceSite: site })} onError={onError} />
|
||||
|
||||
<SourceListPicker serviceScope={serviceScope} defaultValue={defaultValues?.listId} site={selectedSourceSite} onChange={this._onListSelected} onError={onError} />
|
||||
|
||||
<SourceListViewPicker serviceScope={serviceScope} defaultValue={defaultValues?.viewId} site={selectedSourceSite} list={selectedSourceList} onChange={this._onListViewsSelected} onError={onError} />
|
||||
</Stack>
|
||||
</>;
|
||||
}
|
||||
|
||||
private _onListSelected = async (selectedSourceList?: IList): Promise<void> => {
|
||||
this.setState({ selectedSourceList });
|
||||
|
||||
this.props.onSelectionUpdate(undefined, selectedSourceList);
|
||||
}
|
||||
|
||||
private _onListViewsSelected = (listViews: IListView[]): void => {
|
||||
const { selectedSourceList } = this.state;
|
||||
|
||||
this.setState({ selectedViews: listViews });
|
||||
|
||||
this.props.onSelectionUpdate(listViews, selectedSourceList);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
import * as React from 'react';
|
||||
import styles from './../SharedStyles.module.scss';
|
||||
import { IList, IListView, ISite } from './../interfaces';
|
||||
import { ServiceScope } from '@microsoft/sp-core-library';
|
||||
import { IListViewsService, ListViewsService } from './../services';
|
||||
import * as strings from 'CopyViewsSharedStrings';
|
||||
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||
import { Label } from 'office-ui-fabric-react/lib/Label';
|
||||
import { Checkbox } from 'office-ui-fabric-react/lib/Checkbox';
|
||||
|
||||
interface ISourceListViewPickerProps {
|
||||
serviceScope: ServiceScope;
|
||||
defaultValue?: string;
|
||||
site?: ISite;
|
||||
list?: IList;
|
||||
onChange: (listViews?:IListView[]) => void;
|
||||
onError: (error: Error) => void;
|
||||
}
|
||||
|
||||
interface ISourceListViewPickerState {
|
||||
availableViews?: IListView[];
|
||||
selectedViews: IListView[];
|
||||
loading: boolean;
|
||||
error?: boolean;
|
||||
}
|
||||
|
||||
export class SourceListViewPicker extends React.Component<ISourceListViewPickerProps, ISourceListViewPickerState> {
|
||||
private _listViewsService: IListViewsService;
|
||||
|
||||
public constructor(props: ISourceListViewPickerProps) {
|
||||
super(props);
|
||||
|
||||
this._listViewsService = props.serviceScope.consume(ListViewsService.serviceKey);
|
||||
|
||||
this.state = {
|
||||
loading: false,
|
||||
selectedViews: []
|
||||
}
|
||||
}
|
||||
|
||||
public componentDidUpdate(prevProps: Readonly<ISourceListViewPickerProps>): void {
|
||||
if (prevProps.list?.id !== this.props.list?.id) {
|
||||
const { site, list } = this.props;
|
||||
|
||||
if (site && list) {
|
||||
this._loadListViews();
|
||||
}
|
||||
else {
|
||||
this.setState({ availableViews: null, selectedViews: [] });
|
||||
this.props.onChange([]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<ISourceListViewPickerProps> {
|
||||
const { site, list } = this.props;
|
||||
const { availableViews, selectedViews } = this.state;
|
||||
|
||||
return <div>
|
||||
<Label>{strings.SelectViewsToCopy}</Label>
|
||||
<div className={styles.checkboxSelectionContainer} style={{ height: 235 }}>
|
||||
{
|
||||
site && list
|
||||
? <Stack tokens={{ childrenGap: 5 }}>
|
||||
{
|
||||
availableViews?.map(view => {
|
||||
const viewDisabled = view.viewType === 'KANBAN' || view.viewType === 'MODERNCALENDAR';
|
||||
return <><Checkbox key={view.id} disabled={viewDisabled} label={view.title} id={view.id} checked={selectedViews.some(v => v.id === view.id)} onChange={this._onChangeViewSelected} title={viewDisabled ? strings.ViewTypeNotSupported : ''} /></>
|
||||
})}
|
||||
</Stack>
|
||||
: <em>{strings.SelectASiteAndList}</em>
|
||||
}
|
||||
</div>
|
||||
</div>;
|
||||
}
|
||||
|
||||
private _onChangeViewSelected = (ev?: React.FormEvent<HTMLElement | HTMLInputElement>, checked?: boolean): void => {
|
||||
const { availableViews, selectedViews } = this.state;
|
||||
const view = availableViews.filter(v => v.id === ev.currentTarget.id)[0];
|
||||
|
||||
const views = selectedViews.filter(v => v.id !== view.id);
|
||||
|
||||
if (checked) {
|
||||
views.push(view);
|
||||
}
|
||||
|
||||
this.setState({ selectedViews: views });
|
||||
|
||||
this.props.onChange(views);
|
||||
}
|
||||
|
||||
|
||||
private _loadListViews = (): void => {
|
||||
const { site, list, defaultValue } = this.props;
|
||||
const { error } = this.state;
|
||||
|
||||
if (error) {
|
||||
this.props.onError(undefined);
|
||||
}
|
||||
this.setState({ loading: true, error: undefined });
|
||||
|
||||
this._listViewsService.get(site.url, list.id).then((availableViews) => {
|
||||
const selectedViews = availableViews && defaultValue ? availableViews.filter(l => l.id === defaultValue) : [];
|
||||
this.setState({ loading: false, availableViews, selectedViews });
|
||||
this.props.onChange(selectedViews);
|
||||
}, (error) => {
|
||||
this.setState({ error });
|
||||
this.props.onError(error);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
import * as React from 'react';
|
||||
import styles from './../SharedStyles.module.scss';
|
||||
import { ISite } from './../interfaces';
|
||||
import { ServiceScope } from '@microsoft/sp-core-library';
|
||||
import { SitesService, ISitesService } from './../services';
|
||||
import * as strings from 'CopyViewsSharedStrings';
|
||||
import { BasePicker, IBasePickerProps, IPickerItemProps } from 'office-ui-fabric-react/lib/Pickers';
|
||||
import { Label } from 'office-ui-fabric-react/lib/Label';
|
||||
import { IconButton } from 'office-ui-fabric-react/lib/Button';
|
||||
|
||||
interface ISourceSitePickerProps {
|
||||
serviceScope: ServiceScope;
|
||||
resultSourceId?: string;
|
||||
defaultValue?: string;
|
||||
onChange: (site?:ISite) => void;
|
||||
onError: (error: Error) => void;
|
||||
}
|
||||
|
||||
interface ISourceSitePickerState {
|
||||
selectedSourceSite?: ISite;
|
||||
loading: boolean;
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
export interface ISitePickerProps extends IBasePickerProps<ISite> {}
|
||||
|
||||
class SitePicker extends BasePicker<ISite, ISitePickerProps> {}
|
||||
|
||||
export class SourceSitePicker extends React.Component<ISourceSitePickerProps, ISourceSitePickerState> {
|
||||
private _sitesService: ISitesService;
|
||||
|
||||
public constructor(props: ISourceSitePickerProps) {
|
||||
super(props);
|
||||
|
||||
this._sitesService = props.serviceScope.consume(SitesService.serviceKey);
|
||||
|
||||
this.state = {
|
||||
loading: false
|
||||
};
|
||||
}
|
||||
|
||||
public componentDidMount(): void {
|
||||
const { defaultValue } = this.props;
|
||||
|
||||
if (defaultValue) {
|
||||
this._loadSite();
|
||||
}
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<ISourceSitePickerProps> {
|
||||
const { selectedSourceSite } = this.state;
|
||||
|
||||
return <>
|
||||
<Label>{strings.SearchAndSelectSourceSite}</Label>
|
||||
<SitePicker
|
||||
onResolveSuggestions={this._getSitePickerOptions}
|
||||
onRenderSuggestionsItem={this._renderSuggestion}
|
||||
onRenderItem={this._renderItem}
|
||||
onChange={this._onSiteSelected}
|
||||
selectedItems={selectedSourceSite ? [selectedSourceSite] : []}
|
||||
itemLimit={1}
|
||||
resolveDelay={500} className={styles.sitePicker} />
|
||||
</>;
|
||||
}
|
||||
|
||||
private _getSitePickerOptions = async (filterText: string): Promise<ISite[]> => {
|
||||
const { resultSourceId } = this.props;
|
||||
|
||||
if(filterText.length <= 2)
|
||||
return [];
|
||||
|
||||
try {
|
||||
const sites = await this._sitesService.search(filterText, resultSourceId);
|
||||
return sites;
|
||||
}
|
||||
catch(error) {
|
||||
this.props.onError(error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private _renderSuggestion = (props: ISite): JSX.Element => {
|
||||
return <div className={styles.SiteSuggestion}>
|
||||
{props.title}<br/>
|
||||
<small>{props.url}</small>
|
||||
</div>;
|
||||
}
|
||||
|
||||
private _renderItem = (props: IPickerItemProps<ISite>): JSX.Element => {
|
||||
return <div className={styles.selectedSite}>
|
||||
{props.item.title}
|
||||
<IconButton iconProps={{ iconName: 'Cancel' }} onClick={this._clearSelection} />
|
||||
</div>;
|
||||
}
|
||||
|
||||
private _onSiteSelected = async (selectedSourceSites: ISite[]): Promise<void> => {
|
||||
const selectedSourceSite = selectedSourceSites ? selectedSourceSites[0] : null;
|
||||
|
||||
this.props.onChange(selectedSourceSite);
|
||||
|
||||
this.setState({ selectedSourceSite });
|
||||
}
|
||||
|
||||
private _clearSelection = (): void => {
|
||||
this.props.onChange(null);
|
||||
|
||||
this.setState({ selectedSourceSite: null });
|
||||
}
|
||||
|
||||
private _loadSite = (): void => {
|
||||
const { defaultValue, onChange, onError } = this.props;
|
||||
const { error } = this.state;
|
||||
|
||||
if (error) {
|
||||
this.props.onError(undefined);
|
||||
}
|
||||
this.setState({ loading: true, error: undefined });
|
||||
|
||||
this._sitesService.get(defaultValue).then(site => {
|
||||
this.setState({ selectedSourceSite: site });
|
||||
onChange(site);
|
||||
}, (error: Error) => {
|
||||
this.setState({ error });
|
||||
onError(error);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/* eslint-disable react/jsx-no-bind */
|
||||
import * as React from 'react';
|
||||
import { IList } from './../interfaces';
|
||||
import { ServiceScope } from '@microsoft/sp-core-library';
|
||||
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||
import { SearchBox } from 'office-ui-fabric-react/lib/SearchBox';
|
||||
import * as strings from 'CopyViewsSharedStrings';
|
||||
import { TargetListPicker } from './TargetListPicker';
|
||||
import { Label } from 'office-ui-fabric-react/lib/Label';
|
||||
import { BaseType } from '../enums';
|
||||
import styles from '../SharedStyles.module.scss';
|
||||
|
||||
interface ITargetListFormProps {
|
||||
serviceScope: ServiceScope;
|
||||
baseType?: BaseType;
|
||||
exclude?: IList;
|
||||
resultSourceId?: string;
|
||||
onSelectionUpdate: (lists?:IList[]) => void;
|
||||
onError: (error: Error) => void;
|
||||
}
|
||||
|
||||
interface ITargetListFormState {
|
||||
searchTerm?: string;
|
||||
selectedLists: IList[];
|
||||
}
|
||||
|
||||
export class TargetListForm extends React.Component<ITargetListFormProps, ITargetListFormState> {
|
||||
private _debouncer: number;
|
||||
|
||||
public constructor(props: ITargetListFormProps) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
selectedLists: []
|
||||
}
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<ITargetListFormProps> {
|
||||
const { serviceScope, baseType, exclude, resultSourceId, onError } = this.props;
|
||||
const { searchTerm } = this.state;
|
||||
|
||||
return <>
|
||||
<Stack tokens={{ childrenGap: 5 }}>
|
||||
<Label>{strings.TargetSearchLabel}</Label>
|
||||
<SearchBox disabled={baseType === undefined} title={strings.TargetSearchPlaceholder} onChange={this._onSearch} onEscape={this._onClearSearch} onClear={this._onClearSearch} className={styles.searchBox} />
|
||||
<TargetListPicker serviceScope={serviceScope} baseType={baseType} exclude={exclude} resultSourceId={resultSourceId} searchTerm={searchTerm} onChange={this._onListsSelected} onError={onError} />
|
||||
</Stack>
|
||||
</>;
|
||||
}
|
||||
|
||||
private _onSearch = (ev: never, searchTerm: string): void => {
|
||||
clearTimeout(this._debouncer);
|
||||
this._debouncer = setTimeout(() => {
|
||||
this.setState({ searchTerm });
|
||||
}, 200);
|
||||
}
|
||||
|
||||
private _onClearSearch = (): void => {
|
||||
this.setState({ searchTerm: null });
|
||||
}
|
||||
|
||||
private _onListsSelected = (lists: IList[]): void => {
|
||||
this.setState({ selectedLists: lists });
|
||||
|
||||
this.props.onSelectionUpdate(lists);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
import * as React from 'react';
|
||||
import styles from './../SharedStyles.module.scss';
|
||||
import { IList } from './../interfaces';
|
||||
import { ServiceScope } from '@microsoft/sp-core-library';
|
||||
import { IListsService, ListsService } from './../services';
|
||||
import * as strings from 'CopyViewsSharedStrings';
|
||||
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||
import { Label } from 'office-ui-fabric-react/lib/Label';
|
||||
import { Checkbox } from 'office-ui-fabric-react/lib/Checkbox';
|
||||
import { BaseType } from '../enums';
|
||||
|
||||
interface ITargetListPickerProps {
|
||||
serviceScope: ServiceScope;
|
||||
baseType?: BaseType;
|
||||
exclude?: IList;
|
||||
searchTerm?: string;
|
||||
resultSourceId?: string;
|
||||
onChange: (lists?:IList[]) => void;
|
||||
onError: (error: Error) => void;
|
||||
}
|
||||
|
||||
interface ITargetListPickerState {
|
||||
foundLists?: IList[];
|
||||
selectedLists: IList[];
|
||||
loading: boolean;
|
||||
error?: boolean;
|
||||
}
|
||||
|
||||
export class TargetListPicker extends React.Component<ITargetListPickerProps, ITargetListPickerState> {
|
||||
private _listsService: IListsService;
|
||||
|
||||
public constructor(props: ITargetListPickerProps) {
|
||||
super(props);
|
||||
|
||||
this._listsService = props.serviceScope.consume(ListsService.serviceKey);
|
||||
|
||||
this.state = {
|
||||
loading: false,
|
||||
selectedLists: []
|
||||
}
|
||||
}
|
||||
|
||||
public componentDidUpdate(prevProps: Readonly<ITargetListPickerProps>): void {
|
||||
if (this.props.baseType !== undefined) {
|
||||
if (prevProps.searchTerm !== this.props.searchTerm
|
||||
|| (prevProps.baseType !== this.props.baseType)
|
||||
|| (prevProps.exclude !== this.props.exclude)) {
|
||||
|
||||
if (prevProps.baseType !== this.props.baseType) {
|
||||
this.setState({ selectedLists: []}, () => {
|
||||
this._searchLists();
|
||||
});
|
||||
}
|
||||
else {
|
||||
this._searchLists();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<ITargetListPickerProps> {
|
||||
const { baseType } = this.props;
|
||||
const { foundLists, selectedLists, loading } = this.state;
|
||||
|
||||
const hiddenSelectedLists = selectedLists?.filter(sl => foundLists.every(fl => fl.uniqueKey !== sl.uniqueKey));
|
||||
const disabled = baseType === undefined;
|
||||
|
||||
return <div>
|
||||
<Label>{strings.SelectListsToCopyViewsTo} {foundLists ? `(${foundLists.length})` : ''}</Label>
|
||||
<div className={styles.checkboxSelectionContainer}>
|
||||
{
|
||||
!disabled && <>
|
||||
{
|
||||
hiddenSelectedLists.length > 0 &&
|
||||
<Stack style={{ marginBottom: 5}} tokens={{ childrenGap: 5 }} id="SelectedLists">
|
||||
{
|
||||
hiddenSelectedLists.map((list) => <><Checkbox key={list.uniqueKey} label={list.title} defaultChecked={true} id={list.uniqueKey} /></>)
|
||||
}
|
||||
</Stack>
|
||||
}
|
||||
{
|
||||
foundLists?.length > 0
|
||||
? <>
|
||||
|
||||
<Stack tokens={{ childrenGap: 5 }} id="FoundLists">
|
||||
{
|
||||
foundLists?.map((list) => <><Checkbox key={list.uniqueKey} label={list.title} id={list.uniqueKey} defaultChecked={selectedLists.some(sl => sl.uniqueKey === list.uniqueKey)} onChange={this._onChangeListSelected} /></>)
|
||||
}
|
||||
</Stack>
|
||||
</>
|
||||
: <em>{!loading && strings.NoListsFound}</em>
|
||||
}
|
||||
</>
|
||||
}
|
||||
</div>
|
||||
</div>;
|
||||
}
|
||||
|
||||
private _onChangeListSelected = (ev?: React.FormEvent<HTMLElement | HTMLInputElement>, checked?: boolean): void => {
|
||||
const { foundLists, selectedLists } = this.state;
|
||||
const uniqueKey = ev.currentTarget.id;
|
||||
const list = foundLists.filter(l => l.uniqueKey === uniqueKey)[0];
|
||||
|
||||
const lists = selectedLists.filter(l => l.uniqueKey !== uniqueKey);
|
||||
|
||||
if (checked) {
|
||||
lists.push(list);
|
||||
}
|
||||
|
||||
this.setState({ selectedLists: lists }, () => {
|
||||
this.props.onChange(lists);
|
||||
});
|
||||
}
|
||||
|
||||
private _searchLists = (): void => {
|
||||
const { searchTerm, resultSourceId, baseType, exclude } = this.props;
|
||||
const { error } = this.state;
|
||||
|
||||
if (error) {
|
||||
this.props.onError(undefined);
|
||||
}
|
||||
this.setState({ loading: true, error: undefined });
|
||||
|
||||
this._listsService.search(baseType, searchTerm, resultSourceId).then(foundLists => {
|
||||
|
||||
this.setState({ loading: false, foundLists: foundLists.filter(l => l.uniqueKey !== exclude.uniqueKey) });
|
||||
}, (error) => {
|
||||
this.setState({ error });
|
||||
this.props.onError(error);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
export { CopyViewsContainer } from './CopyViewsContainer';
|
||||
export { SourceListPicker } from './SourceListPicker';
|
||||
export { SourceListViewForm } from './SourceListViewForm';
|
||||
export { SourceListViewPicker } from './SourceListViewPicker';
|
||||
export { SourceSitePicker } from './SourceSitePicker';
|
||||
export { TargetListForm } from './TargetListForm';
|
||||
export { TargetListPicker } from './TargetListPicker';
|
||||
export { CopyStatus } from './CopyStatus';
|
|
@ -0,0 +1,11 @@
|
|||
export enum BaseType {
|
||||
GenericList = 0,
|
||||
DocumentLibrary = 1
|
||||
}
|
||||
|
||||
export enum CopyTaskState {
|
||||
None = 0,
|
||||
Busy = 1,
|
||||
Error = 2,
|
||||
Done = 3
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
import { BaseType, CopyTaskState } from "./enums";
|
||||
import { ISearchResult } from "@pnp/sp/search";
|
||||
|
||||
export interface ICopyTask {
|
||||
index: number;
|
||||
sourceView: IListView;
|
||||
targetList: IList;
|
||||
state: CopyTaskState;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface IList {
|
||||
title: string;
|
||||
id: string;
|
||||
type: BaseType;
|
||||
siteUrl: string;
|
||||
listUrl: string;
|
||||
siteTitle?: string;
|
||||
uniqueKey?: string;
|
||||
}
|
||||
|
||||
export interface IListSearchResult extends ISearchResult {
|
||||
BaseType: string;
|
||||
ListUrl: string;
|
||||
SPSiteURL: string;
|
||||
SiteTitle: string;
|
||||
SiteId: string;
|
||||
ListId: string;
|
||||
}
|
||||
|
||||
export interface IListView {
|
||||
id: string;
|
||||
title: string;
|
||||
viewUrl:string;
|
||||
// eslint-disable-next-line @rushstack/no-new-null
|
||||
viewType: "KANBAN" | "TILES" | "COMPACTLIST" | "MODERNCALENDAR" | null;
|
||||
fileName: string;
|
||||
listId: string;
|
||||
listBaseType: BaseType;
|
||||
siteUrl: string;
|
||||
}
|
||||
|
||||
export interface ISite {
|
||||
title: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
|
||||
export interface IDefaults {
|
||||
viewId?: string;
|
||||
listId?: string;
|
||||
siteUrl?: string;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"CopyViews": "Copy views",
|
||||
"CopyStatus": "Copy views - status",
|
||||
"NoOptions": "No sites found with '{0}'",
|
||||
"NoOptionsMinimumChars": "Enter at least 3 characters to search a site",
|
||||
"SearchAndSelectSourceSite": "Search and select a SharePoint site",
|
||||
"SelectAList": "Select a list or library",
|
||||
"ListHeader": "Lists",
|
||||
"LibraryHeader": "Libraries",
|
||||
"SelectViewsToCopy": "Select one or more views to copy",
|
||||
"SelectASiteAndList": "Select a site and list first",
|
||||
|
||||
"TargetSearchLabel": "Search lists by title or site title",
|
||||
"TargetSearchPlaceholder": "Enter search term and press enter",
|
||||
"SelectListsToCopyViewsTo": "Select target lists",
|
||||
"NoListsFound": "No lists found",
|
||||
"Copy": "Copy",
|
||||
"OK": "OK",
|
||||
"ErrorOccurred": "An error occurred",
|
||||
"SeeMore": "See more",
|
||||
"Retry": "Retry",
|
||||
"SetAsDefaultView": "Set as default view",
|
||||
"ViewTypeNotSupported": "Board and calendar views are currently not supported",
|
||||
"CopyTask": "View to copy",
|
||||
"BusyCopyingViews": "Busy copying views",
|
||||
"DoneCopyingViews": "Done copying views",
|
||||
"CopyAnotherView": "Copy another view",
|
||||
"CloseDialog": "Close"
|
||||
}
|
||||
});
|
|
@ -0,0 +1,32 @@
|
|||
declare interface ICopyViewsSharedStrings {
|
||||
CopyViews: string;
|
||||
NoOptions: string;
|
||||
NoOptionsMinimumChars: string;
|
||||
SearchAndSelectSourceSite: string;
|
||||
SelectAList: string;
|
||||
ListHeader: string;
|
||||
LibraryHeader: string;
|
||||
SelectViewsToCopy: string;
|
||||
SelectASiteAndList: string;
|
||||
|
||||
TargetSearchLabel: string;
|
||||
TargetSearchPlaceholder: string;
|
||||
SelectListsToCopyViewsTo: string;
|
||||
NoListsFound: string;
|
||||
Copy: string;
|
||||
ErrorOccurred: string;
|
||||
SeeMore: string;
|
||||
Retry: string;
|
||||
SetAsDefaultView: string;
|
||||
ViewTypeNotSupported: string;
|
||||
CopyStatus: string;
|
||||
BusyCopyingViews: string;
|
||||
DoneCopyingViews: string;
|
||||
CopyAnotherView: string;
|
||||
CloseDialog: string;
|
||||
}
|
||||
|
||||
declare module 'CopyViewsSharedStrings' {
|
||||
const strings: ICopyViewsSharedStrings;
|
||||
export = strings;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"CopyViews": "Views kopiëren",
|
||||
"CopyStatus": "Views kopiëren - status",
|
||||
"NoOptions": "Geen sites gevonden met '{0}'",
|
||||
"NoOptionsMinimumChars": "Voer minimaal 3 karakters in om een site te zoeken",
|
||||
"SearchAndSelectSourceSite": "Zoek en selecteer een SharePoint site",
|
||||
"SelectAList": "Selecteer een lijst of bibliotheek",
|
||||
"ListHeader": "Lijsten",
|
||||
"LibraryHeader": "Bibliotheken",
|
||||
"SelectViewsToCopy": "Selecteer één of meerdere weergaven om te kopiëren",
|
||||
"SelectASiteAndList": "Selecteer eerst een site en lijst",
|
||||
|
||||
"TargetSearchLabel": "Zoek lijsten op titel en site titel",
|
||||
"TargetSearchPlaceholder": "Voer zoekterm in en druk op enter",
|
||||
"SelectListsToCopyViewsTo": "Selecteer doellijsten",
|
||||
"NoListsFound": "Geen lijsten gevonden",
|
||||
"Copy": "Kopiëren",
|
||||
"OK": "OK",
|
||||
"ErrorOccurred": "Er is een fout opgetreden",
|
||||
"SeeMore": "Meer lezen",
|
||||
"Retry": "Opnieuw",
|
||||
"SetAsDefaultView": "Instellen als default view",
|
||||
"ViewTypeNotSupported": "Board en calendar views worden momenteel niet gesupport",
|
||||
"BusyCopyingViews": "Bezig met kopiëren van views",
|
||||
"DoneCopyingViews": "Klaar met kopiëren van views",
|
||||
"CopyAnotherView": "Nog een view kopiëren",
|
||||
"CloseDialog": "Sluiten"
|
||||
}
|
||||
});
|
|
@ -0,0 +1,19 @@
|
|||
import { TimelinePipe } from "@pnp/core";
|
||||
import { Queryable } from "@pnp/queryable";
|
||||
|
||||
export function CacheBust(): TimelinePipe<Queryable> {
|
||||
|
||||
return (instance: Queryable) => {
|
||||
|
||||
instance.on.pre(async (url, init, result) => {
|
||||
|
||||
url += url.indexOf("?") > -1 ? "&" : "?";
|
||||
|
||||
url += "nonce=" + encodeURIComponent(new Date().toISOString());
|
||||
|
||||
return [url, init, result];
|
||||
});
|
||||
|
||||
return instance;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,218 @@
|
|||
import "@pnp/sp/fields/list";
|
||||
import "@pnp/sp/lists";
|
||||
import "@pnp/sp/views";
|
||||
import "@pnp/sp/webs";
|
||||
import { ServiceKey, ServiceScope } from "@microsoft/sp-core-library";
|
||||
import { PageContext } from "@microsoft/sp-page-context";
|
||||
import { RequestDigest, spfi, SPFI, SPFx } from "@pnp/sp";
|
||||
import { IListInfo } from "@pnp/sp/lists";
|
||||
import { IView, IViewInfo } from "@pnp/sp/views";
|
||||
import { Web } from "@pnp/sp/webs";
|
||||
import { CacheBust } from "./CacheBust";
|
||||
import { IListView } from "../interfaces";
|
||||
|
||||
export interface IListViewsService {
|
||||
get: (siteUrl: string, listId: string) => Promise<IListView[]>;
|
||||
copy: (sourceView: IListView, targetSiteUrl: string, targetListId: string, setAsDefaultView: boolean) => Promise<void>;
|
||||
}
|
||||
|
||||
export class ListViewsService implements IListViewsService {
|
||||
|
||||
public static readonly serviceKey: ServiceKey<IListViewsService> =
|
||||
ServiceKey.create<IListViewsService>('SPFx:ListViewsService', ListViewsService);
|
||||
|
||||
private _sp: SPFI;
|
||||
|
||||
public constructor(serviceScope: ServiceScope) {
|
||||
serviceScope.whenFinished(() => {
|
||||
const pageContext = serviceScope.consume(PageContext.serviceKey);
|
||||
|
||||
/*
|
||||
* About RequestDigest():
|
||||
* Include RequestDigest() to ensure a correct X-RequestDigest header value is present.
|
||||
* This is necessary because of a bug in SPFx, where an old pageContext can be consumed after refreshing the page.
|
||||
*
|
||||
* About CacheBust():
|
||||
* This ensures that every call has a unique URL, to override browser caching.
|
||||
*/
|
||||
this._sp = spfi().using(RequestDigest(), SPFx({ pageContext }), CacheBust());
|
||||
});
|
||||
}
|
||||
|
||||
public async get(siteUrl: string, listId: string): Promise<IListView[]> {
|
||||
|
||||
const web = Web([this._sp.web, siteUrl]);
|
||||
|
||||
const views = await web.lists.getById(listId).views.select("Id", "Title", "ServerRelativeUrl", "ViewType2")();
|
||||
|
||||
return views.map((view: IViewInfo) => {
|
||||
const viewFileName = view.ServerRelativeUrl.substring(view.ServerRelativeUrl.lastIndexOf('/') + 1);
|
||||
|
||||
return {
|
||||
id: view.Id,
|
||||
title: view.Title,
|
||||
viewUrl: view.ServerRelativeUrl,
|
||||
viewType: view.ViewType2,
|
||||
fileName: viewFileName,
|
||||
listId,
|
||||
siteUrl
|
||||
} as IListView;
|
||||
});
|
||||
}
|
||||
|
||||
public async copy(sourceView: IListView, targetSiteUrl: string, targetListId: string, setAsDefaultView: boolean): Promise<void> {
|
||||
const sourceWeb = Web([this._sp.web, sourceView.siteUrl]);
|
||||
const sourceList = sourceWeb.lists.getById(sourceView.listId);
|
||||
const sourceViewInfo = await sourceList.getView(sourceView.id)();
|
||||
const sourceViewFields = await sourceList.getView(sourceView.id).fields();
|
||||
|
||||
const targetWeb = Web([this._sp.web, targetSiteUrl]);
|
||||
const targetList = targetWeb.lists.getById(targetListId);
|
||||
const targetListInfo = await targetList.expand("Views", "Fields").select("Views/Id", "Views/ServerRelativeUrl", "Fields/InternalName")();
|
||||
|
||||
const targetView = targetListInfo.Views.filter(view => {
|
||||
const viewFileName = view.ServerRelativeUrl.substring(view.ServerRelativeUrl.lastIndexOf('/') + 1);
|
||||
return viewFileName === sourceView.fileName;
|
||||
})[0];
|
||||
|
||||
const properties = this._buildProperties(sourceViewInfo as IViewInfo, targetListInfo, setAsDefaultView);
|
||||
|
||||
if (!targetView) {
|
||||
const viewAddResult = await targetList.views.add(sourceView.title, false, properties);
|
||||
|
||||
await this._updateViewFields(viewAddResult.view, sourceViewFields, targetListInfo);
|
||||
}
|
||||
else {
|
||||
const viewUpdateResult = await targetList.views.getById(targetView.Id).update(properties);
|
||||
|
||||
await this._updateViewFields(viewUpdateResult.view, sourceViewFields, targetListInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private _buildProperties = (sourceView: IViewInfo, targetList: IListInfo, setAsDefaultView: boolean): IViewInfo => {
|
||||
const properties = {
|
||||
CustomFormatter: sourceView.CustomFormatter,
|
||||
RowLimit: sourceView.RowLimit,
|
||||
Hidden: sourceView.Hidden,
|
||||
IncludeRootFolder: sourceView.IncludeRootFolder,
|
||||
JSLink: sourceView.JSLink,
|
||||
Paged: sourceView.Paged,
|
||||
Scope: sourceView.Scope,
|
||||
TabularView: sourceView.TabularView,
|
||||
Title: sourceView.Title,
|
||||
ViewQuery: this._buildViewQuery(sourceView, targetList),
|
||||
ViewType2: sourceView.ViewType2
|
||||
} as IViewInfo;
|
||||
|
||||
if (setAsDefaultView) {
|
||||
properties.DefaultView = true;
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
/*
|
||||
* Builds a new ViewQuery based on the source ViewQuery and the available fields on the target list.
|
||||
*/
|
||||
private _buildViewQuery = (sourceView: IViewInfo, targetList: IListInfo): string => {
|
||||
|
||||
const domParser = new DOMParser();
|
||||
const sourceViewDoc = domParser.parseFromString("<Root>" + sourceView.ViewQuery + "</Root>", "text/xml");
|
||||
const elementsToRemove = this._getFieldRefsToRemove(sourceViewDoc, targetList);
|
||||
|
||||
if (elementsToRemove.length === 0) {
|
||||
return sourceView.ViewQuery;
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < elementsToRemove.length; i++) {
|
||||
this._recursiveDeleteElement(elementsToRemove[i]);
|
||||
}
|
||||
|
||||
this._ensureOrderByElement(sourceViewDoc);
|
||||
this._fixAndOrConditions(sourceViewDoc);
|
||||
|
||||
return sourceViewDoc.firstElementChild.innerHTML;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get all FieldRef elements that can be removed from the ViewQuery.
|
||||
* If fields are in the ViewQuery that are not available in the targetList, they are removed.
|
||||
* Also includes their corresponding Value elements in the where condition
|
||||
*/
|
||||
private _getFieldRefsToRemove = (sourceViewDoc: Document, targetList: IListInfo): Element[] => {
|
||||
const elementsToRemove: Element[] = [];
|
||||
const fieldRefs = sourceViewDoc.getElementsByTagName("FieldRef");
|
||||
|
||||
for (let i = 0; i < fieldRefs.length; i++) {
|
||||
if (targetList.Fields.every(field => field.InternalName !== fieldRefs[i].getAttribute("Name"))) {
|
||||
elementsToRemove.push(fieldRefs[i]);
|
||||
|
||||
if (fieldRefs[i].nextElementSibling && fieldRefs[i].nextElementSibling.nodeName === "Value") {
|
||||
elementsToRemove.push(fieldRefs[i].nextElementSibling);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return elementsToRemove;
|
||||
}
|
||||
|
||||
/*
|
||||
* Deletes the referenced element and also any parent element that is left without children.
|
||||
*/
|
||||
private _recursiveDeleteElement = (element: Element): void => {
|
||||
const parentElement = element.parentElement;
|
||||
parentElement.removeChild(element);
|
||||
|
||||
if (!parentElement.hasChildNodes()) {
|
||||
this._recursiveDeleteElement(parentElement);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If the OrderBy element contained Fields that are not available on the TargetList, the OrderBy element will have been empty and removed.
|
||||
* This function ensures that a default OrderBy element is created.
|
||||
*/
|
||||
private _ensureOrderByElement = (sourceViewDoc: Document): void => {
|
||||
if (sourceViewDoc.getElementsByTagName("OrderBy").length === 0) {
|
||||
sourceViewDoc.firstElementChild.innerHTML = "<OrderBy><FieldRef Name=\"ID\" Ascending=\"TRUE\"/></OrderBy>" + sourceViewDoc.firstElementChild.innerHTML;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If any And/Or element has been left with a single condition, replace it with that condition.
|
||||
*/
|
||||
private _fixAndOrConditions = (sourceViewDoc: Document): void => {
|
||||
this._fixConditions(sourceViewDoc, "And");
|
||||
this._fixConditions(sourceViewDoc, "Or");
|
||||
}
|
||||
|
||||
private _fixConditions = (sourceViewDoc: Document, condition: string): void => {
|
||||
const elements = sourceViewDoc.getElementsByTagName(condition);
|
||||
|
||||
for (let i = 0; i < elements.length; i++) {
|
||||
if (elements[i].childElementCount === 1) {
|
||||
elements[i].replaceWith(elements[i].firstChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _updateViewFields = async (targetView: IView, sourceViewFields: { Items: string[]; SchemaXml: string; }, targetList: IListInfo): Promise<void> => {
|
||||
|
||||
const viewFields: string[] = [];
|
||||
sourceViewFields.Items.forEach(item => {
|
||||
if (targetList.Fields.some(field => field.InternalName === item)) {
|
||||
viewFields.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (viewFields.length > 0) {
|
||||
await targetView.fields.removeAll();
|
||||
|
||||
for (let i = 0; i < viewFields.length; i++) {
|
||||
await targetView.fields.add(viewFields[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
import "@pnp/sp/lists";
|
||||
import "@pnp/sp/search";
|
||||
import "@pnp/sp/webs";
|
||||
import { ServiceKey, ServiceScope } from "@microsoft/sp-core-library";
|
||||
import { PageContext } from "@microsoft/sp-page-context";
|
||||
import { RequestDigest, spfi, SPFI, SPFx } from "@pnp/sp";
|
||||
import { ISearchQuery, SortDirection } from "@pnp/sp/search";
|
||||
import { Web } from "@pnp/sp/webs";
|
||||
import { startsWith } from "lodash";
|
||||
import { BaseType } from "../enums";
|
||||
import { CacheBust } from "./CacheBust";
|
||||
import { IList, IListSearchResult } from "../interfaces";
|
||||
|
||||
export interface IListsService {
|
||||
get: (siteUrl: string) => Promise<IList[]>;
|
||||
search: (baseType: BaseType, searchTerm?: string, resultSourceId?: string) => Promise<IList[]>;
|
||||
}
|
||||
|
||||
export class ListsService implements IListsService {
|
||||
|
||||
public static readonly serviceKey: ServiceKey<IListsService> =
|
||||
ServiceKey.create<IListsService>('SPFx:ListsService', ListsService);
|
||||
|
||||
private _sp: SPFI;
|
||||
|
||||
public constructor(serviceScope: ServiceScope) {
|
||||
serviceScope.whenFinished(() => {
|
||||
const pageContext = serviceScope.consume(PageContext.serviceKey);
|
||||
|
||||
/*
|
||||
* About RequestDigest():
|
||||
* Include RequestDigest() to ensure a correct X-RequestDigest header value is present.
|
||||
* This is necessary because of a bug in SPFx, where an old pageContext can be consumed after refreshing the page.
|
||||
*
|
||||
* About CacheBust():
|
||||
* This ensures that every call has a unique URL, to override browser caching.
|
||||
*/
|
||||
this._sp = spfi().using(RequestDigest(), SPFx({ pageContext }), CacheBust());
|
||||
});
|
||||
}
|
||||
|
||||
public async get(siteUrl: string): Promise<IList[]> {
|
||||
|
||||
const web = Web([this._sp.web, siteUrl])
|
||||
|
||||
const filterConditions = [
|
||||
"IsApplicationList eq false", // Don't get application lists
|
||||
"Hidden eq false", // Don't get hidden lists
|
||||
"BaseTemplate le 101", // Only get libraries and lists based on the regular templates
|
||||
"EntityTypeName ne 'Style_x0020_Library'", // Exclude the Style library
|
||||
"EntityTypeName ne 'FormServerTemplates'" // Exclude the Form Templates library
|
||||
];
|
||||
|
||||
const lists = await web.lists.expand("RootFolder").select("Id", "Title", "BaseType", "RootFolder/ServerRelativeUrl").filter(filterConditions.join(" and "))();
|
||||
|
||||
return lists
|
||||
.filter(l => l.BaseType === 1 || l.BaseType === 0)
|
||||
.map(l => { return { title: l.Title, id: l.Id, type: l.BaseType as BaseType, siteUrl, listUrl: l.RootFolder.ServerRelativeUrl } as IList; });
|
||||
}
|
||||
|
||||
public async search(baseType: BaseType, searchTerm?: string, resultSourceId?: string): Promise<IList[]> {
|
||||
|
||||
const queryConditions = [
|
||||
`ContentClass:${baseType === BaseType.DocumentLibrary ? 'STS_List_DocumentLibrary' : 'STS_List_GenericList'}`,
|
||||
`-ListUrl:FormServerTemplates`,
|
||||
`-ListUrl:/SiteAssets/`,
|
||||
`-ListUrl:"Style Library"`,
|
||||
`-ListUrl:"SitePages"`
|
||||
];
|
||||
|
||||
if (searchTerm) {
|
||||
queryConditions.push(`${searchTerm}*`);
|
||||
}
|
||||
|
||||
const searchQuery = {
|
||||
Querytext: queryConditions.join(' '),
|
||||
RowLimit: 500,
|
||||
SourceId: resultSourceId && resultSourceId !== "" ? resultSourceId : undefined,
|
||||
TrimDuplicates: false,
|
||||
EnableSorting: true,
|
||||
SortList: [{ Property: 'SPSiteURL', Direction: SortDirection.Ascending }],
|
||||
SelectProperties: ["ListId", "Title", "ListUrl", "SPSiteURL", "SiteId", "SiteTitle", "BaseType"]
|
||||
} as ISearchQuery;
|
||||
|
||||
const results = await this._sp.search(searchQuery);
|
||||
|
||||
const mappedResults: IList[] = [];
|
||||
|
||||
results.PrimarySearchResults.forEach(r => {
|
||||
const result = r as IListSearchResult;
|
||||
|
||||
// Some libraries have the same listId across site collections, therefore we combine siteId and listid for a uniqueId
|
||||
const uniqueKey = result.SiteId + "_" + result.ListId;
|
||||
|
||||
if (mappedResults.every(r => r.uniqueKey !== uniqueKey)) {
|
||||
mappedResults.push({
|
||||
id: result.ListId,
|
||||
uniqueKey: uniqueKey,
|
||||
title: startsWith(result.Title, `${result.SiteTitle} - `, 0) ? result.Title : `${result.SiteTitle} - ${result.Title}`,
|
||||
type: this._getTypeFromString(result.BaseType),
|
||||
listUrl: result.ListUrl,
|
||||
siteUrl: result.SPSiteURL,
|
||||
siteTitle: result.SiteTitle
|
||||
} as IList);
|
||||
}
|
||||
});
|
||||
|
||||
return mappedResults.sort((a, b) => {
|
||||
if (a.siteUrl < b.siteUrl) { return -1; } else if (a.siteUrl > b.siteUrl) { return 1; } else { return 0; }
|
||||
});
|
||||
}
|
||||
|
||||
private _getTypeFromString(baseTypeString: string): BaseType {
|
||||
switch (baseTypeString) {
|
||||
case "GenericList":
|
||||
return BaseType.GenericList;
|
||||
case "DocumentLibrary":
|
||||
return BaseType.DocumentLibrary;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
import "@pnp/sp/search";
|
||||
import "@pnp/sp/webs";
|
||||
import { ServiceKey, ServiceScope } from "@microsoft/sp-core-library";
|
||||
import { PageContext } from "@microsoft/sp-page-context";
|
||||
import { RequestDigest, spfi, SPFI, SPFx } from "@pnp/sp";
|
||||
import { ISearchQuery } from "@pnp/sp/search";
|
||||
import { Web } from "@pnp/sp/webs";
|
||||
import { CacheBust } from "./CacheBust";
|
||||
import { ISite } from "../interfaces";
|
||||
|
||||
export interface ISitesService {
|
||||
get: (url: string) => Promise<ISite>;
|
||||
search: (searchTerm: string, resultSourceId?: string) => Promise<ISite[]>;
|
||||
}
|
||||
|
||||
export class SitesService implements ISitesService {
|
||||
|
||||
public static readonly serviceKey: ServiceKey<ISitesService> =
|
||||
ServiceKey.create<ISitesService>('SPFx:SitesService', SitesService);
|
||||
|
||||
private _sp: SPFI;
|
||||
|
||||
public constructor(serviceScope: ServiceScope) {
|
||||
serviceScope.whenFinished(() => {
|
||||
const pageContext = serviceScope.consume(PageContext.serviceKey);
|
||||
|
||||
/*
|
||||
* About RequestDigest():
|
||||
* Include RequestDigest() to ensure a correct X-RequestDigest header value is present.
|
||||
* This is necessary because of a bug in SPFx, where an old pageContext can be consumed after refreshing the page.
|
||||
*
|
||||
* About CacheBust():
|
||||
* This ensures that every call has a unique URL, to override browser caching.
|
||||
*/
|
||||
this._sp = spfi().using(RequestDigest(), SPFx({ pageContext }), CacheBust());
|
||||
});
|
||||
}
|
||||
|
||||
public async get(url: string): Promise<ISite> {
|
||||
const web = Web([this._sp.web, url]);
|
||||
|
||||
const webInfo = await web.select("Title")();
|
||||
|
||||
return {
|
||||
title: webInfo.Title,
|
||||
url: url
|
||||
}
|
||||
}
|
||||
|
||||
public async search(searchTerm: string, resultSourceId?: string): Promise<ISite[]> {
|
||||
const searchQuery = {
|
||||
Querytext: `"${searchTerm}*" contentclass:STS_Site`,
|
||||
RowLimit: 500,
|
||||
SourceId: resultSourceId,
|
||||
TrimDuplicates: false,
|
||||
SelectProperties: ["Title", "Path"]
|
||||
} as ISearchQuery;
|
||||
|
||||
const results = await this._sp.search(searchQuery);
|
||||
|
||||
return results.PrimarySearchResults.map(r => { return { title: r.Title, url: r.Path } as ISite; });
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export * from "./SitesService";
|
||||
export * from "./ListsService";
|
||||
export * from "./ListViewsService";
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||
"id": "1f59d413-5f43-41a1-bd36-a01403f89c4b",
|
||||
"alias": "CopyViewsWebPart",
|
||||
"componentType": "WebPart",
|
||||
"version": "*",
|
||||
"manifestVersion": 2,
|
||||
"requiresCustomScript": false,
|
||||
"supportedHosts": ["SharePointWebPart", "TeamsPersonalApp", "TeamsTab", "SharePointFullPage"],
|
||||
"supportsThemeVariants": true,
|
||||
|
||||
"preconfiguredEntries": [{
|
||||
"groupId": "5c03119e-3074-46fd-976b-c60198311f70",
|
||||
"group": { "default": "Other", "nl-nl": "Overige" },
|
||||
"title": { "default": "Copy views", "nl-nl": "Weergaven kopiëren" },
|
||||
"description": { "default": "Copy views from one list to another.", "nl-nl": "Weergaven kopiëren van één lijst naar een andere." },
|
||||
"officeFabricIconFontName": "Page",
|
||||
"properties": {
|
||||
}
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
import { IReadonlyTheme } from '@microsoft/sp-component-base';
|
||||
import { Version } from '@microsoft/sp-core-library';
|
||||
import { IPropertyPaneConfiguration, PropertyPaneTextField } from '@microsoft/sp-property-pane';
|
||||
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
|
||||
import * as strings from 'CopyViewsWebPartStrings';
|
||||
import * as React from 'react';
|
||||
import * as ReactDom from 'react-dom';
|
||||
import { IDefaults } from '../../shared/interfaces';
|
||||
import CopyViews, { ICopyViewsProps } from './components/CopyViews';
|
||||
|
||||
export interface ICopyViewsWebPartProps {
|
||||
resultSourceId?: string;
|
||||
}
|
||||
|
||||
export default class CopyViewsWebPart extends BaseClientSideWebPart<ICopyViewsWebPartProps> {
|
||||
|
||||
private _isDarkTheme: boolean = false;
|
||||
private _environmentMessage: string = '';
|
||||
|
||||
public render(): void {
|
||||
const defaultValues = {
|
||||
siteUrl: this.context.pageContext.site.absoluteUrl
|
||||
} as IDefaults;
|
||||
|
||||
|
||||
const element: React.ReactElement<ICopyViewsProps> = React.createElement(
|
||||
CopyViews,
|
||||
{
|
||||
resultSourceId: this.properties.resultSourceId,
|
||||
serviceScope: this.context.serviceScope,
|
||||
defaultValues: defaultValues,
|
||||
isDarkTheme: this._isDarkTheme,
|
||||
environmentMessage: this._environmentMessage,
|
||||
hasTeamsContext: !!this.context.sdks.microsoftTeams,
|
||||
userDisplayName: this.context.pageContext.user.displayName
|
||||
}
|
||||
);
|
||||
|
||||
ReactDom.render(element, this.domElement);
|
||||
}
|
||||
|
||||
protected async onInit(): Promise<void> {
|
||||
this._environmentMessage = this._getEnvironmentMessage();
|
||||
|
||||
await super.onInit();
|
||||
}
|
||||
|
||||
private _getEnvironmentMessage(): string {
|
||||
if (!!this.context.sdks.microsoftTeams) { // running in Teams
|
||||
return this.context.isServedFromLocalhost ? strings.AppLocalEnvironmentTeams : strings.AppTeamsTabEnvironment;
|
||||
}
|
||||
|
||||
return this.context.isServedFromLocalhost ? strings.AppLocalEnvironmentSharePoint : strings.AppSharePointEnvironment;
|
||||
}
|
||||
|
||||
protected onThemeChanged(currentTheme: IReadonlyTheme | undefined): void {
|
||||
if (!currentTheme) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._isDarkTheme = !!currentTheme.isInverted;
|
||||
const {
|
||||
semanticColors
|
||||
} = currentTheme;
|
||||
|
||||
if (semanticColors) {
|
||||
this.domElement.style.setProperty('--bodyText', semanticColors.bodyText || null);
|
||||
this.domElement.style.setProperty('--link', semanticColors.link || null);
|
||||
this.domElement.style.setProperty('--linkHovered', semanticColors.linkHovered || null);
|
||||
}
|
||||
}
|
||||
|
||||
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||
return {
|
||||
pages: [
|
||||
{
|
||||
header: {
|
||||
description: strings.PropertyPaneDescription
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
groupName: strings.SearchSettingsGroupName,
|
||||
groupFields: [
|
||||
PropertyPaneTextField('resultSourceId', {
|
||||
label: strings.ResultSourceIdFieldLabel
|
||||
})
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
protected onDispose(): void {
|
||||
ReactDom.unmountComponentAtNode(this.domElement);
|
||||
}
|
||||
|
||||
protected get dataVersion(): Version {
|
||||
return Version.parse('1.0');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
@import '~office-ui-fabric-react/dist/sass/References.scss';
|
||||
|
||||
.copyViews {
|
||||
padding: 1em;
|
||||
color: "[theme:bodyText, default: #323130]";
|
||||
color: var(--bodyText);
|
||||
&.teams {
|
||||
font-family: $ms-font-family-fallbacks;
|
||||
}
|
||||
}
|
||||
|
||||
.fieldSetLegend {
|
||||
background-color: "[theme:themePrimary, default: lime]";
|
||||
color: "[theme:white, default: #ffffff]";
|
||||
padding: 3px 6px;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
import { ServiceScope } from '@microsoft/sp-core-library';
|
||||
import * as React from 'react';
|
||||
import styles from './CopyViews.module.scss';
|
||||
import { CopyViewsContainer } from '../../../shared/components';
|
||||
import { IDefaults } from '../../../shared/interfaces';
|
||||
|
||||
export interface ICopyViewsProps {
|
||||
resultSourceId?: string;
|
||||
serviceScope: ServiceScope;
|
||||
defaultValues?: IDefaults;
|
||||
isDarkTheme: boolean;
|
||||
environmentMessage: string;
|
||||
hasTeamsContext: boolean;
|
||||
userDisplayName: string;
|
||||
}
|
||||
|
||||
export default class CopyViews extends React.Component<ICopyViewsProps, {}> {
|
||||
|
||||
public render(): React.ReactElement<ICopyViewsProps> {
|
||||
const { serviceScope, resultSourceId, hasTeamsContext, defaultValues } = this.props;
|
||||
|
||||
return (
|
||||
<div className={hasTeamsContext ? styles.teams : ''}>
|
||||
<CopyViewsContainer serviceScope={serviceScope} defaultValues={defaultValues} resultSourceId={resultSourceId} onCopied={this._onCopied} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
private _onCopied = ():void => {
|
||||
//
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"PropertyPaneDescription": "The place to edit basic webpart settings.",
|
||||
"SearchSettingsGroupName": "Search settings",
|
||||
"ResultSourceIdFieldLabel": "Result source Id",
|
||||
"AppLocalEnvironmentSharePoint": "The app is running on your local environment as SharePoint web part",
|
||||
"AppLocalEnvironmentTeams": "The app is running on your local environment as Microsoft Teams app",
|
||||
"AppSharePointEnvironment": "The app is running on SharePoint page",
|
||||
"AppTeamsTabEnvironment": "The app is running in Microsoft Teams"
|
||||
}
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
declare interface ICopyViewsWebPartStrings {
|
||||
PropertyPaneDescription: string;
|
||||
SearchSettingsGroupName: string;
|
||||
ResultSourceIdFieldLabel: string;
|
||||
AppLocalEnvironmentSharePoint: string;
|
||||
AppLocalEnvironmentTeams: string;
|
||||
AppSharePointEnvironment: string;
|
||||
AppTeamsTabEnvironment: string;
|
||||
}
|
||||
|
||||
declare module 'CopyViewsWebPartStrings' {
|
||||
const strings: ICopyViewsWebPartStrings;
|
||||
export = strings;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"PropertyPaneDescription": "De plek om basale webpart instellingen aan te passen.",
|
||||
"SearchSettingsGroupName": "Search instellingen",
|
||||
"ResultSourceIdFieldLabel": "Result source Id",
|
||||
"AppLocalEnvironmentSharePoint": "The app is running on your local environment as SharePoint web part",
|
||||
"AppLocalEnvironmentTeams": "The app is running on your local environment as Microsoft Teams app",
|
||||
"AppSharePointEnvironment": "The app is running on SharePoint page",
|
||||
"AppTeamsTabEnvironment": "The app is running in Microsoft Teams"
|
||||
}
|
||||
});
|
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
After Width: | Height: | Size: 542 B |
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
After Width: | Height: | Size: 542 B |
|
@ -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",
|
||||
"noImplicitAny": true,
|
||||
"jsx": "react",
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": true,
|
||||
"outDir": "lib",
|
||||
"inlineSources": false,
|
||||
"strictNullChecks": false,
|
||||
"noUnusedLocals": false,
|
||||
"typeRoots": [
|
||||
"./node_modules/@types",
|
||||
"./node_modules/@microsoft"
|
||||
],
|
||||
"types": [
|
||||
"webpack-env"
|
||||
],
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.collection",
|
||||
"es2015.promise"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.tsx"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue