mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-22 07:29:08 +00:00
fix: validateLinkStart (#1430)
* fix validateLinkStart * update comment * use fallback * cast to MaybeString * update comment Co-authored-by: Carlos Valente <34649812+cpvalente@users.noreply.github.com> --------- Co-authored-by: Carlos Valente <34649812+cpvalente@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
891c43ba77
commit
743d7fa782
@@ -376,7 +376,7 @@ export function createPatch(originalEvent: OntimeEvent, patchEvent: Partial<Onti
|
|||||||
timeEnd,
|
timeEnd,
|
||||||
duration,
|
duration,
|
||||||
timeStrategy,
|
timeStrategy,
|
||||||
linkStart: validateLinkStart(patchEvent.linkStart),
|
linkStart: validateLinkStart(patchEvent.linkStart, originalEvent.linkStart),
|
||||||
endAction: validateEndAction(patchEvent.endAction, originalEvent.endAction),
|
endAction: validateEndAction(patchEvent.endAction, originalEvent.endAction),
|
||||||
timerType: validateTimerType(patchEvent.timerType, originalEvent.timerType),
|
timerType: validateTimerType(patchEvent.timerType, originalEvent.timerType),
|
||||||
countToEnd: typeof patchEvent.countToEnd === 'boolean' ? patchEvent.countToEnd : originalEvent.countToEnd,
|
countToEnd: typeof patchEvent.countToEnd === 'boolean' ? patchEvent.countToEnd : originalEvent.countToEnd,
|
||||||
|
|||||||
@@ -2,12 +2,16 @@ import type { MaybeString } from 'ontime-types';
|
|||||||
import { EndAction, TimerType, TimeStrategy } from 'ontime-types';
|
import { EndAction, TimerType, TimeStrategy } from 'ontime-types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a given value is a valid type of string, returns null otherwise
|
* Check if a given value is a valid type linkStart, returns the fallback otherwise
|
||||||
|
* linkStart can be a string (id of an event to link) or null (unlinked)
|
||||||
* @param {MaybeString} maybeLinkStart
|
* @param {MaybeString} maybeLinkStart
|
||||||
* @returns {MaybeString}
|
* @returns {MaybeString}
|
||||||
*/
|
*/
|
||||||
export function validateLinkStart(maybeLinkStart: unknown): MaybeString {
|
export function validateLinkStart(maybeLinkStart: unknown, fallback: MaybeString = null): MaybeString {
|
||||||
return typeof maybeLinkStart === 'string' ? maybeLinkStart : null;
|
if (typeof maybeLinkStart === 'string' || maybeLinkStart === null) {
|
||||||
|
return maybeLinkStart as MaybeString;
|
||||||
|
}
|
||||||
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user