lint warnings, tbc

This commit is contained in:
Kazala Kinga (ID) 2023-02-04 09:20:31 +01:00
parent 7de5fb04a7
commit 750632b6da
16 changed files with 16240 additions and 25976 deletions

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -12,34 +12,39 @@
"test": "gulp test"
},
"dependencies": {
"@microsoft/sp-core-library": "1.10.0",
"@microsoft/sp-lodash-subset": "1.10.0",
"@microsoft/sp-office-ui-fabric-core": "1.10.0",
"@microsoft/sp-property-pane": "1.10.0",
"@microsoft/sp-webpart-base": "1.10.0",
"@pnp/spfx-controls-react": "1.17.0",
"@types/es6-promise": "0.0.33",
"@types/react": "16.8.8",
"@types/react-dom": "16.8.3",
"@types/webpack-env": "1.13.1",
"lodash": "^4.17.21",
"moment": "^2.29.2",
"office-ui-fabric-react": "6.189.2",
"react": "16.8.5",
"react-dom": "16.8.5"
"@fluentui/react": "~8.105.2",
"@microsoft/applicationinsights-react-js": "^3.4.0",
"@microsoft/applicationinsights-web": "^2.8.9",
"@microsoft/sp-core-library": "1.16.1",
"@microsoft/sp-http": "^1.16.1",
"@microsoft/sp-lodash-subset": "1.16.1",
"@microsoft/sp-office-ui-fabric-core": "1.16.1",
"@microsoft/sp-property-pane": "1.16.1",
"@microsoft/sp-webpart-base": "1.16.1",
"@pnp/spfx-controls-react": "^3.12.0",
"history": "~5.3.0",
"moment": "^2.29.4",
"react": "17.0.1",
"react-dom": "17.0.1",
"tslib": "2.3.1"
},
"resolutions": {
"@types/react": "16.8.8"
"@types/react": "17.0.45"
},
"devDependencies": {
"@microsoft/eslint-config-spfx": "1.16.1",
"@microsoft/eslint-plugin-spfx": "1.16.1",
"@microsoft/rush-stack-compiler-4.5": "0.2.2",
"@microsoft/sp-build-web": "1.16.1",
"@microsoft/sp-tslint-rules": "1.10.0",
"@microsoft/sp-module-interfaces": "1.10.0",
"@microsoft/sp-webpart-workbench": "1.12.1",
"@microsoft/rush-stack-compiler-3.3": "0.3.5",
"gulp": "~3.9.1",
"@types/chai": "3.4.34",
"@types/mocha": "2.2.38",
"ajv": "~5.2.2"
"@microsoft/sp-module-interfaces": "1.16.1",
"@rushstack/eslint-config": "2.5.1",
"@types/react": "17.0.45",
"@types/react-dom": "17.0.17",
"@types/webpack-env": "~1.15.2",
"ajv": "^6.12.5",
"eslint": "8.7.0",
"eslint-plugin-react-hooks": "4.3.0",
"gulp": "4.0.2",
"typescript": "4.5.5"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -21,4 +21,7 @@ export interface IPerfDurationProps {
PerDur_50: number;
PerDur_95: number;
PerDur_99: number;
}
}
export interface Dictionary<T> {
[index: string]: T;
}

View File

