Skip to content

Commit 241c801

Browse files
authored
Scheduler: fix Appointment collector button with wrong info about date (DevExpress#32176)
1 parent 4519473 commit 241c801

File tree

2 files changed

+80
-21
lines changed

2 files changed

+80
-21
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import Scheduler from 'devextreme-testcafe-models/scheduler';
2+
import { createWidget } from '../../../helpers/createWidget';
3+
import { getTimezoneTest, MACHINE_TIMEZONES } from '../../../helpers/machineTimezones';
4+
import url from '../../../helpers/getPageUrl';
5+
6+
fixture.disablePageReloads`Scheduler - Appointment Collector Timezone`
7+
.page(url(__dirname, '../../container.html'));
8+
9+
[
10+
MACHINE_TIMEZONES.EuropeBerlin,
11+
].forEach((machineTimezone) => {
12+
getTimezoneTest([machineTimezone])(
13+
'Appointment collector button should have correct date',
14+
async (t) => {
15+
const scheduler = new Scheduler('#container');
16+
const schedulerCollector = scheduler.collectors.get(0);
17+
const expectedDate = 'March 5, 2021';
18+
19+
const ariaRoleDescription = await schedulerCollector.element().getAttribute('aria-roledescription');
20+
21+
await t
22+
.expect(scheduler.element().exists)
23+
.ok()
24+
.expect(ariaRoleDescription)
25+
.contains(expectedDate, `Collector should display ${expectedDate} after timezone conversion`);
26+
},
27+
).before(async () => {
28+
await createWidget('dxScheduler', {
29+
timeZone: 'America/Los_Angeles',
30+
dataSource: [
31+
{
32+
text: 'Website Re-Design Plan',
33+
startDate: new Date('2021-03-05T15:30:00.000Z'),
34+
endDate: new Date('2021-03-05T17:00:00.000Z'),
35+
},
36+
{
37+
text: 'Complete Shipper Selection Form',
38+
startDate: new Date('2021-03-05T15:30:00.000Z'),
39+
endDate: new Date('2021-03-05T17:00:00.000Z'),
40+
},
41+
{
42+
text: 'Upgrade Server Hardware',
43+
startDate: new Date('2021-03-05T19:00:00.000Z'),
44+
endDate: new Date('2021-03-05T21:15:00.000Z'),
45+
},
46+
{
47+
text: 'Upgrade Personal Computers',
48+
startDate: new Date('2021-03-05T23:45:00.000Z'),
49+
endDate: new Date('2021-03-06T01:30:00.000Z'),
50+
},
51+
],
52+
currentView: 'month',
53+
currentDate: new Date(2021, 2, 1),
54+
maxAppointmentsPerCell: 3,
55+
});
56+
});
57+
});

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import messageLocalization from '@js/common/core/localization/message';
44
import $, { type dxElementWrapper } from '@js/core/renderer';
55
import { FunctionTemplate } from '@js/core/templates/function_template';
66
import Button from '@js/ui/button';
7+
import type { Appointment } from '@js/ui/scheduler';
78

89
import { APPOINTMENT_SETTINGS_KEY, LIST_ITEM_CLASS, LIST_ITEM_DATA_KEY } from './constants';
9-
import type { AppointmentTooltipItem, CompactAppointmentOptions } from './types';
10+
import type Scheduler from './m_scheduler';
11+
import type { AppointmentTooltipItem, CompactAppointmentOptions, TargetedAppointment } from './types';
1012

1113
const APPOINTMENT_COLLECTOR_CLASS = 'dx-scheduler-appointment-collector';
1214
const COMPACT_APPOINTMENT_COLLECTOR_CLASS = `${APPOINTMENT_COLLECTOR_CLASS}-compact`;
@@ -15,7 +17,10 @@ const APPOINTMENT_COLLECTOR_CONTENT_CLASS = `${APPOINTMENT_COLLECTOR_CLASS}-cont
1517
export class CompactAppointmentsHelper {
1618
elements: any[] = [];
1719

18-
constructor(public instance) {
20+
instance: Scheduler;
21+
22+
constructor(instance: Scheduler) {
23+
this.instance = instance;
1924
}
2025

2126
render(options: CompactAppointmentOptions): dxElementWrapper {
@@ -43,6 +48,7 @@ export class CompactAppointmentsHelper {
4348
const $button = $(e.element);
4449
this.instance.showAppointmentTooltipCore(
4550
$button,
51+
// @ts-expect-error
4652
$button.data('items'),
4753
this._getExtraOptionsForTooltip(options, $button),
4854
);
@@ -96,6 +102,7 @@ export class CompactAppointmentsHelper {
96102
_createCompactButton(template, options: CompactAppointmentOptions) {
97103
const $button = this._createCompactButtonElement(options);
98104

105+
// @ts-expect-error
99106
return this.instance._createComponent($button, Button, {
100107
type: 'default',
101108
width: options.width,
@@ -127,7 +134,10 @@ export class CompactAppointmentsHelper {
127134
_createCompactButtonElement({
128135
isCompact, $container, coordinates, sortedIndex, items,
129136
}: CompactAppointmentOptions) {
130-
const appointmentDate = this._getDateText(items[0].appointment);
137+
const appointmentDate = this._getDateText(
138+
items[0].appointment,
139+
items[0].targetedAppointment,
140+
);
131141
const result = $('<div>')
132142
.addClass(APPOINTMENT_COLLECTOR_CLASS)
133143
.attr('aria-roledescription', appointmentDate)
@@ -177,26 +187,18 @@ export class CompactAppointmentsHelper {
177187
return `${dateLocalization.format(date, 'monthAndDay')}, ${dateLocalization.format(date, 'year')}`;
178188
}
179189

180-
_getStartDate(appointment) {
181-
const date = appointment.startDate;
182-
return date ? new Date(date) : null;
183-
}
184-
185-
_getEndDate(appointment) {
186-
const date = appointment.endDate;
187-
return date ? new Date(date) : null;
188-
}
190+
_getDateText(
191+
appointment: Appointment,
192+
targetedAppointment: Appointment | TargetedAppointment | undefined,
193+
): string {
194+
const startDate = targetedAppointment?.displayStartDate ?? appointment.startDate;
195+
const endDate = targetedAppointment?.displayEndDate ?? appointment.endDate;
189196

190-
_getDateText(appointment) {
191-
const startDate = this.instance._dataAccessors.get('startDate', appointment);
192-
const endDate = this.instance._dataAccessors.get('endDate', appointment);
193-
const startDateText = startDate ? this._localizeDate(startDate) : '';
194-
const endDateText = endDate ? this._localizeDate(endDate) : '';
197+
const startDateText = this._localizeDate(startDate);
198+
const endDateText = this._localizeDate(endDate);
195199

196-
const dateText = startDateText === endDateText
197-
? `${startDateText}`
200+
return startDateText === endDateText
201+
? startDateText
198202
: `${startDateText} - ${endDateText}`;
199-
200-
return `${dateText}`;
201203
}
202204
}

0 commit comments

Comments
 (0)