Skip to content

Commit 9c22a9b

Browse files
committed
refactor(scheduler): pass config object to grouped strategies
1 parent 069e8ea commit 9c22a9b

5 files changed

Lines changed: 232 additions & 109 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import {
2+
describe, expect, it,
3+
} from '@jest/globals';
4+
5+
import type { WorkspaceGroupedStrategyConfig } from '../workspaces/types';
6+
import HorizontalGroupedStrategy from '../workspaces/work_space_grouped_strategy_horizontal';
7+
import VerticalGroupedStrategy from '../workspaces/work_space_grouped_strategy_vertical';
8+
9+
const createConfig = (
10+
overrides: Partial<WorkspaceGroupedStrategyConfig> = {},
11+
): WorkspaceGroupedStrategyConfig => ({
12+
isGroupedByDate: () => false,
13+
getCellCount: () => 7,
14+
getGroupCount: () => 3,
15+
getRowCount: () => 48,
16+
getCellWidth: () => 75,
17+
getCellHeight: () => 50,
18+
getAllDayHeight: () => 30,
19+
getTimePanelWidth: () => 100,
20+
getGroupTableWidth: () => 60,
21+
getWorkSpaceWidth: () => 800,
22+
getWorkSpaceLeftOffset: () => 160,
23+
getIndicatorOffset: () => 10,
24+
getIndicationHeight: () => 200,
25+
getIndicationWidth: () => 300,
26+
getCellIndexByCoordinates: () => 5,
27+
supportAllDayRow: () => true,
28+
getScrollableScrollTop: () => 0,
29+
getScrollableContentElement: () => document.createElement('div'),
30+
getElement: () => document.createElement('div'),
31+
getHeaderPanelContainerElement: () => document.createElement('div'),
32+
isRtlEnabled: () => false,
33+
isShowAllDayPanel: () => true,
34+
isCrossScrollingEnabled: () => false,
35+
getStartDayHour: () => 0,
36+
getEndDayHour: () => 24,
37+
getHoursInterval: () => 0.5,
38+
getHeaderHeight: () => 40,
39+
...overrides,
40+
});
41+
42+
describe('HorizontalGroupedStrategy with config object', () => {
43+
it('should work with config interface instead of workspace', () => {
44+
const strategy = new HorizontalGroupedStrategy(
45+
createConfig({ getCellCount: () => 5, getGroupCount: () => 4 }),
46+
);
47+
48+
const result = strategy.prepareCellIndexes({ rowIndex: 2, columnIndex: 3 }, 2);
49+
50+
expect(result.columnIndex).toBe(3 + 2 * 5);
51+
expect(result.rowIndex).toBe(2);
52+
});
53+
});
54+
55+
describe('VerticalGroupedStrategy with config object', () => {
56+
it('should work with config interface instead of workspace', () => {
57+
const strategy = new VerticalGroupedStrategy(createConfig({
58+
getRowCount: () => 10,
59+
supportAllDayRow: () => true,
60+
isShowAllDayPanel: () => true,
61+
}));
62+
63+
const result = strategy.prepareCellIndexes({ rowIndex: 3, columnIndex: 2 }, 2, false);
64+
65+
expect(result.rowIndex).toBe(3 + 2 * 10 + 2 + 1);
66+
expect(result.columnIndex).toBe(2);
67+
});
68+
});

packages/devextreme/js/__internal/scheduler/workspaces/m_work_space.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import {
9898
getMaxAllowedPosition,
9999
PositionHelper,
100100
} from './helpers/position_helper';
101+
import type { WorkspaceGroupedStrategyConfig } from './types';
101102
import type { ViewDataProviderOptions } from './view_model/m_types';
102103
import ViewDataProvider from './view_model/m_view_data_provider';
103104
import { VirtualScrollingDispatcher, VirtualScrollingRenderer } from './virtual_scrolling';
@@ -924,6 +925,18 @@ class SchedulerWorkSpace extends Widget<WorkspaceOptionsInternal> {
924925
});
925926
}
926927

