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

fix: Card items overflow out of cards #2658

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

Wassaf001
Copy link

@Wassaf001 Wassaf001 commented Feb 17, 2025

Checklist:

  • I've thoroughly self-reviewed my changes
  • I've added tests for my changes, unless they affect admin-only areas (or are otherwise not worth testing)
  • I've verified any visual changes using Percy (add a commit with [percy] in the message to trigger)

Summary by CodeRabbit

  • New Features
    • The course progress display has been enhanced to show a refined selection of items. Now, users will see up to five courses in a prioritized order that highlights completion status along with the most recent activity for a cleaner, more focused overview.

Copy link
Contributor

coderabbitai bot commented Feb 17, 2025

Walkthrough

The changes update the course progress list component by modifying its data source. The Handlebars template now iterates over a new computed property languagesToDisplay instead of @courseParticipations. The component logic is enhanced with a new constant MAX_LANGUAGES_TO_DISPLAY and a computed getter that sorts and combines completed and incomplete course participations based on dates before limiting the results.

Changes

File(s) Change Summary
app/components/user-page/course-progress-list-item/index.hbs Updated iteration source from @courseParticipations to this.languagesToDisplay.
app/components/user-page/course-progress-list-item/index.js Added constant MAX_LANGUAGES_TO_DISPLAY = 5 and a computed property languagesToDisplay that sorts and combines completed and incomplete participations based on date thresholds.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant T as Template (index.hbs)
    participant C as Component (index.js)
    participant D as Data (Course Participations)

    T ->> C: Request languagesToDisplay for rendering
    C ->> D: Retrieve completed participations
    D -->> C: Return completed items
    C ->> D: Retrieve incomplete participations
    D -->> C: Return incomplete items
    C ->> C: Sort completed by completion date (desc)
    C ->> C: Sort incomplete by last submission date (desc)
    C ->> C: Combine items based on MAX_LANGUAGES_TO_DISPLAY
    C -->> T: Provide languagesToDisplay array

Suggested reviewers

  • rohitpaulk

Poem

I'm a rabbit with a joyful leap,
Hopping through code changes that we keep.
Sorting languages, both new and old,
Displaying progress in stories told.
A hop, a skip—our code now shines in gold! 🐇🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 5013e3c and 4200900.

📒 Files selected for processing (1)
  • app/components/user-page/course-progress-list-item/index.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/components/user-page/course-progress-list-item/index.js

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
tests/acceptance/view-user-profile-test.js (1)

57-140: Consider extracting test data setup.

The test data setup with multiple course participations is quite lengthy and repetitive. Consider extracting this into a helper function or fixture.

Example refactor:

function createCourseParticipation(server, { course, language, user, completedAt, completedStageSlugs, lastSubmissionAt }) {
  return server.create('course-participation', {
    course,
    language,
    user,
    ...(completedAt && { completedAt }),
    ...(completedStageSlugs && { completedStageSlugs }),
    ...(lastSubmissionAt && { lastSubmissionAt })
  });
}

Then use it like:

const baseDate = new Date('2021-10-10');
const languages = ['cpp', 'java', 'javascript'].map(slug => 
  this.server.schema.languages.findBy({ slug })
);

languages.forEach(language => 
  createCourseParticipation(this.server, {
    course: redis,
    language,
    user: currentUser,
    completedStageSlugs: redis.stages.models.sortBy('position').slice(0, 5).mapBy('slug'),
    lastSubmissionAt: baseDate
  })
);
🧰 Tools
🪛 ESLint

[error] 119-119: Delete ····

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94e0385 and 3e35e62.

📒 Files selected for processing (3)
  • app/components/user-page/course-progress-list-item/index.hbs (1 hunks)
  • app/helpers/limit-array.ts (1 hunks)
  • tests/acceptance/view-user-profile-test.js (3 hunks)
🧰 Additional context used
🪛 ESLint
app/helpers/limit-array.ts

