PluginProbe
WP Ultimate Post Grid / 3.3.0
WP Ultimate Post Grid v3.3.0
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / assets / js / admin-manage / Menu.js

Menu.js in WP Ultimate Post Grid 3.3.0, at assets/js/admin-manage/Menu.js

83 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { Component, Fragment } from 'react';
2 import { NavLink } from 'react-router-dom';
3 import { withRouter } from 'react-router';
4
5 import '../../css/admin/manage/menu.scss';
6
7
8 class Menu extends Component {
9 render() {
10 const { datatables } = this.props;
11 let parents = {};
12
13 // Get all parents.
14 Object.keys(datatables).map((id) => {
15 const datatable = datatables[ id ];
16 const parent = datatable.parent;
17 const link = 'grids' === id ? '/' : `/${id}`;
18
19 // Output each parent once.
20 if ( parent && ! parents.hasOwnProperty( parent ) ) {
21 parents[ parent ] = {
22 name: parent,
23 active: false,
24 link,
25 };
26 }
27
28 // Check if this path is active.
29 if ( link === this.props.location.pathname ) {
30 parents[ parent ].active = true;
31 }
32 });
33
34 return (
35 <Fragment>
36 <div className="wpupg-admin-manage-parent-menu">
37 {
38 Object.keys(parents).map((key, index) => {
39 const parent = parents[ key ];
40
41 return (
42 <NavLink to={ parent.link } className={ `wpupg-admin-manage-menu-item${ parent.active ? ' wpupg-admin-manage-menu-item-active' : ''}` } key={ index } exact>{ parent.name }</NavLink>
43 )
44 })
45 }
46 </div>
47 <div className="wpupg-admin-manage-child-menu">
48 {
49 Object.keys(datatables).map((id, index) => {
50 const datatable = datatables[ id ];
51 const parent = datatable.parent;
52 const link = 'grids' === id ? '/' : `/${id}`;
53
54 // Check requirement.
55 let hasAccess = true;
56 if ( datatable.hasOwnProperty( 'required' ) && ( ! wpupg_admin.addons.hasOwnProperty( datatable.required ) || true !== wpupg_admin.addons[ datatable.required ] ) ) {
57 hasAccess = false;
58 }
59
60 // Only show children for active parent.
61 if ( parents.hasOwnProperty( parent ) && parents[ parent ].active ) {
62 let label = datatable.hasOwnProperty('title') ? datatable.title : datatable.label.plural;
63
64 if ( ! hasAccess ) {
65 label += '*';
66 }
67
68 return (
69 <NavLink to={ link } className={ `wpupg-admin-manage-menu-item${ hasAccess ? '' : ' wpupg-admin-manage-menu-item-requirement'}` } activeClassName="wpupg-admin-manage-menu-item-active" key={ index } exact>{ label }</NavLink>
70 )
71 } else {
72 return null;
73 }
74 })
75 }
76 </div>
77 </Fragment>
78 );
79 }
80 }
81
82 export default withRouter(Menu)
83