Skip to content

Commit

Permalink
Merge pull request #1035 from nrkno/feat/rework-caches-to-structured-…
Browse files Browse the repository at this point in the history
…objects
  • Loading branch information
Julusian authored Oct 24, 2023
2 parents bb13da9 + cbc551a commit 0f76332
Show file tree
Hide file tree
Showing 125 changed files with 5,933 additions and 4,105 deletions.
7 changes: 4 additions & 3 deletions meteor/client/lib/rundown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
processAndPrunePieceInstanceTimings,
resolvePrunedPieceInstance,
} from '@sofie-automation/corelib/dist/playout/processAndPrune'
import { PieceInstance } from '@sofie-automation/corelib/dist/dataModel/PieceInstance'
import { PieceInstance, PieceInstancePiece } from '@sofie-automation/corelib/dist/dataModel/PieceInstance'
import { IAdLibListItem } from '../ui/Shelf/AdLibListItem'
import { BucketAdLibItem, BucketAdLibUi } from '../ui/Shelf/RundownViewBuckets'
import { FindOptions } from '../../lib/collections/lib'
Expand Down Expand Up @@ -675,8 +675,9 @@ export namespace RundownUtils {
) {
// if previousItem is infinite, currentItem caps it within the current part
if (previousItem.instance.infinite) {
previousItem.instance.piece.lifespan = PieceLifespan.WithinPart
delete previousItem.instance.infinite
;(previousItem.instance.piece as PieceInstancePiece).lifespan =
PieceLifespan.WithinPart
delete (previousItem.instance as PieceInstance).infinite
}

if (
Expand Down
11 changes: 6 additions & 5 deletions meteor/client/lib/rundownLayouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getCurrentTime } from '../../lib/lib'
import { invalidateAt } from './../../lib/invalidatingTime'
import { memoizedIsolatedAutorun } from '../../lib/memoizedIsolatedAutorun'
import { PartInstances, PieceInstances } from '../collections'
import { ReadonlyDeep } from 'type-fest'

/**
* If the conditions of the filter are met, activePieceInstance will include the first piece instance found that matches the filter, otherwise it will be undefined.
Expand All @@ -16,9 +17,9 @@ export function getIsFilterActive(
playlist: DBRundownPlaylist,
showStyleBase: UIShowStyleBase,
panel: RequiresActiveLayers
): { active: boolean; activePieceInstance: PieceInstance | undefined } {
): { active: boolean; activePieceInstance: ReadonlyDeep<PieceInstance> | undefined } {
const unfinishedPieces = getUnfinishedPieceInstancesReactive(playlist, showStyleBase)
let activePieceInstance: PieceInstance | undefined
let activePieceInstance: ReadonlyDeep<PieceInstance> | undefined
const activeLayers = unfinishedPieces.map((p) => p.piece.sourceLayerId)
const containsEveryRequiredLayer = panel.requireAllAdditionalSourcelayers
? panel.additionalLayers?.length && panel.additionalLayers.every((s) => activeLayers.includes(s))
Expand All @@ -35,7 +36,7 @@ export function getIsFilterActive(
) {
activePieceInstance =
panel.requiredLayerIds && panel.requiredLayerIds.length
? unfinishedPieces.find((piece: PieceInstance) => {
? unfinishedPieces.find((piece: ReadonlyDeep<PieceInstance>) => {
return (
(panel.requiredLayerIds || []).indexOf(piece.piece.sourceLayerId) !== -1 &&
piece.partInstanceId === playlist.currentPartInfo?.partInstanceId
Expand All @@ -53,7 +54,7 @@ export function getIsFilterActive(
export function getUnfinishedPieceInstancesReactive(
playlist: DBRundownPlaylist,
showStyleBase: UIShowStyleBase
): PieceInstance[] {
): ReadonlyDeep<PieceInstance>[] {
if (playlist.activationId && playlist.currentPartInfo) {
return memoizedIsolatedAutorun(
(
Expand All @@ -62,7 +63,7 @@ export function getUnfinishedPieceInstancesReactive(
showStyleBase: UIShowStyleBase
) => {
const now = getCurrentTime()
let prospectivePieces: PieceInstance[] = []
let prospectivePieces: ReadonlyDeep<PieceInstance>[] = []

const partInstance = PartInstances.findOne(currentPartInstanceId)

Expand Down
27 changes: 19 additions & 8 deletions meteor/client/lib/shelf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ export interface AdlibSegmentUi extends DBSegment {
isCompatibleShowStyle: boolean
}

export function getNextPiecesReactive(playlist: DBRundownPlaylist, showsStyleBase: UIShowStyleBase): PieceInstance[] {
let prospectivePieceInstances: PieceInstance[] = []
export function getNextPiecesReactive(
playlist: DBRundownPlaylist,
showsStyleBase: UIShowStyleBase
): ReadonlyDeep<PieceInstance>[] {
let prospectivePieceInstances: ReadonlyDeep<PieceInstance>[] = []
if (playlist.activationId && playlist.nextPartInfo) {
prospectivePieceInstances = PieceInstances.find({
playlistActivationId: playlist.activationId,
Expand Down Expand Up @@ -88,7 +91,11 @@ export function getNextPiecesReactive(playlist: DBRundownPlaylist, showsStyleBas
export function getUnfinishedPieceInstancesGrouped(
playlist: DBRundownPlaylist,
showStyleBase: UIShowStyleBase
): { unfinishedPieceInstances: PieceInstance[]; unfinishedAdLibIds: PieceId[]; unfinishedTags: string[] } {
): {
unfinishedPieceInstances: ReadonlyDeep<PieceInstance>[]
unfinishedAdLibIds: PieceId[]
unfinishedTags: readonly string[]
} {
const unfinishedPieceInstances = getUnfinishedPieceInstancesReactive(playlist, showStyleBase)

const unfinishedAdLibIds: PieceId[] = unfinishedPieceInstances
Expand All @@ -111,21 +118,25 @@ export function getUnfinishedPieceInstancesGrouped(
export function getNextPieceInstancesGrouped(
playlist: DBRundownPlaylist,
showsStyleBase: UIShowStyleBase
): { nextAdLibIds: PieceId[]; nextTags: string[]; nextPieceInstances: PieceInstance[] } {
): { nextAdLibIds: PieceId[]; nextTags: readonly string[]; nextPieceInstances: ReadonlyDeep<PieceInstance>[] } {
const nextPieceInstances = getNextPiecesReactive(playlist, showsStyleBase)

const nextAdLibIds: PieceId[] = nextPieceInstances
.filter((piece) => !!piece.adLibSourceId)
.map((piece) => piece.adLibSourceId!)
const nextTags: string[] = nextPieceInstances
const nextTags = nextPieceInstances
.filter((piece) => !!piece.piece.tags)
.map((piece) => piece.piece.tags!)
.reduce((a, b) => a.concat(b), [])

return { nextAdLibIds, nextTags, nextPieceInstances }
}

export function isAdLibOnAir(unfinishedAdLibIds: PieceId[], unfinishedTags: string[], adLib: AdLibPieceUi): boolean {
export function isAdLibOnAir(
unfinishedAdLibIds: PieceId[],
unfinishedTags: readonly string[],
adLib: AdLibPieceUi
): boolean {
if (
unfinishedAdLibIds.includes(adLib._id) ||
(adLib.currentPieceTags &&
Expand All @@ -137,7 +148,7 @@ export function isAdLibOnAir(unfinishedAdLibIds: PieceId[], unfinishedTags: stri
return false
}

export function isAdLibNext(nextAdLibIds: PieceId[], nextTags: string[], adLib: AdLibPieceUi): boolean {
export function isAdLibNext(nextAdLibIds: PieceId[], nextTags: readonly string[], adLib: AdLibPieceUi): boolean {
if (
nextAdLibIds.includes(adLib._id) ||
(adLib.nextPieceTags &&
Expand All @@ -151,7 +162,7 @@ export function isAdLibNext(nextAdLibIds: PieceId[], nextTags: string[], adLib:

export function isAdLibDisplayedAsOnAir(
unfinishedAdLibIds: PieceId[],
unfinishedTags: string[],
unfinishedTags: readonly string[],
adLib: AdLibPieceUi
): boolean {
const isOnAir = isAdLibOnAir(unfinishedAdLibIds, unfinishedTags, adLib)
Expand Down
3 changes: 2 additions & 1 deletion meteor/client/ui/ClipTrimPanel/ClipTrimDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import { Rundown } from '@sofie-automation/corelib/dist/dataModel/Rundown'
import { PieceInstancePiece } from '@sofie-automation/corelib/dist/dataModel/PieceInstance'
import { UIStudio } from '../../../lib/api/studios'
import { RundownPlaylistId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { ReadonlyDeep } from 'type-fest'

export interface IProps {
playlistId: RundownPlaylistId
rundown: Rundown
studio: UIStudio
selectedPiece: PieceInstancePiece
selectedPiece: ReadonlyDeep<PieceInstancePiece>

onClose?: () => void
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { PieceLifespan } from '@sofie-automation/blueprints-integration'
import { TFunction, useTranslation } from 'react-i18next'
import { Time } from '../../../../lib/lib'
import Moment from 'react-moment'
import { ReadonlyDeep } from 'type-fest'

interface IProps {
piece: Omit<PieceInstancePiece, 'timelineObjectsString'>
piece: ReadonlyDeep<Omit<PieceInstancePiece, 'timelineObjectsString'>>
pieceRenderedDuration: number | null
pieceRenderedIn: number | null
changed?: Time
Expand Down Expand Up @@ -39,7 +40,7 @@ export const FloatingInspectorTimeInformationRow: React.FunctionComponent<IProps
)
}

function getLifeSpanText(t: TFunction, piece: Omit<PieceInstancePiece, 'timelineObjectsString'>): string {
function getLifeSpanText(t: TFunction, piece: ReadonlyDeep<Omit<PieceInstancePiece, 'timelineObjectsString'>>): string {
switch (piece.lifespan) {
case PieceLifespan.WithinPart:
return t('Until next take')
Expand All @@ -59,7 +60,7 @@ function getLifeSpanText(t: TFunction, piece: Omit<PieceInstancePiece, 'timeline
}

function getDuration(
piece: Omit<PieceInstancePiece, 'timelineObjectsString'>,
piece: ReadonlyDeep<Omit<PieceInstancePiece, 'timelineObjectsString'>>,
pieceRenderedDuration: number | null
): string {
return RundownUtils.formatTimeToShortTime(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { Time } from '../../../lib/lib'
import { PieceInstancePiece } from '@sofie-automation/corelib/dist/dataModel/PieceInstance'
import { FloatingInspectorTimeInformationRow } from './FloatingInspectorHelpers/FloatingInspectorTimeInformationRow'
import { IFloatingInspectorPosition, useInspectorPosition } from './IFloatingInspectorPosition'
import { ReadonlyDeep } from 'type-fest'

interface IProps {
piece: Omit<PieceInstancePiece, 'timelineObjectsString'>
piece: ReadonlyDeep<Omit<PieceInstancePiece, 'timelineObjectsString'>>
pieceRenderedDuration: number | null
pieceRenderedIn: number | null
showMiniInspector: boolean
Expand Down
5 changes: 3 additions & 2 deletions meteor/client/ui/PieceIcons/PieceIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
RundownPlaylistActivationId,
ShowStyleBaseId,
} from '@sofie-automation/corelib/dist/dataModel/Ids'
import { ReadonlyDeep } from 'type-fest'

export interface IPropsHeader {
partInstanceId: PartInstanceId
Expand All @@ -33,7 +34,7 @@ export interface IPropsHeader {
}

export const PieceIcon = (props: {
pieceInstance: PieceInstance | undefined
pieceInstance: ReadonlyDeep<PieceInstance> | undefined
sourceLayer: ISourceLayer | undefined
renderUnknown?: boolean
}): JSX.Element | null => {
Expand Down Expand Up @@ -100,7 +101,7 @@ export function PieceIconContainerNoSub({
sourceLayers,
renderUnknown,
}: {
pieceInstances: PieceInstance[]
pieceInstances: ReadonlyDeep<PieceInstance[]>
sourceLayers: {
[key: string]: ISourceLayer
}
Expand Down
5 changes: 3 additions & 2 deletions meteor/client/ui/PieceIcons/PieceName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IPropsHeader } from './PieceIcon'
import { findPieceInstanceToShow } from './utils'
import { PieceGeneric } from '@sofie-automation/corelib/dist/dataModel/Piece'
import { RundownPlaylistActivationId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { ReadonlyDeep } from 'type-fest'

interface INamePropsHeader extends IPropsHeader {
partName: string
Expand All @@ -20,7 +21,7 @@ const supportedLayers = new Set([
SourceLayerType.LOCAL,
])

function getLocalPieceLabel(piece: PieceGeneric): JSX.Element | null {
function getLocalPieceLabel(piece: ReadonlyDeep<PieceGeneric>): JSX.Element | null {
const { color } = piece.content as EvsContent
return (
<>
Expand All @@ -34,7 +35,7 @@ function getLocalPieceLabel(piece: PieceGeneric): JSX.Element | null {
)
}

function getPieceLabel(piece: PieceGeneric, type: SourceLayerType): JSX.Element | null {
function getPieceLabel(piece: ReadonlyDeep<PieceGeneric>, type: SourceLayerType): JSX.Element | null {
switch (type) {
case SourceLayerType.LOCAL:
return getLocalPieceLabel(piece)
Expand Down
13 changes: 8 additions & 5 deletions meteor/client/ui/PieceIcons/Renderers/SplitInputIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { PieceGeneric } from '@sofie-automation/corelib/dist/dataModel/Piece'
import { SplitsContent, SourceLayerType } from '@sofie-automation/blueprints-integration'
import { RundownUtils } from '../../../lib/rundown'
import classNames from 'classnames'
import { ReadonlyDeep } from 'type-fest'

type SplitIconPieceType = ReadonlyDeep<Omit<PieceGeneric, 'timelineObjectsString'>>

export default class SplitInputIcon extends React.Component<{
abbreviation?: string
piece?: Omit<PieceGeneric, 'timelineObjectsString'>
abbreviation: string | undefined
piece: SplitIconPieceType | undefined
hideLabel?: boolean
}> {
private getCameraLabel(piece: Omit<PieceGeneric, 'timelineObjectsString'> | undefined) {
private getCameraLabel(piece: SplitIconPieceType | undefined) {
if (piece && piece.content) {
const c = piece.content as SplitsContent
const camera = c.boxSourceConfiguration.find((i) => i.type === SourceLayerType.CAMERA)
Expand All @@ -29,7 +32,7 @@ export default class SplitInputIcon extends React.Component<{
}
}

private getLeftSourceType(piece: Omit<PieceGeneric, 'timelineObjectsString'> | undefined): string {
private getLeftSourceType(piece: SplitIconPieceType | undefined): string {
if (piece && piece.content) {
const c = piece.content as SplitsContent
const left = (c.boxSourceConfiguration && c.boxSourceConfiguration[0])?.type || SourceLayerType.CAMERA
Expand All @@ -38,7 +41,7 @@ export default class SplitInputIcon extends React.Component<{
return 'camera'
}

private getRightSourceType(piece: Omit<PieceGeneric, 'timelineObjectsString'> | undefined): string {
private getRightSourceType(piece: SplitIconPieceType | undefined): string {
if (piece && piece.content) {
const c = piece.content as SplitsContent
const right = (c.boxSourceConfiguration && c.boxSourceConfiguration[1])?.type || SourceLayerType.REMOTE
Expand Down
7 changes: 4 additions & 3 deletions meteor/client/ui/PieceIcons/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { IPropsHeader } from './PieceIcon'
import { PieceExtended } from '../../../lib/Rundown'
import { UIShowStyleBases } from '../Collections'
import { PieceInstances } from '../../collections'
import { ReadonlyDeep } from 'type-fest'

export interface IFoundPieceInstance {
sourceLayer: ISourceLayer | undefined
pieceInstance: PieceInstance | undefined
pieceInstance: ReadonlyDeep<PieceInstance> | undefined
}

export function findPieceInstanceToShow(
Expand All @@ -31,12 +32,12 @@ export function findPieceInstanceToShow(
}

export function findPieceInstanceToShowFromInstances(
pieceInstances: PieceInstance[],
pieceInstances: ReadonlyDeep<PieceInstance[]>,
sourceLayers: SourceLayers,
selectedLayerTypes: Set<SourceLayerType>
): IFoundPieceInstance {
let foundSourceLayer: ISourceLayer | undefined
let foundPiece: PieceInstance | undefined
let foundPiece: ReadonlyDeep<PieceInstance> | undefined

for (const pieceInstance of pieceInstances) {
const layer = sourceLayers[pieceInstance.piece.sourceLayerId]
Expand Down
4 changes: 2 additions & 2 deletions meteor/client/ui/RundownView/RundownViewShelf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ interface IRundownViewShelfTrackedProps {
outputLayers: OutputLayers
sourceLayers: SourceLayers
unfinishedAdLibIds: PieceId[]
unfinishedTags: string[]
unfinishedTags: readonly string[]
nextAdLibIds: PieceId[]
nextTags: string[]
nextTags: readonly string[]
}

interface IRundownViewShelfState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SourceLayerItemContainer } from '../SourceLayerItemContainer'
import { ISourceLayerPropsBase, useMouseContext } from './SourceLayer'
import { ISourceLayerExtended } from '../../../../lib/Rundown'
import { PieceInstancePiece } from '@sofie-automation/corelib/dist/dataModel/PieceInstance'
import { ReadonlyDeep } from 'type-fest'

interface IFlattenedSourceLayerProps extends ISourceLayerPropsBase {
layers: ISourceLayerUi[]
Expand All @@ -17,7 +18,7 @@ export function FlattenedSourceLayers(props: IFlattenedSourceLayerProps): JSX.El
const { getPartContext, onMouseDown } = useMouseContext(props)

const piecesForLayers = useMemo(() => {
const piecesForLayers: Map<string, PieceInstancePiece[]> = new Map()
const piecesForLayers: Map<string, ReadonlyDeep<PieceInstancePiece>[]> = new Map()
for (const layer of props.layers) {
piecesForLayers.set(
layer._id,
Expand Down
7 changes: 4 additions & 3 deletions meteor/client/ui/Shelf/AdLibRegionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { withMediaObjectStatus } from '../SegmentTimeline/withMediaObjectStatus'
import { ISourceLayer } from '@sofie-automation/blueprints-integration'
import { UIStudios } from '../Collections'
import { Meteor } from 'meteor/meteor'
import { ReadonlyDeep } from 'type-fest'

interface IState {
objId?: string
Expand Down Expand Up @@ -247,13 +248,13 @@ export const AdLibRegionPanel = translateWithTracker<
)

// Pick thumbnails to display
const nextThumbnail: PieceInstance | undefined = nextPieceInstances.find((p) =>
const nextThumbnail: ReadonlyDeep<PieceInstance> | undefined = nextPieceInstances.find((p) =>
props.panel.thumbnailSourceLayerIds?.includes(p.piece.sourceLayerId)
)
const currentThumbnail: PieceInstance | undefined = !props.panel.hideThumbnailsForActivePieces
const currentThumbnail: ReadonlyDeep<PieceInstance> | undefined = !props.panel.hideThumbnailsForActivePieces
? unfinishedPieceInstances.find((p) => props.panel.thumbnailSourceLayerIds?.includes(p.piece.sourceLayerId))
: undefined
const thumbnailPiece: PieceInstance | undefined = props.panel.thumbnailPriorityNextPieces
const thumbnailPiece: ReadonlyDeep<PieceInstance> | undefined = props.panel.thumbnailPriorityNextPieces
? nextThumbnail ?? currentThumbnail
: currentThumbnail ?? nextThumbnail

Expand Down
4 changes: 2 additions & 2 deletions meteor/client/ui/Shelf/DashboardPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export interface IDashboardPanelProps {
export interface IDashboardPanelTrackedProps {
studio: UIStudio | undefined
unfinishedAdLibIds: PieceId[]
unfinishedTags: string[]
unfinishedTags: readonly string[]
nextAdLibIds: PieceId[]
nextTags: string[]
nextTags: readonly string[]
}

interface DashboardPositionableElement {
Expand Down
Loading

0 comments on commit 0f76332

Please sign in to comment.