Skip to content

Onboarding Project: Maxwill#48

Open
MaxTF141 wants to merge 42 commits into
IMQS:masterfrom
MaxTF141:master
Open

Onboarding Project: Maxwill#48
MaxTF141 wants to merge 42 commits into
IMQS:masterfrom
MaxTF141:master

Conversation

@MaxTF141

Copy link
Copy Markdown

No description provided.

Comment thread app.ts Outdated
let lastPage = firstPage + 9
let currentFromID = 1;
let currentToID = 20;
let difference = 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Try to only make use of 2 global variables and give them a type

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No need to give the Type if you set the variable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should not have any global variables.

And you only have to set the type if they where class variables or if they were normal variables that were not assigned a value in the same line. And these variables are neither.

Comment thread app.ts Outdated
let difference = 0


// This function will handle retrieving the records from the api

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no need for so much space between the code, we all love each other here

Comment thread app.ts Outdated
async function getColumns(): Promise<Array<string>> {
try {
const data = await fetch(`${api}columns`);
const columns: Array<string> = await data.json();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
const columns: Array<string> = await data.json();
const columns: string[]= JSON.parse(data);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Always make use of .json() instead of JSON.parse() when able. But the string[] is still the correct comment.

Comment thread app.ts Outdated
return columns;

} catch (error) {
console.error(error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no need to console log

Comment thread app.ts Outdated
firstPage = lastPage - 9;
$(".pagination").empty();
await pageNumbers(firstPage, lastPage);
// isFunctionRunning = false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

did you mean to comment this out, looks like it could break if you press prev and then next

Comment thread app.ts Outdated
}
if (firstPage === 1) {
$(".prev").css({ display: "none" });
} else $(".prev").css({ display: "block" });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no {} for else?

@DevinFledermaus DevinFledermaus left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Lots of you functions make use of the same variables that you keep having to set, maybe get them all in a central place. will make lots of your functions way smaller

Comment thread apiManager.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please don't add your .js files to this PR.

Comment thread apiManager.js.map Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please don't add your .js.map files to this PR.

Comment thread apiManager.ts
Comment on lines +2 to +3
private mainUrl: string;
constructor(mainUrl: string) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please leave an empty line between your class variables and constructor

Comment thread apiManager.ts Outdated
Comment on lines +8 to +13
return fetch(mainUrl)
.then(res => res.text())
.then(data => JSON.parse(data))
.catch((err) => {
throw err
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You need to check if your fetch was successful, as that does not get catch'd by the .catch.

Please use res.json() instead of res.text() and then JSON.parse(). (I know someone else asked you to do it this way, and I apologize that you have to revert your code now again, but this is the right way)

Also, please add a ; to the throw and at the end.

Comment thread apiManager.ts Outdated
return fetch(mainUrl)
.then(res => res.text())
.then(data => JSON.parse(data))
.catch((err) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Either remove the () around err or specify a type

Comment thread style.css Outdated
Comment on lines +87 to +88
text-overflow: ellipsis;
white-space: nowrap;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice

Comment thread style.css Outdated
padding-left: 10px;
}

input:focus{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a space before the {

Comment thread style.css Outdated
margin: 3px;
background-color: #ffffff36;
box-shadow: inset 0px 0px 20px -10px rgba(255, 255, 255, 0.438);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove this one empty line.

Comment thread style.css
Comment on lines +152 to +165
.header {
height: 5vh;
}
.heading {
height: 5vh;
}
.table-container {
height: 80vh;
}
.wrapper {
height: 10vh;
display: flex;
align-items: center;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please leave an empty line between classes.

Comment thread style.css Outdated
@keyframes rot {
100% {
transform: rotate(360deg);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove this one empty line.

@anzelIMQS anzelIMQS left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I gave a very partial review. Will get back to you if necessary.

Comment thread app.ts Outdated
}
})
.catch(error => {
throw new Error(`Failed to retrieve columns: ${error}`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
throw new Error(`Failed to retrieve columns: ${error}`)
throw new Error(`Failed to retrieve columns: ${error}`);

Missing semi-colon

Comment thread app.ts Outdated
Comment on lines +67 to +68
}
else if (this.currentPage === 1) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
}
else if (this.currentPage === 1) {
} else if (this.currentPage === 1) {

On the same line please

Comment thread app.ts Outdated
this.paginationEnd = pageEnd;
}
} else {
throw new Error("Please provide a valid integer.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
throw new Error("Please provide a valid integer.")
throw new Error("Please provide a valid integer.");

Comment thread app.ts Outdated
return this.apiManager.getRecordCount()
.then(count => {
let inputNumber = this.input();
let inputNumberInt: any = parseInt(inputNumber);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it always a number being returned?

Comment thread apiManager.ts Outdated

/** Retrieves the number of records there are */
getRecordCount(): Promise<number> {
let test = `${this.mainUrl}recordCount`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please remove stray

Comment thread apiManager.ts Outdated
Comment on lines +8 to +9
private fetchJson(mainUrl: string): Promise<any> {
return fetch(mainUrl)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
private fetchJson(mainUrl: string): Promise<any> {
return fetch(mainUrl)
private fetchJson(url: string): Promise<any> {
return fetch(url)

Feels incorrect calling it the main one since in this scope it is only one and can be anything. Main or not.

Comment thread apiManager.ts
Comment on lines +1 to +2
class ApiManager {
private mainUrl: string;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Space inbetween.

Comment thread app.ts
}
$("#records-table-body").append(`</tr>`);
}
this.isFunctionRunning = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do you know that there is a chance that your request doesn't get this far since it broke somewhere above. That would mean your isFunctionRunning will forever be true and causing no new requests to come in for showRecords.

Ideally, make use of the finally-block instead. It will always run irrespective of the request failing.

Comment thread app.ts Outdated
Comment on lines +301 to +304
let screenHeight = <number>($(window).height());
if (screenHeight < 68) {
screenHeight = 68;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Eish, then why not have a min-height prop on your window?

@MaxTF141
MaxTF141 requested a review from anzelIMQS September 20, 2023 08:41

@anzelIMQS anzelIMQS left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please try to see how you can make use of more shared code. I still see some repetitiveness. Try to reduce it by seeing a pattern in your code.

Comment thread app.ts Outdated
}

/** Fetching the records and rendering it on the DOM in the table*/
showRecords(fromID: number, toID: number): Promise<any> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
showRecords(fromID: number, toID: number): Promise<any> {
showRecords(fromID: number, toID: number): Promise<void> {

Change back to void

Comment thread app.ts Outdated

constructor() {
this.isFunctionRunning = false;
this.apiManager = new ApiManager("http://localhost:2050/");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
this.apiManager = new ApiManager("http://localhost:2050/");
this.apiManager = new ApiManager("http://localhost:2050");

Comment thread apiManager.ts Outdated

/** Retrieves records from the api */
getRecords(fromID: number, toID: number): Promise<string[][]> {
return this.fetchJson(`${this.mainUrl}records?from=${fromID}&to=${toID}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
return this.fetchJson(`${this.mainUrl}records?from=${fromID}&to=${toID}`);
return this.fetchJson(`${this.mainUrl}/records?from=${fromID}&to=${toID}`);

Comment thread apiManager.ts Outdated

/** Retrieves columns from the api */
getColumns(): Promise<string[]> {
return this.fetchJson(`${this.mainUrl}columns`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
return this.fetchJson(`${this.mainUrl}columns`);
return this.fetchJson(`${this.mainUrl}/columns`);

Comment thread apiManager.ts Outdated

/** Retrieves the number of records there are */
getRecordCount(): Promise<number> {
return this.fetchJson(`${this.mainUrl}recordCount`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
return this.fetchJson(`${this.mainUrl}recordCount`);
return this.fetchJson(`${this.mainUrl}/recordCount`);

Comment thread app.ts Outdated
$(".prev").on("click", () => {
this.paginationEnd = this.paginationStart - 1;
this.paginationStart = this.paginationEnd - 9;
$(".pagination").empty();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You are already emptying in pageNumbers.
Please remove.

Comment thread app.ts Outdated
start = end - maxRecords;
}
this.currentPage = Math.floor(end / maxRecords);
if (inputNumberInt < 1000000 && inputNumberInt > 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if (inputNumberInt < 1000000 && inputNumberInt > 0) {
if (inputNumberInt < 1000000 && inputNumberInt > 0) {

You have your count. You went all the way to fetch it, use it and not 1000000.

Comment thread app.ts Outdated
/** Fetching the records and rendering it on the DOM in the table*/
showRecords(fromID: number, toID: number): Promise<any> {
if (this.isFunctionRunning) {
return Promise.resolve(undefined);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
return Promise.resolve(undefined);
return new Promise<void>(() => { });

Comment thread app.ts Outdated
// element's attribute value.
$(".pagination").on("click", ".pagination-item", (event) => {
$('.pagination-item').prop('disabled', true);
return this.apiManager.getRecordCount()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You don't have to return here. Just run it.

Suggested change
return this.apiManager.getRecordCount()
this.apiManager.getRecordCount()

Comment thread app.ts Outdated
$(".pagination-item").removeClass("active");
$(event.target).addClass("active");
const self = this;
$(".pagination-item").each(function () {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Any reason why this can't be an arrow function?

@MaxTF141
MaxTF141 requested a review from anzelIMQS September 26, 2023 09:13
Comment thread app.ts Outdated
@@ -0,0 +1,408 @@
class DataHandler {
/** It tracks if the showRecords function is running and would the value would be false if it's not. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** It tracks if the showRecords function is running and would the value would be false if it's not. */
/** It tracks if the showRecords function is running. Is false if it's not. */

Comment thread apiManager.ts Outdated
return fetch(url)
.then(res => {
if (res.ok) {
return res.json()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing ;

Comment thread apiManager.ts Outdated
if (res.ok) {
return res.json()
} else {
throw new Error(`HTTP error! Status: ${res.status}`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing ;

Comment thread apiManager.ts
Comment on lines +34 to +36
getRecordCount(): Promise<number> {
return this.fetchJson(`${this.mainUrl}/recordCount`);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So /recordCount returns a number as text... not a json... this feels misleading. You should probably do a different fetch to handle this case.

Comment thread app.ts Outdated
class DataHandler {
/** It tracks if the showRecords function is running and would the value would be false if it's not. */
private isFunctionRunning: boolean;
/** This is an instance of the ApiManager class and passing a string when being used. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You probably mean that you provide the url to the server during initialization. The way you have it written here it sounds like every function on this class takes a string as a parameter.

Comment thread app.ts Outdated
}
this.currentToID = this.currentFromID + maxRecords;
this.currentPage = newCurrentPage;
let originalID = ((this.currentPage * maxRecords) + (this.currentPage - 1)) - maxRecords;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please just change this to be

(this.currentPage - 1) * (maxRecords + 1)

It just makes it a bit clearer that you are calculating the fromID of the previous page.

Comment thread app.ts Outdated
this.currentFromID = (this.currentPage - 1) * maxRecords + 1;
}
if (this.currentFromID === 0) {
let divisor = screenHeight < 136 ? maxRecords : maxRecords - 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't like this hard coded value... 136. You definitely should not need it. Something must be wrong with the way you calculate maxRecords if this is necessary. Please remove it.

Comment thread app.ts Outdated
clearTimeout(this.resizeTimer);
}
this.resizeTimer = setTimeout(() => {
return this.adjustDisplayedRecords()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Returning here does not make a lot of sens. setTimeout can't do anything with your promise.

Comment thread app.ts Outdated
Comment thread app.ts Outdated

@FritzOnFire FritzOnFire left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please only handle errors as late as possible

Comment thread apiManager.ts Outdated
Comment on lines +36 to +48
.then(res => {
if(res.ok) {
return res.text();
} else {
throw new Error(`HTTP error? Status: ${res.status}`);
}
})
.then (recordCount => {
return parseInt(recordCount);
})
.catch(error => {
throw error;
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is missing some indentation.

Comment thread apiManager.ts Outdated
getRecordCount(): Promise<number> {
return fetch(`${this.mainUrl}/recordCount`)
.then(res => {
if(res.ok) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if(res.ok) {
if (res.ok) {

Comment thread apiManager.ts Outdated
throw new Error(`HTTP error? Status: ${res.status}`);
}
})
.then (recordCount => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
.then (recordCount => {
.then(recordCount => {

Comment thread apiManager.ts Outdated
}
})
.then (recordCount => {
return parseInt(recordCount);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would prefer it you checked for NaN here... but for this project it is probably fine.

Comment thread app.ts Outdated
Comment on lines +182 to +183
alert("An error occurred while trying to load the page. Please try again.");
throw error;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

???

Why are you handling the error and then throwing the error anyway?

In this scenario there is no one to catch that error, which is bad, you should remove the throw.

Comment thread app.ts Outdated
// on to the DOM.
$(".search-input").on("input", (e: any) => {
e.preventDefault();
return this.getRecordCount()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pretty sure the handler function jquery is looking for does not return anything. Please remove the return.

Comment thread app.ts Outdated
Comment on lines +265 to +266
alert("An error occurred while trying to search. Please try again.");
throw error;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar comment about handling the error and then throwing it anyway.

Comment thread app.ts Outdated
Comment on lines +310 to +312
alert("An error occurred while trying to search. Please try again.");
console.error("Failed when clicking on the results: ", error);
throw error;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar comment about handling the error and then throwing it anyway.

Comment thread app.ts Outdated
let endID: number;
let pageEnd: number;
let pageStart: number;
return this.getRecordCount()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pretty sure the handler function jquery is looking for does not return anything. Please remove the return.

Comment thread app.ts Outdated
Comment on lines +359 to +360
alert("An error occurred while trying to adjust the records. Please try again.");
throw error;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

???

So you handle the error... and then you throw it anyway meaning that you have to handle it again later?

Please do not handle the error here, as who ever is calling adjustDisplayedRecords needs to know that we failed to adjustDisplayedRecords and they need to react accordingly.

Comment thread app.ts Outdated
Comment on lines +373 to +374
alert("An error occurred while trying to resize the window. Please try again.");
throw error;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can't throw here, there is no one left to catch it.

Comment thread app.ts Outdated
})
.catch(error => {
alert("An error occurred while trying to load your page. Please try again.");
throw new Error(`An error occurred when loading your page: ${error}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can't throw here, there is no one left to catch it.

@MaxTF141
MaxTF141 requested a review from FritzOnFire October 2, 2023 06:24
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.

4 participants