Skip to content

Commit 3985b26

Browse files
authored
fix: hide drag handle when drawer is open (#1234)
_Reusing this PR_ ## Problem * useEffect that forces a re-render of editor content when variable info changes (e.g., after step reorder) causes cursor to move to the wrong position * After reordering, copied variables hold the wrong value ## Solution * Hide the drag handle when the side drawer is open ## Tests Test to ensure no regression - [ ] Drag handle only shows when drawer is closed - [ ] Step widths are correct - [ ] If-then branch condition step width is aligned with the action step widths - [ ] Hover add step button widths are aligned with the action step widths - [ ] Reordering steps that have been checked are updated appropriately with empty variable pill and prompt to update with the latest data
1 parent 34ce1cf commit 3985b26

File tree

6 files changed

+40
-27
lines changed

6 files changed

+40
-27
lines changed

packages/frontend/src/components/FlowStep/FlowStepWrapper.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ interface FlowStepWrapperProps {
77
children: React.ReactNode
88
canChildStepsReorder?: boolean
99
allowReorder?: boolean
10+
isDrawerOpen?: boolean
11+
isReadOnly?: boolean
1012
}
1113

1214
export default function FlowStepWrapper(props: FlowStepWrapperProps) {
13-
const { children, canChildStepsReorder, allowReorder } = props
15+
const {
16+
children,
17+
canChildStepsReorder,
18+
allowReorder,
19+
isDrawerOpen,
20+
isReadOnly,
21+
} = props
1422
const isMobile = useIsMobile()
1523

1624
return (
@@ -19,7 +27,11 @@ export default function FlowStepWrapper(props: FlowStepWrapperProps) {
1927
display={isMobile ? 'block' : 'flex'}
2028
flexDir="column"
2129
w={
22-
canChildStepsReorder && !allowReorder && !isMobile
30+
canChildStepsReorder &&
31+
!allowReorder &&
32+
!isMobile &&
33+
!isDrawerOpen &&
34+
!isReadOnly
2335
? `calc(100% - ${NESTED_DRAG_HANDLE_WIDTH}px)`
2436
: '100%'
2537
}

packages/frontend/src/components/FlowStep/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,14 @@ export default function FlowStep(
7979
selectedActionOrTrigger,
8080
substeps,
8181
shouldShowDragHandle,
82-
} = useStepMetadata(allApps, step, readOnly, allowReorder, isMobile)
82+
} = useStepMetadata(
83+
allApps,
84+
step,
85+
readOnly,
86+
allowReorder,
87+
isMobile,
88+
isDrawerOpen,
89+
)
8390

8491
const {
8592
cancelRef,
@@ -176,6 +183,8 @@ export default function FlowStep(
176183
<FlowStepWrapper
177184
canChildStepsReorder={canChildStepsReorder}
178185
allowReorder={allowReorder}
186+
isDrawerOpen={isDrawerOpen}
187+
isReadOnly={readOnly}
179188
>
180189
{!app ? (
181190
<EmptyFlowStepHeader

packages/frontend/src/components/FlowStepGroup/Content/IfThen/HoverAddStepButton.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ export function HoverAddStepButton(
4040
const { isOpen, onOpen, onClose } = useDisclosure()
4141
const [isHovered, setIsHovered] = useState(false)
4242

43-
const { allApps, readOnly, isMobile } = useContext(EditorContext)
43+
const { allApps, readOnly, isMobile, isDrawerOpen } =
44+
useContext(EditorContext)
4445
const { shouldShowDragHandle } = useStepMetadata(
4546
allApps,
4647
step,
4748
readOnly,
4849
allowReorder,
4950
isMobile,
51+
isDrawerOpen,
5052
)
5153

5254
const {
@@ -81,7 +83,7 @@ export function HoverAddStepButton(
8183
onMouseEnter={() => setIsHovered(true)}
8284
onMouseLeave={() => setIsHovered(false)}
8385
w={
84-
(shouldShowDragHandle || canChildStepsReorder) && !isMobile
86+
(shouldShowDragHandle || canChildStepsReorder) && !isDrawerOpen
8587
? `calc(100% - ${NESTED_DRAG_HANDLE_WIDTH}px)`
8688
: 'full'
8789
}

packages/frontend/src/components/FlowStepGroup/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default function FlowStepGroup(props: FlowStepGroupProps) {
7373
return (
7474
<Flex
7575
w={
76-
isInsideForEach && stepsBeforeGroup.length > 2
76+
isInsideForEach && stepsBeforeGroup.length > 2 && !isDrawerOpen
7777
? `calc(100% - ${NESTED_DRAG_HANDLE_WIDTH}px)`
7878
: '100%'
7979
}

packages/frontend/src/components/RichTextEditor/index.tsx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -217,25 +217,6 @@ const Editor = ({
217217
editor?.setOptions({ editable })
218218
}, [editable, editor])
219219

220-
// NOTE: we force a re-render editor content when variable info changes (e.g., after step reorder)
221-
// to ensure that the variable shown in the RTE is updated
222-
useEffect(() => {
223-
if (!editor || !content) {
224-
return
225-
}
226-
227-
// Get current editor content
228-
const currentContent = editor.getHTML()
229-
230-
// Re-substitute templates with updated variable info
231-
const updatedContent = substituteOldTemplates(content, varInfo)
232-
233-
// Only update if content has actually changed
234-
if (currentContent !== updatedContent) {
235-
editor.commands.setContent(updatedContent)
236-
}
237-
}, [editor, content, varInfo])
238-
239220
const handleVariableClick = useCallback(
240221
(variable: Variable) => {
241222
// if the selection is a node, means the user clicked on a variable

packages/frontend/src/hooks/useStepMetadata.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function useStepMetadata(
2626
readOnly?: boolean,
2727
allowReorder?: boolean,
2828
isMobile?: boolean,
29+
isDrawerOpen?: boolean,
2930
): UseStepMetadataResult {
3031
const isCompleted = step?.status === 'completed'
3132
const isTrigger = step?.type === 'trigger'
@@ -66,10 +67,18 @@ export function useStepMetadata(
6667
* - step is not a trigger
6768
* - step is not an if-then condition step
6869
* - allowReorder is true
70+
* - side drawer is not open
6971
*/
7072
const shouldShowDragHandle = useMemo(() => {
71-
return !readOnly && !isTrigger && !isMobile && !isIfThenStep && allowReorder
72-
}, [readOnly, isTrigger, isMobile, isIfThenStep, allowReorder])
73+
return (
74+
!readOnly &&
75+
!isTrigger &&
76+
!isMobile &&
77+
!isIfThenStep &&
78+
allowReorder &&
79+
!isDrawerOpen
80+
)
81+
}, [readOnly, isTrigger, isMobile, isIfThenStep, allowReorder, isDrawerOpen])
7382

7483
return {
7584
app,

0 commit comments

Comments
 (0)