Skip to content

Commit 20b621d

Browse files
waleedlatif1claude
andcommitted
fix(selectors): replace hacky prefix stripping with explicit CANONICAL_TO_CONTEXT mapping
Replace CONTEXT_FIELD_SET (Record<string, true>) with CANONICAL_TO_CONTEXT (Record<string, keyof SelectorContext>) that explicitly maps canonical param IDs to their SelectorContext field names. This properly handles the selected_ prefix aliases (e.g. selected_baseId → baseId) without string manipulation, and removes the unsafe Record<string, unknown> cast. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fe812d3 commit 20b621d

File tree

1 file changed

+28
-19
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks

1 file changed

+28
-19
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-selector-setup.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ export function useSelectorSetup(
5151
if (canonicalParamId === 'oauthCredential') {
5252
context.credentialId = strValue
5353
} else {
54-
const contextField = canonicalParamId.startsWith('selected_')
55-
? canonicalParamId.slice('selected_'.length)
56-
: canonicalParamId
57-
if (contextField in CONTEXT_FIELD_SET) {
58-
;(context as Record<string, unknown>)[contextField] = strValue
54+
const contextField = CANONICAL_TO_CONTEXT[canonicalParamId]
55+
if (contextField) {
56+
context[contextField] = strValue
5957
}
6058
}
6159
}
@@ -72,18 +70,29 @@ export function useSelectorSetup(
7270
}
7371
}
7472

75-
const CONTEXT_FIELD_SET: Record<string, true> = {
76-
credentialId: true,
77-
domain: true,
78-
teamId: true,
79-
projectId: true,
80-
knowledgeBaseId: true,
81-
planId: true,
82-
siteId: true,
83-
collectionId: true,
84-
spreadsheetId: true,
85-
fileId: true,
86-
baseId: true,
87-
datasetId: true,
88-
serviceDeskId: true,
73+
/**
74+
* Maps canonical param IDs to SelectorContext field names.
75+
*
76+
* Most canonical param IDs match their SelectorContext field directly (e.g. `siteId` → `siteId`).
77+
* Aliased entries handle cases where `canonicalParamId` was prefixed with `selected_` to avoid
78+
* clashing with a subBlock `id` of the same name.
79+
*/
80+
const CANONICAL_TO_CONTEXT: Record<string, keyof SelectorContext> = {
81+
credentialId: 'credentialId',
82+
domain: 'domain',
83+
teamId: 'teamId',
84+
projectId: 'projectId',
85+
knowledgeBaseId: 'knowledgeBaseId',
86+
planId: 'planId',
87+
siteId: 'siteId',
88+
collectionId: 'collectionId',
89+
spreadsheetId: 'spreadsheetId',
90+
fileId: 'fileId',
91+
baseId: 'baseId',
92+
datasetId: 'datasetId',
93+
serviceDeskId: 'serviceDeskId',
94+
selected_baseId: 'baseId',
95+
selected_datasetId: 'datasetId',
96+
selected_serviceDeskId: 'serviceDeskId',
97+
selected_planId: 'planId',
8998
}

0 commit comments

Comments
 (0)