Skip to content

Commit 5cea73f

Browse files
fix(copilot): show subblocks in diff mode (#1916)
1 parent cbc98ab commit 5cea73f

File tree

5 files changed

+74
-32
lines changed

5 files changed

+74
-32
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/editor.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ export function Editor() {
7575
const focusOnBlock = useFocusOnBlock()
7676

7777
// Get block properties (advanced/trigger modes)
78-
const { advancedMode, triggerMode } = useEditorBlockProperties(currentBlockId)
78+
const { advancedMode, triggerMode } = useEditorBlockProperties(
79+
currentBlockId,
80+
currentWorkflow.isDiffMode
81+
)
7982

8083
// Subscribe to block's subblock values
8184
const blockSubBlockValues = useSubBlockStore(
@@ -95,7 +98,8 @@ export function Editor() {
9598
advancedMode,
9699
triggerMode,
97100
activeWorkflowId,
98-
blockSubBlockValues
101+
blockSubBlockValues,
102+
currentWorkflow.isDiffMode
99103
)
100104

101105
// Get block connections
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
1-
import { useCallback } from 'react'
1+
import { useCallback, useMemo } from 'react'
2+
import { useWorkflowDiffStore } from '@/stores/workflow-diff'
23
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
34

45
/**
56
* Custom hook for managing block display properties in the editor panel.
67
* Provides access to advanced mode and trigger mode states.
78
*
89
* @param blockId - The ID of the block being edited
10+
* @param isDiffMode - Whether we're currently viewing a diff
911
* @returns Block display properties (advanced mode, trigger mode)
1012
*/
11-
export function useEditorBlockProperties(blockId: string | null) {
12-
const blockProperties = useWorkflowStore(
13-
useCallback(
14-
(state) => {
15-
if (!blockId) {
16-
return {
17-
advancedMode: false,
18-
triggerMode: false,
19-
}
20-
}
13+
export function useEditorBlockProperties(blockId: string | null, isDiffMode: boolean) {
14+
// Get blocks from appropriate source
15+
const normalBlocks = useWorkflowStore(useCallback((state) => state.blocks, []))
16+
const diffWorkflow = useWorkflowDiffStore(useCallback((state) => state.diffWorkflow, []))
2117

22-
const block = state.blocks[blockId]
23-
return {
24-
advancedMode: block?.advancedMode ?? false,
25-
triggerMode: block?.triggerMode ?? false,
26-
}
27-
},
28-
[blockId]
29-
)
30-
)
18+
const blockProperties = useMemo(() => {
19+
if (!blockId) {
20+
return {
21+
advancedMode: false,
22+
triggerMode: false,
23+
}
24+
}
25+
26+
// Get block from appropriate source based on mode
27+
const blocks = isDiffMode ? (diffWorkflow as any)?.blocks || {} : normalBlocks
28+
const block = blocks[blockId]
29+
30+
return {
31+
advancedMode: block?.advancedMode ?? false,
32+
triggerMode: block?.triggerMode ?? false,
33+
}
34+
}, [blockId, isDiffMode, normalBlocks, diffWorkflow])
3135

3236
return blockProperties
3337
}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/hooks/use-editor-subblock-layout.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useMemo } from 'react'
22
import { getEnv, isTruthy } from '@/lib/env'
33
import type { BlockConfig, SubBlockConfig, SubBlockType } from '@/blocks/types'
4+
import { useWorkflowDiffStore } from '@/stores/workflow-diff'
45
import { mergeSubblockState } from '@/stores/workflows/utils'
56
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
67

@@ -14,6 +15,7 @@ import { useWorkflowStore } from '@/stores/workflows/workflow/store'
1415
* @param displayTriggerMode - Whether trigger mode is enabled for this block
1516
* @param activeWorkflowId - The active workflow ID
1617
* @param blockSubBlockValues - Current subblock values from the store
18+
* @param isDiffMode - Whether we're currently viewing a diff
1719
* @returns Object containing subBlocks array and stateToUse for stable key generation
1820
*/
1921
export function useEditorSubblockLayout(
@@ -22,7 +24,8 @@ export function useEditorSubblockLayout(
2224
displayAdvancedMode: boolean,
2325
displayTriggerMode: boolean,
2426
activeWorkflowId: string | null,
25-
blockSubBlockValues: Record<string, any>
27+
blockSubBlockValues: Record<string, any>,
28+
isDiffMode: boolean
2629
) {
2730
return useMemo(() => {
2831
// Guard against missing config or block selection
@@ -33,15 +36,28 @@ export function useEditorSubblockLayout(
3336
// Get the appropriate state for conditional evaluation
3437
let stateToUse: Record<string, any> = {}
3538

36-
const blocks = useWorkflowStore.getState().blocks || {}
39+
// Get blocks based on whether we're in diff mode
40+
let blocks: Record<string, any>
41+
if (isDiffMode) {
42+
// In diff mode, get blocks from diff workflow
43+
const diffStore = useWorkflowDiffStore.getState()
44+
const diffWorkflow = diffStore.diffWorkflow
45+
blocks = (diffWorkflow as any)?.blocks || {}
46+
} else {
47+
// In normal mode, get blocks from workflow store
48+
blocks = useWorkflowStore.getState().blocks || {}
49+
}
50+
3751
const mergedMap = mergeSubblockState(blocks, activeWorkflowId || undefined, blockId)
3852
const mergedState = mergedMap ? mergedMap[blockId] : undefined
3953
const mergedSubBlocks = mergedState?.subBlocks || {}
4054

55+
// In diff mode, prioritize diff workflow values; in normal mode, prioritize live store values
4156
stateToUse = Object.keys(mergedSubBlocks).reduce(
4257
(acc, key) => {
43-
const value =
44-
blockSubBlockValues[key] !== undefined
58+
const value = isDiffMode
59+
? (mergedSubBlocks[key]?.value ?? null)
60+
: blockSubBlockValues[key] !== undefined
4561
? blockSubBlockValues[key]
4662
: (mergedSubBlocks[key]?.value ?? null)
4763
acc[key] = { value }
@@ -50,11 +66,14 @@ export function useEditorSubblockLayout(
5066
{} as Record<string, { value: unknown }>
5167
)
5268

53-
Object.keys(blockSubBlockValues).forEach((key) => {
54-
if (!(key in stateToUse)) {
55-
stateToUse[key] = { value: blockSubBlockValues[key] }
56-
}
57-
})
69+
// Only add live store values if not in diff mode
70+
if (!isDiffMode) {
71+
Object.keys(blockSubBlockValues).forEach((key) => {
72+
if (!(key in stateToUse)) {
73+
stateToUse[key] = { value: blockSubBlockValues[key] }
74+
}
75+
})
76+
}
5877

5978
// Filter visible blocks and those that meet their conditions
6079
const visibleSubBlocks = (config.subBlocks || []).filter((block) => {
@@ -134,5 +153,6 @@ export function useEditorSubblockLayout(
134153
displayTriggerMode,
135154
blockSubBlockValues,
136155
activeWorkflowId,
156+
isDiffMode,
137157
])
138158
}

apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ function createBlockFromParams(blockId: string, params: any, parentId?: string):
131131
const subBlocks: Record<string, any> = {}
132132
if (params.inputs) {
133133
Object.entries(params.inputs).forEach(([key, value]) => {
134+
// Skip runtime subblock IDs when computing outputs
135+
if (TRIGGER_RUNTIME_SUBBLOCK_IDS.includes(key)) {
136+
return
137+
}
134138
subBlocks[key] = { id: key, type: 'short-input', value: value }
135139
})
136140
}
@@ -157,6 +161,10 @@ function createBlockFromParams(blockId: string, params: any, parentId?: string):
157161
// Add inputs as subBlocks
158162
if (params.inputs) {
159163
Object.entries(params.inputs).forEach(([key, value]) => {
164+
if (TRIGGER_RUNTIME_SUBBLOCK_IDS.includes(key)) {
165+
return
166+
}
167+
160168
let sanitizedValue = value
161169

162170
// Special handling for inputFormat - ensure it's an array
@@ -729,6 +737,11 @@ function applyOperationsToWorkflowState(
729737
// Update inputs if provided
730738
if (params.inputs) {
731739
Object.entries(params.inputs).forEach(([key, value]) => {
740+
// Skip runtime subblock IDs (webhookId, triggerPath, testUrl, testUrlExpiresAt, scheduleId)
741+
if (TRIGGER_RUNTIME_SUBBLOCK_IDS.includes(key)) {
742+
return
743+
}
744+
732745
let sanitizedValue = value
733746

734747
if (key === 'inputFormat' && value !== null && value !== undefined) {

apps/sim/triggers/consts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ export const TRIGGER_PERSISTED_SUBBLOCK_IDS: string[] = [
3131
]
3232

3333
/**
34-
* Trigger-related subblock IDs that represent runtime metadata. They should remain
34+
* Trigger and schedule-related subblock IDs that represent runtime metadata. They should remain
3535
* in the workflow state but must not be modified or cleared by diff operations.
3636
*/
3737
export const TRIGGER_RUNTIME_SUBBLOCK_IDS: string[] = [
3838
'webhookId',
3939
'triggerPath',
4040
'testUrl',
4141
'testUrlExpiresAt',
42+
'scheduleId',
4243
]

0 commit comments

Comments
 (0)