Skip to content

Commit 49165fe

Browse files
committed
fix(editor): pass current values to required field rules
1 parent 902d701 commit 49165fe

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { isEqual } from 'es-toolkit'
1212
import type { FilterRule, SortRule } from '@/lib/table/query-builder/constants'
1313
import type { FallbackModelEntry } from '@/lib/workflows/blocks/fallback-models'
14+
import { buildSubBlockValues } from '@/lib/workflows/subblocks/visibility'
1415
import { useWorkflowScope } from '@/app/workspace/[workspaceId]/providers/workflow-scope-provider'
1516
import {
1617
CheckboxList,
@@ -121,10 +122,10 @@ interface SubBlockProps {
121122
* Supports boolean, condition objects, and functions that return conditions.
122123
*
123124
* @param config - The sub-block configuration containing requirement rules
124-
* @param subBlockValues - Current values of all subblocks for condition evaluation
125+
* @param values - Flat sibling values for condition evaluation
125126
* @returns `true` if the field is required based on current context
126127
*/
127-
const isFieldRequired = (config: SubBlockConfig, subBlockValues?: Record<string, any>): boolean => {
128+
const isFieldRequired = (config: SubBlockConfig, values?: Record<string, any>): boolean => {
128129
if (!config.required) return false
129130
if (typeof config.required === 'boolean') return config.required
130131

@@ -141,7 +142,7 @@ const isFieldRequired = (config: SubBlockConfig, subBlockValues?: Record<string,
141142
},
142143
values: Record<string, any>
143144
): boolean => {
144-
const fieldValue = values[cond.field]?.value
145+
const fieldValue = values[cond.field]
145146
const condValue = cond.value
146147

147148
let match: boolean
@@ -154,7 +155,7 @@ const isFieldRequired = (config: SubBlockConfig, subBlockValues?: Record<string,
154155
if (cond.not) match = !match
155156

156157
if (cond.and) {
157-
const andFieldValue = values[cond.and.field]?.value
158+
const andFieldValue = values[cond.and.field]
158159
const andCondValue = cond.and.value
159160
let andMatch: boolean
160161
if (Array.isArray(andCondValue)) {
@@ -169,8 +170,9 @@ const isFieldRequired = (config: SubBlockConfig, subBlockValues?: Record<string,
169170
return match
170171
}
171172

172-
const condition = typeof config.required === 'function' ? config.required() : config.required
173-
return evalCond(condition, subBlockValues || {})
173+
const condition =
174+
typeof config.required === 'function' ? config.required(values) : config.required
175+
return evalCond(condition, values || {})
174176
}
175177

176178
/**
@@ -199,7 +201,7 @@ const getPreviewValue = (
199201
*
200202
* @param config - The sub-block configuration defining the label content
201203
* @param isValidJson - Whether the JSON content is valid (for code blocks)
202-
* @param subBlockValues - Current values of all subblocks for evaluating conditional requirements
204+
* @param requiredValues - Flat sibling values for evaluating conditional requirements
203205
* @param wandState - State and handlers for the inline AI generate feature
204206
* @param canonicalToggle - Metadata and handlers for the basic/advanced mode toggle
205207
* @param canonicalToggleIsDisabled - Whether the canonical toggle is disabled (includes dependsOn gating)
@@ -210,7 +212,7 @@ const getPreviewValue = (
210212
const renderLabel = (
211213
config: SubBlockConfig,
212214
isValidJson: boolean,
213-
subBlockValues?: Record<string, any>,
215+
requiredValues?: Record<string, any>,
214216
wandState?: {
215217
isSearchActive: boolean
216218
searchQuery: string
@@ -246,7 +248,7 @@ const renderLabel = (
246248
if (config.type === 'switch') return null
247249
if (!config.title) return null
248250

249-
const required = isFieldRequired(config, subBlockValues)
251+
const required = isFieldRequired(config, requiredValues)
250252
const showWand = wandState?.isWandEnabled && !wandState.isPreview && !wandState.disabled
251253
const showCanonicalToggle = !!canonicalToggle && !wandState?.isPreview
252254
const showCopy = copyState?.showCopyButton && !wandState?.isPreview
@@ -617,6 +619,8 @@ function SubBlockComponent({
617619
| null
618620
| undefined
619621

622+
const requiredValues =
623+
dependencyContext ?? (subBlockValues ? buildSubBlockValues(subBlockValues) : undefined)
620624
const contextValues = dependencyContext ?? (isPreview ? subBlockValues : undefined)
621625

622626
const { finalDisabled: gatedDisabled } = useDependsOnGate(blockId, config, {
@@ -956,7 +960,7 @@ function SubBlockComponent({
956960
blockId={blockId}
957961
subBlock={config}
958962
disabled={isDisabled}
959-
required={isFieldRequired(config, subBlockValues)}
963+
required={isFieldRequired(config, requiredValues)}
960964
isPreview={isPreview}
961965
previewValue={previewValue}
962966
/>
@@ -1248,7 +1252,7 @@ function SubBlockComponent({
12481252
{renderLabel(
12491253
config,
12501254
isValidJson,
1251-
subBlockValues,
1255+
requiredValues,
12521256
{
12531257
isSearchActive,
12541258
searchQuery,

0 commit comments

Comments
 (0)