mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-15 04:13:47 +00:00
fix: resync aux timer names on project load, consolidate name handling
Addresses the review findings on the aux timer naming feature. - Aux timer names are project data, but they were only applied at bootstrap and on a settings POST. Loading another project left the previous project's names in the runtime store, so the controls and views disagreed with the settings panel until a restart. The names are now applied when a project is loaded, and patching the current project settings applies them and sends a settings refetch to the clients (loading a project already triggers a full refetch via the rundown). - Consolidate the name handling into a single normaliser in ontime-utils, used by the project file parser, the API validation and to build the default value. This creates the property when importing project files saved before the feature existed, and enforces the name length limit server side rather than only in the form. - loadNames normalises its input, so the runtime state is consistent regardless of the shape of the stored settings. - Clarify that auxTimerNames is ordered (index 0 is aux timer 1), and derive the settings form from the shared aux timer count. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WCZejVTzuAY3tHTE6nB3JH
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { auxTimerNameMaxLength, normaliseAuxTimerNames, numberOfAuxTimers } from './auxTimerUtils.js';
|
||||
|
||||
describe('normaliseAuxTimerNames()', () => {
|
||||
it('generates the default value when given nothing', () => {
|
||||
expect(normaliseAuxTimerNames()).toStrictEqual(['', '', '']);
|
||||
});
|
||||
|
||||
it('always returns an entry per aux timer', () => {
|
||||
expect(normaliseAuxTimerNames(['Speaker'])).toHaveLength(numberOfAuxTimers);
|
||||
expect(normaliseAuxTimerNames(['a', 'b', 'c', 'extra'])).toStrictEqual(['a', 'b', 'c']);
|
||||
});
|
||||
|
||||
it('pads missing entries with an empty string', () => {
|
||||
expect(normaliseAuxTimerNames(['Speaker'])).toStrictEqual(['Speaker', '', '']);
|
||||
});
|
||||
|
||||
it('trims whitespace', () => {
|
||||
expect(normaliseAuxTimerNames([' Speaker ', '', ''])).toStrictEqual(['Speaker', '', '']);
|
||||
});
|
||||
|
||||
it('caps the name length', () => {
|
||||
const tooLong = 'a'.repeat(auxTimerNameMaxLength + 10);
|
||||
expect(normaliseAuxTimerNames([tooLong])[0]).toHaveLength(auxTimerNameMaxLength);
|
||||
});
|
||||
|
||||
it('falls back to defaults for malformed data', () => {
|
||||
expect(normaliseAuxTimerNames('not-an-array')).toStrictEqual(['', '', '']);
|
||||
expect(normaliseAuxTimerNames(null)).toStrictEqual(['', '', '']);
|
||||
expect(normaliseAuxTimerNames([42, {}, undefined])).toStrictEqual(['', '', '']);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
/** Number of aux timers available in ontime */
|
||||
export const numberOfAuxTimers = 3;
|
||||
|
||||
/** Maximum length of a user given aux timer name */
|
||||
export const auxTimerNameMaxLength = 30;
|
||||
|
||||
/**
|
||||
* Normalises user or file provided aux timer names into a
|
||||
* fixed length array of trimmed, length capped strings.
|
||||
* Missing or malformed entries fallback to an empty string,
|
||||
* which consumers render as the default label.
|
||||
* Used when parsing project files, when validating API payloads
|
||||
* and to generate the default value.
|
||||
*/
|
||||
export function normaliseAuxTimerNames(maybeNames?: unknown): string[] {
|
||||
const source = Array.isArray(maybeNames) ? maybeNames : [];
|
||||
|
||||
return Array.from({ length: numberOfAuxTimers }, (_, index) => {
|
||||
const value = source[index];
|
||||
return typeof value === 'string' ? value.trim().slice(0, auxTimerNameMaxLength) : '';
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { DatabaseModel } from 'ontime-types';
|
||||
import { EndAction, OntimeView, SupportedEntry, TimeStrategy, TimerType } from 'ontime-types';
|
||||
|
||||
import { normaliseAuxTimerNames } from '../aux-timer-utils/auxTimerUtils.js';
|
||||
|
||||
export const demoDb: DatabaseModel = {
|
||||
rundowns: {
|
||||
default: {
|
||||
@@ -342,7 +344,7 @@ export const demoDb: DatabaseModel = {
|
||||
operatorKey: null,
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
auxTimerNames: ['', '', ''],
|
||||
auxTimerNames: normaliseAuxTimerNames(),
|
||||
},
|
||||
viewSettings: {
|
||||
dangerColor: '#ff7300',
|
||||
|
||||
Reference in New Issue
Block a user