From f3334cedb2156e4c1444da2ec427a67dd04d62fa Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 8 Mar 2024 23:03:06 -0500 Subject: [PATCH] Reduce size of Insights display toggle --- app/actions/definitions/documents.tsx | 32 +++ app/menus/InsightsMenu.tsx | 48 +++++ app/scenes/Document/components/Insights.tsx | 205 +++++++++----------- shared/i18n/locales/en_US/translation.json | 8 +- 4 files changed, 173 insertions(+), 120 deletions(-) create mode 100644 app/menus/InsightsMenu.tsx diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx index c52e625d1..b045b57c5 100644 --- a/app/actions/definitions/documents.tsx +++ b/app/actions/definitions/documents.tsx @@ -26,6 +26,7 @@ import { CommentIcon, GlobeIcon, CopyIcon, + EyeIcon, } from "outline-icons"; import * as React from "react"; import { toast } from "sonner"; @@ -899,6 +900,37 @@ export const openDocumentInsights = createAction({ }, }); +export const toggleViewerInsights = createAction({ + name: ({ t, stores, activeDocumentId }) => { + const document = activeDocumentId + ? stores.documents.get(activeDocumentId) + : undefined; + return document?.insightsEnabled + ? t("Disable viewer insights") + : t("Enable viewer insights"); + }, + analyticsName: "Toggle viewer insights", + section: DocumentSection, + icon: , + visible: ({ activeDocumentId, stores }) => { + const can = stores.policies.abilities(activeDocumentId ?? ""); + return can.updateInsights; + }, + perform: async ({ activeDocumentId, stores }) => { + if (!activeDocumentId) { + return; + } + const document = stores.documents.get(activeDocumentId); + if (!document) { + return; + } + + await document.save({ + insightsEnabled: !document.insightsEnabled, + }); + }, +}); + export const rootDocumentActions = [ openDocument, archiveDocument, diff --git a/app/menus/InsightsMenu.tsx b/app/menus/InsightsMenu.tsx new file mode 100644 index 000000000..b507e39a0 --- /dev/null +++ b/app/menus/InsightsMenu.tsx @@ -0,0 +1,48 @@ +import { t } from "i18next"; +import { MoreIcon } from "outline-icons"; +import React from "react"; +import { MenuButton, useMenuState } from "reakit/Menu"; +import styled from "styled-components"; +import { s } from "@shared/styles"; +import ContextMenu from "~/components/ContextMenu"; +import Template from "~/components/ContextMenu/Template"; +import NudeButton from "~/components/NudeButton"; +import { actionToMenuItem } from "~/actions"; +import { toggleViewerInsights } from "~/actions/definitions/documents"; +import useActionContext from "~/hooks/useActionContext"; +import { hover } from "~/styles"; +import { MenuItem } from "~/types"; + +const InsightsMenu: React.FC = () => { + const menuRef = React.useRef(null); + const menu = useMenuState(); + const context = useActionContext(); + const items: MenuItem[] = [actionToMenuItem(toggleViewerInsights, context)]; + + return ( + <> + + {(props) => ( + + )} + + +