-
Notifications
You must be signed in to change notification settings - Fork 11
fix(date-range-filter): update datepicker date-range on preset selection #1206
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
Conversation
WalkthroughThe component’s mutable Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yml Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (4)
🧰 Additional context used🧠 Learnings (16)📓 Common learnings📚 Learning: 2025-12-17T04:34:55.597ZApplied to files:
📚 Learning: 2025-12-11T10:09:01.564ZApplied to files:
📚 Learning: 2025-12-15T07:16:53.762ZApplied to files:
📚 Learning: 2025-12-08T11:25:51.584ZApplied to files:
📚 Learning: 2025-12-08T11:24:45.272ZApplied to files:
📚 Learning: 2025-12-05T08:00:38.407ZApplied to files:
📚 Learning: 2025-12-08T11:25:20.861ZApplied to files:
📚 Learning: 2025-12-15T07:16:32.082ZApplied to files:
📚 Learning: 2025-12-15T07:17:06.981ZApplied to files:
📚 Learning: 2025-12-04T05:50:17.637ZApplied to files:
📚 Learning: 2025-12-02T06:50:25.778ZApplied to files:
📚 Learning: 2025-12-01T14:12:11.111ZApplied to files:
📚 Learning: 2025-12-15T10:05:59.100ZApplied to files:
📚 Learning: 2025-12-01T04:01:27.365ZApplied to files:
📚 Learning: 2025-12-04T05:50:38.735ZApplied to files:
🧬 Code graph analysis (1)projects/element-ng/date-range-filter/si-date-range-filter.component.ts (2)
🔇 Additional comments (8)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
projects/element-ng/date-range-filter/si-date-range-filter.component.ts (1)
462-475: Critical: Signal not updated when datepicker emits date changes.When
updateFromDateRangeis called with a parameter (from the datepicker'sdateRangeChangeevent in the template), the method updates therangemodel but does NOT update thedateRangesignal. This creates inconsistency:
- User manually selects dates in the datepicker
- Datepicker emits
dateRangeChangeevent with newDateRangeupdateFromDateRange($event)updates the model (Line 468-472) but not the signal- Next render cycle: template passes stale signal value via
[dateRange]="dateRange()"- The
focusedDatecomputed (Lines 344-346) also reads the stale signal valueSince
rangeis a model signal, updating it doesn't triggerngOnChangesin the same component, so the signal won't be updated through that lifecycle hook.Apply this diff to ensure the signal is updated when a new range is provided:
protected updateFromDateRange(dateRange?: DateRange): void { const range = dateRange ?? this.dateRange(); const startDate = range.start ?? this.getDateNow(); const endDate = range.end ?? this.getDateNow(); + // Update signal to maintain consistency when called from datepicker event + this.dateRange.set({ start: startDate, end: endDate }); this.point1date = startDate; this.point2date = startDate; this.range.set({ point1: startDate, point2: endDate, range: undefined }); this.point2Mode = 'date'; this.point2offset = 0; }
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (3)
projects/element-ng/date-range-filter/si-date-range-filter.component.html(1 hunks)projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts(3 hunks)projects/element-ng/date-range-filter/si-date-range-filter.component.ts(4 hunks)
🧰 Additional context used
🧠 Learnings (15)
📓 Common learnings
Learnt from: chintankavathia
Repo: siemens/element PR: 1163
File: projects/element-ng/select/si-select.component.spec.ts:511-516
Timestamp: 2025-12-08T11:25:51.584Z
Learning: In the select component overflow tests (projects/element-ng/select/si-select.component.spec.ts), jasmine.clock() cannot be used to control the timing for overflow item detection. Real setTimeout waits must be used instead, likely due to ResizeObserver or debounced layout calculations that jasmine.clock() cannot control in zoneless mode.
Learnt from: chintankavathia
Repo: siemens/element PR: 1163
File: projects/element-ng/select/si-select.component.spec.ts:204-205
Timestamp: 2025-12-08T11:25:20.861Z
Learning: In zoneless Angular tests (using provideZonelessChangeDetection), calling fixture.changeDetectorRef.markForCheck() before fixture.detectChanges() is required even for components using the default change detection strategy (not OnPush). This differs from zone.js-based testing where markForCheck is primarily needed only for OnPush components.
Learnt from: chintankavathia
Repo: siemens/element PR: 1193
File: projects/element-ng/search-bar/si-search-bar.component.spec.ts:21-28
Timestamp: 2025-12-15T10:05:59.100Z
Learning: In zoneless Angular tests, jasmine.clock() can control RxJS debounceTime timing when both jasmine.clock().install() and jasmine.clock().mockDate() are used together. Without mockDate(), jasmine.clock() cannot control RxJS scheduler-based operators like debounceTime.
Learnt from: chintankavathia
Repo: siemens/element PR: 1163
File: projects/element-ng/select/options/si-select-lazy-options.directive.spec.ts:67-85
Timestamp: 2025-12-08T11:24:45.272Z
Learning: In select lazy options tests (projects/element-ng/select/options/si-select-lazy-options.directive.spec.ts), jasmine.clock() cannot control RxJS debounceTime in zoneless mode. Real setTimeout waits must be used instead for tests involving search debouncing.
Learnt from: chintankavathia
Repo: siemens/element PR: 1191
File: projects/dashboards-ng/src/components/gridstack-wrapper/si-gridstack-wrapper.component.spec.ts:92-105
Timestamp: 2025-12-15T07:16:53.762Z
Learning: In gridstack-wrapper component tests (projects/dashboards-ng/src/components/gridstack-wrapper/si-gridstack-wrapper.component.spec.ts), real setTimeout waits must be used instead of fixture.whenStable() to avoid injector destroyed errors during mount/unmount operations in zoneless mode. The GridStack timing-dependent operations require actual async delays.
Learnt from: chintankavathia
Repo: siemens/element PR: 1191
File: projects/dashboards-ng/src/components/gridstack-wrapper/si-gridstack-wrapper.component.spec.ts:69-80
Timestamp: 2025-12-15T07:16:32.082Z
Learning: In gridstack-wrapper component tests (projects/dashboards-ng/src/components/gridstack-wrapper/si-gridstack-wrapper.component.spec.ts), real setTimeout waits (e.g., `await new Promise(resolve => setTimeout(resolve, 0))`) must be used instead of `fixture.whenStable()` when testing grid item rendering and initialization. This is likely due to gridstack library's initialization timing or lifecycle behavior that fixture.whenStable() cannot properly wait for in zoneless mode.
Learnt from: chintankavathia
Repo: siemens/element PR: 1151
File: projects/element-ng/auto-collapsable-list/si-auto-collapsable-list.directive.spec.ts:83-104
Timestamp: 2025-12-11T10:09:01.564Z
Learning: In the auto-collapsable-list directive tests (projects/element-ng/auto-collapsable-list/si-auto-collapsable-list.directive.spec.ts), jasmine.clock() successfully controls the directive's setTimeout-based layout logic in zoneless mode. Mock timers work fine here, unlike in select component overflow tests where real setTimeout waits are required.
📚 Learning: 2025-12-11T10:09:01.564Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1151
File: projects/element-ng/auto-collapsable-list/si-auto-collapsable-list.directive.spec.ts:83-104
Timestamp: 2025-12-11T10:09:01.564Z
Learning: In the auto-collapsable-list directive tests (projects/element-ng/auto-collapsable-list/si-auto-collapsable-list.directive.spec.ts), jasmine.clock() successfully controls the directive's setTimeout-based layout logic in zoneless mode. Mock timers work fine here, unlike in select component overflow tests where real setTimeout waits are required.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-08T11:25:51.584Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1163
File: projects/element-ng/select/si-select.component.spec.ts:511-516
Timestamp: 2025-12-08T11:25:51.584Z
Learning: In the select component overflow tests (projects/element-ng/select/si-select.component.spec.ts), jasmine.clock() cannot be used to control the timing for overflow item detection. Real setTimeout waits must be used instead, likely due to ResizeObserver or debounced layout calculations that jasmine.clock() cannot control in zoneless mode.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-08T11:24:45.272Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1163
File: projects/element-ng/select/options/si-select-lazy-options.directive.spec.ts:67-85
Timestamp: 2025-12-08T11:24:45.272Z
Learning: In select lazy options tests (projects/element-ng/select/options/si-select-lazy-options.directive.spec.ts), jasmine.clock() cannot control RxJS debounceTime in zoneless mode. Real setTimeout waits must be used instead for tests involving search debouncing.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-15T07:16:53.762Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1191
File: projects/dashboards-ng/src/components/gridstack-wrapper/si-gridstack-wrapper.component.spec.ts:92-105
Timestamp: 2025-12-15T07:16:53.762Z
Learning: In gridstack-wrapper component tests (projects/dashboards-ng/src/components/gridstack-wrapper/si-gridstack-wrapper.component.spec.ts), real setTimeout waits must be used instead of fixture.whenStable() to avoid injector destroyed errors during mount/unmount operations in zoneless mode. The GridStack timing-dependent operations require actual async delays.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-15T07:16:32.082Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1191
File: projects/dashboards-ng/src/components/gridstack-wrapper/si-gridstack-wrapper.component.spec.ts:69-80
Timestamp: 2025-12-15T07:16:32.082Z
Learning: In gridstack-wrapper component tests (projects/dashboards-ng/src/components/gridstack-wrapper/si-gridstack-wrapper.component.spec.ts), real setTimeout waits (e.g., `await new Promise(resolve => setTimeout(resolve, 0))`) must be used instead of `fixture.whenStable()` when testing grid item rendering and initialization. This is likely due to gridstack library's initialization timing or lifecycle behavior that fixture.whenStable() cannot properly wait for in zoneless mode.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-05T08:00:38.407Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1151
File: projects/element-ng/typeahead/si-typeahead.directive.spec.ts:114-121
Timestamp: 2025-12-05T08:00:38.407Z
Learning: In the typeahead test suite (projects/element-ng/typeahead/si-typeahead.directive.spec.ts), jasmine.clock() must be installed in beforeAll and uninstalled in afterAll (not beforeEach/afterEach) because using per-test clock installation causes schedulerFunction-related issues in these specific tests.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-08T11:25:20.861Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1163
File: projects/element-ng/select/si-select.component.spec.ts:204-205
Timestamp: 2025-12-08T11:25:20.861Z
Learning: In zoneless Angular tests (using provideZonelessChangeDetection), calling fixture.changeDetectorRef.markForCheck() before fixture.detectChanges() is required even for components using the default change detection strategy (not OnPush). This differs from zone.js-based testing where markForCheck is primarily needed only for OnPush components.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-15T07:17:06.981Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1191
File: projects/dashboards-ng/src/components/widget-instance-editor-dialog/si-widget-instance-editor-dialog.component.spec.ts:37-49
Timestamp: 2025-12-15T07:17:06.981Z
Learning: In widget-instance-editor-dialog component tests (projects/dashboards-ng/src/components/widget-instance-editor-dialog/si-widget-instance-editor-dialog.component.spec.ts), real setTimeout waits (e.g., `await new Promise(resolve => setTimeout(resolve, 0))`) must be used instead of `fixture.whenStable()` when testing component initialization. This is likely due to the component's lifecycle behavior or modal initialization timing that fixture.whenStable() cannot properly wait for in zoneless mode.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-04T05:50:17.637Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1135
File: projects/element-ng/tree-view/si-tree-view.component.spec.ts:953-964
Timestamp: 2025-12-04T05:50:17.637Z
Learning: In the siemens/element repository, when making tree-view tests zoneless-ready, jasmine.clock() should be used to mimic setTimeouts even in zoneless mode, as the component implementation relies on setTimeout calls that need to be controlled in tests.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-02T06:50:25.778Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1104
File: projects/element-ng/datepicker/components/si-day-selection.component.spec.ts:19-19
Timestamp: 2025-12-02T06:50:25.778Z
Learning: The `runOnPushChangeDetection` helper is located at `projects/element-ng/test-helpers/change-detection.helper.ts` and is shared across the element-ng project, not scoped under individual feature modules like datepicker.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-15T10:05:59.100Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1193
File: projects/element-ng/search-bar/si-search-bar.component.spec.ts:21-28
Timestamp: 2025-12-15T10:05:59.100Z
Learning: In tests that rely on Jasmine's fake clock to control time-based RxJS operators (e.g., debounceTime), use jasmine.clock().install() together with jasmine.clock().mockDate() to enable precise timing control. Without mockDate, scheduler-based operators may not respond to the fake clock. Apply this guidance to spec files (e.g., any file named *.spec.ts or *.spec.js) that test time-sensitive behavior, ensuring you install and mockDate before advancing time in tests.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-01T04:01:27.365Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1099
File: projects/element-ng/accordion/si-accordion.component.spec.ts:39-43
Timestamp: 2025-12-01T04:01:27.365Z
Learning: With Angular 20 and esbuild, synchronous `TestBed.configureTestingModule(...).compileComponents()` calls work correctly even when components use external templates (templateUrl), because esbuild pre-compiles templates at build time. The async/await pattern is not required in this scenario.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-01T14:12:11.111Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1104
File: projects/element-ng/datepicker/components/si-day-selection.component.spec.ts:198-202
Timestamp: 2025-12-01T14:12:11.111Z
Learning: In zoneless Angular tests (using provideZonelessChangeDetection), prefer `await fixture.whenStable()` over `fixture.detectChanges()` after dispatching events or triggering async operations, as `whenStable()` waits for all asynchronous operations to complete and better mimics the production environment.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
📚 Learning: 2025-12-04T05:50:38.735Z
Learnt from: chintankavathia
Repo: siemens/element PR: 1135
File: projects/element-ng/tree-view/si-tree-view.component.spec.ts:1244-1245
Timestamp: 2025-12-04T05:50:38.735Z
Learning: In zoneless Angular tests with OnPush components, calling `await runOnPushChangeDetection(fixture)` followed by `await fixture.whenStable()` is NOT redundant. The `runOnPushChangeDetection` helper forces change detection to run for OnPush components, while `whenStable()` waits for all async operations to complete. Both are necessary and serve different purposes.
Applied to files:
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
🧬 Code graph analysis (1)
projects/element-ng/date-range-filter/si-date-range-filter.component.ts (2)
projects/element-ng/datepicker/si-datepicker.model.ts (1)
DateRange(170-173)projects/element-ng/datepicker/si-datepicker.component.ts (2)
startDate(202-204)endDate(206-208)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (5)
projects/element-ng/date-range-filter/si-date-range-filter.component.html (1)
67-68: LGTM! Signal-based binding pattern is correct.The template correctly adapts to the signal-based refactor by using one-way binding
[dateRange]="dateRange()"to pass the current signal value and an explicit event handler(dateRangeChange)="updateFromDateRange($event)"to receive updates from the datepicker.projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts (1)
279-279: LGTM! Explicit change detection calls ensure proper synchronization.The added
fixture.detectChanges()calls after setting the range and clicking the preset ensure that view updates are synchronized in zoneless mode, which aligns with established testing patterns.Based on learnings: In zoneless Angular tests, explicit change detection calls are often necessary to synchronize view updates with state changes.
Also applies to: 283-283
projects/element-ng/date-range-filter/si-date-range-filter.component.ts (3)
305-305: LGTM! Signal-based reactive state management.Converting the
dateRangeproperty to a signal enables reactive state management and aligns with modern Angular patterns. The readonly modifier correctly prevents reassignment of the signal itself.
344-346: LGTM! Computed properly derives from signal.The
focusedDatecomputed correctly reads from thedateRangesignal to derive the focused date for the datepicker.
417-420: LGTM! Signal update pattern is correct.The method correctly updates the signal using
.set()after resolving the date range filter.
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
Show resolved
Hide resolved
projects/element-ng/date-range-filter/si-date-range-filter.component.spec.ts
Outdated
Show resolved
Hide resolved
773bebf to
857a74a
Compare
|
Documentation. Coverage Reports: |
857a74a to
5a62a65
Compare
5a62a65 to
acdab56
Compare
Summary: Fixes datepicker not updating its visible date-range when a preset is selected by switching the component to use a signal-backed dateRange and updating the template to read/write via the signal.
Key changes:
Impact: Ensures the datepicker UI correctly reflects preset selections by syncing the reactive dateRange signal with the datepicker input.