2025-08-27 08:44:30 +02:00
|
|
|
import { createElement, Component, useContext } from '@wordpress/element'
|
|
|
|
|
import { sprintf, __ } from 'ct-i18n'
|
2025-12-12 13:14:39 +01:00
|
|
|
import { Link, NavLink, useLocation } from 'react-router-dom'
|
2025-08-27 08:44:30 +02:00
|
|
|
import ctEvents from 'ct-events'
|
|
|
|
|
|
|
|
|
|
const Navigation = () => {
|
2025-12-12 13:14:39 +01:00
|
|
|
const location = useLocation()
|
2025-08-27 08:44:30 +02:00
|
|
|
const userNavigationLinks = []
|
|
|
|
|
const endUserNavigationLinks = []
|
|
|
|
|
|
|
|
|
|
ctEvents.trigger('ct:dashboard:navigation-links', userNavigationLinks)
|
|
|
|
|
ctEvents.trigger(
|
|
|
|
|
'ct:dashboard:end-navigation-links',
|
|
|
|
|
endUserNavigationLinks
|
|
|
|
|
)
|
|
|
|
|
|
2025-12-12 13:14:39 +01:00
|
|
|
// Filter out @reach/router specific props and handle active states
|
|
|
|
|
const filterLinkProps = (props, path) => {
|
|
|
|
|
const { getProps, ...validProps } = props
|
|
|
|
|
|
|
|
|
|
if (getProps && typeof getProps === 'function') {
|
|
|
|
|
const currentPath = location.pathname
|
|
|
|
|
|
|
|
|
|
const normalizedPath = path.startsWith('/') ? path : `/${path}`
|
|
|
|
|
const normalizedCurrent = currentPath.startsWith('/')
|
|
|
|
|
? currentPath
|
|
|
|
|
: `/${currentPath}`
|
|
|
|
|
|
|
|
|
|
const isPartiallyCurrent =
|
|
|
|
|
normalizedCurrent.startsWith(normalizedPath) ||
|
|
|
|
|
(normalizedPath !== '/' &&
|
|
|
|
|
normalizedCurrent.includes(normalizedPath))
|
|
|
|
|
|
|
|
|
|
const isCurrent =
|
|
|
|
|
normalizedCurrent === normalizedPath ||
|
|
|
|
|
(normalizedPath === '/' && normalizedCurrent === '/')
|
|
|
|
|
|
|
|
|
|
const activeProps = getProps({ isPartiallyCurrent, isCurrent })
|
|
|
|
|
|
|
|
|
|
return { ...validProps, ...activeProps }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return validProps
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-27 08:44:30 +02:00
|
|
|
let hasPlugins = !ctDashboardLocalizations.plugin_data.hide_plugins_tab
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ul className="dashboard-navigation">
|
|
|
|
|
<li>
|
2025-12-12 13:14:39 +01:00
|
|
|
<NavLink
|
|
|
|
|
to="/"
|
|
|
|
|
className={({ isActive }) => (isActive ? 'active' : '')}>
|
|
|
|
|
{__('Home', 'blocksy')}
|
|
|
|
|
</NavLink>
|
2025-08-27 08:44:30 +02:00
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
{userNavigationLinks.map(({ path, text, ...props }) => (
|
|
|
|
|
<li key={path}>
|
2025-12-12 13:14:39 +01:00
|
|
|
<NavLink
|
|
|
|
|
to={path}
|
|
|
|
|
{...filterLinkProps(props, path)}
|
|
|
|
|
className={({ isActive }) =>
|
|
|
|
|
isActive ? 'active' : ''
|
|
|
|
|
}>
|
2025-08-27 08:44:30 +02:00
|
|
|
{text}
|
2025-12-12 13:14:39 +01:00
|
|
|
</NavLink>
|
2025-08-27 08:44:30 +02:00
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
{!ctDashboardLocalizations.plugin_data.hide_plugins_tab && (
|
|
|
|
|
<li>
|
2025-12-12 13:14:39 +01:00
|
|
|
<NavLink
|
|
|
|
|
to="/plugins"
|
|
|
|
|
className={({ isActive }) =>
|
|
|
|
|
isActive ? 'active' : ''
|
|
|
|
|
}>
|
|
|
|
|
{__('Useful Plugins', 'blocksy')}
|
|
|
|
|
</NavLink>
|
2025-08-27 08:44:30 +02:00
|
|
|
</li>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{!ctDashboardLocalizations.plugin_data.hide_changelogs_tab && (
|
|
|
|
|
<li>
|
2025-12-12 13:14:39 +01:00
|
|
|
<NavLink
|
|
|
|
|
to="/changelog"
|
|
|
|
|
className={({ isActive }) =>
|
|
|
|
|
isActive ? 'active' : ''
|
|
|
|
|
}>
|
|
|
|
|
{__('Changelog', 'blocksy')}
|
|
|
|
|
</NavLink>
|
2025-08-27 08:44:30 +02:00
|
|
|
</li>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{endUserNavigationLinks.map(({ path, text, ...props }) => (
|
|
|
|
|
<li key={path}>
|
2025-12-12 13:14:39 +01:00
|
|
|
<NavLink
|
|
|
|
|
to={path}
|
|
|
|
|
{...filterLinkProps(props, path)}
|
|
|
|
|
className={({ isActive }) =>
|
|
|
|
|
isActive ? 'active' : ''
|
|
|
|
|
}>
|
2025-08-27 08:44:30 +02:00
|
|
|
{text}
|
2025-12-12 13:14:39 +01:00
|
|
|
</NavLink>
|
2025-08-27 08:44:30 +02:00
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Navigation
|