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

574-refactor: List component #575

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

Conversation

ansivgit
Copy link
Collaborator

@ansivgit ansivgit commented Sep 29, 2024

What type of PR is this? (select all that apply)

  • πŸ• Feature
  • πŸ› Bug Fix
  • 🚧 Breaking Change
  • πŸ§‘β€πŸ’» Code Refactor
  • πŸ“ Documentation Update

Description

  • moved shared types to shared/types.ts,
  • added cva for List components' variants,
  • changed boolean prop marked to prop type, which can be 'marked', 'unmarked' or smth else,
  • added variant compact which can be used in AboutCourse component

Related Tickets & Documents

Added/updated tests?

  • πŸ‘Œ Yes
  • πŸ™…β€β™‚οΈ No, because they aren't needed
  • πŸ™‹β€β™‚οΈ No, because I need help

Summary by CodeRabbit

  • New Features

    • Introduced a new type prop for various components, replacing the previous marked prop for better clarity and functionality.
    • Added a .compact class to enhance list item styling options.
    • New type definitions for ListData and ListType to improve data handling.
  • Bug Fixes

    • Updated tests to reflect changes in prop usage for the List component.
  • Refactor

    • Streamlined component props and enhanced styling capabilities across multiple components, including List, StageCard, Stages, and StudyPath.

@ansivgit ansivgit self-assigned this Sep 29, 2024
@github-actions github-actions bot changed the title Refactor/574 list component 574-refactor: List component Sep 29, 2024
Copy link

Lighthouse Report:

  • Performance: 95 / 100
  • Accessibility: 100 / 100
  • Best Practices: 100 / 100
  • SEO: 100 / 100

View detailed report

@ansivgit ansivgit marked this pull request as ready for review October 1, 2024 11:24
Copy link

coderabbitai bot commented Oct 1, 2024

πŸ“ Walkthrough

Walkthrough

The changes involve a significant refactor of the List component and its associated types across multiple files. The marked boolean prop has been replaced with a type prop, which is a string that can be either 'marked' or 'unmarked'. This adjustment is reflected in various components, including StageCard, Stages, and StudyPath. Additionally, type definitions for ListData and ListType have been introduced in src/shared/types.ts, enhancing type safety and structure.

Changes

Files Change Summary
dev-data/courses-data.types.ts Modified import of ListData type from @/shared/ui/list to @/shared/types.
dev-data/training-program.data.tsx Updated contentMap to replace marked with type set to "unmarked" for consistency in list definitions.
src/pages/javascript-en.tsx Changed StudyPath component's prop from marked to type="marked".
src/shared/types.ts Introduced new types: ListData as an array of strings or LinkList objects and ListType as a union type of 'marked' or 'unmarked'.
src/shared/ui/list/index.ts Removed exports for ListData and ListProps, retaining only the List component.
src/shared/ui/list/list.module.scss Added a new .compact modifier class to adjust layout and spacing.
src/shared/ui/list/list.test.tsx Updated test cases to reflect changes from marked to type prop in List component.
src/shared/ui/list/list.tsx Refactored List component to use type instead of marked, updated props structure and introduced a variant system for styling.
src/widgets/study-path/ui/stage-card/stage-card.tsx Changed marked prop to type in StageCard component.
src/widgets/study-path/ui/stage-card/stage-card.types.ts Updated StageCardProps interface to replace marked with type.
src/widgets/study-path/ui/stages/stages.tsx Modified StagesProps interface and Stages component to use type instead of marked.
src/widgets/study-path/ui/study-path.tsx Updated StudyPathProps interface and StudyPath component to replace marked with type.

Assessment against linked issues

