Skip to content

Commit 1f936a1

Browse files
author
Tyler Smalley
committed
Revert "[Security Solutions] Sets our default date time to be "today" instead of "Last 24 hours" to enable cachability and fixes one date math bug in the URL (#93548)"
This reverts commit 47bb977.
1 parent 27f2c75 commit 1f936a1

File tree

8 files changed

+20
-47
lines changed

8 files changed

+20
-47
lines changed

x-pack/plugins/security_solution/common/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export const DEFAULT_SEARCH_AFTER_PAGE_SIZE = 100;
2828
export const DEFAULT_ANOMALY_SCORE = 'securitySolution:defaultAnomalyScore';
2929
export const DEFAULT_MAX_TABLE_QUERY_SIZE = 10000;
3030
export const DEFAULT_SCALE_DATE_FORMAT = 'dateFormat:scaled';
31-
export const DEFAULT_FROM = 'now/d';
32-
export const DEFAULT_TO = 'now/d';
31+
export const DEFAULT_FROM = 'now-24h';
32+
export const DEFAULT_TO = 'now';
3333
export const DEFAULT_INTERVAL_PAUSE = true;
3434
export const DEFAULT_INTERVAL_TYPE = 'manual';
3535
export const DEFAULT_INTERVAL_VALUE = 300000; // ms

