(channels, labelFn)
| 65 | * @param {(item: object) => string} [labelFn] defaults to `name || "Channel id"` |
| 66 | */ |
| 67 | export const sortedChannelOptions = (channels, labelFn) => { |
| 68 | const list = Array.isArray(channels) |
| 69 | ? channels |
| 70 | : Object.values(channels || {}); |
| 71 | |
| 72 | const defaultLabel = (item) => item.name || `Channel ${item.id}`; |
| 73 | |
| 74 | return [...list] |
| 75 | .sort((a, b) => { |
| 76 | const aNum = Number(a.channel_number) || 0; |
| 77 | const bNum = Number(b.channel_number) || 0; |
| 78 | if (aNum !== bNum) return aNum - bNum; |
| 79 | return (a.name || '').localeCompare(b.name || ''); |
| 80 | }) |
| 81 | .map((item) => ({ |
| 82 | value: String(item.id), |
| 83 | label: (labelFn ?? defaultLabel)(item), |
| 84 | })); |
| 85 | }; |
| 86 | |
| 87 | /** Label that includes the channel number prefix used in Recording/SeriesRule UIs. */ |
| 88 | export const numberedChannelLabel = (item) => |
no outgoing calls
no test coverage detected