@dereekb/dbx-form 9.25.5 → 9.25.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ import { Injectable, SkipSelf, Directive, Injector, Optional, Component, Inject,
7
7
  import { FieldType } from '@ngx-formly/material';
8
8
  import { switchMap, first, tap, map, distinctUntilChanged, shareReplay, of, combineLatestWith, BehaviorSubject, filter, combineLatest, EMPTY, startWith, throttleTime } from 'rxjs';
9
9
  import { filterMaybe, distinctUntilHasDifferentValues, SubscriptionObject, asObservableFromGetter, asObservable } from '@dereekb/rxjs';
10
- import { DateCellScheduleDayCode, expandDateCellScheduleDayCodesToDayOfWeekSet, dateCellTimingStartsAtForStartOfDay, dateCellTimingRelativeIndexFactory, dateCellDayOfWeekFactory, findMaxDate, findMinDate, isSameDateRange, isSameDateDay, isSameDate, dateCellTimingDateFactory, expandDateCellScheduleRange, formatToISO8601DayString, changeDateCellScheduleDateRangeToTimezone, isSameDateCellScheduleDateRange, dateCellTimingRelativeIndexArrayFactory, isInfiniteDateRange, copyDateCellScheduleDateFilterConfig, SYSTEM_DATE_TIMEZONE_UTC_NORMAL_INSTANCE, dateTimezoneUtcNormal, dateCellScheduleDateFilter, fullDateCellScheduleRange, dateCellTimingTimezoneNormalInstance, expandDateCellScheduleDayCodes, fullWeekDateCellScheduleDayCodes, dateCellScheduleDayCodesAreSetsEquivalent, simplifyDateCellScheduleDayCodes, isDateInDateRangeFunction, isDateWithinDateCellRangeFunction, dateCellScheduleEncodedWeek, dateCellTimingStartDateFactory, enabledDaysFromDateCellScheduleDayCodes, dateCellScheduleDayCodesFromEnabledDays, formatToMonthDayString, dateRange, DateRangeType } from '@dereekb/date';
10
+ import { DateCellScheduleDayCode, expandDateCellScheduleDayCodesToDayOfWeekSet, dateCellTimingStartsAtForStartOfDay, dateCellTimingRelativeIndexFactory, dateCellDayOfWeekFactory, dateTimezoneUtcNormal, findMaxDate, findMinDate, isSameDateRange, isSameDateDay, isSameDate, dateCellTimingDateFactory, expandDateCellScheduleRange, formatToISO8601DayString, changeDateCellScheduleDateRangeToTimezone, isSameDateCellScheduleDateRange, dateCellTimingRelativeIndexArrayFactory, isInfiniteDateRange, copyDateCellScheduleDateFilterConfig, SYSTEM_DATE_TIMEZONE_UTC_NORMAL_INSTANCE, dateCellScheduleDateFilter, fullDateCellScheduleRange, dateCellTimingTimezoneNormalInstance, expandDateCellScheduleDayCodes, fullWeekDateCellScheduleDayCodes, dateCellScheduleDayCodesAreSetsEquivalent, simplifyDateCellScheduleDayCodes, isDateInDateRangeFunction, isDateWithinDateCellRangeFunction, dateCellScheduleEncodedWeek, dateCellTimingStartDateFactory, enabledDaysFromDateCellScheduleDayCodes, dateCellScheduleDayCodesFromEnabledDays, formatToMonthDayString, dateRange, DateRangeType } from '@dereekb/date';
11
11
  import { isInAllowedDaysOfWeekSet, mapValuesToSet, unique, mergeArrays, iterableToArray, range, toggleInSet, removeFromSet, addToSet, isIndexNumberInIndexRangeFunction, minAndMaxNumber, getDaysOfWeekNames, reduceBooleansWithAnd, mergeObjects, KeyValueTypleValueFilter } from '@dereekb/util';
12
12
  import { ComponentStore } from '@ngrx/component-store';
13
13
  import { startOfDay, endOfDay, isBefore, endOfWeek } from 'date-fns';
@@ -116,11 +116,28 @@ function initialCalendarScheduleSelectionState() {
116
116
  cellContentFactory: defaultCalendarScheduleSelectionCellContentFactory
117
117
  };
118
118
  }
