-
Notifications
You must be signed in to change notification settings - Fork 4
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
refactor(StudentRunListComponent): Remove duplication #1463
refactor(StudentRunListComponent): Remove duplication #1463
Conversation
- Combine functions to retrieve number of runs based on status - Extract sortByStartTimeDesc()
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. I added some minor inline code comments to consider before merge. I also realize that we can now write getRunTotal() declaratively (e.g., this.filteredRuns.filter(...).length)
), which will make the code even easier to read, but we can address this at a later time if you'd like.
src/app/domain/run.spec.ts
Outdated
@@ -1,14 +1,14 @@ | |||
import { waitForAsync } from '@angular/core/testing'; | |||
import { Run } from './run'; | |||
import { title } from 'process'; |
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.
Unused, remove?
import { title } from 'process'; | |
import { title } from 'process'; |
src/app/domain/run.spec.ts
Outdated
runList = [run2, run3, run]; | ||
runList.sort(sortByRunStartTimeDesc); | ||
}); | ||
it('should sort runs by start date', async () => { |
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.
Remove async and "should"?
it('should sort runs by start date', async () => { | |
it('sorts runs by start date', () => { |
} | ||
|
||
scheduledTotal(): number { | ||
getRunTotal(type: 'isActive' | 'isScheduled'): number { |
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.
getRunTotal(type: 'isActive' | 'isScheduled'): number { | |
protected getRunTotal(type: 'isActive' | 'isScheduled'): number { |
} | ||
|
||
scheduledTotal(): number { | ||
getRunTotal(type: 'isActive' | 'isScheduled'): number { | ||
let total = 0; | ||
const now = this.configService.getCurrentServerTime(); | ||
for (let run of this.filteredRuns) { |
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.
for (let run of this.filteredRuns) { | |
for (const run of this.filteredRuns) { |
@hirokiterashima Thanks, I updated with your suggestions and wrote |
Changes
Test