-
Notifications
You must be signed in to change notification settings - Fork 15
Ability to Manually Connect MCQ Paths #1015
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
Merged
ffrose
merged 3 commits into
buerokratt:dev
from
1AhmedYasser:Ability-to-Manually-Connect-MCQ-Paths
May 21, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| .mcq-branch-select-modal__button { | ||
| display: inline-flex; | ||
| width: fit-content; | ||
| max-width: 100%; | ||
| overflow: hidden; | ||
|
|
||
| .multiple-choice-question-button__text { | ||
| max-width: 100%; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { Button, Modal, Track } from 'components'; | ||
| import { FC } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { McqEmptyBranch } from 'utils/mcq-flow-utils'; | ||
|
|
||
| import '../FlowElementsPopup/styles.scss'; | ||
| import './McqBranchSelectModal.scss'; | ||
|
|
||
| type McqBranchSelectModalProps = { | ||
| readonly emptyBranches: McqEmptyBranch[]; | ||
| readonly onSelect: (branch: McqEmptyBranch) => void; | ||
| readonly onClose: () => void; | ||
| }; | ||
|
|
||
| const McqBranchSelectModal: FC<McqBranchSelectModalProps> = ({ emptyBranches, onSelect, onClose }) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| return ( | ||
| <Modal title={t('serviceFlow.mcq.selectBranchTitle')} onClose={onClose}> | ||
| <p>{t('serviceFlow.mcq.emptyBranchesMessage', { count: emptyBranches.length })}</p> | ||
| <Track direction="vertical" gap={8} align="left" style={{ marginTop: 16, width: '100%' }}> | ||
| {emptyBranches.map((branch) => ( | ||
| <Button key={branch.edgeId} className="mcq-branch-select-modal__button" onClick={() => onSelect(branch)}> | ||
| <span className="multiple-choice-question-button__text">{branch.label}</span> | ||
| </Button> | ||
| ))} | ||
| </Track> | ||
| </Modal> | ||
| ); | ||
| }; | ||
|
|
||
| export default McqBranchSelectModal; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import { Connection, useReactFlow } from '@xyflow/react'; | ||
| import { useCallback, useState } from 'react'; | ||
| import useServiceStore from 'store/new-services.store'; | ||
| import { | ||
| applyMcqBranchConnection, | ||
| applySimpleConnection, | ||
| getEmptyMcqBranches, | ||
| getMcqNodeIdFromConnection, | ||
| McqEmptyBranch, | ||
| } from 'utils/mcq-flow-utils'; | ||
|
|
||
| export type PendingMcqConnection = { | ||
| readonly connection: Connection; | ||
| readonly emptyBranches: McqEmptyBranch[]; | ||
| }; | ||
|
trevorling marked this conversation as resolved.
|
||
|
|
||
| function useMcqConnect() { | ||
| const { getNodes, getEdges, setNodes, setEdges, getNode } = useReactFlow(); | ||
| const saveToHistory = useServiceStore((state) => state.saveToHistory); | ||
| const setHasUnsavedChanges = useServiceStore((state) => state.setHasUnsavedChanges); | ||
| const [pendingConnection, setPendingConnection] = useState<PendingMcqConnection | null>(null); | ||
|
|
||
| const commitConnection = useCallback( | ||
| (nodes: ReturnType<typeof getNodes>, edges: ReturnType<typeof getEdges>) => { | ||
| setNodes(nodes); | ||
| setEdges(edges); | ||
| setHasUnsavedChanges(true); | ||
| saveToHistory({ nodes, edges }); | ||
| }, | ||
| [saveToHistory, setEdges, setHasUnsavedChanges, setNodes], | ||
| ); | ||
|
|
||
| const applyMcqOutgoingConnection = useCallback( | ||
| (connection: Connection, branch: McqEmptyBranch) => { | ||
| const { source, target } = connection; | ||
| if (!source || !target) return; | ||
|
|
||
| const nodes = getNodes(); | ||
| const edges = getEdges(); | ||
| const result = applyMcqBranchConnection({ | ||
| nodes, | ||
| edges, | ||
| mcqId: source, | ||
| targetId: target, | ||
| branch, | ||
| }); | ||
| commitConnection(result.nodes, result.edges); | ||
| }, | ||
| [commitConnection, getEdges, getNodes], | ||
| ); | ||
|
|
||
| const applyMcqIncomingConnection = useCallback( | ||
| (connection: Connection) => { | ||
| const nodes = getNodes(); | ||
| const edges = getEdges(); | ||
| const result = applySimpleConnection({ nodes, edges, connection }); | ||
| commitConnection(result.nodes, result.edges); | ||
| }, | ||
| [commitConnection, getEdges, getNodes], | ||
| ); | ||
|
|
||
| const handleConnect = useCallback( | ||
| (connection: Connection) => { | ||
| const mcqId = getMcqNodeIdFromConnection(connection, getNode); | ||
| if (!mcqId) return false; | ||
|
|
||
| const nodes = getNodes(); | ||
| const edges = getEdges(); | ||
| const emptyBranches = getEmptyMcqBranches(mcqId, nodes, edges); | ||
| if (emptyBranches.length === 0) return true; | ||
|
|
||
| if (connection.source === mcqId) { | ||
| if (emptyBranches.length === 1) { | ||
| applyMcqOutgoingConnection(connection, emptyBranches[0]); | ||
| } else { | ||
| setPendingConnection({ connection, emptyBranches }); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| applyMcqIncomingConnection(connection); | ||
| return true; | ||
| }, | ||
| [applyMcqIncomingConnection, applyMcqOutgoingConnection, getEdges, getNode, getNodes], | ||
| ); | ||
|
|
||
| const confirmBranch = useCallback( | ||
| (branch: McqEmptyBranch) => { | ||
| if (!pendingConnection) return; | ||
| applyMcqOutgoingConnection(pendingConnection.connection, branch); | ||
| setPendingConnection(null); | ||
| }, | ||
| [applyMcqOutgoingConnection, pendingConnection], | ||
| ); | ||
|
|
||
| const cancelBranchSelection = useCallback(() => { | ||
| setPendingConnection(null); | ||
| }, []); | ||
|
|
||
| const isValidConnection = useCallback( | ||
| (connection: Connection) => { | ||
| if (connection.source === connection.target) return false; | ||
|
|
||
| const mcqId = getMcqNodeIdFromConnection(connection, getNode); | ||
| if (!mcqId) return true; | ||
|
|
||
| return getEmptyMcqBranches(mcqId, getNodes(), getEdges()).length > 0; | ||
| }, | ||
| [getEdges, getNode, getNodes], | ||
| ); | ||
|
|
||
| return { | ||
| pendingConnection, | ||
| handleConnect, | ||
| isValidConnection, | ||
| confirmBranch, | ||
| cancelBranchSelection, | ||
| }; | ||
| } | ||
|
|
||
| export default useMcqConnect; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.