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

Default social input send behavior #199

Merged
merged 2 commits into from
Feb 14, 2025

Conversation

Ronan-Fernandes
Copy link
Contributor

@Ronan-Fernandes Ronan-Fernandes commented Jan 28, 2025

Acceptance Criteria

Customize the component so that future devs can have more freedom to create a custom behavior for sending the message using the keyboard.

Change the default behavior of the current component to be:

Given I am writing a message, when I hit the Enter Key, it should create a line break in the text where I can keep writing.

Given I am writing a message, when I hit CTRL + Enter, then it should send the message I have input.

Update storybook to include this new behavior.

Summary by CodeRabbit

  • New Features

    • Enhanced the SocialInput component by introducing an optional keydown handler prop, allowing for custom keyboard event handling. Default behavior now triggers submission on CTRL + Enter.
  • Documentation

    • Revised component documentation and examples to include the new onKeyDown prop and its updated keyboard interaction details.
  • Style

    • Improved formatting of comments and parameters in the GraphQL schema for better readability and consistency.
  • Chores

    • Updated package version to 1.0.7 in the components package changelog and package.json.

Copy link

changeset-bot bot commented Jan 28, 2025

⚠️ No Changeset found

Latest commit: ef5468e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

coderabbitai bot commented Jan 28, 2025

Walkthrough

The changes introduce a new optional property, onKeyDown, to the SocialInput component. The component’s keyboard event handling has been refactored: the old handleKeyDown function was replaced by a new defaultKeyDown that triggers submission when CTRL+Enter is pressed. The documentation has been updated to include this new prop and its usage examples. The associated type definitions have also been enhanced by adding the new event handler property.

Changes

File(s) Change Summary
packages/components/…/SocialInput/__storybook__/SocialInput.mdx Updated documentation to add the optional onKeyDown prop, including an example usage with the default CTRL+Enter behavior.
packages/components/…/SocialInput/index.tsx and packages/components/…/SocialInput/types.ts Refactored keydown event handling by replacing handleKeyDown with defaultKeyDown; introduced the onKeyDown prop for custom handling; updated type definitions to include KeyboardEvent.
packages/components/…/SocialInput/types.ts Added onKeyDown property to SocialInputProps interface and updated import statement to include KeyboardEvent.
packages/components/schema.graphql Reformatted multi-line comments to single-line comments for clarity; adjusted parameter listings to single line for consistency without functional changes.
packages/components/CHANGELOG.md Added version 1.0.7 to CHANGELOG, noting the introduction of the onKeyDown handler prop to the SocialInput component.
packages/components/package.json Updated package version from "1.0.6" to "1.0.7".

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant SI as SocialInput Component
    participant D as DefaultKeyDown Logic
    U->>+SI: Keydown event (e.g., "Enter" or CTRL+Enter)
    SI-->>SI: Check for custom onKeyDown prop
    alt Custom Handler Provided
        SI->>Custom: Execute provided onKeyDown(event)
    else No Custom Handler
        SI->>+D: Call defaultKeyDown(event)
        D-->>-SI: Process event (CTRL+Enter triggers submission)
    end
    SI-->>-U: Return event feedback/result
Loading

Suggested reviewers

  • anicioalexandre
  • deboracosilveira

Poem

I’m a rabbit in codeland, hopping with glee,
Adding keydown magic for all to see.
CTRL+Enter now makes the submission bright,
Custom actions spring forth in the light.
With carrots and code, I'm dancing tonight!
🥕🐇 Happy hopping in a code delight!

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/components/modules/__shared__/web/SocialInput/index.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /packages/components/.eslintrc.js
Error: Cannot find module '@baseapp-frontend/config/.eslintrc-with-restricted-paths.js'
Require stack:

  • /packages/components/.eslintrc.js
  • /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/packages/components/.eslintrc.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
packages/components/schema.graphql

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /packages/components/.eslintrc.js
Error: Cannot find module '@baseapp-frontend/config/.eslintrc-with-restricted-paths.js'
Require stack:

  • /packages/components/.eslintrc.js
  • /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/packages/components/.eslintrc.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
packages/components/modules/__shared__/web/SocialInput/types.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /packages/components/.eslintrc.js
Error: Cannot find module '@baseapp-frontend/config/.eslintrc-with-restricted-paths.js'
Require stack:

  • /packages/components/.eslintrc.js
  • /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/packages/components/.eslintrc.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)

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.

@Ronan-Fernandes Ronan-Fernandes self-assigned this Jan 28, 2025
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: 1

🧹 Nitpick comments (2)
packages/components/modules/__shared__/SocialInput/index.tsx (1)

97-97: Consider adding error boundaries around form submission.

