chore: Drive settings sidebar from new config (#3236)

This commit is contained in:
Tom Moor
2022-03-13 09:34:50 -07:00
committed by GitHub
parent c979d003e4
commit da8714a4f6

View File

@@ -1,27 +1,14 @@
import { groupBy } from "lodash";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { import { BackIcon } from "outline-icons";
NewDocumentIcon,
EmailIcon,
ProfileIcon,
PadlockIcon,
CodeIcon,
UserIcon,
GroupIcon,
LinkIcon,
TeamIcon,
BackIcon,
BeakerIcon,
DownloadIcon,
} from "outline-icons";
import * as React from "react"; import * as React from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom"; import { useHistory } from "react-router-dom";
import styled from "styled-components"; import styled from "styled-components";
import Flex from "~/components/Flex"; import Flex from "~/components/Flex";
import Scrollable from "~/components/Scrollable"; import Scrollable from "~/components/Scrollable";
import SlackIcon from "~/components/SlackIcon";
import ZapierIcon from "~/components/ZapierIcon";
import env from "~/env"; import env from "~/env";
import useAuthorizedSettingsConfig from "~/hooks/useAuthorizedSettingsConfig";
import useCurrentTeam from "~/hooks/useCurrentTeam"; import useCurrentTeam from "~/hooks/useCurrentTeam";
import usePolicy from "~/hooks/usePolicy"; import usePolicy from "~/hooks/usePolicy";
import Sidebar from "./Sidebar"; import Sidebar from "./Sidebar";
@@ -38,6 +25,8 @@ function SettingsSidebar() {
const history = useHistory(); const history = useHistory();
const team = useCurrentTeam(); const team = useCurrentTeam();
const can = usePolicy(team.id); const can = usePolicy(team.id);
const configs = useAuthorizedSettingsConfig();
const groupedConfig = groupBy(configs, "group");
const returnToApp = React.useCallback(() => { const returnToApp = React.useCallback(() => {
history.push("/home"); history.push("/home");
@@ -54,100 +43,19 @@ function SettingsSidebar() {
<Flex auto column> <Flex auto column>
<Scrollable topShadow> <Scrollable topShadow>
<Section> {Object.keys(groupedConfig).map((header) => (
<Header>{t("Account")}</Header> <Section key={header}>
<SidebarLink <Header>{header}</Header>
to="/settings" {groupedConfig[header].map((item) => (
icon={<ProfileIcon color="currentColor" />}
label={t("Profile")}
/>
<SidebarLink
to="/settings/notifications"
icon={<EmailIcon color="currentColor" />}
label={t("Notifications")}
/>
{can.createApiKey && (
<SidebarLink
to="/settings/tokens"
icon={<CodeIcon color="currentColor" />}
label={t("API Tokens")}
/>
)}
</Section>
<Section>
<Header>{t("Team")}</Header>
{can.update && (
<SidebarLink
to="/settings/details"
icon={<TeamIcon color="currentColor" />}
label={t("Details")}
/>
)}
{can.update && (
<SidebarLink
to="/settings/security"
icon={<PadlockIcon color="currentColor" />}
label={t("Security")}
/>
)}
{can.update && (
<SidebarLink
to="/settings/features"
icon={<BeakerIcon color="currentColor" />}
label={t("Features")}
/>
)}
<SidebarLink
to="/settings/members"
icon={<UserIcon color="currentColor" />}
exact={false}
label={t("Members")}
/>
<SidebarLink
to="/settings/groups"
icon={<GroupIcon color="currentColor" />}
exact={false}
label={t("Groups")}
/>
<SidebarLink
to="/settings/shares"
icon={<LinkIcon color="currentColor" />}
label={t("Share Links")}
/>
{can.manage && (
<SidebarLink
to="/settings/import"
icon={<NewDocumentIcon color="currentColor" />}
label={t("Import")}
/>
)}
{can.export && (
<SidebarLink
to="/settings/export"
icon={<DownloadIcon color="currentColor" />}
label={t("Export")}
/>
)}
</Section>
{can.update && (env.SLACK_KEY || isHosted) && (
<Section>
<Header>{t("Integrations")}</Header>
{env.SLACK_KEY && (
<SidebarLink <SidebarLink
to="/settings/integrations/slack" key={item.path}
icon={<SlackIcon color="currentColor" />} to={item.path}
label="Slack" icon={<item.icon color="currentColor" />}
label={item.name}
/> />
)} ))}
{isHosted && (
<SidebarLink
to="/settings/integrations/zapier"
icon={<ZapierIcon color="currentColor" />}
label="Zapier"
/>
)}
</Section> </Section>
)} ))}
{can.update && !isHosted && ( {can.update && !isHosted && (
<Section> <Section>
<Header>{t("Installation")}</Header> <Header>{t("Installation")}</Header>