From 83fe374e333ad3a79e0a0e90a05a9acb2fef7177 Mon Sep 17 00:00:00 2001 From: mario meltzow Date: Mon, 19 Aug 2024 11:12:29 +0200 Subject: [PATCH] fixing some bugs --- src/app/components/layout/layout.component.ts | 9 +++++-- .../status-history-table.component.ts | 2 +- .../work-item-age.page.html | 20 --------------- src/app/services/business-logic.service.ts | 25 ++++++++++++------- src/app/services/jira-cloud.service.ts | 3 +-- src/app/services/storage.service.ts | 3 ++- 6 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/app/components/layout/layout.component.ts b/src/app/components/layout/layout.component.ts index 5835034..c8b73d2 100644 --- a/src/app/components/layout/layout.component.ts +++ b/src/app/components/layout/layout.component.ts @@ -138,8 +138,13 @@ export class LayoutComponent implements OnInit { } } - clearDatabase() { - this.storageService.clearAllData(); + async clearDatabase() { + const success = await this.storageService.clearIssueData(); + if (success) { + this.toastr.success('Successfully cleared all data'); + } else { + this.toastr.error('Failed to clear all data'); + } } protected readonly THROUGHPUT = THROUGHPUT; diff --git a/src/app/components/status-history-table/status-history-table.component.ts b/src/app/components/status-history-table/status-history-table.component.ts index 8178da0..29db278 100644 --- a/src/app/components/status-history-table/status-history-table.component.ts +++ b/src/app/components/status-history-table/status-history-table.component.ts @@ -64,7 +64,7 @@ export class StatusHistoryTableComponent implements OnInit { async ngOnInit() { const issueHistories = await this.storageService.getAllIssueHistoriesForStatuses(); - const issuesIds = this.businessLogic.removeDuplicates(issueHistories.map(issueHistory => issueHistory.issueId)); + const issuesIds = this.businessLogic.removeDuplicates(issueHistories.map(issueHistory => issueHistory.issueId), (a, b) => a == b); const issues = await this.storageService.getIssuesByIds(issuesIds); const combinedData: CombinedIssueHistory[] = issueHistories.map(issueHistory => { diff --git a/src/app/components/work-item-age-page/work-item-age.page.html b/src/app/components/work-item-age-page/work-item-age.page.html index 50268c1..793e089 100644 --- a/src/app/components/work-item-age-page/work-item-age.page.html +++ b/src/app/components/work-item-age-page/work-item-age.page.html @@ -1,25 +1,5 @@

Work Item Age

- - - - - - Status - - - - @for (status of availableStatuses(); track status.name) { - {{ status.name }} - - } - - - - - diff --git a/src/app/services/business-logic.service.ts b/src/app/services/business-logic.service.ts index 7baa155..467c515 100644 --- a/src/app/services/business-logic.service.ts +++ b/src/app/services/business-logic.service.ts @@ -151,7 +151,7 @@ export class BusinessLogicService { } public findAllNewStatuses(issues: Issue[], issueHistories: IssueHistory[]): Status[] { - const statuses = new Set(); + let statuses = new Array(); issues.forEach(issue => { const status: Status = { @@ -159,16 +159,17 @@ export class BusinessLogicService { name: issue.status, externalId: issue.externalStatusId }; - statuses.add(status); + statuses.push(status); }); + statuses = this.removeDuplicates(statuses, (a, b) => a.externalId === b.externalId); issueHistories.forEach(history => { if (history.field === 'status') { - if (!this.stateExistsInSet(statuses, history.fromValueId!)) { + if (history.fromValueId && !this.stateExistsInSet(statuses, history.fromValueId!)) { - statuses.add({dataSetId: history.datasetId, name: history.fromValue, externalId: history.fromValueId!}); - } else if (!this.stateExistsInSet(statuses, history.toValueId!)) { - statuses.add({dataSetId: history.datasetId, name: history.toValue, externalId: history.toValueId!}); + statuses.push({dataSetId: history.datasetId, name: history.fromValue, externalId: history.fromValueId!}); + } else if (history.toValueId && !this.stateExistsInSet(statuses, history.toValueId!)) { + statuses.push({dataSetId: history.datasetId, name: history.toValue, externalId: history.toValueId!}); } } }); @@ -176,7 +177,7 @@ export class BusinessLogicService { return Array.from(statuses); } - private stateExistsInSet(set: Set, externalId: number): boolean { + private stateExistsInSet(set: Array, externalId: number): boolean { for (let item of set) { if (item.externalId === externalId) { return true; // Object with the same key already exists @@ -192,8 +193,14 @@ export class BusinessLogicService { ); } - removeDuplicates(array: T[]): T[] { - return Array.from(new Set(array)); + removeDuplicates(array: T[], compareFn: (a: T, b: T) => boolean): T[] { + const uniqueArray: T[] = []; + array.forEach(item => { + if (!uniqueArray.some(uniqueItem => compareFn(item, uniqueItem))) { + uniqueArray.push(item); + } + }); + return uniqueArray; } computePercentile(cycleTimes: number[], percentile: number): number { diff --git a/src/app/services/jira-cloud.service.ts b/src/app/services/jira-cloud.service.ts index 0fc8b55..9a80163 100644 --- a/src/app/services/jira-cloud.service.ts +++ b/src/app/services/jira-cloud.service.ts @@ -120,8 +120,7 @@ export class JiraCloudService implements OnInit { url: issue.self!, }; i = await this.storageService.addissue(i); - - + issues.push(i); const issueHistories = this.businessLogicService.mapChangelogToIssueHistory(i, issue.changelog as Version2.Version2Models.Changelog); await this.storageService.addIssueHistories(issueHistories); diff --git a/src/app/services/storage.service.ts b/src/app/services/storage.service.ts index 95d9bc0..6d3df14 100644 --- a/src/app/services/storage.service.ts +++ b/src/app/services/storage.service.ts @@ -193,7 +193,7 @@ export class StorageService { //FIXME: this must be dependent on the dataset async clearIssueData() { this.dbService.selectDb(dbConfigIssueData.name); - this.dbService.deleteDatabase(); + return firstValueFrom(this.dbService.deleteDatabase()); } async clearAllData() { @@ -202,6 +202,7 @@ export class StorageService { await firstValueFrom(this.dbService.clear(TableNames.ISSUES)); await firstValueFrom(this.dbService.clear(TableNames.WORK_ITEM_AGE)); await firstValueFrom(this.dbService.clear(TableNames.CYCLE_TIME)); + await firstValueFrom(this.dbService.clear(TableNames.THROUGHPUT)); } async addIssueHistories(histories: IssueHistory[]): Promise {