Skip to content

Commit

Permalink
fixing some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mario meltzow committed Aug 19, 2024
1 parent 853e492 commit 83fe374
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 35 deletions.
9 changes: 7 additions & 2 deletions src/app/components/layout/layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
20 changes: 0 additions & 20 deletions src/app/components/work-item-age-page/work-item-age.page.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
<div class="grid-container">
<h1 class="mat-h1">Work Item Age</h1>
<mat-grid-list cols="1" rowHeight="100px">
<!-- Metadata Display -->
<mat-grid-tile [colspan]="1" [rowspan]="2">
<mat-card class="dashboard-card">
<mat-card-header>
<mat-card-title>Status</mat-card-title>
</mat-card-header>
<mat-card-content class="status-card-content">
<mat-chip-set
class="example-chip"
>
@for (status of availableStatuses(); track status.name) {
<mat-chip-option class="example-box" cdkDrag> {{ status.name }}
</mat-chip-option>
}
</mat-chip-set>
</mat-card-content>
</mat-card>
</mat-grid-tile>
</mat-grid-list>
<mat-grid-list cols="4" rowHeight="500px">
<!-- Large Chart in the Middle -->
<mat-grid-tile [colspan]="4" [rowspan]="1">
Expand Down
25 changes: 16 additions & 9 deletions src/app/services/business-logic.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,32 +151,33 @@ export class BusinessLogicService {
}

public findAllNewStatuses(issues: Issue[], issueHistories: IssueHistory[]): Status[] {
const statuses = new Set<Status>();
let statuses = new Array<Status>();

issues.forEach(issue => {
const status: Status = {
dataSetId: issue.dataSetId,
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!});
}
}
});

return Array.from(statuses);
}

private stateExistsInSet(set: Set<Status>, externalId: number): boolean {
private stateExistsInSet(set: Array<Status>, externalId: number): boolean {
for (let item of set) {
if (item.externalId === externalId) {
return true; // Object with the same key already exists
Expand All @@ -192,8 +193,14 @@ export class BusinessLogicService {
);
}

removeDuplicates<T>(array: T[]): T[] {
return Array.from(new Set(array));
removeDuplicates<T>(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 {
Expand Down
3 changes: 1 addition & 2 deletions src/app/services/jira-cloud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/app/services/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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<number[]> {
Expand Down

0 comments on commit 83fe374

Please sign in to comment.