Skip to content

Commit 17be8be

Browse files
committed
wip: flow
1 parent 6b5a1f4 commit 17be8be

File tree

8 files changed

+106
-63
lines changed

8 files changed

+106
-63
lines changed

meteor/server/migration/0_1_0.ts

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { addMigrationSteps } from './databaseMigration'
22
import { logger } from '../logging'
3-
import { getRandomId, protectString, getHash } from '../lib/tempLib'
3+
import { getRandomId, protectString } from '../lib/tempLib'
44
import { wrapDefaultObject } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
55
import { ShowStyleVariantId } from '@sofie-automation/corelib/dist/dataModel/Ids'
6-
import { ShowStyleBases, ShowStyleVariants, Studios, TriggeredActions } from '../collections'
6+
import { ShowStyleBases, ShowStyleVariants, Studios } from '../collections'
77
import { DEFAULT_MINIMUM_TAKE_SPAN } from '@sofie-automation/shared-lib/dist/core/constants'
8-
import { DEFAULT_CORE_TRIGGERS } from './upgrades/defaultSystemActionTriggers'
98

109
/**
1110
* This file contains system specific migration steps.
@@ -131,32 +130,4 @@ export const addSteps = addMigrationSteps('0.1.0', [
131130
}
132131
},
133132
},
134-
{
135-
id: 'TriggeredActions.core',
136-
canBeRunAutomatically: true,
137-
validate: async () => {
138-
const coreTriggeredActionsCount = await TriggeredActions.countDocuments({
139-
showStyleBaseId: null,
140-
})
141-
142-
if (coreTriggeredActionsCount === 0) {
143-
return `No system-wide triggered actions set up.`
144-
}
145-
146-
return false
147-
},
148-
migrate: async () => {
149-
for (const triggeredAction of DEFAULT_CORE_TRIGGERS) {
150-
await TriggeredActions.insertAsync({
151-
_id: protectString(getHash(triggeredAction._id)),
152-
_rank: triggeredAction._rank,
153-
name: triggeredAction.name,
154-
blueprintUniqueId: null,
155-
showStyleBaseId: null,
156-
actionsWithOverrides: wrapDefaultObject(triggeredAction.actions),
157-
triggersWithOverrides: wrapDefaultObject(triggeredAction.triggers),
158-
})
159-
}
160-
},
161-
},
162133
])

meteor/server/migration/upgrades/context.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import { ICommonContext, NoteSeverity } from '@sofie-automation/blueprints-integration'
2-
import { assertNever, getHash } from '@sofie-automation/corelib/dist/lib'
1+
import {
2+
IBlueprintDefaultCoreSystemTriggers,
3+
ICommonContext,
4+
NoteSeverity,
5+
} from '@sofie-automation/blueprints-integration'
6+
import { assertNever, clone, getHash } from '@sofie-automation/corelib/dist/lib'
37
import { logger } from '../../logging'
8+
import { ICoreSystemApplyConfigContext } from '@sofie-automation/blueprints-integration/dist/context/systemApplyConfigContext'
9+
import { DEFAULT_CORE_TRIGGERS } from './defaultSystemActionTriggers'
410

511
/**
612
* This is almost identical to the one in the job-worker, but it is hard to share the implementation due to differing loggers
@@ -56,3 +62,9 @@ export class CommonContext implements ICommonContext {
5662
}
5763
}
5864
}
65+
66+
export class CoreSystemApplyConfigContext extends CommonContext implements ICoreSystemApplyConfigContext {
67+
getDefaultSystemActionTriggers(): IBlueprintDefaultCoreSystemTriggers {
68+
return clone(DEFAULT_CORE_TRIGGERS)
69+
}
70+
}

meteor/server/migration/upgrades/defaultSystemActionTriggers.ts

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,34 @@ import {
55
PlayoutActions,
66
} from '@sofie-automation/blueprints-integration'
77
import { getHash, protectString, generateTranslation as t } from '../../lib/tempLib'
8+
import { TriggeredActionId } from '@sofie-automation/corelib/dist/dataModel/Ids'
89

910
let j = 0
1011

11-
export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
12-
{
12+
export enum IBlueprintDefaultCoreTriggersType {
13+
toggleShelf = 'toggleShelf',
14+
activateRundownPlaylist = 'activateRundownPlaylist',
15+
activateRundownPlaylistRehearsal = 'activateRundownPlaylistRehearsal',
16+
deactivateRundownPlaylist = 'deactivateRundownPlaylist',
17+
take = 'take',
18+
hold = 'hold',
19+
holdUndo = 'holdUndo',
20+
resetRundownPlaylist = 'resetRundownPlaylist',
21+
disableNextPiece = 'disableNextPiece',
22+
disableNextPieceUndo = 'disableNextPieceUndo',
23+
createSnapshotForDebug = 'createSnapshotForDebug',
24+
moveNextPart = 'moveNextPart',
25+
moveNextSegment = 'moveNextSegment',
26+
movePreviousPart = 'movePreviousPart',
27+
movePreviousSegment = 'movePreviousSegment',
28+
goToOnAirLine = 'goToOnAirLine',
29+
rewindSegments = 'rewindSegments',
30+
}
31+
32+
export type IBlueprintDefaultCoreTriggers = { [key in IBlueprintDefaultCoreTriggersType]: IBlueprintTriggeredActions }
33+
34+
export const DEFAULT_CORE_TRIGGERS: IBlueprintDefaultCoreTriggers = {
35+
[IBlueprintDefaultCoreTriggersType.toggleShelf]: {
1336
_id: 'core_toggleShelf',
1437
actions: {
1538
'0': {
@@ -32,7 +55,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
3255
_rank: ++j * 1000,
3356
name: t('Toggle Shelf'),
3457
},
35-
{
58+
[IBlueprintDefaultCoreTriggersType.activateRundownPlaylist]: {
3659
_id: 'core_activateRundownPlaylist',
3760
actions: {
3861
'0': {
@@ -55,7 +78,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
5578
_rank: ++j * 1000,
5679
name: t('Activate (On-Air)'),
5780
},
58-
{
81+
[IBlueprintDefaultCoreTriggersType.activateRundownPlaylistRehearsal]: {
5982
_id: 'core_activateRundownPlaylist_rehearsal',
6083
actions: {
6184
'0': {
@@ -78,7 +101,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
78101
_rank: ++j * 1000,
79102
name: t('Activate (Rehearsal)'),
80103
},
81-
{
104+
[IBlueprintDefaultCoreTriggersType.deactivateRundownPlaylist]: {
82105
_id: 'core_deactivateRundownPlaylist',
83106
actions: {
84107
'0': {
@@ -100,7 +123,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
100123
_rank: ++j * 1000,
101124
name: t('Deactivate'),
102125
},
103-
{
126+
[IBlueprintDefaultCoreTriggersType.take]: {
104127
_id: 'core_take',
105128
actions: {
106129
'0': {
@@ -127,7 +150,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
127150
_rank: ++j * 1000,
128151
name: t('Take'),
129152
},
130-
{
153+
[IBlueprintDefaultCoreTriggersType.hold]: {
131154
_id: 'core_hold',
132155
actions: {
133156
'0': {
@@ -149,7 +172,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
149172
_rank: ++j * 1000,
150173
name: t('Hold'),
151174
},
152-
{
175+
[IBlueprintDefaultCoreTriggersType.holdUndo]: {
153176
_id: 'core_hold_undo',
154177
actions: {
155178
'0': {
@@ -172,7 +195,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
172195
_rank: ++j * 1000,
173196
name: t('Undo Hold'),
174197
},
175-
{
198+
[IBlueprintDefaultCoreTriggersType.resetRundownPlaylist]: {
176199
_id: 'core_reset_rundown_playlist',
177200
actions: {
178201
'0': {
@@ -199,7 +222,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
199222
_rank: ++j * 1000,
200223
name: t('Reset Rundown'),
201224
},
202-
{
225+
[IBlueprintDefaultCoreTriggersType.disableNextPiece]: {
203226
_id: 'core_disable_next_piece',
204227
actions: {
205228
'0': {
@@ -221,7 +244,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
221244
_rank: ++j * 1000,
222245
name: t('Disable the next element'),
223246
},
224-
{
247+
[IBlueprintDefaultCoreTriggersType.disableNextPieceUndo]: {
225248
_id: 'core_disable_next_piece_undo',
226249
actions: {
227250
'0': {
@@ -244,7 +267,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
244267
_rank: ++j * 1000,
245268
name: t('Undo Disable the next element'),
246269
},
247-
{
270+
[IBlueprintDefaultCoreTriggersType.createSnapshotForDebug]: {
248271
_id: 'core_create_snapshot_for_debug',
249272
actions: {
250273
'0': {
@@ -266,7 +289,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
266289
_rank: ++j * 1000,
267290
name: t('Store Snapshot'),
268291
},
269-
{
292+
[IBlueprintDefaultCoreTriggersType.moveNextPart]: {
270293
_id: 'core_move_next_part',
271294
actions: {
272295
'0': {
@@ -290,7 +313,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
290313
_rank: ++j * 1000,
291314
name: t('Move Next forwards'),
292315
},
293-
{
316+
[IBlueprintDefaultCoreTriggersType.moveNextSegment]: {
294317
_id: 'core_move_next_segment',
295318
actions: {
296319
'0': {
@@ -314,7 +337,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
314337
_rank: ++j * 1000,
315338
name: t('Move Next to the following segment'),
316339
},
317-
{
340+
[IBlueprintDefaultCoreTriggersType.movePreviousPart]: {
318341
_id: 'core_move_previous_part',
319342
actions: {
320343
'0': {
@@ -338,7 +361,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
338361
_rank: ++j * 1000,
339362
name: t('Move Next backwards'),
340363
},
341-
{
364+
[IBlueprintDefaultCoreTriggersType.movePreviousSegment]: {
342365
_id: 'core_move_previous_segment',
343366
actions: {
344367
'0': {
@@ -362,7 +385,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
362385
_rank: ++j * 1000,
363386
name: t('Move Next to the previous segment'),
364387
},
365-
{
388+
[IBlueprintDefaultCoreTriggersType.goToOnAirLine]: {
366389
_id: 'core_go_to_onAir_line',
367390
actions: {
368391
'0': {
@@ -384,7 +407,7 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
384407
_rank: ++j * 1000,
385408
name: t('Go to On Air line'),
386409
},
387-
{
410+
[IBlueprintDefaultCoreTriggersType.rewindSegments]: {
388411
_id: 'core_rewind_segments',
389412
actions: {
390413
'0': {
@@ -406,8 +429,8 @@ export const DEFAULT_CORE_TRIGGERS: IBlueprintTriggeredActions[] = [
406429
_rank: ++j * 1000,
407430
name: t('Rewind segments to start'),
408431
},
409-
]
432+
}
410433

411-
export const DEFAULT_CORE_TRIGGER_IDS = DEFAULT_CORE_TRIGGERS.map((triggeredAction) =>
412-
protectString(getHash(triggeredAction._id))
434+
export const DEFAULT_CORE_TRIGGER_IDS = Object.values<IBlueprintTriggeredActions>(DEFAULT_CORE_TRIGGERS).map(
435+
(triggeredAction) => protectString<TriggeredActionId>(getHash(triggeredAction._id))
413436
)

meteor/server/migration/upgrades/system.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { Blueprints, CoreSystem } from '../../collections'
44
import {
55
BlueprintManifestType,
66
BlueprintResultApplySystemConfig,
7+
IBlueprintTriggeredActions,
78
SystemBlueprintManifest,
89
} from '@sofie-automation/blueprints-integration'
910
import { evalBlueprint } from '../../api/blueprints/cache'
10-
import { CommonContext } from './context'
11+
import { CoreSystemApplyConfigContext } from './context'
1112
import { updateTriggeredActionsForShowStyleBaseId } from './lib'
1213
import { CoreSystemId } from '@sofie-automation/corelib/dist/dataModel/Ids'
1314
import { DEFAULT_CORE_TRIGGERS } from './defaultSystemActionTriggers'
@@ -21,7 +22,7 @@ export async function runUpgradeForCoreSystem(coreSystemId: CoreSystemId): Promi
2122
let result: BlueprintResultApplySystemConfig
2223

2324
if (blueprintManifest && typeof blueprintManifest.applyConfig === 'function') {
24-
const blueprintContext = new CommonContext(
25+
const blueprintContext = new CoreSystemApplyConfigContext(
2526
'applyConfig',
2627
`coreSystem:${coreSystem._id},blueprint:${blueprint.blueprintId}`
2728
)
@@ -82,6 +83,6 @@ async function loadCoreSystemAndBlueprint(coreSystemId: CoreSystemId) {
8283

8384
function generateDefaultSystemConfig(): BlueprintResultApplySystemConfig {
8485
return {
85-
triggeredActions: DEFAULT_CORE_TRIGGERS,
86+
triggeredActions: Object.values<IBlueprintTriggeredActions>(DEFAULT_CORE_TRIGGERS),
8687
}
8788
}

packages/blueprints-integration/src/api/system.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { IBlueprintTriggeredActions } from '../triggers'
2-
import type { ICommonContext } from '../context'
32
import type { MigrationStepSystem } from '../migrations'
43
import type { BlueprintManifestBase, BlueprintManifestType } from './base'
4+
import type { ICoreSystemApplyConfigContext } from '../context/systemApplyConfigContext'
55

66
export interface SystemBlueprintManifest extends BlueprintManifestBase {
77
blueprintType: BlueprintManifestType.SYSTEM
@@ -32,7 +32,7 @@ export interface SystemBlueprintManifest extends BlueprintManifestBase {
3232
* This should be written to give a predictable and stable result, it can be called with the same config multiple times
3333
*/
3434
applyConfig?: (
35-
context: ICommonContext
35+
context: ICoreSystemApplyConfigContext
3636
// config: TRawConfig,
3737
) => BlueprintResultApplySystemConfig
3838
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { IBlueprintDefaultCoreSystemTriggers } from '../triggers'
2+
import type { ICommonContext } from './baseContext'
3+
4+
export interface ICoreSystemApplyConfigContext extends ICommonContext {
5+
getDefaultSystemActionTriggers(): IBlueprintDefaultCoreSystemTriggers
6+
}

