Skip to content

Conversation

@Ntobe99
Copy link

@Ntobe99 Ntobe99 commented Aug 11, 2023

Please Review

index.html Outdated
</div>

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

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

app.ts Outdated
Comment on lines 43 to 44
console.error('Failed to fetch record count', error);
throw error;

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)

app.ts Outdated
this.data = new Array<GridData>(this.columnNames.length);
} catch (error) {
console.error('Failed to fetch columns', error);
throw error;

Choose a reason for hiding this comment

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

same as above

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

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
Copy link
Contributor

@FritzOnFire FritzOnFire left a comment

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.

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
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));

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

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

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

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.

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

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.

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

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

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

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?

this.updatePageInfo();
})
.catch(error => {
console.error('Failed to fetch records:', error);

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 🤔

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

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 🥵

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

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

}

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

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

ApiData.ts Outdated

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

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
Copy link

@CelesteNaude CelesteNaude left a comment

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.

Copy link

@anzelIMQS anzelIMQS left a comment

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.

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

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;

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) => {

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) => {

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

return this.fetchStrData(`http://localhost:2050/records?from=${from}&to=${to}`)
.then((response:string) => {

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) => {

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);
}

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

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;

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
Copy link

@anzelIMQS anzelIMQS left a comment

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.

ApiData.ts Outdated

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

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.

Copy link
Contributor

@FritzOnFire FritzOnFire left a comment

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.

ApiData.ts Outdated
Comment on lines 58 to 59
alert('Failed to fetch record count.');
throw error;
Copy link
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.

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

$('#fromInput').val('');
return this.fetchAndDisplayRecords();
} else {
alert(`Error while searching, please enter values in the range (0-${this.maxRange})`);
Copy link
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 on lines +154 to +160
private async fetchNumData(url: string): Promise<number> {
const response = await $.ajax({
url,
method: 'GET',
});
return response;
}
Copy link
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