Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar: Should switch to the last date view in multiple mode when value is changed (T1279950) #29358

Open
wants to merge 1 commit into
base: 25_1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ class CalendarMultiSelectionStrategy extends CalendarSelectionStrategy {
}

getDefaultCurrentDate() {
const dates = this.dateOption('value').filter((value) => value);
return this._getLowestDateInArray(dates);
const dates = this.dateOption('value').filter(Boolean);
if (dates.length) {
return dates[dates.length - 1];
}
}

restoreValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,27 @@ QUnit.module('Preserve time component on value change', {

assert.deepEqual(calendar.option('value'), new Date(2015, 8, 2, 12, 57));
});

QUnit.test('should switch to the last date after setting option programmatically (T1279950)', function(assert) {
this.calendar.option({
selectionMode: 'multiple',
value: [new Date(2025, 1, 10), new Date(2025, 2, 10)],
});

const calendar = this.calendar;

assert.ok(
dateUtils.sameMonth(calendar.option('currentDate'), new Date(2025, 2, 10)),
'initially navigated to the last date'
);

calendar.option('value', [new Date(2025, 2, 10), new Date(2025, 4, 10), new Date(2025, 3, 10)]);

assert.ok(
dateUtils.sameMonth(calendar.option('currentDate'), new Date(2025, 3, 10)),
'switched to the last entered date'
);
});
});


Expand Down Expand Up @@ -2015,15 +2036,15 @@ QUnit.module('Options', {

[
{
value: [new Date('01/05/2023'), new Date('02/01/2023')],
value: [new Date('02/01/2023'), new Date('01/05/2023')],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please clarify why we need these changes?

type: 'dates'
},
{
value: ['01/05/2023', '02/01/2023'],
value: ['02/01/2023', '01/05/2023'],
type: 'strings'
},
{
value: [1672916400000, 1675249200000],
value: [1675249200000, 1672916400000],
type: 'numbers'
}
].forEach(({ value, type }) => {
Expand All @@ -2040,14 +2061,23 @@ QUnit.module('Options', {
});

QUnit.module('CurrentDate', {}, () => {
QUnit.test(`Should be equal to the lowest defined date in value on init (selectionMode=${selectionMode}`, function(assert) {
const isMultipleMode = selectionMode === 'multiple';
const currentDateRule = isMultipleMode ? 'latest entered' : 'lowest defined';

QUnit.test(`Should be equal to the ${currentDateRule} date in value on init (selectionMode=${selectionMode}`, function(assert) {
const initialValue = [null, new Date('01/15/2023'), new Date('02/01/2023')];

this.reinit({
value: [null, new Date('01/15/2023'), new Date('02/01/2023')],
value: initialValue,
selectionMode
});
const { currentDate, value } = this.calendar.option();

assert.deepEqual(currentDate, new Date(Math.min(...value.filter(value => value))));
if(isMultipleMode) {
assert.deepEqual(currentDate, initialValue[initialValue.length - 1]);
} else {
assert.deepEqual(currentDate, new Date(Math.min(...value.filter(value => value))));
}
});

QUnit.test(`Should be equal to the lowest date in value on runtime value change (selectionMode=${selectionMode}`, function(assert) {
Expand Down Expand Up @@ -2106,7 +2136,7 @@ QUnit.module('Options', {
});

QUnit.test('It should be possible to deselect already selected value by click', function(assert) {
const $cell = $(getCurrentViewInstance(this.calendar).$element().find('*[data-value="2023/01/15"]'));
const $cell = $(getCurrentViewInstance(this.calendar).$element().find('*[data-value="2023/02/01"]'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. We should be able to deselect any date, why then it's so important to update here?


$cell.trigger('dxclick');

Expand Down
Loading