Refine edit layouts and share states

This commit is contained in:
Mike Cao committed 2026-03-10 02:52:13 -07:00
1 parent cdcb1f379b
commit 6b8159e535
9 files changed
+164 -153

No files matched your search

+11
View File
@@ -2,6 +2,10 @@ import {
BOARD_ENTITY_TYPES,
isBoardComponentSupported,
} from '../boards';
import {
BOARD_COMPONENT_COMPATIBILITY_MATRIX,
getSupportedBoardComponentEntityTypes,
} from '../boardComponentCompatibility';
test('isBoardComponentSupported allows events chart on website boards', () => {
expect(isBoardComponentSupported('EventsChart', BOARD_ENTITY_TYPES.website)).toBe(true);
@@ -12,6 +16,13 @@ test('isBoardComponentSupported rejects events chart on pixel and link boards',
expect(isBoardComponentSupported('EventsChart', BOARD_ENTITY_TYPES.link)).toBe(false);
});
test('board component compatibility matrix defines website-only components explicitly', () => {
expect(BOARD_COMPONENT_COMPATIBILITY_MATRIX.EventsChart).toEqual([BOARD_ENTITY_TYPES.website]);
expect(getSupportedBoardComponentEntityTypes('EventsChart')).toEqual([
BOARD_ENTITY_TYPES.website,
]);
});
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);
+22
View File
@@ -0,0 +1,22 @@
import type { BoardEntityType } from './boards';
export const BOARD_COMPONENT_COMPATIBILITY_MATRIX = {
EventsChart: ['website'],
} as const satisfies Partial<Record<string, readonly BoardEntityType[]>>;
export function getSupportedBoardComponentEntityTypes(componentType: string) {
return BOARD_COMPONENT_COMPATIBILITY_MATRIX[componentType];
}
export function isBoardComponentSupportedByEntityType(
componentType: string,
entityType?: BoardEntityType,
) {
const supportedEntityTypes = getSupportedBoardComponentEntityTypes(componentType);
if (!entityType || !supportedEntityTypes) {
return true;
}
return supportedEntityTypes.includes(entityType);
}
+2 -10
View File
@@ -1,4 +1,5 @@
import type { Board, BoardComponentConfig, BoardParameters } from './types';
import { isBoardComponentSupportedByEntityType } from './boardComponentCompatibility';
export const BOARD_TYPES = {
dashboard: 'dashboard',
@@ -18,9 +19,6 @@ 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) {
@@ -147,13 +145,7 @@ export function isBoardComponentSupported(
componentType: string,
entityType?: BoardEntityType,
) {
const supportedEntityTypes = boardComponentEntityTypes[componentType];
if (!entityType || !supportedEntityTypes) {
return true;
}
return supportedEntityTypes.includes(entityType);
return isBoardComponentSupportedByEntityType(componentType, entityType);
}
export function getFirstBoardComponentEntity(