Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/corelib/src/dataModel/RundownPlaylist/TTimers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,15 @@ export interface RundownTTimer {
* display: { ... } // some kind of options for how to display in the ui
*/
}

export const DEFAULT_RUNDOWN_T_TIMERS: [RundownTTimer, RundownTTimer, RundownTTimer] = [
{ index: 1, label: '', mode: null, state: null },
{ index: 2, label: '', mode: null, state: null },
{ index: 3, label: '', mode: null, state: null },
]

export function getRundownTTimers(
tTimers: [RundownTTimer, RundownTTimer, RundownTTimer] | null | undefined
): [RundownTTimer, RundownTTimer, RundownTTimer] {
return tTimers ?? DEFAULT_RUNDOWN_T_TIMERS
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ interface BasicType {
}

describe('applyAndValidateOverrides', () => {
test('undefined input', () => {
const res = applyAndValidateOverrides<BasicType>(undefined)
expect(res).toBeTruthy()

expect(res.obj).toStrictEqual({})
expect(res.invalid).toHaveLength(0)
expect(res.preserve).toHaveLength(0)
expect(res.unused).toHaveLength(0)
})

test('no overrides', () => {
const inputObj = {
abc: 'def',
Expand Down
19 changes: 15 additions & 4 deletions packages/corelib/src/settings/objectWithOverrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ export function wrapDefaultObject<T extends object>(obj: T): ObjectWithOverrides
overrides: [],
}
}
export function isObjectWithOverrides<T extends object>(o: ObjectWithOverrides<T> | T): o is ObjectWithOverrides<T> {
export function isObjectWithOverrides<T extends object>(
o: ObjectWithOverrides<T> | T | ReadonlyDeep<ObjectWithOverrides<T>> | undefined | null
): o is ObjectWithOverrides<T> {
const oAny = o as any
return typeof oAny.defaults === 'object' && Array.isArray(oAny.overrides)
return oAny != null && typeof oAny.defaults === 'object' && oAny.defaults != null && Array.isArray(oAny.overrides)
}
/**
* In some cases, an ObjectWithOverrides should have no defaults. This is common for when the user owns the object containing the ObjectWithOverrides.
Expand Down Expand Up @@ -194,10 +196,19 @@ function recursivelyGenerateOverrides<T extends object>(
* Note: No validation is done to make sure the type conforms to the typescript definition. It is assumed that the definitions which drive ui ensure that they dont violate the typings, and that any changes will be backwards compatible with old overrides
*/
export function applyAndValidateOverrides<T extends object>(
obj: ReadonlyDeep<ObjectWithOverrides<T>>
obj: ReadonlyDeep<ObjectWithOverrides<T>> | undefined | null
): ApplyOverridesResult<T> {
if (obj == null || !isObjectWithOverrides(obj)) {
return {
obj: {} as T,
preserve: [],
unused: [],
invalid: [],
}
}

const result: ApplyOverridesResult<T> = {
obj: clone(obj.defaults),
obj: clone(obj.defaults) as T,
preserve: [],
unused: [],
invalid: [],
Expand Down
7 changes: 5 additions & 2 deletions packages/webui/src/client/lib/tTimerUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
type RundownTTimer,
getRundownTTimers,
timerStateToDuration,
} from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist/TTimers'

Expand Down Expand Up @@ -49,6 +50,8 @@ export function calculateTTimerOverUnder(timer: RundownTTimer, now: number): num
return projectedDuration - duration
}

export function getDefaultTTimer(tTimers: [RundownTTimer, RundownTTimer, RundownTTimer]): RundownTTimer | undefined {
return tTimers.find((t) => t.mode)
export function getDefaultTTimer(
tTimers: [RundownTTimer, RundownTTimer, RundownTTimer] | null | undefined
): RundownTTimer | undefined {
return getRundownTTimers(tTimers).find((t) => t.mode)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RundownTTimer } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist/TTimers'
import { type RundownTTimer, getRundownTTimers } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist/TTimers'
import { useTiming } from '../RundownTiming/withTiming'
import { RundownUtils } from '../../../lib/rundown.js'
import { calculateTTimerDiff, calculateTTimerOverUnder } from '../../../lib/tTimerUtils'
Expand All @@ -8,13 +8,15 @@ import { Countdown } from './Countdown'
import { OverUnderChip } from '../../../lib/Components/OverUnderChip'

interface IProps {
tTimers: [RundownTTimer, RundownTTimer, RundownTTimer]
tTimers: [RundownTTimer, RundownTTimer, RundownTTimer] | null | undefined
}

export const RundownHeaderTimers: React.FC<IProps> = ({ tTimers }) => {
useTiming()

const activeTimers = tTimers.filter((t) => t.mode).slice(0, 2)
const activeTimers = getRundownTTimers(tTimers)
.filter((t) => t.mode)
.slice(0, 2)
if (activeTimers.length == 0) return null

return (
Expand Down
Loading