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

Add onClick function in the AccordionData #516

Merged
merged 4 commits into from
Oct 23, 2024
Merged

Conversation

aralovelace
Copy link
Contributor

@aralovelace aralovelace commented Oct 17, 2024

Jira Ticket Link / Motivation

WEB-4036

Summary of changes

This pull request introduces a new feature to the Accordion component, allowing custom onClick handlers for each item. Additionally, it includes changing svg files so we can change its color

New feature in Accordion component:

Version update:

How do you manually test this?

Test The Accordion component in the application

Reviewer Tasks (optional)

  • Open storybook and go to Accordion -> With Custom on Click /?path=/story/js-components-accordion--with-custom-on-click

Merge/Deploy Checklist

  • Written automated tests for implemented features/fixed bugs
  • Rebased and squashed commits
  • Commits have clear descriptions of their changes
  • Checked for any performance regressions

Frontend Checklist

  • No frontend changes in this PR
  • Added before/after screenshots for changes
  • Tested on different platforms/browsers with Browserstack
  • Compared with the initial design / our brand guidelines
  • Checked the code for accessibility issues (VoiceOver User Guide)?

Summary by CodeRabbit

  • New Features

    • Enhanced the Accordion component to support custom click handlers for each item, allowing for more interactive user experiences.
    • Introduced a new story showcasing the custom clickable functionality with an alert trigger.
  • Documentation

    • Updated documentation for the new onClick functionality in the Accordion component stories.
  • Chores

    • Updated version number in package.json to reflect the latest development changes.

@aralovelace aralovelace self-assigned this Oct 17, 2024
Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Walkthrough

The changes in this pull request enhance the functionality of the Accordion component by modifying the onClick handler for the AccordionRow component. The handler now toggles the open state and allows for a custom click function defined in the data array for each item. Additionally, a new story has been added to showcase this feature, along with a new data structure that includes an onClick property. The AccordionData type has also been updated to support this new functionality.

Changes

File Change Summary
src/core/Accordion.tsx Modified onClick handler in AccordionRow to include custom click functionality.
src/core/Accordion/Accordion.stories.tsx Added new data structure dataWithCustomClickable and a new story WithCustomOnClick.
src/core/Accordion/types.ts Introduced optional onClick property in AccordionData type.
package.json Updated version from 14.7.4 to 14.7.5.

Assessment against linked issues

Objective Addressed Explanation
Enhance Accordion functionality (WEB-4036)

Possibly related PRs

Suggested labels

review

Suggested reviewers

  • jamiehenson
  • kennethkalmer

Poem

In the forest where bunnies play,
The Accordion now has more to say.
With clicks that toggle and actions anew,
Each row can dance with a custom view!
Hop along, dear friends, and see,
How fun an accordion can truly be! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8bff1e0 and 3c8dadf.

📒 Files selected for processing (1)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json

🪧 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: 0

🧹 Outside diff range and nitpick comments (3)
src/core/Accordion/types.ts (1)

9-9: LGTM! Consider adding documentation and refining the type.

The addition of the optional onClick property to the AccordionData type is correct and aligns with the PR objectives. It allows for custom click behavior on individual accordion items without breaking existing usage.

Consider the following improvements:

  1. Add JSDoc comments to explain the purpose and usage of this new property.
  2. Consider refining the type to include an event parameter for more flexibility:
    onClick?: (event: React.MouseEvent<HTMLElement>) => void;

This would allow users to access event information if needed, while still maintaining the option to ignore it.

src/core/Accordion/Accordion.stories.tsx (2)

46-49: LGTM! Consider using a more descriptive alert message.

The new dataWithCustomClickable constant correctly extends the existing data array with a custom onClick handler, aligning with the PR objectives. This implementation allows for demonstrating custom click functionality in the Storybook.

Consider using a more descriptive alert message to better illustrate the custom click functionality:

const dataWithCustomClickable = data.map((datum, index) => ({
  ...datum,
-  onClick: () => alert("Custom onClick"),
+  onClick: () => alert(`Custom onClick for ${datum.name}`),
}));

This change would make it clearer which item was clicked in the Storybook demo.


213-226: LGTM! Consider enhancing the documentation.

The new CustomClickableButton story effectively demonstrates the custom clickable functionality for accordion items. The implementation aligns well with the PR objectives.

Consider enhancing the documentation to provide more context and guidance:

  parameters: {
    docs: {
      description: {
        story:
-          "Supplying an `onClick` function to a section adds a clickable function. This can be useful for custom actions.",
+          "Supplying an `onClick` function to a section adds a custom clickable function. This can be useful for implementing specific actions or behaviors when an accordion item is clicked. In this example, clicking an item triggers an alert, but in real-world scenarios, this could be used for navigation, data fetching, or any other custom interaction.",
      },
    },
  },