packages/blueprints-integration/src/triggers.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,27 @@ export interface IBlueprintTriggeredActions {
340340
}
341341

342342
export { SomeActionIdentifier, ClientActions, PlayoutActions }
343+
344+
export enum IBlueprintDefaultCoreSystemTriggersType {
345+
toggleShelf = 'toggleShelf',
346+
activateRundownPlaylist = 'activateRundownPlaylist',
347+
activateRundownPlaylistRehearsal = 'activateRundownPlaylistRehearsal',
348+
deactivateRundownPlaylist = 'deactivateRundownPlaylist',
349+
take = 'take',
350+
hold = 'hold',
351+
holdUndo = 'holdUndo',
352+
resetRundownPlaylist = 'resetRundownPlaylist',
353+
disableNextPiece = 'disableNextPiece',
354+
disableNextPieceUndo = 'disableNextPieceUndo',
355+
createSnapshotForDebug = 'createSnapshotForDebug',
356+
moveNextPart = 'moveNextPart',
357+
moveNextSegment = 'moveNextSegment',
358+
movePreviousPart = 'movePreviousPart',
359+
movePreviousSegment = 'movePreviousSegment',
360+
goToOnAirLine = 'goToOnAirLine',
361+
rewindSegments = 'rewindSegments',
362+
}
363+
364+
export type IBlueprintDefaultCoreSystemTriggers = {
365+
[key in IBlueprintDefaultCoreSystemTriggersType]: IBlueprintTriggeredActions
366+
}

