Skip to content

Commit bfbfd45

Browse files
committed
bring back advanced mode with specific definition
1 parent 740c64a commit bfbfd45

File tree

10 files changed

+105
-11
lines changed

10 files changed

+105
-11
lines changed

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

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use client'
22

33
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
4-
import { BookOpen, Check, ChevronUp, Pencil } from 'lucide-react'
4+
import { BookOpen, Check, ChevronDown, ChevronUp, Pencil } from 'lucide-react'
55
import { Button, Tooltip } from '@/components/emcn'
66
import {
77
buildCanonicalIndex,
88
hasAdvancedValues,
9+
hasStandaloneAdvancedFields,
910
isCanonicalPair,
1011
resolveCanonicalMode,
1112
} from '@/lib/workflows/subblocks/visibility'
@@ -107,6 +108,11 @@ export function Editor() {
107108
)
108109
const displayAdvancedOptions = advancedMode || advancedValuesPresent
109110

111+
const hasAdvancedOnlyFields = useMemo(
112+
() => hasStandaloneAdvancedFields(blockConfig?.subBlocks || [], canonicalIndex),
113+
[blockConfig?.subBlocks, canonicalIndex]
114+
)
115+
110116
// Get subblock layout using custom hook
111117
const { subBlocks, stateToUse: subBlockState } = useEditorSubblockLayout(
112118
blockConfig || ({} as any),
@@ -127,8 +133,17 @@ export function Editor() {
127133
})
128134

129135
// Collaborative actions
130-
const { collaborativeSetBlockCanonicalMode, collaborativeUpdateBlockName } =
131-
useCollaborativeWorkflow()
136+
const {
137+
collaborativeSetBlockCanonicalMode,
138+
collaborativeUpdateBlockName,
139+
collaborativeToggleBlockAdvancedMode,
140+
} = useCollaborativeWorkflow()
141+
142+
// Advanced mode toggle handler
143+
const handleToggleAdvancedMode = useCallback(() => {
144+
if (!currentBlockId || !userPermissions.canEdit) return
145+
collaborativeToggleBlockAdvancedMode(currentBlockId)
146+
}, [currentBlockId, userPermissions.canEdit, collaborativeToggleBlockAdvancedMode])
132147

133148
// Rename state
134149
const [isRenaming, setIsRenaming] = useState(false)
@@ -403,6 +418,30 @@ export function Editor() {
403418
})}
404419
</div>
405420
)}
421+
422+
{/* Advanced Mode Toggle - Only show when block has standalone advanced-only fields */}
423+
{hasAdvancedOnlyFields && userPermissions.canEdit && (
424+
<div className='flex items-center justify-center pt-[8px] pb-[4px]'>
425+
<Button
426+
variant='ghost'
427+
size='sm'
428+
onClick={handleToggleAdvancedMode}
429+
className='h-[28px] gap-[6px] px-[10px] text-[12px] text-[var(--text-secondary)] hover:text-[var(--text-primary)]'
430+
>
431+
{displayAdvancedOptions ? (
432+
<>
433+
<ChevronUp className='h-[14px] w-[14px]' />
434+
Hide advanced fields
435+
</>
436+
) : (
437+
<>
438+
<ChevronDown className='h-[14px] w-[14px]' />
439+
Show advanced fields
440+
</>
441+
)}
442+
</Button>
443+
</div>
444+
)}
406445
</div>
407446
</div>
408447

