Improves all-day event row height calculation

Ensures consistent all-day event row height calculation across CSS and TypeScript.

The all-day event row height calculation is adjusted by removing redundant container padding from the TypeScript constant and synchronizing the CSS variable with the event height.

Additionally, the layout engine is directly tested in the test file for better coverage.
This commit is contained in:
Janus C. H. Knudsen 2025-10-02 01:03:35 +02:00
parent a1e1c5d185
commit f2ad13776f
5 changed files with 58 additions and 53 deletions

View file

@ -13,7 +13,7 @@ export const ALL_DAY_CONSTANTS = {
EVENT_GAP: 2, // Gap between stacked events EVENT_GAP: 2, // Gap between stacked events
CONTAINER_PADDING: 4, // Container padding (top + bottom) CONTAINER_PADDING: 4, // Container padding (top + bottom)
get SINGLE_ROW_HEIGHT() { get SINGLE_ROW_HEIGHT() {
return this.EVENT_HEIGHT + this.EVENT_GAP + this.CONTAINER_PADDING; // 28px return this.EVENT_HEIGHT + this.EVENT_GAP; // 28px
} }
} as const; } as const;

View file

@ -42,6 +42,13 @@ export class AllDayManager {
constructor(eventManager: EventManager) { constructor(eventManager: EventManager) {
this.eventManager = eventManager; this.eventManager = eventManager;
this.allDayEventRenderer = new AllDayEventRenderer(); this.allDayEventRenderer = new AllDayEventRenderer();
// Sync CSS variable with TypeScript constant to ensure consistency
document.documentElement.style.setProperty(
'--single-row-height',
`${ALL_DAY_CONSTANTS.EVENT_HEIGHT}px`
);
this.setupEventListeners(); this.setupEventListeners();
} }
@ -134,9 +141,9 @@ export class AllDayManager {
// Filter for all-day events // Filter for all-day events
const allDayEvents = events.filter(event => event.allDay); const allDayEvents = events.filter(event => event.allDay);
let eventLayouts = this.calculateAllDayEventsLayout(allDayEvents, headerReadyEventPayload.headerElements) this.currentLayouts = this.calculateAllDayEventsLayout(allDayEvents, headerReadyEventPayload.headerElements)
this.allDayEventRenderer.renderAllDayEventsForPeriod(eventLayouts); this.allDayEventRenderer.renderAllDayEventsForPeriod(this.currentLayouts );
this.checkAndAnimateAllDayHeight(); this.checkAndAnimateAllDayHeight();
}); });
@ -166,7 +173,7 @@ export class AllDayManager {
heightDifference: number; heightDifference: number;
} { } {
const root = document.documentElement; const root = document.documentElement;
const targetHeight = targetRows * ALL_DAY_CONSTANTS.SINGLE_ROW_HEIGHT; const targetHeight = targetRows * ALL_DAY_CONSTANTS.SINGLE_ROW_HEIGHT + 2;
// Read CSS variable directly from style property or default to 0 // Read CSS variable directly from style property or default to 0
const currentHeightStr = root.style.getPropertyValue('--all-day-row-height') || '0px'; const currentHeightStr = root.style.getPropertyValue('--all-day-row-height') || '0px';
const currentHeight = parseInt(currentHeightStr) || 0; const currentHeight = parseInt(currentHeightStr) || 0;
@ -200,11 +207,6 @@ export class AllDayManager {
// Max rows = highest row number (e.g. if row 3 is used, height = 3 rows) // Max rows = highest row number (e.g. if row 3 is used, height = 3 rows)
maxRows = highestRow; maxRows = highestRow;
console.log('🔍 AllDayManager: Height calculation using currentLayouts', {
totalLayouts: this.currentLayouts.length,
highestRowFound: highestRow,
maxRows
});
} }
// Store actual row count // Store actual row count

View file