[error] 3-3: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 5-5: Insert

(prettier/prettier)

tests/acceptance/view-user-profile-test.js

[error] 33-33: 'objectivec' is assigned a value but never used.

(no-unused-vars)


[error] 34-34: 'scala' is assigned a value but never used.

(no-unused-vars)


[error] 35-35: 'shell' is assigned a value but never used.

(no-unused-vars)


[error] 36-36: 'elixir' is assigned a value but never used.

(no-unused-vars)


[error] 119-119: Delete ····

(prettier/prettier)


[error] 187-187: Do not commit pauseTest()

(ember/no-pause-test)

🔇 Additional comments (1)
app/components/user-page/course-progress-list-item/index.hbs (1)

48-48: LGTM! Effectively limits course participation display.

The change successfully addresses the card items overflow issue by limiting the display to 3 items.

@rohitpaulk
Copy link
Member

@ryan-gang could you review this please?

@rohitpaulk rohitpaulk requested a review from ryan-gang February 21, 2025 02:40
@@ -45,7 +45,7 @@
{{/if}}

<div class="flex items-center space-x-1.5">
{{#each @courseParticipations as |courseParticipation|}}
{{#each (limit-array @courseParticipations 3) as |courseParticipation|}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @Wassaf001, I don't think just limiting the participations here will work as expected.

We want all these constraints to hold:

  • The list of languages should always show the languages in which the participations are Completed (Max 5, if more than 5 take the 5 most recently active ones).
  • The list of languages should then add languages with participations which are incomplete, to bring the total count to maximum 5.
  • Completed languages should come first.
  • Incomplete ones, should be sorted by activity date. (recent ones first).

I think defining a function in app/components/user-page/course-progress-list-item/index.js which accepts courseParticipations and returns this filtered and sorted list to render would be okay.

We do something similar in app/components/user-page/course-progress-list.ts which you can take a look at.

Copy link
Author

Choose a reason for hiding this comment

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

okay thank you, will try it.

@ryan-gang
Copy link
Contributor

Hey @Wassaf001 you can take a look at this PR.
#2705
You can work on top of that if you wish.

@Wassaf001
Copy link
Author

ok will do it at earliest just wait till Sunday.

@Wassaf001
Copy link
Author

I am trying to pause the test using : await pauseTest(); but it won't work as expected, before it was working fine.

Any guidance please.

@Wassaf001
Copy link
Author

it is working using module filter on tests page

@Wassaf001
Copy link
Author

done, if any changes required let me know

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (3)
tests/acceptance/view-user-profile-test.js (3)

35-38: 🛠️ Refactor suggestion

Remove unused language variables.

The following language variables are declared but never used:

  • objectivec
  • scala
  • shell
  • elixir

Remove these unused variables to keep the code clean.

🧰 Tools
🪛 ESLint

[error] 35-35: 'objectivec' is assigned a value but never used.

(no-unused-vars)


[error] 36-36: 'scala' is assigned a value but never used.

(no-unused-vars)


[error] 37-37: 'shell' is assigned a value but never used.

(no-unused-vars)


[error] 38-38: 'elixir' is assigned a value but never used.

(no-unused-vars)


186-186: ⚠️ Potential issue

Remove debugging pause.

The pauseTest() call should not be committed as it will pause the test execution.

-    await this.pauseTest();
🧰 Tools
🪛 ESLint

[error] 186-186: Do not commit pauseTest()

(ember/no-pause-test)


6-6: 🛠️ Refactor suggestion

Import pauseTest only when needed for debugging.

The pauseTest import is used for debugging but shouldn't be in committed code.

-import { currentURL, pauseTest } from '@ember/test-helpers';
+import { currentURL } from '@ember/test-helpers';
🧰 Tools
🪛 ESLint

[error] 6-6: 'pauseTest' is defined but never used.

(no-unused-vars)

🧹 Nitpick comments (4)
app/components/user-page/course-progress-list-item/index.js (3)

39-44: Fix whitespace formatting.

There's an unnecessary line break after the @action decorator.

@action
-

navigateToCourse() {
🧰 Tools
🪛 ESLint

[error] 40-41: Delete

(prettier/prettier)


[error] 44-44: Delete ··

(prettier/prettier)


45-62: Well-implemented languagesToDisplay method to solve overflow issue.

The implementation effectively limits card items to prevent overflow by:

  1. Prioritizing completed courses by most recent completion date
  2. Adding incomplete courses sorted by recent activity when needed
  3. Capping the total number of displayed items to 5

However, there are some formatting issues to fix:

get languagesToDisplay() {
  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(),
  );

  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 (completedParticipations.length >= MAX_LANGUAGES_TO_DISPLAY) {
    return completedParticipations.slice(0, MAX_LANGUAGES_TO_DISPLAY);
  }

-  return [
-    ...completedParticipations,
-    ...incompleteParticipations.slice(0, MAX_LANGUAGES_TO_DISPLAY - completedParticipations.length)
-  ];
+  return [...completedParticipations, ...incompleteParticipations.slice(0, MAX_LANGUAGES_TO_DISPLAY - completedParticipations.length)];
}
🧰 Tools
🪛 ESLint

[error] 45-62: Member languagesToDisplay should be declared before all method definitions.

(@typescript-eslint/member-ordering)


[error] 47-47: Insert ,

(prettier/prettier)


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

(prettier/prettier)


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

(prettier/prettier)


45-62: Consider updating member ordering.

According to the static analysis tool, the languagesToDisplay getter should be declared before method definitions.

Move this getter before the navigateToCourse method to follow the project's style guidelines.

🧰 Tools
🪛 ESLint

[error] 45-62: Member languagesToDisplay should be declared before all method definitions.

(@typescript-eslint/member-ordering)


[error] 47-47: Insert ,

(prettier/prettier)


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

(prettier/prettier)


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

(prettier/prettier)

tests/acceptance/view-user-profile-test.js (1)

56-140: Consider simplifying test setup by reducing redundant course participations.

While adding multiple course participations helps test the fix for card overflow, there's a lot of repetitive code. Consider using a loop or helper function to create these test entries.

// Example of a more concise approach
const languages = ['cpp', 'java', 'javascript', 'haskell', 'c', 'rust', 'ruby'];
languages.forEach(langSlug => {
  const language = this.server.schema.languages.findBy({ slug: langSlug });
  this.server.create('course-participation', {
    course: redis,
    language: language,
    user: currentUser,
    completedStageSlugs: redis.stages.models.sortBy('position').slice(0, 5).mapBy('slug'),
    lastSubmissionAt: new Date('2021-10-10'),
  });
});

// Then create the completed ones separately
const completedLanguages = [
  { slug: 'php', date: '2020-01-01' },
  { slug: 'typescript', date: '2021-10-10' },
  { slug: 'kotlin', date: '2021-10-11' }
];
completedLanguages.forEach(item => {
  const language = this.server.schema.languages.findBy({ slug: item.slug });
  this.server.create('course-participation', {
    course: redis,
    language: language,
    user: currentUser,
    completedAt: new Date(item.date),
  });
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64cfbc3 and e9b41e5.

📒 Files selected for processing (3)
  • app/components/user-page/course-progress-list-item/index.hbs (1 hunks)
  • app/components/user-page/course-progress-list-item/index.js (2 hunks)
  • tests/acceptance/view-user-profile-test.js (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/components/user-page/course-progress-list-item/index.hbs
🧰 Additional context used
🪛 ESLint
app/components/user-page/course-progress-list-item/index.js

[error] 40-41: Delete

(prettier/prettier)


[error] 44-44: Delete ··

(prettier/prettier)


[error] 45-62: Member languagesToDisplay should be declared before all method definitions.

(@typescript-eslint/member-ordering)


[error] 47-47: Insert ,

(prettier/prettier)


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

(prettier/prettier)


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

(prettier/prettier)


[error] 62-63: Delete

(prettier/prettier)

tests/acceptance/view-user-profile-test.js

[error] 6-6: 'pauseTest' is defined but never used.

(no-unused-vars)


[error] 35-35: 'objectivec' is assigned a value but never used.

(no-unused-vars)


[error] 36-36: 'scala' is assigned a value but never used.

(no-unused-vars)


[error] 37-37: 'shell' is assigned a value but never used.

(no-unused-vars)


[error] 38-38: 'elixir' is assigned a value but never used.

(no-unused-vars)


[error] 186-186: Do not commit pauseTest()

(ember/no-pause-test)

🔇 Additional comments (1)
app/components/user-page/course-progress-list-item/index.js (1)

6-6: Good implementation of MAX_LANGUAGES_TO_DISPLAY constant.

This is a good approach to limit the number of language cards shown, which helps prevent card items from overflowing.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/acceptance/view-user-profile-test.js (1)

24-24: Remove unnecessary whitespace.

This empty line with whitespace should be removed.

-  
🧰 Tools
🪛 ESLint

[error] 24-24: Delete ··

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9b41e5 and 98b72f5.

📒 Files selected for processing (1)
  • tests/acceptance/view-user-profile-test.js (2 hunks)
🧰 Additional context used
🪛 ESLint
tests/acceptance/view-user-profile-test.js

[error] 6-6: 'pauseTest' is defined but never used.

(no-unused-vars)


[error] 24-24: Delete ··

(prettier/prettier)

@ryan-gang
Copy link
Contributor

Linter is failing, can you also revert all changes done to tests/acceptance/view-user-profile-test.js ?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/acceptance/view-user-profile-test.js (1)

253-253: Code Formatting: Insert Newline at End of File

Static analysis (prettier) suggests that a newline should be added at the end of the file to satisfy formatting standards. This will help prevent editor or CI warnings regarding end-of-file newlines.

A possible diff to resolve this:

-  });
-}
+  });
+}
+
🧰 Tools
🪛 ESLint

[error] 253-253: Insert

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98b72f5 and 5013e3c.

📒 Files selected for processing (1)
  • tests/acceptance/view-user-profile-test.js (1 hunks)
🧰 Additional context used
🪛 ESLint
tests/acceptance/view-user-profile-test.js

[error] 253-253: Insert

(prettier/prettier)

@Wassaf001
Copy link
Author

Is there anything else, I need to do? Why is the linter taking so long to show results.

@Wassaf001 Wassaf001 requested a review from ryan-gang March 5, 2025 19:23
@ryan-gang
Copy link
Contributor

@Wassaf001 CI jobs won't run without approval from members with write access.
You can just run it locally: npm run lint:fix.

@Wassaf001
Copy link
Author

@Wassaf001 CI jobs won't run without approval from members with write access. You can just run it locally: npm run lint:fix.

ok understood

@ryan-gang
Copy link
Contributor

Copy link
Contributor

@ryan-gang ryan-gang left a comment

Choose a reason for hiding this comment

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

Lint is still failing.

@Wassaf001
Copy link
Author

Fixed It. Please check.
Screenshot 2025-03-11 at 1 04 53 AM

@Wassaf001 Wassaf001 requested a review from ryan-gang March 16, 2025 11:22
@Wassaf001
Copy link
Author

Why are the tests failing? Please guide me on what to do next.

@ryan-gang
Copy link
Contributor

This is an issue with Codecov on forked repos, will have to update our CI tests to accommodate for this.
Once I fix the CI, (hopefully this week), will review.

@ryan-gang ryan-gang removed their request for review March 26, 2025 07:49
@Wassaf001
Copy link
Author

ok thank you

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.

3 participants