Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: rerun button in debug tab #734

Merged
merged 4 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/app/compare/compare-tree/compare-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ export class CompareTreeComponent {
if (item.children) {
for (const child of item.children) {
const checkpoint = child.originalValue as Checkpoint;
if (this.getCheckpointId(checkpoint.uid) === this.getCheckpointId(checkpointToMatch.uid)) {
if (
ReportUtil.getCheckpointIdFromUid(checkpoint.uid) === ReportUtil.getCheckpointIdFromUid(checkpointToMatch.uid)
) {
tree.selectItem(child.path);
return;
} else {
Expand All @@ -142,7 +144,7 @@ export class CompareTreeComponent {
for (let checkpoint of checkpoints) {
if (
ReportUtil.isCheckPoint(itemToMatch) &&
this.getCheckpointId(checkpoint.uid) === this.getCheckpointId(itemToMatch.uid)
ReportUtil.getCheckpointIdFromUid(checkpoint.uid) === ReportUtil.getCheckpointIdFromUid(itemToMatch.uid)
) {
return checkpoint;
}
Expand All @@ -153,8 +155,4 @@ export class CompareTreeComponent {
}
return null;
}

getCheckpointId(uid: string): string {
return uid.split('#')[1];
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { CustomEditorComponent } from './custom-editor.component';
import { EditorComponent } from './editor.component';

describe('CustomEditorComponent', () => {
let component: CustomEditorComponent;
let fixture: ComponentFixture<CustomEditorComponent>;
let component: EditorComponent;
let fixture: ComponentFixture<EditorComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [CustomEditorComponent],
imports: [EditorComponent],
}).compileComponents();

fixture = TestBed.createComponent(CustomEditorComponent);
fixture = TestBed.createComponent(EditorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export const editorViewsConst = [...basicContentTypes, ...prettyContentTypes] as
export type EditorView = (typeof editorViewsConst)[number];

@Component({
selector: 'app-custom-editor',
templateUrl: './custom-editor.component.html',
styleUrl: './custom-editor.component.css',
selector: 'app-editor',
templateUrl: './editor.component.html',
styleUrl: './editor.component.css',
standalone: true,
imports: [MonacoEditorModule, ReactiveFormsModule, FormsModule, TitleCasePipe],
})
export class CustomEditorComponent implements OnInit, OnDestroy, OnChanges {
export class EditorComponent implements OnInit, OnDestroy, OnChanges {
@Input() height!: number;
@Input() readOnlyMode: boolean = true;
@Output() saveReport: Subject<string> = new Subject<string>();
Expand Down Expand Up @@ -106,6 +106,7 @@ export class CustomEditorComponent implements OnInit, OnDestroy, OnChanges {
this.save();
}
}

calculateHeight() {
if (this.statusBar) {
this.calculatedHeight = this.height - this.statusBar.nativeElement.offsetHeight;
Expand Down
28 changes: 13 additions & 15 deletions src/app/report/edit-display/edit-display.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@
></app-toggle-button>

<span class="button-divider">&#124;</span>
@if (ReportUtil.isReport(selectedNode)) {
<button
data-cy-report="rerun"
class="btn btn-info"
[title]=" editingEnabled ? 'Please save your changes to rerun the report' : 'Rerun this report'"
[disabled]="editingEnabled"
(click)="openDifferenceModal('saveRerun')"
>Rerun
</button>
}
<button
data-cy-report="rerun"
class="btn btn-info"
[title]=" editingEnabled ? 'Please save your changes to rerun the report' : 'Rerun this report'"
[disabled]="editingEnabled"
(click)="openDifferenceModal('saveRerun')"
>Rerun
</button>
@if (editingEnabled) {
<button
data-cy-report="discard"
Expand Down Expand Up @@ -107,18 +105,18 @@
}

@if (selectedNode) {
<app-report-alert-message [report]="selectedNode" />
<app-report-alert-message [report]="selectedNode"/>
@if (metadataTableVisible) {
<app-metadata-table [report]="selectedNode" />
<app-metadata-table [report]="selectedNode"/>
}
}
</div>


@if (editingRootNode && ReportUtil.isReport(selectedNode)) {
<app-edit-form [report]="selectedNode" />
<app-edit-form [report]="selectedNode"/>
}
<app-custom-editor
<app-editor
data-cy-report="editor"
[hidden]="editingRootNode"
[height]="calculatedHeight"
Expand All @@ -127,7 +125,7 @@

@if (selectedNode) {
<app-difference-modal (saveChangesEvent)="saveChanges($event)" (discardChangesEvent)="discardChanges()"
(rerunEvent)="rerunReport()" />
(rerunEvent)="rerunReport()"/>
}

<ng-template #possibilitiesModal let-modal>
Expand Down
43 changes: 24 additions & 19 deletions src/app/report/edit-display/edit-display.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { HttpService } from '../../shared/services/http.service';
import DiffMatchPatch from 'diff-match-patch';
import { HelperService } from '../../shared/services/helper.service';
import { CustomEditorComponent } from '../../custom-editor/custom-editor.component';
import { EditorComponent } from '../../editor/editor.component';
import { Report } from '../../shared/interfaces/report';
import { MetadataTableComponent } from '../../shared/components/metadata-table/metadata-table.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
Expand Down Expand Up @@ -52,7 +52,7 @@ import { ReportAlertMessageComponent } from '../report-alert-message/report-aler
NgbDropdownButtonItem,
NgbDropdownItem,
ReactiveFormsModule,
CustomEditorComponent,
EditorComponent,
MetadataTableComponent,
BooleanToStringPipe,
NgStyle,
Expand All @@ -77,7 +77,7 @@ export class EditDisplayComponent implements OnChanges {
@Input() containerHeight!: number;
@Input({ required: true }) currentView!: View;
@Input() newTab: boolean = true;
@ViewChild(CustomEditorComponent) editor!: CustomEditorComponent;
@ViewChild(EditorComponent) editor!: EditorComponent;
@ViewChild(EditFormComponent) editFormComponent!: EditFormComponent;
@ViewChild(DifferenceModalComponent)
differenceModal!: DifferenceModalComponent;
Expand Down Expand Up @@ -135,21 +135,26 @@ export class EditDisplayComponent implements OnChanges {

rerunReport(): void {
const node: Report | Checkpoint = this.selectedNode!;
if (!ReportUtil.isReport(node)) {
let reportId: number | undefined;
if (ReportUtil.isReport(node)) {
reportId = node.storageId;
} else if (ReportUtil.isCheckPoint(node)) {
reportId = ReportUtil.getStorageIdFromUid(node.uid);
}
if (reportId) {
this.httpService
.runReport(this.currentView.storageName, reportId)
.pipe(catchError(this.errorHandler.handleError()))
.subscribe({
next: (response: TestResult): void => {
this.toastService.showSuccess('Report rerun successful');
this.rerunResult = response;
this.debugTab.refreshTable();
},
});
} else {
this.toastService.showDanger('Could not find report to rerun');
return;
}
const reportId: number = node.storageId;
this.httpService
.runReport(this.currentView.storageName, reportId)
.pipe(catchError(this.errorHandler.handleError()))
.subscribe({
next: (response: TestResult): void => {
this.toastService.showSuccess('Report rerun successful');
this.rerunResult = response;
this.debugTab.refreshTable();
},
});
}

closeReport(): void {
Expand Down Expand Up @@ -182,12 +187,12 @@ export class EditDisplayComponent implements OnChanges {
let reportDifferences: ReportDifference[] = [];
if (ReportUtil.isReport(node) && this.editFormComponent) {
reportDifferences = this.editFormComponent.getDifferences();
} else if (ReportUtil.isCheckPoint(node)) {
} else if (ReportUtil.isCheckPoint(node) && this.editor?.getValue() !== node.message) {
const diff = new DiffMatchPatch().diff_main(node.message ?? '', this.editor?.getValue());
reportDifferences.push({
name: 'message',
originalValue: node.message,
// @ts-ignore
difference: new DiffMatchPatch().diff_main(node.message ?? '', this.editor?.getValue()),
difference: diff,
});
}
if (reportDifferences.length > 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/app/shared/interfaces/report-difference.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import DiffMatchPatch from 'diff-match-patch';

export interface ReportDifference {
name: string;
originalValue: string;
difference: (number | string)[][] | string;
difference: DiffMatchPatch.Diff[] | string;
}
6 changes: 6 additions & 0 deletions src/app/shared/util/report-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ export const ReportUtil = {
hasValidUid(uid: string) {
return !uid.includes('null');
},
getCheckpointIdFromUid(uid: string): number {
return +uid.split('#')[1];
},
getStorageIdFromUid(uid: string): number {
return +uid.split('#')[0];
},
};
Loading