Merge pull request #4752 from Paxol/paxol/react-organization-chart

react-organization-chart: Added guest filter + update to latest sharepoint web part template
This commit is contained in:
Hugo Bernier 2024-03-10 13:52:35 -04:00 committed by GitHub
commit 40a35a2329
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
38 changed files with 31407 additions and 18103 deletions

View File

@ -1,39 +1,38 @@
// For more information on how to run this SPFx project in a VS Code Remote Container, please visit https://aka.ms/spfx-devcontainer
{
"name": "SPFx 1.4.1",
"image": "docker.io/m365pnp/spfx:1.4.1",
// Set *default* container specific settings.json values on container create.
"settings": {},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
4321,
35729,
5432
],
"portsAttributes": {
"4321": {
"protocol": "https",
"label": "Manifest",
"onAutoForward": "silent",
"requireLocalPort": true
},
"5432": {
"protocol": "https",
"label": "Workbench",
"onAutoForward": "silent"
},
"35729": {
"protocol": "https",
"label": "LiveReload",
"onAutoForward": "silent",
"requireLocalPort": true
}
},
"postCreateCommand": "bash .devcontainer/spfx-startup.sh",
"remoteUser": "node"
}
"name": "SPFx 1.18.2",
"image": "docker.io/m365pnp/spfx:1.18.2",
"customizations": {
"vscode": {
"extensions": [
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint"
]
}
},
"forwardPorts": [
4321,
35729,
5432
],
"portsAttributes": {
"4321": {
"protocol": "https",
"label": "Manifest",
"onAutoForward": "silent",
"requireLocalPort": true
},
"5432": {
"protocol": "https",
"label": "Workbench",
"onAutoForward": "silent"
},
"35729": {
"protocol": "https",
"label": "LiveReload",
"onAutoForward": "silent",
"requireLocalPort": true
}
},
"postCreateCommand": "bash .devcontainer/spfx-startup.sh",
"remoteUser": "node"
}

View File

@ -7,9 +7,11 @@ echo
echo -e "\e[1;94mGenerating dev certificate\e[0m"
gulp trust-dev-cert
# Convert the generated PEM certificate to a CER certificate
openssl x509 -inform PEM -in ~/.rushstack/rushstack-serve.pem -outform DER -out ./spfx-dev-cert.cer
cp ~/.gcb-serve-data/gcb-serve.cer ./spfx-dev-cert.cer
cp ~/.gcb-serve-data/gcb-serve.cer ./spfx-dev-cert.pem
# Copy the PEM ecrtificate for non-Windows hosts
cp ~/.rushstack/rushstack-serve.pem ./spfx-dev-cert.pem
## add *.cer to .gitignore to prevent certificates from being saved in repo
if ! grep -Fxq '*.cer' ./.gitignore

View File

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

View File

@ -1,27 +0,0 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"settings": {
"react": {
"version": "detect"
}
},
"ignorePatterns": ["*.js"],
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
]
}

View File

@ -9,9 +9,11 @@ node_modules
# Build generated files
dist
lib
release
solution
temp
*.sppkg
.heft
# Coverage directory used by tools like istanbul
coverage
@ -30,3 +32,7 @@ obj
# Styles Generated Code
*.scss.ts
# .CER Certificates
*.cer
# .PEM Certificates
*.pem

View File

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

View File

@ -0,0 +1 @@
v18.19.1

View File

@ -1,11 +1,18 @@
{
"@microsoft/generator-sharepoint": {
"plusBeta": false,
"isCreatingSolution": true,
"environment": "onprem19",
"version": "1.12.0",
"nodeVersion": "18.19.1",
"sdksVersions": {
"@microsoft/microsoft-graph-client": "3.0.2",
"@microsoft/teams-js": "2.12.0"
},
"version": "1.18.2",
"libraryName": "react-organization-chart",
"libraryId": "0b4a3e5d-123f-41ea-96c4-538c6a19932b",
"environment": "onprem19",
"packageManager": "npm",
"solutionName": "react-organization-chart",
"componentType": "webpart"
}
}
}

View File

