Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
signalsAsOptions = (signals: SignalObject[], groupBy: GroupBy = 'type') => {
const sortedSignals = {}
signals.forEach((signal) => {
if (!sortedSignals[signal[groupBy]]) sortedSignals[signal[groupBy]] = []
sortedSignals[signal[groupBy]].push(signal)
})
const optGroups = Object.keys(sortedSignals).map((groupName) => {
const groupLabel = `${groupName.replace(groupName[0], groupName[0].toUpperCase())} signals`
return (
<optgroup key={ groupName } label={ groupLabel }>
{
sortedSignals[groupName].map(signal => (
<option key={ signal.tagName } value={ signal.tagName }>
{ signal.longName }
</option>
))
}
</optgroup>
)
})
return [...optGroups]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.