Skip to content

Commit

Permalink
Revert "[Security Solutions] Sets our default date time to be "today"…
Browse files Browse the repository at this point in the history
… instead of "Last 24 hours" to enable cachability and fixes one date math bug in the URL (#93548) (#93692)"

This reverts commit 34afd4d.
  • Loading branch information
Tyler Smalley committed Mar 5, 2021
1 parent b5a0a8d commit a2a8b9a
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 47 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export const DEFAULT_SEARCH_AFTER_PAGE_SIZE = 100;
export const DEFAULT_ANOMALY_SCORE = 'securitySolution:defaultAnomalyScore';
export const DEFAULT_MAX_TABLE_QUERY_SIZE = 10000;
export const DEFAULT_SCALE_DATE_FORMAT = 'dateFormat:scaled';
export const DEFAULT_FROM = 'now/d';
export const DEFAULT_TO = 'now/d';
export const DEFAULT_FROM = 'now-24h';
export const DEFAULT_TO = 'now';
export const DEFAULT_INTERVAL_PAUSE = true;
export const DEFAULT_INTERVAL_TYPE = 'manual';
export const DEFAULT_INTERVAL_VALUE = 300000; // ms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ describe('QueryBar ', () => {

expect(searchBarProps).toEqual({
dataTestSubj: undefined,
dateRangeFrom: 'now/d',
dateRangeTo: 'now/d',
dateRangeFrom: 'now-24h',
dateRangeTo: 'now',
filters: [],
indexPatterns: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ describe('SIEM Super Date Picker', () => {
expect(store.getState().inputs.global.timerange.kind).toBe('relative');
});

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ describe('Inputs', () => {
],
timerange: {
from: '2020-07-07T08:20:18.966Z',
fromStr: 'now/d',
fromStr: 'now-24h',
kind: 'relative',
to: '2020-07-08T08:20:18.966Z',
toStr: 'now/d',
toStr: 'now',
},
query: { query: '', language: 'kuery' },
filters: [],
Expand All @@ -293,10 +293,10 @@ describe('Inputs', () => {
queries: [],
timerange: {
from: '2020-07-07T08:20:18.966Z',
fromStr: 'now/d',
fromStr: 'now-24h',
kind: 'relative',
to: '2020-07-08T08:20:18.966Z',
toStr: 'now/d',
toStr: 'now',
},
query: { query: '', language: 'kuery' },
filters: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,6 @@ describe('getTimeRangeSettings', () => {
expect(to).toBe(new Date(DEFAULT_TO_DATE).toISOString());
});

test('should round up "to" when from and to are both "now/d"', () => {
const mockTo = 'now/d';
const mockFrom = 'now/d';
mockTimeRange({ from: mockFrom, to: mockTo });
const { to } = getTimeRangeSettings();
expect(to).toContain('59:59.999Z');
});

test('should round up "to" when from and to are different date maths', () => {
const mockTo = 'now/d';
const mockFrom = 'now/d+1';
mockTimeRange({ from: mockFrom, to: mockTo });
const { to } = getTimeRangeSettings();
expect(to).toContain('59:59.999Z');
});

test('should return the DEFAULT_TO_DATE when the from value is malformed', () => {
const malformedTimeRange = { from: true };
if (isMalformedTimeRange(malformedTimeRange)) {
Expand Down Expand Up @@ -522,10 +506,5 @@ describe('getIntervalSettings', () => {
const value = parseDateWithDefault('trashed string', moment('1950-05-31T13:03:54.234Z'));
expect(value.toISOString()).toBe(new Date('1950-05-31T13:03:54.234Z').toISOString());
});

test('should round up a valid date string and end with 59:59.999Z', () => {
const value = parseDateWithDefault('now/d', moment('1950-05-31T13:03:54.234Z'), true);
expect(value.toISOString()).toContain('59:59.999Z');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export const getTimeRangeSettings = (uiSettings = true) => {
const fromStr = (isString(timeRange?.from) && timeRange?.from) || DEFAULT_FROM;
const toStr = (isString(timeRange?.to) && timeRange?.to) || DEFAULT_TO;
const from = parseDateWithDefault(fromStr, DEFAULT_FROM_MOMENT).toISOString();
const to = parseDateWithDefault(toStr, DEFAULT_TO_MOMENT, true).toISOString();
const to = parseDateWithDefault(toStr, DEFAULT_TO_MOMENT).toISOString();

return { from, fromStr, to, toStr };
};

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

/**
* Parses a date and returns the default if the date string is not valid.
* @param dateString The date string to parse
* @param defaultDate The defaultDate if we cannot parse the dateMath
* @returns The moment of the date time parsed
*/
export const parseDateWithDefault = (
dateString: string,
defaultDate: moment.Moment,
roundUp: boolean = false
defaultDate: moment.Moment
): moment.Moment => {
const date = dateMath.parse(dateString, { roundUp });
const date = dateMath.parse(dateString);
if (date != null && date.isValid()) {
return date;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('RecentCases', () => {
wrapper.find(`[data-test-subj="no-cases-create-case"]`).first().simulate('click');
expect(navigateToApp).toHaveBeenCalledWith('securitySolution:case', {
path:
"/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)))",
"/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)))",
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ describe('Timeline QueryBar ', () => {
);
const queryBarProps = wrapper.find(QueryBar).props();

expect(queryBarProps.dateRangeFrom).toEqual('now/d');
expect(queryBarProps.dateRangeTo).toEqual('now/d');
expect(queryBarProps.dateRangeFrom).toEqual('now-24h');
expect(queryBarProps.dateRangeTo).toEqual('now');
expect(queryBarProps.filterQuery).toEqual({ query: 'here: query', language: 'kuery' });
expect(queryBarProps.savedQuery).toEqual(undefined);
expect(queryBarProps.filters).toHaveLength(1);
Expand Down

0 comments on commit a2a8b9a

Please sign in to comment.