Skip to content

Commit e2f8d7f

Browse files
committed
chore: handle variables from steps that were reordered (#1207)
## TL;DR Fix UI issues when reordering steps: * Ensure variables are shown properly in the RTE when steps are reordered * Show the `Update this step with the latest data` warning when variable no longer exists after steps are reordered ## How to test? Use variables in a step, reorder the step - [ ] Shows `Update this step with the latest data` if the variable the step is from is now after the step it was used in - [ ] RTE should show the empty variable pill Revert the ordering of the steps - [ ] Should no longer show `Update this step with the latest data` - [ ] RTE should show the valid variable pill ## Screenshot [Screen Recording 2025-09-12 at 5.04.06 PM.mov <span class="graphite__hidden">(uploaded via Graphite)</span> <img class="graphite__hidden" src="https://app.graphite.dev/user-attachments/thumbnails/5317a820-6d92-49b6-b4a0-961559ffc611.mov" />](https://app.graphite.dev/user-attachments/video/5317a820-6d92-49b6-b4a0-961559ffc611.mov)
1 parent 528f14f commit e2f8d7f

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,7 @@ export default function FlowStep(
153153
const shouldShowDragHandle =
154154
!readOnly && !isTrigger && !isMobile && !isIfThenStep && allowReorder
155155

156-
const headerWidth = getFlowStepHeaderWidth(
157-
isDrawerOpen,
158-
isMobile,
159-
isNested,
160-
shouldShowDragHandle,
161-
)
156+
const headerWidth = getFlowStepHeaderWidth(isDrawerOpen, isMobile, isNested)
162157

163158
// generate help message only if template config exists
164159
const stepAppEventKey = `${step?.appKey}_${step?.key}`

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,25 @@ 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+
220239
const handleVariableClick = useCallback(
221240
(variable: Variable) => {
222241
// if the selection is a node, means the user clicked on a variable

packages/frontend/src/helpers/editor.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export const getFlowStepHeaderWidth = (
1919
isDrawerOpen: boolean,
2020
isMobile?: boolean,
2121
isNested?: boolean,
22-
shouldShowDragHandle?: boolean,
2322
) => {
2423
if (isDrawerOpen) {
2524
if (isMobile) {
@@ -33,9 +32,7 @@ export const getFlowStepHeaderWidth = (
3332
}
3433

3534
return isNested
36-
? shouldShowDragHandle
37-
? 'full'
38-
: 'calc(100% - 16px)' // 16px is the width of the drag handle
35+
? 'calc(100% - 16px)' // 16px is the width of the drag handle
3936
: '600px'
4037
}
4138

packages/frontend/src/helpers/validateStepParams.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ export const validateStepParams = (
6767

6868
const shouldTestStepAgain = hasMissingStepReference(
6969
filteredParams,
70-
new Set(testExecutionSteps.map((ts) => ts.stepId)),
70+
new Set(
71+
testExecutionSteps
72+
.filter((ts) => ts.step.position < step.position)
73+
.map((ts) => ts.stepId),
74+
),
7175
)
7276

7377
return {

0 commit comments

Comments
 (0)