@@ -12,9 +12,10 @@ import { PartInstance } from '@sofie-automation/meteor-lib/dist/collections/Part
1212import { literal } from 'shuttle-webhid'
1313import { Notifications } from '../../collections'
1414import { getIgnorePieceContentStatus } from '../../lib/localStorage'
15- import { UISegmentPartNotes , UIPieceContentStatuses , UIPartInstances } from '../Collections'
15+ import { UISegmentPartNotes , UIPieceContentStatuses , UIPartInstances , UIParts } from '../Collections'
1616import { useTracker } from '../../lib/ReactMeteorData/ReactMeteorData'
1717import type { ITranslatableMessage } from '@sofie-automation/corelib/dist/TranslatableMessage'
18+ import type { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
1819
1920export interface SegmentHeaderNotesProps {
2021 /** Override the classname of the root div */
@@ -77,7 +78,7 @@ function getReactivePieceNoteCountsForSegment(segmentId: SegmentId): SegmentNote
7778 const segmentNoteCounts : SegmentNoteCounts = {
7879 criticalNotes : 0 ,
7980 warningNotes : 0 ,
80- headerNotes : [ ] , // TODO - define
81+ headerNotes : [ ] ,
8182 }
8283
8384 const rawNotes = UISegmentPartNotes . find ( { segmentId } , { fields : { note : 1 } } ) . fetch ( ) as Pick <
@@ -144,9 +145,15 @@ function getReactivePieceNoteCountsForSegment(segmentId: SegmentId): SegmentNote
144145 {
145146 fields : {
146147 _id : 1 ,
148+ // @ts -expect-error deep property
149+ 'part._id' : 1 ,
150+ 'part._rank' : 1 ,
151+ 'part.segmentHeaderNotes' : 1 ,
147152 } ,
148153 }
149- ) . fetch ( ) as Array < Pick < PartInstance , '_id' > >
154+ ) . fetch ( ) as Array <
155+ Pick < PartInstance , '_id' > & { part : Pick < PartInstance [ 'part' ] , '_id' | '_rank' | 'segmentHeaderNotes' > }
156+ >
150157 const rawNotifications = Notifications . find (
151158 {
152159 $or : [
@@ -179,5 +186,37 @@ function getReactivePieceNoteCountsForSegment(segmentId: SegmentId): SegmentNote
179186 }
180187 }
181188
189+ const partsForSegment = UIParts . find (
190+ { segmentId } ,
191+ {
192+ fields : {
193+ _id : 1 ,
194+ _rank : 1 ,
195+ segmentHeaderNotes : 1 ,
196+ } ,
197+ }
198+ ) . fetch ( ) as Array < Pick < DBPart , '_id' | '_rank' | 'segmentHeaderNotes' > >
199+
200+ // Collect the segment header notes from the parts in part rank order, with partinstance taking priority over the part
201+ const partIdsWithInstance = new Set ( partInstancesForSegment . map ( ( pi ) => pi . part . _id ) )
202+
203+ const mergedNoteEntries : Array < { rank : number ; notes : ITranslatableMessage [ ] } > = [ ]
204+ for ( const partInstance of partInstancesForSegment ) {
205+ if ( partInstance . part . segmentHeaderNotes ?. length ) {
206+ mergedNoteEntries . push ( { rank : partInstance . part . _rank , notes : partInstance . part . segmentHeaderNotes } )
207+ }
208+ }
209+ for ( const part of partsForSegment ) {
210+ if ( partIdsWithInstance . has ( part . _id ) ) continue
211+ if ( part . segmentHeaderNotes ?. length ) {
212+ mergedNoteEntries . push ( { rank : part . _rank , notes : part . segmentHeaderNotes } )
213+ }
214+ }
215+
216+ mergedNoteEntries . sort ( ( a , b ) => a . rank - b . rank )
217+ for ( const entry of mergedNoteEntries ) {
218+ segmentNoteCounts . headerNotes . push ( ...entry . notes )
219+ }
220+
182221 return segmentNoteCounts
183222}
0 commit comments