mirror of
https://git.vectorsigma.ru/public/AdGuardHome.git
synced 2026-07-31 09:19:33 +00:00
Merge in DNS/adguard-home from ADG-8368-typescript-node-18 to master Squashed commit of the following: commit daa288ae0d76178af24595cc807055902e6f09ab Merge:4c89cf7201085d59a6Author: Igor Lobanov <bniwredyc@gmail.com> Date: Mon Jun 10 17:22:20 2024 +0200 merge commit4c89cf7209Author: Ildar Kamalov <ik@adguard.com> Date: Thu Jun 6 13:27:18 2024 +0300 remove install from initial state commitb943f2011fAuthor: Igor Lobanov <bniwredyc@gmail.com> Date: Wed Jun 5 23:10:55 2024 +0200 frontend production build fix commitcd1be2d66dAuthor: Igor Lobanov <bniwredyc@gmail.com> Date: Wed Jun 5 20:23:14 2024 +0200 production build quickfix commit7b8ac01fc2Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Jun 5 19:57:31 2024 +0300 all: upd node docker commit02afed66d5Author: Igor Lobanov <bniwredyc@gmail.com> Date: Wed Jun 5 18:23:12 2024 +0200 changelog fixes commit9c0f736f0cMerge:62c4fbf1ee04775c4fAuthor: Igor Lobanov <bniwredyc@gmail.com> Date: Wed Jun 5 18:18:29 2024 +0200 merge commit62c4fbf1e3Author: Igor Lobanov <bniwredyc@gmail.com> Date: Wed Jun 5 16:22:22 2024 +0200 empty line in changelog commit76b1e44a93Author: Igor Lobanov <bniwredyc@gmail.com> Date: Wed Jun 5 16:20:37 2024 +0200 changelog commitf783e90040Author: Igor Lobanov <bniwredyc@gmail.com> Date: Wed Jun 5 16:19:13 2024 +0200 filters.js -> filters.ts commit3d4ce6554cAuthor: Igor Lobanov <bniwredyc@gmail.com> Date: Wed Jun 5 16:18:03 2024 +0200 generated file removed commite35ba58f2aAuthor: Igor Lobanov <bniwredyc@gmail.com> Date: Wed Jun 5 15:45:21 2024 +0200 rollback unwanted changes commit1f30d4216dAuthor: Igor Lobanov <bniwredyc@gmail.com> Date: Wed Jun 5 15:27:36 2024 +0200 review fix commit6cd4e44f07Author: Igor Lobanov <bniwredyc@gmail.com> Date: Wed Jun 5 11:55:39 2024 +0200 missing generated file restoresd commit2ab738b303Author: Igor Lobanov <bniwredyc@gmail.com> Date: Wed Jun 5 11:40:32 2024 +0200 Frontend rewritten in TypeScript, added Node 18 support
188 lines
5.0 KiB
TypeScript
188 lines
5.0 KiB
TypeScript
import React, { Component } from 'react';
|
|
|
|
import { NavLink } from 'react-router-dom';
|
|
|
|
import enhanceWithClickOutside from 'react-click-outside';
|
|
import classnames from 'classnames';
|
|
import { Trans, withTranslation } from 'react-i18next';
|
|
import { SETTINGS_URLS, FILTERS_URLS, MENU_URLS } from '../../helpers/constants';
|
|
|
|
import Dropdown from '../ui/Dropdown';
|
|
|
|
const MENU_ITEMS = [
|
|
{
|
|
route: MENU_URLS.root,
|
|
exact: true,
|
|
icon: 'dashboard',
|
|
text: 'dashboard',
|
|
order: 0,
|
|
},
|
|
|
|
// Settings dropdown should have visual order 1
|
|
|
|
// Filters dropdown should have visual order 2
|
|
|
|
{
|
|
route: MENU_URLS.logs,
|
|
icon: 'log',
|
|
text: 'query_log',
|
|
order: 3,
|
|
},
|
|
{
|
|
route: MENU_URLS.guide,
|
|
icon: 'setup',
|
|
text: 'setup_guide',
|
|
order: 4,
|
|
},
|
|
];
|
|
|
|
const SETTINGS_ITEMS = [
|
|
{
|
|
route: SETTINGS_URLS.settings,
|
|
text: 'general_settings',
|
|
},
|
|
{
|
|
route: SETTINGS_URLS.dns,
|
|
text: 'dns_settings',
|
|
},
|
|
{
|
|
route: SETTINGS_URLS.encryption,
|
|
text: 'encryption_settings',
|
|
},
|
|
{
|
|
route: SETTINGS_URLS.clients,
|
|
text: 'client_settings',
|
|
},
|
|
{
|
|
route: SETTINGS_URLS.dhcp,
|
|
text: 'dhcp_settings',
|
|
},
|
|
];
|
|
|
|
const FILTERS_ITEMS = [
|
|
{
|
|
route: FILTERS_URLS.dns_blocklists,
|
|
text: 'dns_blocklists',
|
|
},
|
|
{
|
|
route: FILTERS_URLS.dns_allowlists,
|
|
text: 'dns_allowlists',
|
|
},
|
|
{
|
|
route: FILTERS_URLS.dns_rewrites,
|
|
text: 'dns_rewrites',
|
|
},
|
|
{
|
|
route: FILTERS_URLS.blocked_services,
|
|
text: 'blocked_services',
|
|
},
|
|
{
|
|
route: FILTERS_URLS.custom_rules,
|
|
text: 'custom_filtering_rules',
|
|
},
|
|
];
|
|
|
|
interface MenuProps {
|
|
isMenuOpen: boolean;
|
|
closeMenu: (...args: unknown[]) => unknown;
|
|
pathname: string;
|
|
t?: (...args: unknown[]) => string;
|
|
}
|
|
|
|
class Menu extends Component<MenuProps> {
|
|
handleClickOutside = () => {
|
|
this.props.closeMenu();
|
|
};
|
|
|
|
closeMenu = () => {
|
|
this.props.closeMenu();
|
|
};
|
|
|
|
getActiveClassForDropdown = (URLS: any) => {
|
|
const isActivePage = Object.values(URLS)
|
|
|
|
.some((item: any) => item === this.props.pathname);
|
|
|
|
return isActivePage ? 'active' : '';
|
|
};
|
|
|
|
getNavLink = ({ route, exact, text, order, className, icon }: any) => (
|
|
<NavLink
|
|
to={route}
|
|
key={route}
|
|
exact={exact || false}
|
|
className={`order-${order} ${className}`}
|
|
onClick={this.closeMenu}>
|
|
{icon && (
|
|
<svg className="nav-icon">
|
|
<use xlinkHref={`#${icon}`} />
|
|
</svg>
|
|
)}
|
|
|
|
<Trans>{text}</Trans>
|
|
</NavLink>
|
|
);
|
|
|
|
getDropdown = ({ label, order, URLS, icon, ITEMS }: any) => (
|
|
<Dropdown
|
|
label={this.props.t(label)}
|
|
baseClassName="dropdown"
|
|
controlClassName={`nav-link ${this.getActiveClassForDropdown(URLS)}`}
|
|
icon={icon}>
|
|
{ITEMS.map((item: any) =>
|
|
this.getNavLink({
|
|
...item,
|
|
order,
|
|
className: 'dropdown-item',
|
|
}),
|
|
)}
|
|
</Dropdown>
|
|
);
|
|
|
|
render() {
|
|
const menuClass = classnames({
|
|
'header__column mobile-menu': true,
|
|
|
|
'mobile-menu--active': this.props.isMenuOpen,
|
|
});
|
|
return (
|
|
<>
|
|
<div className={menuClass}>
|
|
<ul className="nav nav-tabs border-0 flex-column flex-lg-row flex-nowrap">
|
|
{MENU_ITEMS.map((item) => (
|
|
<li className={`nav-item order-${item.order}`} key={item.text} onClick={this.closeMenu}>
|
|
{this.getNavLink({
|
|
...item,
|
|
className: 'nav-link',
|
|
})}
|
|
</li>
|
|
))}
|
|
|
|
<li className="nav-item order-1">
|
|
{this.getDropdown({
|
|
order: 1,
|
|
label: 'settings',
|
|
icon: 'settings',
|
|
URLS: SETTINGS_URLS,
|
|
ITEMS: SETTINGS_ITEMS,
|
|
})}
|
|
</li>
|
|
|
|
<li className="nav-item order-2">
|
|
{this.getDropdown({
|
|
order: 2,
|
|
label: 'filters',
|
|
icon: 'filters',
|
|
URLS: FILTERS_URLS,
|
|
ITEMS: FILTERS_ITEMS,
|
|
})}
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default withTranslation()(enhanceWithClickOutside(Menu));
|