mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-15 12:23:51 +00:00
refactor: address review feedback on aux timer naming
- Revert the automation action labels back to "Aux N: action" (no functional reason to change this wording). - Simplify the aux timers header in the playback control: the flex container now only handles layout, and the label text reuses the same font-size/color as the per-timer labels below it, instead of a bespoke style block duplicating those values. - Replace the generic, length-driven normaliser with an explicit sanitiseAuxTimerNames() that always deals with exactly three timers, and rename it away from "normalise" (which didn't convey that it trims, caps length and fills in missing entries). Static defaults now use a plain ['', '', ''] literal instead of calling the sanitiser with no input to sanitise. - Settings.type.ts and AuxTimerSettings.tsx no longer generate their three fields from a loop; the form mirrors the same explicit, one-field-per-row style already used by GeneralSettings.tsx. - Trim comments that only restated what the following line already says, keeping the ones that explain non-obvious behaviour (why AuxTimerService needs to be resynced separately from the data provider, why SimpleTimer.reset() preserves the name). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WCZejVTzuAY3tHTE6nB3JH
This commit is contained in:
@@ -1,31 +1,30 @@
|
||||
import { auxTimerNameMaxLength, normaliseAuxTimerNames, numberOfAuxTimers } from './auxTimerUtils.js';
|
||||
import { auxTimerNameMaxLength, sanitiseAuxTimerNames } from './auxTimerUtils.js';
|
||||
|
||||
describe('normaliseAuxTimerNames()', () => {
|
||||
describe('sanitiseAuxTimerNames()', () => {
|
||||
it('generates the default value when given nothing', () => {
|
||||
expect(normaliseAuxTimerNames()).toStrictEqual(['', '', '']);
|
||||
expect(sanitiseAuxTimerNames()).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('always returns exactly three entries', () => {
|
||||
expect(sanitiseAuxTimerNames(['a', 'b', 'c', 'extra'])).toStrictEqual(['a', 'b', 'c']);
|
||||
});
|
||||
|
||||
it('pads missing entries with an empty string', () => {
|
||||
expect(normaliseAuxTimerNames(['Speaker'])).toStrictEqual(['Speaker', '', '']);
|
||||
expect(sanitiseAuxTimerNames(['Speaker'])).toStrictEqual(['Speaker', '', '']);
|
||||
});
|
||||
|
||||
it('trims whitespace', () => {
|
||||
expect(normaliseAuxTimerNames([' Speaker ', '', ''])).toStrictEqual(['Speaker', '', '']);
|
||||
expect(sanitiseAuxTimerNames([' Speaker ', '', ''])).toStrictEqual(['Speaker', '', '']);
|
||||
});
|
||||
|
||||
it('caps the name length', () => {
|
||||
const tooLong = 'a'.repeat(auxTimerNameMaxLength + 10);
|
||||
expect(normaliseAuxTimerNames([tooLong])[0]).toHaveLength(auxTimerNameMaxLength);
|
||||
expect(sanitiseAuxTimerNames([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(['', '', '']);
|
||||
expect(sanitiseAuxTimerNames('not-an-array')).toStrictEqual(['', '', '']);
|
||||
expect(sanitiseAuxTimerNames(null)).toStrictEqual(['', '', '']);
|
||||
expect(sanitiseAuxTimerNames([42, {}, undefined])).toStrictEqual(['', '', '']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
/** 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) : '';
|
||||
});
|
||||
function sanitiseAuxTimerName(value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim().slice(0, auxTimerNameMaxLength) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Ontime has three aux timers. Given whatever was found on disk or in a request body,
|
||||
* returns a name for each of them, so callers never need to deal with a missing
|
||||
* or malformed auxTimerNames (eg. a project file saved before this feature existed).
|
||||
*/
|
||||
export function sanitiseAuxTimerNames(names?: unknown): [string, string, string] {
|
||||
const source = Array.isArray(names) ? names : [];
|
||||
return [sanitiseAuxTimerName(source[0]), sanitiseAuxTimerName(source[1]), sanitiseAuxTimerName(source[2])];
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
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: {
|
||||
@@ -344,7 +342,7 @@ export const demoDb: DatabaseModel = {
|
||||
operatorKey: null,
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
auxTimerNames: normaliseAuxTimerNames(),
|
||||
auxTimerNames: ['', '', ''],
|
||||
},
|
||||
viewSettings: {
|
||||
dangerColor: '#ff7300',
|
||||
|
||||
Reference in New Issue
Block a user