Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Use latestSelectedDateObj to find which date got clicked

Oliver Günther57a48d83fb14
diff --git a/frontend/src/app/shared/components/datepicker/multi-date-modal/multi-date.modal.ts b/frontend/src/app/shared/components/datepicker/multi-date-modal/multi-date.modal.ts
index 335776b8b36..7bf200bf40e 100644
--- a/frontend/src/app/shared/components/datepicker/multi-date-modal/multi-date.modal.ts
+++ b/frontend/src/app/shared/components/datepicker/multi-date-modal/multi-date.modal.ts
@@ -76,7 +76,6 @@ import {
setDates,
validDate,
} from 'core-app/shared/components/datepicker/helpers/date-modal.helpers';
-import { castArray } from 'lodash';
import { WeekdayService } from 'core-app/core/days/weekday.service';
import DateOption = flatpickr.Options.DateOption;
import { FocusHelperService } from 'core-app/shared/directives/focus/focus-helper';
@@ -88,7 +87,7 @@ type StartUpdate = { startDate:string };
type EndUpdate = { dueDate:string };
type DurationUpdate = { duration:string|number|null };
type DateUpdate = { date:string };
-type ActiveDateChange = [DateFields, null|Date|Date[]];
+type ActiveDateChange = [DateFields, null|Date|Date];
export type FieldUpdates =
StartUpdate
@@ -192,7 +191,7 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVi
.subscribe(([field, update]) => {
// When clearing the one date, clear the others as well
if (update !== null) {
- this.handleDatePickerChange(field, castArray(update));
+ this.handleSingleDateUpdate(field, update);
}
// Clear active field and duration
@@ -474,9 +473,10 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVi
this.reposition(jQuery(this.modalContainer.nativeElement), jQuery(`.${activeFieldContainerClassName}`));
this.ensureHoveredSelection(instance.calendarContainer);
},
- onChange: (dates:Date[]) => {
+ onChange: (dates:Date[], _datestr, instance) => {
+ const { latestSelectedDateObj } = instance as { latestSelectedDateObj:Date };
const activeField = this.currentlyActivatedDateField;
- this.datepickerChanged$.next([activeField, dates]);
+ this.datepickerChanged$.next([activeField, latestSelectedDateObj]);
// The duration field is special in how it handles focus transitions
// For start/due we just toggle here
@@ -520,26 +520,6 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVi
this.onDataChange();
}
- private handleDatePickerChange(activeField:DateFields, dates:Date[]) {
- if (dates.length === 2) {
- this.handleMultiDateUpdate(activeField, dates);
- } else {
- this.handleSingleDateUpdate(activeField, dates[0]);
- }
- }
-
- private handleMultiDateUpdate(activeField:DateFields, dates:Date[]) {
- // Write the dates to the input fields
- this.dates.start = this.timezoneService.formattedISODate(dates[0]);
- this.dates.end = this.timezoneService.formattedISODate(dates[1]);
-
- if (activeField === 'duration') {
- this.durationActiveDateSelected(dates[0]);
- } else if (this.dates.start && this.dates.end) {
- this.formUpdates$.next({ startDate: this.dates.start, dueDate: this.dates.end });
- }
- }
-
private handleSingleDateUpdate(activeField:DateFields, selectedDate:Date) {
if (activeField === 'duration') {
this.durationActiveDateSelected(selectedDate);
diff --git a/spec/features/work_packages/datepicker/datepicker_logic_spec.rb b/spec/features/work_packages/datepicker/datepicker_logic_spec.rb
index baad7ee048a..71b19a7d050 100644
--- a/spec/features/work_packages/datepicker/datepicker_logic_spec.rb
+++ b/spec/features/work_packages/datepicker/datepicker_logic_spec.rb
@@ -78,7 +78,7 @@ describe 'Datepicker modal logic test cases (WP #43539)',
datepicker.expect_visible
end
- context 'when only start_date set, updating duration (test case 1)' do
+ context 'when only start_date set, updating duration (scenario 1)' do
let(:current_attributes) do
{
start_date: Date.parse('2021-02-08'),
@@ -104,7 +104,7 @@ describe 'Datepicker modal logic test cases (WP #43539)',
end
end
- describe 'when no values set, updating duration (test case 2)' do
+ describe 'when no values set, updating duration (scenario 2)' do
let(:current_attributes) do
{
start_date: nil,
@@ -130,7 +130,7 @@ describe 'Datepicker modal logic test cases (WP #43539)',
end
end
- describe 'when only due date set, updating duration (test case 3)' do
+ describe 'when only due date set, updating duration (scenario 3)' do
let(:current_attributes) do
{
start_date: nil,
@@ -156,7 +156,7 @@ describe 'Datepicker modal logic test cases (WP #43539)',
end
end
- describe 'when all values set, increasing duration (test case 4)' do
+ describe 'when all values set, increasing duration (scenario 4)' do
let(:current_attributes) do
{
start_date: Date.parse('2021-02-08'),
@@ -182,7 +182,7 @@ describe 'Datepicker modal logic test cases (WP #43539)',
end
end
- describe 'when all values set, reducing duration (test case 5)' do
+ describe 'when all values set, reducing duration (scenario 5)' do
let(:current_attributes) do
{
start_date: Date.parse('2021-02-08'),
@@ -208,7 +208,7 @@ describe 'Datepicker modal logic test cases (WP #43539)',
end
end
- describe 'when all values set, removing duration (test case 6)' do
+ describe 'when all values set, removing duration (scenario 6)' do
let(:current_attributes) do
{
start_date: Date.parse('2021-02-09'),
@@ -232,7 +232,7 @@ describe 'Datepicker modal logic test cases (WP #43539)',
end
end
- describe 'when all values set, removing duration through icon (test case 6a)' do
+ describe 'when all values set, removing duration through icon (scenario 6a)' do
let(:current_attributes) do
{
start_date: Date.parse('2021-02-09'),
@@ -300,7 +300,7 @@ describe 'Datepicker modal logic test cases (WP #43539)',
end
end
- describe 'when all values set, changing start date in calendar (test case 7)' do
+ describe 'when all values set, changing start date in calendar (scenario 7)' do
let(:current_attributes) do
{
start_date: Date.parse('2021-02-08'),
@@ -350,7 +350,7 @@ describe 'Datepicker modal logic test cases (WP #43539)',
end
end
- describe 'when all values set, changing due date (test case 8)' do
+ describe 'when all values set, changing due date (scenario 8)' do
let(:current_attributes) do
{
start_date: Date.parse('2021-02-09'),
@@ -372,7 +372,7 @@ describe 'Datepicker modal logic test cases (WP #43539)',
end
end
- describe 'when only duration set, setting finish date (test case 9)' do
+ describe 'when only duration set, setting finish date (scenario 9)' do
let(:current_attributes) do
{
start_date: nil,
@@ -394,7 +394,7 @@ describe 'Datepicker modal logic test cases (WP #43539)',
end
end
- describe 'when only due date set, setting start date (test case 10)' do
+ describe 'when only due date set, setting start date (scenario 10)' do
let(:current_attributes) do
{
start_date: nil,