Objective Addressed Explanation
Refactor the List component for universal usage (#574) βœ…
Move types out of the component (#574) βœ…

Possibly related PRs

Suggested reviewers

  • dzmitry-varabei
  • andron13
  • natanchik
  • Quiddlee
  • SpaNb4
  • Wystov
  • KristiBo

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❀️ Share
πŸͺ§ 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.

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

@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: 2

🧹 Outside diff range and nitpick comments (8)
src/shared/types.ts (2)

3-3: ListData type definition is flexible and well-structured.

The type allows for various list data scenarios. Consider using Array<string | LinkList> instead of (string | LinkList)[] for consistency with TypeScript best practices.


5-5: ListType definition aligns with PR objectives.

The union type effectively replaces the boolean marked prop. Consider using an enum if you anticipate adding more list types in the future.

src/widgets/study-path/ui/stage-card/stage-card.types.ts (1)

19-19: StageCardProps update is on point.

The 'type' property replacement enhances flexibility. Consider adding a JSDoc comment to explain its usage.

src/shared/ui/list/list.module.scss (1)

12-19: New .compact class looks good.

The .compact class effectively reduces spacing and adjusts font size for larger screens. This aligns with the PR objectives.

Consider adding a comment explaining the purpose of the .compact class for better maintainability.

src/widgets/study-path/ui/stages/stages.tsx (1)

8-8: StagesProps interface updated.

The type prop replacement enhances component flexibility. Consider adding a JSDoc comment to explain the purpose and possible values of the type prop.

src/widgets/study-path/ui/stage-card/stage-card.tsx (1)

30-30: List component update approved.

The type prop is correctly passed to the List component. Consider adding a comment explaining the possible values of type for better clarity.

-        {list && <List data={list} type={type} />}
+        {list && <List data={list} type={type} />} {/* type can be 'marked' or 'unmarked' */}
src/widgets/study-path/ui/study-path.tsx (1)

15-15: StudyPathProps interface updated.

The marked prop has been replaced with type, aligning with PR objectives.

Consider adding a JSDoc comment to describe the type prop and its possible values.

src/shared/ui/list/list.tsx (1)

22-24: Simplify the 'unmarked' variant in listVariants

In the 'unmarked' variant, the class is set to cx(''), which returns an empty string. This might be unnecessary. You can omit the class assignment for 'unmarked' to simplify the code.

Consider changing it to:

type: {
  marked: cx('marked'),
- unmarked: cx(''),
+ unmarked: undefined,
},
πŸ“œ Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

πŸ“₯ Commits

Files that changed from the base of the PR and between 2fb40a4 and 8e36fa5.

πŸ“’ Files selected for processing (12)
  • dev-data/courses-data.types.ts (1 hunks)
  • dev-data/training-program.data.tsx (3 hunks)
  • src/pages/javascript-en.tsx (1 hunks)
  • src/shared/types.ts (1 hunks)
  • src/shared/ui/list/index.ts (1 hunks)
  • src/shared/ui/list/list.module.scss (1 hunks)
  • src/shared/ui/list/list.test.tsx (1 hunks)
  • src/shared/ui/list/list.tsx (1 hunks)
  • src/widgets/study-path/ui/stage-card/stage-card.tsx (2 hunks)
  • src/widgets/study-path/ui/stage-card/stage-card.types.ts (2 hunks)
  • src/widgets/study-path/ui/stages/stages.tsx (2 hunks)
  • src/widgets/study-path/ui/study-path.tsx (4 hunks)
πŸ”‡ Additional comments (18)
src/shared/ui/list/index.ts (1)

1-1: Export simplification approved.

The removal of type exports aligns with the refactoring goals.

Verify type relocation:

src/shared/types.ts (1)

1-1: Import statement looks good.

The import of LinkList is necessary for the ListData type definition.

src/widgets/study-path/ui/stage-card/stage-card.types.ts (1)

1-1: Import update looks good.

The addition of ListType aligns with the refactoring goals.

dev-data/courses-data.types.ts (1)

2-2: Import statement updated.

The ListData type is now imported from @/shared/types instead of @/shared/ui/list. This change aligns with the PR objective of moving type definitions out of the component.

βœ… Verification successful

Adjusting the search command for TypeScript files.

The previous rg command failed because 'typescript' is not a recognized file type. Let's retry the search by specifying the file extensions .ts and .tsx.


---

```markdown

Updating the search command for TypeScript files.

The previous rg command had an invalid type definition. Let's retry by specifying the file extensions using -g flags.


<!-- [monologue]
[task finalize_verification_1/1]
Analyzed the output of the latest rg command.
[observations]
- Found two files where `ListData` is imported from `'@/shared/types'`.
- These imports are consistent with the recent change.
[analysis]
The import statement has been successfully updated in the identified files, aligning with the PR's objective.
[actions]
- Conclude the verification process as successful.
-->

Import statement consistently updated across the codebase.

The ListData type is now correctly imported from @/shared/types in all relevant files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify consistent usage of the new import across the codebase
rg --type typescript "import.*ListData.*from '@/shared/types'" -g '!dev-data/courses-data.types.ts'

Length of output: 142


Script:

#!/bin/bash
# Verify consistent usage of the new import across the codebase by searching .ts and .tsx files
rg "import.*ListData.*from '@/shared/types'" --type-add 'ts=**/*.ts' --type-add 'tsx=**/*.tsx' --type ts --type tsx -g '!dev-data/courses-data.types.ts'

Length of output: 220


Script:

#!/bin/bash
# Verify consistent usage of the new import across .ts and .tsx files
rg "import.*ListData.*from '@/shared/types'" -g "*.ts" -g "*.tsx" -g '!dev-data/courses-data.types.ts'

Length of output: 296

src/widgets/study-path/ui/stages/stages.tsx (3)

2-2: Import added for ListType.

The new import is correctly added and uses the project's import alias convention.


11-11: Stages component signature updated.

The component signature correctly reflects the StagesProps interface change.


29-29: Prop passed to StageCard updated.

The type prop is correctly passed to StageCard. Ensure StageCard component is updated to handle this new prop.

src/widgets/study-path/ui/stage-card/stage-card.tsx (1)

20-20: Prop update approved.

The addition of the type prop aligns with the PR objectives.

src/shared/ui/list/list.test.tsx (1)

30-31: Test case updated to reflect new API.

The test now checks for 'unmarked' type instead of false 'marked' prop. This aligns with the component's refactored API.

src/pages/javascript-en.tsx (1)

25-25: Prop change looks good.

The marked prop has been correctly updated to type="marked" for the StudyPath component.

src/widgets/study-path/ui/study-path.tsx (2)

4-4: Import added for ListType.

The import is correctly placed and aligns with the PR objectives.


34-34: StudyPath component updated to use type prop.

The component signature and Stages prop have been correctly updated.

Verify that the Stages component correctly handles the new type prop:

Also applies to: 51-51

dev-data/training-program.data.tsx (6)

204-204: LGTM: Prop change aligns with refactor.

The type="unmarked" prop replaces the previous marked boolean, matching the PR's refactor objectives.


215-215: LGTM: Consistent prop change.

The type="unmarked" prop is consistently applied here, maintaining the refactor's uniformity.


227-227: LGTM: Prop change maintains consistency.

The type="unmarked" prop is applied here as well, ensuring consistency across the component usage.


232-232: LGTM: Prop change follows pattern.

The type="unmarked" prop is correctly applied, maintaining the refactor's consistency.


238-238: LGTM: Refactor successfully applied.

The type="unmarked" prop is consistently used here and throughout the file, completing the List component refactor for this course content.


Line range hint 204-238: Summary: Successful List component refactor.

The changes consistently replace the marked boolean prop with type="unmarked" throughout the 'js / front-end pre-school ru' course content. This refactor enhances the List component's flexibility and aligns with the PR's objectives.

Comment on lines +9 to +11
type ListProps = Pick<HTMLAttributes<HTMLElement>, 'className'>
& VariantProps<typeof listVariants>
& Record<'data', ListData>;
Copy link

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Consider extending additional HTML attributes for flexibility

Currently, ListProps only picks className from HTMLAttributes<HTMLElement>. Extending other HTML attributes (e.g., id, style, onClick) could enhance the component's usability.

You could adjust the type definition as follows:

-type ListProps = Pick<HTMLAttributes<HTMLElement>, 'className'>
+type ListProps = HTMLAttributes<HTMLElement>
  & VariantProps<typeof listVariants>
  & { data: ListData };
πŸ“ 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
type ListProps = Pick<HTMLAttributes<HTMLElement>, 'className'>
& VariantProps<typeof listVariants>
& Record<'data', ListData>;
type ListProps = HTMLAttributes<HTMLElement>
& VariantProps<typeof listVariants>
& { data: ListData };

Comment on lines +43 to 46
})}
data-testid="list"
>
{data.map((listItem) => {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure consistent structure for listItem when generating keys

The keyListItem is derived using listItem[0].id when listItem is not a string. This assumes that listItem is an array with the first element having an id property. To avoid potential runtime errors, ensure that this structure is consistent or adjust the key generation logic.

Consider verifying the structure of listItem or updating the key extraction:

-const keyListItem = isLink ? listItem[0].id : listItem;
+const keyListItem = isLink ? listItem.id : listItem;

Ensure that listItem has an id property when it's not a string.

Committable suggestion was skipped due to low confidence.

@@ -0,0 +1,5 @@
import { LinkList } from '@/widgets/required/required.types';

export type ListData = (string | LinkList)[] | [] | undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really ned undefined here?

export type ListData = (string | LinkList)[] | [] | undefined;
type ListProps = Pick<HTMLAttributes<HTMLElement>, 'className'>
& VariantProps<typeof listVariants>
& Record<'data', ListData>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd use { data: ListData }; instead of Record<'data', ListData> to make it more clear

Comment on lines +17 to +20
size: {
compact: cx('compact'),
medium: cx('medium'),
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really need that prop? I can't find any usage of compact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

List component refactor
5 participants