@ -1,22 +1,22 @@
import { describe, it, expect, beforeEach } from 'vitest'; import { describe, it, expect, beforeEach } from 'vitest';
import { AllDayManager } from '../../src/managers/AllDayManager'; import { AllDayLayoutEngine } from '../../src/utils/AllDayLayoutEngine';
import { setupMockDOM, createMockEvent } from '../helpers/dom-helpers'; import { setupMockDOM, createMockEvent } from '../helpers/dom-helpers';
describe('AllDayManager - Manager Functionality', () => { describe('AllDayManager - Layout Engine Integration', () => {
let allDayManager: AllDayManager; let layoutEngine: AllDayLayoutEngine;
beforeEach(() => { beforeEach(() => {
setupMockDOM(); setupMockDOM();
allDayManager = new AllDayManager();
}); });
describe('Layout Calculation Integration', () => { describe('Layout Calculation Integration', () => {
it('should delegate layout calculation to AllDayLayoutEngine', () => { it('should delegate layout calculation to AllDayLayoutEngine', () => {
// Simple integration test to verify manager uses the layout engine correctly // Test AllDayLayoutEngine directly since calculateAllDayEventsLayout is private
const event = createMockEvent('test', 'Test Event', '2024-09-24', '2024-09-24'); const event = createMockEvent('test', 'Test Event', '2024-09-24', '2024-09-24');
const weekDates = ['2024-09-22', '2024-09-23', '2024-09-24', '2024-09-25', '2024-09-26']; const weekDates = ['2024-09-22', '2024-09-23', '2024-09-24', '2024-09-25', '2024-09-26'];
const layouts = allDayManager.calculateAllDayEventsLayout([event], weekDates); layoutEngine = new AllDayLayoutEngine(weekDates);
const layouts = layoutEngine.calculateLayout([event]);
expect(layouts.length).toBe(1); expect(layouts.length).toBe(1);
expect(layouts[0].calenderEvent.id).toBe('test'); expect(layouts[0].calenderEvent.id).toBe('test');
@ -26,14 +26,16 @@ describe('AllDayManager - Manager Functionality', () => {
it('should handle empty event list', () => { it('should handle empty event list', () => {
const weekDates = ['2024-09-22', '2024-09-23', '2024-09-24', '2024-09-25', '2024-09-26']; const weekDates = ['2024-09-22', '2024-09-23', '2024-09-24', '2024-09-25', '2024-09-26'];
const layouts = allDayManager.calculateAllDayEventsLayout([], weekDates); layoutEngine = new AllDayLayoutEngine(weekDates);
const layouts = layoutEngine.calculateLayout([]);
expect(layouts.length).toBe(0); expect(layouts.length).toBe(0);
}); });
it('should handle empty week dates', () => { it('should handle empty week dates', () => {
const event = createMockEvent('test', 'Test Event', '2024-09-24', '2024-09-24'); const event = createMockEvent('test', 'Test Event', '2024-09-24', '2024-09-24');
const layouts = allDayManager.calculateAllDayEventsLayout([event], []); layoutEngine = new AllDayLayoutEngine([]);
const layouts = layoutEngine.calculateLayout([event]);
expect(layouts.length).toBe(0); expect(layouts.length).toBe(0);
}); });

View file

@ -18,6 +18,7 @@
--header-height: 80px; --header-height: 80px;
--all-day-row-height: 0px; /* Default height for all-day events row */ --all-day-row-height: 0px; /* Default height for all-day events row */
--all-day-event-height: 26px; /* Height of single all-day event including gaps */ --all-day-event-height: 26px; /* Height of single all-day event including gaps */
--single-row-height: 28px; /* Height of single row in all-day container - synced with TypeScript */
--stack-levels: 1; /* Number of stack levels for all-day events */ --stack-levels: 1; /* Number of stack levels for all-day events */
/* Time boundaries - Default fallback values */ /* Time boundaries - Default fallback values */

View file

@ -200,8 +200,8 @@ swp-allday-container {
grid-row: 2; grid-row: 2;
display: grid; display: grid;
grid-template-columns: repeat(var(--grid-columns, 7), minmax(var(--day-column-min-width), 1fr)); grid-template-columns: repeat(var(--grid-columns, 7), minmax(var(--day-column-min-width), 1fr));
grid-template-rows: repeat(1, auto); grid-auto-rows: var(--single-row-height); /* Each row is exactly SINGLE_ROW_HEIGHT */
gap: 2px; gap: 2px 0px;
padding: 2px; padding: 2px;
align-items: center; align-items: center;
overflow: hidden; overflow: hidden;