Farmbot-Web-App/frontend/nav/nav_links.tsx

75 lines
2.5 KiB
TypeScript
Raw Normal View History

2017-07-04 07:20:51 -06:00
import * as React from "react";
2017-08-11 15:48:20 -06:00
import { NavLinksProps } from "./interfaces";
2017-11-22 00:00:58 -07:00
import { getPathArray } from "../history";
2018-06-21 15:04:21 -06:00
import {
2020-02-28 09:35:32 -07:00
computeEditorUrlFromState, computeFarmwareUrlFromState,
2018-06-21 15:04:21 -06:00
} from "./compute_editor_url_from_state";
import { Link } from "../link";
2019-04-02 13:59:37 -06:00
import { t } from "../i18next_wrapper";
2019-08-23 15:18:28 -06:00
import { betterCompact } from "../util";
2020-02-28 09:50:14 -07:00
import { DevSettings } from "../account/dev/dev_support";
2018-04-26 07:42:04 -06:00
/** Uses a slug and a child path to compute the `href` of a navbar link. */
2018-04-26 08:43:06 -06:00
export type LinkComputeFn = (slug: string, childPath: string) => string;
2018-04-26 07:42:04 -06:00
/** If no LinkComputeFn is provided, the default behavior prevails. */
const DEFAULT: LinkComputeFn =
(slug, childpath) => `/app/${slug}${childpath}`;
interface NavLinkParams {
/** User visible verbiage. */
name: string;
/** Font awesome icon name. */
icon: string;
/** A unique name used for the path in the URL bar. */
slug: string;
computeHref?: LinkComputeFn
}
2019-08-23 15:18:28 -06:00
export const getLinks = (): NavLinkParams[] => betterCompact([
2017-07-05 08:30:41 -06:00
{ name: "Farm Designer", icon: "leaf", slug: "designer" },
{ name: "Controls", icon: "keyboard-o", slug: "controls" },
2020-02-28 09:50:14 -07:00
DevSettings.futureFeaturesEnabled() ? undefined :
{ name: "Device", icon: "cog", slug: "device" },
2018-05-01 22:14:41 -06:00
{
name: "Sequences", icon: "server", slug: "sequences",
computeHref: computeEditorUrlFromState("Sequence")
},
{
name: "Regimens", icon: "calendar-check-o", slug: "regimens",
computeHref: computeEditorUrlFromState("Regimen")
},
2018-06-21 15:04:21 -06:00
{
name: "Farmware", icon: "crosshairs", slug: "farmware",
computeHref: computeFarmwareUrlFromState
},
2019-04-16 11:03:44 -06:00
{ name: "Messages", icon: "list", slug: "messages" },
2019-08-23 15:18:28 -06:00
]);
2017-07-04 07:20:51 -06:00
2017-08-11 15:48:20 -06:00
export const NavLinks = (props: NavLinksProps) => {
2017-11-22 00:00:58 -07:00
const currPageSlug = getPathArray()[2];
return <div className="links">
<div className="nav-links">
2019-08-23 15:18:28 -06:00
{getLinks().map(link => {
const isActive = (currPageSlug === link.slug) ? "active" : "";
const childPath = link.slug === "designer" ? "/plants" : "";
2018-04-26 07:42:04 -06:00
const fn = link.computeHref || DEFAULT;
return <Link
2018-04-26 07:42:04 -06:00
to={fn(link.slug, childPath)}
className={`${isActive}`}
key={link.slug}
2018-04-27 23:57:17 -06:00
draggable={false}
onClick={props.close("mobileMenuOpen")}>
<i className={`fa fa-${link.icon}`} />
<div data-title={t(link.name)}>
2019-04-16 11:03:44 -06:00
{t(link.name)}
{link.slug === "messages" && props.alertCount > 0 &&
<div className={"saucer fun"}>
<p>{props.alertCount}</p>
</div>}
</div>
</Link>;
})}
2017-07-05 08:30:41 -06:00
</div>
</div>;
2017-07-04 07:20:51 -06:00
};