-
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.
[RAM] Add the "updated at" feature in new alerts table (#136949)
* first commit * fix and add test * Update x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/toolbar/components/last_updated_at/translations.ts Co-authored-by: Xavier Mouligneau <[email protected]> * Update x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/toolbar/components/last_updated_at/translations.ts Co-authored-by: Xavier Mouligneau <[email protected]> Co-authored-by: Xavier Mouligneau <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
1377ef2
commit 8b21e25
Showing
9 changed files
with
181 additions
and
25 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
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
79 changes: 79 additions & 0 deletions
79
..._ui/public/application/sections/alerts_table/toolbar/components/last_updated_at/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,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EuiText, EuiToolTip } from '@elastic/eui'; | ||
import { FormattedRelative } from '@kbn/i18n-react'; | ||
import React, { useEffect, useMemo, useState } from 'react'; | ||
|
||
import * as i18n from './translations'; | ||
|
||
export interface LastUpdatedAtProps { | ||
compact?: boolean; | ||
updatedAt: number; | ||
showUpdating?: boolean; | ||
} | ||
|
||
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 content={<Updated date={date} prefix={prefix} updatedAt={updatedAt} />}> | ||
<EuiText color="subdued" size="xs" data-test-subj="toolbar-updated-at"> | ||
{updateText} | ||
</EuiText> | ||
</EuiToolTip> | ||
); | ||
} | ||
); | ||
|
||
LastUpdatedAt.displayName = 'LastUpdatedAt'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export { LastUpdatedAt as default }; |
16 changes: 16 additions & 0 deletions
16
...blic/application/sections/alerts_table/toolbar/components/last_updated_at/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,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const UPDATING = i18n.translate('xpack.triggersActionsUI.alertsTable.lastUpdated.updating', { | ||
defaultMessage: 'Updating...', | ||
}); | ||
|
||
export const UPDATED = i18n.translate('xpack.triggersActionsUI.alertsTable.lastUpdated.updated', { | ||
defaultMessage: 'Updated', | ||
}); |
Oops, something went wrong.