-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
…so added TODO comments for tracking progress
… added to list of interfaces.
…refrank/ladybug-frontend into origin/refactor/correct-type
Co-authored-by: Matthijs Smets <93487259+MatthijsSmets@users.noreply.github.com>
Co-authored-by: Matthijs Smets <93487259+MatthijsSmets@users.noreply.github.com>
…nterfaces to help accomplish that.
…d interfaces to help accomplish that.
utilize http.service functions.
…ll interfaces used to achieve type safety. only some issues left in table.component.html
There was a problem hiding this 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.
There was a problem hiding this 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
There was a problem hiding this 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}`); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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> = {}; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
'CONVERSATION ID': string; | ||
'CORRELATION ID': string; | ||
'ENDPOINT NAME': string; | ||
'NR OF CHECKPOINTS': string; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
metadataLabels: [], | ||
defaultView: false, | ||
crudStorage: false, | ||
metadataNames: [], | ||
nodeLinkStrategy: '', | ||
storageName: '', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@Banshaan Is this almost ready? |
There was a problem hiding this 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
Added suggestion to turn a string concatenation into a template string Co-authored-by: Vivy <4380412+Matthbo@users.noreply.github.com>
Please request review when you're finished. |
<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> |
There was a problem hiding this comment.
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
There was a problem hiding this 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.
let currentViewName: string = ''; | ||
if (currentView.name) { | ||
currentViewName = currentView.name; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 = {}; |
There was a problem hiding this comment.
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?
@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); |
There was a problem hiding this comment.
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
this.helperService.download('id=' + queryString + '&', this.currentView.storageName, exportBinary, exportXML); | |
this.helperService.download(`id=${queryString}&`, this.currentView.storageName, exportBinary, exportXML); |
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 | ||
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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), |
There was a problem hiding this comment.
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?
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.