Skip to content

Commit 8baa753

Browse files
authored
Improve menu groups (#475)
* chore(menu): improve menu groups * chore(menu): fix mesh wide upgrade path * chore(menu): delete commented
1 parent 4b4b329 commit 8baa753

10 files changed

Lines changed: 56 additions & 55 deletions

File tree

plugins/lime-plugin-firmware/src/upgradeAvailable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const UpgradeAvailableBanner = () => {
2222
// @ts-ignore
2323
<Match>
2424
{({ path }) =>
25-
!["firmware", "releaseInfo", "meshwideupgrade"].includes(
25+
!["firmware", "releaseInfo", "meshwide/upgrade"].includes(
2626
path.replace("/", "")
2727
) && (
2828
<div
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { MeshConfigMenu } from "plugins/lime-plugin-mesh-wide-config/src/meshConfigMenu";
2+
13
import MeshConfigPage from "./src/meshConfigPage";
24

35
export default {
46
name: "meshwide/config",
57
page: MeshConfigPage,
8+
menu: MeshConfigMenu,
69
isCommunityProtected: true,
7-
additionalRoutes: [["/meshwide/config", MeshConfigPage]],
10+
menuGroup: "meshwide",
811
} as LimePlugin;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Trans } from "@lingui/macro";
2+
3+
import { AdjustVertical } from "components/icons/teenny/adjust";
4+
5+
export const MeshConfigMenu = () => (
6+
<span>
7+
<AdjustVertical />
8+
<a href={"#/meshwide/config"}>
9+
<Trans>Mesh Wide Config</Trans>
10+
</a>
11+
</span>
12+
);

plugins/lime-plugin-mesh-wide-upgrade/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { MeshUpgradeMenu } from "plugins/lime-plugin-mesh-wide-upgrade/src/meshU
22
import MeshUpgradePage from "plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradePage";
33

44
export default {
5-
name: "MeshWideUpgrade",
5+
name: "meshwide/upgrade",
66
page: MeshUpgradePage,
77
menu: MeshUpgradeMenu,
88
isCommunityProtected: true,
9+
menuGroup: "meshwide",
910
} as LimePlugin;

plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradeMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { GlobeAmericasIcon } from "components/icons/teenny/globe";
55
export const MeshUpgradeMenu = () => (
66
<span>
77
<GlobeAmericasIcon />
8-
<a href={"#/meshwideupgrade"}>
8+
<a href={"#/meshwide/upgrade"}>
99
<Trans>Mesh Wide Upgrade</Trans>
1010
</a>
1111
</span>

plugins/lime-plugin-mesh-wide/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export default {
55
name: "MeshWide",
66
page: MeshWidePage,
77
menu: MeshWideMenu,
8+
menuGroup: "meshwide",
89
} as LimePlugin;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const AdjustVertical = () => (
2+
<svg
3+
viewBox="0 0 15 15"
4+
fill="none"
5+
xmlns="http://www.w3.org/2000/svg"
6+
width="15"
7+
height="15"
8+
>
9+
<path
10+
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"
11+
stroke="currentColor"
12+
/>
13+
</svg>
14+
);

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ export const plugins: LimePlugin[] = [
2929
ChangeNode,
3030
RemoteSupport,
3131
Pirania,
32+
MeshConfigPage,
3233
Fbw, // does not have menu item
33-
MeshConfigPage, // does not have menu item
3434
];

src/containers/Menu/menu.js

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { Trans } from "@lingui/macro";
2-
import { useState } from "preact/hooks";
3-
41
import { plugins } from "../../config";
52
import style from "./style.less";
63

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

1717
return (
1818
<div
@@ -21,38 +21,15 @@ export const Menu = ({ opened, toggle }) => {
2121
} d-flex flex-column`}
2222
>
2323
<nav className={style.menuItemsWrapper} onClick={toggle}>
24-
{plugins
25-
.map((plugin) => ({
26-
...plugin,
27-
menuView: plugin.menuView || "node",
28-
}))
29-
.filter(
30-
(plugin) =>
31-
plugin.page &&
32-
plugin.menu &&
33-
plugin.menuView === currentView
34-
)
35-
.map((plugin) => plugin.menu)
36-
.map((Component, index) => (
37-
<Component key={index} />
38-
))}
24+
{Object.entries(groupedPlugins).map(([group, components]) => (
25+
<div key={group} className={style.menuGroup}>
26+
{group !== "default" && <hr />}
27+
{components.map((Component, index) => (
28+
<Component key={index} />
29+
))}
30+
</div>
31+
))}
3932
</nav>
40-
{hasCommunityPlugins() && (
41-
<nav className={style.viewSwitchWrapper}>
42-
<a
43-
href="#0"
44-
className={style.viewSwitch}
45-
onClick={changeCurrentView}
46-
>
47-
{currentView === "node" && (
48-
<Trans>Go to Community View</Trans>
49-
)}
50-
{currentView === "community" && (
51-
<Trans>Go to Node View</Trans>
52-
)}
53-
</a>
54-
</nav>
55-
)}
5633
</div>
5734
);
5835
};

src/types.d.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,8 @@ interface LimePlugin {
1212
name: string;
1313
page: typeof JSX.Element;
1414
menu: typeof JSX.Element;
15-
menuView?: string;
1615
isCommunityProtected?: boolean;
1716
additionalRoutes?: LimeRoutes[];
1817
additionalProtectedRoutes?: LimeRoutes[];
19-
store?: {
20-
name: string;
21-
epics?: any; // FIXME
22-
reducer?: any; // FIXME
23-
selector?: any; // FIXME
24-
constants?: any; // FIXME
25-
};
18+
menuGroup?: string;
2619
}

0 commit comments

Comments
 (0)