x-pack/plugins/security_solution/public/common/components/query_bar/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ describe('QueryBar ', () => {
8282

8383
expect(searchBarProps).toEqual({
8484
dataTestSubj: undefined,
85-
dateRangeFrom: 'now/d',
86-
dateRangeTo: 'now/d',
85+
dateRangeFrom: 'now-24h',
86+
dateRangeTo: 'now',
8787
filters: [],
8888
indexPatterns: [
8989
{

x-pack/plugins/security_solution/public/common/components/super_date_picker/index.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ describe('SIEM Super Date Picker', () => {
135135
expect(store.getState().inputs.global.timerange.kind).toBe('relative');
136136
});
137137

138-
test('Make Sure it is last "now-${x}h" where ${x} is in hours date', () => {
139-
expect(store.getState().inputs.global.timerange.fromStr).toMatch(/^now-[0-9]+h/);
138+
test('Make Sure it is last 24 hours date', () => {
139+
expect(store.getState().inputs.global.timerange.fromStr).toBe('now-24h');
140140
expect(store.getState().inputs.global.timerange.toStr).toBe('now');
141141
});
142142

@@ -206,7 +206,7 @@ describe('SIEM Super Date Picker', () => {
206206
expect(wrapper.find('div.euiQuickSelectPopover__section').at(1).text()).toBe('Today');
207207
});
208208

209-
test('Today and "Last ${x} hours" where ${x} is in hours are in Recently used date ranges', () => {
209+
test('Today and Last 24 hours are in Recently used date ranges', () => {
210210
wrapper
211211
.find('[data-test-subj="superDatePickerToggleQuickMenuButton"]')
212212
.first()
@@ -216,8 +216,8 @@ describe('SIEM Super Date Picker', () => {
216216
wrapper.find('button.euiQuickSelect__applyButton').first().simulate('click');
217217
wrapper.update();
218218

219-
expect(wrapper.find('div.euiQuickSelectPopover__section').at(1).text()).toMatch(
220-
/^Last\s[0-9]+\shoursToday/
219+
expect(wrapper.find('div.euiQuickSelectPopover__section').at(1).text()).toBe(
220+
'Last 24 hoursToday'
221221
);
222222
});
223223

x-pack/plugins/security_solution/public/common/store/inputs/helpers.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,10 @@ describe('Inputs', () => {
276276
],
277277
timerange: {
278278
from: '2020-07-07T08:20:18.966Z',
279-
fromStr: 'now/d',
279+
fromStr: 'now-24h',
280280
kind: 'relative',
281281
to: '2020-07-08T08:20:18.966Z',
282-
toStr: 'now/d',
282+
toStr: 'now',
283283
},
284284
query: { query: '', language: 'kuery' },
285285
filters: [],
@@ -293,10 +293,10 @@ describe('Inputs', () => {
293293
queries: [],
294294
timerange: {
295295
from: '2020-07-07T08:20:18.966Z',
296-
fromStr: 'now/d',
296+
fromStr: 'now-24h',
297297
kind: 'relative',
298298
to: '2020-07-08T08:20:18.966Z',
299-
toStr: 'now/d',
299+
toStr: 'now',
300300
},
301301
query: { query: '', language: 'kuery' },
302302
filters: [],

x-pack/plugins/security_solution/public/common/utils/default_date_settings.test.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -315,22 +315,6 @@ describe('getTimeRangeSettings', () => {
315315
expect(to).toBe(new Date(DEFAULT_TO_DATE).toISOString());
316316
});
317317

318-
test('should round up "to" when from and to are both "now/d"', () => {
319-
const mockTo = 'now/d';
320-
const mockFrom = 'now/d';
321-
mockTimeRange({ from: mockFrom, to: mockTo });
322-
const { to } = getTimeRangeSettings();
323-
expect(to).toContain('59:59.999Z');
324-
});
325-
326-
test('should round up "to" when from and to are different date maths', () => {
327-
const mockTo = 'now/d';
328-
const mockFrom = 'now/d+1';
329-
mockTimeRange({ from: mockFrom, to: mockTo });
330-
const { to } = getTimeRangeSettings();
331-
expect(to).toContain('59:59.999Z');
332-
});
333-
334318
test('should return the DEFAULT_TO_DATE when the from value is malformed', () => {
335319
const malformedTimeRange = { from: true };
336320
if (isMalformedTimeRange(malformedTimeRange)) {
@@ -522,10 +506,5 @@ describe('getIntervalSettings', () => {
522506
const value = parseDateWithDefault('trashed string', moment('1950-05-31T13:03:54.234Z'));
523507
expect(value.toISOString()).toBe(new Date('1950-05-31T13:03:54.234Z').toISOString());
524508
});
525-
526-
test('should round up a valid date string and end with 59:59.999Z', () => {
527-
const value = parseDateWithDefault('now/d', moment('1950-05-31T13:03:54.234Z'), true);
528-
expect(value.toISOString()).toContain('59:59.999Z');
529-
});
530509
});
531510
});

x-pack/plugins/security_solution/public/common/utils/default_date_settings.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export const getTimeRangeSettings = (uiSettings = true) => {
5151
const fromStr = (isString(timeRange?.from) && timeRange?.from) || DEFAULT_FROM;
5252
const toStr = (isString(timeRange?.to) && timeRange?.to) || DEFAULT_TO;
5353
const from = parseDateWithDefault(fromStr, DEFAULT_FROM_MOMENT).toISOString();
54-
const to = parseDateWithDefault(toStr, DEFAULT_TO_MOMENT, true).toISOString();
54+
const to = parseDateWithDefault(toStr, DEFAULT_TO_MOMENT).toISOString();
55+
5556
return { from, fromStr, to, toStr };
5657
};
5758

@@ -71,18 +72,11 @@ export const getIntervalSettings = (uiSettings = true): Policy => {
7172
return { kind, duration };
7273
};
7374

74-
/**
75-
* Parses a date and returns the default if the date string is not valid.
76-
* @param dateString The date string to parse
77-
* @param defaultDate The defaultDate if we cannot parse the dateMath
78-
* @returns The moment of the date time parsed
79-
*/
8075
export const parseDateWithDefault = (
8176
dateString: string,
82-
defaultDate: moment.Moment,
83-
roundUp: boolean = false
77+
defaultDate: moment.Moment
8478
): moment.Moment => {
85-
const date = dateMath.parse(dateString, { roundUp });
79+
const date = dateMath.parse(dateString);
8680
if (date != null && date.isValid()) {
8781
return date;
8882
} else {

x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('RecentCases', () => {
3434
wrapper.find(`[data-test-subj="no-cases-create-case"]`).first().simulate('click');
3535
expect(navigateToApp).toHaveBeenCalledWith('securitySolution:case', {
3636
path:
37-
"/create?sourcerer=(default:!('apm-*-transaction*','auditbeat-*','endgame-*','filebeat-*','logs-*','packetbeat-*','winlogbeat-*'))&timerange=(global:(linkTo:!(timeline),timerange:(from:'2020-07-07T08:20:18.966Z',fromStr:now%2Fd,kind:relative,to:'2020-07-08T08:20:18.966Z',toStr:now%2Fd)),timeline:(linkTo:!(global),timerange:(from:'2020-07-07T08:20:18.966Z',fromStr:now%2Fd,kind:relative,to:'2020-07-08T08:20:18.966Z',toStr:now%2Fd)))",
37+
"/create?sourcerer=(default:!('apm-*-transaction*','auditbeat-*','endgame-*','filebeat-*','logs-*','packetbeat-*','winlogbeat-*'))&timerange=(global:(linkTo:!(timeline),timerange:(from:'2020-07-07T08:20:18.966Z',fromStr:now-24h,kind:relative,to:'2020-07-08T08:20:18.966Z',toStr:now)),timeline:(linkTo:!(global),timerange:(from:'2020-07-07T08:20:18.966Z',fromStr:now-24h,kind:relative,to:'2020-07-08T08:20:18.966Z',toStr:now)))",
3838
});
3939
});
4040
});

x-pack/plugins/security_solution/public/timelines/components/timeline/query_bar/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ describe('Timeline QueryBar ', () => {
9696
);
9797
const queryBarProps = wrapper.find(QueryBar).props();
9898

99-
expect(queryBarProps.dateRangeFrom).toEqual('now/d');
100-
expect(queryBarProps.dateRangeTo).toEqual('now/d');
99+
expect(queryBarProps.dateRangeFrom).toEqual('now-24h');
100+
expect(queryBarProps.dateRangeTo).toEqual('now');
101101
expect(queryBarProps.filterQuery).toEqual({ query: 'here: query', language: 'kuery' });
102102
expect(queryBarProps.savedQuery).toEqual(undefined);
103103
expect(queryBarProps.filters).toHaveLength(1);

0 commit comments

Comments
 (0)