Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to select last 24h compliance report #4358

Merged
merged 3 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ describe('ReportingOverviewComponent', () => {
startDate: moment(endDate).subtract(10, 'days'),
endDate: endDate,
interval: 0,
filters: [ {type: { name: 'node'}, value: { id: '1231'}},
{type: { name: 'platform'}, value: { text: 'ubuntu'}} ]
filters: [
{type: { name: 'node'}, value: { id: '1231'}},
{type: { name: 'platform'}, value: { text: 'ubuntu'}}
],
last24h: false
};

describe('when selected tab is "Node Status"', () => {
Expand Down Expand Up @@ -418,7 +421,8 @@ describe('ReportingOverviewComponent', () => {
startDate: moment(endDate).subtract(10, 'days'),
endDate: endDate,
interval: 0,
filters: [ {type: { name: 'node'}, value: { id: '1231'}}]
filters: [ {type: { name: 'node'}, value: { id: '1231'}}],
last24h: false
};
const data = [
{
Expand Down Expand Up @@ -449,7 +453,8 @@ describe('ReportingOverviewComponent', () => {
startDate: moment(endDate).subtract(10, 'days'),
endDate: endDate,
interval: 0,
filters: [ {type: { name: 'node'}, value: { id: '1231'}}]
filters: [ {type: { name: 'node'}, value: { id: '1231'}}],
last24h: false
};
const data = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ describe('ReportingProfileComponent', () => {
startDate: moment(endDate).subtract(10, 'days'),
endDate: endDate,
interval: 0,
filters: [ ]
filters: [ ],
last24h: false
};
component.getNodes(reportQuery, {profileId: '123', controlId: '321'});

Expand All @@ -92,7 +93,8 @@ describe('ReportingProfileComponent', () => {
filters: [
{type: { name: 'profile_id' }, value: { text: '123'} },
{type: { name: 'control_id' }, value: { text: '321'} }
]
],
last24h: false
};

expect(statsService.getNodes).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,24 @@
<chef-icon>filter_list</chef-icon>
<span>{{ filters.length }}</span>
</chef-button>
<chef-button class="calendar-btn" secondary (click)="toggleCalendar()">
<chef-icon>date_range</chef-icon>
<span>{{ date | datetime: CHEF_SHORT_DATE }}</span>
<chef-button class="calendar-menu-btn" secondary (click)="toggleCalendarMenu()">
<span *ngIf="last24h">Last 24 hours</span>
<ng-container *ngIf="!last24h">
<chef-icon>date_range</chef-icon>
<span>{{ date | datetime: CHEF_SHORT_DATE }}</span>
</ng-container>
</chef-button>
<chef-dropdown class="calendar-menu-dropdown" [attr.visible]="calendarMenuVisible">
<chef-click-outside omit="calendar-menu-btn" (clickOutside)="hideCalendarMenu()">
<chef-button class="select-last-btn" secondary (click)="handleSelectLast24()">
Last 24 hours
</chef-button>
<chef-button class="calendar-btn" secondary (click)="showCalendar()">
scottopherson marked this conversation as resolved.
Show resolved Hide resolved
<chef-icon>date_range</chef-icon>
<span>{{ date | datetime: CHEF_SHORT_DATE }}</span>
</chef-button>
</chef-click-outside>
</chef-dropdown>
<chef-dropdown class="calendar-dropdown" [attr.visible]="calendarVisible">
<chef-click-outside omit="calendar-btn" (clickOutside)="hideCalendar()">
<chef-calendar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@
padding: 0.5em;
z-index: 1;
}

.calendar-menu-dropdown {
top: calc(100% - 0.5em);
right: 1em;
padding: 0;

chef-button {
margin: 0;
width: 100%;
border: none;
border-radius: 0;
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { DateTime } from 'app/helpers/datetime/datetime';
})
export class ReportingSearchbarComponent implements OnInit {
@Input() date = moment().utc();
@Input() last24h = true;
@Input() filters: FilterC[] = [];
@Input() filterTypes = [];
@Input() filterValues = [];
Expand All @@ -38,6 +39,7 @@ export class ReportingSearchbarComponent implements OnInit {
@Output() filterRemoved = new EventEmitter();
@Output() filterAdded = new EventEmitter();
@Output() dateChanged = new EventEmitter();
@Output() last24Selected = new EventEmitter();

@ViewChild('keyInput', { static: true }) keyInput: ElementRef;
@ViewChild('valInput', { static: true }) valInput: ElementRef;
Expand All @@ -48,6 +50,7 @@ export class ReportingSearchbarComponent implements OnInit {
public CHEF_SHORT_DATE = DateTime.CHEF_SHORT_DATE;

filterTypesCategories = [];
calendarMenuVisible = false;
calendarVisible = false;
keyInputVisible = true;
valInputVisible = false;
Expand Down Expand Up @@ -116,6 +119,18 @@ export class ReportingSearchbarComponent implements OnInit {
this.filtersVisible = true;
}

toggleCalendarMenu() {
this.calendarMenuVisible = !this.calendarMenuVisible;
}

hideCalendarMenu() {
this.calendarMenuVisible = false;
}

showCalendarMenu() {
this.calendarMenuVisible = true;
}

toggleCalendar() {
this.calendarVisible = !this.calendarVisible;
}
Expand All @@ -128,6 +143,10 @@ export class ReportingSearchbarComponent implements OnInit {
this.calendarVisible = true;
}

handleSelectLast24() {
this.last24Selected.emit();
}

handleFocus(event: Event): void {
event.stopPropagation();
this.suggestionsVisibleStream.next(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
<app-reporting-searchbar
[date]="endDate$ | async"
[filters]="filters$ | async"
[last24h]="(reportQuery.state | async).last24h"
[filterTypes]="availableFilterTypes"
[filterValues]="availableFilterValues"
(suggestValues)="onSuggestValues($event)"
(filtersCleared)="onFiltersClear($event)"
(filterRemoved)="onFilterRemoved($event)"
(filterAdded)="onFilterAdded($event)"
(dateChanged)="onEndDateChanged($event)">
(dateChanged)="onEndDateChanged($event)"
(last24Selected)="onLast24Selected()">
</app-reporting-searchbar>
<div class="download-report">
<chef-button class="dropdown-toggle" secondary (click)="toggleDownloadDropdown()">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ describe('ReportingComponent', () => {
startDate: start,
endDate: originalDate,
interval: 0,
filters: []
filters: [],
last24h: false
} as ReportQuery);
fixture.detectChanges();

Expand Down Expand Up @@ -150,21 +151,6 @@ describe('ReportingComponent', () => {
});

describe('onEndDateChanged', () => {
it('no date set when today is selected with date object', () => {
spyOn(router, 'navigate');
const endDate = new Date();
const event = {detail: endDate};
component.onEndDateChanged(event);
expect(router.navigate).toHaveBeenCalledWith([], {queryParams: { }});
});

it('no date set when today is selected with string', () => {
spyOn(router, 'navigate');
const event = {detail: moment().utc().format('YYYY-MM-DD')};
component.onEndDateChanged(event);
expect(router.navigate).toHaveBeenCalledWith([], {queryParams: { }});
});

it('specific string date', () => {
spyOn(router, 'navigate');
const event = {detail: '2017-10-23'};
Expand All @@ -180,6 +166,14 @@ describe('ReportingComponent', () => {
});
});

describe('onLast24Selected', () => {
it('no date set when last 24 hours is selected', () => {
spyOn(router, 'navigate');
component.onLast24Selected();
expect(router.navigate).toHaveBeenCalledWith([], {queryParams: {}});
});
});

describe('getSuggestions()', () => {
describe('when the item has a version', () => {
it('sets the title to text, version values to display to the user', () => {
Expand All @@ -189,7 +183,8 @@ describe('ReportingComponent', () => {
endDate: moment(0).utc().startOf('day'),
startDate: moment(0).utc().startOf('day'),
interval: 0,
filters: []
filters: [],
last24h: false
};
spyOn(suggestionsService, 'getSuggestions').and.returnValue(observableOf([
{text: 'dev sec baseline, v2.0', version: '2.0'}
Expand All @@ -210,7 +205,8 @@ describe('ReportingComponent', () => {
endDate: moment(0).utc().startOf('day'),
startDate: moment(0).utc().startOf('day'),
interval: 0,
filters: []
filters: [],
last24h: false
};
spyOn(suggestionsService, 'getSuggestions').and.returnValue(observableOf([
{text: 'teal-spohn'}
Expand All @@ -233,7 +229,8 @@ describe('ReportingComponent', () => {
filters: [
{type: {name: 'Node'}, value: { id: '1231' }},
{type: {name: 'Platform'}, value: { id: 'ubuntu'}}
]
],
last24h: false
};
const reportingSummaryData: ReportingSummary = {
'stats': {
Expand Down Expand Up @@ -292,7 +289,8 @@ describe('ReportingComponent', () => {
filters: [
{type: {name: 'chef_tags'}, value: { text: '123' }},
{type: {name: 'chef_tags'}, value: { text: '456'}}
]
],
last24h: true
};
component.applyParamFilters([
{type: 'chef_tags', text: '123', type_key: ''},
Expand All @@ -309,7 +307,8 @@ describe('ReportingComponent', () => {
interval: 0,
filters: [
{type: {name: 'chef_tags'}, value: { text: '123' }}
]
],
last24h: true
};

component.applyParamFilters([{type: 'chef_tags', text: '123', type_key: ''}]);
Expand All @@ -331,7 +330,8 @@ describe('ReportingComponent', () => {
interval: interval,
filters: [
{type: {name: 'chef_tags'}, value: { text: '123' }}
]
],
last24h: false
};

component.applyParamFilters([
Expand All @@ -354,7 +354,8 @@ describe('ReportingComponent', () => {
interval: interval,
filters: [
{type: {name: 'chef_tags'}, value: { text: '123' }}
]
],
last24h: true
};

component.applyParamFilters([
Expand All @@ -377,7 +378,8 @@ describe('ReportingComponent', () => {
interval: interval,
filters: [
{type: {name: 'chef_tags'}, value: { text: '123' }}
]
],
last24h: true
};

component.applyParamFilters([
Expand All @@ -400,7 +402,8 @@ describe('ReportingComponent', () => {
interval: interval,
filters: [
{type: {name: 'chef_tags'}, value: { text: '123' }}
]
],
last24h: true
};

component.applyParamFilters([
Expand All @@ -423,7 +426,8 @@ describe('ReportingComponent', () => {
interval: interval,
filters: [
{type: {name: 'chef_tags'}, value: { text: '123' }}
]
],
last24h: true
};

component.applyParamFilters([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,15 @@ export class ReportingComponent implements OnInit, OnDestroy {
const queryParams = {...this.route.snapshot.queryParams};
const endDate = moment.utc(event.detail);

if (moment().utc().format('YYYY-MM-DD') === moment(endDate).format('YYYY-MM-DD')) {
delete queryParams['end_time'];
scottopherson marked this conversation as resolved.
Show resolved Hide resolved
} else {
queryParams['end_time'] = moment(endDate).format('YYYY-MM-DD');
}
queryParams['end_time'] = moment(endDate).format('YYYY-MM-DD');

this.router.navigate([], {queryParams});
}

onLast24Selected() {
const queryParams = {...this.route.snapshot.queryParams};

delete queryParams['end_time'];

this.router.navigate([], {queryParams});
}
Expand Down Expand Up @@ -468,6 +472,7 @@ export class ReportingComponent implements OnInit, OnDestroy {
reportQuery.endDate = this.getEndDate(urlFilters);
reportQuery.startDate = this.reportQuery.findTimeIntervalStartDate(
reportQuery.interval, reportQuery.endDate);
reportQuery.last24h = this.isLast24h(urlFilters);

this.reportQuery.setState(reportQuery);
}
Expand Down Expand Up @@ -517,4 +522,8 @@ export class ReportingComponent implements OnInit, OnDestroy {
convertMomentToDate(m: moment.Moment): Date {
return new Date(Date.UTC(m.year(), m.month(), m.date()));
}

isLast24h(urlFilters: Chicklet[]): boolean {
scottopherson marked this conversation as resolved.
Show resolved Hide resolved
return !urlFilters.some((filter: Chicklet) => filter.type === 'end_time');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ describe('ReportDataService', () => {
startDate: moment(endDate).subtract(10, 'days'),
endDate: endDate,
interval: 0,
filters: [ ]
filters: [ ],
last24h: false
};
const data = {stats: {}};
spyOn(statsService, 'getSummary').and.returnValue(observableOf(data));
Expand All @@ -87,7 +88,8 @@ describe('ReportDataService', () => {
startDate: moment(endDate).subtract(10, 'days'),
endDate: endDate,
interval: 0,
filters: [ ]
filters: [ ],
last24h: false
};
const params = {};
const data = [];
Expand All @@ -109,7 +111,8 @@ describe('ReportDataService', () => {
startDate: moment(endDate).subtract(10, 'days'),
endDate: endDate,
interval: 0,
filters: [ ]
filters: [ ],
last24h: false
};
const params = {};
const data = [];
Expand All @@ -131,7 +134,8 @@ describe('ReportDataService', () => {
startDate: moment(endDate).subtract(10, 'days'),
endDate: endDate,
interval: 0,
filters: [ ]
filters: [ ],
last24h: false
};
const data = [];
spyOn(statsService, 'getControls').and.returnValue(observableOf(data));
Expand Down
Loading