Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve menu groups #475

Draft
wants to merge 2 commits into
base: f/v3-candidate
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/lime-plugin-firmware/src/upgradeAvailable.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const UpgradeAvailableBanner = () => {
// @ts-ignore
<Match>
{({ path }) =>
!["firmware", "releaseInfo", "meshwideupgrade"].includes(
!["firmware", "releaseInfo", "meshwide/upgrade"].includes(
path.replace("/", "")
) && (
<div
Expand Down
5 changes: 4 additions & 1 deletion plugins/lime-plugin-mesh-wide-config/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { MeshConfigMenu } from "plugins/lime-plugin-mesh-wide-config/src/meshConfigMenu";

import MeshConfigPage from "./src/meshConfigPage";

export default {
name: "meshwide/config",
page: MeshConfigPage,
menu: MeshConfigMenu,
isCommunityProtected: true,
additionalRoutes: [["/meshwide/config", MeshConfigPage]],
menuGroup: "meshwide",
} as LimePlugin;
12 changes: 12 additions & 0 deletions plugins/lime-plugin-mesh-wide-config/src/meshConfigMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Trans } from "@lingui/macro";

import { AdjustVertical } from "components/icons/teenny/adjust";

export const MeshConfigMenu = () => (
<span>
<AdjustVertical />
<a href={"#/meshwide/config"}>
<Trans>Mesh Wide Config</Trans>
</a>
</span>
);
3 changes: 2 additions & 1 deletion plugins/lime-plugin-mesh-wide-upgrade/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { MeshUpgradeMenu } from "plugins/lime-plugin-mesh-wide-upgrade/src/meshU
import MeshUpgradePage from "plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradePage";

export default {
name: "MeshWideUpgrade",
name: "meshwide/upgrade",
page: MeshUpgradePage,
menu: MeshUpgradeMenu,
isCommunityProtected: true,
menuGroup: "meshwide",
} as LimePlugin;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GlobeAmericasIcon } from "components/icons/teenny/globe";
export const MeshUpgradeMenu = () => (
<span>
<GlobeAmericasIcon />
<a href={"#/meshwideupgrade"}>
<a href={"#/meshwide/upgrade"}>
<Trans>Mesh Wide Upgrade</Trans>
</a>
</span>
Expand Down
1 change: 1 addition & 0 deletions plugins/lime-plugin-mesh-wide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export default {
name: "MeshWide",
page: MeshWidePage,
menu: MeshWideMenu,
menuGroup: "meshwide",
} as LimePlugin;
14 changes: 14 additions & 0 deletions src/components/icons/teenny/adjust.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const AdjustVertical = () => (
<svg
viewBox="0 0 15 15"
fill="none"
xmlns="http://www.w3.org/2000/svg"
width="15"
height="15"
>
<path
d="M7.5 12.5V15m5-15v2.5M2.5 0v6.5m0 2V15m5-4.5V0m5 4.5V15m-2-10.5h4v-2h-4v2zm-5 8h4v-2h-4v2zm-5-4h4v-2h-4v2z"
stroke="currentColor"
/>
</svg>
);
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export const plugins: LimePlugin[] = [
ChangeNode,
RemoteSupport,
Pirania,
MeshConfigPage,
Fbw, // does not have menu item
MeshConfigPage, // does not have menu item
];
64 changes: 22 additions & 42 deletions src/containers/Menu/menu.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Trans } from "@lingui/macro";
import { useState } from "preact/hooks";

import { plugins } from "../../config";
import style from "./style.less";

export const Menu = ({ opened, toggle }) => {
const [currentView, setCurrentView] = useState("node");
const hasCommunityPlugins = () =>
plugins.filter((p) => p.menuView && p.menuView === "community").length >
0;
function changeCurrentView(e) {
e.preventDefault();
setCurrentView(currentView === "node" ? "community" : "node");
}
// Group plugins by menuGroup
const groupedPlugins = plugins
.filter((plugin) => plugin.page && plugin.menu) // Only include plugins with both `page` and `menu`
.reduce((groups, plugin) => {
const group = plugin.menuGroup || "default"; // Use "default" for plugins without a menuGroup
if (!groups[group]) {
groups[group] = [];
}
groups[group].push(plugin.menu);
return groups;
}, {});

return (
<div
Expand All @@ -21,38 +21,18 @@ export const Menu = ({ opened, toggle }) => {
} d-flex flex-column`}
>
<nav className={style.menuItemsWrapper} onClick={toggle}>
{plugins
.map((plugin) => ({
...plugin,
menuView: plugin.menuView || "node",
}))
.filter(
(plugin) =>
plugin.page &&
plugin.menu &&
plugin.menuView === currentView
)
.map((plugin) => plugin.menu)
.map((Component, index) => (
<Component key={index} />
))}
</nav>
{hasCommunityPlugins() && (
<nav className={style.viewSwitchWrapper}>
<a
href="#0"
className={style.viewSwitch}
onClick={changeCurrentView}
>
{currentView === "node" && (
<Trans>Go to Community View</Trans>
{Object.entries(groupedPlugins).map(([group, components]) => (
<div key={group} className={style.menuGroup}>
{group !== "default" && (
// <div className={style.menuGroupTitle}>{group}</div>
<hr />
)}
{currentView === "community" && (
<Trans>Go to Node View</Trans>
)}
</a>
</nav>
)}
{components.map((Component, index) => (
<Component key={index} />
))}
</div>
))}
</nav>
</div>
);
};
9 changes: 1 addition & 8 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@ interface LimePlugin {
name: string;
page: typeof JSX.Element;
menu: typeof JSX.Element;
menuView?: string;
isCommunityProtected?: boolean;
additionalRoutes?: LimeRoutes[];
additionalProtectedRoutes?: LimeRoutes[];
store?: {
name: string;
epics?: any; // FIXME
reducer?: any; // FIXME
selector?: any; // FIXME
constants?: any; // FIXME
};
menuGroup?: string;
}
Loading