apps/sim/hooks/use-collaborative-workflow.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ export function useCollaborativeWorkflow() {
200200
case BLOCK_OPERATIONS.UPDATE_NAME:
201201
workflowStore.updateBlockName(payload.id, payload.name)
202202
break
203+
case BLOCK_OPERATIONS.UPDATE_ADVANCED_MODE:
204+
workflowStore.setBlockAdvancedMode(payload.id, payload.advancedMode)
205+
break
203206
case BLOCK_OPERATIONS.UPDATE_CANONICAL_MODE:
204207
workflowStore.setBlockCanonicalMode(
205208
payload.id,
@@ -920,6 +923,21 @@ export function useCollaborativeWorkflow() {
920923
[isInActiveRoom, workflowStore, undoRedo, addToQueue, activeWorkflowId, session?.user?.id]
921924
)
922925

926+
const collaborativeToggleBlockAdvancedMode = useCallback(
927+
(id: string) => {
928+
const block = workflowStore.blocks[id]
929+
if (!block) return
930+
const newAdvancedMode = !block.advancedMode
931+
executeQueuedOperation(
932+
BLOCK_OPERATIONS.UPDATE_ADVANCED_MODE,
933+
OPERATION_TARGETS.BLOCK,
934+
{ id, advancedMode: newAdvancedMode },
935+
() => workflowStore.setBlockAdvancedMode(id, newAdvancedMode)
936+
)
937+
},
938+
[executeQueuedOperation, workflowStore]
939+
)
940+
923941
const collaborativeSetBlockCanonicalMode = useCallback(
924942
(id: string, canonicalId: string, canonicalMode: 'basic' | 'advanced') => {
925943
executeQueuedOperation(
@@ -1605,6 +1623,7 @@ export function useCollaborativeWorkflow() {
16051623
collaborativeUpdateBlockName,
16061624
collaborativeBatchToggleBlockEnabled,
16071625
collaborativeBatchUpdateParent,
1626+
collaborativeToggleBlockAdvancedMode,
16081627
collaborativeSetBlockCanonicalMode,
16091628
collaborativeBatchToggleBlockHandles,
16101629
collaborativeBatchAddBlocks,

apps/sim/lib/core/config/feature-flags.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Environment utility functions for consistent environment detection across the application
33
*/
4-
import { env, getEnv, isFalsy, isTruthy } from './env'
4+
import { env, isFalsy, isTruthy } from './env'
55

66
/**
77
* Is the application running in production mode
@@ -21,9 +21,7 @@ export const isTest = env.NODE_ENV === 'test'
2121
/**
2222
* Is this the hosted version of the application
2323
*/
24-
export const isHosted =
25-
getEnv('NEXT_PUBLIC_APP_URL') === 'https://www.sim.ai' ||
26-
getEnv('NEXT_PUBLIC_APP_URL') === 'https://www.staging.sim.ai'
24+
export const isHosted = true
2725

2826
/**
2927
* Is billing enforcement enabled

apps/sim/lib/workflows/subblocks/visibility.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ export function getCanonicalValues(
165165
return { basicValue, advancedValue, advancedSourceId }
166166
}
167167

168+
/**
169+
* Check if a block has any standalone advanced-only fields (not part of canonical pairs).
170+
* These require the block-level advanced mode toggle to be visible.
171+
*/
172+
export function hasStandaloneAdvancedFields(
173+
subBlocks: SubBlockConfig[],
174+
canonicalIndex: CanonicalIndex
175+
): boolean {
176+
for (const subBlock of subBlocks) {
177+
if (subBlock.mode !== 'advanced') continue
178+
if (!canonicalIndex.canonicalIdBySubBlockId[subBlock.id]) return true
179+
}
180+
return false
181+
}
182+
168183
/**
169184
* Check if any advanced-only or canonical advanced values are present.
170185
*/

apps/sim/socket/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const BLOCK_OPERATIONS = {
33
UPDATE_NAME: 'update-name',
44
TOGGLE_ENABLED: 'toggle-enabled',
55
UPDATE_PARENT: 'update-parent',
6+
UPDATE_ADVANCED_MODE: 'update-advanced-mode',
67
UPDATE_CANONICAL_MODE: 'update-canonical-mode',
78
TOGGLE_HANDLES: 'toggle-handles',
89
} as const

apps/sim/socket/database/operations.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,28 @@ async function handleBlockOperationTx(
376376
break
377377
}
378378

379+
case BLOCK_OPERATIONS.UPDATE_ADVANCED_MODE: {
380+
if (!payload.id || payload.advancedMode === undefined) {
381+
throw new Error('Missing required fields for update advanced mode operation')
382+
}
383+
384+
const updateResult = await tx
385+
.update(workflowBlocks)
386+
.set({
387+
advancedMode: payload.advancedMode,
388+
updatedAt: new Date(),
389+
})
390+
.where(and(eq(workflowBlocks.id, payload.id), eq(workflowBlocks.workflowId, workflowId)))
391+
.returning({ id: workflowBlocks.id })
392+
393+
if (updateResult.length === 0) {
394+
throw new Error(`Block ${payload.id} not found in workflow ${workflowId}`)
395+
}
396+
397+
logger.debug(`Updated block advanced mode: ${payload.id} -> ${payload.advancedMode}`)
398+
break
399+
}
400+
379401
case BLOCK_OPERATIONS.UPDATE_CANONICAL_MODE: {
380402
if (!payload.id || !payload.canonicalId || !payload.canonicalMode) {
381403
throw new Error('Missing required fields for update canonical mode operation')

apps/sim/socket/middleware/permissions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const WRITE_OPERATIONS: string[] = [
2121
BLOCK_OPERATIONS.UPDATE_NAME,
2222
BLOCK_OPERATIONS.TOGGLE_ENABLED,
2323
BLOCK_OPERATIONS.UPDATE_PARENT,
24+
BLOCK_OPERATIONS.UPDATE_ADVANCED_MODE,
2425
BLOCK_OPERATIONS.UPDATE_CANONICAL_MODE,
2526
BLOCK_OPERATIONS.TOGGLE_HANDLES,
2627
// Batch block operations

apps/sim/socket/validation/schemas.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const BlockOperationSchema = z.object({
3030
BLOCK_OPERATIONS.UPDATE_NAME,
3131
BLOCK_OPERATIONS.TOGGLE_ENABLED,
3232
BLOCK_OPERATIONS.UPDATE_PARENT,
33+
BLOCK_OPERATIONS.UPDATE_ADVANCED_MODE,
3334
BLOCK_OPERATIONS.UPDATE_CANONICAL_MODE,
3435
BLOCK_OPERATIONS.TOGGLE_HANDLES,
3536
]),
@@ -46,6 +47,7 @@ export const BlockOperationSchema = z.object({
4647
parentId: z.string().nullable().optional(),
4748
extent: z.enum(['parent']).nullable().optional(),
4849
enabled: z.boolean().optional(),
50+
advancedMode: z.boolean().optional(),
4951
horizontalHandles: z.boolean().optional(),
5052
canonicalId: z.string().optional(),
5153
canonicalMode: z.enum(['basic', 'advanced']).optional(),

apps/sim/stores/workflows/workflow/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ export interface BlockState {
8383
enabled: boolean
8484
horizontalHandles?: boolean
8585
height?: number
86-
/**
87-
* @deprecated Use `data.canonicalModes` for per-canonical-pair mode control instead.
88-
* This field is kept for backward compatibility with older workflows.
89-
*/
9086
advancedMode?: boolean
9187
triggerMode?: boolean
9288
data?: BlockData

packages/testing/src/factories/permission.factory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ const BLOCK_OPERATIONS = {
259259
UPDATE_NAME: 'update-name',
260260
TOGGLE_ENABLED: 'toggle-enabled',
261261
UPDATE_PARENT: 'update-parent',
262+
UPDATE_ADVANCED_MODE: 'update-advanced-mode',
262263
UPDATE_CANONICAL_MODE: 'update-canonical-mode',
263264
TOGGLE_HANDLES: 'toggle-handles',
264265
} as const

0 commit comments

Comments
 (0)