Skip to content

Conversation

@jaycnz
Copy link
Contributor

@jaycnz jaycnz commented Jan 23, 2026

Summary by CodeRabbit

  • New Features

    • Pressing Enter while editing a radio option now creates a new option and focuses it, speeding up option entry.
  • Refactor

    • Radio-option creation logic extracted to a shared utility to standardize creation flow across the editor.
  • Tests

    • Added tests covering radio-option creation scenarios, including ordering and early-exit cases.

✏️ Tip: You can customize this high-level summary in your review settings.

@jaycnz jaycnz requested a review from edmonday January 23, 2026 01:31
@jaycnz jaycnz self-assigned this Jan 23, 2026
@jaycnz jaycnz added type: feat Brand new functionality, features, pages, workflows, endpoints, etc. Interns labels Jan 23, 2026
@linear
Copy link

linear bot commented Jan 23, 2026

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 23, 2026

Walkthrough

Refactors RadioOption creation into a new utility handleCreateRadioOption and adds Enter-key submission in RadioOptionEdit to create a new RadioOption block.

Changes

Cohort / File(s) Summary
Enter Key Support in RadioOptionEdit
apps/journeys-admin/src/components/Editor/Slider/Content/Canvas/InlineEditWrapper/RadioOptionEdit/RadioOptionEdit.tsx
Adds keyDown handler that submits on Enter (no Shift) and triggers creation flow via useBlockCreateCommand / RADIO_OPTION_BLOCK_CREATE wiring.
Delegation to External Utility
apps/journeys-admin/src/components/Editor/Slider/Content/Canvas/InlineEditWrapper/RadioQuestionEdit/RadioQuestionEdit.tsx
Replaces inline RadioOption creation logic with a call to handleCreateRadioOption; removes local UUID/mutation/cache wiring.
RadioOption Creation Utility
apps/journeys-admin/src/components/Editor/Slider/Content/Canvas/InlineEditWrapper/RadioQuestionEdit/utils/handleCreateRadioOption/handleCreateRadioOption.ts
New function that builds a RadioOption block, inserts it via addBlock, dispatches focus action, executes radioOptionBlockCreate mutation with optimistic response, and updates Apollo cache.
Tests for Creation Utility
.../handleCreateRadioOption/handleCreateRadioOption.spec.tsx
Adds tests covering siblingCount present/absent and early-return when journey missing; asserts addBlock, dispatch, mutation inputs, and optimistic response.
Re-export
.../handleCreateRadioOption/index.ts
Re-exports handleCreateRadioOption for easier imports.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant User as User
  participant RadioOptionEdit as RadioOptionEdit\n(component)
  participant createUtil as handleCreateRadioOption
  participant EditorState as addBlock / dispatch
  participant GraphQL as radioOptionBlockCreate
  participant Apollo as Apollo Cache

  User->>RadioOptionEdit: Press Enter (no Shift)
  RadioOptionEdit->>createUtil: submit value -> handleCreateRadioOption(...)
  createUtil->>EditorState: addBlock(new RadioOptionBlock)
  EditorState->>createUtil: returns block reference
  createUtil->>EditorState: dispatch SetEditorFocusAction(newBlockId)
  createUtil->>GraphQL: radioOptionBlockCreate(input) with optimisticResponse
  GraphQL->>Apollo: mutation result
  Apollo->>Apollo: writeFragment / modify Journey blocks list
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • csiyang
  • Kneesal
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature: enabling the Enter key to create a new radio option in a poll editor, which is the core functionality added across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jaychen/nes-493-poll-option-edit-pressing-enter-should-add-a-new-option-not

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Jan 23, 2026

View your CI Pipeline Execution ↗ for commit 22b8280

Command Status Duration Result
nx run journeys-admin-e2e:e2e ✅ Succeeded 33s View ↗
nx run-many --target=vercel-alias --projects=jo... ✅ Succeeded 2s View ↗
nx run-many --target=upload-sourcemaps --projec... ✅ Succeeded 13s View ↗
nx run-many --target=deploy --projects=journeys... ✅ Succeeded 2m 49s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-26 20:23:03 UTC

