Skip to content

Conversation

@dioo1461
Copy link
Contributor

@dioo1461 dioo1461 commented Feb 17, 2025

#️⃣ 연관된 이슈>

📝 작업 내용> 이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)

  • 세그먼트 컨트롤 컴포넌트의 내부에서 Content를 정의할 수 있도록 구현을 변경했습니다.
const SegmentControlWithContent = () => (
  <SegmentControl defaultValue='라벨1' values={['라벨1', '라벨2', '라벨3']}>
    <SegmentControl.Content value='라벨1'>컨텐츠1</SegmentControl.Content>
    <SegmentControl.Content value='라벨2'>컨텐츠2</SegmentControl.Content>
    <SegmentControl.Content value='라벨3'>컨텐츠3</SegmentControl.Content>
  </SegmentControl>
);

🙏 여기는 꼭 봐주세요! > 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

Summary by CodeRabbit

  • New Features

    • Introduced new Content and ControlButton components for enhanced segmented control functionality.
    • Added a new story demonstrating segmented control with contextual content in Storybook.
  • Refactor

    • Simplified segmented control setup by transitioning from detailed option objects to straightforward value arrays.
    • Streamlined schedule filtering by removing unnecessary state management.
  • Style

    • Enhanced styling for segmented controls to improve layout and full-width content presentation.

@dioo1461 dioo1461 requested a review from hamo-o as a code owner February 17, 2025 06:11
@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces several enhancements to the segment control feature. New components, including a Content component and a ControlButton, have been added to work with a newly created SegmentControlContext. The SegmentControl component itself has been refactored to use a simpler API with a values array instead of an options object, and the related Storybook stories have been updated. Additionally, style constants have been renamed and expanded, and the UnConfirmedSchedules component has been modified to use the new segment control configuration.

Changes

File(s) Change Summary
frontend/.../SegmentControl/Content.tsx
frontend/.../SegmentControl/ControlButton.tsx
frontend/.../SegmentControl/SegmentControlContext.ts
Added new components (Content, ControlButton) and a new context. The Content component conditionally renders based on the context’s selected value, and ControlButton manages selection using the context’s handler.
frontend/.../SegmentControl/index.tsx
frontend/.../SegmentControl/index.css.ts
frontend/.../SegmentControl/SegmentControl.stories.tsx
Refactored the main SegmentControl API by replacing the options prop with a values array, renaming onChange to onValueChange, and adopting a Flex layout. Styling constants were renamed/added, and Storybook stories were updated (including the addition of a new WithContent story).
frontend/.../UnConfirmedSchedules/index.tsx Updated the segment control usage by replacing object-based segment options with a simpler values array and removing extra state management, relying on default properties instead.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CB as ControlButton
    participant SC as SegmentControlContext
    participant C as Content
    U->>CB: Click on button
    CB->>SC: Invoke handleSelect(value)
    SC->>C: Update selectedValue in context
    C-->>U: Conditionally render content if value matches
Loading

Suggested labels

🖥️ FE

Suggested reviewers

  • hamo-o

Poem

I'm a bunny hopping with delight,
New controls and context shining bright.
Buttons leap and content appears,
With each click, the magic clears.
Code carrots crunch in rhythm and rhyme,
Celebrating changes, one hop at a time!
🐰✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e480558 and c2c9ffd.

📒 Files selected for processing (2)
  • frontend/src/components/SegmentControl/ControlButton.tsx (1 hunks)
  • frontend/src/components/SegmentControl/index.tsx (1 hunks)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

@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 (3)
frontend/src/components/SegmentControl/index.tsx (1)

10-16: Consider validating empty values.

If values is empty, defaultValue becomes an empty string. This might cause unexpected behavior (e.g., no button is selected). You could display a fallback or throw an error to ensure a functional SegmentControl.

 export interface SegmentControlProps extends PropsWithChildren {
   values: string[];
   style?: 'weak' | 'filled';
   shadow?: boolean;
   defaultValue?: string;
   onValueChange?: (value: string) => void;
 };
 
+// Consider adding a runtime check or fallback
+// if (!values?.length) {
+//   throw new Error("SegmentControl requires a non-empty 'values' array.");
+// }
frontend/src/components/SegmentControl/SegmentControlContext.ts (1)

8-8: Initialized context with null default.

This is a common pattern, ensures consumers can handle a null context if unwrapped incorrectly. Consider using a safer approach that warns if context is used without a provider.

