Skip to content

Commit 99f9b45

Browse files
authored
Scheduler: workspace refactor — pass config object instead of workspace for groupedStrategy (#33957)
1 parent 0d9c8f1 commit 99f9b45

5 files changed

Lines changed: 157 additions & 113 deletions

File tree

packages/devextreme/js/__internal/scheduler/shaders/current_time_shader_horizontal.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class HorizontalCurrentTimeShader extends CurrentTimeShader {
3434
groupIndex: number,
3535
dateTableCellCount: number,
3636
): void {
37-
// @ts-expect-error
38-
const shaderWidth = this.workSpace.getIndicationWidth() as number;
37+
const shaderWidth = this.workSpace.getIndicationWidth();
3938

4039
this.applyShaderWidth($shader, shaderWidth);
4140

@@ -68,8 +67,7 @@ class HorizontalCurrentTimeShader extends CurrentTimeShader {
6867
const isFirstShaderPart = groupIndex === 0;
6968
const { workSpace } = this;
7069
const shaderWidth = isFirstShaderPart
71-
// @ts-expect-error
72-
? workSpace.getIndicationWidth() as number
70+
? workSpace.getIndicationWidth()
7371
: fractionPart * workSpace.getCellWidth();
7472
let shaderLeft = 0;
7573

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import {
101101
import type { ViewDataProviderOptions } from './view_model/types';
102102
import ViewDataProvider from './view_model/view_data_provider';
103103
import { VirtualScrollingDispatcher, VirtualScrollingRenderer } from './virtual_scrolling';
104+
import type { GroupedStrategyConfig } from './work_space_grouped_strategy_config';
104105
import HorizontalGroupedStrategy from './work_space_grouped_strategy_horizontal';
105106
import VerticalGroupedStrategy from './work_space_grouped_strategy_vertical';
106107

@@ -1685,6 +1686,18 @@ class SchedulerWorkSpace extends Widget<WorkspaceOptionsInternal> {
16851686
);
16861687
}
16871688

1689+
getIndicatorOffset(): number {
1690+
return 0;
1691+
}
1692+
1693+
getIndicationHeight(): number {
1694+
return 0;
1695+
}
1696+
1697+
getIndicationWidth(): number {
1698+
return 0;
1699+
}
1700+
16881701
getMaxAllowedPosition(groupIndex) {
16891702
return getMaxAllowedPosition(
16901703
groupIndex,
@@ -2609,7 +2622,39 @@ class SchedulerWorkSpace extends Widget<WorkspaceOptionsInternal> {
26092622
? VerticalGroupedStrategy
26102623
: HorizontalGroupedStrategy;
26112624

2612-
this.groupedStrategy = new Strategy(this);
2625+
this.groupedStrategy = new Strategy(this.createGroupedStrategyConfig());
2626+
}
2627+
2628+
private createGroupedStrategyConfig(): GroupedStrategyConfig {
2629+
return {
2630+
getRowCount: () => this.getRowCount(),
2631+
getCellCount: () => this.getCellCount(),
2632+
getGroupCount: () => this.getGroupCount(),
2633+
getCellHeight: () => this.getCellHeight(),
2634+
getCellWidth: () => this.getCellWidth(),
2635+
getTimePanelWidth: () => this.getTimePanelWidth(),
2636+
getGroupTableWidth: () => this.getGroupTableWidth(),
2637+
getAllDayHeight: () => this.getAllDayHeight(),
2638+
getWorkSpaceWidth: () => this.getWorkSpaceWidth(),
2639+
getWorkSpaceLeftOffset: () => this.getWorkSpaceLeftOffset(),
2640+
getIndicatorOffset: () => this.getIndicatorOffset(),
2641+
getIndicationHeight: () => this.getIndicationHeight(),
2642+
getIndicationWidth: () => this.getIndicationWidth(),
2643+
getScrollableScrollTop: () => this.getScrollable().scrollTop(),
2644+
getScrollableContentElement: () => this.getScrollable().$content().get(0),
2645+
getElement: () => this.$element().get(0),
2646+
getHeaderPanelContainerElement: () => this.$headerPanelContainer.get(0),
2647+
getCellIndexByCoordinates: (coordinates) => this.getCellIndexByCoordinates(coordinates),
2648+
supportAllDayRow: () => this.supportAllDayRow(),
2649+
isGroupedByDate: () => this.isGroupedByDate(),
2650+
showAllDayPanel: () => this.option('showAllDayPanel'),
2651+
startDayHour: () => this.option('startDayHour'),
2652+
endDayHour: () => this.option('endDayHour'),
2653+
hoursInterval: () => this.option('hoursInterval'),
2654+
crossScrollingEnabled: () => this.option('crossScrollingEnabled'),
2655+
rtlEnabled: () => this.option('rtlEnabled'),
2656+
getHeaderHeight: () => this.option('getHeaderHeight')?.() ?? 0,
2657+
};
26132658
}
26142659

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

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

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,46 @@ import type {
66
GroupBoundsOffset,
77
} from '@ts/scheduler/types';
88
import { WORK_SPACE_BORDER_PX } from '@ts/scheduler/workspaces/const';
9-
import type SchedulerWorkSpace from '@ts/scheduler/workspaces/m_work_space';
109

1110
import { FIRST_GROUP_CELL_CLASS, LAST_GROUP_CELL_CLASS } from '../classes';
1211
import type { ResourceLoader } from '../utils/loader/resource_loader';
12+
import type { GroupedStrategyConfig } from './work_space_grouped_strategy_config';
1313

1414
class HorizontalGroupedStrategy {
15-
constructor(private readonly workspace: SchedulerWorkSpace) {}
15+
constructor(private readonly config: GroupedStrategyConfig) {}
1616

1717
prepareCellIndexes(
1818
cellCoordinates: CellPositionData,
1919
groupIndex: number,
2020
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2121
inAllDay?: boolean,
2222
): CellPositionData {
23-
const groupByDay = this.workspace.isGroupedByDate();
23+
const groupByDay = this.config.isGroupedByDate();
2424

2525
if (!groupByDay) {
2626
return {
2727
rowIndex: cellCoordinates.rowIndex,
28-
// @ts-expect-error
29-
columnIndex: cellCoordinates.columnIndex + groupIndex * this.workspace.getCellCount(),
28+
columnIndex: cellCoordinates.columnIndex + groupIndex * this.config.getCellCount(),
3029
};
3130
}
3231
return {
3332
rowIndex: cellCoordinates.rowIndex,
34-
// @ts-expect-error
35-
columnIndex: cellCoordinates.columnIndex * this.workspace.getGroupCount() + groupIndex,
33+
columnIndex: cellCoordinates.columnIndex * this.config.getGroupCount() + groupIndex,
3634
};
3735
}
3836

3937
getGroupIndex(rowIndex: number, columnIndex: number): number {
40-
const groupByDay = this.workspace.isGroupedByDate();
41-
// @ts-expect-error
42-
const groupCount = this.workspace.getGroupCount();
38+
const groupByDay = this.config.isGroupedByDate();
39+
const groupCount = this.config.getGroupCount();
4340

4441
if (groupByDay) {
4542
return columnIndex % groupCount;
4643
}
47-
// @ts-expect-error
48-
return Math.floor(columnIndex / this.workspace.getCellCount());
44+
return Math.floor(columnIndex / this.config.getCellCount());
4945
}
5046

5147
calculateHeaderCellRepeatCount(): number {
52-
// @ts-expect-error
53-
return this.workspace.getGroupCount() || 1;
48+
return this.config.getGroupCount() || 1;
5449
}
5550

5651
insertAllDayRowsIntoDateTable(): boolean {
@@ -60,28 +55,26 @@ class HorizontalGroupedStrategy {
6055
getTotalCellCount(groupCount: number): number {
6156
const effectiveGroupCount = groupCount || 1;
6257

63-
// @ts-expect-error
64-
return this.workspace.getCellCount() * effectiveGroupCount;
58+
return this.config.getCellCount() * effectiveGroupCount;
6559
}
6660

6761
getTotalRowCount(): number {
68-
// @ts-expect-error
69-
return this.workspace.getRowCount();
62+
return this.config.getRowCount();
7063
}
7164

7265
calculateTimeCellRepeatCount(): number {
7366
return 1;
7467
}
7568

7669
getWorkSpaceMinWidth(): number {
77-
const workSpaceElementWidth = getBoundingRect(this.workspace.$element().get(0)).width;
70+
const workSpaceElementWidth = getBoundingRect(this.config.getElement()).width;
7871
return workSpaceElementWidth
79-
- this.workspace.getTimePanelWidth()
72+
- this.config.getTimePanelWidth()
8073
- 2 * WORK_SPACE_BORDER_PX;
8174
}
8275

8376
getAllDayOffset(): number {
84-
return this.workspace.getAllDayHeight();
77+
return this.config.getAllDayHeight();
8578
}
8679

8780
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -90,7 +83,7 @@ class HorizontalGroupedStrategy {
9083
}
9184

9285
getLeftOffset(): number {
93-
return this.workspace.getTimePanelWidth();
86+
return this.config.getTimePanelWidth();
9487
}
9588

9689
private createGroupBoundOffset(
@@ -130,11 +123,11 @@ class HorizontalGroupedStrategy {
130123
coordinates: { top: number; left: number; groupIndex?: number },
131124
groupedDataMap: { dateTableGroupedMap: CellInfo[][][] },
132125
): GroupBoundsOffset {
133-
if (this.workspace.isGroupedByDate()) {
126+
if (this.config.isGroupedByDate()) {
134127
return this.getGroupedByDateBoundOffset($cells, cellWidth);
135128
}
136129

137-
const cellIndex = this.workspace.getCellIndexByCoordinates(coordinates);
130+
const cellIndex = this.config.getCellIndexByCoordinates(coordinates);
138131
const groupIndex = coordinates.groupIndex ?? Math.floor(cellIndex / cellCount);
139132

140133
const currentCellGroup = groupedDataMap.dateTableGroupedMap[groupIndex];
@@ -168,37 +161,33 @@ class HorizontalGroupedStrategy {
168161
}
169162

170163
private getIndicatorOffset(groupIndex: number): number {
171-
const groupByDay = this.workspace.isGroupedByDate();
164+
const groupByDay = this.config.isGroupedByDate();
172165

173166
return groupByDay
174167
? this.calculateGroupByDateOffset(groupIndex)
175168
: this.calculateOffset(groupIndex);
176169
}
177170

178171
private calculateOffset(groupIndex: number): number {
179-
// @ts-expect-error
180-
const indicatorStartPosition = this.workspace.getIndicatorOffset(groupIndex) as number;
181-
// @ts-expect-error
182-
const offset = this.workspace.getCellCount() * this.workspace.getCellWidth() * groupIndex;
172+
const indicatorStartPosition = this.config.getIndicatorOffset();
173+
const offset = this.config.getCellCount() * this.config.getCellWidth() * groupIndex;
183174

184175
return indicatorStartPosition + offset;
185176
}
186177

187178
private calculateGroupByDateOffset(groupIndex: number): number {
188-
// @ts-expect-error
189-
return this.workspace.getIndicatorOffset(0) * this.workspace.getGroupCount()
190-
+ this.workspace.getCellWidth() * groupIndex;
179+
return this.config.getIndicatorOffset() * this.config.getGroupCount()
180+
+ this.config.getCellWidth() * groupIndex;
191181
}
192182

193183
getShaderOffset(i: number, width: number): number {
194-
// @ts-expect-error
195-
const offset = this.workspace.getCellCount() * this.workspace.getCellWidth() * i;
184+
const offset = this.config.getCellCount() * this.config.getCellWidth() * i;
196185

197-
if (this.workspace.option('rtlEnabled')) {
186+
if (this.config.rtlEnabled()) {
198187
const containerWidth = getBoundingRect(
199-
this.workspace.getScrollable().$content().get(0),
188+
this.config.getScrollableContentElement(),
200189
).width;
201-
return containerWidth - offset - this.workspace.getTimePanelWidth() - width;
190+
return containerWidth - offset - this.config.getTimePanelWidth() - width;
202191
}
203192

204193
return offset;
@@ -209,21 +198,19 @@ class HorizontalGroupedStrategy {
209198
}
210199

211200
getShaderHeight(): number {
212-
// @ts-expect-error
213-
return this.workspace.getIndicationHeight() as number;
201+
return this.config.getIndicationHeight();
214202
}
215203

216204
getShaderMaxHeight(): number {
217-
return (getBoundingRect(this.workspace.getScrollable().$content().get(0)) as DOMRect).height;
205+
return (getBoundingRect(this.config.getScrollableContentElement()) as DOMRect).height;
218206
}
219207

220208
getShaderWidth(): number {
221-
// @ts-expect-error
222-
return this.workspace.getIndicationWidth() as number;
209+
return this.config.getIndicationWidth();
223210
}
224211

225212
getScrollableScrollTop(allDay: boolean): number {
226-
return !allDay ? this.workspace.getScrollable().scrollTop() : 0;
213+
return !allDay ? this.config.getScrollableScrollTop() : 0;
227214
}
228215

229216
// ---------------
@@ -251,15 +238,13 @@ class HorizontalGroupedStrategy {
251238
return `${cellClass} ${LAST_GROUP_CELL_CLASS}`;
252239
}
253240

254-
const groupByDate = this.workspace.isGroupedByDate();
241+
const groupByDate = this.config.isGroupedByDate();
255242

256243
if (groupByDate) {
257-
// @ts-expect-error
258-
if (index % this.workspace.getGroupCount() === 0) {
244+
if (index % this.config.getGroupCount() === 0) {
259245
return `${cellClass} ${LAST_GROUP_CELL_CLASS}`;
260246
}
261-
// @ts-expect-error
262-
} else if (index % this.workspace.getCellCount() === 0) {
247+
} else if (index % this.config.getCellCount() === 0) {
263248
return `${cellClass} ${LAST_GROUP_CELL_CLASS}`;
264249
}
265250

@@ -275,15 +260,13 @@ class HorizontalGroupedStrategy {
275260
return `${cellClass} ${FIRST_GROUP_CELL_CLASS}`;
276261
}
277262

278-
const groupByDate = this.workspace.isGroupedByDate();
263+
const groupByDate = this.config.isGroupedByDate();
279264

280265
if (groupByDate) {
281-
// @ts-expect-error
282-
if ((index - 1) % this.workspace.getGroupCount() === 0) {
266+
if ((index - 1) % this.config.getGroupCount() === 0) {
283267
return `${cellClass} ${FIRST_GROUP_CELL_CLASS}`;
284268
}
285-
// @ts-expect-error
286-
} else if ((index - 1) % this.workspace.getCellCount() === 0) {
269+
} else if ((index - 1) % this.config.getCellCount() === 0) {
287270
return `${cellClass} ${FIRST_GROUP_CELL_CLASS}`;
288271
}
289272

0 commit comments

Comments
 (0)