mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-10 01:43:43 +00:00
1849b4d39f
* chore: migrate eslint to oxlint * chore: migrate prettier to oxfmt * chore: migrate typescript * chore: toThrow should have a expected value * chore: cast test value as Day * chore: small title fix * chore: mocks should be hoisted * chore: incorrect async useage * chore: test should be inside description * chore: test sohuld include an expeced * chore: oxfmt --------- Co-authored-by: alex-Arc <omnivox@LAPTOP-RC5SNBVV.localdomain>
33 lines
1011 B
TypeScript
33 lines
1011 B
TypeScript
import { CustomFields, MaybeString, OntimeEvent } from 'ontime-types';
|
|
|
|
import { getPropertyValue } from '../../views/common/viewUtils';
|
|
import type { Subscribed } from './operator.types';
|
|
|
|
export function getEventData(
|
|
event: OntimeEvent,
|
|
main: MaybeString,
|
|
secondary: MaybeString,
|
|
subscriptions: string[],
|
|
customFields: CustomFields,
|
|
) {
|
|
const mainField = main ? (getPropertyValue(event, main) ?? '') : event.title;
|
|
const secondaryField = getPropertyValue(event, secondary) ?? '';
|
|
|
|
// remove subscriptions that are not in customFields
|
|
const sanitisedSubscriptions = subscriptions.filter((field) => Object.hasOwn(customFields, field));
|
|
const subscribedData = sanitisedSubscriptions.reduce<Subscribed>((acc, id) => {
|
|
const field = customFields[id];
|
|
if (field) {
|
|
acc.push({
|
|
id,
|
|
label: field.label,
|
|
colour: field.colour,
|
|
value: event.custom[id],
|
|
});
|
|
}
|
|
return acc;
|
|
}, []);
|
|
|
|
return { mainField, secondaryField, subscribedData };
|
|
}
|