While the implementation is correct, consider wrapping the form submission in a try-catch block to handle potential errors gracefully.

   const defaultKeyDown: KeyboardEventHandler<HTMLDivElement> = (event) => {
     if (event.key === 'Enter' && event.ctrlKey) {
       event.preventDefault()
-      form.handleSubmit(submit)(event)
+      try {
+        form.handleSubmit(submit)(event)
+      } catch (error) {
+        console.error('Failed to submit form:', error)
+      }
     }
   }
packages/components/modules/__shared__/SocialInput/__storybook__/SocialInput.mdx (1)

33-33: Enhance prop documentation with more details.

While the documentation mentions the default behavior, it would be helpful to explicitly state:

  • The default behavior uses CTRL+Enter to send messages
  • Enter alone creates a new line
  • How to override the default behavior
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c11c03 and 17b049b.

⛔ Files ignored due to path filters (3)
  • packages/components/__generated__/ActivityLogsFragment.graphql.ts is excluded by !**/__generated__/**
  • packages/components/__generated__/ActivityLogsPaginationQuery.graphql.ts is excluded by !**/__generated__/**
  • packages/components/__generated__/ActivityLogsQuery.graphql.ts is excluded by !**/__generated__/**
📒 Files selected for processing (3)
  • packages/components/modules/__shared__/SocialInput/__storybook__/SocialInput.mdx (2 hunks)
  • packages/components/modules/__shared__/SocialInput/index.tsx (3 hunks)
  • packages/components/modules/__shared__/SocialInput/types.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/components/modules/__shared__/SocialInput/types.ts (1)

18-18: LGTM! Well-typed optional prop addition.

The onKeyDown prop is correctly typed as an optional handler for keyboard events, maintaining backward compatibility while providing type safety.

packages/components/modules/__shared__/SocialInput/index.tsx (1)

82-86: LGTM! Clean implementation of CTRL+Enter behavior.

The defaultKeyDown handler correctly implements the new message sending behavior:

  • Checks for both Enter key and CTRL modifier
  • Prevents default event to avoid unwanted line breaks
  • Properly triggers form submission

Copy link
Collaborator

@tsl-ps2 tsl-ps2 left a comment

Choose a reason for hiding this comment

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

Would it make sense to expose form data or at least the submit method to the onKeyDown handler? Suppose I want to customize the behavior on the template and switch back to sending messages when pressing enter. How would I do that? With the current code, if I try to write an onKeyDown handler on the template, I only get access to the event, but not the current form or any other social input variables. So I cannot really do anything except for stopping the event from propagating, right? (Triggering some other event or changing the event variables so that this new event does what I want sounds like a really bad hack.)

@Ronan-Fernandes Ronan-Fernandes force-pushed the BA-2197-fe-social-input-heydown-behavior branch from 17b049b to 6346d75 Compare February 12, 2025 20:08
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: 1

🧹 Nitpick comments (1)
packages/components/modules/__shared__/web/SocialInput/index.tsx (1)

82-87: Add JSDoc for the defaultKeyDown function.

The function implementation is correct, but adding documentation would improve maintainability.

+    /**
+     * Default keyboard event handler that submits the form when CTRL + Enter is pressed.
+     * @param event - The keyboard event
+     */
     const defaultKeyDown: KeyboardEventHandler<HTMLDivElement> = (event) => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 17b049b and 6346d75.

📒 Files selected for processing (3)
  • packages/components/modules/__shared__/web/SocialInput/__storybook__/SocialInput.mdx (2 hunks)
  • packages/components/modules/__shared__/web/SocialInput/index.tsx (3 hunks)
  • packages/components/modules/__shared__/web/SocialInput/types.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Lint Packages
🔇 Additional comments (3)
packages/components/modules/__shared__/web/SocialInput/types.ts (1)

1-1: LGTM! Type definitions are accurate.

The new onKeyDown prop is correctly typed as an optional keyboard event handler for HTMLDivElement, which aligns with the PR's objective of enabling custom keyboard event handling.

Also applies to: 18-18

packages/components/modules/__shared__/web/SocialInput/index.tsx (1)

71-71: LGTM! Implementation aligns with PR objectives.

The keyboard event handling is well-implemented:

  • Custom handlers can be provided via the onKeyDown prop
  • Default behavior (CTRL + Enter to send) is provided as a fallback

Also applies to: 97-97

packages/components/modules/__shared__/web/SocialInput/__storybook__/SocialInput.mdx (1)

33-33: LGTM! Documentation is clear and accurate.

The prop documentation clearly describes the default behavior of sending with CTRL + Enter.

@Ronan-Fernandes Ronan-Fernandes force-pushed the BA-2197-fe-social-input-heydown-behavior branch from 6346d75 to 00b204f Compare February 12, 2025 21:50
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6346d75 and 00b204f.