928+
protected getIndicatorOffset(): number {
929+
return 0;
930+
}
931+
932+
protected getIndicationHeight(): number {
933+
return 0;
934+
}
935+
936+
protected getIndicationWidth(): number {
937+
return 0;
938+
}
939+
927940
private isVirtualModeOn() {
928941
return this.option('scrolling.mode') === 'virtual';
929942
}
@@ -2625,7 +2638,37 @@ class SchedulerWorkSpace extends Widget<WorkspaceOptionsInternal> {
26252638
? VerticalGroupedStrategy
26262639
: HorizontalGroupedStrategy;
26272640

2628-
this.groupedStrategy = new Strategy(this);
2641+
const config: WorkspaceGroupedStrategyConfig = {
2642+
isGroupedByDate: this.isGroupedByDate.bind(this),
2643+
getCellCount: this.getCellCount.bind(this),
2644+
getGroupCount: this.getGroupCount.bind(this),
2645+
getRowCount: this.getRowCount.bind(this),
2646+
getCellWidth: this.getCellWidth.bind(this),
2647+
getCellHeight: this.getCellHeight.bind(this),
2648+
getAllDayHeight: this.getAllDayHeight.bind(this),
2649+
getTimePanelWidth: this.getTimePanelWidth.bind(this),
2650+
getGroupTableWidth: this.getGroupTableWidth.bind(this),
2651+
getWorkSpaceWidth: this.getWorkSpaceWidth.bind(this),
2652+
getWorkSpaceLeftOffset: this.getWorkSpaceLeftOffset.bind(this),
2653+
getIndicatorOffset: () => this.getIndicatorOffset(),
2654+
getIndicationHeight: () => this.getIndicationHeight(),
2655+
getIndicationWidth: () => this.getIndicationWidth(),
2656+
getCellIndexByCoordinates: this.getCellIndexByCoordinates.bind(this),
2657+
supportAllDayRow: this.supportAllDayRow.bind(this),
2658+
getScrollableScrollTop: () => this.getScrollable().scrollTop(),
2659+
getScrollableContentElement: () => this.getScrollable().$content().get(0) as HTMLElement,
2660+
getElement: () => (this.$element() as any).get(0) as HTMLElement,
2661+
getHeaderPanelContainerElement: () => this.$headerPanelContainer.get(0) as HTMLElement,
2662+
isRtlEnabled: () => this.option('rtlEnabled'),
2663+
isShowAllDayPanel: () => this.option('showAllDayPanel'),
2664+
isCrossScrollingEnabled: () => this.option('crossScrollingEnabled'),
2665+
getStartDayHour: () => this.option('startDayHour'),
2666+
getEndDayHour: () => this.option('endDayHour'),
2667+
getHoursInterval: () => this.option('hoursInterval'),
2668+
getHeaderHeight: () => this.option('getHeaderHeight')(),
2669+
};
2670+
2671+
this.groupedStrategy = new Strategy(config);
26292672
}
26302673

26312674
protected getDefaultGroupStrategy() {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export interface WorkspaceGroupedStrategyConfig {
2+
isGroupedByDate: () => boolean;
3+
getCellCount: () => number;
4+
getGroupCount: () => number;
5+
getRowCount: () => number;
6+
getCellWidth: () => number;
7+
getCellHeight: () => number;
8+
getAllDayHeight: () => number;
9+
getTimePanelWidth: () => number;
10+
getGroupTableWidth: () => number;
11+
getWorkSpaceWidth: () => number;
12+
getWorkSpaceLeftOffset: () => number;
13+
getIndicatorOffset: () => number;
14+
getIndicationHeight: () => number;
15+
getIndicationWidth: () => number;
16+
getCellIndexByCoordinates: (
17+
coordinates: { top: number; left: number },
18+
allDay?: boolean,
19+
) => number;
20+
supportAllDayRow: () => boolean;
21+
getScrollableScrollTop: () => number;
22+
getScrollableContentElement: () => HTMLElement;
23+
getElement: () => HTMLElement;
24+
getHeaderPanelContainerElement: () => HTMLElement;
25+
isRtlEnabled: () => boolean;
26+
isShowAllDayPanel: () => boolean;
27+
isCrossScrollingEnabled: () => boolean;
28+
getStartDayHour: () => number;
29+
getEndDayHour: () => number;
30+
getHoursInterval: () => number;
31+
getHeaderHeight: () => number;
32+
}

0 commit comments

Comments
 (0)