Skip to content

Commit 69927db

Browse files
authored
Add a tooltip with absolute datetime to relative time element (#1879)
* Add a tooltip with absolute datetime to relative time element * Improve tooltip centering
1 parent a3165df commit 69927db

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

app/components/TimeAgo.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* Copyright Oxide Computer Company
7+
*/
8+
import type { Placement } from '@floating-ui/react'
9+
import { format } from 'date-fns'
10+
11+
import { Tooltip } from '@oxide/ui'
12+
13+
import { timeAgoAbbr } from 'app/util/date'
14+
15+
export const TimeAgo = ({
16+
datetime,
17+
description,
18+
placement = 'top',
19+
}: {
20+
datetime: Date
21+
description?: string
22+
placement?: Placement
23+
}): JSX.Element => {
24+
const content = (
25+
<div className="flex flex-col">
26+
<span className="text-tertiary">{description}</span>
27+
<span>{format(datetime, 'MMM d, yyyy p')}</span>
28+
</div>
29+
)
30+
return (
31+
<span className="mt-0.5">
32+
<Tooltip content={content} placement={placement}>
33+
<span className="text-sans-sm text-tertiary">{timeAgoAbbr(datetime)}</span>
34+
</Tooltip>
35+
</span>
36+
)
37+
}

libs/table/cells/InstanceStatusCell.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@
88
import type { Instance } from '@oxide/api'
99

1010
import { InstanceStatusBadge } from 'app/components/StatusBadge'
11-
import { timeAgoAbbr } from 'app/util/date'
11+
import { TimeAgo } from 'app/components/TimeAgo'
1212

1313
import type { Cell } from './Cell'
14-
import { TwoLineCell } from './TwoLineCell'
1514

1615
export const InstanceStatusCell = ({
1716
value,
1817
}: Cell<Pick<Instance, 'runState' | 'timeRunStateUpdated'>>) => {
1918
return (
20-
<TwoLineCell
21-
detailsClass="text-sans-sm"
22-
value={[
23-
<InstanceStatusBadge key="run-state" status={value.runState} />,
24-
timeAgoAbbr(value.timeRunStateUpdated),
25-
]}
26-
></TwoLineCell>
19+
<div className="flex flex-col">
20+
<InstanceStatusBadge key="run-state" status={value.runState} />
21+
<TimeAgo description="Run state updated" datetime={value.timeRunStateUpdated} />
22+
</div>
2723
)
2824
}

0 commit comments

Comments
 (0)