@ -14,14 +14,18 @@ This web part shows an organization chart based on specified user, and user can
| :warning: Important |
|:---------------------------|
| Every SPFx version is only compatible with specific version(s) of Node.js. In order to be able to build this sample, please ensure that the version of Node on your workstation matches one of the versions listed in this section. This sample will not work on a different version of Node.|
| Every SPFx version is optimally compatible with specific versions of Node.js. In order to be able to build this sample, you need to ensure that the version of Node on your workstation matches one of the versions listed in this section. This sample will not work on a different version of Node.|
|Refer to <https://aka.ms/spfx-matrix> for more information on SPFx compatibility. |
![SPFx 1.4.1](https://img.shields.io/badge/SPFx-1.4.1-green.svg)
![Node.js v6 | v8](https://img.shields.io/badge/Node.js-LTS%206.x%20%7C%20v8-green.svg)
![SharePoint 2019 | Online](https://img.shields.io/badge/SharePoint-2019%20%7C%20Online-yellow.svg)
![Teams No: Not designed for Microsoft Teams](https://img.shields.io/badge/Teams-No-red.svg "Not designed for Microsoft Teams")
![Workbench Hosted: Does not work with local workbench](https://img.shields.io/badge/Workbench-Hosted-yellow.svg "Does not work with local workbench")
This sample is optimally compatible with the following environment configuration:
![SPFx 1.18.2](https://img.shields.io/badge/SPFx-1.18.2-green.svg)
![Node.js v16 | v18](https://img.shields.io/badge/Node.js-v16%20%7C%20v18-green.svg)
![Compatible with SharePoint Online](https://img.shields.io/badge/SharePoint%20Online-Compatible-green.svg)
![Does not work with SharePoint 2019](https://img.shields.io/badge/SharePoint%20Server%202019-Incompatible-red.svg "SharePoint Server 2019 requires SPFx 1.4.1 or lower")
![Does not work with SharePoint 2016 (Feature Pack 2)](https://img.shields.io/badge/SharePoint%20Server%202016%20(Feature%20Pack%202)-Incompatible-red.svg "SharePoint Server 2016 Feature Pack 2 requires SPFx 1.1")
![Local Workbench Unsupported](https://img.shields.io/badge/Local%20Workbench-Unsupported-red.svg "Local workbench is no longer available as of SPFx 1.13 and above")
![Hosted Workbench Compatible](https://img.shields.io/badge/Hosted%20Workbench-Compatible-green.svg)
![Compatible with Remote Containers](https://img.shields.io/badge/Remote%20Containers-Compatible-green.svg)
## Applies to
@ -30,13 +34,15 @@ This web part shows an organization chart based on specified user, and user can
## Contributors
* [João Mendes](https://github.com/joaojmendes), Storm Technology, ([@joaojmendes](https://twitter.com/joaojmendes))
- [João Mendes](https://github.com/joaojmendes)
- [Passoli Mirko](https://github.com/Paxol)
## Version history
Version|Date|Comments
-------|----|--------
1.0|May, 2021|Initial release
|Version|Date|Comments|
|-------|----|--------|
|1.1|Feb, 2024|Guest user filter + update to SPFx 1.18.2|
|1.0|May, 2021|Initial release|
## Prerequisites

View File

@ -10,7 +10,7 @@
"Can be installed on SharePoint Server 2019, and SharePoint Online."
],
"creationDateTime": "2021-05-03",
"updateDateTime": "2021-05-03",
"updateDateTime": "2024-02-25",
"products": [
"SharePoint"
],
@ -21,7 +21,7 @@
},
{
"key": "SPFX-VERSION",
"value": "1.4.1"
"value": "1.18.2"
}
],
"thumbnails": [
@ -51,6 +51,10 @@
"pictureUrl": "https://github.com/joaojmendes.png",
"name": "João Mendes",
"twitter": "joaojmendes"
},
{
"gitHubAccount": "Paxol",
"pictureUrl": "https://github.com/Paxol.png"
}
],
"references": [

View File

@ -3,11 +3,9 @@
"solution": {
"name": "react-organization-chart",
"id": "0b4a3e5d-123f-41ea-96c4-538c6a19932b",
"version": "1.0.0.0",
"version": "1.1.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true
},
"paths": {
"zippedPackage": "solution/react-organization-chart.sppkg"

View File

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

View File

@ -1,10 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json",
"port": 4321,
"https": true,
"initialPage": "https://localhost:5432/workbench",
"api": {
"port": 5432,
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
}
"initialPage": "https://{tenantDomain}/_layouts/workbench.aspx"
}

View File

@ -1,57 +1,16 @@
// gulpfile.js
'use strict';
const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');
const merge = require('webpack-merge');
const TerserPlugin = require('terser-webpack-plugin-legacy');
build.addSuppression(/Warning - \[sass\] The local CSS class .* is not camelCase and will not be type-safe./gi);
// force use of projects specified typescript version
const typeScriptConfig = require('@microsoft/gulp-core-build-typescript/lib/TypeScriptConfiguration');
typeScriptConfig.TypeScriptConfiguration.setTypescriptCompiler(require('typescript'));
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
// disable tslint
build.tslint.enabled = false;
var getTasks = build.rig.getTasks;
build.rig.getTasks = function () {
var result = getTasks.call(build.rig);
const eslint = require('gulp-eslint');
result.set('serve', result.get('serve-deprecated'));
const eslintSubTask = build.subTask('eslint', function (gulp, buildOptions, done) {
return gulp.src(['src/**/*.{ts,tsx}'])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError());
});
return result;
};
build.rig.addPreBuildTask(build.task('eslint-task', eslintSubTask));
// force use of projects specified react version
build.configureWebpack.mergeConfig({
additionalConfiguration: (generatedConfiguration) => {
// force use of projects specified react version
generatedConfiguration.externals = generatedConfiguration.externals
.filter(name => !(["react", "react-dom"].includes(name)));
// force use TerserPlugIn (remove UglifyJs)
generatedConfiguration.plugins.forEach((plugin, i) => {
if (plugin.options && plugin.options.mangle) {
generatedConfiguration.plugins.splice(i, 1);
generatedConfiguration = merge(generatedConfiguration, {
plugins: [
new TerserPlugin()
]
});
}
});
return generatedConfiguration;
}
});
build.initialize(gulp);
build.initialize(require('gulp'));

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,9 @@
"name": "react-organization-chart",
"version": "0.0.1",
"private": true,
"engines": {
"node": ">=16.13.0 <17.0.0 || >=18.17.1 <19.0.0"
},
"main": "lib/index.js",
"scripts": {
"build": "gulp bundle",
@ -9,48 +12,36 @@
"test": "gulp test"
},
"dependencies": {
"@fluentui/theme": "^2.1.0",
"@microsoft/office-ui-fabric-react-bundle": "^1.11.0",
"@microsoft/sp-core-library": "~1.4.1",
"@microsoft/sp-lodash-subset": "~1.4.1",
"@microsoft/sp-office-ui-fabric-core": "^1.11.0",
"@microsoft/sp-tslint-rules": "^1.11.0",
"@microsoft/sp-webpart-base": "~1.4.1",
"@pnp/common": "^1.3.11",
"@pnp/logging": "^1.3.11",
"@pnp/odata": "^1.3.11",
"@fluentui/react": "^8.115.6",
"@microsoft/sp-component-base": "1.18.2",
"@microsoft/sp-core-library": "1.18.2",
"@microsoft/sp-lodash-subset": "1.18.2",
"@microsoft/sp-office-ui-fabric-core": "1.18.2",
"@microsoft/sp-property-pane": "1.18.2",
"@microsoft/sp-webpart-base": "1.18.2",
"@pnp/sp": "^1.3.11",
"@pnp/spfx-controls-react": "^1.21.1",
"@pnp/spfx-property-controls": "^1.3.0",
"@uifabric/merge-styles": "^7.19.2",
"enhanced-resolve": "^5.8.0",
"idb-keyval": "^5.0.5",
"office-ui-fabric-react": "^6.214.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"spfx-uifabric-themes": "^0.8.5",
"jsonpointer": ">=5.0.0"
"@pnp/spfx-controls-react": "^3.17.0",
"@pnp/spfx-property-controls": "^3.16.0",
"idb-keyval": "^6.2.1",
"react": "17.0.1",
"react-dom": "17.0.1",
"spfx-uifabric-themes": "^0.9.0",
"tslib": "2.3.1"
},
"devDependencies": {
"@microsoft/sp-build-web": "1.4.1",
"@microsoft/sp-module-interfaces": "1.4.1",
"@microsoft/sp-webpart-workbench": "1.4.1",
"@types/chai": "3.4.34",
"@types/es6-promise": "0.0.33",
"@types/mocha": "2.2.38",
"@types/react": "^16.9.19",
"@types/react-dom": "^16.9.0",
"@types/webpack-env": "1.13.1",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"ajv": "~5.2.2",
"eslint": "^7.25.0",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-react-hooks": "^4.2.0",
"gulp": "~3.9.1",
"gulp-eslint": "^6.0.0",
"terser-webpack-plugin-legacy": "^1.2.3",
"typescript": "3.9.7",
"webpack-merge": "^4.2.1"
"@microsoft/eslint-config-spfx": "1.18.2",
"@microsoft/eslint-plugin-spfx": "1.18.2",
"@microsoft/rush-stack-compiler-4.7": "0.1.0",
"@microsoft/sp-build-web": "1.18.2",
"@microsoft/sp-module-interfaces": "1.18.2",
"@rushstack/eslint-config": "2.5.1",
"@types/react": "17.0.45",
"@types/react-dom": "17.0.17",
"@types/webpack-env": "~1.15.2",
"ajv": "^6.12.5",
"eslint": "8.7.0",
"eslint-plugin-react-hooks": "4.3.0",
"gulp": "4.0.2",
"typescript": "4.7.4"
}
}

View File

@ -18,8 +18,10 @@ export const getUserPhoto = async (userId: string): Promise<string> => {
const personaImgUrl = PROFILE_IMAGE_URL + userId;
// tslint:disable-next-line: no-use-before-declare
// eslint-disable-next-line @typescript-eslint/no-use-before-define
const url: string = await getImageBase64(personaImgUrl);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
const newHash = await getMd5HashForUrl(url);
if (
@ -36,8 +38,8 @@ export const getUserPhoto = async (userId: string): Promise<string> => {
* Get MD5Hash for the image url to verify whether user has default image or custom image
* @param url
*/
export const getMd5HashForUrl = async (url: string): Promise<string> => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const getMd5HashForUrl = async (url: string): Promise<Maybe<string>> => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-use-before-define
const library : any = await loadSPComponentById(MD5_MODULE_ID) ;
try {
const md5Hash = library.Md5Hash;
@ -71,9 +73,10 @@ export const getImageBase64 = async (pictureUrl: string): Promise<string> => {
const image = new Image();
image.addEventListener("load", () => {
const tempCanvas = document.createElement("canvas");
// eslint-disable-next-line no-unused-expressions, no-sequences
(tempCanvas.width = image.width),
(tempCanvas.height = image.height),
tempCanvas.getContext("2d").drawImage(image, 0, 0);
tempCanvas.getContext("2d")?.drawImage(image, 0, 0);
let base64Str;
try {
base64Str = tempCanvas.toDataURL("image/png");

View File

@ -5,7 +5,7 @@ import {
PersonaSize,
DocumentCardActions,
IButtonProps,
} from "office-ui-fabric-react";
} from "@fluentui/react";
import * as React from "react";
import { Person } from "../Person/Person";
import { ICompactCardProps } from "./ICompactCardProps";

View File

@ -5,7 +5,7 @@ import {
IStackTokens,
PersonaSize,
Link,
} from "office-ui-fabric-react"
} from "@fluentui/react"
import * as React from "react";
import { Person } from "../Person/Person";
import { IExpandedCardProps } from "./IExpandedCardProps";
@ -34,11 +34,14 @@ export const ExpandedCard: React.FunctionComponent<IExpandedCardProps> = (
return;
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => {
const { currentUserProfile } = await getUserProfile(user.manager);
const wManager: IUserInfo = await manpingUserProperties(
currentUserProfile
);
if (!user.manager) return;
const userProfileResponse = await getUserProfile(user.manager);
if (!userProfileResponse) return;
const wManager: IUserInfo = await manpingUserProperties(userProfileResponse.currentUserProfile);
setManager(wManager);
})();
}, [getUserProfile, user.manager]);
@ -65,7 +68,7 @@ export const ExpandedCard: React.FunctionComponent<IExpandedCardProps> = (
<Text variant="smallPlus">{user.email}</Text>
</Link>
</Stack>
<div className={hoverCardStyles.separatorHorizontal}></div>
<div className={hoverCardStyles.separatorHorizontal} />
</>
)
}
@ -88,7 +91,7 @@ export const ExpandedCard: React.FunctionComponent<IExpandedCardProps> = (
<Text variant="smallPlus">{user.workPhone}</Text>
</Link>
</Stack>
<div className={hoverCardStyles.separatorHorizontal}></div>
<div className={hoverCardStyles.separatorHorizontal} />
</>
)}
{user.location && (
@ -131,7 +134,7 @@ export const ExpandedCard: React.FunctionComponent<IExpandedCardProps> = (
pictureUrl={manager.pictureUrl}
text={manager.displayName}
secondaryText={manager.title}
></Person>
/>
</>
)}
</Stack>

View File

@ -1,9 +1,8 @@
import { IButtonStyles, IDocumentCardActionsStyles, IStackStyles, mergeStyles, mergeStyleSets } from "office-ui-fabric-react";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import Theme from "spfx-uifabric-themes";
const currentTheme = window.__themeState__.theme;
import { IButtonStyles, IDocumentCardActionsStyles, IStackStyles, mergeStyles, mergeStyleSets } from "@fluentui/react";
import type { Theme } from "spfx-uifabric-themes";
const currentTheme: Theme = window.__themeState__.theme;
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export const useHoverCardStyles = () => {
const stackPersonaStyles: Partial<IStackStyles> = {

View File

@ -8,5 +8,6 @@ export interface IOrgChartProps {
context: WebPartContext;
startFromUser: IPropertyFieldGroupOrPerson[];
showAllManagers: boolean;
showGuestUsers: boolean;
showActionsBar:boolean;
}

View File

@ -5,8 +5,8 @@ export interface IErrorInfo {
}
export interface IOrgChartState {
isLoading: boolean;
error:IErrorInfo;
renderManagers:JSX.Element[];
renderManagers: JSX.Element[];
renderDirectReports: JSX.Element[];
currentUser:IUserInfo;
error?: IErrorInfo;
currentUser?: IUserInfo;
}

View File

@ -6,7 +6,7 @@ import {
useGetUserProperties,
manpingUserProperties,
} from "../../hooks/useGetUserProperties";
import { IStackStyles, Stack } from "office-ui-fabric-react/lib/Stack";
import { IStackStyles, Stack } from "@fluentui/react/lib/Stack";
import { PersonCard } from "../PersonCard/PersonCard";
import { IUserInfo } from "../../models/IUserInfo";
import { EOrgChartTypes } from "./EOrgChartTypes";
@ -17,13 +17,15 @@ import {
Spinner,
SpinnerSize,
Text,
} from "office-ui-fabric-react";
} from "@fluentui/react";
import { Placeholder } from "@pnp/spfx-controls-react/lib/Placeholder";
import { getGUID } from "@pnp/common";
import { useOrgChartStyles } from "./useOrgChartStyles";
import "./OrgChart.module.scss";
const initialState: IOrgChartState = {
isLoading: true,
renderDirectReports: [],
@ -56,13 +58,14 @@ export const OrgChart: React.FunctionComponent<IOrgChartProps> = (
const {
context,
showAllManagers,
showGuestUsers,
startFromUser,
showActionsBar,
title,
}: IOrgChartProps = props;
const startFromUserId: string = React.useMemo(
const startFromUserId: Maybe<string> = React.useMemo(
() => startFromUser && startFromUser[0].id,
[startFromUser]
);
@ -80,13 +83,14 @@ export const OrgChart: React.FunctionComponent<IOrgChartProps> = (
const wRenderDirectReports: JSX.Element[] = [];
try {
const { managersList, reportsLists } = await getUserProfile(
const profileResponse = await getUserProfile(
selectedUser,
startFromUserId,
showAllManagers
showAllManagers,
showGuestUsers,
);
if (managersList) {
for (const managerInfo of managersList) {
if (profileResponse) {
for (const managerInfo of profileResponse.managersList) {
wRenderManagers.push(
<>
<PersonCard
@ -95,16 +99,16 @@ export const OrgChart: React.FunctionComponent<IOrgChartProps> = (
onUserSelected={onUserSelected}
selectedUser={currentUser}
showActionsBar={showActionsBar}
></PersonCard>
/>
<div
key={getGUID()}
className={orgChartClasses.separatorVertical}
></div>
/>
</>
);
}
for (const directReport of reportsLists) {
for (const directReport of profileResponse.reportsLists) {
wRenderDirectReports.push(
<>
<PersonCard
@ -113,7 +117,7 @@ export const OrgChart: React.FunctionComponent<IOrgChartProps> = (
onUserSelected={onUserSelected}
selectedUser={currentUser}
showActionsBar={showActionsBar}
></PersonCard>
/>
</>
);
}
@ -145,6 +149,7 @@ export const OrgChart: React.FunctionComponent<IOrgChartProps> = (
getUserProfile,
startFromUserId,
showAllManagers,
showGuestUsers,
onUserSelected,
currentUser,
showActionsBar,
@ -153,6 +158,7 @@ export const OrgChart: React.FunctionComponent<IOrgChartProps> = (
);
React.useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => {
try {
if (startFromUserId === undefined) return;
@ -170,9 +176,10 @@ export const OrgChart: React.FunctionComponent<IOrgChartProps> = (
});
return;
}
const { currentUserProfile } = await getUserProfile(startFromUserId);
const profileResponse = await getUserProfile(startFromUserId);
const wCurrentUser: IUserInfo = await manpingUserProperties(
currentUserProfile
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
profileResponse!.currentUserProfile
);
dispatch({
type: EOrgChartTypes.SET_CURRENT_USER,
@ -200,8 +207,9 @@ export const OrgChart: React.FunctionComponent<IOrgChartProps> = (
}, [getUserProfile, startFromUserId]);
React.useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => {
if (!currentUser) return;
if (!currentUser || !currentUser.id) return;
dispatch({
type: EOrgChartTypes.SET_IS_LOADING,
payload: true,
@ -246,7 +254,7 @@ export const OrgChart: React.FunctionComponent<IOrgChartProps> = (
size={SpinnerSize.large}
label={"loading Organization Chart..."}
labelPosition={"bottom"}
></Spinner>
/>
</Stack>
</Overlay>
);
@ -279,15 +287,16 @@ export const OrgChart: React.FunctionComponent<IOrgChartProps> = (
{renderManagers}
<PersonCard
key={getGUID()}
userInfo={currentUser}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
userInfo={currentUser!}
onUserSelected={onUserSelected}
selectedUser={currentUser}
showActionsBar={showActionsBar}
></PersonCard>
/>
{renderDirectReports.length && (
<>
<div className={orgChartClasses.separatorVertical}></div>
<div className={orgChartClasses.separatorHorizontal}></div>
<div className={orgChartClasses.separatorVertical} />
<div className={orgChartClasses.separatorHorizontal} />
</>
)}
</Stack>

View File

@ -1,6 +1,5 @@
export * from './EOrgChartTypes';
export * from './IOrgChartProps';
export * from './IOrgChartState';
export * from './OrgChart.module.scss';
export * from './OrgChart';
export * from './OrgChartReducer';

View File

@ -1,8 +1,8 @@
import { mergeStyles, mergeStyleSets } from "office-ui-fabric-react";
import { mergeStyles, mergeStyleSets } from "@fluentui/react";
const currentTheme = window.__themeState__.theme;
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export const useOrgChartStyles = () => {
const orgChartClasses = mergeStyleSets({

View File

@ -1,4 +1,4 @@
import { PersonaSize } from "office-ui-fabric-react/lib/Persona";
import { PersonaSize } from "@fluentui/react/lib/Persona";
export interface IPersonProps {
userEmail: string;
text: string;

View File

@ -3,8 +3,8 @@ import {
IPersonaSharedProps,
Persona,
PersonaSize,
} from "office-ui-fabric-react/lib/Persona";
import { Text } from "office-ui-fabric-react/lib/Text";
} from "@fluentui/react/lib/Persona";
import { Text } from "@fluentui/react/lib/Text";
import { IPersonProps } from "./IPersonProps";
export const Person: React.FunctionComponent<IPersonProps> = (

View File

@ -5,7 +5,7 @@ import {
DocumentCardActions,
DocumentCardDetails,
IDocumentCard,
} from "office-ui-fabric-react/lib/DocumentCard";
} from "@fluentui/react/lib/DocumentCard";
import {
Stack,
@ -15,7 +15,7 @@ import {
IExpandingCardProps,
PersonaSize,
DirectionalHint,
} from "office-ui-fabric-react";
} from "@fluentui/react";
import { Person } from "../Person/Person";
import { IUserInfo } from "../../models/IUserInfo";
import { ExpandedCard, CompactCard } from "../HoverCard";
@ -29,7 +29,7 @@ export const PersonCard: React.FunctionComponent<IPersonCardProps> = (
) => {
const { userInfo, onUserSelected, showActionsBar } = props;
const documentCardRef = React.useRef<IDocumentCard>(undefined);
const documentCardRef = React.useRef<IDocumentCard>(null);
const {
personaCardStyles,
documentCardActionStyles,

View File

@ -1,9 +1,8 @@
import { IButtonStyles, IDocumentCardActionsStyles, IStackStyles, mergeStyles, mergeStyleSets } from "office-ui-fabric-react";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import Theme from "spfx-uifabric-themes";
const currentTheme = window.__themeState__.theme;
import { IButtonStyles, IDocumentCardActionsStyles, IStackStyles, mergeStyles, mergeStyleSets } from "@fluentui/react";
import type { Theme } from "spfx-uifabric-themes";
const currentTheme: Theme = window.__themeState__.theme;
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export const usePersonaCardStyles = () => {
const stackPersonaStyles: Partial<IStackStyles> = {
@ -91,7 +90,7 @@ export const usePersonaCardStyles = () => {
},
"@media((min-width : 481px) and (max-width : 12480px))": {
maxWidth: 260,
minWidth: "50%",
minWidth: "min(50%, 260px)",
},
}
}),

View File

@ -0,0 +1 @@
type Maybe<T> = T | undefined;

View File

@ -1,5 +1,5 @@
import { sp, SPBatch} from "@pnp/sp/";
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { sp, SPBatch } from "@pnp/sp/";
import { IUserInfo } from "../models/IUserInfo";
import * as React from "react";
import { get, set } from "idb-keyval";
@ -10,28 +10,39 @@ import { IPersonProperties } from "../models/IPersonProperties";
// Hook to get user profile information
// *************************************************************************************/
type getUserProfileFunc = ( currentUser: string,
type getUserProfileFunc = (
currentUser: string,
startUser?: string,
showAllManagers?: boolean) => Promise<returnProfileData>;
showAllManagers?: boolean,
showGuestUsers?: boolean
) => Promise<ProfileDataResponse>;
type returnProfileData = { managersList:IUserInfo[], reportsLists:IUserInfo[], currentUserProfile :IPersonProperties} ;
export const useGetUserProperties = (): { getUserProfile:getUserProfileFunc } => {
type ProfileDataResponse = Maybe<{
managersList: IUserInfo[];
reportsLists: IUserInfo[];
currentUserProfile: IPersonProperties;
}>;
export const useGetUserProperties = (): {
getUserProfile: getUserProfileFunc;
} => {
const getUserProfile = React.useCallback(
async (
currentUser: string,
startUser?: string,
showAllManagers?: boolean
): Promise<returnProfileData> => {
showAllManagers: boolean = false,
showGuestUsers: boolean = false
): Promise<ProfileDataResponse> => {
if (!currentUser) return;
const loginName = currentUser;
const loginNameStartUser: string = startUser && startUser;
const cacheCurrentUser:IPersonProperties = await get(`${loginName}__orgchart__`);
let currentUserProfile:IPersonProperties = undefined;
const loginNameStartUser: Maybe<string> = startUser && startUser;
const cacheCurrentUser: Maybe<IPersonProperties> = await get(
`${loginName}__orgchart__`
);
let currentUserProfile: IPersonProperties;
if (!cacheCurrentUser) {
currentUserProfile = await sp.profiles.getPropertiesFor(loginName);
// console.log(currentUserProfile);
// console.log(currentUserProfile);
await set(`${loginName}__orgchart__`, currentUserProfile);
} else {
currentUserProfile = cacheCurrentUser;
@ -40,49 +51,64 @@ export const useGetUserProperties = (): { getUserProfile:getUserProfileFunc }
let reportsLists: IUserInfo[] = [];
let managersList: IUserInfo[] = [];
const wDirectReports: string[] =
const wDirectReports: Maybe<string[]> =
currentUserProfile && currentUserProfile.DirectReports;
const wExtendedManagers: string[] =
const wExtendedManagers: Maybe<string[]> =
currentUserProfile && currentUserProfile.ExtendedManagers;
// Get Direct Reports if exists
if (wDirectReports && wDirectReports.length > 0) {
reportsLists = await getDirectReports(wDirectReports);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
reportsLists = await getDirectReports(wDirectReports, showGuestUsers);
}
// Get Managers if exists
if (startUser && wExtendedManagers && wExtendedManagers.length > 0) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
managersList = await getExtendedManagers(
wExtendedManagers,
loginNameStartUser,
showAllManagers
loginNameStartUser!,
showAllManagers,
showGuestUsers
);
}
return { managersList, reportsLists, currentUserProfile } ;
return { managersList, reportsLists, currentUserProfile };
},
[]
);
return { getUserProfile } ;
return { getUserProfile };
};
const getDirectReports = async (
directReports: string[]
directReports: string[],
showGuestUsers: boolean
): Promise<IUserInfo[]> => {
const _reportsList: IUserInfo[] = [];
const batch: SPBatch = sp.createBatch();
for (const userReport of directReports) {
const cacheDirectReport: IPersonProperties = await get(`${userReport}__orgchart__`);
const cacheDirectReport: Maybe<IPersonProperties> = await get(
`${userReport}__orgchart__`
);
if (!cacheDirectReport) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
sp.profiles
.inBatch(batch)
.getPropertiesFor(userReport)
.then(async (directReport: IPersonProperties) => {
_reportsList.push(await manpingUserProperties(directReport));
// eslint-disable-next-line @typescript-eslint/no-use-before-define
const userInfo = await manpingUserProperties(directReport);
if (!showGuestUsers && userInfo.userType === "Guest") return;
_reportsList.push(userInfo);
await set(`${userReport}__orgchart__`, directReport);
});
} else {
_reportsList.push(await manpingUserProperties(cacheDirectReport));
// eslint-disable-next-line @typescript-eslint/no-use-before-define
const userInfo = await manpingUserProperties(cacheDirectReport);
if (!showGuestUsers && userInfo.userType === "Guest") continue;
_reportsList.push(userInfo);
}
}
await batch.execute();
@ -92,7 +118,8 @@ const getDirectReports = async (
const getExtendedManagers = async (
extendedManagers: string[],
startUser: string,
showAllManagers: boolean
showAllManagers: boolean,
showGuestUsers: boolean
): Promise<IUserInfo[]> => {
const wManagers: IUserInfo[] = [];
const batch: SPBatch = sp.createBatch();
@ -101,26 +128,50 @@ const getExtendedManagers = async (
if (!showAllManagers && manager !== startUser) {
continue;
}
const cacheManager: IPersonProperties = await get(`${manager}__orgchart__`);
const cacheManager: Maybe<IPersonProperties> = await get(
`${manager}__orgchart__`
);
if (!cacheManager) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
sp.profiles
.inBatch(batch)
.getPropertiesFor(manager)
.then(async (_profile: IPersonProperties) => {
wManagers.push(await manpingUserProperties(_profile));
// eslint-disable-next-line @typescript-eslint/no-use-before-define
const userInfo = await manpingUserProperties(_profile);
if (!showGuestUsers && userInfo.userType === "Guest") return;
wManagers.push(userInfo);
await set(`${manager}__orgchart__`, _profile);
});
} else {
wManagers.push(await manpingUserProperties(cacheManager));
// eslint-disable-next-line @typescript-eslint/no-use-before-define
const userInfo = await manpingUserProperties(cacheManager);
if (!showGuestUsers && userInfo.userType === "Guest") continue;
wManagers.push(userInfo);
}
}
await batch.execute();
return wManagers;
};
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
function userTypeMapper(userType: string) {
switch (userType) {
case "0":
return "Employee";
case "1":
return "Guest";
default:
return "Unknown";
}
}
export const manpingUserProperties = async (
userProperties: IPersonProperties
): Promise<IUserInfo> => {
console.log(userProperties);
return {
displayName: userProperties.DisplayName as string,
@ -133,12 +184,28 @@ export const manpingUserProperties = async (
hasDirectReports: userProperties.DirectReports.length > 0 ? true : false,
hasPeers: userProperties.Peers.length > 0 ? true : false,
numberPeers: userProperties.Peers.length,
department: filter(userProperties?.UserProfileProperties,{"Key": "Department"})[0].Value ?? '',
workPhone: filter(userProperties?.UserProfileProperties,{"Key": "WorkPhone"})[0].Value ?? '',
cellPhone: filter(userProperties?.UserProfileProperties,{"Key": "CellPhone"})[0].Value ?? '',
location: filter(userProperties?.UserProfileProperties,{"Key": "SPS-Location"})[0].Value ?? '',
office: filter(userProperties?.UserProfileProperties,{"Key": "Office"})[0].Value ?? '',
manager: filter(userProperties?.UserProfileProperties,{"Key": "Manager"})[0].Value ?? '',
loginName: userProperties.loginName
department:
filter(userProperties?.UserProfileProperties, { Key: "Department" })[0]
.Value ?? "",
workPhone:
filter(userProperties?.UserProfileProperties, { Key: "WorkPhone" })[0]
.Value ?? "",
cellPhone:
filter(userProperties?.UserProfileProperties, { Key: "CellPhone" })[0]
.Value ?? "",
location:
filter(userProperties?.UserProfileProperties, { Key: "SPS-Location" })[0]
.Value ?? "",
office:
filter(userProperties?.UserProfileProperties, { Key: "Office" })[0]
.Value ?? "",
manager:
filter(userProperties?.UserProfileProperties, { Key: "Manager" })[0]
.Value ?? "",
userType: userTypeMapper(
filter(userProperties?.UserProfileProperties, { Key: "SPS-UserType" })[0]
.Value
),
loginName: userProperties.loginName,
};
};

View File

@ -1,6 +1,8 @@
/* tslint:disable */
import { IUser } from "./IUser";
import { UserType } from "./UserType";
export interface IUserInfo extends IUser {
title:string;
pictureUrl?: string;
@ -16,5 +18,5 @@ export interface IUserInfo extends IUser {
cellPhone?:string;
location?:string;
office?: string;
}
userType: UserType;
}

View File

@ -0,0 +1,2 @@
export type UserType = "Employee" | "Guest" | "Unknown";

View File

@ -23,6 +23,7 @@
"properties": {
"title": "Organization Chart",
"showAllManagers": true,
"showGuestUsers": false,
"showActionsBar": true
}
}]

View File

@ -1,19 +1,19 @@
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import * as React from "react";
import * as ReactDom from "react-dom";
import { Version } from "@microsoft/sp-core-library";
import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base";
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField,
PropertyPaneToggle
} from '@microsoft/sp-webpart-base';
PropertyPaneToggle,
} from "@microsoft/sp-property-pane";
import {
PropertyFieldPeoplePicker,
PrincipalType,
IPropertyFieldGroupOrPerson,
} from "@pnp/spfx-property-controls/lib/PropertyFieldPeoplePicker";
import * as strings from 'OrganizationChartWebPartStrings';
import {OrgChart} from '../../components/OrgChart/OrgChart';
import * as strings from "OrganizationChartWebPartStrings";
import { OrgChart } from "../../components/OrgChart/OrgChart";
import { IOrgChartProps } from "../../components/OrgChart/IOrgChartProps";
import { sp } from "@pnp/sp";
@ -22,26 +22,28 @@ export interface IOrganizationChartWebPartProps {
currentUser: string;
selectedUser: IPropertyFieldGroupOrPerson[];
showAllManagers: boolean;
showGuestUsers: boolean;
showActionsBar: boolean;
}
export default class OrganizationChartWebPart extends BaseClientSideWebPart<IOrganizationChartWebPartProps> {
public async onInit(): Promise<void> {
sp.setup({
sp.setup({
spfxContext: this.context,
});
return Promise.resolve();
return Promise.resolve();
}
public render(): void {
const element: React.ReactElement<IOrgChartProps > = React.createElement(
const element: React.ReactElement<IOrgChartProps> = React.createElement(
OrgChart,
{
title: this.properties.title,
defaultUser: this.properties.currentUser,
startFromUser: this.properties.selectedUser,
showAllManagers: this.properties.showAllManagers,
showGuestUsers: this.properties.showGuestUsers,
context: this.context,
showActionsBar: this.properties.showActionsBar
showActionsBar: this.properties.showActionsBar,
}
);
@ -53,7 +55,7 @@ return Promise.resolve();
}
protected get dataVersion(): Version {
return Version.parse('1.0');
return Version.parse("1.0");
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
@ -80,11 +82,13 @@ return Promise.resolve();
principalType: [PrincipalType.Users],
onPropertyChange: this.onPropertyPaneFieldChanged,
properties: this.properties,
onGetErrorMessage: null,
}),
PropertyPaneToggle("showAllManagers", {
label: strings.showAllManagers,
}),
PropertyPaneToggle("showGuestUsers", {
label: strings.showGuestUsers,
}),
PropertyPaneToggle("showActionsBar", {
label: strings.showactionsLabel,
}),
@ -95,5 +99,4 @@ return Promise.resolve();
],
};
}
}

View File

@ -5,6 +5,7 @@ define([], function() {
"TitleFieldLabel": "Title",
"startFromUserLabel": "Start from user",
"showactionsLabel": "Show actions bar",
"showAllManagers": "Show all managers"
"showAllManagers": "Show all managers",
"showGuestUsers": "Show guest users",
}
});

View File

@ -5,6 +5,7 @@ declare interface IOrganizationChartWebPartStrings {
startFromUserLabel: string;
showactionsLabel:string;
showAllManagers:string;
showGuestUsers:string;
}
declare module 'OrganizationChartWebPartStrings' {

View File

@ -1,6 +1,7 @@
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-4.7/includes/tsconfig-web.json",
"compilerOptions": {
"target": "es6",
"target": "es5",
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
@ -9,6 +10,10 @@
"sourceMap": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"outDir": "lib",
"inlineSources": false,
"noImplicitAny": true,
"typeRoots": [
"./node_modules/@types",
"./node_modules/@microsoft"
@ -18,10 +23,13 @@
],
"lib": [
"es5",
"es6",
"dom",
"es2015.collection",
"es2015.promise"
]
}
},
"include": [
"src/**/*.ts",
"src/**/*.tsx"
]
}