Skip to content

Commit ecb93f7

Browse files
sjburweb-flow
andauthored
Scheduler: refactor workspaces module (TS): part 4 (#33915)
Co-authored-by: Sergei Burkatskii <noreply@github.com>
1 parent 1b32068 commit ecb93f7

27 files changed

Lines changed: 441 additions & 261 deletions

packages/devextreme/js/__internal/scheduler/r1/components/base/cell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { PropsWithChildren, PropsWithClassName } from '@ts/core/r1/index';
22
import { BaseInfernoComponent } from '@ts/core/r1/runtime/inferno/index';
3+
import type { GroupLeaf } from '@ts/scheduler/utils/resource_manager/types';
34

45
import { renderUtils } from '../../utils/index';
56
import type { ContentTemplateProps, DefaultProps, PropsWithViewContext } from '../types';
@@ -12,7 +13,7 @@ export interface CellBaseProps extends PropsWithClassName,
1213
startDate: Date;
1314
endDate: Date;
1415
allDay?: boolean;
15-
groups?: Record<string, unknown>;
16+
groups?: GroupLeaf['grouped'];
1617
groupIndex?: number;
1718
text?: string;
1819
index: number;

packages/devextreme/js/__internal/scheduler/r1/components/base/time_panel_table.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ export interface TimePanelTableProps extends PropsWithViewContext {
2121
export const TimePanelTableDefaultProps: DefaultProps<TimePanelTableProps> = {
2222
timePanelData: {
2323
groupedData: [],
24-
leftVirtualCellCount: 0,
25-
rightVirtualCellCount: 0,
26-
topVirtualRowCount: 0,
27-
bottomVirtualRowCount: 0,
24+
isGroupedAllDayPanel: false,
2825
},
2926
};
3027

packages/devextreme/js/__internal/scheduler/r1/components/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { JSXTemplate } from '@ts/core/r1/types';
2+
import type { GroupLeaf } from '@ts/scheduler/utils/resource_manager/types';
23

34
import type { GroupItem, ViewDataBase, ViewType } from '../../types';
45

@@ -7,7 +8,7 @@ export interface BaseTemplateProps {
78
}
89

910
interface BaseTemplateData {
10-
groups?: Record<string, unknown>;
11+
groups?: GroupLeaf['grouped'];
1112
groupIndex?: number;
1213
allDay?: boolean;
1314
text?: string;
@@ -49,7 +50,7 @@ export interface ViewCellData {
4950
otherMonth?: boolean;
5051
today?: boolean;
5152
allDay?: boolean;
52-
groups?: Record<string, unknown>;
53+
groups?: GroupLeaf['grouped'];
5354
groupIndex?: number;
5455
index: number;
5556
isFirstGroupCell: boolean;

packages/devextreme/js/__internal/scheduler/r1/utils/base.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type { ResourceLoader } from '../../utils/loader/resource_loader';
2424
import type { ResourceId } from '../../utils/loader/types';
2525
import { VIEWS } from '../../utils/options/constants_view';
2626
import timeZoneUtils from '../../utils_time_zone';
27+
import type { TimeZoneCalculator } from '../timezone_calculator';
2728

2829
const toMs = dateUtils.dateToMilliseconds;
2930
const DAY_HOURS = 24;
@@ -304,12 +305,12 @@ export const calculateCellIndex: CalculateCellIndex = (
304305
) => columnIndex * rowCount + rowIndex;
305306

306307
export const getTotalRowCountByCompleteData = (
307-
completeData: unknown[][],
308+
completeData: unknown[] | unknown[][],
308309
): number => completeData.length;
309310

310311
export const getDisplayedRowCount = (
311312
displayedRowCount: number | undefined,
312-
completeData: unknown[][],
313+
completeData: unknown[] | unknown[][],
313314
): number => displayedRowCount ?? getTotalRowCountByCompleteData(completeData);
314315

315316
export const getStartViewDateWithoutDST = (startViewDate: Date, startDayHour: number): Date => {
@@ -335,9 +336,10 @@ export const getKeyByGroup = (
335336
return '0';
336337
};
337338

338-
export const getToday = (indicatorTime: Date | undefined, timeZoneCalculator: {
339-
createDate: (todayDate: Date, path: unknown) => Date;
340-
}): Date => {
339+
export const getToday = (
340+
indicatorTime: Date | undefined,
341+
timeZoneCalculator: TimeZoneCalculator | undefined,
342+
): Date => {
341343
const todayDate = indicatorTime ?? new Date();
342344

343345
return timeZoneCalculator?.createDate(todayDate, 'toGrid') || todayDate;

packages/devextreme/js/__internal/scheduler/r1/utils/month.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export const getViewStartByOptions = (
2020
startDate: Date | undefined,
2121
currentDate: Date,
2222
intervalCount: number,
23-
startViewDate: Date,
23+
startViewDate?: Date,
2424
): Date => {
25-
if (!startDate) {
25+
if (!startDate || !startViewDate) {
2626
return new Date(currentDate);
2727
}
2828
let currentStartDate = new Date(startViewDate);
@@ -58,7 +58,7 @@ export const getCellText = (date: Date, intervalCount: number): string => {
5858
export const calculateStartViewDate = (
5959
currentDate: Date,
6060
startDayHour: number,
61-
startDate: Date,
61+
startDate: Date | undefined,
6262
intervalCount: number,
6363
firstDayOfWeekOption: number | undefined,
6464
): Date => {

packages/devextreme/js/__internal/scheduler/types.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Appointment, Properties } from '@js/ui/scheduler';
33
import type { Component } from '@ts/core/widget/component';
44

55
import type { ResourceLoader } from './utils/loader/resource_loader';
6-
import type { GroupValues, RawGroupValues } from './utils/resource_manager/types';
6+
import type { GroupLeaf, GroupValues, RawGroupValues } from './utils/resource_manager/types';
77
import type { AppointmentItemViewModel } from './view_model/types';
88

99
export type Direction = 'vertical' | 'horizontal';
@@ -82,9 +82,9 @@ export type CalculateCellIndex = (
8282
export type CalculateStartViewDate = (
8383
currentDate: Date,
8484
startDayHour: number,
85-
startDate: Date,
85+
startDate: Date | undefined,
8686
intervalCount: number,
87-
firstDayOfWeekOption?: number,
87+
firstDayOfWeekOption?: number | undefined,
8888
skippedDays?: number[],
8989
) => Date;
9090

@@ -95,7 +95,7 @@ export interface ViewCellData {
9595
otherMonth?: boolean;
9696
today?: boolean;
9797
allDay?: boolean;
98-
groups?: Record<string, unknown>;
98+
groups?: GroupLeaf['grouped'];
9999
groupIndex?: number;
100100
index: number;
101101
isFirstGroupCell: boolean;
@@ -107,6 +107,8 @@ export interface ViewCellData {
107107
highlighted?: boolean;
108108
}
109109

110+
export type TimePanelCellData = Omit<ViewCellData, 'endDate'>;
111+
110112
export interface CountGenerationConfig {
111113
intervalCount: number;
112114
currentDate: Date;
@@ -163,7 +165,7 @@ export interface ViewDataProviderOptions {
163165
startDate?: Date;
164166
firstDayOfWeek: number;
165167
today: Date;
166-
168+
skippedDays: number[];
167169
isGenerateTimePanelData?: boolean;
168170
isGenerateWeekDaysHeaderData?: boolean;
169171
}
@@ -173,6 +175,13 @@ export interface CellInfo {
173175
position: CellPositionData;
174176
}
175177

178+
export interface GroupInfo {
179+
allDay: boolean;
180+
startDate: Date;
181+
endDate: Date;
182+
groupIndex: number;
183+
}
184+
176185
export interface ViewDataMap {
177186
dateTableMap: CellInfo[][];
178187
allDayPanelMap: CellInfo[];
@@ -218,7 +227,7 @@ export interface GroupPanelData {
218227
}
219228

220229
export interface ViewDataBase {
221-
groupIndex: number;
230+
groupIndex: number | undefined;
222231
isGroupedAllDayPanel?: boolean;
223232
key: string;
224233
}
@@ -234,12 +243,18 @@ export interface GroupedViewDataBase {
234243
bottomVirtualRowCount: number;
235244
}
236245

246+
export interface TimePanelDataBase {
247+
topVirtualRowHeight?: number;
248+
bottomVirtualRowHeight?: number;
249+
isGroupedAllDayPanel: boolean;
250+
}
251+
237252
export interface TimePanelCellsData extends ViewDataBase {
238-
dateTable: ViewCellData[];
239-
allDayPanel?: ViewCellData;
253+
dateTable: TimePanelCellData[];
254+
allDayPanel?: TimePanelCellData;
240255
}
241256

242-
export interface TimePanelData extends GroupedViewDataBase {
257+
export interface TimePanelData extends TimePanelDataBase {
243258
groupedData: TimePanelCellsData[];
244259
}
245260

packages/devextreme/js/__internal/scheduler/view_model/generate_view_model/steps/virtual_screen_filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import timeZoneUtils from '../../../utils_time_zone';
2-
import type ViewDataProvider from '../../../workspaces/view_model/m_view_data_provider';
2+
import type ViewDataProvider from '../../../workspaces/view_model/view_data_provider';
33
import { isAppointmentMatchedIntervals } from '../../common/is_appointment_matched_intervals';
44
import type { ListEntity } from '../../types';
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isDateAndTimeView } from '@ts/scheduler/r1/utils/index';
22
import type { CellPositionData, ViewCellData, ViewType } from '@ts/scheduler/types';
33

4-
interface EdgeIndices {
4+
export interface EdgeIndices {
55
firstColumnIndex: number;
66
lastColumnIndex: number;
77
firstRowIndex: number;

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { CellPositionData, ViewCellData } from '@ts/scheduler/types';
22

3-
import type { CellPosition } from './view_model/m_types';
4-
import type ViewDataProvider from './view_model/m_view_data_provider';
3+
import type { CellPosition } from './view_model/types';
4+
import type ViewDataProvider from './view_model/view_data_provider';
55

66
export default class CellsSelectionState {
77
private focusedCell: ViewCellData | null = null;
@@ -28,11 +28,7 @@ export default class CellsSelectionState {
2828
return undefined;
2929
}
3030

31-
const { groupIndex, startDate, allDay } = focusedCell;
32-
const cellInfo = {
33-
groupIndex, startDate, isAllDay: allDay, index: focusedCell.index,
34-
};
35-
const cellPosition = this.viewDataProvider.findCellPositionInMap(cellInfo);
31+
const cellPosition = this.viewDataProvider.findCellPositionInMap(focusedCell);
3632

3733
return { coordinates: cellPosition, cellData: focusedCell };
3834
}

packages/devextreme/js/__internal/scheduler/workspaces/helpers/position_helper.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable max-classes-per-file */
22

33
import type { CountGenerationConfig, DOMMetaData } from '../../types';
4-
import type ViewDataProvider from '../view_model/m_view_data_provider';
4+
import type ViewDataProvider from '../view_model/view_data_provider';
55

66
export interface PositionHelperOptions {
77
viewDataProvider: ViewDataProvider;
@@ -68,7 +68,11 @@ const getMaxAllowedHorizontalPosition = (
6868

6969
if (!firstRow) return 0;
7070

71-
const { columnIndex } = viewDataProvider.getLastGroupCellPosition(groupIndex);
71+
const lastGroupCellPosition = viewDataProvider.getLastGroupCellPosition(groupIndex);
72+
73+
if (!lastGroupCellPosition) return 0;
74+
75+
const { columnIndex } = lastGroupCellPosition;
7276
const cellPosition = firstRow[columnIndex];
7377

7478
if (!cellPosition) return 0;
@@ -273,7 +277,11 @@ class GroupStrategyBase {
273277
showAllDayPanel,
274278
isGroupedAllDayPanel,
275279
}: GroupTopOptions): number {
276-
const { rowIndex } = this.viewDataProvider.getLastGroupCellPosition(groupIndex);
280+
const lastGroupCellPosition = this.viewDataProvider.getLastGroupCellPosition(groupIndex);
281+
282+
if (!lastGroupCellPosition) return 0;
283+
284+
const { rowIndex } = lastGroupCellPosition;
277285
const { dateTableCellsMeta } = this.DOMMetaData;
278286
const lastGroupRow = dateTableCellsMeta[rowIndex];
279287

0 commit comments

Comments
 (0)