Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/admin/dashboard/static/js/Navigation.js

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + import { createElement, Component, useContext } from '@wordpress/element'
2 + import { sprintf, __ } from 'ct-i18n'
3 + import { Link, NavLink, useLocation } from 'react-router-dom'
4 + import ctEvents from 'ct-events'
5 +
6 + const Navigation = () => {
7 + const location = useLocation()
8 + const userNavigationLinks = []
9 + const endUserNavigationLinks = []
10 +
11 + ctEvents.trigger('ct:dashboard:navigation-links', userNavigationLinks)
12 + ctEvents.trigger(
13 + 'ct:dashboard:end-navigation-links',
14 + endUserNavigationLinks
15 + )
16 +
17 + // Filter out @reach/router specific props and handle active states
18 + const filterLinkProps = (props, path) => {
19 + const { getProps, ...validProps } = props
20 +
21 + if (getProps && typeof getProps === 'function') {
22 + const currentPath = location.pathname
23 +
24 + const normalizedPath = path.startsWith('/') ? path : `/${path}`
25 + const normalizedCurrent = currentPath.startsWith('/')
26 + ? currentPath
27 + : `/${currentPath}`
28 +
29 + const isPartiallyCurrent =
30 + normalizedCurrent.startsWith(normalizedPath) ||
31 + (normalizedPath !== '/' &&
32 + normalizedCurrent.includes(normalizedPath))
33 +
34 + const isCurrent =
35 + normalizedCurrent === normalizedPath ||
36 + (normalizedPath === '/' && normalizedCurrent === '/')
37 +
38 + const activeProps = getProps({ isPartiallyCurrent, isCurrent })
39 +
40 + return { ...validProps, ...activeProps }
41 + }
42 +
43 + return validProps
44 + }
45 +
46 + let hasPlugins = !ctDashboardLocalizations.plugin_data.hide_plugins_tab
47 +
48 + return (
49 + <ul className="dashboard-navigation">
50 + <li>
51 + <NavLink
52 + to="/"
53 + className={({ isActive }) => (isActive ? 'active' : '')}>
54 + {__('Home', 'blocksy')}
55 + </NavLink>
56 + </li>
57 +
58 + {userNavigationLinks.map(({ path, text, ...props }) => (
59 + <li key={path}>
60 + <NavLink
61 + to={path}
62 + {...filterLinkProps(props, path)}
63 + className={({ isActive }) =>
64 + isActive ? 'active' : ''
65 + }>
66 + {text}
67 + </NavLink>
68 + </li>
69 + ))}
70 +
71 + {!ctDashboardLocalizations.plugin_data.hide_plugins_tab && (
72 + <li>
73 + <NavLink
74 + to="/plugins"
75 + className={({ isActive }) =>
76 + isActive ? 'active' : ''
77 + }>
78 + {__('Useful Plugins', 'blocksy')}
79 + </NavLink>
80 + </li>
81 + )}
82 +
83 + {!ctDashboardLocalizations.plugin_data.hide_changelogs_tab && (
84 + <li>
85 + <NavLink
86 + to="/changelog"
87 + className={({ isActive }) =>
88 + isActive ? 'active' : ''
89 + }>
90 + {__('Changelog', 'blocksy')}
91 + </NavLink>
92 + </li>
93 + )}
94 +
95 + {endUserNavigationLinks.map(({ path, text, ...props }) => (
96 + <li key={path}>
97 + <NavLink
98 + to={path}
99 + {...filterLinkProps(props, path)}
100 + className={({ isActive }) =>
101 + isActive ? 'active' : ''
102 + }>
103 + {text}
104 + </NavLink>
105 + </li>
106 + ))}
107 + </ul>
108 + )
109 + }
110 +
111 + export default Navigation
112 +