-
Notifications
You must be signed in to change notification settings - Fork 35
Onboarding Project #46
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
base: master
Are you sure you want to change the base?
Conversation
index.html
Outdated
| </div> | ||
|
|
||
| </div> | ||
| <script src="/app.js"></script> |
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 script tag can be moved into head tag
app.ts
Outdated
| console.error('Failed to fetch record count', error); | ||
| throw error; |
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.
| 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; |
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.
same as above
app.ts
Outdated
| this.displayRecords(); | ||
| this.updatePageInfo(); | ||
| } | ||
| else { |
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.
move the else to the same line as the }
FritzOnFire
left a comment
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.
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)); |
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.
We prefer to use arrow functions instead of using .bind(this).
| $(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()) |
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.
| .then(() => this.setupControls()) | |
| .then(() => this.setupControls()); |
Missing semi-colon
ApiData.ts
Outdated
| .then((response: number | string) => { | ||
| const res = JSON.parse(<string>(response)); |
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.
| .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
| .then((response: number | string) => { | ||
| const totalItems = <number>response; | ||
| this.totalItems = totalItems; |
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.
| .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
| .then((response: number | string) => { | ||
| const res = JSON.parse(<string>(response)); |
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.
| .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
| .catch(() => { | ||
| throw ('Failed to fetch records'); |
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.
| .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); |
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.
Technically speaking, what do you think your console.error will look like since you have nested promises?
Think about it 🤔
ApiData.ts
Outdated
| this.displayRecords(); | ||
| this.updatePageInfo(); |
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.
So this.displayRecords() calls this.updatePageInfo() and then we call it again?
Sounds like double work to me 🥵
ApiData.ts
Outdated
| this.displayRecords(); | ||
| this.updatePageInfo(); |
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.
Same vibe as previously mentioned
| } | ||
|
|
||
| private displayRecords(): void { | ||
| const gridTemplate = new GridTemplate(this.columnNames, this.data); |
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.
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(); |
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 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.
CelesteNaude
left a comment
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.
Couldn't find any further major changes.
anzelIMQS
left a comment
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.
Something small but I think after this you should be home free.
ApiData.ts
Outdated
| const totalItems =response; | ||
| this.totalItems = totalItems; |
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.
| 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) => { |
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.
| .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) => { |
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.
| .then((response:string) => { | |
| .then((response: string) => { |
ApiData.ts
Outdated
| // 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); | ||
| } |
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.
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
| 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; |
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.
With the above comment being said. This could then be executed before the time and life would be good, right?
anzelIMQS
left a comment
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.
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; |
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 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
left a comment
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.
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
| alert('Failed to fetch record count.'); | ||
| throw error; |
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 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) => { |
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 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})`); |
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 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.
| private async fetchNumData(url: string): Promise<number> { | ||
| const response = await $.ajax({ | ||
| url, | ||
| method: 'GET', | ||
| }); | ||
| return response; | ||
| } |
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 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.
Please Review