@@ -2,7 +2,6 @@ import * as React from 'react'
22// @ts -expect-error No types available
33import * as VelocityReact from 'velocity-react'
44import { i18nTranslator } from '../i18n'
5- import { IContextMenuContext } from '../RundownView'
65import { translateMessage } from '@sofie-automation/corelib/dist/TranslatableMessage'
76import { doUserAction , UserAction } from '../../lib/clientUserAction'
87import { MeteorCall } from '../../lib/meteorApi'
@@ -24,20 +23,13 @@ import { useTranslation } from 'react-i18next'
2423import { useTracker } from '../../lib/ReactMeteorData/ReactMeteorData'
2524import _ from 'underscore'
2625import { Segments } from '../../collections'
27- import { UIParts } from '../Collections'
26+ import { UIPartInstances , UIParts } from '../Collections'
2827import { useSelection } from '../RundownView/SelectedElementsContext'
28+ import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
29+ import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
30+ import { RundownId } from '@sofie-automation/corelib/dist/dataModel/Ids'
2931
30- /**
31- * Propertiespanel PopUp props.
32- */
33- interface Props {
34- // Currently selected context menu context
35- // Plan is to replace this with a more specific selection of what is selected in the UI
36- // When selected element for propertiesPanel has been implemented
37- contextMenuContext : IContextMenuContext | null
38- }
39-
40- export function PropertiesPanel ( props : Props ) : JSX . Element {
32+ export function PropertiesPanel ( ) : JSX . Element {
4133 const { listSelectedElements } = useSelection ( )
4234 console . log ( 'listSelectedElements' , listSelectedElements ( ) )
4335 const selectedElement = listSelectedElements ( ) ?. [ 0 ]
@@ -54,14 +46,19 @@ export function PropertiesPanel(props: Props): JSX.Element {
5446 }
5547 } , [ ] )
5648
57- const rundownId = props . contextMenuContext ?. segment ?. rundownId
58- const part = useTracker ( ( ) => UIParts . findOne ( { _id : selectedElement . elementId } ) , [ selectedElement . elementId ] )
49+ const partInstance = useTracker (
50+ ( ) => UIPartInstances . findOne ( { _id : selectedElement . elementId } ) ,
51+ [ selectedElement . elementId ]
52+ )
53+ const part = useTracker ( ( ) => UIParts . findOne ( { _id : partInstance ?. part . _id } ) , [ partInstance ?. part . _id ] )
5954
60- console . log ( 'Context Segment id' , props . contextMenuContext ?. segment ?. _id )
61- const segment = useTracker (
62- ( ) => Segments . findOne ( { rundownId : rundownId , _id : selectedElement . elementId } ) ,
55+ const segment : DBSegment | undefined = useTracker (
56+ ( ) => Segments . findOne ( { _id : part ? part . segmentId : selectedElement . elementId } ) ,
6357 [ selectedElement . elementId ]
6458 )
59+ const rundownId = part ? part . rundownId : segment ?. rundownId
60+
61+ if ( ! rundownId ) return < > </ >
6562
6663 return (
6764 < div className = "propertiespanel-pop-up" >
@@ -94,15 +91,19 @@ export function PropertiesPanel(props: Props): JSX.Element {
9491 < EditingTypeAction
9592 key = { i }
9693 userEditOperation = { userEditOperation }
97- contextMenuContext = { props . contextMenuContext }
94+ segment = { segment }
95+ part = { part }
96+ rundownId = { rundownId }
9897 />
9998 )
10099 case UserEditingType . FORM :
101100 return (
102101 < EditingTypeChangeSource
103102 key = { i }
104103 userEditOperation = { userEditOperation }
105- contextMenuContext = { props . contextMenuContext }
104+ segment = { segment }
105+ part = { part }
106+ rundownId = { rundownId }
106107 />
107108 )
108109 default :
@@ -143,15 +144,19 @@ export function PropertiesPanel(props: Props): JSX.Element {
143144 < EditingTypeAction
144145 key = { i }
145146 userEditOperation = { userEditOperation }
146- contextMenuContext = { props . contextMenuContext }
147+ segment = { segment }
148+ part = { part }
149+ rundownId = { rundownId }
147150 />
148151 )
149152 case UserEditingType . FORM :
150153 return (
151154 < EditingTypeChangeSource
152155 key = { i }
153156 userEditOperation = { userEditOperation }
154- contextMenuContext = { props . contextMenuContext }
157+ segment = { segment }
158+ part = { part }
159+ rundownId = { rundownId }
155160 />
156161 )
157162 default :
@@ -196,7 +201,9 @@ export function PropertiesPanel(props: Props): JSX.Element {
196201
197202function EditingTypeAction ( props : {
198203 userEditOperation : CoreUserEditingDefinitionAction
199- contextMenuContext : IContextMenuContext | null
204+ segment : DBSegment | undefined
205+ part : DBPart | undefined
206+ rundownId : RundownId
200207} ) {
201208 if ( ! props . userEditOperation . buttonType ) return null
202209 switch ( props . userEditOperation . buttonType ) {
@@ -213,8 +220,8 @@ function EditingTypeAction(props: {
213220 //@ts -expect-error TODO: Fix this
214221 props . contextMenuContext ?. segment ?. rundownId ,
215222 {
216- segmentExternalId : props . contextMenuContext ?. segment ?. externalId ,
217- partExternalId : props . contextMenuContext ?. part ?. instance . part . externalId ,
223+ segmentExternalId : props . segment ?. externalId ,
224+ partExternalId : props . part ?. externalId ,
218225 pieceExternalId : undefined ,
219226 } ,
220227 {
@@ -246,8 +253,8 @@ function EditingTypeAction(props: {
246253 //@ts -expect-error TODO: Fix this
247254 props . contextMenuContext ?. segment ?. rundownId ,
248255 {
249- segmentExternalId : props . contextMenuContext ?. segment ?. externalId ,
250- partExternalId : props . contextMenuContext ?. part ?. instance . part . externalId ,
256+ segmentExternalId : props . segment ?. externalId ,
257+ partExternalId : props . part ?. externalId ,
251258 pieceExternalId : undefined ,
252259 } ,
253260 {
@@ -282,7 +289,9 @@ function EditingTypeAction(props: {
282289
283290function EditingTypeChangeSource ( props : {
284291 userEditOperation : CoreUserEditingDefinitionForm
285- contextMenuContext : IContextMenuContext | null
292+ segment : DBSegment | undefined
293+ part : DBPart | undefined
294+ rundownId : RundownId
286295} ) {
287296 const { t } = useTranslation ( )
288297 const [ selectedSource , setSelectedSource ] = React . useState < Record < string , string > > (
@@ -371,8 +380,8 @@ function EditingTypeChangeSource(props: {
371380 //@ts -expect-error TODO: Fix this
372381 props . contextMenuContext ?. segment ?. rundownId ,
373382 {
374- segmentExternalId : props . contextMenuContext ?. segment ?. externalId ,
375- partExternalId : props . contextMenuContext ?. part ?. instance . part . externalId ,
383+ segmentExternalId : props . segment ?. externalId ,
384+ partExternalId : props . part ?. externalId ,
376385 pieceExternalId : undefined ,
377386 } ,
378387 {
@@ -395,18 +404,3 @@ function EditingTypeChangeSource(props: {
395404 </ >
396405 )
397406}
398-
399- // This is simmilar implementation as the function in SegmentContextMenu.tsx
400- // and is used to check if a segment or a part is used.
401- // A better implementation of what is selected in the UI should be implemented.
402- function getTimePosition ( contextMenuContext : IContextMenuContext ) : number | null {
403- let offset = 0
404- if ( contextMenuContext && contextMenuContext . partDocumentOffset ) {
405- const left = contextMenuContext . partDocumentOffset . left || 0
406- const timeScale = contextMenuContext . timeScale || 1
407- const menuPosition = contextMenuContext . mousePosition || { left }
408- offset = ( menuPosition . left - left ) / timeScale
409- return offset
410- }
411- return null
412- }
0 commit comments