Skip to content
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

Merged

Conversation

breity
Copy link
Member

@breity breity commented Oct 11, 2023

Changes

  • Combine functions to retrieve number of runs based on status.
  • Extract sortByStartTimeDesc() for use in both student and teacher run lists.

Test

  • Make sure student and teacher run lists load runs properly and work as before.
  • Ensure that # of runs active/running/scheduled is still calculated correctly.

- Combine functions to retrieve number of runs based on status
- Extract sortByStartTimeDesc()
@breity breity self-assigned this Oct 11, 2023
@breity breity added this to the Tech Debt 19 -> 18 milestone Oct 11, 2023
Copy link
Member

@hirokiterashima hirokiterashima left a 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.

@@ -1,14 +1,14 @@
import { waitForAsync } from '@angular/core/testing';
import { Run } from './run';
import { title } from 'process';
Copy link
Member

Choose a reason for hiding this comment

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

Unused, remove?

Suggested change
import { title } from 'process';
import { title } from 'process';

runList = [run2, run3, run];
runList.sort(sortByRunStartTimeDesc);
});
it('should sort runs by start date', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Remove async and "should"?

Suggested change
it('should sort runs by start date', async () => {
it('sorts runs by start date', () => {

}

scheduledTotal(): number {
getRunTotal(type: 'isActive' | 'isScheduled'): number {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for (let run of this.filteredRuns) {
for (const run of this.filteredRuns) {

@breity
Copy link
Member Author

breity commented Oct 11, 2023

@hirokiterashima Thanks, I updated with your suggestions and wrote getRunTotal() declaratively. Will merge.

@breity breity merged commit 360ecd4 into develop Oct 11, 2023
2 checks passed
@breity breity deleted the refactor-student-run-list-component-remove-duplication branch October 11, 2023 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants