Skip to content

Onboarding Project#46

Open
Ntobe99 wants to merge 91 commits into
IMQS:masterfrom
Ntobe99:master
Open

Onboarding Project#46
Ntobe99 wants to merge 91 commits into
IMQS:masterfrom
Ntobe99:master

Conversation

@Ntobe99

@Ntobe99 Ntobe99 commented Aug 11, 2023

Copy link
Copy Markdown

Please Review

Comment thread index.html Outdated
</div>

</div>
<script src="/app.js"></script>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The script tag can be moved into head tag

Comment thread app.ts Outdated
Comment on lines +43 to +44
console.error('Failed to fetch record count', error);
throw 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
console.error('Failed to fetch record count', error);
throw error;
throw new Error('Failed to fetch record count', error)

Comment thread app.ts Outdated
this.data = new Array<GridData>(this.columnNames.length);
} catch (error) {
console.error('Failed to fetch columns', error);
throw 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.

same as above

Comment thread app.ts Outdated
this.displayRecords();
this.updatePageInfo();
}
else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

move the else to the same line as the }

@Ntobe99
Ntobe99 requested a review from FritzOnFire September 14, 2023 11:01

@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.

One small comment, but from my side I think you are done.

@anzelIMQS @CelesteNaude Can I ask both of you to give this a once over, just in case there is anything major that I looked over. But I feel that we have covered enough to call this done.

