-
Notifications
You must be signed in to change notification settings - Fork 14
feat: enter key creates new radio option in poll #8633
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
base: main
Are you sure you want to change the base?
feat: enter key creates new radio option in poll #8633
Conversation
WalkthroughRefactors RadioOption creation into a new utility Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
View your CI Pipeline Execution ↗ for commit 22b8280
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this 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 thehandleCreateRadioOptioncall.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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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.
|
The latest updates on your projects.
|
…ter-should-add-a-new-option-not
There was a problem hiding this 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 =
| onKeyDown={(e) => { | ||
| if (e.key === 'Enter' && !e.shiftKey) { | ||
| e.preventDefault() | ||
| handleSubmit(value) | ||
|
|
||
| handleCreateRadioOption({ | ||
| dispatch, | ||
| addBlock, | ||
| radioOptionBlockCreate, | ||
| parentBlockId: radioOptionProps.parentBlockId, | ||
| journey, | ||
| selectedStep | ||
| }) | ||
| } | ||
| }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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.
…ter-should-add-a-new-option-not
| }: HandleCreateRadioOptionProps): void { | ||
| if (journey == null) return | ||
|
|
||
| console.log('siblingCount', siblingCount) |
There was a problem hiding this comment.
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={ |
There was a problem hiding this comment.
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.
| addOption={ | |
| addOption={() => { | |
| if (props.children.length >= 12) return | |
| handleCreateRadioOption(...) | |
| }} |
| const dispatch = jest.fn() | ||
| const addBlock = jest.fn() | ||
| const radioOptionBlockCreate = jest.fn() | ||
| const parentBlockId = 'parentBlockId' | ||
| const journey = { id: 'journeyId' } as unknown as JourneyFields |
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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.
Summary by CodeRabbit
New Features
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.