-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Detections] - Auto refresh all rules/monitoring t…
…ables (#82062) (#82890) ## Summary This PR addresses #63865 . Please read the issue for more detail, but essentially, stale data on the tables and use of relative date format leads to confusion as to whether the table was auto refreshing or not.
- Loading branch information
Showing
26 changed files
with
1,226 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...curity_solution/public/common/components/header_section/__snapshots__/index.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
x-pack/plugins/security_solution/public/common/components/last_updated/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { I18nProvider } from '@kbn/i18n/react'; | ||
|
||
import { LastUpdatedAt } from './'; | ||
|
||
describe('LastUpdatedAt', () => { | ||
beforeEach(() => { | ||
Date.now = jest.fn().mockReturnValue(1603995369774); | ||
}); | ||
|
||
test('it renders correct relative time', () => { | ||
const wrapper = mount( | ||
<I18nProvider> | ||
<LastUpdatedAt updatedAt={1603995240115} /> | ||
</I18nProvider> | ||
); | ||
|
||
expect(wrapper.text()).toEqual(' Updated 2 minutes ago'); | ||
}); | ||
|
||
test('it only renders icon if "compact" is true', () => { | ||
const wrapper = mount( | ||
<I18nProvider> | ||
<LastUpdatedAt compact updatedAt={1603995240115} /> | ||
</I18nProvider> | ||
); | ||
|
||
expect(wrapper.text()).toEqual(''); | ||
expect(wrapper.find('[data-test-subj="last-updated-at-clock-icon"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('it renders updating text if "showUpdating" is true', () => { | ||
const wrapper = mount( | ||
<I18nProvider> | ||
<LastUpdatedAt updatedAt={1603995240115} showUpdating /> | ||
</I18nProvider> | ||
); | ||
|
||
expect(wrapper.text()).toEqual(' Updating...'); | ||
}); | ||
}); |
83 changes: 83 additions & 0 deletions
83
x-pack/plugins/security_solution/public/common/components/last_updated/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { EuiIcon, EuiText, EuiToolTip } from '@elastic/eui'; | ||
import { FormattedRelative } from '@kbn/i18n/react'; | ||
import React, { useEffect, useMemo, useState } from 'react'; | ||
|
||
import * as i18n from './translations'; | ||
|
||
interface LastUpdatedAtProps { | ||
compact?: boolean; | ||
updatedAt: number; | ||
showUpdating?: boolean; | ||
} | ||
|
||
export const Updated = React.memo<{ date: number; prefix: string; updatedAt: number }>( | ||
({ date, prefix, updatedAt }) => ( | ||
<> | ||
{prefix} | ||
{ | ||
<FormattedRelative | ||
data-test-subj="last-updated-at-date" | ||
key={`formatedRelative-${date}`} | ||
value={new Date(updatedAt)} | ||
/> | ||
} | ||
</> | ||
) | ||
); | ||
|
||
Updated.displayName = 'Updated'; | ||
|
||
const prefix = ` ${i18n.UPDATED} `; | ||
|
||
export const LastUpdatedAt = React.memo<LastUpdatedAtProps>( | ||
({ compact = false, updatedAt, showUpdating = false }) => { | ||
const [date, setDate] = useState(Date.now()); | ||
|
||
function tick() { | ||
setDate(Date.now()); | ||
} | ||
|
||
useEffect(() => { | ||
const timerID = setInterval(() => tick(), 10000); | ||
return () => { | ||
clearInterval(timerID); | ||
}; | ||
}, []); | ||
|
||
const updateText = useMemo(() => { | ||
if (showUpdating) { | ||
return <span> {i18n.UPDATING}</span>; | ||
} | ||
|
||
if (!compact) { | ||
return <Updated date={date} prefix={prefix} updatedAt={updatedAt} />; | ||
} | ||
|
||
return null; | ||
}, [compact, date, showUpdating, updatedAt]); | ||
|
||
return ( | ||
<EuiToolTip | ||
data-test-subj="timeline-stream-tool-tip" | ||
content={ | ||
<> | ||
<Updated date={date} prefix={prefix} updatedAt={updatedAt} /> | ||
</> | ||
} | ||
> | ||
<EuiText size="s"> | ||
<EuiIcon data-test-subj="last-updated-at-clock-icon" type="clock" /> | ||
{updateText} | ||
</EuiText> | ||
</EuiToolTip> | ||
); | ||
} | ||
); | ||
|
||
LastUpdatedAt.displayName = 'LastUpdatedAt'; |
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/security_solution/public/common/components/last_updated/translations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const UPDATING = i18n.translate('xpack.securitySolution.lastUpdated.updating', { | ||
defaultMessage: 'Updating...', | ||
}); | ||
|
||
export const UPDATED = i18n.translate('xpack.securitySolution.lastUpdated.updated', { | ||
defaultMessage: 'Updated', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.