@github-actions github-actions bot requested a deployment to Preview - journeys-admin January 23, 2026 01:34 Pending
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

🤖 Fix all issues with AI agents
In
`@apps/journeys-admin/src/components/Editor/Slider/Content/Canvas/InlineEditWrapper/RadioQuestionEdit/utils/handleCreateRadioOption/handleCreateRadioOption.ts`:
- Line 23: Remove the debug console.log in the handleCreateRadioOption
implementation: delete the line that logs "siblingCount"
(console.log('siblingCount', siblingCount)) so no debug output remains; locate
this inside the handleCreateRadioOption function (the scope where siblingCount
is computed) and remove that single logging statement.
🧹 Nitpick comments (4)
apps/journeys-admin/src/components/Editor/Slider/Content/Canvas/InlineEditWrapper/RadioQuestionEdit/utils/handleCreateRadioOption/handleCreateRadioOption.ts (1)

64-68: Fix inconsistent indentation in the GraphQL fragment.

The fragment definition has inconsistent indentation compared to the surrounding code.

Proposed fix
                                     const newBlockRef = cache.writeFragment({
                                         data: data.radioOptionBlockCreate,
                                         fragment: gql`
-                        fragment NewBlock on Block {
-                          id
-                        }
-                      `
+                                            fragment NewBlock on Block {
+                                                id
+                                            }
+                                        `
                                     })
apps/journeys-admin/src/components/Editor/Slider/Content/Canvas/InlineEditWrapper/RadioOptionEdit/RadioOptionEdit.tsx (2)

19-22: Consider organizing imports by grouping external dependencies separately from internal ones.

The new imports are added between existing imports, breaking the grouping pattern. As per coding guidelines, ensure proper organization of imports.

Suggested import organization
 import {
   RadioOptionBlockUpdateContent,
   RadioOptionBlockUpdateContentVariables
 } from '../../../../../../../../__generated__/RadioOptionBlockUpdateContent'
+import { RadioOptionBlockCreate, RadioOptionBlockCreateVariables } from '../../../../../../../../__generated__/RadioOptionBlockCreate'
 import { RadioOptionFields } from '../../../../../../../../__generated__/RadioOptionFields'
+import { useBlockCreateCommand } from '../../../../../utils/useBlockCreateCommand'
 import { InlineEditInput } from '../InlineEditInput'
-import { useBlockCreateCommand } from '../../../../../utils/useBlockCreateCommand'
-import { RadioOptionBlockCreate, RadioOptionBlockCreateVariables } from '../../../../../../../../__generated__/RadioOptionBlockCreate'
 import { RADIO_OPTION_BLOCK_CREATE } from '../RadioQuestionEdit/RadioQuestionEdit'
 import { handleCreateRadioOption } from '../RadioQuestionEdit/utils/handleCreateRadioOption/handleCreateRadioOption'

138-140: Remove unnecessary blank lines.

Multiple consecutive blank lines should be consolidated.

Proposed fix
   const [radioOptionBlockCreate] = useMutation<
     RadioOptionBlockCreate,
     RadioOptionBlockCreateVariables
   >(RADIO_OPTION_BLOCK_CREATE)
-
-

   return (
apps/journeys-admin/src/components/Editor/Slider/Content/Canvas/InlineEditWrapper/RadioQuestionEdit/RadioQuestionEdit.tsx (1)

54-68: Fix inconsistent formatting in the handleCreateRadioOption call.

The object properties have inconsistent indentation.

Proposed fix
       addOption={
         props.children.length < 12
           ? () => handleCreateRadioOption(
-            {
-              dispatch,
-            addBlock,
-              radioOptionBlockCreate,
-              parentBlockId: id,
-              journey,
-              selectedStep: undefined,
-              siblingCount: selectedBlock?.children?.length
-            }
-          )
+              {
+                dispatch,
+                addBlock,
+                radioOptionBlockCreate,
+                parentBlockId: id,
+                journey,
+                selectedStep: undefined,
+                siblingCount: selectedBlock?.children?.length
+              }
+            )
           : undefined
       }

export function handleCreateRadioOption({ dispatch, addBlock, radioOptionBlockCreate, parentBlockId, journey, selectedStep, siblingCount }: HandleCreateRadioOptionProps): void {
if (journey == null) return

console.log('siblingCount', siblingCount)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove debug console.log statement.

This debug logging should be removed before merging to production.

Proposed fix
-    console.log('siblingCount', siblingCount)
-
     const parentOrder = siblingCount ?? searchBlocks(selectedStep?.children ?? [], parentBlockId ?? '')?.children?.length ?? 0
📝 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
console.log('siblingCount', siblingCount)
const parentOrder = siblingCount ?? searchBlocks(selectedStep?.children ?? [], parentBlockId ?? '')?.children?.length ?? 0
🤖 Prompt for AI Agents
In
`@apps/journeys-admin/src/components/Editor/Slider/Content/Canvas/InlineEditWrapper/RadioQuestionEdit/utils/handleCreateRadioOption/handleCreateRadioOption.ts`
at line 23, Remove the debug console.log in the handleCreateRadioOption
implementation: delete the line that logs "siblingCount"
(console.log('siblingCount', siblingCount)) so no debug output remains; locate
this inside the handleCreateRadioOption function (the scope where siblingCount
is computed) and remove that single logging statement.

@github-actions github-actions bot temporarily deployed to Preview - journeys-admin January 23, 2026 01:38 Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Jan 23, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
journeys-admin ✅ Ready journeys-admin preview Tue Jan 27 09:19:58 NZDT 2026

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

🤖 Fix all issues with AI agents
In
`@apps/journeys-admin/src/components/Editor/Slider/Content/Canvas/InlineEditWrapper/RadioOptionEdit/RadioOptionEdit.tsx`:
- Around line 174-188: The Enter-key handler currently calls
handleCreateRadioOption without checking the 12-option limit or passing the
sibling count; add a guard in the onKeyDown callback to compute the current
sibling count (e.g., from journey/selectedStep or radioOptionProps.siblings) and
only call handleCreateRadioOption when siblings.length < 12, and pass that
sibling count (or siblings.length) into handleCreateRadioOption along with
dispatch, addBlock, radioOptionBlockCreate, parentBlockId:
radioOptionProps.parentBlockId, journey, and selectedStep so ordering aligns
with the button path.
♻️ Duplicate comments (1)
apps/journeys-admin/src/components/Editor/Slider/Content/Canvas/InlineEditWrapper/RadioQuestionEdit/utils/handleCreateRadioOption/handleCreateRadioOption.ts (1)

32-49: Remove debug logging before merge.

This console output will leak into production logs.

🧹 Suggested fix
-  console.log('siblingCount', siblingCount)
-
   const parentOrder =

Comment on lines +174 to +188
onKeyDown={(e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault()
handleSubmit(value)

handleCreateRadioOption({
dispatch,
addBlock,
radioOptionBlockCreate,
parentBlockId: radioOptionProps.parentBlockId,
journey,
selectedStep
})
}
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Prevent Enter key from bypassing the 12‑option cap.

The button path enforces a 12‑option limit, but the Enter‑key path does not, so users can exceed the cap. Add a guard before calling handleCreateRadioOption and pass the sibling count for consistent ordering.

🔧 Suggested fix
-          onKeyDown={(e) => {
-            if (e.key === 'Enter' && !e.shiftKey) {
-              e.preventDefault()
-              handleSubmit(value)
-
-              handleCreateRadioOption({
-                dispatch,
-                addBlock,
-                radioOptionBlockCreate,
-                parentBlockId: radioOptionProps.parentBlockId,
-                journey,
-                selectedStep
-              })
-            }
-          }}
+          onKeyDown={(e) => {
+            if (e.key !== 'Enter' || e.shiftKey) return
+            e.preventDefault()
+            handleSubmit(value)
+
+            const parentBlock = selectedStep?.children?.find(
+              (block) => block.id === radioOptionProps.parentBlockId
+            )
+            const siblingCount = parentBlock?.children?.length ?? 0
+            if (siblingCount >= 12) return
+
+            handleCreateRadioOption({
+              dispatch,
+              addBlock,
+              radioOptionBlockCreate,
+              parentBlockId: radioOptionProps.parentBlockId,
+              journey,
+              selectedStep,
+              siblingCount
+            })
+          }}
📝 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
onKeyDown={(e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault()
handleSubmit(value)
handleCreateRadioOption({
dispatch,
addBlock,
radioOptionBlockCreate,
parentBlockId: radioOptionProps.parentBlockId,
journey,
selectedStep
})
}
}}
onKeyDown={(e) => {
if (e.key !== 'Enter' || e.shiftKey) return
e.preventDefault()
handleSubmit(value)
const parentBlock = selectedStep?.children?.find(
(block) => block.id === radioOptionProps.parentBlockId
)
const siblingCount = parentBlock?.children?.length ?? 0
if (siblingCount >= 12) return
handleCreateRadioOption({
dispatch,
addBlock,
radioOptionBlockCreate,
parentBlockId: radioOptionProps.parentBlockId,
journey,
selectedStep,
siblingCount
})
}}
🤖 Prompt for AI Agents
In
`@apps/journeys-admin/src/components/Editor/Slider/Content/Canvas/InlineEditWrapper/RadioOptionEdit/RadioOptionEdit.tsx`
around lines 174 - 188, The Enter-key handler currently calls
handleCreateRadioOption without checking the 12-option limit or passing the
sibling count; add a guard in the onKeyDown callback to compute the current
sibling count (e.g., from journey/selectedStep or radioOptionProps.siblings) and
only call handleCreateRadioOption when siblings.length < 12, and pass that
sibling count (or siblings.length) into handleCreateRadioOption along with
dispatch, addBlock, radioOptionBlockCreate, parentBlockId:
radioOptionProps.parentBlockId, journey, and selectedStep so ordering aligns
with the button path.

@github-actions github-actions bot temporarily deployed to Preview - journeys-admin January 23, 2026 01:48 Inactive
@github-actions github-actions bot temporarily deployed to Preview - journeys-admin January 26, 2026 20:15 Inactive
}: HandleCreateRadioOptionProps): void {
if (journey == null) return

console.log('siblingCount', siblingCount)
Copy link
Contributor

Choose a reason for hiding this comment

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

remove console log please

{...props}
id={id}
addOption={props.children.length < 12 ? handleCreateOption : undefined}
addOption={
Copy link
Contributor

Choose a reason for hiding this comment

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

lets not use a ternary here, instead we can pass a function with a guard. Improves readability.

Suggested change
addOption={
addOption={() => {
if (props.children.length >= 12) return
handleCreateRadioOption(...)
}}

Comment on lines +14 to +18
const dispatch = jest.fn()
const addBlock = jest.fn()
const radioOptionBlockCreate = jest.fn()
const parentBlockId = 'parentBlockId'
const journey = { id: 'journeyId' } as unknown as JourneyFields
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move these to the top of the file so there is less repetition.?


expect(addBlock).toHaveBeenCalledTimes(1)
expect(addBlock).toHaveBeenCalledWith({
block: expect.objectContaining({
Copy link
Contributor

Choose a reason for hiding this comment

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

You can drop the expect.objectContaining here as we are already asserting that addBlock is called with something.

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

Labels

Interns type: feat Brand new functionality, features, pages, workflows, endpoints, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants