-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
77 lines (75 loc) · 2.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { humanTimeDiff } from '@wordpress/date';
import { createInterpolateElement } from '@wordpress/element';
import { addQueryArgs } from '@wordpress/url';
import {
Icon,
__experimentalItemGroup as ItemGroup,
} from '@wordpress/components';
import { backup } from '@wordpress/icons';
/**
* Internal dependencies
*/
import {
SidebarNavigationScreenDetailsPanelRow,
SidebarNavigationScreenDetailsPanelLabel,
SidebarNavigationScreenDetailsPanelValue,
} from '../sidebar-navigation-screen-details-panel';
import SidebarNavigationItem from '../sidebar-navigation-item';
export default function SidebarNavigationScreenDetailsFooter( {
record,
...otherProps
} ) {
/*
* There might be other items in the future,
* but for now it's just modified date.
* Later we might render a list of items and isolate
* the following logic.
*/
const hrefProps = {};
const lastRevisionId =
record?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null;
const revisionsCount =
record?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;
// Enable the revisions link if there is a last revision and there are more than one revisions.
if ( lastRevisionId && revisionsCount > 1 ) {
hrefProps.href = addQueryArgs( 'revision.php', {
revision: record?._links[ 'predecessor-version' ][ 0 ].id,
} );
hrefProps.as = 'a';
}
return (
<ItemGroup className="edit-site-sidebar-navigation-screen-details-footer">
<SidebarNavigationItem
aria-label={ __( 'Revisions' ) }
{ ...hrefProps }
{ ...otherProps }
>
<SidebarNavigationScreenDetailsPanelRow justify="space-between">
<SidebarNavigationScreenDetailsPanelLabel>
{ __( 'Last modified' ) }
</SidebarNavigationScreenDetailsPanelLabel>
<SidebarNavigationScreenDetailsPanelValue>
{ createInterpolateElement(
sprintf(
/* translators: %s: is the relative time when the post was last modified. */
__( '<time>%s</time>' ),
humanTimeDiff( record.modified )
),
{
time: <time dateTime={ record.modified } />,
}
) }
</SidebarNavigationScreenDetailsPanelValue>
<Icon
className="edit-site-sidebar-navigation-screen-details-footer__icon"
icon={ backup }
/>
</SidebarNavigationScreenDetailsPanelRow>
</SidebarNavigationItem>
</ItemGroup>
);
}