@ -1,8 +1,8 @@
import { HttpClient, IHttpClientOptions, HttpClientResponse } from '@microsoft/sp-http';
import { TimeInterval, TimeSpan, Segments } from './enumHelper';
import { IPageViewCountProps, IPageViewDetailProps, defaultDateFormat, chartDateFormat } from './CommonProps';
import { IPageViewCountProps, IPageViewDetailProps, defaultDateFormat, chartDateFormat, Dictionary } from './CommonProps';
import moment from 'moment';
const moment: any = require('moment');
export default class Helper {
private _appid: string = '';
@ -23,12 +23,12 @@ export default class Helper {
}
public getPageViewCount = async (timespan: TimeSpan, timeinterval: TimeInterval): Promise<IPageViewCountProps[]> => {
let finalRes: IPageViewCountProps[] = [];
let finalPostUrl: string = this._postUrl + `/metrics/pageViews/count?timespan=${timespan}&interval=${timeinterval}`;
let response: HttpClientResponse = await this.httpClient.get(finalPostUrl, HttpClient.configurations.v1, this.httpClientOptions);
let responseJson: any = await response.json();
const finalRes: IPageViewCountProps[] = [];
const finalPostUrl: string = this._postUrl + `/metrics/pageViews/count?timespan=${timespan}&interval=${timeinterval}`;
const response: HttpClientResponse = await this.httpClient.get(finalPostUrl, HttpClient.configurations.v1, this.httpClientOptions);
const responseJson: any = await response.json();
if (responseJson.value && responseJson.value.segments.length > 0) {
let segments: any[] = responseJson.value.segments;
const segments: any[] = responseJson.value.segments;
segments.map((seg: any) => {
finalRes.push({
oriDate: seg.start,
@ -41,12 +41,12 @@ export default class Helper {
}
public getPageViews = async (timespan: TimeSpan, timeinterval: TimeInterval, segment: Segments[]): Promise<IPageViewDetailProps[]> => {
let finalRes: IPageViewDetailProps[] = [];
let finalPostUrl: string = this._postUrl + `/metrics/pageViews/count?timespan=${timespan}&interval=${timeinterval}&segment=${encodeURIComponent(segment.join(','))}`;
let response: HttpClientResponse = await this.httpClient.get(finalPostUrl, HttpClient.configurations.v1, this.httpClientOptions);
let responseJson: any = await response.json();
const finalRes: IPageViewDetailProps[] = [];
const finalPostUrl: string = this._postUrl + `/metrics/pageViews/count?timespan=${timespan}&interval=${timeinterval}&segment=${encodeURIComponent(segment.join(','))}`;
const response: HttpClientResponse = await this.httpClient.get(finalPostUrl, HttpClient.configurations.v1, this.httpClientOptions);
const responseJson: any = await response.json();
if (responseJson.value && responseJson.value.segments.length > 0) {
let mainSegments: any[] = responseJson.value.segments;
const mainSegments: any[] = responseJson.value.segments;
mainSegments.map(mainseg => {
if (mainseg.segments.length > 0) {
mainseg.segments.map((seg: any) => {
@ -68,9 +68,9 @@ export default class Helper {
public getResponseByQuery = async (query: string, useTimespan: boolean, timespan?: TimeSpan): Promise<any[]> => {
let finalRes: any[] = [];
let urlQuery: string = useTimespan ? `timespan=${timespan}&query=${encodeURIComponent(query)}` : `query=${encodeURIComponent(query)}`;
let finalPostUrl: string = this._postUrl + `/query?${urlQuery}`;
let responseJson: any = await this.getAPIResponse(finalPostUrl);
const urlQuery: string = useTimespan ? `timespan=${timespan}&query=${encodeURIComponent(query)}` : `query=${encodeURIComponent(query)}`;
const finalPostUrl: string = this._postUrl + `/query?${urlQuery}`;
const responseJson: any = await this.getAPIResponse(finalPostUrl);
if (responseJson.tables.length > 0) {
finalRes = responseJson.tables[0].rows;
}
@ -78,19 +78,19 @@ export default class Helper {
}
public getUserPageViews = async (timespan: TimeSpan | string, timeinterval: TimeInterval, segment: Segments[]): Promise<IPageViewDetailProps[]> => {
let finalRes: any[] = [];
let finalPostUrl: string = this._postUrl + `/metrics/pageViews/count?timespan=${encodeURIComponent(timespan)}&interval=${timeinterval}&segment=${encodeURIComponent(segment.join(','))}`;
let response: HttpClientResponse = await this.httpClient.get(finalPostUrl, HttpClient.configurations.v1, this.httpClientOptions);
let responseJson: any = await response.json();
const finalRes: any[] = [];
const finalPostUrl: string = this._postUrl + `/metrics/pageViews/count?timespan=${encodeURIComponent(timespan)}&interval=${timeinterval}&segment=${encodeURIComponent(segment.join(','))}`;
const response: HttpClientResponse = await this.httpClient.get(finalPostUrl, HttpClient.configurations.v1, this.httpClientOptions);
const responseJson: any = await response.json();
if (responseJson.value && responseJson.value.segments.length > 0) {
let mainSegments: any[] = responseJson.value.segments;
const mainSegments: any[] = responseJson.value.segments;
mainSegments.map(mainseg => {
if (mainseg.segments.length > 0) {
let childSegments: any[] = mainseg.segments;
const childSegments: any[] = mainseg.segments;
childSegments.map(childseg => {
let grandChildSegments: any[] = childseg.segments;
const grandChildSegments: any[] = childseg.segments;
grandChildSegments.map(grandchildseg => {
if (grandchildseg['pageView/urlPath'] != '') {
if (grandchildseg['pageView/urlPath'] !== '') {
finalRes.push({
oriStartDate: mainseg.start,
oriEndDate: mainseg.end,
@ -111,12 +111,12 @@ export default class Helper {
}
public getAPIResponse = async (urlWithQuery: string): Promise<any> => {
let response: HttpClientResponse = await this.httpClient.get(urlWithQuery, HttpClient.configurations.v1, this.httpClientOptions);
const response: HttpClientResponse = await this.httpClient.get(urlWithQuery, HttpClient.configurations.v1, this.httpClientOptions);
return await response.json();
}
public getTimeSpanMenu = (): any[] => {
let items: any[] = [];
public getTimeSpanMenu = (): Dictionary<string>[] => {
const items: Dictionary<string>[] = []; //KK: any=> string
Object.keys(TimeSpan).map(key => {
items.push({
text: key,
@ -126,8 +126,8 @@ export default class Helper {
return items;
}
public getTimeIntervalMenu = (): any[] => {
let items: any[] = [];
public getTimeIntervalMenu = (): Dictionary<string>[] => {
const items: Dictionary<string>[] = [];
Object.keys(TimeInterval).map(key => {
items.push({
text: key,
@ -157,7 +157,7 @@ export default class Helper {
return moment(datetime).format('YYYY-MM-DDTHH:MM:00.000Z');
}
public getRandomColor = () => {
public getRandomColor = () : string => {
return "rgb(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," +
Math.floor(Math.random() * 255) + ")";
}

View File

@ -1,6 +1,6 @@
import { PivotItem, Pivot } from '@fluentui/react';
import * as React from 'react';
import styles from '../CommonControl.module.scss';
import { Pivot, PivotItem } from 'office-ui-fabric-react/lib/Pivot';
export interface IPivotProps {
ShowLabel: boolean;

View File

@ -1,9 +1,11 @@
import * as React from 'react';
import styles from '../CommonControl.module.scss';
import { DetailsList, IColumn, DetailsListLayoutMode, ConstrainMode, SelectionMode, IGroup } from 'office-ui-fabric-react/lib/DetailsList';
import { IColumn, DetailsListLayoutMode, ConstrainMode, SelectionMode, IGroup, ShimmeredDetailsList } from '@fluentui/react';
import { findIndex, groupBy } from '@microsoft/sp-lodash-subset';
const groupBy: any = require('lodash/groupBy');
const findIndex: any = require('lodash/findIndex');
export interface Dictionary<T> {
[index: string]: T;
}
export interface IDataListProps {
Items: any[];
@ -23,8 +25,8 @@ const DataList: React.FunctionComponent<IDataListProps> = (props) => {
return findIndex(props.Items, (o) => { return o.date == key; });
};
const _buildGroups = () => {
let grouped: any[] = groupBy(props.Items, props.GroupByCol);
let groupsTemp: IGroup[] = [];
let grouped: Dictionary<string[]> = groupBy(props.Items, props.GroupByCol); //KK: any=> string
const groupsTemp: IGroup[] = [];
Object.keys(grouped).map((key, index) => {
groupsTemp.push({
key: key,
@ -35,7 +37,7 @@ const DataList: React.FunctionComponent<IDataListProps> = (props) => {
});
setGroups(groupsTemp);
};
const _loadDataList = () => {
const _loadDataList = ():void => {
setColumns(props.Columns);
if (props.GroupBy && props.GroupByCol.length > 0 && props.CountCol.length > 0) _buildGroups();
setItems(props.Items);
@ -50,7 +52,7 @@ const DataList: React.FunctionComponent<IDataListProps> = (props) => {
return (
<div className={styles.dataList}>
{(groups.length > 0 && props.GroupBy && props.GroupByCol.length > 0 && props.CountCol.length > 0) ? (
<DetailsList
<ShimmeredDetailsList
items={items}
setKey="set"
columns={columns}
@ -65,7 +67,7 @@ const DataList: React.FunctionComponent<IDataListProps> = (props) => {
selectionMode={SelectionMode.none}
enableShimmer={true} />
) : (
<DetailsList
<ShimmeredDetailsList
items={items}
setKey="set"
columns={columns}

View File

@ -1,13 +1,7 @@
import * as React from 'react';
import * as strings from 'AppInsightsDashboardWebPartStrings';
import styles from '../CommonControl.module.scss';
import { IconType, Icon } from 'office-ui-fabric-react/lib/Icon';
import { ChartControl, ChartType } from '@pnp/spfx-controls-react/lib/ChartControl';
import { Spinner } from 'office-ui-fabric-react/lib/Spinner';
import { MessageBar, MessageBarType } from 'office-ui-fabric-react/lib/MessageBar';
import { PivotItem } from 'office-ui-fabric-react/lib/Pivot';
import { IColumn } from 'office-ui-fabric-react/lib/DetailsList';
import { css } from 'office-ui-fabric-react/lib/Utilities';
import { AppInsightsProps } from '../../webparts/appInsightsDashboard/components/AppInsightsDashboard';
import { TimeInterval, TimeSpan, Segments } from '../enumHelper';
import { IPageViewDetailProps, IPageViewCountProps } from '../CommonProps';
@ -15,6 +9,7 @@ import SectionTitle from '../components/SectionTitle';
import CustomPivot from '../components/CustomPivot';
import DataList from '../components/DataList';
import Helper from '../Helper';
import { IColumn, PivotItem, Icon, IconType, css, Spinner, MessageBar, MessageBarType } from '@fluentui/react';
const map: any = require('lodash/map');
@ -58,7 +53,7 @@ const PageViews: React.FunctionComponent<IPageViewsProps> = (props) => {
if (menuClick) setLoadingChart(true);
let response: IPageViewCountProps[] = await props.helper.getPageViewCount(TimeSpan[selTimeSpan], TimeInterval[selTimeInterval]);
if (response.length > 0) {
const data: Chart.ChartData = {
const data = { //: Chart.ChartData
labels: map(response, 'date'),
datasets: [
{
@ -73,7 +68,7 @@ const PageViews: React.FunctionComponent<IPageViewsProps> = (props) => {
]
};
setChartData(data);
const options: Chart.ChartOptions = {
const options= {//: Chart.ChartOptions
legend: {
display: false
},

View File

@ -2,15 +2,11 @@ import * as React from 'react';
import * as strings from 'AppInsightsDashboardWebPartStrings';
import styles from '../CommonControl.module.scss';
import { ChartControl, ChartType } from '@pnp/spfx-controls-react/lib/ChartControl';
import { Spinner } from 'office-ui-fabric-react/lib/Spinner';
import { css } from 'office-ui-fabric-react/lib/Utilities';
import { DatePicker } from 'office-ui-fabric-react/lib/DatePicker';
import { addDays } from 'office-ui-fabric-react/lib/utilities/dateMath/DateMath';
import { MessageBar, MessageBarType } from 'office-ui-fabric-react/lib/MessageBar';
import { AppInsightsProps } from '../../webparts/appInsightsDashboard/components/AppInsightsDashboard';
import { IPerfDurationProps } from '../CommonProps';
import SectionTitle from '../components/SectionTitle';
import Helper from '../Helper';
import { addDays, DatePicker, css, Spinner, MessageBar, MessageBarType } from '@fluentui/react';
const map: any = require('lodash/map');
@ -75,7 +71,7 @@ const PerformanceStatistics: React.FunctionComponent<IPerformanceProps> = (props
PerDur_99: res[5]
});
});
const data: Chart.ChartData = {
const data= {//: Chart.ChartData
labels: map(finalRes, 'PageName'),
datasets: [
{
@ -116,7 +112,7 @@ const PerformanceStatistics: React.FunctionComponent<IPerformanceProps> = (props
]
};
setChartData1(data);
const options: Chart.ChartOptions = {
const options = {//: Chart.ChartOptions
legend: {
display: false
},

View File

@ -1,11 +1,6 @@
import * as React from 'react';
import * as strings from 'AppInsightsDashboardWebPartStrings';
import styles from '../CommonControl.module.scss';
import { css } from 'office-ui-fabric-react/lib/Utilities';
import { PivotItem } from 'office-ui-fabric-react/lib/Pivot';
import { MessageBar, MessageBarType } from 'office-ui-fabric-react/lib/MessageBar';
import { DatePicker } from 'office-ui-fabric-react/lib/DatePicker';
import { addDays } from 'office-ui-fabric-react/lib/utilities/dateMath/DateMath';
import { ChartControl, ChartType } from '@pnp/spfx-controls-react/lib/ChartControl';
import { AppInsightsProps } from '../../webparts/appInsightsDashboard/components/AppInsightsDashboard';
import { TimeSpan, TimeInterval, Segments } from '../enumHelper';
@ -13,10 +8,9 @@ import SectionTitle from '../components/SectionTitle';
import CustomPivot from './CustomPivot';
import Helper from '../Helper';
import { Spinner } from 'office-ui-fabric-react/lib/Spinner';
import { IColumn } from 'office-ui-fabric-react/lib/DetailsList';
import { Icon, IconType } from 'office-ui-fabric-react/lib/Icon';
import DataList from './DataList';
import { addDays, IColumn, PivotItem, Icon, IconType, DatePicker, css, Spinner, MessageBar, MessageBarType } from '@fluentui/react';
import { IPageViewDetailProps } from '../CommonProps';
const map: any = require('lodash/map');
@ -46,12 +40,12 @@ const UserStatistics: React.FunctionComponent<IUserStatisticsProps> = (props) =>
const [listCols, setListCols] = React.useState<IColumn[]>([]);
const [items, setItems] = React.useState<any[]>([]);
const _loadMenus = () => {
const _loadMenus = (): void => {
let tsMenus: any[] = props.helper.getTimeSpanMenu();
setTimeSpanMenus(tsMenus);
setSelTimeSpan(tsMenus[4].key);
};
const handleTimeSpanMenuClick = (item: PivotItem) => {
const handleTimeSpanMenuClick = (item: PivotItem): void => {
setMenuClick(true);
setSelTimeSpan(item.props.itemKey);
setStartDate(null);
@ -63,7 +57,7 @@ const UserStatistics: React.FunctionComponent<IUserStatisticsProps> = (props) =>
const handleEndDateChange = (selDate: Date | null | undefined): void => {
setEndDate(selDate);
};
const _loadUserStatistics = async () => {
const _loadUserStatistics = async (): Promise<void> => {
if (menuClick) setLoadingChart(true);
let query: string = ``;
if (startDate && endDate) {
@ -90,7 +84,7 @@ const UserStatistics: React.FunctionComponent<IUserStatisticsProps> = (props) =>
sum: res[1]
});
});
const data: Chart.ChartData = {
const data = {//: Chart.ChartData
labels: map(results, 'date'),
datasets: [
{
@ -102,7 +96,7 @@ const UserStatistics: React.FunctionComponent<IUserStatisticsProps> = (props) =>
]
};
setChartData(data);
const options: Chart.ChartOptions = {
const options = {//: Chart.ChartOptions
legend: {
display: false
},
@ -135,7 +129,8 @@ const UserStatistics: React.FunctionComponent<IUserStatisticsProps> = (props) =>
setMenuClick(false);
}
};
const _generateColumns = () => {
const _generateColumns = ():void => {
let cols: IColumn[] = [];
cols.push({
key: 'user', name: 'User', fieldName: 'user', minWidth: 100, maxWidth: 150,
@ -145,8 +140,8 @@ const UserStatistics: React.FunctionComponent<IUserStatisticsProps> = (props) =>
{item.user ? (
<span>{item.user}</span>
) : (
<span>{strings.Msg_NoUser}</span>
)}
<span>{strings.Msg_NoUser}</span>
)}
</div>
);
}
@ -162,8 +157,8 @@ const UserStatistics: React.FunctionComponent<IUserStatisticsProps> = (props) =>
{item.Url ? (
<a href={item.Url} target="_blank" className={styles.pageLink}>{item.Url}</a>
) : (
<span>{strings.Msg_NoUrl}</span>
)}
<span>{strings.Msg_NoUrl}</span>
)}
</div>
);
}
@ -173,9 +168,10 @@ const UserStatistics: React.FunctionComponent<IUserStatisticsProps> = (props) =>
});
setListCols(cols);
};
const _loadUsersPageViewsList = async () => {
const _loadUsersPageViewsList = async (): Promise<void> => {
if (menuClick) setLoadingList(true);
let response: any[] = [];
let response: IPageViewDetailProps[] = [];
if (startDate && endDate) {
response = await props.helper.getUserPageViews(`${props.helper.getFormattedDate(startDate.toUTCString(), 'YYYY-MM-DD')}/${props.helper.getFormattedDate(addDays(endDate, 1).toUTCString(), 'YYYY-MM-DD')}`,
TimeInterval["1 Hour"], [Segments.Cust_UserTitle, Segments.PV_URL]);
@ -194,7 +190,7 @@ const UserStatistics: React.FunctionComponent<IUserStatisticsProps> = (props) =>
}
};
React.useEffect(() => {
React.useEffect((): void => {
if (selTimeSpan || (startDate && endDate)) {
setNoData(false);
setNoListData(false);
@ -202,7 +198,8 @@ const UserStatistics: React.FunctionComponent<IUserStatisticsProps> = (props) =>
_loadUsersPageViewsList();
}
}, [selTimeSpan, startDate, endDate]);
React.useEffect(() => {
React.useEffect(():void => {
if (props.helper) {
_loadMenus();
}
@ -253,32 +250,32 @@ const UserStatistics: React.FunctionComponent<IUserStatisticsProps> = (props) =>
{loadingList ? (
<Spinner label={strings.Msg_LoadList} labelPosition={"bottom"} />
) : (
<>
{!noListData ? (
<DataList Items={items} Columns={listCols} GroupBy={true} GroupByCol={"date"} CountCol={"count"} />
) : (
<MessageBar messageBarType={MessageBarType.error}>{strings.Msg_NoData}</MessageBar>
)}
</>
)}
<>
{!noListData ? (
<DataList Items={items} Columns={listCols} GroupBy={true} GroupByCol={"date"} CountCol={"count"} />
) : (
<MessageBar messageBarType={MessageBarType.error}>{strings.Msg_NoData}</MessageBar>
)}
</>
)}
</div>
<div className={"ms-Grid-col ms-xxxl6 ms-xxl6 ms-xl6 ms-lg6"} style={{ minHeight: '358px' }}>
{loadingChart ? (
<Spinner label={strings.Msg_LoadChart} labelPosition={"bottom"} />
) : (
<>
{!noData ? (
<ChartControl
type={ChartType.Bar}
data={chartData}
options={chartOptions}
className={styles.chart}
/>
) : (
<MessageBar messageBarType={MessageBarType.error}>{strings.Msg_NoData}</MessageBar>
)}
</>
)}
<>
{!noData ? (
<ChartControl
type={ChartType.Bar}
data={chartData}
options={chartOptions}
className={styles.chart}
/>
) : (
<MessageBar messageBarType={MessageBarType.error}>{strings.Msg_NoData}</MessageBar>
)}
</>
)}
</div>
</div>
</div>

View File

@ -45,7 +45,7 @@ export default class AppInsightsDashboardWebPart extends BaseClientSideWebPart<I
return true;
}
public _onConfigure = () => {
public _onConfigure = ():void => {
this.context.propertyPane.open();
}

View File

@ -1,4 +1,4 @@
@import '~office-ui-fabric-react/dist/sass/References.scss';
@import '~@fluentui/react/dist/sass/References.scss';
.appInsightsDashboard {
.container {
@ -7,7 +7,7 @@
}
.row {
@include ms-Grid-row;
// background-color: $ms-color-themeDark;
background-color: $ms-color-themeDark;
padding: 20px;
}
}

View File

@ -1,5 +1,4 @@
import * as React from 'react';
import styles from './AppInsightsDashboard.module.scss';
import * as strings from 'AppInsightsDashboardWebPartStrings';
import { Placeholder } from "@pnp/spfx-controls-react/lib/Placeholder";
import { DisplayMode } from '@microsoft/sp-core-library';
@ -8,6 +7,8 @@ import PageViews from '../../../common/components/PageViews';
import UserStatistics from '../../../common/components/UserStatistics';
import PerformanceStatistics from '../../../common/components/PerformanceStatistics';
import Helper from '../../../common/Helper';
import styles from './AppInsightsDashboard.module.scss';
export interface IAppInsightsDashboardProps {
AppId: string;
@ -21,7 +22,7 @@ export const AppInsightsProps = React.createContext<IAppInsightsDashboardProps>(
const AppInsightsDashboard: React.FunctionComponent<IAppInsightsDashboardProps> = (props) => {
const [helper, setHelper] = React.useState<any>(null);
const [helper, setHelper] = React.useState<Helper>(null); //KK
React.useEffect(() => {
setHelper(new Helper(props.AppId, props.AppKey, props.httpClient));

View File

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

View File

@ -1,30 +0,0 @@
{
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
"rules": {
"class-name": false,
"export-name": false,
"forin": false,
"label-position": false,
"member-access": true,
"no-arg": false,
"no-console": false,
"no-construct": false,
"no-duplicate-variable": true,
"no-eval": false,
"no-function-expression": true,
"no-internal-module": true,
"no-shadowed-variable": true,
"no-switch-case-fall-through": true,
"no-unnecessary-semicolons": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-with-statement": true,
"semicolon": true,
"trailing-comma": false,
"typedef": false,
"typedef-whitespace": false,
"use-named-parameter": true,
"variable-name": false,
"whitespace": false
}
}