[ACS-5991] ESLint fixes and code quality improvements (#8893)

* prefer-optional-chain: core

* prefer-optional-chain: content, fix typings

* prefer-optional-chain: process, fix typings

* prefer-optional-chain: process-cloud, fix typings, fix ts configs and eslint

* [ci: force] sonar errors fixes, insights lib

* [ci:force] fix security issues

* [ci:force] fix metadata e2e bug, js assignment bugs

* [ci:force] fix lint issue

* [ci:force] fix tests
This commit is contained in:
Denys Vuika
2023-09-18 09:42:16 +01:00
committed by GitHub
parent 99f591ed67
commit a1dd270c5d
203 changed files with 4155 additions and 4960 deletions

View File

@@ -52,10 +52,6 @@
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-var-requires": "error",
"brace-style": [
"error",
"1tbs"
],
"comma-dangle": "error",
"default-case": "error",
"import/order": "off",

View File

@@ -103,35 +103,28 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On
private hideParameters: boolean = true;
private onDestroy$ = new Subject<boolean>();
constructor(private analyticsService: AnalyticsService,
private formBuilder: UntypedFormBuilder,
private logService: LogService,
private downloadService: DownloadService,
private dialog: MatDialog) {
}
constructor(
private analyticsService: AnalyticsService,
private formBuilder: UntypedFormBuilder,
private logService: LogService,
private downloadService: DownloadService,
private dialog: MatDialog
) {}
ngOnInit() {
this.onDropdownChanged
.pipe(takeUntil(this.onDestroy$))
.subscribe((field: any) => {
const paramDependOn = this.reportParameters.definition.parameters.find(
(param) => param.dependsOn === field.id
);
if (paramDependOn) {
this.retrieveParameterOptions(
this.reportParameters.definition.parameters, this.appId, this.reportId, field.value
);
}
});
this.onDropdownChanged.pipe(takeUntil(this.onDestroy$)).subscribe((field: any) => {
const paramDependOn = this.reportParameters.definition.parameters.find((param) => param.dependsOn === field.id);
if (paramDependOn) {
this.retrieveParameterOptions(this.reportParameters.definition.parameters, this.appId, this.reportId, field.value);
}
});
this.successReportParams
.pipe(takeUntil(this.onDestroy$))
.subscribe(report => {
if (report.hasParameters()) {
this.retrieveParameterOptions(report.definition.parameters, this.appId);
this.generateFormGroupFromParameter(report.definition.parameters);
}
});
this.successReportParams.pipe(takeUntil(this.onDestroy$)).subscribe((report) => {
if (report.hasParameters()) {
this.retrieveParameterOptions(report.definition.parameters, this.appId);
this.generateFormGroupFromParameter(report.definition.parameters);
}
});
}
ngOnChanges(changes: SimpleChanges) {
@@ -141,7 +134,7 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On
}
const reportId = changes['reportId'];
if (reportId && reportId.currentValue) {
if (reportId?.currentValue) {
this.reportId = reportId.currentValue;
this.getReportParams(reportId.currentValue);
}
@@ -249,17 +242,15 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On
}
editTitle() {
this.analyticsService
.updateReport(`${this.reportParameters.id}`, this.reportParameters.name)
.subscribe(
() => {
this.editDisable();
this.edit.emit(this.reportParameters.name);
},
err => {
this.error.emit(err);
}
);
this.analyticsService.updateReport(`${this.reportParameters.id}`, this.reportParameters.name).subscribe(
() => {
this.editDisable();
this.edit.emit(this.reportParameters.name);
},
(err) => {
this.error.emit(err);
}
);
}
showDialog(event: string) {
@@ -293,11 +284,10 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On
}
doExport(paramQuery: ReportQuery) {
this.analyticsService.exportReportToCsv(this.reportId, paramQuery).subscribe(
(data: any) => {
const blob: Blob = new Blob([data], { type: 'text/csv' });
this.downloadService.downloadBlob(blob, paramQuery.reportName + '.csv');
});
this.analyticsService.exportReportToCsv(this.reportId, paramQuery).subscribe((data: any) => {
const blob: Blob = new Blob([data], { type: 'text/csv' });
this.downloadService.downloadBlob(blob, paramQuery.reportName + '.csv');
});
}
doSave(paramQuery: ReportQuery) {
@@ -307,9 +297,12 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On
}
deleteReport(reportId: string) {
this.analyticsService.deleteReport(reportId).subscribe(() => {
this.deleteReportSuccess.emit(reportId);
}, (error) => this.logService.error(error));
this.analyticsService.deleteReport(reportId).subscribe(
() => {
this.deleteReportSuccess.emit(reportId);
},
(error) => this.logService.error(error)
);
}
ngAfterContentChecked() {
@@ -370,39 +363,60 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On
formBuilderGroup.dateRange = new UntypedFormGroup({}, Validators.required);
break;
case 'processDefinition':
formBuilderGroup.processDefGroup = new UntypedFormGroup({
processDefinitionId: new UntypedFormControl(null, Validators.required, null)
}, Validators.required);
formBuilderGroup.processDefGroup = new UntypedFormGroup(
{
processDefinitionId: new UntypedFormControl(null, Validators.required, null)
},
Validators.required
);
break;
case 'duration':
formBuilderGroup.durationGroup = new UntypedFormGroup({
duration: new UntypedFormControl(null, Validators.required, null)
}, Validators.required);
formBuilderGroup.durationGroup = new UntypedFormGroup(
{
duration: new UntypedFormControl(null, Validators.required, null)
},
Validators.required
);
break;
case 'dateInterval':
formBuilderGroup.dateIntervalGroup = new UntypedFormGroup({
dateRangeInterval: new UntypedFormControl(null, Validators.required, null)
}, Validators.required);
formBuilderGroup.dateIntervalGroup = new UntypedFormGroup(
{
dateRangeInterval: new UntypedFormControl(null, Validators.required, null)
},
Validators.required
);
break;
case 'boolean':
formBuilderGroup.typeFilteringGroup = new UntypedFormGroup({
typeFiltering: new UntypedFormControl(null, Validators.required, null)
}, Validators.required);
formBuilderGroup.typeFilteringGroup = new UntypedFormGroup(
{
typeFiltering: new UntypedFormControl(null, Validators.required, null)
},
Validators.required
);
break;
case 'task':
formBuilderGroup.taskGroup = new UntypedFormGroup({
taskName: new UntypedFormControl(null, Validators.required, null)
}, Validators.required);
formBuilderGroup.taskGroup = new UntypedFormGroup(
{
taskName: new UntypedFormControl(null, Validators.required, null)
},
Validators.required
);
break;
case 'integer':
formBuilderGroup.processInstanceGroup = new UntypedFormGroup({
slowProcessInstanceInteger: new UntypedFormControl(null, Validators.required, null)
}, Validators.required);
formBuilderGroup.processInstanceGroup = new UntypedFormGroup(
{
slowProcessInstanceInteger: new UntypedFormControl(null, Validators.required, null)
},
Validators.required
);
break;
case 'status':
formBuilderGroup.statusGroup = new UntypedFormGroup({
status: new UntypedFormControl(null, Validators.required, null)
}, Validators.required);
formBuilderGroup.statusGroup = new UntypedFormGroup(
{
status: new UntypedFormControl(null, Validators.required, null)
},
Validators.required
);
break;
default:
return;

View File

@@ -33,8 +33,9 @@ const SHOW_FORMAT = 'DD/MM/YYYY';
templateUrl: './date-range.widget.html',
styleUrls: ['./date-range.widget.scss'],
providers: [
{provide: DateAdapter, useClass: MomentDateAdapter},
{provide: MAT_DATE_FORMATS, useValue: MOMENT_DATE_FORMATS}],
{ provide: DateAdapter, useClass: MomentDateAdapter },
{ provide: MAT_DATE_FORMATS, useValue: MOMENT_DATE_FORMATS }
],
encapsulation: ViewEncapsulation.None
})
export class DateRangeWidgetComponent implements OnInit, OnDestroy {
@@ -54,26 +55,23 @@ export class DateRangeWidgetComponent implements OnInit, OnDestroy {
private onDestroy$ = new Subject<boolean>();
constructor(
private dateAdapter: DateAdapter<Moment>,
private userPreferencesService: UserPreferencesService) {
}
constructor(private dateAdapter: DateAdapter<Moment>, private userPreferencesService: UserPreferencesService) {}
ngOnInit() {
this.userPreferencesService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))
.subscribe(locale => this.dateAdapter.setLocale(locale));
.subscribe((locale) => this.dateAdapter.setLocale(locale));
const momentDateAdapter = this.dateAdapter as MomentDateAdapter;
momentDateAdapter.overrideDisplayFormat = SHOW_FORMAT;
if (this.field) {
if (this.field.value && this.field.value.startDate) {
if (this.field.value?.startDate) {
this.startDatePicker = moment(this.field.value.startDate, FORMAT_DATE_ACTIVITI);
}
if (this.field.value && this.field.value.endDate) {
if (this.field.value?.endDate) {
this.endDatePicker = moment(this.field.value.endDate, FORMAT_DATE_ACTIVITI);
}
}
@@ -99,7 +97,7 @@ export class DateRangeWidgetComponent implements OnInit, OnDestroy {
if (this.dateRange.valid) {
const dateStart = this.convertToMomentDateWithTime(this.dateRange.controls.startDate.value);
const endStart = this.convertToMomentDateWithTime(this.dateRange.controls.endDate.value);
this.dateRangeChanged.emit({startDate: dateStart, endDate: endStart});
this.dateRangeChanged.emit({ startDate: dateStart, endDate: endStart });
}
}
@@ -111,14 +109,14 @@ export class DateRangeWidgetComponent implements OnInit, OnDestroy {
const startDate = moment(formControl.get('startDate').value);
const endDate = moment(formControl.get('endDate').value);
const isAfterCheck = startDate.isAfter(endDate);
return isAfterCheck ? {greaterThan: true} : null;
return isAfterCheck ? { greaterThan: true } : null;
}
isStartDateGreaterThanEndDate() {
return this.dateRange && this.dateRange.errors && this.dateRange.errors.greaterThan;
isStartDateGreaterThanEndDate(): boolean {
return !!this.dateRange?.errors?.greaterThan;
}
isStartDateEmpty() {
return this.dateRange && this.dateRange.controls.startDate && !this.dateRange.controls.startDate.valid;
isStartDateEmpty(): boolean {
return this.dateRange?.controls.startDate && !this.dateRange.controls.startDate.valid;
}
}

View File

@@ -20,7 +20,6 @@ import { EventEmitter, Input, OnChanges, Output, SimpleChanges, Directive } from
@Directive()
// eslint-disable-next-line @angular-eslint/directive-class-suffix
export class WidgetComponent implements OnChanges {
/** field. */
@Input()
field: any;
@@ -31,7 +30,7 @@ export class WidgetComponent implements OnChanges {
ngOnChanges(changes: SimpleChanges) {
const field = changes['field'];
if (field && field.currentValue) {
if (field?.currentValue) {
this.fieldChanged.emit(field.currentValue.value);
return;
}
@@ -42,13 +41,10 @@ export class WidgetComponent implements OnChanges {
}
hasValue(): boolean {
return this.field &&
this.field.value !== null &&
this.field.value !== undefined;
return this.field?.value !== null && this.field.value !== undefined;
}
changeValue(field: any) {
this.fieldChanged.emit(field);
}
}

View File

@@ -20,7 +20,7 @@ export class Point {
y: number;
constructor(obj?: any) {
this.x = obj && obj.x || 0;
this.y = obj && obj.y || 0;
this.x = obj?.x || 0;
this.y = obj?.y || 0;
}
}

View File

@@ -29,28 +29,28 @@ export class Chart {
options?: any;
constructor(obj?: any) {
this.id = obj && obj.id || null;
this.title = obj.title;
this.titleKey = obj.titleKey;
this.labels = obj.labels || [];
this.data = obj.data || [];
this.datasets = obj.datasets || [];
this.detailsTable = obj.detailsTable;
this.showDetails = !!obj.showDetails;
this.options = obj.options;
this.id = obj?.id;
this.title = obj?.title;
this.titleKey = obj?.titleKey;
this.labels = obj?.labels || [];
this.data = obj?.data || [];
this.datasets = obj?.datasets || [];
this.detailsTable = obj?.detailsTable;
this.showDetails = !!obj?.showDetails;
this.options = obj?.options;
if (obj && obj.type) {
if (obj?.type) {
this.type = this.convertType(obj.type);
this.icon = this.getIconType(this.type);
}
}
hasData(): boolean {
return this.data && this.data.length > 0;
return this.data?.length > 0;
}
hasDatasets(): boolean {
return this.datasets && this.datasets.length > 0;
return this.datasets?.length > 0;
}
hasDetailsTable(): boolean {

View File

@@ -28,12 +28,12 @@ export class HeatMapChart extends Chart {
constructor(obj?: any) {
super(obj);
this.avgTimePercentages = obj && obj.avgTimePercentages || null;
this.avgTimeValues = obj && obj.avgTimeValues || null;
this.processDefinitionId = obj && obj.processDefinitionId || null;
this.totalCountValues = obj && obj.totalCountValues || null;
this.totalCountsPercentages = obj && obj.totalCountsPercentages || null;
this.totalTimePercentages = obj && obj.totalTimePercentages || null;
this.totalTimeValues = obj && obj.totalTimeValues || null;
this.avgTimePercentages = obj?.avgTimePercentages;
this.avgTimeValues = obj?.avgTimeValues;
this.processDefinitionId = obj?.processDefinitionId;
this.totalCountValues = obj?.totalCountValues;
this.totalCountsPercentages = obj?.totalCountsPercentages;
this.totalTimePercentages = obj?.totalTimePercentages;
this.totalTimeValues = obj?.totalTimeValues;
}
}

View File

@@ -22,10 +22,10 @@ export class LineChart extends Chart {
constructor(obj?: any) {
super(obj);
this.labels = obj && obj.columnNames.slice(1, obj.columnNames.length);
this.labels = obj?.columnNames.slice(1, obj.columnNames.length);
obj.rows.forEach((value: any) => {
this.datasets.push({data: value.slice(1, value.length), label: value[0]});
this.datasets.push({ data: value.slice(1, value.length), label: value[0] });
});
}
}

View File

@@ -21,10 +21,10 @@ export class TableChart extends Chart {
constructor(obj?: any) {
super(obj);
this.labels = obj && obj.columnNames;
this.labels = obj?.columnNames;
if (obj.rows) {
this.datasets = obj && obj.rows;
if (obj?.rows) {
this.datasets = obj.rows;
}
}
}

View File

@@ -22,10 +22,10 @@ export class ParameterValueModel {
value: string;
constructor(obj?: any) {
this.id = obj && obj.id;
this.name = obj && obj.name || null;
this.value = obj && obj.value || null;
this.version = obj && obj.version || null;
this.id = obj?.id;
this.name = obj?.name;
this.value = obj?.value;
this.version = obj?.version;
}
get label() {

View File

@@ -21,9 +21,8 @@ export class ReportDateRange {
rangeId: string;
constructor(obj?: any) {
this.startDate = obj && obj.startDate || null;
this.endDate = obj && obj.endDate || null;
this.rangeId = obj && obj.rangeId || null;
this.startDate = obj?.startDate;
this.endDate = obj?.endDate;
this.rangeId = obj?.rangeId;
}
}

View File

@@ -27,12 +27,12 @@ export class ReportParameterDetailsModel {
dependsOn: string;
constructor(obj?: any) {
this.id = obj && obj.id;
this.name = obj && obj.name || null;
this.nameKey = obj && obj.nameKey || null;
this.type = obj && obj.type || null;
this.value = obj && obj.value || null;
this.options = obj && obj.options || null;
this.dependsOn = obj && obj.dependsOn || null;
this.id = obj?.id;
this.name = obj?.name;
this.nameKey = obj?.nameKey;
this.type = obj?.type;
this.value = obj?.value;
this.options = obj?.options;
this.dependsOn = obj?.dependsOn;
}
}

View File

@@ -25,17 +25,17 @@ export class ReportParametersModel {
description?: string;
constructor(obj?: any) {
this.id = obj && obj.id;
this.name = obj && obj.name || null;
this.id = obj?.id;
this.name = obj?.name;
this.description = obj.description;
if (obj && obj.definition) {
if (obj?.definition) {
this.definition = new ReportDefinitionModel(JSON.parse(obj.definition));
}
this.created = obj && obj.created || null;
this.created = obj?.created;
}
hasParameters() {
return (this.definition && this.definition.parameters && this.definition.parameters.length > 0) ? true : false;
return this.definition?.parameters?.length > 0;
}
}

View File

@@ -29,15 +29,14 @@ export class ReportQuery {
duration: number;
constructor(obj?: any) {
this.reportName = obj && obj.reportName || null;
this.processDefinitionId = obj && obj.processDefinitionId || null;
this.status = obj && obj.status || null;
this.taskName = obj && obj.taskName || null;
this.dateRangeInterval = obj && obj.dateRangeInterval || null;
this.typeFiltering = obj && (typeof obj.typeFiltering !== 'undefined') ? obj.typeFiltering : true;
this.slowProcessInstanceInteger = obj && obj.slowProcessInstanceInteger || 0;
this.duration = obj && obj.duration || 0;
this.reportName = obj?.reportName;
this.processDefinitionId = obj?.processDefinitionId;
this.status = obj?.status;
this.taskName = obj?.taskName;
this.dateRangeInterval = obj?.dateRangeInterval;
this.typeFiltering = obj && typeof obj.typeFiltering !== 'undefined' ? obj.typeFiltering : true;
this.slowProcessInstanceInteger = obj?.slowProcessInstanceInteger || 0;
this.duration = obj?.duration || 0;
this.dateRange = new ReportDateRange(obj);
}
}

View File

@@ -34,7 +34,7 @@ export class DiagramColorService {
}
getFillColour(key: string) {
if (this.totalColors && this.totalColors.hasOwnProperty(key)) {
if (this.totalColors?.hasOwnProperty(key)) {
const colorPercentage = this.totalColors[key];
return this.convertColorToHsb(colorPercentage);
} else {
@@ -61,7 +61,7 @@ export class DiagramColorService {
}
convertColorToHsb(colorPercentage: number): string {
const hue = (120.0 - (colorPercentage * 1.2)) / 360.0;
const hue = (120.0 - colorPercentage * 1.2) / 360.0;
return 'hsb(' + hue + ', 1, 1)';
}
}

View File

@@ -2,6 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"declarationMap": true,
"paths": {
"@alfresco/adf-extensions": ["../../../dist/libs/extensions"],