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

Origin/refactor/retype functions READY FOR REVIEW #391

Closed
wants to merge 39 commits into from

Conversation

Banshaan
Copy link
Contributor

All functions that utilize http.service have been assigned (hopefully) the right types.
I also added/revised some interfaces so that they could be (better) utilized.

dylan van dijk and others added 27 commits March 28, 2024 10:02
…so added TODO comments for tracking progress
Co-authored-by: Matthijs Smets <93487259+MatthijsSmets@users.noreply.github.com>
Co-authored-by: Matthijs Smets <93487259+MatthijsSmets@users.noreply.github.com>
utilize http.service functions.
…ll interfaces used to achieve type safety. only some issues left in table.component.html
Copy link
Member

@philipsens philipsens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you first resolve the git conflicts?
That way we can have a better representation of what will get merged.

Copy link
Member

@Matthbo Matthbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a lot of let keywords to initialize a variable.
Maybe its best to see if its really needed and change it to const when the variables aren't being reassigned, try to do this for every bit of code you've been working on so that hopefully at some point its correct in most places

src/app/debug/debug.component.ts Outdated Show resolved Hide resolved
src/app/debug/display/display.component.ts Outdated Show resolved Hide resolved
src/app/debug/table/table.component.ts Outdated Show resolved Hide resolved
src/app/debug/table/table.component.ts Outdated Show resolved Hide resolved
src/app/debug/table/table.component.ts Outdated Show resolved Hide resolved
src/app/debug/table/table.component.ts Outdated Show resolved Hide resolved
src/app/debug/debug-tree/debug-tree.component.ts Outdated Show resolved Hide resolved
src/app/debug/table/table.component.ts Outdated Show resolved Hide resolved
src/app/report/edit-display/edit-display.component.html Outdated Show resolved Hide resolved
src/app/report/edit-display/edit-display.component.ts Outdated Show resolved Hide resolved
src/app/report/edit-display/edit-display.component.ts Outdated Show resolved Hide resolved
src/app/report/edit-display/edit-display.component.ts Outdated Show resolved Hide resolved
src/app/shared/pipes/table-cell-shortener.pipe.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@MatthijsSmets MatthijsSmets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at my comments. In some cases it feels like you're solving as you go, instead of taking a step back and trying to work out a better solution.

}

