{ __( 'No rules yet. Add a rule to control when this field is shown.', 'profile-builder' ) }
) } { rules.map( ( rule, index ) => { const sourceField = sourcesById[ Number( rule.field ) ]; const isNumericSource = sourceField && config.numericFieldTypes.includes( sourceField.fieldType ); const ruleFieldId = rule.field ? Number( rule.field ) : 0; // A rule references an off-form field when the picked // source isn't on the current canvas. Covers both: // (a) source picked from the global list that was never // added to this form; (b) source previously added and // since removed (the rule survives in attributes). const refsOffFormField = !! ruleFieldId && ( ! sourceField || ! sourceField.inForm ); // In-form vs off-form groups; disabled options are section headings. const formatLabel = ( f ) => `${ f.title } [${ f.fieldType }]`; const inFormSources = groupedSources.inForm; const offFormSources = groupedSources.offForm; const fieldOptions = [ { label: __( 'Choose…', 'profile-builder' ), value: '' }, ]; if ( inFormSources.length ) { // Only label the in-form group when there's an // off-form group to contrast against — otherwise // the heading is noise. if ( offFormSources.length ) { fieldOptions.push( { value: '__hdr_in_form__', label: '── ' + __( 'In this form', 'profile-builder' ) + ' ──', disabled: true, } ); } inFormSources.forEach( ( f ) => fieldOptions.push( { value: String( f.id ), label: formatLabel( f ), } ) ); } if ( offFormSources.length ) { // Always label the off-form group so the user // sees the boundary even if no in-form fields // exist yet (e.g. empty form, references picked // from the global list). fieldOptions.push( { value: '__hdr_off_form__', label: '── ' + __( 'Not in this form', 'profile-builder' ) + ' ──', disabled: true, } ); offFormSources.forEach( ( f ) => fieldOptions.push( { value: String( f.id ), label: formatLabel( f ), } ) ); } // Reference to a field that no longer exists anywhere // (deleted from the global list) — surface it in the // dropdown under its own heading so the user can see // what the rule pointed at and pick something else. if ( ruleFieldId && ! sourceField ) { fieldOptions.push( { value: '__hdr_missing__', label: '── ' + __( 'Missing field', 'profile-builder' ) + ' ──', disabled: true, } ); fieldOptions.push( { value: String( ruleFieldId ), label: `(${ __( 'missing field', 'profile-builder' ) } #${ ruleFieldId })`, } ); } const operatorLabels = OPERATOR_LABELS(); const operatorOptions = OPERATORS.map( ( op ) => ( { label: operatorLabels[ op ] || op, value: op, disabled: NUMERIC_OPERATORS.includes( op ) && sourceField && ! isNumericSource, } ) ); return (