packages/webui/src/client/ui/Settings/components/triggeredActions/TriggeredActionsEditor.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ export const TriggeredActionsEditor: React.FC<IProps> = function TriggeredAction
437437
{showStyleBaseId !== null ? (
438438
<>
439439
<div className={classNames('mod mhn', parsedTriggerFilter ? 'mtn' : undefined)}>
440-
{(systemTriggeredActionIds?.length ?? 0) > 0 && !parsedTriggerFilter ? (
440+
{!parsedTriggerFilter ? (
441441
<h3
442442
className="mhn mvs clickable disable-select"
443443
onClick={() => setSystemWideCollapsed(!systemWideCollapsed)}
@@ -470,13 +470,19 @@ export const TriggeredActionsEditor: React.FC<IProps> = function TriggeredAction
470470
/>
471471
))
472472
: null}
473+
474+
{!systemWideCollapsed && !parsedTriggerFilter && systemTriggeredActionIds?.length === 0 && (
475+
<p className="mod mhn subtle">{t('No Action Triggers set up.')}</p>
476+
)}
473477
</div>
474478
</>
475479
) : null}
476480
<div className="mod mhs">
477-
<button className="btn btn-primary" onClick={onNewTriggeredAction}>
478-
<FontAwesomeIcon icon={faPlus} />
479-
</button>
481+
<Tooltip overlay={t('Add Action Trigger')} placement="top">
482+
<button className="btn btn-primary" onClick={onNewTriggeredAction}>
483+
<FontAwesomeIcon icon={faPlus} />
484+
</button>
485+
</Tooltip>
480486
<Tooltip overlay={t('Upload stored Action Triggers')} placement="top">
481487
<span className="inline-block">
482488
<UploadButton

0 commit comments

Comments
 (0)