Comment thread ApiData.ts Outdated
private setupControls(): void {
$('#prevBtn').on('click', () => this.handlePageChange(-1));
$('#nextBtn').on('click', () => this.handlePageChange(1));
$(window).on('resize', debounce(this.handleResize.bind(this), 100));

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 prefer to use arrow functions instead of using .bind(this).

Suggested change
$(window).on('resize', debounce(this.handleResize.bind(this), 100));
$(window).on('resize', debounce(() => { this.handleResize(); }, 100));

Comment thread ApiData.ts Outdated
.then(() => this.recordCount())
.then(() => this.fetchColumns())
.then(() => this.fetchRecords())
.then(() => this.setupControls())

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
.then(() => this.setupControls())
.then(() => this.setupControls());

Missing semi-colon

Comment thread ApiData.ts Outdated
Comment on lines +66 to +67
.then((response: number | string) => {
const res = JSON.parse(<string>(response));

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
.then((response: number | string) => {
const res = JSON.parse(<string>(response));
.then((response: string) => {
const res = JSON.parse(response);

Isn't just always a string? I would think that the /columns response brings back a number.

Comment thread ApiData.ts Outdated
Comment on lines +52 to +54
.then((response: number | string) => {
const totalItems = <number>response;
this.totalItems = totalItems;

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
.then((response: number | string) => {
const totalItems = <number>response;
this.totalItems = totalItems;
.then((response: number) => {
this.totalItems = response;

I also think this can only be a number once it is successful.

Comment thread ApiData.ts Outdated
Comment on lines +83 to +84
.then((response: number | string) => {
const res = JSON.parse(<string>(response));

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
.then((response: number | string) => {
const res = JSON.parse(<string>(response));
.then((response: string) => {
const res = JSON.parse(response);

It will never return a number and if one day it does, we know something fishy is going on and at least you would log that?

I would suggest return response.json() instead of JSON.parse(response) and handling your promises' error in your catch. Just a suggestion though. You don't have to as long as you log the error in your catch..

Comment thread ApiData.ts Outdated
Comment on lines +96 to +97
.catch(() => {
throw ('Failed to fetch records');

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
.catch(() => {
throw ('Failed to fetch records');
.catch(error => {
throw ('Failed to fetch records: ', error);

I mean, wouldn't you like to know the error? We know if failed but why?

Comment thread ApiData.ts
this.updatePageInfo();
})
.catch(error => {
console.error('Failed to fetch records:', 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.

Technically speaking, what do you think your console.error will look like since you have nested promises?
Think about it 🤔

Comment thread ApiData.ts Outdated
Comment on lines +117 to +118
this.displayRecords();
this.updatePageInfo();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So this.displayRecords() calls this.updatePageInfo() and then we call it again?

Sounds like double work to me 🥵

Comment thread ApiData.ts Outdated
Comment on lines +147 to +148
this.displayRecords();
this.updatePageInfo();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same vibe as previously mentioned

Comment thread ApiData.ts
}

private displayRecords(): void {
const gridTemplate = new GridTemplate(this.columnNames, this.data);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So we are creating the GridTemplate class everytime we displayRecords()?

I would have loved that we could just set the dataRecords every time we update the display because columnNames never changes throughout this life. It just sounds like a lot of objects being created and created and created...

Comment thread ApiData.ts Outdated

this.fetchAndDisplayRecords()
.then(() => {
this.updatePageInfo();

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 look at the number of times you call this.updatePageInfo() and see if it really is necessary? I would think fetchAndDisplayRecords() already called it for you and this.displayRecords() as well and now this.handlePageChange() as well.

@Ntobe99
Ntobe99 requested a review from anzelIMQS September 19, 2023 10:08

@CelesteNaude CelesteNaude 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.

Couldn't find any further major changes.

@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.

Something small but I think after this you should be home free.

Comment thread ApiData.ts Outdated
Comment on lines +53 to +54
const totalItems =response;
this.totalItems = totalItems;

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 totalItems =response;
this.totalItems = totalItems;
this.totalItems = response;

Comment thread ApiData.ts Outdated
/** Use the fetchData() func to make an HTTP request to the API endpoint and process the data */
fetchColumns(): Promise<void> {
return this.fetchStrData('http://localhost:2050/columns')
.then((response: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.

Suggested change
.then((response:string) => {
.then((response: string) => {

Comment thread ApiData.ts Outdated
$('#grid').hide();

return this.fetchStrData(`http://localhost:2050/records?from=${from}&to=${to}`)
.then((response: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.

Suggested change
.then((response:string) => {
.then((response: string) => {

Comment thread ApiData.ts Outdated
Comment on lines +129 to +138
// Maximum allowed Value
const maxRange = this.maxRange;

if (searchValue >= 0 && searchValue <= maxRange) {
let from = searchValue;
const pageSize = this.pageSize;

if (from + pageSize > maxRange) {
from = Math.max(0, maxRange - pageSize);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So how much different is this logic compared to your fetchAndDisplayRecords() logic?

The way I see it you can set this.firstVal = searchValue and let nature take its course by just calling fetchAndDisplayRecords(), or am I missing something?

Similar to what you did with handleResize

Comment thread ApiData.ts Outdated
Comment on lines +143 to +147
this.currentPage = Math.ceil(from / this.pageSize) + 1;
// Set firstVal to searched value
this.firstVal = from;
// Calculate lastVal based on pageSize
this.lastVal = from + this.pageSize - 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.

With the above comment being said. This could then be executed before the time and life would be good, right?

@Ntobe99
Ntobe99 requested a review from anzelIMQS September 21, 2023 10:19

@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.

LGTM, just the one comment but no other major issues to comment on.

Comment thread ApiData.ts Outdated

/** Fetches records using fetchAndProcessRecords(), processes them, displays them, and updates page information. */
fetchAndDisplayRecords(): Promise<void> {
this.maxRange = this.totalItems - 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.

Please move this line to your recordCount() as this value does not change but you are setting it over and over again with the same value when you do a fetchAndDisplayRecords.

@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.

There are some comments, but I don't think they are that major.

I would once again say that, you are done.

Comment thread ApiData.ts Outdated
Comment on lines +58 to +59
alert('Failed to fetch record count.');
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 handle the error... but then you throw it anyway? Rather just throw an error here, and handle the error as late as possible.

Comment thread ApiData.ts Outdated
return this.fetchStrData(`http://localhost:2050/records?from=${from}&to=${to}`)
.then((response: string) => {
const res = JSON.parse(response);
const processedData = res.map((record: 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.

I don't think the type you have for record is correct

Comment thread ApiData.ts
$('#fromInput').val('');
return this.fetchAndDisplayRecords();
} else {
alert(`Error while searching, please enter values in the range (0-${this.maxRange})`);

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 don't need to make an changes, just a comment.

I find it interesting that you would handle the error here instead of throwing it and letting the calling function deal with it, but it kinda makes sens, I can't imagine doing anything after the function that needs it to succeed.

Comment thread ApiData.ts
Comment on lines +154 to +160
private async fetchNumData(url: string): Promise<number> {
const response = await $.ajax({
url,
method: 'GET',
});
return response;
}

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 really want to comment on how you don't know if response is actually a number... but I am finding it hard to phrase it... but I guess for this project it is fine.

@Ntobe99
Ntobe99 requested a review from FritzOnFire October 4, 2023 06:03
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.

5 participants