Merge pull request #3997 from ejazhussain/main
This commit is contained in:
commit
ddcadc871e
|
@ -0,0 +1,379 @@
|
||||||
|
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: {
|
||||||
|
semi: 2, //Added by FRESH
|
||||||
|
"react/jsx-no-target-blank": 0, //O3C
|
||||||
|
// Prevent usage of the JavaScript null value, while allowing code to access existing APIs that may require null. https://www.npmjs.com/package/@rushstack/eslint-plugin
|
||||||
|
"@rushstack/no-new-null": 1,
|
||||||
|
// Require Jest module mocking APIs to be called before any other statements in their code block. https://www.npmjs.com/package/@rushstack/eslint-plugin
|
||||||
|
"@rushstack/hoist-jest-mock": 1,
|
||||||
|
// Require regular expressions to be constructed from string constants rather than dynamically building strings at runtime. https://www.npmjs.com/package/@rushstack/eslint-plugin-security
|
||||||
|
"@rushstack/security/no-unsafe-regexp": 1,
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
"@typescript-eslint/adjacent-overload-signatures": 1,
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
//
|
||||||
|
// CONFIGURATION: By default, these are banned: String, Boolean, Number, Object, Symbol
|
||||||
|
"@typescript-eslint/ban-types": [
|
||||||
|
1,
|
||||||
|
{
|
||||||
|
extendDefaults: false,
|
||||||
|
types: {
|
||||||
|
String: {
|
||||||
|
message: "Use 'string' instead",
|
||||||
|
fixWith: "string",
|
||||||
|
},
|
||||||
|
Boolean: {
|
||||||
|
message: "Use 'boolean' instead",
|
||||||
|
fixWith: "boolean",
|
||||||
|
},
|
||||||
|
Number: {
|
||||||
|
message: "Use 'number' instead",
|
||||||
|
fixWith: "number",
|
||||||
|
},
|
||||||
|
Object: {
|
||||||
|
message:
|
||||||
|
"Use 'object' instead, or else define a proper TypeScript type:",
|
||||||
|
},
|
||||||
|
Symbol: {
|
||||||
|
message: "Use 'symbol' instead",
|
||||||
|
fixWith: "symbol",
|
||||||
|
},
|
||||||
|
Function: {
|
||||||
|
message:
|
||||||
|
"The 'Function' type accepts any function-like value.\nIt provides no type safety when calling the function, which can be a common source of bugs.\nIt also accepts things like class declarations, which will throw at runtime as they will not be called with 'new'.\nIf you are expecting the function to accept certain arguments, you should explicitly define the function shape.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// RATIONALE: Code is more readable when the type of every variable is immediately obvious.
|
||||||
|
// Even if the compiler may be able to infer a type, this inference will be unavailable
|
||||||
|
// to a person who is reviewing a GitHub diff. This rule makes writing code harder,
|
||||||
|
// but writing code is a much less important activity than reading it.
|
||||||
|
//
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
"@typescript-eslint/explicit-function-return-type": [
|
||||||
|
0, //O3C
|
||||||
|
{
|
||||||
|
allowExpressions: true,
|
||||||
|
allowTypedFunctionExpressions: true,
|
||||||
|
allowHigherOrderFunctions: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
// Rationale to disable: although this is a recommended rule, it is up to dev to select coding style.
|
||||||
|
// Set to 1 (warning) or 2 (error) to enable.
|
||||||
|
"@typescript-eslint/explicit-member-accessibility": 0,
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
"@typescript-eslint/no-array-constructor": 1,
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
//
|
||||||
|
// RATIONALE: The "any" keyword disables static type checking, the main benefit of using TypeScript.
|
||||||
|
// This rule should be suppressed only in very special cases such as JSON.stringify()
|
||||||
|
// where the type really can be anything. Even if the type is flexible, another type
|
||||||
|
// may be more appropriate such as "unknown", "{}", or "Record<k,V>".
|
||||||
|
"@typescript-eslint/no-explicit-any": 0, //O3C
|
||||||
|
// RATIONALE: The #1 rule of promises is that every promise chain must be terminated by a catch()
|
||||||
|
// handler. Thus wherever a Promise arises, the code must either append a catch handler,
|
||||||
|
// or else return the object to a caller (who assumes this responsibility). Unterminated
|
||||||
|
// promise chains are a serious issue. Besides causing errors to be silently ignored,
|
||||||
|
// they can also cause a NodeJS process to terminate unexpectedly.
|
||||||
|
"@typescript-eslint/no-floating-promises": 0, // FRESH
|
||||||
|
// 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": 0, //O3C
|
||||||
|
// 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": 0, //O3C
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 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,35 @@
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
# Build generated files
|
||||||
|
dist
|
||||||
|
lib
|
||||||
|
release
|
||||||
|
solution
|
||||||
|
temp
|
||||||
|
*.sppkg
|
||||||
|
.heft
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# OSX
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Visual Studio files
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
.vs
|
||||||
|
bin
|
||||||
|
obj
|
||||||
|
|
||||||
|
# Resx Generated Code
|
||||||
|
*.resx.ts
|
||||||
|
|
||||||
|
# Styles Generated Code
|
||||||
|
*.scss.ts
|
||||||
|
*.scss.d.ts
|
|
@ -0,0 +1,16 @@
|
||||||
|
!dist
|
||||||
|
config
|
||||||
|
|
||||||
|
gulpfile.js
|
||||||
|
|
||||||
|
release
|
||||||
|
src
|
||||||
|
temp
|
||||||
|
|
||||||
|
tsconfig.json
|
||||||
|
tslint.json
|
||||||
|
|
||||||
|
*.log
|
||||||
|
|
||||||
|
.yo-rc.json
|
||||||
|
.vscode
|
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"@microsoft/generator-sharepoint": {
|
||||||
|
"plusBeta": false,
|
||||||
|
"isCreatingSolution": true,
|
||||||
|
"nodeVersion": "16.18.1",
|
||||||
|
"sdksVersions": {
|
||||||
|
"@microsoft/microsoft-graph-client": "3.0.2",
|
||||||
|
"@microsoft/teams-js": "2.9.1"
|
||||||
|
},
|
||||||
|
"version": "1.17.4",
|
||||||
|
"libraryName": "smart-dev-ops",
|
||||||
|
"libraryId": "9639232e-a86e-406c-8d73-cab01892ee5c",
|
||||||
|
"environment": "spo",
|
||||||
|
"packageManager": "npm",
|
||||||
|
"solutionName": "SmartDevOps",
|
||||||
|
"solutionShortDescription": "SmartDevOps description",
|
||||||
|
"skipFeatureDeployment": true,
|
||||||
|
"isDomainIsolated": false,
|
||||||
|
"componentType": "webpart"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
# OpenAI Azure DevOps Bot
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
The SPFx web part is a SharePoint Framework web part that allows users to view recent tasks, bugs, and commits assigned to them from a specific project in Azure DevOps. The web part uses the Open AI function calling feature to determine the user's request and intention, and then processes the relevant function using the Azure DevOps API.
|
||||||
|
|
||||||
|
![Sample Web part showing Azure DevOps integration with OpenAI](./assets/demo.gif)
|
||||||
|
|
||||||
|
## Compatibility
|
||||||
|
|
||||||
|
| :warning: Important |
|
||||||
|
| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| Every SPFx version is only compatible with specific version(s) of Node.js. In order to be able to build this sample, please ensure that the version of Node on your workstation matches one of the versions listed in this section. This sample will not work on a different version of Node. |
|
||||||
|
| Refer to <https://aka.ms/spfx-matrix> for more information on SPFx compatibility. |
|
||||||
|
|
||||||
|
![SPFx 1.17.4](https://img.shields.io/badge/SPFx-1.17.4-green.svg)
|
||||||
|
![Node.js v16.18.1](https://img.shields.io/badge/Node.js-v16.18.1-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")
|
||||||
|
![Teams Incompatible](https://img.shields.io/badge/Teams-Incompatible-lightgrey.svg)
|
||||||
|
![Local Workbench Incompatible](https://img.shields.io/badge/Local%20Workbench-Incompatible-red.svg "This solution requires access to a user's user and group ids")
|
||||||
|
![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://learn.microsoft.com/sharepoint/dev/spfx/set-up-your-developer-tenant)
|
||||||
|
|
||||||
|
> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/m365devprogram)
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
1. Access to a SharePoint online site with various tenant users granted access to various site resources directly, via AAD groups and via SharePoint groups.
|
||||||
|
|
||||||
|
2. Create [OpenAI account](https://beta.openai.com/) and get API key
|
||||||
|
|
||||||
|
3. Create and configure Azure DevOps organizations [Click here for more detail](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/create-organization?view=azure-devops).
|
||||||
|
|
||||||
|
4. Configure atleast one project and git repositoy. [Click here for more detail](https://learn.microsoft.com/en-us/azure/devops/repos/git/create-new-repo?view=azure-devops). Assign yourself some tasks, bugs.
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
- [Ejaz Hussain](https://github.com/ejazhussain)
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
| Version | Date | Comments |
|
||||||
|
| ------- | ------------- | --------------- |
|
||||||
|
| 1.0.0 | July 30, 2023 | Initial release |
|
||||||
|
|
||||||
|
## Minimal Path to Awesome
|
||||||
|
|
||||||
|
1. Clone this repository
|
||||||
|
2. From your command line, change your current directory to the directory containing this sample (`react-openai-devops`, located under `samples`)
|
||||||
|
3. In the command line run:
|
||||||
|
|
||||||
|
```cmd
|
||||||
|
`npm install`
|
||||||
|
`gulp bundle`
|
||||||
|
`gulp package-solution`
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Deploy the package to your app catalog
|
||||||
|
5. Approve the following API permission request from the SharePoint admin
|
||||||
|
|
||||||
|
```JSON
|
||||||
|
{
|
||||||
|
"resource": "Azure DevOps",
|
||||||
|
"scope": "user_impersonation"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
7. In the command-line run:
|
||||||
|
|
||||||
|
```cmd
|
||||||
|
gulp serve --nobrowser
|
||||||
|
```
|
||||||
|
|
||||||
|
8. Open the hosted workbench on a SharePoint site - i.e. https://_tenant_.sharepoint.com/site/_sitename_/_layouts/workbench.aspx
|
||||||
|
|
||||||
|
- Add the [O3C] Smart DevOps web part to the page.
|
||||||
|
- In the web part properties, Add OpenAPI Key
|
||||||
|
under Open API Key field.
|
||||||
|
- Select the required Azure DevOps organization from the list under Organization name
|
||||||
|
dropdown. This dropdown will be auto populated based on your Azure DevOps configurations in your tenant
|
||||||
|
- Close the web part properties pane and save and reload the page
|
||||||
|
|
||||||
|
9. Here are some sample questions. You must provide the project name in the message to retrieve bugs and tasks. You must provide the project and repo name for recent commits.
|
||||||
|
|
||||||
|
```
|
||||||
|
1. show me all tasks assigned to me in O3C project
|
||||||
|
2. show me bugs assigned to me in O3C project
|
||||||
|
3. show me recent commits from spfx-dev-webparts repo in O3C project?
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
**The web part has three main functions:**
|
||||||
|
|
||||||
|
- **Show all recent tasks assigned to me from a specific project:** This function retrieves all recent tasks that have been assigned to the user from the specified project in Azure DevOps. The tasks are displayed in a list, and the user can click on a task to view more information about it.
|
||||||
|
|
||||||
|
- **Show all bugs assigned to me from a specific project:** This function retrieves all recent bugs that have been assigned to the user from the specified project in Azure DevOps. The bugs are displayed in a list, and the user can click on a bug to view more information about it.
|
||||||
|
|
||||||
|
- **Show recent commits in a specific repository under a given project:** This function retrieves all recent commits that have been made to a specific repository under the specified project in Azure DevOps. The commits are displayed in a list, and the user can click on a commit to view more information about it.
|
Binary file not shown.
After Width: | Height: | Size: 10 MiB |
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||||
|
"version": "2.0",
|
||||||
|
"bundles": {
|
||||||
|
"smart-dev-ops-web-part": {
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"entrypoint": "./lib/webparts/smartDevOps/SmartDevOpsWebPart.js",
|
||||||
|
"manifest": "./src/webparts/smartDevOps/SmartDevOpsWebPart.manifest.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"externals": {},
|
||||||
|
"localizedResources": {
|
||||||
|
"SmartDevOpsWebPartStrings": "lib/webparts/smartDevOps/loc/{locale}.js",
|
||||||
|
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/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": "smart-dev-ops",
|
||||||
|
"accessKey": "<!-- ACCESS KEY -->"
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||||
|
"solution": {
|
||||||
|
"name": "O3C-OpenAI DevOps",
|
||||||
|
"id": "9639232e-a86e-406c-8d73-cab01892ee5c",
|
||||||
|
"version": "1.0.0.0",
|
||||||
|
"includeClientSideAssets": true,
|
||||||
|
"skipFeatureDeployment": true,
|
||||||
|
"isDomainIsolated": false,
|
||||||
|
"developer": {
|
||||||
|
"name": "",
|
||||||
|
"websiteUrl": "",
|
||||||
|
"privacyUrl": "",
|
||||||
|
"termsOfUseUrl": "",
|
||||||
|
"mpnId": "Undefined-1.17.4"
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"shortDescription": {
|
||||||
|
"default": "o3c-openai-devops description"
|
||||||
|
},
|
||||||
|
"longDescription": {
|
||||||
|
"default": "o3c-openai-devops description"
|
||||||
|
},
|
||||||
|
"screenshotPaths": [],
|
||||||
|
"videoUrl": "",
|
||||||
|
"categories": []
|
||||||
|
},
|
||||||
|
"features": [
|
||||||
|
{
|
||||||
|
"title": "O3C-OpenAI DevOps Feature",
|
||||||
|
"description": "The feature that activates elements of the O3C-OpenAI DevOps solution.",
|
||||||
|
"id": "fc371c00-5641-4fcf-8875-4be239c71e70",
|
||||||
|
"version": "1.0.0.0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"webApiPermissionRequests": [
|
||||||
|
{
|
||||||
|
"resource": "Azure DevOps",
|
||||||
|
"scope": "user_impersonation"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"paths": {
|
||||||
|
"zippedPackage": "solution/o3c-openai-devops.sppkg"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/core-build/sass.schema.json"
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json",
|
||||||
|
"port": 4321,
|
||||||
|
"https": true,
|
||||||
|
"initialPage": "https://{tenantDomain}/_layouts/workbench.aspx"
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||||
|
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://raw.githubusercontent.com/s-KaiNet/spfx-fast-serve/master/schema/config.latest.schema.json",
|
||||||
|
"cli": {
|
||||||
|
"isLibraryComponent": false
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* User webpack settings file. You can add your own settings here.
|
||||||
|
* Changes from this file will be merged into the base webpack configuration file.
|
||||||
|
* This file will not be overwritten by the subsequent spfx-fast-serve calls.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// you can add your project related webpack configuration here, it will be merged using webpack-merge module
|
||||||
|
// i.e. plugins: [new webpack.Plugin()]
|
||||||
|
const webpackConfig = {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// for even more fine-grained control, you can apply custom webpack settings using below function
|
||||||
|
const transformConfig = function (initialWebpackConfig) {
|
||||||
|
// transform the initial webpack config here, i.e.
|
||||||
|
// initialWebpackConfig.plugins.push(new webpack.Plugin()); etc.
|
||||||
|
|
||||||
|
return initialWebpackConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
webpackConfig,
|
||||||
|
transformConfig
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
'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 */
|
||||||
|
|
||||||
|
build.initialize(require('gulp'));
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,57 @@
|
||||||
|
{
|
||||||
|
"name": "smart-dev-ops",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16.13.0 <17.0.0"
|
||||||
|
},
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "gulp bundle",
|
||||||
|
"clean": "gulp clean",
|
||||||
|
"test": "gulp test",
|
||||||
|
"serve": "gulp bundle --custom-serve --max_old_space_size=4096 && fast-serve"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@fluentui/react": "^7.199.1",
|
||||||
|
"@microsoft/sp-component-base": "1.17.4",
|
||||||
|
"@microsoft/sp-core-library": "1.17.4",
|
||||||
|
"@microsoft/sp-lodash-subset": "1.17.4",
|
||||||
|
"@microsoft/sp-office-ui-fabric-core": "1.17.4",
|
||||||
|
"@microsoft/sp-property-pane": "1.17.4",
|
||||||
|
"@microsoft/sp-webpart-base": "1.17.4",
|
||||||
|
"@pnp/logging": "^3.16.0",
|
||||||
|
"@pnp/spfx-controls-react": "3.15.0",
|
||||||
|
"html-react-parser": "^4.2.0",
|
||||||
|
"luxon": "^3.3.0",
|
||||||
|
"office-ui-fabric-react": "^7.199.1",
|
||||||
|
"react": "17.0.1",
|
||||||
|
"react-chat-elements": "^11.0.1",
|
||||||
|
"react-dom": "17.0.1",
|
||||||
|
"react-icons": "^4.10.1",
|
||||||
|
"semantic-ui-css": "^2.5.0",
|
||||||
|
"semantic-ui-react": "^2.1.4",
|
||||||
|
"tslib": "2.3.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@microsoft/eslint-config-spfx": "1.17.4",
|
||||||
|
"@microsoft/eslint-plugin-spfx": "1.17.4",
|
||||||
|
"@microsoft/rush-stack-compiler-4.5": "0.5.0",
|
||||||
|
"@microsoft/sp-build-web": "1.17.4",
|
||||||
|
"@microsoft/sp-module-interfaces": "1.17.4",
|
||||||
|
"@rushstack/eslint-config": "2.5.1",
|
||||||
|
"@types/luxon": "^3.3.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-import": "^2.27.5",
|
||||||
|
"eslint-plugin-prettier": "^4.2.1",
|
||||||
|
"eslint-plugin-react-hooks": "4.3.0",
|
||||||
|
"gulp": "4.0.2",
|
||||||
|
"prettier": "^2.8.4",
|
||||||
|
"spfx-fast-serve-helpers": "~1.17.0",
|
||||||
|
"typescript": "4.5.5"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
export class AppConstants {
|
||||||
|
private static DEVOPS_ORGANIZATION = "";
|
||||||
|
private static OPENAI_API_KEY = "";
|
||||||
|
|
||||||
|
public static getDevOpsOrganization() {
|
||||||
|
return AppConstants.DEVOPS_ORGANIZATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static setDevOpsOrganization(newValue: string) {
|
||||||
|
AppConstants.DEVOPS_ORGANIZATION = newValue;
|
||||||
|
}
|
||||||
|
public static getOpenAIKey() {
|
||||||
|
return AppConstants.OPENAI_API_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static setOpenAIKey(newValue: string) {
|
||||||
|
AppConstants.OPENAI_API_KEY = newValue;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
export const DEVOPS_BOT_NAME = "DevOps Bot";
|
||||||
|
export const OPENAI_API_ENDPOINT = "https://api.openai.com/v1/chat/completions";
|
||||||
|
export const GPT_MODELTO_USE = "gpt-3.5-turbo-0613";
|
||||||
|
//export const GPT_MODELTO_USE = 'gpt-4-0613';
|
||||||
|
export const TRY_LATER_MESSAGE =
|
||||||
|
"Sorry, I am unable to process your query at the moment. Please try again later.";
|
||||||
|
export const SYSTEM_MESSAGE = `
|
||||||
|
List all projects and their tasks assigned to you for a specific project. Also, help me with all tasks related to GIT such as creating a new branch, merging branches, resolving merge conflicts, pushing changes to the remote repository, and retrieving the latest commits.
|
||||||
|
Your final reply must be in HTML format surrounded in <span></span>.
|
||||||
|
Make the status bold using <b></b>.`;
|
||||||
|
export const FUNCTIONS = [
|
||||||
|
{
|
||||||
|
name: "getAssignedTasks",
|
||||||
|
description: "Get the all active tasks assigned to me across all projects",
|
||||||
|
parameters: {
|
||||||
|
type: "object",
|
||||||
|
required: ["projectName"],
|
||||||
|
properties: {
|
||||||
|
projectName: {
|
||||||
|
type: "string",
|
||||||
|
description: "The name or id of the Azure DevOps project.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "getAssignedBugs",
|
||||||
|
description: "Get the all active bugs assigned to me across all projects",
|
||||||
|
parameters: {
|
||||||
|
type: "object",
|
||||||
|
required: ["projectName"],
|
||||||
|
properties: {
|
||||||
|
projectName: {
|
||||||
|
type: "string",
|
||||||
|
description: "The name or id of the Azure DevOps project.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "getRecentCommitsAsync",
|
||||||
|
description:
|
||||||
|
"Get recent commits for given repository under specified project",
|
||||||
|
parameters: {
|
||||||
|
type: "object",
|
||||||
|
required: ["repositoryName", "projectName"],
|
||||||
|
properties: {
|
||||||
|
projectName: {
|
||||||
|
type: "string",
|
||||||
|
description: "The name or id of the Azure DevOps project.",
|
||||||
|
},
|
||||||
|
repositoryName: {
|
||||||
|
type: "string",
|
||||||
|
description: "The name of the Azure DevOps git repositories.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "showFunnyMessage",
|
||||||
|
description:
|
||||||
|
"If user's query is not related to TfL status then show a funny message",
|
||||||
|
parameters: {
|
||||||
|
type: "object",
|
||||||
|
required: ["funnyMessage"],
|
||||||
|
properties: {
|
||||||
|
funnyMessage: {
|
||||||
|
type: "string",
|
||||||
|
description:
|
||||||
|
"A funny message to say why user's query is not related to TfL. Max 20 words.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { IPropertyPaneCustomFieldProps } from '@microsoft/sp-property-pane';
|
||||||
|
import { IPropertyPaneAsyncDropdownProps } from './IPropertyPaneAsyncDropdownProps';
|
||||||
|
|
||||||
|
export interface IPropertyPaneAsyncDropdownInternalProps extends IPropertyPaneAsyncDropdownProps, IPropertyPaneCustomFieldProps {
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { IDropdownOption } from 'office-ui-fabric-react/lib/components/Dropdown';
|
||||||
|
|
||||||
|
export interface IPropertyPaneAsyncDropdownProps {
|
||||||
|
label: string;
|
||||||
|
loadOptions: () => Promise<IDropdownOption[]>;
|
||||||
|
onPropertyChange: (propertyPath: string, newValue: any) => void;
|
||||||
|
selectedKey: string | number;
|
||||||
|
disabled: boolean;
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as ReactDom from 'react-dom';
|
||||||
|
import { IPropertyPaneField, PropertyPaneFieldType } from '@microsoft/sp-property-pane';
|
||||||
|
import { IDropdownOption } from 'office-ui-fabric-react/lib/components/Dropdown';
|
||||||
|
import { IPropertyPaneAsyncDropdownProps } from './IPropertyPaneAsyncDropdownProps';
|
||||||
|
import { IPropertyPaneAsyncDropdownInternalProps } from './IPropertyPaneAsyncDropdownInternalProps';
|
||||||
|
import AsyncDropdown from './components/AsyncDropdown';
|
||||||
|
import { IAsyncDropdownProps } from './components/IAsyncDropdownProps';
|
||||||
|
|
||||||
|
export class PropertyPaneAsyncDropdown implements IPropertyPaneField<IPropertyPaneAsyncDropdownProps> {
|
||||||
|
public type: PropertyPaneFieldType = PropertyPaneFieldType.Custom;
|
||||||
|
public targetProperty: string;
|
||||||
|
public properties: IPropertyPaneAsyncDropdownInternalProps;
|
||||||
|
private elem: HTMLElement;
|
||||||
|
|
||||||
|
constructor(targetProperty: string, properties: IPropertyPaneAsyncDropdownProps) {
|
||||||
|
this.targetProperty = targetProperty;
|
||||||
|
this.properties = {
|
||||||
|
key: properties.label,
|
||||||
|
label: properties.label,
|
||||||
|
loadOptions: properties.loadOptions,
|
||||||
|
onPropertyChange: properties.onPropertyChange,
|
||||||
|
selectedKey: properties.selectedKey,
|
||||||
|
disabled: properties.disabled,
|
||||||
|
onRender: this.onRender.bind(this),
|
||||||
|
onDispose: this.onDispose.bind(this),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): void {
|
||||||
|
if (!this.elem) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.onRender(this.elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onDispose(element: HTMLElement): void {
|
||||||
|
ReactDom.unmountComponentAtNode(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onRender(elem: HTMLElement): void {
|
||||||
|
if (!this.elem) {
|
||||||
|
this.elem = elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
const element: React.ReactElement<IAsyncDropdownProps> = React.createElement(AsyncDropdown, {
|
||||||
|
label: this.properties.label,
|
||||||
|
loadOptions: this.properties.loadOptions,
|
||||||
|
onChanged: this.onChanged.bind(this),
|
||||||
|
selectedKey: this.properties.selectedKey,
|
||||||
|
disabled: this.properties.disabled,
|
||||||
|
// required to allow the component to be re-rendered by calling this.render() externally
|
||||||
|
stateKey: new Date().toString(),
|
||||||
|
});
|
||||||
|
ReactDom.render(element, elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onChanged(option: IDropdownOption, index?: number): void {
|
||||||
|
this.properties.onPropertyChange(this.targetProperty, option.key);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,103 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import { Dropdown, IDropdownOption } from 'office-ui-fabric-react/lib/components/Dropdown';
|
||||||
|
import { Spinner } from 'office-ui-fabric-react/lib/components/Spinner';
|
||||||
|
import { IAsyncDropdownProps } from './IAsyncDropdownProps';
|
||||||
|
import { IAsyncDropdownState } from './IAsyncDropdownState';
|
||||||
|
|
||||||
|
export default class AsyncDropdown extends React.Component<IAsyncDropdownProps, IAsyncDropdownState> {
|
||||||
|
private selectedKey: React.ReactText;
|
||||||
|
|
||||||
|
constructor(props: IAsyncDropdownProps, state: IAsyncDropdownState) {
|
||||||
|
super(props);
|
||||||
|
this.selectedKey = props.selectedKey;
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
loading: false,
|
||||||
|
options: [],
|
||||||
|
error: undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public componentDidMount(): void {
|
||||||
|
this.loadOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public componentDidUpdate(prevProps: IAsyncDropdownProps, prevState: IAsyncDropdownState): void {
|
||||||
|
if (this.props.disabled !== prevProps.disabled || this.props.stateKey !== prevProps.stateKey) {
|
||||||
|
this.loadOptions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private loadOptions(): void {
|
||||||
|
this.setState({
|
||||||
|
loading: true,
|
||||||
|
error: undefined,
|
||||||
|
options: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
this.props.loadOptions().then(
|
||||||
|
(options: IDropdownOption[]): void => {
|
||||||
|
this.setState({
|
||||||
|
loading: false,
|
||||||
|
error: undefined,
|
||||||
|
options: options,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
(error: any): void => {
|
||||||
|
this.setState((prevState: IAsyncDropdownState, props: IAsyncDropdownProps): IAsyncDropdownState => {
|
||||||
|
prevState.loading = false;
|
||||||
|
prevState.error = error;
|
||||||
|
return prevState;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): JSX.Element {
|
||||||
|
const loading: JSX.Element = this.state.loading ? (
|
||||||
|
<div>
|
||||||
|
<Spinner label={'Loading options...'} />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div />
|
||||||
|
);
|
||||||
|
const error: JSX.Element =
|
||||||
|
this.state.error !== undefined ? (
|
||||||
|
<div className={'ms-TextField-errorMessage ms-u-slideDownIn20'}>Error while loading items: {this.state.error}</div>
|
||||||
|
) : (
|
||||||
|
<div />
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Dropdown
|
||||||
|
label={this.props.label}
|
||||||
|
disabled={this.props.disabled || this.state.loading || this.state.error !== undefined}
|
||||||
|
onChanged={this.onChanged.bind(this)}
|
||||||
|
selectedKey={this.selectedKey}
|
||||||
|
options={this.state.options}
|
||||||
|
/>
|
||||||
|
{loading}
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onChanged(option: IDropdownOption, index?: number): void {
|
||||||
|
this.selectedKey = option.key;
|
||||||
|
// reset previously selected options
|
||||||
|
const options: IDropdownOption[] = this.state.options;
|
||||||
|
options.forEach((o: IDropdownOption): void => {
|
||||||
|
if (o.key !== option.key) {
|
||||||
|
o.selected = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.setState((prevState: IAsyncDropdownState, props: IAsyncDropdownProps): IAsyncDropdownState => {
|
||||||
|
prevState.options = options;
|
||||||
|
return prevState;
|
||||||
|
});
|
||||||
|
if (this.props.onChanged) {
|
||||||
|
this.props.onChanged(option, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { IDropdownOption } from 'office-ui-fabric-react/lib/components/Dropdown';
|
||||||
|
|
||||||
|
export interface IAsyncDropdownProps {
|
||||||
|
label: string;
|
||||||
|
loadOptions: () => Promise<IDropdownOption[]>;
|
||||||
|
onChanged: (option: IDropdownOption, index?: number) => void;
|
||||||
|
selectedKey: string | number;
|
||||||
|
disabled: boolean;
|
||||||
|
stateKey: string;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { IDropdownOption } from 'office-ui-fabric-react/lib/components/Dropdown';
|
||||||
|
|
||||||
|
export interface IAsyncDropdownState {
|
||||||
|
loading: boolean;
|
||||||
|
options: IDropdownOption[];
|
||||||
|
error: string | undefined;
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
import { Logger, LogLevel } from "@pnp/logging";
|
||||||
|
|
||||||
|
export class LogHelper {
|
||||||
|
public static verbose(
|
||||||
|
className: string,
|
||||||
|
methodName: string,
|
||||||
|
message: string
|
||||||
|
): void {
|
||||||
|
message = this._formatMessage(className, methodName, message);
|
||||||
|
Logger.write(message, LogLevel.Verbose);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static info(
|
||||||
|
className: string,
|
||||||
|
methodName: string,
|
||||||
|
message: string
|
||||||
|
): void {
|
||||||
|
message = this._formatMessage(className, methodName, message);
|
||||||
|
Logger.write(message, LogLevel.Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static warning(
|
||||||
|
className: string,
|
||||||
|
methodName: string,
|
||||||
|
message: string
|
||||||
|
): void {
|
||||||
|
message = this._formatMessage(className, methodName, message);
|
||||||
|
Logger.write(message, LogLevel.Warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static error(
|
||||||
|
className: string,
|
||||||
|
methodName: string,
|
||||||
|
message: string
|
||||||
|
): void {
|
||||||
|
message = this._formatMessage(className, methodName, message);
|
||||||
|
Logger.write(message, LogLevel.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static exception(
|
||||||
|
className: string,
|
||||||
|
methodName: string,
|
||||||
|
error: Error
|
||||||
|
): void {
|
||||||
|
error.message = this._formatMessage(className, methodName, error.message);
|
||||||
|
Logger.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static _formatMessage(
|
||||||
|
className: string,
|
||||||
|
methodName: string,
|
||||||
|
message: string
|
||||||
|
): string {
|
||||||
|
const d: Date = new Date();
|
||||||
|
const dateStr: string =
|
||||||
|
d.getDate() +
|
||||||
|
"-" +
|
||||||
|
(d.getMonth() + 1) +
|
||||||
|
"-" +
|
||||||
|
d.getFullYear() +
|
||||||
|
" " +
|
||||||
|
d.getHours() +
|
||||||
|
":" +
|
||||||
|
d.getMinutes() +
|
||||||
|
":" +
|
||||||
|
d.getSeconds() +
|
||||||
|
"." +
|
||||||
|
d.getMilliseconds();
|
||||||
|
return `${dateStr} ${className} > ${methodName} > ${message}`;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { DateTime } from "luxon";
|
||||||
|
|
||||||
|
export function stripHtml(htmlString: string) {
|
||||||
|
const pattern = /<[^>]+>/g;
|
||||||
|
const strippedString = htmlString.replace(pattern, "");
|
||||||
|
return strippedString;
|
||||||
|
}
|
||||||
|
export function getRelativeTime(dateString: string): string {
|
||||||
|
const now = DateTime.now().toMillis();
|
||||||
|
const date = DateTime.fromISO(dateString).toMillis();
|
||||||
|
|
||||||
|
const difference = now - date;
|
||||||
|
|
||||||
|
if (difference < 60 * 1000) {
|
||||||
|
return `${Math.round(difference / 1000)} seconds ago`;
|
||||||
|
} else if (difference < 60 * 60 * 1000) {
|
||||||
|
return `${Math.round(difference / 60000)} minutes ago`;
|
||||||
|
} else if (difference < 24 * 60 * 60 * 1000) {
|
||||||
|
return `${Math.round(difference / 3600000)} hours ago`;
|
||||||
|
} else {
|
||||||
|
return `${Math.round(difference / 86400000)} days ago`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export function getInitials(fullName: string): string {
|
||||||
|
const initials = [];
|
||||||
|
const words = fullName.split(" ");
|
||||||
|
for (const word of words) {
|
||||||
|
initials.push(word[0].toUpperCase());
|
||||||
|
}
|
||||||
|
return initials.join("");
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
export const getAssistantMessage = (functionName: string, functionArguments: any) => {
|
||||||
|
return {
|
||||||
|
role: 'assistant',
|
||||||
|
content: '',
|
||||||
|
function_call: {
|
||||||
|
name: functionName,
|
||||||
|
arguments: JSON.stringify(functionArguments),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getFunctionMessage = (functionName: string, functionResult: any) => {
|
||||||
|
return {
|
||||||
|
role: 'function',
|
||||||
|
name: functionName,
|
||||||
|
content: JSON.stringify(functionResult),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getUserMessage = (userMessage: string) => {
|
||||||
|
return {
|
||||||
|
role: 'user',
|
||||||
|
content: userMessage,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getSystemMessage = (systemMessage: string) => {
|
||||||
|
return {
|
||||||
|
role: 'system',
|
||||||
|
content: systemMessage,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './useOpenAI';
|
||||||
|
// export * from './useTfL';
|
|
@ -0,0 +1,81 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import { HttpClient } from "@microsoft/sp-http";
|
||||||
|
import {
|
||||||
|
OPENAI_API_ENDPOINT,
|
||||||
|
GPT_MODELTO_USE,
|
||||||
|
} from "../constants/OpenAPIConstants";
|
||||||
|
import { AppConstants } from "../constants/AppConstants";
|
||||||
|
|
||||||
|
export const useOpenAI = (httpClient: HttpClient) => {
|
||||||
|
const callOpenAI = React.useCallback(
|
||||||
|
async (messages: any[], functions: any[]) => {
|
||||||
|
try {
|
||||||
|
const endpoint: string = OPENAI_API_ENDPOINT;
|
||||||
|
|
||||||
|
const requestHeaders: any = {};
|
||||||
|
requestHeaders["Content-Type"] = "application/json";
|
||||||
|
requestHeaders.Authorization = `Bearer ${AppConstants.getOpenAIKey()}`;
|
||||||
|
|
||||||
|
const request: any = {};
|
||||||
|
request.model = GPT_MODELTO_USE;
|
||||||
|
request.messages = messages;
|
||||||
|
request.functions = functions;
|
||||||
|
/*
|
||||||
|
"temperature": 0,
|
||||||
|
"max_tokens": 256,
|
||||||
|
"top_p": 1.0,
|
||||||
|
"frequency_penalty": 0.0,
|
||||||
|
"presence_penalty": 0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
request.temperature = 0;
|
||||||
|
request.max_tokens = 256;
|
||||||
|
request.top_p = 1.0;
|
||||||
|
request.frequency_penalty = 0.0;
|
||||||
|
request.presence_penalty = 0.0;
|
||||||
|
|
||||||
|
const response = await httpClient.post(
|
||||||
|
endpoint,
|
||||||
|
HttpClient.configurations.v1,
|
||||||
|
{
|
||||||
|
headers: requestHeaders,
|
||||||
|
body: JSON.stringify(request),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("response", response);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
console.error("Error:", response);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
console.log("OpenAI API result - ", result);
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
if (!DEBUG) {
|
||||||
|
console.error("Error:", error);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[httpClient]
|
||||||
|
);
|
||||||
|
|
||||||
|
/* const callOpenAI_GPT35 = React.useCallback(
|
||||||
|
async (messages: any[], functions: any[]) => {
|
||||||
|
return await callOpenAI(messages, functions, "gpt-3.5-turbo-0613");
|
||||||
|
},
|
||||||
|
[callOpenAI]
|
||||||
|
);
|
||||||
|
|
||||||
|
const callOpenAI_GPT4 = React.useCallback(
|
||||||
|
async (messages: any[], functions: any[]) => {
|
||||||
|
return await callOpenAI(messages, functions, "gpt-4-0613");
|
||||||
|
},
|
||||||
|
[callOpenAI]
|
||||||
|
); */
|
||||||
|
|
||||||
|
return { callOpenAI };
|
||||||
|
};
|
|
@ -0,0 +1 @@
|
||||||
|
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,90 @@
|
||||||
|
export interface IProfile {
|
||||||
|
displayName?: string;
|
||||||
|
publicAlias?: string;
|
||||||
|
emailAddress?: string;
|
||||||
|
coreRevision?: number;
|
||||||
|
timeStamp?: string;
|
||||||
|
id: string;
|
||||||
|
revisionrevision?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IWorkItemReference {
|
||||||
|
id?: string;
|
||||||
|
url?: string;
|
||||||
|
}
|
||||||
|
export interface IWorkItem {
|
||||||
|
id?: number;
|
||||||
|
url?: string;
|
||||||
|
rev?: number;
|
||||||
|
fields?: {};
|
||||||
|
WorkItemRelation?: any;
|
||||||
|
}
|
||||||
|
export interface IWorkItemDetails {
|
||||||
|
url: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
teamProject: string;
|
||||||
|
orgName: string;
|
||||||
|
createdDate: string;
|
||||||
|
assignedTo: {
|
||||||
|
displayName: string;
|
||||||
|
id: string;
|
||||||
|
uniqueName: string;
|
||||||
|
imageUrl: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export interface IWorkItemBug {
|
||||||
|
url: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
teamProject: string;
|
||||||
|
orgName: string;
|
||||||
|
createdDate: string;
|
||||||
|
assignedTo: {
|
||||||
|
displayName: string;
|
||||||
|
id: string;
|
||||||
|
uniqueName: string;
|
||||||
|
imageUrl: string;
|
||||||
|
};
|
||||||
|
priority: number;
|
||||||
|
severity: string;
|
||||||
|
}
|
||||||
|
export interface ICommitDetail {
|
||||||
|
commitId: string;
|
||||||
|
author: Author;
|
||||||
|
committer: Author;
|
||||||
|
comment: string;
|
||||||
|
changeCounts: ChangeCounts;
|
||||||
|
url: string;
|
||||||
|
remoteUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ChangeCounts {
|
||||||
|
Add: number;
|
||||||
|
Edit: number;
|
||||||
|
Delete: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Author {
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
date: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IAccount {
|
||||||
|
accountId: string;
|
||||||
|
accountUri?: string;
|
||||||
|
accountName: string;
|
||||||
|
properties?: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IChatMessage {
|
||||||
|
position: string;
|
||||||
|
type: string;
|
||||||
|
title: string;
|
||||||
|
text: string | JSX.Element | JSX.Element[];
|
||||||
|
date: Date;
|
||||||
|
focus?: boolean;
|
||||||
|
status?: "waiting" | "sent" | "received" | "read";
|
||||||
|
className?: string;
|
||||||
|
}
|
|
@ -0,0 +1,103 @@
|
||||||
|
import { AppConstants } from "../constants/AppConstants";
|
||||||
|
import { getRelativeTime } from "../helpers/UtilityHelper";
|
||||||
|
import {
|
||||||
|
ICommitDetail,
|
||||||
|
IWorkItemBug,
|
||||||
|
IWorkItemDetails,
|
||||||
|
} from "../interfaces/webpart.types";
|
||||||
|
|
||||||
|
export default class DevOpsMapper {
|
||||||
|
public static mapDevOpsCommits(commit: ICommitDetail): ICommitDetail {
|
||||||
|
return {
|
||||||
|
commitId: commit.commitId,
|
||||||
|
author: {
|
||||||
|
name: commit.author.name ?? "",
|
||||||
|
email: commit.author.email ?? "",
|
||||||
|
date: getRelativeTime(commit.author.date) ?? "",
|
||||||
|
},
|
||||||
|
committer: {
|
||||||
|
name: commit.committer.name ?? "",
|
||||||
|
email: commit.committer.email ?? "",
|
||||||
|
date: getRelativeTime(commit.committer.date) ?? "",
|
||||||
|
},
|
||||||
|
comment: commit.comment ?? "",
|
||||||
|
changeCounts: {
|
||||||
|
Add: commit.changeCounts.Add,
|
||||||
|
Edit: commit.changeCounts.Edit,
|
||||||
|
Delete: commit.changeCounts.Delete,
|
||||||
|
},
|
||||||
|
url: commit.url,
|
||||||
|
remoteUrl: commit.remoteUrl ?? "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const mapDevOpsTasks = (item: any) => {
|
||||||
|
const workItemDetails: IWorkItemDetails = {
|
||||||
|
url: `https://dev.azure.com/${AppConstants.getDevOpsOrganization()}/${
|
||||||
|
item.fields["System.TeamProject"]
|
||||||
|
}/_workitems/edit/${item.id}/`,
|
||||||
|
title: item.fields["System.Title"] ?? "",
|
||||||
|
description: item.fields["System.Description"] ?? "",
|
||||||
|
teamProject: item.fields["System.TeamProject"] ?? "",
|
||||||
|
orgName: AppConstants.getDevOpsOrganization(),
|
||||||
|
createdDate: item.fields["System.CreatedDate"] ?? "",
|
||||||
|
assignedTo: {
|
||||||
|
displayName: item.fields["System.AssignedTo"]?.displayName ?? "",
|
||||||
|
id: item.fields["System.AssignedTo"]?.id ?? "",
|
||||||
|
uniqueName: item.fields["System.AssignedTo"]?.uniqueName ?? "",
|
||||||
|
imageUrl: item.fields["System.AssignedTo"]?.imageUrl ?? "",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return workItemDetails;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const mapDevOpsBugs = (item: any) => {
|
||||||
|
const workItemDetails: IWorkItemBug = {
|
||||||
|
url: `https://dev.azure.com/${AppConstants.getDevOpsOrganization()}/${
|
||||||
|
item.fields["System.TeamProject"]
|
||||||
|
}/_workitems/edit/${item.id}/`,
|
||||||
|
title: item.fields["System.Title"] ?? "",
|
||||||
|
description: item.fields["System.Description"] ?? "",
|
||||||
|
teamProject: item.fields["System.TeamProject"] ?? "",
|
||||||
|
orgName: AppConstants.getDevOpsOrganization(),
|
||||||
|
createdDate: item.fields["System.CreatedDate"] ?? "",
|
||||||
|
assignedTo: {
|
||||||
|
displayName: item.fields["System.AssignedTo"]?.displayName ?? "",
|
||||||
|
id: item.fields["System.AssignedTo"]?.id ?? "",
|
||||||
|
uniqueName: item.fields["System.AssignedTo"]?.uniqueName ?? "",
|
||||||
|
imageUrl: item.fields["System.AssignedTo"]?.imageUrl ?? "",
|
||||||
|
},
|
||||||
|
priority: item.fields["Microsoft.VSTS.Common.Priority"] ?? undefined,
|
||||||
|
severity: item.fields["Microsoft.VSTS.Common.Severity"] ?? "",
|
||||||
|
};
|
||||||
|
return workItemDetails;
|
||||||
|
};
|
||||||
|
|
||||||
|
// export const mapDevOpsCommits = (
|
||||||
|
// item: ICommitDetail,
|
||||||
|
// repositoryName: string
|
||||||
|
// ) => {
|
||||||
|
// const commitItem: ICommitDetail = {
|
||||||
|
// commitId: item.commitId,
|
||||||
|
// author: {
|
||||||
|
// name: item.author.name ?? "",
|
||||||
|
// email: item.author.email ?? "",
|
||||||
|
// date: getRelativeTime(item.author.date) ?? "",
|
||||||
|
// },
|
||||||
|
// committer: {
|
||||||
|
// name: item.committer.name ?? "",
|
||||||
|
// email: item.committer.email ?? "",
|
||||||
|
// date: getRelativeTime(item.committer.date) ?? "",
|
||||||
|
// },
|
||||||
|
// comment: item.comment ?? "",
|
||||||
|
// changeCounts: {
|
||||||
|
// Add: item.changeCounts.Add,
|
||||||
|
// Edit: item.changeCounts.Edit,
|
||||||
|
// Delete: item.changeCounts.Delete,
|
||||||
|
// },
|
||||||
|
// url: item.url,
|
||||||
|
// remoteUrl: item.remoteUrl ?? "",
|
||||||
|
// };
|
||||||
|
// return commitItem;
|
||||||
|
// };
|
|
@ -0,0 +1,137 @@
|
||||||
|
import { WebPartContext } from "@microsoft/sp-webpart-base";
|
||||||
|
import {
|
||||||
|
IAccount,
|
||||||
|
ICommitDetail,
|
||||||
|
IProfile,
|
||||||
|
IWorkItem,
|
||||||
|
IWorkItemReference,
|
||||||
|
} from "../interfaces/webpart.types";
|
||||||
|
import { LogHelper } from "../helpers/LogHelper";
|
||||||
|
import { AadHttpClient } from "@microsoft/sp-http";
|
||||||
|
|
||||||
|
export default class AzureDevOpsService {
|
||||||
|
private static client: AadHttpClient;
|
||||||
|
private static readonly endpoint: string =
|
||||||
|
"499b84ac-1321-427f-aa17-267ca6975798";
|
||||||
|
|
||||||
|
public static async Init(context: WebPartContext): Promise<void> {
|
||||||
|
this.client = await context.aadHttpClientFactory.getClient(
|
||||||
|
AzureDevOpsService.endpoint
|
||||||
|
);
|
||||||
|
LogHelper.info("AzureDevOpsService", "Init", "Aad HttpClient Initialized");
|
||||||
|
}
|
||||||
|
public static async getProfile(): Promise<IProfile> {
|
||||||
|
const response = await this.client.get(
|
||||||
|
"https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=7.1-preview.3",
|
||||||
|
AadHttpClient.configurations.v1
|
||||||
|
);
|
||||||
|
const json = await response.json();
|
||||||
|
return json as IProfile;
|
||||||
|
}
|
||||||
|
public static async getAccounts(memberId: string): Promise<IAccount[]> {
|
||||||
|
const response = await this.client.get(
|
||||||
|
`https://app.vssps.visualstudio.com/_apis/accounts?memberId=${memberId}&api-version=7.1-preview.1`,
|
||||||
|
AadHttpClient.configurations.v1
|
||||||
|
);
|
||||||
|
const json = await response.json();
|
||||||
|
return json.value as IAccount[];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async getWorkItemsAsync(
|
||||||
|
ids: string[],
|
||||||
|
projectName: string,
|
||||||
|
organizationName: string
|
||||||
|
): Promise<IWorkItem[]> {
|
||||||
|
const response = await this.client.get(
|
||||||
|
`https://dev.azure.com/${organizationName}/${projectName}/_apis/wit/workitems?ids=${ids}&api-version=7.0`,
|
||||||
|
AadHttpClient.configurations.v1
|
||||||
|
);
|
||||||
|
const json = await response.json();
|
||||||
|
return json.value as IWorkItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async getAssignedTasks(
|
||||||
|
projectName: string,
|
||||||
|
organizationName: string
|
||||||
|
): Promise<IWorkItem[]> {
|
||||||
|
const response = await this.client.post(
|
||||||
|
`https://dev.azure.com/${organizationName}/${projectName}/_apis/wit/wiql?api-version=7.0`,
|
||||||
|
AadHttpClient.configurations.v1,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
query:
|
||||||
|
"SELECT [System.Id],[System.Title],[System.State] FROM WorkItems" +
|
||||||
|
" WHERE [System.WorkItemType] = 'Task'" +
|
||||||
|
" AND [State] <> 'Closed'" +
|
||||||
|
" AND [State] <> 'Removed'" +
|
||||||
|
" AND [System.AssignedTo] = @Me",
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const json = await response.json();
|
||||||
|
const workItems = json.workItems as IWorkItemReference[];
|
||||||
|
const ids: any[] = workItems.map((item) => item.id);
|
||||||
|
// some error handling
|
||||||
|
if (ids.length === 0) {
|
||||||
|
return [] as IWorkItem[];
|
||||||
|
}
|
||||||
|
const result = await this.getWorkItemsAsync(
|
||||||
|
ids,
|
||||||
|
projectName,
|
||||||
|
organizationName
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public static async getAssignedBugs(
|
||||||
|
projectName: string,
|
||||||
|
organizationName: string
|
||||||
|
): Promise<IWorkItem[]> {
|
||||||
|
const response = await this.client.post(
|
||||||
|
`https://dev.azure.com/${organizationName}/${projectName}/_apis/wit/wiql?api-version=7.0`,
|
||||||
|
AadHttpClient.configurations.v1,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
query:
|
||||||
|
"SELECT [System.Id],[System.Title],[System.State] FROM WorkItems" +
|
||||||
|
" WHERE [System.WorkItemType] = 'Bug'" +
|
||||||
|
" AND [State] <> 'Closed'" +
|
||||||
|
" AND [State] <> 'Removed'" +
|
||||||
|
" AND [System.AssignedTo] = @Me",
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const json = await response.json();
|
||||||
|
const workItems = json.workItems as IWorkItemReference[];
|
||||||
|
const ids: any[] = workItems.map((item) => item.id);
|
||||||
|
// some error handling
|
||||||
|
if (ids.length === 0) {
|
||||||
|
return [] as IWorkItem[];
|
||||||
|
}
|
||||||
|
const result = await this.getWorkItemsAsync(
|
||||||
|
ids,
|
||||||
|
projectName,
|
||||||
|
organizationName
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async getRecentCommitsAsync(
|
||||||
|
projectName: string,
|
||||||
|
repositoryName: string,
|
||||||
|
organizationName: string
|
||||||
|
): Promise<ICommitDetail[]> {
|
||||||
|
const requestUrl = `https://dev.azure.com/${organizationName}/${projectName}/_apis/git/repositories/${repositoryName}/commits?api-version=7.0`;
|
||||||
|
const response = await this.client.get(
|
||||||
|
requestUrl,
|
||||||
|
AadHttpClient.configurations.v1
|
||||||
|
);
|
||||||
|
const json = await response.json();
|
||||||
|
return json.value as ICommitDetail[];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||||
|
"id": "238b4413-e2c2-428c-ae07-9365fe5871ad",
|
||||||
|
"alias": "SmartDevOpsWebPart",
|
||||||
|
"componentType": "WebPart",
|
||||||
|
// The "*" signifies that the version should be taken from the package.json
|
||||||
|
"version": "*",
|
||||||
|
"manifestVersion": 2,
|
||||||
|
// If true, the component can only be installed on sites where Custom Script is allowed.
|
||||||
|
// Components that allow authors to embed arbitrary script code should set this to true.
|
||||||
|
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
|
||||||
|
"requiresCustomScript": false,
|
||||||
|
"supportedHosts": [
|
||||||
|
"SharePointWebPart",
|
||||||
|
"TeamsPersonalApp",
|
||||||
|
"TeamsTab",
|
||||||
|
"SharePointFullPage"
|
||||||
|
],
|
||||||
|
"supportsFullBleed": true,
|
||||||
|
"supportsThemeVariants": true,
|
||||||
|
"preconfiguredEntries": [
|
||||||
|
{
|
||||||
|
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Advanced
|
||||||
|
"group": {
|
||||||
|
"default": "Advanced"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"default": "[O3C] Smart DevOps"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"default": "SmartDevOps description"
|
||||||
|
},
|
||||||
|
"officeFabricIconFontName": "TaskLogo",
|
||||||
|
"properties": {
|
||||||
|
"description": "SmartDevOps"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,192 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import * as ReactDom from "react-dom";
|
||||||
|
import { Version } from "@microsoft/sp-core-library";
|
||||||
|
import {
|
||||||
|
IPropertyPaneConfiguration,
|
||||||
|
PropertyPaneTextField,
|
||||||
|
} from "@microsoft/sp-property-pane";
|
||||||
|
import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base";
|
||||||
|
import { IReadonlyTheme } from "@microsoft/sp-component-base";
|
||||||
|
import * as strings from "SmartDevOpsWebPartStrings";
|
||||||
|
import { ISmartDevOpsProps } from "./components/ISmartDevOpsProps";
|
||||||
|
import { ConsoleListener, Logger } from "@pnp/logging";
|
||||||
|
import AzureDevOpsService from "../../services/AzureDevOpsService";
|
||||||
|
import { SmartDevOps } from "./components/SmartDevOps";
|
||||||
|
import { PropertyPaneAsyncDropdown } from "../../controls/PropertyPaneAsyncDropdown/PropertyPaneAsyncDropdown";
|
||||||
|
import { IDropdownOption } from "@fluentui/react";
|
||||||
|
//import { get, update } from '@microsoft/sp-lodash-subset';
|
||||||
|
import { SPComponentLoader } from "@microsoft/sp-loader";
|
||||||
|
|
||||||
|
export interface ISmartDevOpsWebPartProps {
|
||||||
|
organizationName: string;
|
||||||
|
openAPIKey: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const LOG_SOURCE: string = "SmartDevOpsWebPart";
|
||||||
|
export default class SmartDevOpsWebPart extends BaseClientSideWebPart<ISmartDevOpsWebPartProps> {
|
||||||
|
private _isDarkTheme: boolean = false;
|
||||||
|
private _environmentMessage: string = "";
|
||||||
|
|
||||||
|
public render(): void {
|
||||||
|
const element: React.ReactElement<ISmartDevOpsProps> = React.createElement(
|
||||||
|
SmartDevOps,
|
||||||
|
{
|
||||||
|
context: this.context,
|
||||||
|
organizationName: this.properties.organizationName,
|
||||||
|
openAPIKey: this.properties.openAPIKey,
|
||||||
|
isDarkTheme: this._isDarkTheme,
|
||||||
|
environmentMessage: this._environmentMessage,
|
||||||
|
hasTeamsContext: !!this.context.sdks.microsoftTeams,
|
||||||
|
userDisplayName: this.context.pageContext.user.displayName,
|
||||||
|
httpClient: this.context.httpClient,
|
||||||
|
configureWebPart: this.configureWebPart,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
ReactDom.render(element, this.domElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async onInit(): Promise<void> {
|
||||||
|
// subscribe a listener
|
||||||
|
Logger.subscribe(
|
||||||
|
ConsoleListener(LOG_SOURCE, { warning: "#e36c0b", error: "#a80000" })
|
||||||
|
);
|
||||||
|
|
||||||
|
SPComponentLoader.loadCss(
|
||||||
|
"https://cdn.jsdelivr.net/npm/semantic-ui@2/dist/semantic.min.css"
|
||||||
|
);
|
||||||
|
|
||||||
|
//Init Azure DevOps Service
|
||||||
|
await AzureDevOpsService.Init(this.context);
|
||||||
|
|
||||||
|
return this._getEnvironmentMessage().then((message) => {
|
||||||
|
this._environmentMessage = message;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getEnvironmentMessage(): Promise<string> {
|
||||||
|
if (!!this.context.sdks.microsoftTeams) {
|
||||||
|
// running in Teams, office.com or Outlook
|
||||||
|
return this.context.sdks.microsoftTeams.teamsJs.app
|
||||||
|
.getContext()
|
||||||
|
.then((context) => {
|
||||||
|
let environmentMessage: string = "";
|
||||||
|
switch (context.app.host.name) {
|
||||||
|
case "Office": // running in Office
|
||||||
|
environmentMessage = this.context.isServedFromLocalhost
|
||||||
|
? strings.AppLocalEnvironmentOffice
|
||||||
|
: strings.AppOfficeEnvironment;
|
||||||
|
break;
|
||||||
|
case "Outlook": // running in Outlook
|
||||||
|
environmentMessage = this.context.isServedFromLocalhost
|
||||||
|
? strings.AppLocalEnvironmentOutlook
|
||||||
|
: strings.AppOutlookEnvironment;
|
||||||
|
break;
|
||||||
|
case "Teams": // running in Teams
|
||||||
|
environmentMessage = this.context.isServedFromLocalhost
|
||||||
|
? strings.AppLocalEnvironmentTeams
|
||||||
|
: strings.AppTeamsTabEnvironment;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error("Unknown host");
|
||||||
|
}
|
||||||
|
|
||||||
|
return environmentMessage;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve(
|
||||||
|
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 onDispose(): void {
|
||||||
|
ReactDom.unmountComponentAtNode(this.domElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected get dataVersion(): Version {
|
||||||
|
return Version.parse("1.0");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||||
|
return {
|
||||||
|
pages: [
|
||||||
|
{
|
||||||
|
groups: [
|
||||||
|
{
|
||||||
|
groupName: strings.OpenAPISettingsGroupName,
|
||||||
|
groupFields: [
|
||||||
|
PropertyPaneTextField("openAPIKey", {
|
||||||
|
label: "Open API Key",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
groupName: strings.DevOpsSettingsGroupName,
|
||||||
|
groupFields: [
|
||||||
|
new PropertyPaneAsyncDropdown("organizationName", {
|
||||||
|
label: "Organization name",
|
||||||
|
loadOptions: this.loadsDevOpsOrgs.bind(this),
|
||||||
|
onPropertyChange: this.onChange.bind(this),
|
||||||
|
selectedKey: this.properties.organizationName,
|
||||||
|
disabled: false,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
private configureWebPart(): void {
|
||||||
|
this.context.propertyPane.open();
|
||||||
|
}
|
||||||
|
private loadsDevOpsOrgs(): Promise<IDropdownOption[]> {
|
||||||
|
return new Promise<IDropdownOption[]>(async (resolve, reject) => {
|
||||||
|
let options: IDropdownOption[] = [];
|
||||||
|
|
||||||
|
const profile = await AzureDevOpsService.getProfile();
|
||||||
|
const accounts = await AzureDevOpsService.getAccounts(profile.id);
|
||||||
|
options = accounts.map((account) => {
|
||||||
|
return {
|
||||||
|
key: account.accountName,
|
||||||
|
text: account.accountName,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
resolve(options);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private onChange(propertyPath: string, newValue: any): void {
|
||||||
|
if (propertyPath === "organizationName" && newValue) {
|
||||||
|
// Update the web part property
|
||||||
|
this.properties.organizationName = newValue;
|
||||||
|
// Refresh the web part to reflect the new property value
|
||||||
|
this.render();
|
||||||
|
this.context.propertyPane.refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,51 @@
|
||||||
|
@import "~@fluentui/react/dist/sass/References.scss";
|
||||||
|
|
||||||
|
.dateFormat {
|
||||||
|
color: "[theme:themePrimary, default: #0078d7]" !important;
|
||||||
|
font-weight: 500;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-size: 12px;
|
||||||
|
margin: 4px 0 0;
|
||||||
|
}
|
||||||
|
.bugList {
|
||||||
|
.header {
|
||||||
|
font-weight: 400 !important;
|
||||||
|
font-size: 14px !important;
|
||||||
|
color: #0065b1 !important;
|
||||||
|
}
|
||||||
|
// li {
|
||||||
|
// display: flex;
|
||||||
|
// margin-bottom: 10px;
|
||||||
|
// font-size: 14px;
|
||||||
|
// border-bottom: 1px dotted "[theme:link, default:#03787c]";
|
||||||
|
// .icon {
|
||||||
|
// width: 40px;
|
||||||
|
// display: flex;
|
||||||
|
// align-items: baseline;
|
||||||
|
// justify-content: center;
|
||||||
|
// color: "[theme:successIcon, default:#03787c]";
|
||||||
|
// font-size: 23px;
|
||||||
|
// margin-top: 8px;
|
||||||
|
// }
|
||||||
|
// .content {
|
||||||
|
// display: flex;
|
||||||
|
// flex-direction: column;
|
||||||
|
// align-items: self-start;
|
||||||
|
// margin-left: 5px;
|
||||||
|
// font-size: 14px;
|
||||||
|
// padding: 5px 0;
|
||||||
|
// a {
|
||||||
|
// text-decoration: none;
|
||||||
|
// color: "[theme:link, default:#03787c]";
|
||||||
|
// cursor: pointer;
|
||||||
|
// .title {
|
||||||
|
// font-weight: 500;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// .description {
|
||||||
|
// text-align: left;
|
||||||
|
// font-size: 12px;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import styles from "./BugList.module.scss";
|
||||||
|
import { IWorkItemBug } from "../../../../interfaces/webpart.types";
|
||||||
|
import { Header, Label, List } from "semantic-ui-react";
|
||||||
|
import { getRelativeTime, stripHtml } from "../../../../helpers/UtilityHelper";
|
||||||
|
|
||||||
|
interface IBugListProps {
|
||||||
|
bugs: IWorkItemBug[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const BugList = ({ bugs }: IBugListProps) => {
|
||||||
|
const bugItems = bugs.map((bug: IWorkItemBug, index: number) => {
|
||||||
|
return (
|
||||||
|
<List key={index} selection size="mini">
|
||||||
|
<List.Item>
|
||||||
|
<List.Icon name="bug" size="large" verticalAlign="middle" />
|
||||||
|
<List.Content>
|
||||||
|
<List.Header
|
||||||
|
className={styles.header}
|
||||||
|
as="a"
|
||||||
|
target="_blank"
|
||||||
|
data-interception="off"
|
||||||
|
href={bug.url}
|
||||||
|
>
|
||||||
|
{bug.title}
|
||||||
|
</List.Header>
|
||||||
|
<List.Description>{stripHtml(bug.description)}</List.Description>
|
||||||
|
<List.Description className={styles.dateFormat}>
|
||||||
|
<List.Item>
|
||||||
|
<Label horizontal>Created</Label>
|
||||||
|
{getRelativeTime(bug.createdDate)}
|
||||||
|
<Label style={{ marginLeft: "5px" }} horizontal>
|
||||||
|
Priority
|
||||||
|
</Label>
|
||||||
|
{bug.priority}
|
||||||
|
</List.Item>
|
||||||
|
</List.Description>
|
||||||
|
</List.Content>
|
||||||
|
</List.Item>
|
||||||
|
</List>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Header as="h2">
|
||||||
|
Bugs
|
||||||
|
<Header.Subheader>Bugs assigned to me</Header.Subheader>
|
||||||
|
</Header>
|
||||||
|
<div className={styles.bugList}>{bugItems}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default BugList;
|
|
@ -0,0 +1,12 @@
|
||||||
|
@import "~@fluentui/react/dist/sass/References.scss";
|
||||||
|
|
||||||
|
.commitList {
|
||||||
|
.dateFormat {
|
||||||
|
color: "[theme:themePrimary, default: #0078d7]" !important;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
font-weight: 400 !important;
|
||||||
|
font-size: 14px !important;
|
||||||
|
color: #0065b1 !important;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import styles from "./CommitList.module.scss";
|
||||||
|
import { List, Image, Header, Label } from "semantic-ui-react";
|
||||||
|
import { ICommitDetail } from "../../../../interfaces/webpart.types";
|
||||||
|
import { getInitials } from "../../../../helpers/UtilityHelper";
|
||||||
|
|
||||||
|
interface ICommitListProps {
|
||||||
|
commits: ICommitDetail[];
|
||||||
|
respositoryName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CommitList = ({ commits, respositoryName }: ICommitListProps) => {
|
||||||
|
const recentCommits = commits.map((commit: ICommitDetail, index: number) => {
|
||||||
|
return (
|
||||||
|
<List key={commit.commitId} selection size="medium">
|
||||||
|
<List.Item>
|
||||||
|
<Image
|
||||||
|
avatar
|
||||||
|
src="https://react.semantic-ui.com/images/avatar/small/elliot.jpg"
|
||||||
|
/>
|
||||||
|
<List.Content>
|
||||||
|
<List.Header
|
||||||
|
className={styles.header}
|
||||||
|
as="a"
|
||||||
|
target="_blank"
|
||||||
|
data-interception="off"
|
||||||
|
href={commit.remoteUrl}
|
||||||
|
>
|
||||||
|
{commit.comment}
|
||||||
|
</List.Header>
|
||||||
|
<List.Description>
|
||||||
|
<List.Item>
|
||||||
|
{/* <Label basic horizontal>
|
||||||
|
Created
|
||||||
|
</Label> */}
|
||||||
|
{commit.committer.date}
|
||||||
|
<Label as="a" style={{ marginLeft: "5px" }} horizontal>
|
||||||
|
{commit.commitId}
|
||||||
|
</Label>
|
||||||
|
<Label
|
||||||
|
as="a"
|
||||||
|
color="teal"
|
||||||
|
style={{ marginLeft: "5px" }}
|
||||||
|
horizontal
|
||||||
|
>
|
||||||
|
{getInitials(commit.committer.name)}
|
||||||
|
</Label>
|
||||||
|
</List.Item>
|
||||||
|
</List.Description>
|
||||||
|
</List.Content>
|
||||||
|
</List.Item>
|
||||||
|
</List>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Header as="h2">
|
||||||
|
Recent commits
|
||||||
|
<Header.Subheader>
|
||||||
|
Recent commits from DevOps git repository - {respositoryName}
|
||||||
|
</Header.Subheader>
|
||||||
|
</Header>
|
||||||
|
<div className={styles.commitList}>{recentCommits}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CommitList;
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { HttpClient } from "@microsoft/sp-http";
|
||||||
|
import { WebPartContext } from "@microsoft/sp-webpart-base";
|
||||||
|
|
||||||
|
export interface ISmartDevOpsProps {
|
||||||
|
context: WebPartContext;
|
||||||
|
organizationName: string;
|
||||||
|
openAPIKey: string;
|
||||||
|
isDarkTheme: boolean;
|
||||||
|
environmentMessage: string;
|
||||||
|
hasTeamsContext: boolean;
|
||||||
|
userDisplayName: string;
|
||||||
|
httpClient: HttpClient;
|
||||||
|
configureWebPart: () => void;
|
||||||
|
}
|
1
samples/react-openai-devops/src/webparts/smartDevOps/components/ReactChatElements.d.ts
vendored
Normal file
1
samples/react-openai-devops/src/webparts/smartDevOps/components/ReactChatElements.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
declare module 'react-chat-elements';
|
|
@ -0,0 +1,39 @@
|
||||||
|
@import '~@fluentui/react/dist/sass/References.scss';
|
||||||
|
|
||||||
|
.smartDevOps {
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 1em;
|
||||||
|
color: '[theme:bodyText, default: #323130]';
|
||||||
|
color: var(--bodyText);
|
||||||
|
&.teams {
|
||||||
|
font-family: $ms-font-family-fallbacks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.welcome {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.welcomeImage {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 420px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links {
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: '[theme:link, default:#03787c]';
|
||||||
|
color: var(--link); // note: CSS Custom Properties support is limited to modern browsers only
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
color: '[theme:linkHovered, default: #014446]';
|
||||||
|
color: var(--linkHovered); // note: CSS Custom Properties support is limited to modern browsers only
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// :global {
|
||||||
|
// // .rce-mbox .message-focus {
|
||||||
|
// // background-color: 'cornsilk';
|
||||||
|
// // }
|
||||||
|
// }
|
|
@ -0,0 +1,441 @@
|
||||||
|
import * as React from "react";
|
||||||
|
//import styles from "./SmartDevOps.module.scss";
|
||||||
|
import { ISmartDevOpsProps } from "./ISmartDevOpsProps";
|
||||||
|
import AzureDevOpsService from "../../../services/AzureDevOpsService";
|
||||||
|
import "react-chat-elements/dist/main.css";
|
||||||
|
// MessageBox component
|
||||||
|
import { MessageList } from "react-chat-elements";
|
||||||
|
import { IChatMessage, IWorkItem } from "../../../interfaces/webpart.types";
|
||||||
|
import {
|
||||||
|
getStyles,
|
||||||
|
loadingSpinnerStyles,
|
||||||
|
sendChatTextFiledStyles,
|
||||||
|
} from "./styles";
|
||||||
|
import { TextField } from "@fluentui/react/lib/TextField";
|
||||||
|
import {
|
||||||
|
getSystemMessage,
|
||||||
|
getUserMessage,
|
||||||
|
} from "../../../helpers/openaiHelpers";
|
||||||
|
import {
|
||||||
|
DEVOPS_BOT_NAME,
|
||||||
|
FUNCTIONS,
|
||||||
|
SYSTEM_MESSAGE,
|
||||||
|
TRY_LATER_MESSAGE,
|
||||||
|
} from "../../../constants/OpenAPIConstants";
|
||||||
|
import { useOpenAI } from "../../../hooks";
|
||||||
|
import { IconButton, Spinner, SpinnerSize } from "@fluentui/react";
|
||||||
|
import DevOpsMapper, {
|
||||||
|
mapDevOpsBugs,
|
||||||
|
mapDevOpsTasks,
|
||||||
|
} from "../../../mapper/DevOpsMapper";
|
||||||
|
import TaskList from "./TaskList/TaskList";
|
||||||
|
import parse from "html-react-parser";
|
||||||
|
import { Placeholder } from "@pnp/spfx-controls-react";
|
||||||
|
import * as strings from "SmartDevOpsWebPartStrings";
|
||||||
|
import { AppConstants } from "../../../constants/AppConstants";
|
||||||
|
import BugList from "./BugList/BugList";
|
||||||
|
import CommitList from "./CommitList/CommitList";
|
||||||
|
import {
|
||||||
|
Divider,
|
||||||
|
Grid,
|
||||||
|
Header,
|
||||||
|
Label,
|
||||||
|
List,
|
||||||
|
Message,
|
||||||
|
Segment,
|
||||||
|
} from "semantic-ui-react";
|
||||||
|
|
||||||
|
const firstChatMessage: IChatMessage = {
|
||||||
|
position: "left",
|
||||||
|
type: "text",
|
||||||
|
title: DEVOPS_BOT_NAME,
|
||||||
|
text: (
|
||||||
|
<>
|
||||||
|
Hi, I am the <b>DevOps Bot</b>. I can help you with queries about the
|
||||||
|
Azure DevOps tasks. Please type your query below.
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
date: new Date(),
|
||||||
|
focus: true,
|
||||||
|
};
|
||||||
|
export const SmartDevOps: React.FC<ISmartDevOpsProps> = (props) => {
|
||||||
|
const systemMessage = getSystemMessage(SYSTEM_MESSAGE);
|
||||||
|
|
||||||
|
const { httpClient, organizationName, openAPIKey, context } = props;
|
||||||
|
const [loading, setLoading] = React.useState<boolean>(false);
|
||||||
|
const [query, setQuery] = React.useState<string>("");
|
||||||
|
const [chatMessages, setChatMessages] = React.useState<IChatMessage[]>([
|
||||||
|
firstChatMessage,
|
||||||
|
]);
|
||||||
|
const [openaiMessages, setOpenaiMessages] = React.useState<any[]>([
|
||||||
|
systemMessage,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const { callOpenAI } = useOpenAI(httpClient);
|
||||||
|
|
||||||
|
const chatStyles = getStyles();
|
||||||
|
|
||||||
|
// function to show tasks list
|
||||||
|
const showDevOpsTasksMessage = (finalResponse: any) => {
|
||||||
|
const newChatMessage = {
|
||||||
|
position: "left",
|
||||||
|
type: "text",
|
||||||
|
title: DEVOPS_BOT_NAME,
|
||||||
|
text: <TaskList tasks={finalResponse} />,
|
||||||
|
date: new Date(),
|
||||||
|
className: chatStyles.chatMessage,
|
||||||
|
focus: true,
|
||||||
|
};
|
||||||
|
setChatMessages((prevChatMessages) => [
|
||||||
|
...prevChatMessages,
|
||||||
|
newChatMessage,
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
// function to show bugs list
|
||||||
|
const showDevOpsBugsMessage = (finalResponse: any) => {
|
||||||
|
const newChatMessage = {
|
||||||
|
position: "left",
|
||||||
|
type: "text",
|
||||||
|
title: DEVOPS_BOT_NAME,
|
||||||
|
text: <BugList bugs={finalResponse} />,
|
||||||
|
date: new Date(),
|
||||||
|
className: chatStyles.chatMessage,
|
||||||
|
focus: true,
|
||||||
|
};
|
||||||
|
setChatMessages((prevChatMessages) => [
|
||||||
|
...prevChatMessages,
|
||||||
|
newChatMessage,
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
// function to recent commits
|
||||||
|
const showRecentCommitsMessage = (
|
||||||
|
finalResponse: any,
|
||||||
|
respositoryName: string
|
||||||
|
) => {
|
||||||
|
const newChatMessage = {
|
||||||
|
position: "left",
|
||||||
|
type: "text",
|
||||||
|
title: DEVOPS_BOT_NAME,
|
||||||
|
text: (
|
||||||
|
<CommitList commits={finalResponse} respositoryName={respositoryName} />
|
||||||
|
),
|
||||||
|
date: new Date(),
|
||||||
|
className: chatStyles.chatMessage,
|
||||||
|
focus: true,
|
||||||
|
};
|
||||||
|
setChatMessages((prevChatMessages) => [
|
||||||
|
...prevChatMessages,
|
||||||
|
newChatMessage,
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
// function to show generic message
|
||||||
|
const showMessage = (finalResponse: any) => {
|
||||||
|
const newChatMessage = {
|
||||||
|
position: "left",
|
||||||
|
type: "text",
|
||||||
|
title: DEVOPS_BOT_NAME,
|
||||||
|
text: parse(finalResponse),
|
||||||
|
date: new Date(),
|
||||||
|
className: chatStyles.chatMessage,
|
||||||
|
focus: true,
|
||||||
|
};
|
||||||
|
setChatMessages((prevChatMessages) => [
|
||||||
|
...prevChatMessages,
|
||||||
|
newChatMessage,
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
async function callFunction(functionName: string, functionArguments: any) {
|
||||||
|
let functionResult;
|
||||||
|
|
||||||
|
if (functionName === "getAssignedTasks") {
|
||||||
|
const workItems: IWorkItem[] = await AzureDevOpsService.getAssignedTasks(
|
||||||
|
functionArguments.projectName,
|
||||||
|
organizationName
|
||||||
|
);
|
||||||
|
functionResult = workItems.map(mapDevOpsTasks);
|
||||||
|
}
|
||||||
|
if (functionName === "getAssignedBugs") {
|
||||||
|
const workItems: IWorkItem[] = await AzureDevOpsService.getAssignedBugs(
|
||||||
|
functionArguments.projectName,
|
||||||
|
organizationName
|
||||||
|
);
|
||||||
|
functionResult = workItems.map(mapDevOpsBugs);
|
||||||
|
}
|
||||||
|
if (functionName === "getRecentCommitsAsync") {
|
||||||
|
const commitResponse: IWorkItem[] =
|
||||||
|
await AzureDevOpsService.getRecentCommitsAsync(
|
||||||
|
functionArguments.projectName,
|
||||||
|
functionArguments.repositoryName,
|
||||||
|
organizationName
|
||||||
|
);
|
||||||
|
|
||||||
|
functionResult = commitResponse
|
||||||
|
? commitResponse.map((t: any) => DevOpsMapper.mapDevOpsCommits(t))
|
||||||
|
: [];
|
||||||
|
}
|
||||||
|
return functionResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
// function to process the response from OpenAI
|
||||||
|
const processResponse = async (response: any) => {
|
||||||
|
console.log(response);
|
||||||
|
|
||||||
|
// if response is null or undefined then show an error message
|
||||||
|
if (response === null || response === undefined) {
|
||||||
|
showMessage(TRY_LATER_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response_finish_reason = response.choices[0].finish_reason;
|
||||||
|
|
||||||
|
switch (response_finish_reason) {
|
||||||
|
case "stop": {
|
||||||
|
const responseText = response.choices[0].message.content;
|
||||||
|
showMessage(responseText);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "function_call": {
|
||||||
|
const function_name = response.choices[0].message.function_call.name;
|
||||||
|
const function_arguments =
|
||||||
|
response.choices[0].message.function_call.arguments;
|
||||||
|
const function_arguments_json = JSON.parse(function_arguments);
|
||||||
|
|
||||||
|
switch (function_name) {
|
||||||
|
case "getAssignedTasks": {
|
||||||
|
const functionResult: any = await callFunction(
|
||||||
|
function_name,
|
||||||
|
function_arguments_json
|
||||||
|
);
|
||||||
|
showDevOpsTasksMessage(functionResult);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "getAssignedBugs": {
|
||||||
|
const functionResult: any = await callFunction(
|
||||||
|
function_name,
|
||||||
|
function_arguments_json
|
||||||
|
);
|
||||||
|
showDevOpsBugsMessage(functionResult);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "getRecentCommitsAsync": {
|
||||||
|
const functionResult: any = await callFunction(
|
||||||
|
function_name,
|
||||||
|
function_arguments_json
|
||||||
|
);
|
||||||
|
showRecentCommitsMessage(
|
||||||
|
functionResult,
|
||||||
|
function_arguments_json.repositoryName
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "showFunnyMessage": {
|
||||||
|
const funnyMessage = function_arguments_json.funnyMessage;
|
||||||
|
showMessage(funnyMessage);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
showMessage(TRY_LATER_MESSAGE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
showMessage(TRY_LATER_MESSAGE);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
showMessage(TRY_LATER_MESSAGE);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// function to send a message to OpenAI and get a response
|
||||||
|
const onSendClick = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
// add the user message to the chatMessages array
|
||||||
|
const newChatMessage: IChatMessage = {
|
||||||
|
position: "right",
|
||||||
|
type: "text",
|
||||||
|
title: "You",
|
||||||
|
text: query,
|
||||||
|
date: new Date(),
|
||||||
|
status: "read",
|
||||||
|
};
|
||||||
|
|
||||||
|
setChatMessages((prevChatMessages) => [
|
||||||
|
...prevChatMessages,
|
||||||
|
newChatMessage,
|
||||||
|
]);
|
||||||
|
const userMessage = getUserMessage(query);
|
||||||
|
setOpenaiMessages((prevMessages) => [...prevMessages, userMessage]);
|
||||||
|
|
||||||
|
// clear the text field
|
||||||
|
setQuery("");
|
||||||
|
};
|
||||||
|
|
||||||
|
// function to handle the text change in the text field
|
||||||
|
const onTextChange = (
|
||||||
|
event: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>,
|
||||||
|
newValue?: string
|
||||||
|
) => {
|
||||||
|
setQuery(newValue || "");
|
||||||
|
};
|
||||||
|
|
||||||
|
// function to handle the key press in the text field
|
||||||
|
const onKeyDown = async (
|
||||||
|
event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>
|
||||||
|
) => {
|
||||||
|
if (event.key === "Enter") {
|
||||||
|
// if query is empty, then return
|
||||||
|
if (query === "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await onSendClick();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// function to scroll to the bottom of the chat window
|
||||||
|
const scrollToBottom = () => {
|
||||||
|
const chatWindow = document.getElementsByClassName("rce-mlist")[0];
|
||||||
|
if (chatWindow) {
|
||||||
|
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const _onConfigure = () => {
|
||||||
|
// Context of the web part
|
||||||
|
context.propertyPane.open();
|
||||||
|
};
|
||||||
|
|
||||||
|
// useEffect scroll to the bottom of the chat window when messages change
|
||||||
|
React.useEffect(() => {
|
||||||
|
scrollToBottom();
|
||||||
|
}, [chatMessages]);
|
||||||
|
|
||||||
|
// useEffect to call OpenAI when openaiMessages change
|
||||||
|
React.useEffect(() => {
|
||||||
|
// if openaiMessages is empty or has only one message, then return
|
||||||
|
if (openaiMessages.length === 0 || openaiMessages.length === 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpenAIResponse = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
const response = await callOpenAI(openaiMessages, FUNCTIONS);
|
||||||
|
await processResponse(response);
|
||||||
|
setLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
handleOpenAIResponse().catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
setLoading(false);
|
||||||
|
showMessage(TRY_LATER_MESSAGE);
|
||||||
|
});
|
||||||
|
}, [openaiMessages]);
|
||||||
|
|
||||||
|
if (!organizationName || !openAPIKey) {
|
||||||
|
return (
|
||||||
|
<Placeholder
|
||||||
|
iconName="Edit"
|
||||||
|
iconText={strings.PlaceholderIconText}
|
||||||
|
description={strings.PlaceholderDescription}
|
||||||
|
buttonLabel={strings.PlaceholderButtonLabel}
|
||||||
|
onConfigure={_onConfigure}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Set the constant value dynamically
|
||||||
|
AppConstants.setDevOpsOrganization(organizationName);
|
||||||
|
AppConstants.setOpenAIKey(openAPIKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Grid container style={{ padding: "3em 0em" }}>
|
||||||
|
<Grid.Row>
|
||||||
|
<Grid.Column>
|
||||||
|
<Message style={{ background: "white" }}>
|
||||||
|
<Header as="h1">Azure DevOps Bot</Header>
|
||||||
|
<p>
|
||||||
|
The SPFx web part is a SharePoint Framework web part that allows
|
||||||
|
users to view recent tasks, bugs, and commits assigned to them
|
||||||
|
from a specific project in Azure DevOps. The web part uses the
|
||||||
|
Open AI function calling feature to determine the user's request
|
||||||
|
and intention, and then processes the relevant function using the
|
||||||
|
Azure DevOps API.
|
||||||
|
</p>
|
||||||
|
<List.Item>
|
||||||
|
<Label color="red" horizontal>
|
||||||
|
DevOps organization
|
||||||
|
</Label>
|
||||||
|
{organizationName}
|
||||||
|
</List.Item>
|
||||||
|
<Grid.Row>
|
||||||
|
<Grid.Column>
|
||||||
|
<Divider />
|
||||||
|
<Grid columns={1}>
|
||||||
|
<Grid.Column>
|
||||||
|
<Header attached="top" as="h4" block>
|
||||||
|
Assistant
|
||||||
|
</Header>
|
||||||
|
<Segment attached="bottom">
|
||||||
|
<div className={chatStyles.chatWindowContainer}>
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
className={`${chatStyles.chatWindow}`}
|
||||||
|
id="chatWindow"
|
||||||
|
>
|
||||||
|
<MessageList
|
||||||
|
className={chatStyles.chatWindowMessageList}
|
||||||
|
lockable={false}
|
||||||
|
toBottomHeight={"100%"}
|
||||||
|
dataSource={chatMessages}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/* Insert a textbox woth icon */}
|
||||||
|
<div className={chatStyles.chatWindowFooter}>
|
||||||
|
<TextField
|
||||||
|
placeholder={
|
||||||
|
loading ? "" : "Type your query here"
|
||||||
|
}
|
||||||
|
onChange={onTextChange}
|
||||||
|
onKeyDown={onKeyDown}
|
||||||
|
disabled={loading}
|
||||||
|
value={query}
|
||||||
|
autoComplete="off"
|
||||||
|
borderless={true}
|
||||||
|
multiline
|
||||||
|
rows={2}
|
||||||
|
resizable={false}
|
||||||
|
styles={sendChatTextFiledStyles}
|
||||||
|
/>
|
||||||
|
<div className={chatStyles.chatWindowFooterButtons}>
|
||||||
|
{loading ? (
|
||||||
|
<Spinner
|
||||||
|
size={SpinnerSize.small}
|
||||||
|
styles={loadingSpinnerStyles}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<IconButton
|
||||||
|
iconProps={{ iconName: "Send" }}
|
||||||
|
onClick={() => onSendClick()}
|
||||||
|
className={chatStyles.sendChatButton}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Segment>
|
||||||
|
</Grid.Column>
|
||||||
|
</Grid>
|
||||||
|
</Grid.Column>
|
||||||
|
</Grid.Row>
|
||||||
|
</Message>
|
||||||
|
</Grid.Column>
|
||||||
|
</Grid.Row>
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,47 @@
|
||||||
|
@import "~@fluentui/react/dist/sass/References.scss";
|
||||||
|
|
||||||
|
.taskList {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
.header {
|
||||||
|
font-weight: 400 !important;
|
||||||
|
font-size: 14px !important;
|
||||||
|
color: #0065b1 !important;
|
||||||
|
}
|
||||||
|
// li {
|
||||||
|
// display: flex;
|
||||||
|
// margin-bottom: 10px;
|
||||||
|
// font-size: 14px;
|
||||||
|
// border-bottom: 1px dotted '[theme:link, default:#03787c]';
|
||||||
|
// .icon {
|
||||||
|
// width: 40px;
|
||||||
|
// display: flex;
|
||||||
|
// align-items: baseline;
|
||||||
|
// justify-content: center;
|
||||||
|
// color: '[theme:successIcon, default:#03787c]';
|
||||||
|
// font-size: 23px;
|
||||||
|
// margin-top: 8px;
|
||||||
|
// }
|
||||||
|
// .content {
|
||||||
|
// display: flex;
|
||||||
|
// flex-direction: column;
|
||||||
|
// align-items: self-start;
|
||||||
|
// margin-left: 5px;
|
||||||
|
// font-size: 14px;
|
||||||
|
// padding: 5px 0;
|
||||||
|
// a {
|
||||||
|
// text-decoration: none;
|
||||||
|
// color: '[theme:link, default:#03787c]';
|
||||||
|
// cursor: pointer;
|
||||||
|
// .title {
|
||||||
|
// font-weight: 500;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// .description {
|
||||||
|
// text-align: left;
|
||||||
|
// font-size: 12px;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import styles from "./TaskList.module.scss";
|
||||||
|
import { IWorkItemDetails } from "../../../../interfaces/webpart.types";
|
||||||
|
//import { MdOutlineTask } from "react-icons/md/";
|
||||||
|
//import parse from "html-react-parser";
|
||||||
|
import { Header, List } from "semantic-ui-react";
|
||||||
|
import { getRelativeTime, stripHtml } from "../../../../helpers/UtilityHelper";
|
||||||
|
|
||||||
|
interface ITaskListProps {
|
||||||
|
tasks: IWorkItemDetails[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const TaskList = ({ tasks }: ITaskListProps) => {
|
||||||
|
const taskItems = tasks.map((task: IWorkItemDetails, index: number) => {
|
||||||
|
return (
|
||||||
|
<List key={index} divided celled animated>
|
||||||
|
<List.Item>
|
||||||
|
<List.Icon
|
||||||
|
name="check square outline"
|
||||||
|
size="large"
|
||||||
|
verticalAlign="middle"
|
||||||
|
/>
|
||||||
|
<List.Content>
|
||||||
|
<List.Header
|
||||||
|
className={styles.header}
|
||||||
|
as="a"
|
||||||
|
target="_blank"
|
||||||
|
data-interception="off"
|
||||||
|
href={task.url}
|
||||||
|
>
|
||||||
|
{task.title}
|
||||||
|
</List.Header>
|
||||||
|
<List.Description>{stripHtml(task.description)}</List.Description>
|
||||||
|
<List.Description>
|
||||||
|
{getRelativeTime(task.createdDate)}
|
||||||
|
</List.Description>
|
||||||
|
</List.Content>
|
||||||
|
</List.Item>
|
||||||
|
</List>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Header as="h2">
|
||||||
|
Tasks
|
||||||
|
<Header.Subheader>Tasks assigned to me </Header.Subheader>
|
||||||
|
</Header>
|
||||||
|
<div className={styles.taskList}>{taskItems}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TaskList;
|
|
@ -0,0 +1,208 @@
|
||||||
|
import { mergeStyleSets } from "@fluentui/merge-styles";
|
||||||
|
import { getTheme } from "@fluentui/react/lib/Styling";
|
||||||
|
import { IButtonStyles } from "@fluentui/react/lib/Button";
|
||||||
|
import { ITextFieldStyles } from "@fluentui/react/lib/TextField";
|
||||||
|
import { ISpinnerStyles } from "@fluentui/react/lib/Spinner";
|
||||||
|
|
||||||
|
export interface IDevopsOpenAIChatWindowStyles {
|
||||||
|
organizationLabel: string;
|
||||||
|
chatButtonIcon: string;
|
||||||
|
chatWindowContainer: string;
|
||||||
|
chatWindow: string;
|
||||||
|
chatMessage: string;
|
||||||
|
chatWindowHeader: string;
|
||||||
|
chatWindowHeaderText: string;
|
||||||
|
chatWindowMessageList: string;
|
||||||
|
chatWindowFooter: string;
|
||||||
|
chatWindowFooterButtons: string;
|
||||||
|
sendChatButton: string;
|
||||||
|
show: string;
|
||||||
|
hide: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const theme: any = getTheme();
|
||||||
|
const ThemeState = (<any>window).__themeState__;
|
||||||
|
function getThemeColor(slot: string) {
|
||||||
|
if (ThemeState && ThemeState.theme && ThemeState.theme[slot]) {
|
||||||
|
return ThemeState.theme[slot];
|
||||||
|
}
|
||||||
|
return theme[slot];
|
||||||
|
}
|
||||||
|
|
||||||
|
// const fadeIn = keyframes({
|
||||||
|
// from: {
|
||||||
|
// opacity: 0,
|
||||||
|
// },
|
||||||
|
// to: {
|
||||||
|
// opacity: 1,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const fadeOut = keyframes({
|
||||||
|
// from: {
|
||||||
|
// opacity: 1,
|
||||||
|
// },
|
||||||
|
// to: {
|
||||||
|
// opacity: 0,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
export const chatButtonStyles: Partial<IButtonStyles> = {
|
||||||
|
root: {
|
||||||
|
color: getThemeColor("neutralPrimary"),
|
||||||
|
marginLeft: "auto",
|
||||||
|
marginTop: "4px",
|
||||||
|
marginRight: "2px",
|
||||||
|
marginBottom: "2px",
|
||||||
|
backgroundColor: getThemeColor("neutralLighter"),
|
||||||
|
boxShadow: "0 0 10px rgba(0,0,0,0.2)",
|
||||||
|
selectors: {
|
||||||
|
":hover": {
|
||||||
|
backgroundColor: getThemeColor("neutralLight"),
|
||||||
|
color: getThemeColor("neutralDark"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rootHovered: {
|
||||||
|
color: getThemeColor("neutralDark"),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sendChatTextFiledStyles: Partial<ITextFieldStyles> = {
|
||||||
|
root: {
|
||||||
|
backgroundColor: "#fff",
|
||||||
|
selectors: {
|
||||||
|
":hover": {
|
||||||
|
backgroundColor: "#fff",
|
||||||
|
color: "#000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
width: "89%",
|
||||||
|
marginRight: "5px",
|
||||||
|
},
|
||||||
|
field: {
|
||||||
|
backgroundColor: "#fff",
|
||||||
|
selectors: {
|
||||||
|
":focus": {
|
||||||
|
boxShadow: "0 0 10px rgba(0,0,0,0.2)",
|
||||||
|
backgroundColor: "#fff",
|
||||||
|
color: "#000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const chatMinimiseButtonStyles: Partial<IButtonStyles> = {
|
||||||
|
root: {
|
||||||
|
color: "#fff",
|
||||||
|
},
|
||||||
|
rootHovered: {
|
||||||
|
color: "#fff",
|
||||||
|
},
|
||||||
|
rootPressed: {
|
||||||
|
color: "#fff",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const loadingSpinnerStyles: Partial<ISpinnerStyles> = {
|
||||||
|
root: {
|
||||||
|
paddingTop: "10px",
|
||||||
|
paddingLeft: "7px",
|
||||||
|
},
|
||||||
|
circle: {
|
||||||
|
borderColor: "#113b92 #589bfe #589bfe",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getStyles = (): IDevopsOpenAIChatWindowStyles => {
|
||||||
|
return mergeStyleSets({
|
||||||
|
organizationLabel: {
|
||||||
|
color: getThemeColor("themePrimary"),
|
||||||
|
fontSize: "14px",
|
||||||
|
fontWeight: "500",
|
||||||
|
marginBottom: "10px",
|
||||||
|
},
|
||||||
|
|
||||||
|
chatButtonIcon: {
|
||||||
|
color: "#113b92 !important",
|
||||||
|
},
|
||||||
|
chatWindowContainer: {
|
||||||
|
position: "relative",
|
||||||
|
zIndex: 1000,
|
||||||
|
backgroundColor: "rgb(249 245 232)",
|
||||||
|
},
|
||||||
|
chatWindow: {
|
||||||
|
// backgroundColor: getThemeColor("neutralLighter"),
|
||||||
|
color: getThemeColor("neutralPrimary"),
|
||||||
|
padding: "10px",
|
||||||
|
width: "100%",
|
||||||
|
boxSizing: "border-box",
|
||||||
|
overflow: "auto",
|
||||||
|
},
|
||||||
|
chatMessage: {
|
||||||
|
// animationName: fadeIn,
|
||||||
|
// animationDuration: "0.25s",
|
||||||
|
// animationIterationCount: "1",
|
||||||
|
// animationTimingFunction: "ease-in-out",
|
||||||
|
// '.rce-mbox': {
|
||||||
|
// backgroundColor: 'cornsilk',
|
||||||
|
// },
|
||||||
|
},
|
||||||
|
chatWindowHeader: {
|
||||||
|
backgroundColor: getThemeColor("themePrimary"),
|
||||||
|
color: "#fff",
|
||||||
|
display: "flex",
|
||||||
|
boxSizing: "border-box",
|
||||||
|
borderBottom: "1px solid " + getThemeColor("neutralLight"),
|
||||||
|
cursor: "pointer",
|
||||||
|
borderRadius: "5px 5px 0 0",
|
||||||
|
/* selectors: {
|
||||||
|
':hover': {
|
||||||
|
backgroundColor: getThemeColor("neutralLight"),
|
||||||
|
color: getThemeColor("neutralDark")
|
||||||
|
}
|
||||||
|
} */
|
||||||
|
},
|
||||||
|
chatWindowHeaderText: {
|
||||||
|
marginLeft: "10px",
|
||||||
|
flex: 2,
|
||||||
|
paddingTop: "5px",
|
||||||
|
},
|
||||||
|
chatWindowMessageList: {
|
||||||
|
minHeight: "150px",
|
||||||
|
maxHeight: "400px",
|
||||||
|
padding: "10px 2px",
|
||||||
|
borderRadius: "5px",
|
||||||
|
// backgroundColor: '#589bfe',
|
||||||
|
},
|
||||||
|
chatWindowFooter: {
|
||||||
|
// backgroundColor: getThemeColor("neutralLighter"),
|
||||||
|
color: getThemeColor("neutralPrimary"),
|
||||||
|
display: "flex",
|
||||||
|
boxSizing: "border-box",
|
||||||
|
borderTop: `1px solid #000`,
|
||||||
|
padding: "10px",
|
||||||
|
borderRadius: "0 0 5px 5px",
|
||||||
|
},
|
||||||
|
chatWindowFooterButtons: {
|
||||||
|
paddingTop: "15px",
|
||||||
|
},
|
||||||
|
sendChatButton: {
|
||||||
|
color: "#113b92",
|
||||||
|
},
|
||||||
|
show: {
|
||||||
|
display: "block",
|
||||||
|
// animationName: fadeIn,
|
||||||
|
// animationDuration: "0.25s",
|
||||||
|
// animationIterationCount: "1",
|
||||||
|
// animationTimingFunction: "ease-in-out",
|
||||||
|
},
|
||||||
|
hide: {
|
||||||
|
display: "none",
|
||||||
|
// animationName: fadeOut,
|
||||||
|
// animationDuration: "0.25s",
|
||||||
|
// animationIterationCount: "1",
|
||||||
|
// animationTimingFunction: "ease-in-out",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
|
@ -0,0 +1,24 @@
|
||||||
|
define([], function () {
|
||||||
|
return {
|
||||||
|
PropertyPaneDescription: "Description",
|
||||||
|
DevOpsSettingsGroupName: "DevOps Settings",
|
||||||
|
OpenAPISettingsGroupName: "OpenAI Settings",
|
||||||
|
DescriptionFieldLabel: "Description Field",
|
||||||
|
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",
|
||||||
|
AppLocalEnvironmentOffice:
|
||||||
|
"The app is running on your local environment in office.com",
|
||||||
|
AppLocalEnvironmentOutlook:
|
||||||
|
"The app is running on your local environment in Outlook",
|
||||||
|
AppSharePointEnvironment: "The app is running on SharePoint page",
|
||||||
|
AppTeamsTabEnvironment: "The app is running in Microsoft Teams",
|
||||||
|
AppOfficeEnvironment: "The app is running in office.com",
|
||||||
|
AppOutlookEnvironment: "The app is running in Outlook",
|
||||||
|
PlaceholderIconText: "Configure your web part",
|
||||||
|
PlaceholderDescription:
|
||||||
|
"Please configure OpenAPI key and Choose DevOps oragnization name",
|
||||||
|
PlaceholderButtonLabel: "Configure",
|
||||||
|
};
|
||||||
|
});
|
|
@ -0,0 +1,22 @@
|
||||||
|
declare interface ISmartDevOpsWebPartStrings {
|
||||||
|
PropertyPaneDescription: string;
|
||||||
|
DevOpsSettingsGroupName: string;
|
||||||
|
OpenAPISettingsGroupName: string;
|
||||||
|
DescriptionFieldLabel: string;
|
||||||
|
AppLocalEnvironmentSharePoint: string;
|
||||||
|
AppLocalEnvironmentTeams: string;
|
||||||
|
AppLocalEnvironmentOffice: string;
|
||||||
|
AppLocalEnvironmentOutlook: string;
|
||||||
|
AppSharePointEnvironment: string;
|
||||||
|
AppTeamsTabEnvironment: string;
|
||||||
|
AppOfficeEnvironment: string;
|
||||||
|
AppOutlookEnvironment: string;
|
||||||
|
PlaceholderIconText: string;
|
||||||
|
PlaceholderDescription: string;
|
||||||
|
PlaceholderButtonLabel: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module "SmartDevOpsWebPartStrings" {
|
||||||
|
const strings: ISmartDevOpsWebPartStrings;
|
||||||
|
export = strings;
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
After Width: | Height: | Size: 542 B |
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"extends": "./node_modules/@microsoft/rush-stack-compiler-4.5/includes/tsconfig-web.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es5",
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"jsx": "react",
|
||||||
|
"declaration": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"outDir": "lib",
|
||||||
|
"inlineSources": false,
|
||||||
|
"noImplicitAny": true,
|
||||||
|
|
||||||
|
"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