Prevent events chart on pixel and link boards

This commit is contained in:
Mike Cao committed 2026-03-10 00:23:19 -07:00
1 parent 6629ab598b
commit 54023e3796
3 files changed
+65 -4

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
import {
BOARD_ENTITY_TYPES,
isBoardComponentSupported,
} from '../boards';
test('isBoardComponentSupported allows events chart on website boards', () => {
expect(isBoardComponentSupported('EventsChart', BOARD_ENTITY_TYPES.website)).toBe(true);
});
test('isBoardComponentSupported rejects events chart on pixel and link boards', () => {
expect(isBoardComponentSupported('EventsChart', BOARD_ENTITY_TYPES.pixel)).toBe(false);
expect(isBoardComponentSupported('EventsChart', BOARD_ENTITY_TYPES.link)).toBe(false);
});
test('isBoardComponentSupported leaves other components available for all board entities', () => {
expect(isBoardComponentSupported('WebsiteChart', BOARD_ENTITY_TYPES.pixel)).toBe(true);
expect(isBoardComponentSupported('TextBlock', BOARD_ENTITY_TYPES.link)).toBe(true);
});
+16
View File
@@ -18,6 +18,9 @@ export type BoardType = (typeof BOARD_TYPES)[keyof typeof BOARD_TYPES];
export type BoardEntityType = (typeof BOARD_ENTITY_TYPES)[keyof typeof BOARD_ENTITY_TYPES];
const boardTypes = new Set<string>(Object.values(BOARD_TYPES));
const boardComponentEntityTypes: Partial<Record<string, readonly BoardEntityType[]>> = {
EventsChart: [BOARD_ENTITY_TYPES.website],
};
export function getLegacyBoardType(parameters?: BoardParameters): BoardType {
if (parameters?.pixelId) {
@@ -140,6 +143,19 @@ export function getResolvedComponentEntity(
return getComponentEntity(config);
}
export function isBoardComponentSupported(
componentType: string,
entityType?: BoardEntityType,
) {
const supportedEntityTypes = boardComponentEntityTypes[componentType];
if (!entityType || !supportedEntityTypes) {
return true;
}
return supportedEntityTypes.includes(entityType);
}
export function getFirstBoardComponentEntity(
board?: Pick<Board, 'type' | 'parameters'> | Partial<Board>,
) {