(field, value)
| 53 | // Coerce a form value to the backend's storage shape so equality |
| 54 | // comparisons against channel data don't drift on type mismatches. |
| 55 | export const normalizeFieldValue = (field, value) => { |
| 56 | if (value === '' || value === null || value === undefined || value === '-1') { |
| 57 | return null; |
| 58 | } |
| 59 | // The stream_profile and logo pickers encode "(use default)" as '0', |
| 60 | // which is semantically a null FK on the Channel row. |
| 61 | if ((field === 'stream_profile_id' || field === 'logo_id') && value === '0') { |
| 62 | return null; |
| 63 | } |
| 64 | if (field === 'channel_number') { |
| 65 | const n = parseFloat(value); |
| 66 | return Number.isFinite(n) ? n : null; |
| 67 | } |
| 68 | if ( |
| 69 | field === 'channel_group_id' || |
| 70 | field === 'logo_id' || |
| 71 | field === 'epg_data_id' || |
| 72 | field === 'stream_profile_id' |
| 73 | ) { |
| 74 | const n = parseInt(value, 10); |
| 75 | return Number.isFinite(n) ? n : null; |
| 76 | } |
| 77 | return value; |
| 78 | }; |
| 79 | |
| 80 | // Per-field form shape for FK pickers (string for popovers, raw for |
| 81 | // the EPG select); used by the reset-to-provider affordance. |
no outgoing calls
no test coverage detected