📒 Files selected for processing (4)
  • packages/components/modules/__shared__/web/SocialInput/__storybook__/SocialInput.mdx (2 hunks)
  • packages/components/modules/__shared__/web/SocialInput/index.tsx (3 hunks)
  • packages/components/modules/__shared__/web/SocialInput/types.ts (2 hunks)
  • packages/components/schema.graphql (70 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/components/schema.graphql
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/components/modules/shared/web/SocialInput/storybook/SocialInput.mdx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Lint Packages
🔇 Additional comments (2)
packages/components/modules/__shared__/web/SocialInput/types.ts (1)

1-1: LGTM! Well-typed keyboard event handler.

The new onKeyDown prop is correctly typed with KeyboardEvent<HTMLDivElement> and a submission callback, providing flexibility for custom keyboard event handling.

Also applies to: 18-18

packages/components/modules/__shared__/web/SocialInput/index.tsx (1)

82-87: LGTM! Correct implementation of CTRL + Enter submission.

The defaultKeyDown function correctly implements the PR objectives by:

  • Triggering submission only when CTRL + Enter is pressed
  • Preventing default behavior to avoid unwanted line breaks

Copy link
Collaborator

@tsl-ps2 tsl-ps2 left a comment

Choose a reason for hiding this comment

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

I would still change one little thing (see below) before merging, but nothing serious.

@Ronan-Fernandes Ronan-Fernandes force-pushed the BA-2197-fe-social-input-heydown-behavior branch from 00b204f to 7a2b017 Compare February 13, 2025 12:36
@Ronan-Fernandes Ronan-Fernandes force-pushed the BA-2197-fe-social-input-heydown-behavior branch from 7a2b017 to ef5468e Compare February 14, 2025 12:24
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

♻️ Duplicate comments (1)
packages/components/modules/__shared__/web/SocialInput/__storybook__/SocialInput.mdx (1)

67-72: ⚠️ Potential issue

Update example to match the component's default behavior.

The example shows preventing default on Enter without Shift, which contradicts the component's default behavior of using CTRL + Enter to send.

Apply this diff to align with the default behavior:

-      onKeyDown={(event, onSubmit) => {
-        if (event.key === 'Enter' && !event.shiftKey) {
-          event.preventDefault()
-          onSubmit()
-        }
-      }}
+      onKeyDown={(event, onSubmit) => {
+        if (event.key === 'Enter' && event.ctrlKey) {
+          event.preventDefault()
+          onSubmit()
+        }
+      }}
🧹 Nitpick comments (1)
packages/components/modules/__shared__/web/SocialInput/__storybook__/SocialInput.mdx (1)

33-33: Enhance onKeyDown prop documentation.

While the documentation mentions the default behavior, it would be helpful to add more details about:

  • The event and onSubmit callback parameters
  • How to prevent default behavior
  • Common use cases
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7a2b017 and ef5468e.

📒 Files selected for processing (6)
  • packages/components/CHANGELOG.md (1 hunks)
  • packages/components/modules/__shared__/web/SocialInput/__storybook__/SocialInput.mdx (2 hunks)
  • packages/components/modules/__shared__/web/SocialInput/index.tsx (3 hunks)
  • packages/components/modules/__shared__/web/SocialInput/types.ts (2 hunks)
  • packages/components/package.json (1 hunks)
  • packages/components/schema.graphql (70 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/components/package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/components/modules/shared/web/SocialInput/types.ts
  • packages/components/schema.graphql
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Build and Lint Packages
🔇 Additional comments (4)
packages/components/modules/__shared__/web/SocialInput/index.tsx (3)

71-71: LGTM! Clean implementation of the keyboard event handling.

The implementation of defaultKeyDown with CTRL+Enter behavior is clean and aligns well with the PR objectives.

Also applies to: 82-87


89-95: LGTM! Proper handling of custom and default keyboard events.

The implementation correctly prevents duplicate submissions by using an else block, as suggested in the past review comments.


105-105: LGTM! Proper prop passing to SocialTextField.

The handleKeyDown function is correctly passed down to the SocialTextField component.

packages/components/CHANGELOG.md (1)

3-8: LGTM! Clear and accurate changelog entry.

The changelog entry properly describes the changes and follows semantic versioning.

@anicioalexandre anicioalexandre merged commit 25c5d9d into master Feb 14, 2025
7 of 8 checks passed
@anicioalexandre anicioalexandre deleted the BA-2197-fe-social-input-heydown-behavior branch February 14, 2025 12:29
pt-tsl pushed a commit that referenced this pull request Feb 14, 2025
* Default social input send behavior

* Versioning
pt-tsl pushed a commit that referenced this pull request Feb 14, 2025
* Default social input send behavior

* Versioning
pt-tsl pushed a commit that referenced this pull request Feb 17, 2025
* Default social input send behavior

* Versioning
anicioalexandre pushed a commit that referenced this pull request Feb 18, 2025
* feat: delete chat room messages

* BA-2197: default social input send behavior (#199)

* Default social input send behavior

* Versioning

* fix: chat rooms refetch issue

* fix: decrease border radius on system messages

---------

Co-authored-by: Ronan <62265281+Ronan-Fernandes@users.noreply.github.com>
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.

4 participants