Skip to content

Commit

Permalink
Move default refresh interval settings to time selection service (#3352)
Browse files Browse the repository at this point in the history
* Move default refresh interval settings to time selection service

* Integrate option to enable/disable live refresh interval
  • Loading branch information
Marcelfrueh authored Dec 1, 2024
1 parent 97aecd0 commit 21d5610
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export interface TimeSettings {
timeSelectionId?: string;
}

export interface ExtendedTimeSettings {
timeSettings: TimeSettings;
supportsLiveRefresh: boolean;
}

export class TimeSelectionConstants {
static CUSTOM = 'custom';
static LAST_15_MINUTES = 'last-15-minutes';
Expand Down Expand Up @@ -101,6 +106,7 @@ export interface QuickTimeSelection {
startTime: (now: Date) => Date;
endTime: (now: Date) => Date;
addDividerAfter?: boolean;
supportsLiveRefresh?: boolean;
}

export class DateRange {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
[matMenuTriggerFor]="menu"
aria-label="Refresh interval"
matTooltip="Refresh interval"
[disabled]="!liveRefreshEnabled"
>
<mat-icon>autorenew</mat-icon>
{{ liveSettings.label }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,52 +30,10 @@ export class DataExplorerRefreshIntervalSettingsComponent implements OnInit {
intervalSettingsChangedEmitter: EventEmitter<DashboardLiveSettings> =
new EventEmitter<DashboardLiveSettings>();

availableOptions: DashboardLiveSettings[] = [
{
label: 'Off',
refreshModeActive: false,
},
{
label: '1 sec',
refreshModeActive: true,
refreshIntervalInSeconds: 1,
},
{
label: '2 sec',
refreshModeActive: true,
refreshIntervalInSeconds: 2,
},
{
label: '5 sec',
refreshModeActive: true,
refreshIntervalInSeconds: 5,
},
{
label: '10 sec',
refreshModeActive: true,
refreshIntervalInSeconds: 10,
},
{
label: '30 sec',
refreshModeActive: true,
refreshIntervalInSeconds: 30,
},
{
label: '1 min',
refreshModeActive: true,
refreshIntervalInSeconds: 60,
},
{
label: '5 min',
refreshModeActive: true,
refreshIntervalInSeconds: 300,
},
{
label: '30 min',
refreshModeActive: true,
refreshIntervalInSeconds: 60 * 30,
},
];
@Input()
availableOptions: DashboardLiveSettings[];

liveRefreshEnabled: boolean;

ngOnInit() {
if (!this.liveSettings?.label) {
Expand All @@ -87,4 +45,11 @@ export class DataExplorerRefreshIntervalSettingsComponent implements OnInit {
this.liveSettings = option;
this.intervalSettingsChangedEmitter.emit(option);
}

handleEnableLiveRefresh(liveRefreshEnabled: boolean) {
if (this.liveRefreshEnabled === true && liveRefreshEnabled === false) {
this.intervalSettingsChangedEmitter.emit(this.availableOptions[0]);
}
this.liveRefreshEnabled = liveRefreshEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@
</div>
<div fxLayoutAlign="end center">
<sp-data-explorer-refresh-interval-settings-component
*ngIf="liveSettings"
#refreshIntervalSettings
*ngIf="liveSettings && showTimeSelector && showIntervalSettings"
[liveSettings]="liveSettings"
(intervalSettingsChangedEmitter)="
intervalSettingsChangedEmitter.emit($event)
"
[availableOptions]="availableOptions"
>
</sp-data-explorer-refresh-interval-settings-component>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import {
AfterViewInit,
Component,
EventEmitter,
Input,
Expand All @@ -33,23 +34,29 @@ import {
TimeSelectionConstants,
TimeSettings,
TimeString,
ExtendedTimeSettings,
} from '@streampipes/platform-services';
import { MatMenuTrigger } from '@angular/material/menu';
import { TimeSelectionService } from '../../services/time-selection.service';
import { TimeRangeSelectorMenuComponent } from './time-selector-menu/time-selector-menu.component';
import { TimeSelectorLabel } from './time-selector.model';
import { differenceInMilliseconds, isSameDay } from 'date-fns';
import { DataExplorerRefreshIntervalSettingsComponent } from './refresh-interval-settings/refresh-interval-settings.component';

@Component({
selector: 'sp-time-range-selector',
templateUrl: 'time-range-selector.component.html',
styleUrls: ['./time-range-selector.component.scss'],
encapsulation: ViewEncapsulation.None,
})
export class TimeRangeSelectorComponent implements OnInit, OnChanges {
export class TimeRangeSelectorComponent
implements OnInit, OnChanges, AfterViewInit
{
@ViewChild('menuTrigger') menu: MatMenuTrigger;
@ViewChild('timeSelectorMenu')
timeSelectorMenu: TimeRangeSelectorMenuComponent;
@ViewChild('refreshIntervalSettings')
refreshIntervalSettingsComponent: DataExplorerRefreshIntervalSettingsComponent;

@Output() dateRangeEmitter = new EventEmitter<TimeSettings>();

Expand All @@ -68,12 +75,18 @@ export class TimeRangeSelectorComponent implements OnInit, OnChanges {
@Input()
enableTimeChange = true;

@Input()
showIntervalSettings = true;

@Input()
maxDayRange = 0;

@Input()
quickSelections: QuickTimeSelection[];

@Input()
availableOptions: DashboardLiveSettings[];

@Input()
labels: TimeSelectorLabel;

Expand All @@ -93,6 +106,8 @@ export class TimeRangeSelectorComponent implements OnInit, OnChanges {
this.quickSelections ??=
this.timeSelectionService.defaultQuickTimeSelections;
this.labels ??= this.timeSelectionService.defaultLabels;
this.availableOptions ??=
this.timeSelectionService.defaultAvailableLiveSettingsOptions;
this.createDateString();
}

Expand All @@ -102,12 +117,44 @@ export class TimeRangeSelectorComponent implements OnInit, OnChanges {
}
}

ngAfterViewInit(): void {
this.changeLiveRefreshEnabled();
}

changeLiveRefreshEnabled(): void {
if (
this.timeSettings.timeSelectionId ===
TimeSelectionConstants.CUSTOM ||
this.hasLiveRefreshEnabled(this.timeSettings.timeSelectionId) ===
false
) {
this.refreshIntervalSettingsComponent?.handleEnableLiveRefresh(
false,
);
} else {
this.refreshIntervalSettingsComponent?.handleEnableLiveRefresh(
true,
);
}
}

hasLiveRefreshEnabled(timeSelectionId: string) {
const selectedQuickTimeSelection = this.quickSelections.find(
qs => timeSelectionId === qs.timeSelectionId,
);
return selectedQuickTimeSelection.supportsLiveRefresh;
}

applyPreviousInterval(): void {
this.timeSettings.timeSelectionId = TimeSelectionConstants.CUSTOM;
this.changeTimeByInterval((a, b) => a - b);
this.changeLiveRefreshEnabled();
}

applyNextInterval(): void {
this.timeSettings.timeSelectionId = TimeSelectionConstants.CUSTOM;
this.changeTimeByInterval((a, b) => a + b);
this.changeLiveRefreshEnabled();
}

compare(newDateRange: TimeSettings, oldDateRange: TimeSettings): boolean {
Expand Down Expand Up @@ -155,8 +202,11 @@ export class TimeRangeSelectorComponent implements OnInit, OnChanges {
this.reloadData();
}

applyCurrentDateRange(timeSettings: TimeSettings) {
this.timeSettings = timeSettings;
applyCurrentDateRange(extendedTimeSettings: ExtendedTimeSettings) {
this.timeSettings = extendedTimeSettings.timeSettings;
this.refreshIntervalSettingsComponent?.handleEnableLiveRefresh(
extendedTimeSettings.supportsLiveRefresh,
);
this.createDateString();
this.menu.closeMenu();
this.reloadData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@
#timeRangeSelection
[timeSettings]="timeSettings"
[labels]="labels"
(timeSettingsEmitter)="timeSettingsEmitter.emit($event)"
(timeSettingsEmitter)="
timeSettingsEmitter.emit({
supportsLiveRefresh: false,
timeSettings: $event
})
"
[enableTimeChange]="enableTimeChange"
[maxDayRange]="maxDayRange"
class="w-100"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import {
QuickTimeSelection,
TimeSettings,
ExtendedTimeSettings,
} from '@streampipes/platform-services';
import { TimeSelectionService } from '../../../services/time-selection.service';
import { CustomTimeRangeSelectionComponent } from './custom-time-range-selection/custom-time-range-selection.component';
Expand All @@ -51,8 +52,8 @@ export class TimeRangeSelectorMenuComponent implements OnInit {
maxDayRange: number;

@Output()
timeSettingsEmitter: EventEmitter<TimeSettings> =
new EventEmitter<TimeSettings>();
timeSettingsEmitter: EventEmitter<ExtendedTimeSettings> =
new EventEmitter<ExtendedTimeSettings>();

@Input()
quickSelections: QuickTimeSelection[];
Expand All @@ -72,7 +73,10 @@ export class TimeRangeSelectorMenuComponent implements OnInit {
this.timeSettings.endTime = selectedDateRange.endDate.getTime();
this.timeRangeSelection.initializeDateRange();
this.triggerDisplayUpdate();
this.timeSettingsEmitter.emit(this.timeSettings);
this.timeSettingsEmitter.emit({
supportsLiveRefresh: quickSelection.supportsLiveRefresh,
timeSettings: this.timeSettings,
});
}

triggerDisplayUpdate(): void {
Expand Down
Loading

0 comments on commit 21d5610

Please sign in to comment.