119
- function calendarScheduleMinDate(x) {
120
- return findMaxDate([x.filter?.start, x.minMaxDateRange?.start]);
121
- }
122
- function calendarScheduleMaxDate(x) {
123
- return findMinDate([x.filter?.end, x.minMaxDateRange?.end]);
119
+ /**
120
+ * This is used in cases where the dates in the min/max date range need to be shifted to the filter's timezone.
121
+ *
122
+ * This is because the index factory is always in system timezone, but when selecting all/none with a filter we need to use the filter's timezone.
123
+ *
124
+ * @param x
125
+ * @returns
126
+ */
127
+ function calendarScheduleMinAndMaxDateRangeRelativeToFilter(x) {
128
+ let input = x;
129
+ if (x.filter?.timezone && x.minMaxDateRange != null) {
130
+ const filterNormal = dateTimezoneUtcNormal(x.filter.timezone);
131
+ const transformFn = filterNormal.transformFunction('systemDateToTargetDate');
132
+ input = {
133
+ filter: x.filter,
134
+ minMaxDateRange: {
135
+ start: x.minMaxDateRange.start ? transformFn(x.minMaxDateRange.start) : undefined,
136
+ end: x.minMaxDateRange.end ? transformFn(x.minMaxDateRange.end) : undefined
137
+ }
138
+ };
139
+ }
140
+ return calendarScheduleMinAndMaxDateRange(input);
124
141
  }
125
142
  function calendarScheduleMinAndMaxDateRange(x) {
126
143
  return {
@@ -128,6 +145,12 @@ function calendarScheduleMinAndMaxDateRange(x) {
128
145
  end: calendarScheduleMaxDate(x) || undefined
129
146
  };
130
147
  }
148
+ function calendarScheduleMinDate(x) {
149
+ return findMaxDate([x.filter?.start, x.minMaxDateRange?.start]);
150
+ }
151
+ function calendarScheduleMaxDate(x) {
152
+ return findMinDate([x.filter?.end, x.minMaxDateRange?.end]);
153
+ }
131
154
  function calendarScheduleStartBeingUsedFromFilter(x) {
132
155
  return x.computeSelectionResultRelativeToFilter && x.filter?.start != null; // may be using either
133
156
  }
@@ -547,7 +570,7 @@ function finalizeUpdateStateWithChangedScheduleDays(previousState, nextState) {
547
570
  }
548
571
  function updateStateWithChangedDates(state, change) {
549
572
  const { allowedDaysOfWeek, indexFactory, indexDayOfWeek, inputStart: currentInputStart, inputEnd: currentInputEnd, minMaxDateRange, filter } = state;
550
- const { start: minDate, end: maxDate } = calendarScheduleMinAndMaxDateRange(state);
573
+ const { start: minDate, end: maxDate } = calendarScheduleMinAndMaxDateRangeRelativeToFilter(state);
551
574
  let inputStart = currentInputStart;
552
575
  let inputEnd = currentInputEnd;
553
576
  /**
@@ -632,8 +655,8 @@ function noSelectionCalendarScheduleSelectionState(state) {
632
655
  return finalizeNewCalendarScheduleSelectionState({ ...state, toggledIndexes: new Set(), inputStart: null, inputEnd: null });
633
656
  }
634
657
  function updateStateWithChangedRange(state, change) {
635
- const { inputStart: currentInputStart, inputEnd: currentInputEnd, indexFactory, minMaxDateRange } = state;
636
- const { start: minDate, end: maxDate } = minMaxDateRange ?? {};
658
+ const { inputStart: currentInputStart, inputEnd: currentInputEnd, indexFactory } = state;
659
+ const { start: minDate, end: maxDate } = calendarScheduleMinAndMaxDateRange(state);
637
660
  const inputStart = startOfDay(change.inputStart);
638
661
  const inputEnd = startOfDay(change.inputEnd); // midnight of the last day
639
662
  const isValidRange = minDate != null || maxDate != null ? isDateInDateRangeFunction({ start: minDate ?? undefined, end: maxDate ?? undefined }) : () => true;