* refactor: ♻️ refactor isHosted && type clean up Change-Id: I4dfbad8a07607432801de78920ce42bf81e46498 * refactor: ♻️ code clean up Change-Id: I8f487a33d332a2acaff84397a97371b56ace28a1 * feat: 💄 lint Change-Id: I776b1a5e249bdb542f8e6da7cb2277821cf91094 * feat: ✨ ci type Change-Id: I486dde7bf60321238e9a394c40ad8cdb8bfc54c8 * feat: some code sugession Change-Id: I4761d057344b95a98e99068d312a42292977875b
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import { groupBy } from "lodash";
|
|
import { observer } from "mobx-react";
|
|
import { BackIcon } from "outline-icons";
|
|
import * as React from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useHistory } from "react-router-dom";
|
|
import styled from "styled-components";
|
|
import Flex from "~/components/Flex";
|
|
import Scrollable from "~/components/Scrollable";
|
|
import useAuthorizedSettingsConfig from "~/hooks/useAuthorizedSettingsConfig";
|
|
import isHosted from "~/utils/isHosted";
|
|
import Sidebar from "./Sidebar";
|
|
import Header from "./components/Header";
|
|
import Section from "./components/Section";
|
|
import SidebarButton from "./components/SidebarButton";
|
|
import SidebarLink from "./components/SidebarLink";
|
|
import Version from "./components/Version";
|
|
|
|
function SettingsSidebar() {
|
|
const { t } = useTranslation();
|
|
const history = useHistory();
|
|
const configs = useAuthorizedSettingsConfig();
|
|
const groupedConfig = groupBy(configs, "group");
|
|
|
|
const returnToApp = React.useCallback(() => {
|
|
history.push("/home");
|
|
}, [history]);
|
|
|
|
return (
|
|
<Sidebar>
|
|
<SidebarButton
|
|
title={t("Return to App")}
|
|
image={<StyledBackIcon color="currentColor" />}
|
|
onClick={returnToApp}
|
|
minHeight={48}
|
|
/>
|
|
|
|
<Flex auto column>
|
|
<Scrollable shadow>
|
|
{Object.keys(groupedConfig).map((header) => (
|
|
<Section key={header}>
|
|
<Header>{header}</Header>
|
|
{groupedConfig[header].map((item) => (
|
|
<SidebarLink
|
|
key={item.path}
|
|
to={item.path}
|
|
icon={<item.icon color="currentColor" />}
|
|
label={item.name}
|
|
/>
|
|
))}
|
|
</Section>
|
|
))}
|
|
{!isHosted && (
|
|
<Section>
|
|
<Header>{t("Installation")}</Header>
|
|
<Version />
|
|
</Section>
|
|
)}
|
|
</Scrollable>
|
|
</Flex>
|
|
</Sidebar>
|
|
);
|
|
}
|
|
|
|
const StyledBackIcon = styled(BackIcon)`
|
|
margin-left: 4px;
|
|
`;
|
|
|
|
export default observer(SettingsSidebar);
|