Skip to content

Commit

Permalink
feat(date-range): synchronize date-range-dropdown with selected date …
Browse files Browse the repository at this point in the history
…range

even without the date input, this is used in the calendar display
  • Loading branch information
tkohr committed Nov 13, 2024
1 parent 2355bb8 commit 2693db5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<gn-ui-date-range-dropdown
*ngIf="fieldType === 'dateRange'; else multiselect"
[title]="title"
[startDate]="(selectedDateRange$ | async)?.start"
[endDate]="(selectedDateRange$ | async)?.end"
(startDateChange)="onStartDateChange($event)"
(endDateChange)="onEndDateChange($event)"
></gn-ui-date-range-dropdown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export class FilterDropdownComponent implements OnInit {
catchError(() => of([]))
) as Observable<FieldValue[]>

selectedDateRange$ = this.selected$.pipe(
map((selectedDateRange) => selectedDateRange as DateRange)
) as Observable<DateRange>

onSelectedValues(values: unknown[]) {
this.fieldsService
.buildFiltersFromFieldValues({ [this.fieldName]: values as FieldValue[] })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
</gn-ui-button>
<!--date range input is just present for output events and hidden from the DOM-->
<mat-date-range-input [rangePicker]="picker">
<input matStartDate (dateInput)="startDateChange.emit($event.value)" />
<input matEndDate (dateInput)="endDateChange.emit($event.value)" />
<input
matStartDate
[value]="startDate"
(dateInput)="startDateChange.emit($event.value)"
/>
<input
matEndDate
[value]="endDate"
(dateInput)="endDateChange.emit($event.value)"
/>
</mat-date-range-input>
<mat-date-range-picker #picker></mat-date-range-picker>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { OverlayContainer } from '@angular/cdk/overlay'
})
export class DateRangeDropdownComponent implements AfterViewChecked {
@Input() title: string
@Input() startDate: Date
@Input() endDate: Date
@Output() startDateChange = new EventEmitter<Date>()
@Output() endDateChange = new EventEmitter<Date>()

Expand Down

0 comments on commit 2693db5

Please sign in to comment.