(direction: 'up' | 'down')
| 287 | } |
| 288 | } |
| 289 | function handleNavigation(direction: 'up' | 'down'): void { |
| 290 | // Collapse accordion and validate on navigate away |
| 291 | if (currentField && isMultiSelectEnumSchema(currentField.schema)) { |
| 292 | validateMultiSelect(currentField.name, currentField.schema); |
| 293 | setExpandedAccordion(undefined); |
| 294 | } else if (currentField && isEnumSchema(currentField.schema)) { |
| 295 | setExpandedAccordion(undefined); |
| 296 | } |
| 297 | |
| 298 | // Commit current text field before navigating away |
| 299 | if (isEditingTextField && currentField) { |
| 300 | commitTextField(currentField.name, currentField.schema, textInputValue); |
| 301 | |
| 302 | // Cancel any pending debounce — we're resolving now on navigate-away |
| 303 | if (dateDebounceRef.current !== undefined) { |
| 304 | clearTimeout(dateDebounceRef.current); |
| 305 | dateDebounceRef.current = undefined; |
| 306 | } |
| 307 | |
| 308 | // For date/datetime fields that failed sync validation, try async NL parsing |
| 309 | if (isDateTimeSchema(currentField.schema) && textInputValue.trim() !== '' && validationErrors[currentField.name]) { |
| 310 | resolveFieldAsync(currentField.name, currentField.schema, textInputValue); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | // Fields + accept + decline |
| 315 | const itemCount = schemaFields.length + 2; |
| 316 | const index = currentFieldIndex ?? (focusedButton === 'accept' ? schemaFields.length : focusedButton === 'decline' ? schemaFields.length + 1 : undefined); |
| 317 | const nextIndex = index !== undefined ? (index + (direction === 'up' ? itemCount - 1 : 1)) % itemCount : 0; |
| 318 | if (nextIndex < schemaFields.length) { |
| 319 | setCurrentFieldIndex(nextIndex); |
| 320 | setFocusedButton(null); |
| 321 | syncTextInput(nextIndex); |
| 322 | } else { |
| 323 | setCurrentFieldIndex(undefined); |
| 324 | setFocusedButton(nextIndex === schemaFields.length ? 'accept' : 'decline'); |
| 325 | setTextInputValue(''); |
| 326 | } |
| 327 | } |
| 328 | function setField(fieldName_0: string, value: number | string | boolean | string[] | undefined) { |
| 329 | setFormValues(prev => { |
| 330 | const next = { |
no test coverage detected