From b1dffc348699498d30f6bc73382f8f05ee94a76e Mon Sep 17 00:00:00 2001 From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com> Date: Mon, 11 Aug 2025 18:57:27 -0400 Subject: [PATCH] Convert insights from sidebar to modal dialog (#9892) * Convert insights from sidebar to modal dialog - Remove insights routing and sidebar layout - Update DocumentMeta to use modal action instead of navigation - Convert Insights component to modal-ready format - Clean up route helpers and authenticated layout - Remove insights route from authenticated routes Co-authored-by: Tom Moor * Applied automatic fixes * refactor * singular * refactor --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor --- app/actions/definitions/documents.tsx | 47 +---- app/components/AuthenticatedLayout.tsx | 13 +- app/components/Collaborators.tsx | 4 + app/hooks/useFormatNumber.ts | 16 ++ app/menus/DocumentMenu.tsx | 20 +++ app/menus/InsightsMenu.tsx | 36 ---- app/routes/authenticated.tsx | 6 +- .../Document/components/DocumentMeta.tsx | 34 ++-- app/scenes/Document/components/Insights.tsx | 170 ++++++------------ .../Settings/components/SharesTable.tsx | 15 +- app/utils/language.ts | 5 +- app/utils/routeHelpers.ts | 6 +- shared/i18n/locales/en_US/translation.json | 28 ++- 13 files changed, 152 insertions(+), 248 deletions(-) create mode 100644 app/hooks/useFormatNumber.ts delete mode 100644 app/menus/InsightsMenu.tsx diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx index a3df8920eb..e83d7f8f8b 100644 --- a/app/actions/definitions/documents.tsx +++ b/app/actions/definitions/documents.tsx @@ -26,7 +26,6 @@ import { PublishIcon, CommentIcon, CopyIcon, - EyeIcon, PadlockIcon, GlobeIcon, LogoutIcon, @@ -70,7 +69,6 @@ import env from "~/env"; import { setPersistedState } from "~/hooks/usePersistedState"; import history from "~/utils/history"; import { - documentInsightsPath, documentHistoryPath, homePath, newDocumentPath, @@ -84,6 +82,7 @@ import { import capitalize from "lodash/capitalize"; import CollectionIcon from "~/components/Icons/CollectionIcon"; import { ActionV2, ActionV2Group, ActionV2Separator } from "~/types"; +import Insights from "~/scenes/Document/components/Insights"; export const openDocument = createAction({ name: ({ t }) => t("Open document"), @@ -1329,7 +1328,7 @@ export const openDocumentHistory = createInternalLinkActionV2({ }, }); -export const openDocumentInsights = createInternalLinkActionV2({ +export const openDocumentInsights = createActionV2({ name: ({ t }) => t("Insights"), analyticsName: "Open document insights", section: ActiveDocumentSection, @@ -1347,51 +1346,17 @@ export const openDocumentInsights = createInternalLinkActionV2({ !document?.isDeleted ); }, - to: ({ activeDocumentId, stores, sidebarContext }) => { + perform: ({ activeDocumentId, stores, t }) => { const document = activeDocumentId ? stores.documents.get(activeDocumentId) : undefined; - if (!document) { - return ""; - } - - const [pathname, search] = documentInsightsPath(document).split("?"); - - return { - pathname, - search, - state: { sidebarContext }, - }; - }, -}); - -export const toggleViewerInsights = createActionV2({ - 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: ActiveDocumentSection, - 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, + stores.dialogs.openModal({ + title: t("Insights"), + content: , }); }, }); diff --git a/app/components/AuthenticatedLayout.tsx b/app/components/AuthenticatedLayout.tsx index 4ce45e3e49..c565c1cd65 100644 --- a/app/components/AuthenticatedLayout.tsx +++ b/app/components/AuthenticatedLayout.tsx @@ -27,7 +27,6 @@ import { settingsPath, matchDocumentHistory, matchDocumentSlug as slug, - matchDocumentInsights, } from "~/utils/routeHelpers"; import { DocumentContextProvider } from "./DocumentContext"; import Fade from "./Fade"; @@ -39,9 +38,7 @@ const DocumentComments = lazyWithRetry( const DocumentHistory = lazyWithRetry( () => import("~/scenes/Document/components/History") ); -const DocumentInsights = lazyWithRetry( - () => import("~/scenes/Document/components/Insights") -); + const CommandBar = lazyWithRetry(() => import("~/components/CommandBar")); type Props = { @@ -98,12 +95,7 @@ const AuthenticatedLayout: React.FC = ({ children }: Props) => { !!matchPath(location.pathname, { path: matchDocumentHistory, }) && can.listRevisions; - const showInsights = - !!matchPath(location.pathname, { - path: matchDocumentInsights, - }) && can.listViews; const showComments = - !showInsights && !showHistory && can.comment && ui.activeDocumentId && @@ -115,12 +107,11 @@ const AuthenticatedLayout: React.FC = ({ children }: Props) => { initial={false} key={ui.activeDocumentId ? "active" : "inactive"} > - {(showHistory || showInsights || showComments) && ( + {(showHistory || showComments) && ( {showHistory && } - {showInsights && } {showComments && } diff --git a/app/components/Collaborators.tsx b/app/components/Collaborators.tsx index f70cf79a1b..c8c2758e41 100644 --- a/app/components/Collaborators.tsx +++ b/app/components/Collaborators.tsx @@ -148,6 +148,10 @@ function Collaborators(props: Props) { [presentIds, editingIds, observingUserId, currentUserId, handleAvatarClick] ); + if (!document.insightsEnabled) { + return null; + } + return ( diff --git a/app/hooks/useFormatNumber.ts b/app/hooks/useFormatNumber.ts new file mode 100644 index 0000000000..e492a7cd9f --- /dev/null +++ b/app/hooks/useFormatNumber.ts @@ -0,0 +1,16 @@ +import { formatNumber } from "~/utils/language"; +import useUserLocale from "./useUserLocale"; +import { unicodeCLDRtoBCP47 } from "@shared/utils/date"; + +/** + * Hook that returns a function to format numbers based on the user's locale. + * + * @returns A function that formats numbers + */ +export function useFormatNumber() { + const language = useUserLocale(); + return (input: number) => + language + ? formatNumber(input, unicodeCLDRtoBCP47(language)) + : input.toString(); +} diff --git a/app/menus/DocumentMenu.tsx b/app/menus/DocumentMenu.tsx index a7b5e7d2e2..5f1a50b662 100644 --- a/app/menus/DocumentMenu.tsx +++ b/app/menus/DocumentMenu.tsx @@ -148,6 +148,13 @@ function DocumentMenu({ [user, document] ); + const handleInsightsToggle = React.useCallback( + (checked: boolean) => { + void document.save({ insightsEnabled: checked }); + }, + [document] + ); + const templateMenuActions = useTemplateMenuActions({ document, onSelectTemplate, @@ -231,6 +238,18 @@ function DocumentMenu({ <> + {can.updateInsights && ( + + )} {showToggleEmbeds && (