frontend/src/components/SegmentControl/Content.tsx (1)

9-24: Conditional content rendering is clean and extensible.

• The Content component gracefully renders children only if selectedValue === value.
• Using the local context ensures a straightforward user experience.
• Consider adding a test case to ensure correct behavior when multiple Content components appear with different values.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 28a3027 and e480558.

📒 Files selected for processing (7)
  • frontend/src/components/SegmentControl/Content.tsx (1 hunks)
  • frontend/src/components/SegmentControl/ControlButton.tsx (1 hunks)
  • frontend/src/components/SegmentControl/SegmentControl.stories.tsx (1 hunks)
  • frontend/src/components/SegmentControl/SegmentControlContext.ts (1 hunks)
  • frontend/src/components/SegmentControl/index.css.ts (2 hunks)
  • frontend/src/components/SegmentControl/index.tsx (1 hunks)
  • frontend/src/features/shared-schedule/ui/UnConfirmedSchedules/index.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Send PR Notification to Reviewers
🔇 Additional comments (18)
frontend/src/components/SegmentControl/index.tsx (6)

1-1: Good use of PropsWithChildren.

Using PropsWithChildren clarifies that this component can wrap child elements, making the component flexible and self-contained.


4-8: Imports look appropriate and consistent.

All imported modules are relevant for layout, context, and styling. No issues found.


19-24: Destructure props carefully.

The usage of defaultValue = values[0] ?? '' is neat, but see the earlier suggestion about validating values. Otherwise, this is a clean and idiomatic approach.


30-30: Optional callback usage looks correct.

onValueChange?.(value) is a safe optional call that prevents errors if no callback is passed.


34-53: Good usage of context and composition.

Providing selectedValue and handleSelect through a context fosters an extendable design. Rendering buttons and children inside a <Flex> container is straightforward.


57-57: Attaching Content as a static property.

Exporting SegmentControl.Content is a convenient approach to nest related components. This pattern might be less discoverable for some developers, but it’s a neat pattern for your library.

frontend/src/components/SegmentControl/SegmentControlContext.ts (2)

1-1: Context creation is straightforward.

createContext is correctly imported from React. No issues here.


3-6: Context props nicely typed.

Defining selectedValue and handleSelect on the context makes the API clear.

frontend/src/components/SegmentControl/Content.tsx (1)

1-7: Imports align with usage needs.

PropsWithChildren, custom useSafeContext hook, and local utilities/styles are properly imported.

frontend/src/components/SegmentControl/index.css.ts (2)

6-30: LGTM! Clear and descriptive style name.

The rename from segmentControlContainer to controlButtonContainerStyle better reflects the style's purpose and improves code readability.


32-34: LGTM! Simple and effective content style.

The contentContainerStyle with width: '100%' ensures content spans the full width of its container.

frontend/src/components/SegmentControl/SegmentControl.stories.tsx (2)

20-25: LGTM! Simplified API with direct values.

The Default story now uses a simpler values array instead of complex options objects, making the API more intuitive.


27-33: LGTM! Clear demonstration of content functionality.

The WithContent story effectively demonstrates how to define content within the segment control, aligning with the PR objectives.

frontend/src/features/shared-schedule/ui/UnConfirmedSchedules/index.tsx (2)

10-10: LGTM! Clean implementation of the new SegmentControl API.

The component has been updated to use the simplified SegmentControl API with direct values and defaultValue.

Also applies to: 22-22


12-12: Verify the empty schedule objects.

The schedules array contains empty objects which might indicate incomplete implementation or placeholder data.

Could you clarify if this is intentional or if it needs to be updated with actual schedule data?

frontend/src/components/SegmentControl/ControlButton.tsx (3)

7-11: LGTM! Clear and typed props interface.

The ControlButtonProps interface clearly defines the required and optional props.


13-33: LGTM! Well-structured component with proper event handling.

The component effectively uses context and handles click events. The button styling is appropriately configured.


35-39: LGTM! Clean and maintainable style selection logic.

The getButtonStyle function provides a clear and maintainable way to determine button styles based on selection state.

const ControlButton = ({
value,
segmentControlStyle,
key,
Copy link
Contributor

Choose a reason for hiding this comment

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

p2; key 삭제좀요

@dioo1461 dioo1461 merged commit 809eff5 into dev Feb 17, 2025
1 check was pending
@dioo1461 dioo1461 deleted the feature/fe/segment-control branch February 17, 2025 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🖥️ FE Frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants