Skip to content

Commit 33514b1

Browse files
committed
feat: allow adlib-actions to remove pieces from the current partInstance
1 parent 902e7ff commit 33514b1

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

packages/job-worker/src/blueprints/context/services/PartAndPieceInstanceActionService.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,15 @@ export class PartAndPieceInstanceActionService {
9595
this.showStyleCompound = showStyle
9696
}
9797

98-
private _getPartInstance(part: 'current' | 'next'): PlayoutPartInstanceModel | null {
98+
#trackStateChange(part: 'current' | 'next', change: ActionPartChange): void {
99+
if (part === 'current') {
100+
this.currentPartState = Math.max(this.currentPartState, change)
101+
} else {
102+
this.nextPartState = Math.max(this.nextPartState, change)
103+
}
104+
}
105+
106+
#getPartInstance(part: 'current' | 'next'): PlayoutPartInstanceModel | null {
99107
switch (part) {
100108
case 'current':
101109
return this._playoutModel.currentPartInstance
@@ -109,16 +117,16 @@ export class PartAndPieceInstanceActionService {
109117
}
110118

111119
async getPartInstance(part: 'current' | 'next'): Promise<IBlueprintPartInstance | undefined> {
112-
const partInstance = this._getPartInstance(part)
120+
const partInstance = this.#getPartInstance(part)
113121

114122
return partInstance ? convertPartInstanceToBlueprints(partInstance.partInstance) : undefined
115123
}
116124
async getPieceInstances(part: 'current' | 'next'): Promise<IBlueprintPieceInstance[]> {
117-
const partInstance = this._getPartInstance(part)
125+
const partInstance = this.#getPartInstance(part)
118126
return partInstance?.pieceInstances?.map((p) => convertPieceInstanceToBlueprints(p.pieceInstance)) ?? []
119127
}
120128
async getResolvedPieceInstances(part: 'current' | 'next'): Promise<IBlueprintResolvedPieceInstance[]> {
121-
const partInstance = this._getPartInstance(part)
129+
const partInstance = this.#getPartInstance(part)
122130
if (!partInstance) {
123131
return []
124132
}
@@ -244,7 +252,7 @@ export class PartAndPieceInstanceActionService {
244252
}
245253

246254
async insertPiece(part: 'current' | 'next', rawPiece: IBlueprintPiece): Promise<IBlueprintPieceInstance> {
247-
const partInstance = this._getPartInstance(part)
255+
const partInstance = this.#getPartInstance(part)
248256
if (!partInstance) {
249257
throw new Error('Cannot insert piece when no active part')
250258
}
@@ -270,11 +278,7 @@ export class PartAndPieceInstanceActionService {
270278
// Do the work
271279
const newPieceInstance = partInstance.insertAdlibbedPiece(piece, undefined)
272280

273-
if (part === 'current') {
274-
this.currentPartState = Math.max(this.currentPartState, ActionPartChange.SAFE_CHANGE)
275-
} else {
276-
this.nextPartState = Math.max(this.nextPartState, ActionPartChange.SAFE_CHANGE)
277-
}
281+
this.#trackStateChange(part, ActionPartChange.SAFE_CHANGE)
278282

279283
return convertPieceInstanceToBlueprints(newPieceInstance.pieceInstance)
280284
}
@@ -330,8 +334,8 @@ export class PartAndPieceInstanceActionService {
330334

331335
// setupPieceInstanceInfiniteProperties(pieceInstance)
332336

333-
this.nextPartState = Math.max(this.nextPartState, updatesNextPart)
334-
this.currentPartState = Math.max(this.currentPartState, updatesCurrentPart)
337+
this.#trackStateChange('next', updatesNextPart)
338+
this.#trackStateChange('current', updatesCurrentPart)
335339

336340
return convertPieceInstanceToBlueprints(pieceInstance.pieceInstance)
337341
}
@@ -340,7 +344,7 @@ export class PartAndPieceInstanceActionService {
340344
part: 'current' | 'next',
341345
props: Partial<IBlueprintMutatablePart>
342346
): Promise<IBlueprintPartInstance> {
343-
const partInstance = this._getPartInstance(part)
347+
const partInstance = this.#getPartInstance(part)
344348
if (!partInstance) {
345349
throw new Error('PartInstance could not be found')
346350
}
@@ -351,14 +355,7 @@ export class PartAndPieceInstanceActionService {
351355
throw new Error('Some valid properties must be defined')
352356
}
353357

354-
this.nextPartState = Math.max(
355-
this.nextPartState,
356-
part === 'next' ? ActionPartChange.SAFE_CHANGE : ActionPartChange.NONE
357-
)
358-
this.currentPartState = Math.max(
359-
this.currentPartState,
360-
part === 'current' ? ActionPartChange.SAFE_CHANGE : ActionPartChange.NONE
361-
)
358+
this.#trackStateChange(part, ActionPartChange.SAFE_CHANGE)
362359

363360
return convertPartInstanceToBlueprints(partInstance.partInstance)
364361
}
@@ -451,7 +448,7 @@ export class PartAndPieceInstanceActionService {
451448
}
452449

453450
async removePieceInstances(part: 'current' | 'next', pieceInstanceIds: string[]): Promise<string[]> {
454-
const partInstance = this._getPartInstance(part)
451+
const partInstance = this.#getPartInstance(part)
455452
if (!partInstance) {
456453
throw new Error('Cannot remove pieceInstances when no selected partInstance')
457454
}
@@ -466,7 +463,7 @@ export class PartAndPieceInstanceActionService {
466463
}
467464
}
468465

469-
this.nextPartState = Math.max(this.nextPartState, ActionPartChange.SAFE_CHANGE)
466+
this.#trackStateChange(part, ActionPartChange.SAFE_CHANGE)
470467

471468
return unprotectStringArray(removedPieceInstanceIds)
472469
}
@@ -505,7 +502,7 @@ export class PartAndPieceInstanceActionService {
505502
)
506503

507504
if (stoppedIds.length > 0) {
508-
this.currentPartState = Math.max(this.currentPartState, ActionPartChange.SAFE_CHANGE)
505+
this.#trackStateChange('current', ActionPartChange.SAFE_CHANGE)
509506
}
510507

511508
return unprotectStringArray(stoppedIds)

packages/job-worker/src/blueprints/context/services/__tests__/PartAndPieceInstanceActionService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ describe('Test blueprint api context', () => {
16661666

16671667
// Ensure it was all removed
16681668
expect(playoutModel.findPieceInstance(targetPieceInstance.pieceInstance._id)).toBeFalsy()
1669-
expect(service.nextPartState).toEqual(ActionPartChange.SAFE_CHANGE)
1669+
expect(service.currentPartState).toEqual(ActionPartChange.SAFE_CHANGE)
16701670
})
16711671
})
16721672
})

0 commit comments

Comments
 (0)