Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/components/account/config/menu.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Menu } from "antd";6import { useEffect, useMemo, useState } from "react";78import { Icon } from "@cocalc/frontend/components/icon";9import { capitalize } from "@cocalc/util/misc";10import { menuItem, MenuItems } from "components/antd-menu-items";11import { useRouter } from "next/router";12import { menu, topIcons } from "./register";1314export default function ConfigMenu({ main, sub }) {15const router = useRouter();16const [openKeys, setOpenKeys] = useState<string[]>([main]);1718// This useEffect is to ensure that the selected section (main)19// is always expanded, e.g., when you get there by clicking on20// a search result:21useEffect(() => {22if (openKeys.indexOf(main) == -1) {23setOpenKeys(openKeys.concat([main]));24}25}, [main]);2627const items: MenuItems = useMemo(28() =>29Object.keys(menu).map((main) => {30const sub = Object.keys(menu[main]).map((sub) => {31const { title, icon, danger } = menu[main][sub];32return menuItem(`${main}/${sub}`, title, icon, undefined, danger);33});3435const title = capitalize(main);36const icon = topIcons[main] ?? "gear";37return menuItem(main, title, <Icon name={icon} />, sub);38}),39[]40);4142return (43<Menu44mode="inline"45openKeys={openKeys}46onOpenChange={(keys) => {47setOpenKeys(keys);48}}49selectedKeys={[main + "/" + sub]}50style={{ height: "100%" }}51onSelect={(e) => {52router.push(`/config/${e.keyPath[0]}`, undefined, {53scroll: false,54});55}}56items={items}57/>58);59}606162