This expanded description provides more context on the feature's potential uses, which could be helpful for developers using the component.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1b5ff20 and 6c44de4.

📒 Files selected for processing (3)
  • src/core/Accordion.tsx (1 hunks)
  • src/core/Accordion/Accordion.stories.tsx (2 hunks)
  • src/core/Accordion/types.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
src/core/Accordion.tsx (1)

206-209: LGTM! Enhanced accordion item click handling.

The changes successfully implement the custom onClick handler for accordion items as per the PR objectives. The implementation:

  1. Preserves the original toggle functionality.
  2. Adds the ability to execute a custom click handler if provided.
  3. Maintains backwards compatibility by using optional chaining.

This enhancement provides greater flexibility for developers using the Accordion component, allowing for additional interactive functionality within accordion items.

src/core/Accordion/Accordion.stories.tsx (1)

Line range hint 1-226: Summary: Excellent implementation of custom click handlers for accordion items.

The changes in this file effectively implement and demonstrate the new custom click functionality for accordion items. The additions are well-integrated with the existing code structure and follow the established patterns for Storybook stories.

Key points:

  1. The new dataWithCustomClickable constant provides a clear example of how to add custom click handlers to accordion items.
  2. The CustomClickableButton story effectively showcases the new functionality.
  3. The changes align perfectly with the PR objectives of enhancing the Accordion component with custom onClick handlers.

These modifications provide developers with more flexibility in implementing interactive behaviors within the Accordion component. The Storybook demonstration will be valuable for understanding and utilizing this new feature.

Copy link
Member

@jamiehenson jamiehenson left a comment

Choose a reason for hiding this comment

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

I won't mark this as "request changes" as I won't be able to approve again for a week after this - but worth considering what you would like onClick to do on voltaire, and if anything can be passed to your function from inside Accordion to help you.

src/core/Accordion/Accordion.stories.tsx Outdated Show resolved Hide resolved
src/core/Accordion/Accordion.stories.tsx Outdated Show resolved Hide resolved
src/core/Accordion.tsx Outdated Show resolved Hide resolved
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6c44de4 and 9b02210.

⛔ Files ignored due to path filters (5)
  • src/core/icons/icon-display-chat-mono.svg is excluded by !**/*.svg
  • src/core/icons/icon-display-data-broadcast-mono.svg is excluded by !**/*.svg
  • src/core/icons/icon-display-equalisers-mono.svg is excluded by !**/*.svg
  • src/core/icons/icon-display-push-notifications-mono.svg is excluded by !**/*.svg
  • src/core/icons/icon-display-support-chat-mono.svg is excluded by !**/*.svg
📒 Files selected for processing (4)
  • package.json (1 hunks)
  • src/core/Accordion.tsx (1 hunks)
  • src/core/Accordion/Accordion.stories.tsx (2 hunks)
  • src/core/Accordion/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/core/Accordion.tsx
  • src/core/Accordion/Accordion.stories.tsx
  • src/core/Accordion/types.ts
🧰 Additional context used
🔇 Additional comments (1)
package.json (1)

Line range hint 1-145: Verify completeness of changes.

The PR objectives and AI summary mention changes to the Accordion component, including updates to its functionality and Storybook stories. However, these changes are not reflected in the package.json file.

Please ensure that all necessary changes have been included in this pull request. You may want to run the following command to check for any uncommitted changes:

#!/bin/bash
# Check for any uncommitted changes
git status --porcelain

If this command returns any output, it indicates that there are uncommitted changes that might need to be included in this PR.

package.json Outdated Show resolved Hide resolved
@aralovelace aralovelace force-pushed the Accordion_add_onClick branch 2 times, most recently from 4a225db to aa51511 Compare October 23, 2024 09:46
@aralovelace
Copy link
Contributor Author

@jamiehenson thanks Jamie, I passed an index but I do not need to pass anything so I leave it for now.

I will ask @kennethkalmer for re-review thanks

Copy link
Member

@kennethkalmer kennethkalmer left a comment

Choose a reason for hiding this comment

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

I'm grateful you took on @jamiehenson's feedback around passing something, like the index, to the onClick handler. It can be too easy on the consuming side to get confused and long for a way to disambiguate between callbacks.

@aralovelace aralovelace merged commit c7893e5 into main Oct 23, 2024
5 checks passed
@aralovelace aralovelace deleted the Accordion_add_onClick branch October 23, 2024 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants