Skip to content

Commit 748473c

Browse files
committed
trigger canoncial index ops consolidation
1 parent 79a1a77 commit 748473c

10 files changed

Lines changed: 286 additions & 65 deletions

File tree

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
hasAdvancedValues,
2525
isCanonicalPair,
2626
resolveCanonicalMode,
27+
shouldUseSubBlockForTriggerModeCanonicalIndex,
2728
} from '@/lib/workflows/subblocks/visibility'
2829
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
2930
import {
@@ -47,7 +48,6 @@ import {
4748
} from '@/app/workspace/[workspaceId]/w/[workflowId]/utils/block-protection-utils'
4849
import { PreviewWorkflow } from '@/app/workspace/[workspaceId]/w/components/preview'
4950
import { getBlock } from '@/blocks/registry'
50-
import type { SubBlockType } from '@/blocks/types'
5151
import { useFolderMap } from '@/hooks/queries/folders'
5252
import { isWorkflowEffectivelyLocked } from '@/hooks/queries/utils/folder-tree'
5353
import { useWorkflowMap, useWorkflowState } from '@/hooks/queries/workflows'
@@ -154,12 +154,7 @@ export function Editor() {
154154
const subBlocksForCanonical = useMemo(() => {
155155
const subBlocks = blockConfig?.subBlocks || []
156156
if (!triggerMode) return subBlocks
157-
return subBlocks.filter(
158-
(subBlock) =>
159-
subBlock.mode === 'trigger' ||
160-
subBlock.mode === 'trigger-advanced' ||
161-
subBlock.type === ('trigger-config' as SubBlockType)
162-
)
157+
return subBlocks.filter(shouldUseSubBlockForTriggerModeCanonicalIndex)
163158
}, [blockConfig?.subBlocks, triggerMode])
164159

165160
const canonicalIndex = useMemo(

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
isSubBlockFeatureEnabled,
66
isSubBlockHidden,
77
isSubBlockVisibleForMode,
8+
isSubBlockVisibleForTriggerMode,
9+
shouldUseSubBlockForTriggerModeCanonicalIndex,
810
} from '@/lib/workflows/subblocks/visibility'
9-
import type { BlockConfig, SubBlockConfig, SubBlockType } from '@/blocks/types'
11+
import type { BlockConfig, SubBlockConfig } from '@/blocks/types'
1012
import { usePermissionConfig } from '@/hooks/use-permission-config'
1113
import { useReactiveConditions } from '@/hooks/use-reactive-conditions'
1214
import { useWorkflowDiffStore } from '@/stores/workflow-diff'
@@ -100,12 +102,7 @@ export function useEditorSubblockLayout(
100102
)
101103

102104
const subBlocksForCanonical = displayTriggerMode
103-
? (config.subBlocks || []).filter(
104-
(subBlock) =>
105-
subBlock.mode === 'trigger' ||
106-
subBlock.mode === 'trigger-advanced' ||
107-
subBlock.type === ('trigger-config' as SubBlockType)
108-
)
105+
? (config.subBlocks || []).filter(shouldUseSubBlockForTriggerModeCanonicalIndex)
109106
: config.subBlocks || []
110107
const canonicalIndex = buildCanonicalIndex(subBlocksForCanonical)
111108
const effectiveAdvanced = displayAdvancedMode
@@ -132,19 +129,7 @@ export function useEditorSubblockLayout(
132129
// Hide tool API key fields when hosted or when env var is set
133130
if (isSubBlockHidden(block)) return false
134131

135-
// Special handling for trigger-config type (legacy trigger configuration UI)
136-
if (block.type === ('trigger-config' as SubBlockType)) {
137-
const isPureTriggerBlock = config?.triggers?.enabled && config.category === 'triggers'
138-
return displayTriggerMode || isPureTriggerBlock
139-
}
140-
141-
// Filter by mode if specified
142-
if (block.mode === 'trigger' || block.mode === 'trigger-advanced') {
143-
if (!displayTriggerMode) return false
144-
}
145-
146-
// When in trigger mode, hide blocks that don't have mode: 'trigger' or 'trigger-advanced'
147-
if (displayTriggerMode && block.mode !== 'trigger' && block.mode !== 'trigger-advanced') {
132+
if (!isSubBlockVisibleForTriggerMode(block, displayTriggerMode, config)) {
148133
return false
149134
}
150135

apps/sim/lib/workflows/search-replace/indexer.test.ts

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ describe('indexWorkflowSearchMatches', () => {
172172
basicOnly: { id: 'basicOnly', type: 'short-input', value: 'visible-basic' },
173173
advancedOnly: { id: 'advancedOnly', type: 'short-input', value: 'hidden-advanced' },
174174
triggerOnly: { id: 'triggerOnly', type: 'short-input', value: 'hidden-trigger' },
175+
triggerManual: { id: 'triggerManual', type: 'short-input', value: 'hidden-trigger-manual' },
176+
triggerConfig: {
177+
id: 'triggerConfig',
178+
type: 'trigger-config',
179+
value: 'visible-trigger-config',
180+
},
175181
},
176182
}
177183
const blockConfigs = {
@@ -180,7 +186,21 @@ describe('indexWorkflowSearchMatches', () => {
180186
subBlocks: [
181187
{ id: 'basicOnly', title: 'Basic', type: 'short-input', mode: 'basic' },
182188
{ id: 'advancedOnly', title: 'Advanced', type: 'short-input', mode: 'advanced' },
183-
{ id: 'triggerOnly', title: 'Trigger', type: 'short-input', mode: 'trigger' },
189+
{
190+
id: 'triggerOnly',
191+
title: 'Trigger',
192+
type: 'short-input',
193+
mode: 'trigger',
194+
canonicalParamId: 'triggerValue',
195+
},
196+
{
197+
id: 'triggerManual',
198+
title: 'Trigger Manual',
199+
type: 'short-input',
200+
mode: 'trigger-advanced',
201+
canonicalParamId: 'triggerValue',
202+
},
203+
{ id: 'triggerConfig', title: 'Trigger Config', type: 'trigger-config' },
184204
],
185205
},
186206
}
@@ -215,7 +235,7 @@ describe('indexWorkflowSearchMatches', () => {
215235
workflow.blocks['mode-1'].triggerMode = true
216236
const triggerMatches = indexWorkflowSearchMatches({
217237
workflow,
218-
query: 'trigger',
238+
query: 'hidden-trigger',
219239
mode: 'text',
220240
blockConfigs,
221241
}).filter((match) => match.blockId === 'mode-1')
@@ -229,6 +249,23 @@ describe('indexWorkflowSearchMatches', () => {
229249
expect(triggerMatches).toHaveLength(1)
230250
expect(triggerMatches[0].subBlockId).toBe('triggerOnly')
231251
expect(nonTriggerMatches).toEqual([])
252+
253+
const triggerConfigMatches = indexWorkflowSearchMatches({
254+
workflow,
255+
query: 'trigger-config',
256+
mode: 'text',
257+
blockConfigs,
258+
}).filter((match) => match.blockId === 'mode-1')
259+
const triggerManualMatches = indexWorkflowSearchMatches({
260+
workflow,
261+
query: 'trigger-manual',
262+
mode: 'text',
263+
blockConfigs,
264+
}).filter((match) => match.blockId === 'mode-1')
265+
266+
expect(triggerConfigMatches).toHaveLength(1)
267+
expect(triggerConfigMatches[0].subBlockId).toBe('triggerConfig')
268+
expect(triggerManualMatches).toEqual([])
232269
})
233270

234271
it('does not index fixed-choice dropdown values as text replacements', () => {
@@ -1288,7 +1325,7 @@ describe('indexWorkflowSearchMatches', () => {
12881325
])
12891326
})
12901327

1291-
it('indexes object-valued fallback tool params by values without exposing metadata', () => {
1328+
it('indexes object-valued fallback tool params by leaf values', () => {
12921329
const workflow = createSearchReplaceWorkflowFixture()
12931330
workflow.blocks['tool-input-1'] = {
12941331
id: 'tool-input-1',
@@ -1329,7 +1366,7 @@ describe('indexWorkflowSearchMatches', () => {
13291366
mode: 'text',
13301367
blockConfigs,
13311368
}).filter((match) => match.blockId === 'tool-input-1')
1332-
const metadataMatches = indexWorkflowSearchMatches({
1369+
const typeMatches = indexWorkflowSearchMatches({
13331370
workflow,
13341371
query: 'metadata-type',
13351372
mode: 'text',
@@ -1344,7 +1381,14 @@ describe('indexWorkflowSearchMatches', () => {
13441381
searchText: 'open customer',
13451382
}),
13461383
])
1347-
expect(metadataMatches).toEqual([])
1384+
expect(typeMatches).toEqual([
1385+
expect.objectContaining({
1386+
subBlockId: 'tools',
1387+
subBlockType: 'workflow-input-mapper',
1388+
valuePath: [0, 'params', 'payload', 'type'],
1389+
searchText: 'metadata-type',
1390+
}),
1391+
])
13481392
})
13491393

13501394
it('indexes visible tool params ending in key', () => {

apps/sim/lib/workflows/search-replace/indexer.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ import {
3030
isSubBlockFeatureEnabled,
3131
isSubBlockHidden,
3232
isSubBlockVisibleForMode,
33+
isSubBlockVisibleForTriggerMode,
3334
normalizeDependencyValue,
3435
parseDependsOn,
3536
resolveDependencyValue,
37+
shouldUseSubBlockForTriggerModeCanonicalIndex,
3638
} from '@/lib/workflows/subblocks/visibility'
3739
import { isSyntheticToolSubBlockId } from '@/lib/workflows/tool-input/synthetic-subblocks'
3840
import { type ParsedStoredTool, parseStoredToolInputValue } from '@/lib/workflows/tool-input/types'
@@ -911,12 +913,14 @@ function isReactiveSearchSubBlockVisible({
911913

912914
function isSearchSubBlockVisibleForMode({
913915
block,
916+
blockConfig,
914917
subBlockConfig,
915918
subBlockValues,
916919
canonicalIndex,
917920
canonicalModes,
918921
}: {
919922
block: WorkflowSearchBlockState
923+
blockConfig?: NonNullable<WorkflowSearchIndexerOptions['blockConfigs']>[string]
920924
subBlockConfig?: WorkflowSearchSubBlockConfig
921925
subBlockValues: Record<string, unknown>
922926
canonicalIndex: ReturnType<typeof buildCanonicalIndex>
@@ -925,11 +929,15 @@ function isSearchSubBlockVisibleForMode({
925929
if (!subBlockConfig) return true
926930

927931
const displayTriggerMode = Boolean(block.triggerMode)
928-
const isTriggerSubBlock =
929-
subBlockConfig.mode === 'trigger' || subBlockConfig.mode === 'trigger-advanced'
930-
931-
if (isTriggerSubBlock) return displayTriggerMode
932-
if (displayTriggerMode) return false
932+
if (
933+
!isSubBlockVisibleForTriggerMode(
934+
subBlockConfig as SubBlockConfig,
935+
displayTriggerMode,
936+
blockConfig
937+
)
938+
) {
939+
return false
940+
}
933941

934942
return isSubBlockVisibleForMode(
935943
subBlockConfig as SubBlockConfig,
@@ -965,12 +973,7 @@ export function indexWorkflowSearchMatches(
965973
const blockConfig = blockConfigs[block.type] ?? getBlock(block.type)
966974
const subBlockConfigs = blockConfig?.subBlocks ?? []
967975
const canonicalSubBlockConfigs = block.triggerMode
968-
? subBlockConfigs.filter(
969-
(subBlock) =>
970-
subBlock.mode === 'trigger' ||
971-
subBlock.mode === 'trigger-advanced' ||
972-
subBlock.type === ('trigger-config' as SubBlockType)
973-
)
976+
? subBlockConfigs.filter(shouldUseSubBlockForTriggerModeCanonicalIndex)
974977
: subBlockConfigs
975978
const configsById = new Map(subBlockConfigs.map((subBlock) => [subBlock.id, subBlock]))
976979
const canonicalIndex = buildCanonicalIndex(canonicalSubBlockConfigs)
@@ -1012,6 +1015,7 @@ export function indexWorkflowSearchMatches(
10121015
if (
10131016
!isSearchSubBlockVisibleForMode({
10141017
block,
1018+
blockConfig,
10151019
subBlockConfig,
10161020
subBlockValues,
10171021
canonicalIndex,

apps/sim/lib/workflows/search-replace/json-value-fields.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ const SEARCHABLE_JSON_OBJECT_VALUE_FIELDS: Partial<Record<SubBlockType, string>>
2929
'workflow-input-mapper': 'Value',
3030
}
3131

32-
const JSON_METADATA_KEYS = new Set([
33-
'collapsed',
34-
'fieldType',
35-
'id',
36-
'operator',
37-
'tagName',
38-
'type',
39-
'variableId',
40-
'variableName',
41-
])
42-
4332
const SERIALIZED_SUBBLOCK_VALUE_TYPES = new Set<SubBlockType>([
4433
'file-upload',
4534
'grouped-checkbox-list',
@@ -102,10 +91,9 @@ function getObjectStringLeaves({
10291

10392
if (!value || typeof value !== 'object') return []
10493

105-
return Object.entries(value).flatMap(([fieldKey, fieldValue]) => {
106-
if (JSON_METADATA_KEYS.has(fieldKey)) return []
107-
return getObjectStringLeaves({ value: fieldValue, path: [...path, fieldKey], fieldTitle })
108-
})
94+
return Object.entries(value).flatMap(([fieldKey, fieldValue]) =>
95+
getObjectStringLeaves({ value: fieldValue, path: [...path, fieldKey], fieldTitle })
96+
)
10997
}
11098

11199
export function isSearchableJsonValueSubBlock(

0 commit comments

Comments
 (0)