openSelected(): void {
for (const report of this.tableSettings.reportMetadata) {
if (report.checked) {
this.openReport(report.storageId);
this.openReport(`${report.storageId}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe its better to set the parameter type of openReport to number? That way it doesn't have to be cast.

(report: MetaData) => report.checked,
);
this.httpService
.getReport(`${reportTab?.storageId}`, this.viewSettings.currentView.storageName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if reportTab is undefined?

}

compareTwoReports(): void {
let compareReports: any = {};
let compareReports: Partial<CompareReports> = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a const

<div *ngIf="report.preTruncatedMessageLength > 0" id="truncatedMessageLabel" class="btn btn-static my-2 mx-1 px-2">
Message is truncated ( {{ report.preTruncatedMessageLength - report.message.length}} characters removed)
<div *ngIf="report.preTruncatedMessageLength && report.preTruncatedMessageLength > 0" id="truncatedMessageLabel" class="btn btn-static my-2 mx-1 px-2">
Message is truncated ( {{ report.preTruncatedMessageLength - report.message!.length}} characters removed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now you use the ! to tell typescript that this wont be null or undefined when accessed. However the report.message can be null as its not in the if condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been fixed

let reportId: string = this.report.storageId;
this.httpService.runDisplayReport(reportId, this.currentView.storageName).subscribe((response) => {
let element = document.querySelector('#showRerunResult')!;
const reportId: string = String(this.report.storageId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the storageId should either be saved as a string in the model or always be used as a number. Right now the implementation makes it so it always has to be cast.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StorageId is now saved as a string in the model.

Comment on lines 14 to 17
'CONVERSATION ID': string;
'CORRELATION ID': string;
'ENDPOINT NAME': string;
'NR OF CHECKPOINTS': string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this hardcoded all caps string as an attribute name is not done. Please make them camelCase and maybe use a transform function to transform the backend response with all caps: "CONVERSION ID" => conversationId into this model.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been fixed

STATUS: string;
TIMESTAMP: string;

[key: string]: string | boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is not necessary for an object thats retrieved from the backend. This should only be used when you do not know what the object can contain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been taken out.

@@ -7,10 +7,13 @@ import { Subscription } from 'rxjs';
standalone: true,
})
export class TableCellShortenerPipe implements PipeTransform {
transform(value: string): string {
transform(value: string | boolean): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this can be a boolean, as far as i know a table cell never has a boolean value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue has been fixed, it had to do with the array it looped over also having a boolean value (checked). I changed the interface around a bit so that this wouldnt cause issues anymore

Comment on lines 26 to 31
metadataLabels: [],
defaultView: false,
crudStorage: false,
metadataNames: [],
nodeLinkStrategy: '',
storageName: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're setting these attributes to an empty array or string. Is this necessary or should the model maybe changed so that the attributes can be undefined? I've seen you do this in other places as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason i did it this way is because if i make them able to be undefined in the interface, there'll be many errors complaining that the value could be undefined. Should i fix this by having those places first check if they have a value or is there a better way of doing this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's better to check whether the value is (not) undefined than to set the value to an empty string or array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been fixed, instead of setting the properties to empty arrays/strings it now checks whether they have a value or not.

@philipsens
Copy link
Member

@Banshaan Is this almost ready?

Matthbo
Matthbo previously approved these changes May 24, 2024
Copy link
Member

@Matthbo Matthbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good but I haven't tested the functionality, I'm assuming it's working as it should since this is supposed to be a refactor pr

src/app/debug/display/display.component.ts Outdated Show resolved Hide resolved
Added suggestion to turn a string concatenation into a template string

Co-authored-by: Vivy <4380412+Matthbo@users.noreply.github.com>
@philipsens
Copy link
Member

Please request review when you're finished.

Comment on lines +12 to +14
<button ngbDropdownItem (click)="downloadReports(true, true)"> XML & Binary </button>
<button ngbDropdownItem (click)="downloadReports(false, true)"> XML <i class="fa fa-info-circle" title="Only a binary file can be uploaded again"></i></button>
<button ngbDropdownItem (click)="downloadReports(true, false)"> Binary </button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are the spaces for? :o

Copy link
Contributor

@MatthijsSmets MatthijsSmets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at my previous comment about taking a step back and deciding what you need to do instead of solving as you go.

Comment on lines +71 to +74
let currentViewName: string = '';
if (currentView.name) {
currentViewName = currentView.name;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let currentViewName: string = '';
if (currentView.name) {
currentViewName = currentView.name;
}
let currentViewName: string = currentView.name ?? '';

@Output() closeReportEvent = new EventEmitter<any>();
@ViewChild('editorComponent') editorComponent!: CustomEditorComponent;
@ViewChild(DisplayTableComponent)
displayTableComponent!: DisplayTableComponent;
metadataTableVisible: boolean = false;
@ViewChild('container') container!: ElementRef;
@Input() containerHeight!: number;
@Input() currentView: View = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If currentView is an input attribute, why is it initialised with an empty object?
Wouldn't it be better to do it like the other input?

Suggested change
@Input() currentView: View = {};
@Input() currentView!: View;

this.helperService.download('id=' + queryString + '&', this.currentView.storageName, exportBinary, exportXML);
const queryString: string = this.report.xml ? this.report.storageId : this.report.uid.split('#')[0];
if (this.currentView.storageName) {
this.helperService.download('id=' + queryString + '&', this.currentView.storageName, exportBinary, exportXML);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make use of string templating instead of concatenation

Suggested change
this.helperService.download('id=' + queryString + '&', this.currentView.storageName, exportBinary, exportXML);
this.helperService.download(`id=${queryString}&`, this.currentView.storageName, exportBinary, exportXML);

Comment on lines 53 to 60
copyReport(): void {
const storageId: number = this.report.xml ? +this.report.storageId : +this.report.uid.split('#')[0];
const data: any = {};
data[this.currentView.storageName] = [storageId];
const data: Record<string, number[]> = {};
if (this.currentView.storageName) {
data[this.currentView.storageName] = [storageId];
}
this.httpService.copyReport(data, 'Test').subscribe(); // TODO: storage is hardcoded, fix issue #196 for this
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this function, if this.currentView.storageName is null or undefined, then the copyReport method is called with an empty data object. It is better to add that to the if block.
Also, the declaration and initialisation can be combined like so:

    if (this.currentView.storageName) {
      const data: Record<string, number[]> = { [this.currentView.storageName]: [storageId] };
      this.httpService.copyReport(data, 'Test').subscribe(); // TODO: storage is hardcoded, fix issue #196 for this
    }

catchError(this.httpService.handleError());
},
});
if (this.viewSettings.currentView?.metadataNames && this.viewSettings.currentView?.storageName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.viewSettings.currentView?.metadataNames && this.viewSettings.currentView?.storageName) {
if (
this.viewSettings.currentView &&
this.viewSettings.currentView.metadataNames &&
this.viewSettings.currentView.storageName
) {

endpointName: string;
timestamp: string;

// [key: string]: string | boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove commented code

@@ -0,0 +1,3 @@
export interface TargetWithFiles extends EventTarget {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at my comment about using HtmlInputElement, that way this interface is redundant and can be removed


export interface ViewSettings {
currentView?: View;
currentViewName?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentView already has an attribute called name

name: 'tableCellTypeChecker',
standalone: true,
})
export class tableCellTypeChecker implements PipeTransform {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export class tableCellTypeChecker implements PipeTransform {
export class TableCellTypeChecker implements PipeTransform {

@@ -20,7 +20,7 @@ export class TestFolderTreeComponent {
folderBehaviourOnClick: 'select',
expandAllFolders: true,
highlightOpenFolders: false,
autoSelectCondition: (item: CreateTreeItem) => this.autoSelectItem(item),
autoOpenCondition: (item: CreateTreeItem) => this.autoSelectItem(item),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autoOpenCondition is an entirely different function in the tree. Why did you change this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants