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

Development: Migrate the git diff report module to standalone components #9443

Merged
merged 41 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a8a407d
Make GitDiffFileComponent standalone
pzdr7 Oct 7, 2024
3141b5f
Make GitDiffFilePanelTitleComponent standalone
pzdr7 Oct 7, 2024
bab7d17
Make GitDiffLineStatComponent standalone
pzdr7 Oct 7, 2024
2802c99
Make GitDiffFilePanel standalone
pzdr7 Oct 7, 2024
93bea42
Make remaining components standalone
pzdr7 Oct 7, 2024
65fbc62
Import components into other modules
pzdr7 Oct 7, 2024
a529ddf
Remove module import
pzdr7 Oct 7, 2024
4ca8642
Delete GitDiffReportModule
pzdr7 Oct 7, 2024
e687745
Use signals (GitDiffFile)
pzdr7 Oct 7, 2024
aea1054
Use signals (GitDiffFilePanelTitle)
pzdr7 Oct 7, 2024
733cdd0
Use computed signal
pzdr7 Oct 7, 2024
528d235
Tracked
pzdr7 Oct 7, 2024
2035abb
Use signals (GitDiffLineStatComponent)
pzdr7 Oct 7, 2024
dda89f2
Use signals (GitDiffFilePanelComponent)
pzdr7 Oct 7, 2024
36f456a
Use signals (GitDiffReportComponent)
pzdr7 Oct 7, 2024
47177a7
Use inject in Modal
pzdr7 Oct 7, 2024
768ca8d
Make signals readonly
pzdr7 Oct 8, 2024
70d9f7a
wip modal
pzdr7 Oct 8, 2024
bd51c28
Revert change to git-diff-report-modal.component.ts
pzdr7 Oct 8, 2024
47ec8ba
Fix tests
pzdr7 Oct 8, 2024
f8f0448
Fix tests
pzdr7 Oct 8, 2024
4578fd2
Remove dead code
pzdr7 Oct 8, 2024
b1cad69
Rename methods
pzdr7 Oct 8, 2024
b6052bd
Simplify diff layout
pzdr7 Oct 8, 2024
1bd8192
Reorganize
pzdr7 Oct 8, 2024
4e26ffd
Adjust tooltip placemnet
pzdr7 Oct 8, 2024
e2ad9c2
Merge branch 'develop' into chore/development/migrate-diff
pzdr7 Oct 8, 2024
7a9c966
Update src/main/webapp/app/detail-overview-list/components/programmin…
pzdr7 Oct 10, 2024
5511344
Update src/main/webapp/app/exam/manage/student-exams/student-exam-tim…
pzdr7 Oct 10, 2024
011c89f
Add constant
pzdr7 Oct 10, 2024
cd37721
Add translate directive
pzdr7 Oct 10, 2024
bf3c2eb
Fix display bug
pzdr7 Oct 10, 2024
671cac5
Remove redundant setup
pzdr7 Oct 10, 2024
82454b3
Move icons to the very top
pzdr7 Oct 10, 2024
6601bfc
Move more icons to the top
pzdr7 Oct 10, 2024
e8bf525
Simplify untracked
pzdr7 Oct 10, 2024
f849a55
Merge branch 'develop' into chore/development/migrate-diff
pzdr7 Oct 11, 2024
428b65a
Merge branch 'develop' into chore/development/migrate-diff
pzdr7 Oct 11, 2024
fa5f6b8
Merge branch 'develop' into chore/development/migrate-diff
pzdr7 Oct 12, 2024
ce1f712
Merge branch 'develop' into chore/development/migrate-diff
pzdr7 Oct 12, 2024
6739eb8
Merge branch 'develop' into chore/development/migrate-diff
pzdr7 Oct 12, 2024
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
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Component, Input, OnDestroy, inject } from '@angular/core';
import { Component, Input, OnDestroy, inject, signal } from '@angular/core';
import type { ProgrammingDiffReportDetail } from 'app/detail-overview-list/detail.model';
import { FeatureToggle } from 'app/shared/feature-toggle/feature-toggle.service';
import { ButtonSize, ButtonType, TooltipPlacement } from 'app/shared/components/button.component';
import { faCodeCompare } from '@fortawesome/free-solid-svg-icons';
import { ProgrammingExerciseGitDiffReport } from 'app/entities/hestia/programming-exercise-git-diff-report.model';
import { GitDiffReportModalComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report-modal.component';
import { GitDiffReportModule } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report.module';
import { ArtemisSharedComponentModule } from 'app/shared/components/shared-component.module';
import { ArtemisSharedModule } from 'app/shared/shared.module';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { GitDiffLineStatComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component';

@Component({
selector: 'jhi-programming-diff-report-detail',
templateUrl: 'programming-diff-report-detail.component.html',
standalone: true,
imports: [ArtemisSharedModule, ArtemisSharedComponentModule, GitDiffReportModule],
imports: [ArtemisSharedModule, ArtemisSharedComponentModule, GitDiffLineStatComponent],
})
export class ProgrammingDiffReportDetailComponent implements OnDestroy {
protected readonly FeatureToggle = FeatureToggle;
Expand All @@ -38,7 +38,7 @@ export class ProgrammingDiffReportDetailComponent implements OnDestroy {
return;
}

this.modalRef = this.modalService.open(GitDiffReportModalComponent, { windowClass: 'diff-view-modal' });
this.modalRef.componentInstance.report = gitDiff;
this.modalRef = this.modalService.open(GitDiffReportModalComponent, { windowClass: GitDiffReportModalComponent.WINDOW_CLASS });
this.modalRef.componentInstance.report = signal(gitDiff);
}
}
2 changes: 0 additions & 2 deletions src/main/webapp/app/detail-overview-list/detail.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ArtemisSharedComponentModule } from 'app/shared/components/shared-compo
import { SubmissionResultStatusModule } from 'app/overview/submission-result-status.module';
import { ArtemisProgrammingExerciseStatusModule } from 'app/exercises/programming/manage/status/programming-exercise-status.module';
import { ArtemisProgrammingExerciseActionsModule } from 'app/exercises/programming/shared/actions/programming-exercise-actions.module';
import { GitDiffReportModule } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report.module';
import { ArtemisProgrammingExerciseInstructionsEditorModule } from 'app/exercises/programming/manage/instructions-editor/programming-exercise-instructions-editor.module';
import { ArtemisProgrammingExerciseLifecycleModule } from 'app/exercises/programming/shared/lifecycle/programming-exercise-lifecycle.module';
import { AssessmentInstructionsModule } from 'app/assessment/assessment-instructions/assessment-instructions.module';
Expand All @@ -25,7 +24,6 @@ import { NoDataComponent } from 'app/shared/no-data-component';
SubmissionResultStatusModule,
ArtemisProgrammingExerciseStatusModule,
ArtemisProgrammingExerciseActionsModule,
GitDiffReportModule,
ArtemisProgrammingExerciseInstructionsEditorModule,
ArtemisProgrammingExerciseLifecycleModule,
AssessmentInstructionsModule,
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/app/exam/manage/exam-management.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ import { ArtemisExamNavigationBarModule } from 'app/exam/participate/exam-naviga
import { ArtemisExamSubmissionComponentsModule } from 'app/exam/participate/exercises/exam-submission-components.module';
import { MatSliderModule } from '@angular/material/slider';
import { ProgrammingExerciseExamDiffComponent } from './student-exams/student-exam-timeline/programming-exam-diff/programming-exercise-exam-diff.component';
import { GitDiffReportModule } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report.module';
import { ArtemisProgrammingExerciseModule } from 'app/exercises/programming/shared/programming-exercise.module';
import { DetailModule } from 'app/detail-overview-list/detail.module';
import { ArtemisDurationFromSecondsPipe } from 'app/shared/pipes/artemis-duration-from-seconds.pipe';
import { NoDataComponent } from 'app/shared/no-data-component';
import { GitDiffLineStatComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component';

const ENTITY_STATES = [...examManagementState];

Expand Down Expand Up @@ -110,10 +110,10 @@ const ENTITY_STATES = [...examManagementState];
ArtemisExamNavigationBarModule,
ArtemisExamSubmissionComponentsModule,
MatSliderModule,
GitDiffReportModule,
ArtemisProgrammingExerciseModule,
DetailModule,
NoDataComponent,
GitDiffLineStatComponent,
],
declarations: [
ExamManagementComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectorRef, Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { ChangeDetectorRef, Component, EventEmitter, Input, OnDestroy, OnInit, Output, signal } from '@angular/core';
import { ProgrammingExercise } from 'app/entities/programming/programming-exercise.model';
import { ProgrammingSubmission } from 'app/entities/programming/programming-submission.model';
import { FeatureToggle } from 'app/shared/feature-toggle/feature-toggle.service';
Expand Down Expand Up @@ -123,10 +123,10 @@ export class ProgrammingExerciseExamDiffComponent extends ExamPageComponent impl
* Shows the git-diff in a modal.
*/
showGitDiff(): void {
const modalRef = this.modalService.open(GitDiffReportModalComponent, { size: 'xl' });
modalRef.componentInstance.report = this.exercise.gitDiffReport;
modalRef.componentInstance.diffForTemplateAndSolution = false;
modalRef.componentInstance.cachedRepositoryFiles = this.cachedRepositoryFiles;
const modalRef = this.modalService.open(GitDiffReportModalComponent, { windowClass: GitDiffReportModalComponent.WINDOW_CLASS });
modalRef.componentInstance.report = signal(this.exercise.gitDiffReport);
modalRef.componentInstance.diffForTemplateAndSolution = signal(false);
modalRef.componentInstance.cachedRepositoryFiles = signal(this.cachedRepositoryFiles);
this.cachedRepositoryFilesService.getCachedRepositoryFilesObservable().subscribe((cachedRepositoryFiles) => {
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
this.cachedRepositoryFiles = cachedRepositoryFiles;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { CoverageGenerationStepComponent } from '../steps/coverage-generation-st
import { SolutionEntryGenerationStepComponent } from '../steps/solution-entry-generation-step/solution-entry-generation-step.component';
import { CodeHintGenerationStepComponent } from '../steps/code-hint-generation-step/code-hint-generation-step.component';
import { TestwiseCoverageReportModule } from 'app/exercises/programming/hestia/testwise-coverage-report/testwise-coverage-report.module';
import { GitDiffReportModule } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report.module';
import { CodeHintGenerationOverviewComponent } from 'app/exercises/programming/hestia/generation-overview/code-hint-generation-overview/code-hint-generation-overview.component';
import { RouterModule } from '@angular/router';
import { ArtemisMarkdownModule } from 'app/shared/markdown.module';
import { MatExpansionModule } from '@angular/material/expansion';
import { CodeHintGenerationStatusStepComponent } from 'app/exercises/programming/hestia/generation-overview/code-hint-generation-status/code-hint-generation-status-step.component';
import { ManualSolutionEntryCreationModalComponent } from '../manual-solution-entry-creation-modal/manual-solution-entry-creation-modal.component';
import { GitDiffReportComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report.component';

@NgModule({
imports: [
Expand All @@ -24,13 +24,9 @@ import { ManualSolutionEntryCreationModalComponent } from '../manual-solution-en
ArtemisExerciseHintSharedModule,
ArtemisSharedComponentModule,
TestwiseCoverageReportModule,
GitDiffReportModule,
GitDiffReportModule,
TestwiseCoverageReportModule,
ArtemisSharedComponentModule,
ArtemisMarkdownModule,
ArtemisExerciseHintSharedModule,
MatExpansionModule,
GitDiffReportComponent,
],
declarations: [
CodeHintGenerationStatusComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div class="my-2 ps-1 file-path-with-badge">
{{ title }}
@if (fileStatus !== FileStatus.UNCHANGED) {
{{ title() }}
@if (fileStatus() !== FileStatus.UNCHANGED) {
<span
[jhiTranslate]="'artemisApp.programmingExercise.diffReport.fileChange.' + fileStatus"
[jhiTranslate]="'artemisApp.programmingExercise.diffReport.fileChange.' + fileStatus()"
[ngClass]="{
badge: true,
'bg-success': fileStatus === FileStatus.CREATED,
'bg-warning': fileStatus === FileStatus.RENAMED,
'bg-danger': fileStatus === FileStatus.DELETED,
'bg-success': fileStatus() === FileStatus.CREATED,
'bg-warning': fileStatus() === FileStatus.RENAMED,
'bg-danger': fileStatus() === FileStatus.DELETED,
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
}"
></span>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Component, Input, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core';
import { TranslateDirective } from 'app/shared/language/translate.directive';
import { CommonModule } from '@angular/common';

enum FileStatus {
CREATED = 'created',
Expand All @@ -10,35 +12,33 @@ enum FileStatus {
selector: 'jhi-git-diff-file-panel-title',
templateUrl: './git-diff-file-panel-title.component.html',
styleUrls: ['./git-diff-file-panel-title.component.scss'],
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [TranslateDirective, CommonModule],
})
export class GitDiffFilePanelTitleComponent implements OnInit {
@Input()
previousFilePath?: string;
export class GitDiffFilePanelTitleComponent {
readonly originalFilePath = input<string>();
readonly modifiedFilePath = input<string>();

@Input()
filePath?: string;
readonly titleAndFileStatus = computed(() => this.getTitleAndFileStatus());
readonly title = computed(() => this.titleAndFileStatus().title);
readonly fileStatus = computed(() => this.titleAndFileStatus().fileStatus);

title?: string;
fileStatus: FileStatus = FileStatus.UNCHANGED;

// Expose to template
protected readonly FileStatus = FileStatus;

ngOnInit(): void {
if (this.filePath && this.previousFilePath) {
if (this.filePath !== this.previousFilePath) {
this.title = `${this.previousFilePath} → ${this.filePath}`;
this.fileStatus = FileStatus.RENAMED;
private getTitleAndFileStatus(): { title?: string; fileStatus: FileStatus } {
const originalFilePath = this.originalFilePath();
const modifiedFilePath = this.modifiedFilePath();
if (modifiedFilePath && originalFilePath) {
if (modifiedFilePath !== originalFilePath) {
return { title: `${originalFilePath} → ${modifiedFilePath}`, fileStatus: FileStatus.RENAMED };
} else {
this.title = this.filePath;
this.fileStatus = FileStatus.UNCHANGED;
return { title: modifiedFilePath, fileStatus: FileStatus.UNCHANGED };
}
} else if (this.filePath) {
this.title = this.filePath;
this.fileStatus = FileStatus.CREATED;
} else if (modifiedFilePath) {
return { title: modifiedFilePath, fileStatus: FileStatus.CREATED };
} else {
this.title = this.previousFilePath;
this.fileStatus = FileStatus.DELETED;
return { title: originalFilePath, fileStatus: FileStatus.DELETED };
}
}
}
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div ngbAccordion [destroyOnHide]="false" class="git-diff-file-panel">
<div ngbAccordionItem #fileDiffPanel="ngbAccordionItem" [collapsed]="false">
<div ngbAccordionHeader class="d-flex align-items-center justify-content-between">
<jhi-git-diff-file-panel-title [filePath]="filePath" [previousFilePath]="previousFilePath" />
<jhi-git-diff-file-panel-title [modifiedFilePath]="modifiedFilePath()" [originalFilePath]="originalFilePath()" />
<div>
<jhi-git-diff-line-stat
[addedLineCount]="addedLineCount"
[removedLineCount]="removedLineCount"
[addedLineCount]="addedLineCount()"
[removedLineCount]="removedLineCount()"
ngbTooltip="{{
(diffForTemplateAndSolution
(diffForTemplateAndSolution()
? 'artemisApp.programmingExercise.diffReport.lineStatTooltipFullReport'
: 'artemisApp.programmingExercise.diffReport.lineStatTooltipFullReportExamTimeline'
) | artemisTranslate
Expand All @@ -21,11 +21,13 @@
<div ngbAccordionCollapse>
<div ngbAccordionBody>
<jhi-git-diff-file
[allowSplitView]="allowSplitView"
[diffForTemplateAndSolution]="diffForTemplateAndSolution"
[diffEntries]="diffEntries"
[originalFileContent]="templateFileContent"
[modifiedFileContent]="solutionFileContent"
[allowSplitView]="allowSplitView()"
[diffForTemplateAndSolution]="diffForTemplateAndSolution()"
[diffEntries]="diffEntries()"
[originalFileContent]="originalFileContent()"
[originalFilePath]="originalFilePath()"
[modifiedFileContent]="modifiedFileContent()"
[modifiedFilePath]="modifiedFilePath()"
(onDiffReady)="onDiffReady.emit($event)"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,66 @@
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { ChangeDetectionStrategy, Component, ViewEncapsulation, computed, input, output } from '@angular/core';
import { ProgrammingExerciseGitDiffEntry } from 'app/entities/hestia/programming-exercise-git-diff-entry.model';
import { faAngleDown, faAngleUp } from '@fortawesome/free-solid-svg-icons';
import { GitDiffFilePanelTitleComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-file-panel-title.component';
import { GitDiffLineStatComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component';
import { GitDiffFileComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-file.component';
import { ArtemisSharedModule } from 'app/shared/shared.module';

@Component({
selector: 'jhi-git-diff-file-panel',
templateUrl: './git-diff-file-panel.component.html',
styleUrls: ['./git-diff-file-panel.component.scss'],
encapsulation: ViewEncapsulation.None,
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [GitDiffFilePanelTitleComponent, GitDiffLineStatComponent, GitDiffFileComponent, ArtemisSharedModule],
})
export class GitDiffFilePanelComponent implements OnInit {
@Input() diffEntries: ProgrammingExerciseGitDiffEntry[];
export class GitDiffFilePanelComponent {
protected readonly faAngleUp = faAngleUp;
protected readonly faAngleDown = faAngleDown;

@Input() templateFileContent: string | undefined;
readonly diffEntries = input.required<ProgrammingExerciseGitDiffEntry[]>();
readonly originalFileContent = input<string>();
readonly modifiedFileContent = input<string>();
readonly diffForTemplateAndSolution = input<boolean>(true);
readonly allowSplitView = input<boolean>(true);
readonly onDiffReady = output<boolean>();

@Input() solutionFileContent: string | undefined;

@Input() diffForTemplateAndSolution = true;

@Input() allowSplitView = true;

@Output() onDiffReady = new EventEmitter<boolean>();

previousFilePath: string | undefined;
filePath: string | undefined;

addedLineCount: number;
removedLineCount: number;

faAngleUp = faAngleUp;
faAngleDown = faAngleDown;

ngOnInit(): void {
this.filePath = this.diffEntries
.map((entry) => entry.filePath)
readonly originalFilePath = computed(() =>
this.diffEntries()
.map((entry) => entry.previousFilePath)
.filter((filePath) => filePath)
.first();
.first(),
);

this.previousFilePath = this.diffEntries
.map((entry) => entry.previousFilePath)
readonly modifiedFilePath = computed(() =>
this.diffEntries()
.map((entry) => entry.filePath)
.filter((filePath) => filePath)
.first();
.first(),
);

this.addedLineCount = this.diffEntries
.filter((entry) => entry && entry.filePath && entry.startLine && entry.lineCount)
.flatMap((entry) => {
return this.solutionFileContent?.split('\n').slice(entry.startLine! - 1, entry.startLine! + entry.lineCount! - 1);
})
.filter((line) => line && line.trim().length !== 0).length;
readonly addedLineCount = computed(
() =>
this.diffEntries()
.filter((entry) => entry && entry.filePath && entry.startLine && entry.lineCount)
.flatMap((entry) => {
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
return this.modifiedFileContent()
?.split('\n')
.slice(entry.startLine! - 1, entry.startLine! + entry.lineCount! - 1);
})
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
.filter((line) => line && line.trim().length !== 0).length,
);

this.removedLineCount = this.diffEntries
.filter((entry) => entry && entry.previousFilePath && entry.previousStartLine && entry.previousLineCount)
.flatMap((entry) => {
return this.templateFileContent?.split('\n').slice(entry.previousStartLine! - 1, entry.previousStartLine! + entry.previousLineCount! - 1);
})
.filter((line) => line && line.trim().length !== 0).length;
}
readonly removedLineCount = computed(
() =>
this.diffEntries()
.filter((entry) => entry && entry.previousFilePath && entry.previousStartLine && entry.previousLineCount)
.flatMap((entry) => {
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
return this.originalFileContent()
?.split('\n')
.slice(entry.previousStartLine! - 1, entry.previousStartLine! + entry.previousLineCount! - 1);
})
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
.filter((line) => line && line.trim().length !== 0).length,
);
}
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="ph-1">
@if (fileUnchanged) {
@if (fileUnchanged()) {
<div class="w-100 d-flex justify-content-center">
<span class="p-2" jhiTranslate="artemisApp.repository.commitHistory.commitDetails.fileUnchanged"></span>
</div>
}
<!-- The editor is only hidden, not removed, as we still want it to report its readiness. -->
<jhi-monaco-diff-editor [hidden]="fileUnchanged" [allowSplitView]="allowSplitView" (onReadyForDisplayChange)="onDiffReady.emit($event)" />
<jhi-monaco-diff-editor [hidden]="fileUnchanged()" [allowSplitView]="allowSplitView()" (onReadyForDisplayChange)="onDiffReady.emit($event)" />
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
</div>
Loading
Loading