-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
112 lines (98 loc) · 2.91 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* WordPress dependencies
*/
import { useEntityRecord, store as coreStore } from '@wordpress/core-data';
import {
__experimentalUseNavigator as useNavigator,
Spinner,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { decodeEntities } from '@wordpress/html-entities';
/**
* Internal dependencies
*/
import { SidebarNavigationScreenWrapper } from '../sidebar-navigation-screen-navigation-menus';
import ScreenNavigationMoreMenu from './more-menu';
import SingleNavigationMenu from './single-navigation-menu';
import useNavigationMenuHandlers from './use-navigation-menu-handlers';
import buildNavigationLabel from '../sidebar-navigation-screen-navigation-menus/build-navigation-label';
export const postType = `wp_navigation`;
export default function SidebarNavigationScreenNavigationMenu() {
const {
params: { postId },
} = useNavigator();
const { record: navigationMenu, isResolving } = useEntityRecord(
'postType',
postType,
postId
);
const { isSaving, isDeleting } = useSelect(
( select ) => {
const { isSavingEntityRecord, isDeletingEntityRecord } =
select( coreStore );
return {
isSaving: isSavingEntityRecord( 'postType', postType, postId ),
isDeleting: isDeletingEntityRecord(
'postType',
postType,
postId
),
};
},
[ postId ]
);
const isLoading = isResolving || isSaving || isDeleting;
const menuTitle = navigationMenu?.title?.rendered || navigationMenu?.slug;
const { handleSave, handleDelete, handleDuplicate } =
useNavigationMenuHandlers();
const _handleDelete = () => handleDelete( navigationMenu );
const _handleSave = ( edits ) => handleSave( navigationMenu, edits );
const _handleDuplicate = () => handleDuplicate( navigationMenu );
if ( isLoading ) {
return (
<SidebarNavigationScreenWrapper
description={ __(
'Navigation menus are a curated collection of blocks that allow visitors to get around your site.'
) }
>
<Spinner className="edit-site-sidebar-navigation-screen-navigation-menus__loading" />
</SidebarNavigationScreenWrapper>
);
}
if ( ! isLoading && ! navigationMenu ) {
return (
<SidebarNavigationScreenWrapper
description={ __( 'Navigation Menu missing.' ) }
/>
);
}
if ( ! navigationMenu?.content?.raw ) {
return (
<SidebarNavigationScreenWrapper
actions={
<ScreenNavigationMoreMenu
menuTitle={ decodeEntities( menuTitle ) }
onDelete={ _handleDelete }
onSave={ _handleSave }
onDuplicate={ _handleDuplicate }
/>
}
title={ buildNavigationLabel(
navigationMenu?.title,
navigationMenu?.id,
navigationMenu?.status
) }
description={ __( 'This Navigation Menu is empty.' ) }
/>
);
}
return (
<SingleNavigationMenu
navigationMenu={ navigationMenu }
handleDelete={ _handleDelete }
handleSave={ _handleSave }
handleDuplicate={ _handleDuplicate }
/>
);
}