|
| 1 | +import { useTranslation } from 'react-i18next' |
| 2 | +import { useTracker } from '../../../../../../../lib/ReactMeteorData/ReactMeteorData' |
| 3 | +import { Studios } from '../../../../../../../collections' |
| 4 | +import { DropdownInputControl, DropdownInputOption } from '../../../../../../../lib/Components/DropdownInput' |
| 5 | +import { SwitchRouteSetProps } from '@sofie-automation/corelib/dist/worker/studio' |
| 6 | +import { applyAndValidateOverrides } from '@sofie-automation/corelib/dist/settings/objectWithOverrides' |
| 7 | +import { StudioRouteSet } from '@sofie-automation/blueprints-integration' |
| 8 | + |
| 9 | +export function SwitchRouteSetEditor({ |
| 10 | + action, |
| 11 | + onChange, |
| 12 | +}: Readonly<{ |
| 13 | + action: SwitchRouteSetProps |
| 14 | + onChange: (newVal: Partial<typeof action>) => void |
| 15 | +}>): JSX.Element | null { |
| 16 | + const { t } = useTranslation() |
| 17 | + const allRouteSetOptions = useTracker<DropdownInputOption<string>[]>( |
| 18 | + () => { |
| 19 | + const studios = Studios.find({}, { sort: { name: 1 } }).fetch() |
| 20 | + const routeSetOptions = studios.flatMap((studio) => { |
| 21 | + const routeSets = applyAndValidateOverrides(studio.routeSetsWithOverrides).obj |
| 22 | + return Object.entries<StudioRouteSet>(routeSets).map( |
| 23 | + ([id, routeSet]): Omit<DropdownInputOption<string>, 'i'> => ({ |
| 24 | + value: id, |
| 25 | + name: studios.length > 1 ? `${studio.name} - ${routeSet.name}` : routeSet.name, |
| 26 | + }) |
| 27 | + ) |
| 28 | + }) |
| 29 | + |
| 30 | + return routeSetOptions.map((option, i): DropdownInputOption<string> => ({ ...option, i })) |
| 31 | + }, |
| 32 | + [], |
| 33 | + [] |
| 34 | + ) |
| 35 | + |
| 36 | + return ( |
| 37 | + <> |
| 38 | + <div className="mts"> |
| 39 | + <label className="block">{t('Route Set')}</label> |
| 40 | + <DropdownInputControl<typeof action.routeSetId> |
| 41 | + classNames="input text-input input-m" |
| 42 | + value={action.routeSetId} |
| 43 | + options={allRouteSetOptions} |
| 44 | + handleUpdate={(newVal) => { |
| 45 | + onChange({ |
| 46 | + ...action, |
| 47 | + routeSetId: newVal, |
| 48 | + }) |
| 49 | + }} |
| 50 | + /> |
| 51 | + </div> |
| 52 | + |
| 53 | + <div className="mts"> |
| 54 | + <label className="block">{t('State')}</label> |
| 55 | + <DropdownInputControl<typeof action.state> |
| 56 | + classNames="input text-input input-m" |
| 57 | + value={action.state} |
| 58 | + options={[ |
| 59 | + { |
| 60 | + name: t('Enabled'), |
| 61 | + value: true, |
| 62 | + i: 0, |
| 63 | + }, |
| 64 | + { |
| 65 | + name: t('Disabled'), |
| 66 | + value: false, |
| 67 | + i: 1, |
| 68 | + }, |
| 69 | + { |
| 70 | + name: t('Toggle'), |
| 71 | + value: 'toggle', |
| 72 | + i: 2, |
| 73 | + }, |
| 74 | + ]} |
| 75 | + handleUpdate={(newVal) => { |
| 76 | + onChange({ |
| 77 | + ...action, |
| 78 | + state: newVal, |
| 79 | + }) |
| 80 | + }} |
| 81 | + /> |
| 82 | + </div> |
| 83 | + </> |
| 84 | + ) |
| 85 | +} |
0 commit comments