Skip to content

Commit 3e0dadb

Browse files
authored
Scheduler: refactor Tooltip Strategies module (TS) (#33509)
1 parent 46da7ca commit 3e0dadb

7 files changed

Lines changed: 452 additions & 316 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export class CompactAppointmentsHelper {
5858
private getExtraOptionsForTooltip(options: CompactAppointmentOptions, $appointmentCollector) {
5959
return {
6060
clickEvent: this.clickEvent(options.onAppointmentClick).bind(this),
61-
dragBehavior: options.allowDrag && this.createTooltipDragBehavior($appointmentCollector).bind(this),
61+
dragBehavior: options.allowDrag
62+
? this.createTooltipDragBehavior($appointmentCollector).bind(this)
63+
: undefined,
6264
isButtonClick: true,
6365
_loopFocus: true,
6466
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ import {
6262
} from './r1/utils/index';
6363
import { validateRRule } from './recurrence/validate_rule';
6464
import { SchedulerOptionsBaseWidget } from './scheduler_options_base_widget';
65-
import { DesktopTooltipStrategy } from './tooltip_strategies/m_desktop_tooltip_strategy';
66-
import { MobileTooltipStrategy } from './tooltip_strategies/m_mobile_tooltip_strategy';
65+
import { DesktopTooltipStrategy } from './tooltip_strategies/desktop_tooltip_strategy';
66+
import { MobileTooltipStrategy } from './tooltip_strategies/mobile_tooltip_strategy';
6767
import type {
6868
AppointmentTooltipItem,
6969
SafeAppointment,

packages/devextreme/js/__internal/scheduler/tooltip_strategies/m_desktop_tooltip_strategy.ts renamed to packages/devextreme/js/__internal/scheduler/tooltip_strategies/desktop_tooltip_strategy.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,65 @@
11
import messageLocalization from '@js/common/core/localization/message';
2+
import type { dxElementWrapper } from '@js/core/renderer';
3+
import type { ContentReadyEvent, ItemContextMenuEvent, Properties as ListProperties } from '@js/ui/list';
24
import supportUtils from '@ts/core/utils/m_support';
35
import Tooltip from '@ts/ui/m_tooltip';
46

5-
import { TooltipStrategyBase } from './m_tooltip_strategy_base';
7+
import type { AppointmentTooltipItem } from '../types';
8+
import { TooltipStrategyBase } from './tooltip_strategy_base';
69

710
const APPOINTMENT_TOOLTIP_WRAPPER_CLASS = 'dx-scheduler-appointment-tooltip-wrapper';
811
const MAX_TOOLTIP_HEIGHT = 200;
912

1013
export class DesktopTooltipStrategy extends TooltipStrategyBase {
11-
protected override prepareBeforeVisibleChanged(dataList) {
12-
this.tooltip.option('position', {
14+
protected override prepareBeforeVisibleChanged(dataList: AppointmentTooltipItem[]): void {
15+
this.tooltip?.option('position', {
1316
my: 'bottom',
1417
at: 'top',
1518
boundary: this.getBoundary(dataList),
16-
offset: this.extraOptions.offset,
19+
offset: this.extraOptions?.offset,
1720
collision: 'fit flipfit',
1821
});
1922
}
2023

21-
private getBoundary(dataList) {
22-
return this._options.isAppointmentInAllDayPanel(dataList[0].appointment) ? this._options.container : this._options.getScrollableContainer();
24+
private getBoundary(dataList: AppointmentTooltipItem[]): dxElementWrapper {
25+
return this._options.isAppointmentInAllDayPanel(dataList[0].appointment)
26+
? this._options.container
27+
: this._options.getScrollableContainer();
2328
}
2429

25-
protected override onShown() {
30+
protected override onShown(): void {
2631
super.onShown();
27-
if (this.extraOptions.isButtonClick) {
32+
if (this.extraOptions?.isButtonClick) {
2833
this.list.focus();
2934
this.list.option('focusedElement', null);
3035
}
3136
}
3237

33-
// @ts-expect-error
34-
protected override createListOption(target, dataList) {
35-
// @ts-expect-error
36-
const result: any = super.createListOption(target, dataList);
38+
protected override createListOption(
39+
dataList: AppointmentTooltipItem[],
40+
): ListProperties<AppointmentTooltipItem> {
41+
const result = super.createListOption(dataList);
3742
// T724287 this condition is not covered by tests, because touch variable cannot be overridden.
3843
// In the future, it is necessary to cover the tests
3944
result.showScrollbar = supportUtils.touch ? 'always' : 'onHover';
4045
return result;
4146
}
4247

43-
protected override createTooltip(dataList) {
48+
protected override createTooltip(
49+
dataList: AppointmentTooltipItem[],
50+
): Tooltip {
4451
const tooltipElement = this.createTooltipElement(APPOINTMENT_TOOLTIP_WRAPPER_CLASS);
4552

4653
const tooltip = this._options.createComponent(tooltipElement, Tooltip, {
4754
target: this.$target,
4855
maxHeight: MAX_TOOLTIP_HEIGHT,
49-
rtlEnabled: this.extraOptions.rtlEnabled,
56+
rtlEnabled: this.extraOptions?.rtlEnabled,
5057
onShown: this.onShown.bind(this),
5158
contentTemplate: this.getContentTemplate(dataList),
5259
wrapperAttr: { class: APPOINTMENT_TOOLTIP_WRAPPER_CLASS },
53-
_loopFocus: this.extraOptions._loopFocus,
54-
});
60+
// @ts-expect-error
61+
_loopFocus: this.extraOptions?._loopFocus,
62+
}) as Tooltip;
5563

5664
tooltip.setAria({
5765
role: 'dialog',
@@ -61,11 +69,17 @@ export class DesktopTooltipStrategy extends TooltipStrategyBase {
6169
return tooltip;
6270
}
6371

64-
protected override onListRender(e) {
65-
return this.extraOptions.dragBehavior && this.extraOptions.dragBehavior(e);
72+
protected override onListRender(
73+
e: ContentReadyEvent<AppointmentTooltipItem>,
74+
): void {
75+
if (this.extraOptions?.dragBehavior) {
76+
this.extraOptions.dragBehavior(e);
77+
}
6678
}
6779

68-
protected override onListItemContextMenu(e) {
80+
protected override onListItemContextMenu(
81+
e: ItemContextMenuEvent<AppointmentTooltipItem>,
82+
): void {
6983
const contextMenuEventArgs = this._options.createEventArgs(e);
7084
this._options.onItemContextMenu(contextMenuEventArgs);
7185
}

0 commit comments

Comments
 (0)