mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 19:03:47 +00:00
shortcuts using useHotkeys from mantine/hooks (#907)
--------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Carlos Valente <34649812+cpvalente@users.noreply.github.com> Co-authored-by: Carlos Valente <carlosvalente@pm.me>
This commit is contained in:
committed by
GitHub
parent
0c3c08ac98
commit
9e04a1dcfa
@@ -1,7 +1,15 @@
|
||||
import type { OntimeEvent, OntimeRundown } from 'ontime-types';
|
||||
import type { NormalisedRundown, OntimeEvent, OntimeRundown } from 'ontime-types';
|
||||
import { SupportedEvent } from 'ontime-types';
|
||||
|
||||
import { getLastEvent, getNext, getNextEvent, getPrevious, getPreviousEvent, swapEventData } from './rundownUtils';
|
||||
import {
|
||||
getLastEvent,
|
||||
getLastNormal,
|
||||
getNext,
|
||||
getNextEvent,
|
||||
getPrevious,
|
||||
getPreviousEvent,
|
||||
swapEventData,
|
||||
} from './rundownUtils';
|
||||
|
||||
describe('getNext()', () => {
|
||||
it('returns the next event of type event', () => {
|
||||
@@ -85,9 +93,9 @@ describe('getPrevious()', () => {
|
||||
{ id: '3', type: SupportedEvent.Event },
|
||||
];
|
||||
|
||||
const { previousEvent, previousIndex } = getPrevious(testRundown as OntimeRundown, '3');
|
||||
expect(previousEvent?.id).toBe('2');
|
||||
expect(previousIndex).toBe(1);
|
||||
const { entry, index } = getPrevious(testRundown as OntimeRundown, '3');
|
||||
expect(entry?.id).toBe('2');
|
||||
expect(index).toBe(1);
|
||||
});
|
||||
it('allow other event types', () => {
|
||||
const testRundown = [
|
||||
@@ -97,9 +105,9 @@ describe('getPrevious()', () => {
|
||||
{ id: '4', type: SupportedEvent.Event },
|
||||
];
|
||||
|
||||
const { previousEvent, previousIndex } = getPrevious(testRundown as OntimeRundown, '3');
|
||||
expect(previousEvent?.id).toBe('2');
|
||||
expect(previousIndex).toBe(1);
|
||||
const { entry, index } = getPrevious(testRundown as OntimeRundown, '3');
|
||||
expect(entry?.id).toBe('2');
|
||||
expect(index).toBe(1);
|
||||
});
|
||||
it('returns null if none found', () => {
|
||||
const testRundown = [
|
||||
@@ -108,9 +116,9 @@ describe('getPrevious()', () => {
|
||||
{ id: '4', type: SupportedEvent.Event },
|
||||
];
|
||||
|
||||
const { previousEvent, previousIndex } = getPrevious(testRundown as OntimeRundown, '2');
|
||||
expect(previousEvent).toBe(null);
|
||||
expect(previousIndex).toBe(null);
|
||||
const { entry, index } = getPrevious(testRundown as OntimeRundown, '2');
|
||||
expect(entry).toBe(null);
|
||||
expect(index).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -209,4 +217,49 @@ describe('getLastEvent', () => {
|
||||
const { lastEvent } = getLastEvent(testRundown as OntimeRundown);
|
||||
expect(lastEvent?.id).toBe('1');
|
||||
});
|
||||
|
||||
describe('getLastNormal', () => {
|
||||
it('returns the last entry', () => {
|
||||
const testRundown = {
|
||||
4: { id: '4', type: SupportedEvent.Block },
|
||||
1: { id: '1', type: SupportedEvent.Event },
|
||||
3: { id: '3', type: SupportedEvent.Event },
|
||||
2: { id: '2', type: SupportedEvent.Delay },
|
||||
};
|
||||
|
||||
const order = ['1', '2', '3', '4'];
|
||||
|
||||
const lastEntry = getLastNormal(testRundown as unknown as NormalisedRundown, order);
|
||||
expect(lastEntry?.id).toBe('4');
|
||||
});
|
||||
it('handles rundowns with a single event', () => {
|
||||
const testRundown = [{ id: '1', type: SupportedEvent.Event }];
|
||||
|
||||
const { lastEvent } = getLastEvent(testRundown as OntimeRundown);
|
||||
expect(lastEvent?.id).toBe('1');
|
||||
});
|
||||
|
||||
it('handles empty order', () => {
|
||||
const testRundown = {
|
||||
4: { id: '4', type: SupportedEvent.Block },
|
||||
1: { id: '1', type: SupportedEvent.Event },
|
||||
3: { id: '3', type: SupportedEvent.Event },
|
||||
2: { id: '2', type: SupportedEvent.Delay },
|
||||
};
|
||||
|
||||
const order: string[] = [];
|
||||
|
||||
const lastEntry = getLastNormal(testRundown as unknown as NormalisedRundown, order);
|
||||
expect(lastEntry).toBe(null);
|
||||
});
|
||||
|
||||
it('handles empty rundown', () => {
|
||||
const testRundown = {};
|
||||
|
||||
const order = ['1', '2', '3', '4'];
|
||||
|
||||
const lastEntry = getLastNormal(testRundown as unknown as NormalisedRundown, order);
|
||||
expect(lastEntry).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { NormalisedRundown, OntimeEvent, OntimeRundown, OntimeRundownEntry } from 'ontime-types';
|
||||
import { isOntimeEvent } from 'ontime-types';
|
||||
|
||||
type IndexAndEntry = { entry: OntimeRundownEntry | null; index: number | null };
|
||||
|
||||
/**
|
||||
* Gets first event in rundown, if it exists
|
||||
* @param {OntimeRundownEntry[]} rundown
|
||||
@@ -62,6 +64,20 @@ export function getFirstEventNormal(
|
||||
return { firstEvent: null, firstIndex: null };
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets last event in a normalised rundown, if it exists
|
||||
* @param rundown
|
||||
* @param order
|
||||
* @returns
|
||||
*/
|
||||
export function getLastNormal(rundown: NormalisedRundown, order: string[]): OntimeRundownEntry | null {
|
||||
const lastId = order.at(-1);
|
||||
if (lastId === undefined) {
|
||||
return null;
|
||||
}
|
||||
return rundown[lastId] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets last scheduled event in rundown, if it exists
|
||||
* @param {OntimeRundownEntry[]} rundown
|
||||
@@ -138,19 +154,15 @@ export function getNext(
|
||||
* @param currentId
|
||||
* @returns
|
||||
*/
|
||||
export function getNextNormal(
|
||||
rundown: NormalisedRundown,
|
||||
order: string[],
|
||||
currentId: string,
|
||||
): { nextEvent: OntimeRundownEntry | null; nextIndex: number | null } {
|
||||
const index = order.findIndex((id) => id === currentId);
|
||||
if (index !== -1 && index + 1 < order.length) {
|
||||
const nextIndex = index + 1;
|
||||
const nextId = order[nextIndex];
|
||||
const nextEvent = rundown[nextId];
|
||||
return { nextEvent, nextIndex };
|
||||
export function getNextNormal(rundown: NormalisedRundown, order: string[], currentId: string): IndexAndEntry {
|
||||
const currentIndex = order.findIndex((id) => id === currentId);
|
||||
if (currentIndex !== -1 && currentIndex + 1 < order.length) {
|
||||
const index = currentIndex + 1;
|
||||
const nextId = order[index];
|
||||
const entry = rundown[nextId];
|
||||
return { entry, index };
|
||||
} else {
|
||||
return { nextEvent: null, nextIndex: null };
|
||||
return { entry: null, index: null };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,19 +221,15 @@ export function getNextEventNormal(
|
||||
* Gets previous entry in rundown, if it exists
|
||||
* @param {OntimeRundownEntry[]} rundown
|
||||
* @param {string} currentId
|
||||
* @return {{ previousEvent: OntimeRundownEntry | null; previousIndex: number | null } }
|
||||
*/
|
||||
export function getPrevious(
|
||||
rundown: OntimeRundownEntry[],
|
||||
currentId: string,
|
||||
): { previousEvent: OntimeRundownEntry | null; previousIndex: number | null } {
|
||||
const index = rundown.findIndex((event) => event.id === currentId);
|
||||
if (index !== -1 && index - 1 >= 0) {
|
||||
const previousIndex = index - 1;
|
||||
const previousEvent = rundown[previousIndex];
|
||||
return { previousEvent, previousIndex };
|
||||
export function getPrevious(rundown: OntimeRundownEntry[], currentId: string): IndexAndEntry {
|
||||
const currentIndex = rundown.findIndex((event) => event.id === currentId);
|
||||
if (currentIndex !== -1 && currentIndex - 1 >= 0) {
|
||||
const index = currentIndex - 1;
|
||||
const entry = rundown[index];
|
||||
return { entry, index };
|
||||
} else {
|
||||
return { previousEvent: null, previousIndex: null };
|
||||
return { entry: null, index: null };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,21 +238,16 @@ export function getPrevious(
|
||||
* @param rundown
|
||||
* @param order
|
||||
* @param {string} currentId
|
||||
* @return {{ previousEvent: OntimeRundownEntry | null; previousIndex: number | null } }
|
||||
*/
|
||||
export function getPreviousNormal(
|
||||
rundown: NormalisedRundown,
|
||||
order: string[],
|
||||
currentId: string,
|
||||
): { previousEvent: OntimeRundownEntry | null; previousIndex: number | null } {
|
||||
const index = order.findIndex((id) => id === currentId);
|
||||
if (index !== -1 && index - 1 >= 0) {
|
||||
const previousIndex = index - 1;
|
||||
const previousId = order[previousIndex];
|
||||
const previousEvent = rundown[previousId];
|
||||
return { previousEvent, previousIndex };
|
||||
export function getPreviousNormal(rundown: NormalisedRundown, order: string[], currentId: string): IndexAndEntry {
|
||||
const currentIndex = order.findIndex((id) => id === currentId);
|
||||
if (currentIndex !== -1 && currentIndex - 1 >= 0) {
|
||||
const index = currentIndex - 1;
|
||||
const previousId = order[index];
|
||||
const entry = rundown[previousId];
|
||||
return { entry, index };
|
||||
} else {
|
||||
return { previousEvent: null, previousIndex: null };
|
||||
return { entry: null, index: null };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user