Skip to content

feat(profile): limit language logos to 5 in course progress items #2705

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{{/if}}

<div class="flex items-center space-x-1.5">
{{#each @courseParticipations as |courseParticipation|}}
{{#each this.languagesToDisplay as |courseParticipation|}}
{{#if courseParticipation.isCompleted}}
<LanguageLogo @language={{courseParticipation.language}} @variant="teal" class="h-4" />
{{else}}
Expand Down
25 changes: 25 additions & 0 deletions app/components/user-page/course-progress-list-item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import { action } from '@ember/object';
import { inject as service } from '@ember/service';

const MAX_LANGUAGES_TO_DISPLAY = 5;

export default class CourseProgressListItemComponent extends Component {
@service router;

Expand Down Expand Up @@ -34,6 +36,29 @@
}
}

get languagesToDisplay() {
// First, get all completed course participations sorted by completion time (most recent first)
const completedParticipations = this.completedCourseParticipations.sort(
(a, b) => new Date(b.completedAt).getTime() - new Date(a.completedAt).getTime()
);

Check warning on line 43 in app/components/user-page/course-progress-list-item/index.js

View check run for this annotation

Codecov / codecov/patch

app/components/user-page/course-progress-list-item/index.js#L43

Added line #L43 was not covered by tests

// Next, get incomplete participations sorted by activity time (most recent first)
const incompleteParticipations = this.args.courseParticipations
.filter(p => !p.isCompleted)
.sort((a, b) => new Date(b.lastSubmissionAt).getTime() - new Date(a.lastSubmissionAt).getTime());

// If we have 5 or fewer completed participations, show all of them
if (completedParticipations.length >= MAX_LANGUAGES_TO_DISPLAY) {
return completedParticipations.slice(0, MAX_LANGUAGES_TO_DISPLAY);
}

Check warning on line 53 in app/components/user-page/course-progress-list-item/index.js

View check run for this annotation

Codecov / codecov/patch

app/components/user-page/course-progress-list-item/index.js#L53

Added line #L53 was not covered by tests

// Otherwise, show all completed participations + recent incomplete ones (up to 5 total)
return [
...completedParticipations,
...incompleteParticipations.slice(0, MAX_LANGUAGES_TO_DISPLAY - completedParticipations.length)
];
}
Comment on lines +39 to +60
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Implementation correctly satisfies all requirements, but has formatting issues

The implementation correctly:

  1. Prioritizes completed languages
  2. Sorts by recency (completion date or last submission date)
  3. Displays incomplete languages if fewer than 5 completed ones exist

However, there are some formatting issues flagged by ESLint that should be fixed.

  get languagesToDisplay() {
    // First, get all completed course participations sorted by completion time (most recent first)
    const completedParticipations = this.completedCourseParticipations.sort(
-      (a, b) => new Date(b.completedAt).getTime() - new Date(a.completedAt).getTime()
+      (a, b) => new Date(b.completedAt).getTime() - new Date(a.completedAt).getTime(),
    );
    
    // Next, get incomplete participations sorted by activity time (most recent first)
    const incompleteParticipations = this.args.courseParticipations
-      .filter(p => !p.isCompleted)
+      .filter((p) => !p.isCompleted)
      .sort((a, b) => new Date(b.lastSubmissionAt).getTime() - new Date(a.lastSubmissionAt).getTime());
    
    // If we have 5 or fewer completed participations, show all of them
    if (completedParticipations.length >= MAX_LANGUAGES_TO_DISPLAY) {
      return completedParticipations.slice(0, MAX_LANGUAGES_TO_DISPLAY);
    }
    
    // Otherwise, show all completed participations + recent incomplete ones (up to 5 total)
-    return [
-      ...completedParticipations,
-      ...incompleteParticipations.slice(0, MAX_LANGUAGES_TO_DISPLAY - completedParticipations.length)
-    ];
+    return [...completedParticipations, ...incompleteParticipations.slice(0, MAX_LANGUAGES_TO_DISPLAY - completedParticipations.length)];
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
get languagesToDisplay() {
// First, get all completed course participations sorted by completion time (most recent first)
const completedParticipations = this.completedCourseParticipations.sort(
(a, b) => new Date(b.completedAt).getTime() - new Date(a.completedAt).getTime()
);
// Next, get incomplete participations sorted by activity time (most recent first)
const incompleteParticipations = this.args.courseParticipations
.filter(p => !p.isCompleted)
.sort((a, b) => new Date(b.lastSubmissionAt).getTime() - new Date(a.lastSubmissionAt).getTime());
// If we have 5 or fewer completed participations, show all of them
if (completedParticipations.length >= MAX_LANGUAGES_TO_DISPLAY) {
return completedParticipations.slice(0, MAX_LANGUAGES_TO_DISPLAY);
}
// Otherwise, show all completed participations + recent incomplete ones (up to 5 total)
return [
...completedParticipations,
...incompleteParticipations.slice(0, MAX_LANGUAGES_TO_DISPLAY - completedParticipations.length)
];
}
get languagesToDisplay() {
// First, get all completed course participations sorted by completion time (most recent first)
const completedParticipations = this.completedCourseParticipations.sort(
(a, b) => new Date(b.completedAt).getTime() - new Date(a.completedAt).getTime(),
);
// Next, get incomplete participations sorted by activity time (most recent first)
const incompleteParticipations = this.args.courseParticipations
.filter((p) => !p.isCompleted)
.sort((a, b) => new Date(b.lastSubmissionAt).getTime() - new Date(a.lastSubmissionAt).getTime());
// If we have 5 or fewer completed participations, show all of them
if (completedParticipations.length >= MAX_LANGUAGES_TO_DISPLAY) {
return completedParticipations.slice(0, MAX_LANGUAGES_TO_DISPLAY);
}
// Otherwise, show all completed participations + recent incomplete ones (up to 5 total)
return [...completedParticipations, ...incompleteParticipations.slice(0, MAX_LANGUAGES_TO_DISPLAY - completedParticipations.length)];
}
🧰 Tools
🪛 ESLint

[error] 42-42: Insert ,

(prettier/prettier)


[error] 44-44: Delete ····

(prettier/prettier)


[error] 47-47: Replace p with (p)

(prettier/prettier)


[error] 49-49: Delete ····

(prettier/prettier)


[error] 54-54: Delete ····

(prettier/prettier)


[error] 56-59: Replace ⏎······...completedParticipations,⏎······...incompleteParticipations.slice(0,·MAX_LANGUAGES_TO_DISPLAY·-·completedParticipations.length)⏎···· with ...completedParticipations,·...incompleteParticipations.slice(0,·MAX_LANGUAGES_TO_DISPLAY·-·completedParticipations.length)

(prettier/prettier)


@action
navigateToCourse() {
this.router.transitionTo('course-overview', this.course.slug);
Expand Down
Loading