@@ -20,15 +20,14 @@ import { unprotectString } from '@sofie-automation/corelib/dist/protectedString'
2020import { SchemaFormWithOverrides } from '../../../../lib/forms/SchemaFormWithOverrides'
2121import { LabelActual , LabelAndOverrides } from '../../../../lib/Components/LabelAndOverrides'
2222import { getRandomString , literal } from '@sofie-automation/corelib/dist/lib'
23- import { PeripheralDevice } from '@sofie-automation/corelib/dist/dataModel/PeripheralDevice'
2423import { StudioDeviceSettings } from '@sofie-automation/corelib/dist/dataModel/Studio'
2524import {
2625 SomeObjectOverrideOp ,
2726 wrapDefaultObject ,
2827 ObjectOverrideSetOp ,
2928} from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
3029import Tooltip from 'rc-tooltip'
31- import { Studios } from '../../../../collections'
30+ import { PeripheralDevices , Studios } from '../../../../collections'
3231import { getHelpMode } from '../../../../lib/localStorage'
3332import { useTracker } from '../../../../lib/ReactMeteorData/ReactMeteorData'
3433import { TextInputControl } from '../../../../lib/Components/TextInput'
@@ -37,9 +36,8 @@ import { MeteorCall } from '../../../../lib/meteorApi'
3736
3837interface StudioParentDevicesProps {
3938 studioId : StudioId
40- studioDevices : PeripheralDevice [ ]
4139}
42- export function StudioParentDevices ( { studioId, studioDevices } : Readonly < StudioParentDevicesProps > ) : JSX . Element {
40+ export function StudioParentDevices ( { studioId } : Readonly < StudioParentDevicesProps > ) : JSX . Element {
4341 const { t } = useTranslation ( )
4442
4543 const studio = useTracker ( ( ) => Studios . findOne ( studioId ) , [ studioId ] )
@@ -75,11 +73,6 @@ export function StudioParentDevices({ studioId, studioDevices }: Readonly<Studio
7573 [ deviceSettings ]
7674 )
7775
78- const filteredPeripheralDevices = useMemo (
79- ( ) => studioDevices . filter ( ( d ) => d . parentDeviceId === undefined ) ,
80- [ studioDevices ]
81- )
82-
8376 const addNewItem = useCallback ( ( ) => {
8477 const newId = getRandomString ( )
8578 const newDevice = literal < StudioDeviceSettings > ( {
@@ -113,12 +106,7 @@ export function StudioParentDevices({ studioId, studioDevices }: Readonly<Studio
113106 </ Tooltip >
114107 </ h2 >
115108
116- < GenericParentDevicesTable
117- studioId = { studioId }
118- devices = { wrappedDeviceSettings }
119- overrideHelper = { overrideHelper }
120- peripheralDevices = { filteredPeripheralDevices }
121- />
109+ < GenericParentDevicesTable studioId = { studioId } devices = { wrappedDeviceSettings } overrideHelper = { overrideHelper } />
122110
123111 < div className = "mod mhs" >
124112 < button className = "btn btn-primary" onClick = { addNewItem } >
@@ -140,21 +128,22 @@ interface ParentDevicesTableProps {
140128 studioId : StudioId
141129 devices : WrappedOverridableItem < StudioDeviceSettings > [ ]
142130 overrideHelper : OverrideOpHelper
143- peripheralDevices : PeripheralDevice [ ]
144131}
145132function GenericParentDevicesTable ( {
146133 studioId,
147134 devices,
148135 overrideHelper,
149- peripheralDevices,
150136} : Readonly < ParentDevicesTableProps > ) : JSX . Element {
151137 const { t } = useTranslation ( )
152138 const { toggleExpanded, isExpanded } = useToggleExpandHelper ( )
153139
140+ const allParentDevices = useTracker ( ( ) => PeripheralDevices . find ( { parentDeviceId : undefined } ) . fetch ( ) , [ ] , [ ] )
141+
154142 const peripheralDevicesByConfigIdMap = useMemo ( ( ) => {
155143 const devicesMap = new Map < string , PeripheralDeviceTranslated > ( )
156144
157- for ( const device of peripheralDevices ) {
145+ for ( const device of allParentDevices ) {
146+ if ( device . studioId !== studioId ) continue
158147 if ( ! device . configId ) continue
159148
160149 devicesMap . set (
@@ -169,7 +158,7 @@ function GenericParentDevicesTable({
169158 }
170159
171160 return devicesMap
172- } , [ peripheralDevices ] )
161+ } , [ studioId , allParentDevices ] )
173162
174163 const confirmRemove = useCallback (
175164 ( parentdeviceId : string ) => {
@@ -205,7 +194,7 @@ function GenericParentDevicesTable({
205194 } ,
206195 ]
207196
208- for ( const device of peripheralDevices ) {
197+ for ( const device of allParentDevices ) {
209198 options . push ( {
210199 value : device . _id ,
211200 name : device . name || unprotectString ( device . _id ) ,
@@ -214,7 +203,7 @@ function GenericParentDevicesTable({
214203 }
215204
216205 return options
217- } , [ peripheralDevicesByConfigIdMap ] )
206+ } , [ allParentDevices ] )
218207
219208 const undeleteItemWithId = useCallback (
220209 ( itemId : string ) => overrideHelper ( ) . resetItem ( itemId ) . commit ( ) ,
0 commit comments