From 950e1c8779d81adef49160bc02cd9adf9544127a Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Sat, 12 Oct 2024 00:49:05 -0700 Subject: [PATCH] Build and lint fixes. --- docs/deploy-reverse-proxy.md | 2 +- src/common/components/useMatchMedia.ts | 6 ++-- .../layout/optima/portals/OptimaPortalsIn.tsx | 8 ++--- src/common/util/textUtils.ts | 29 +++++++++++++++++++ src/modules/blocks/blocks.hooks.ts | 2 +- .../markdown/CustomMarkdownRenderer.tsx | 3 +- .../vendors/openai/OpenAIServiceSetup.tsx | 2 +- 7 files changed, 40 insertions(+), 12 deletions(-) diff --git a/docs/deploy-reverse-proxy.md b/docs/deploy-reverse-proxy.md index 08dcad0a9..5ed7f3cf2 100644 --- a/docs/deploy-reverse-proxy.md +++ b/docs/deploy-reverse-proxy.md @@ -55,4 +55,4 @@ ensure that your proxy is configured to support streaming output as described ab - For Kubernetes deployments, see our [Kubernetes Deployment Guide](deploy-k8s.md) - For general installation instructions, see our [Installation Guide](installation.md) -If you continue to experience issues, please reach out to our [community support channels](README.md#support-and-community). +If you continue to experience issues, please reach out to our [community support channels](../README.md#-get-involved). diff --git a/src/common/components/useMatchMedia.ts b/src/common/components/useMatchMedia.ts index 1c0e5c3e3..2a32cd50a 100644 --- a/src/common/components/useMatchMedia.ts +++ b/src/common/components/useMatchMedia.ts @@ -8,19 +8,19 @@ export function getIsMobile() { } export function useIsMobile(): boolean { - return _useMatchMedia(_isMobileQuery, false); + return useMatchMedia(_isMobileQuery, false); } export function useIsTallScreen(): boolean { // Adjust the aspect ratio value as needed (e.g., 10/9 for a slightly taller than square ratio) - return _useMatchMedia('(max-aspect-ratio: 10/9)', false); + return useMatchMedia('(max-aspect-ratio: 10/9)', false); } // the query was was ${appTheme.breakpoints.values.md: { xs: 0, sm: 600, md: 900, lg: 1200, xl: 1536 } - 1}px const _isMobileQuery: string = `(max-width: 899px)`; -function _useMatchMedia(query: string, ssrValue: boolean): boolean { +function useMatchMedia(query: string, ssrValue: boolean): boolean { const [matches, setMatches] = React.useState(isBrowser ? window.matchMedia(query).matches : ssrValue); React.useEffect(() => { diff --git a/src/common/layout/optima/portals/OptimaPortalsIn.tsx b/src/common/layout/optima/portals/OptimaPortalsIn.tsx index 836306513..c0fdbe246 100644 --- a/src/common/layout/optima/portals/OptimaPortalsIn.tsx +++ b/src/common/layout/optima/portals/OptimaPortalsIn.tsx @@ -5,17 +5,17 @@ import { OptimaPortalId, useOptimaPortalsStore } from './store-optima-portals'; export function OptimaDrawerIn(props: { children: React.ReactNode }) { - const portalElement = _useOptimaPortalTargetElement('optima-portal-drawer'); + const portalElement = useOptimaPortalTargetElement('optima-portal-drawer'); return portalElement ? createPortal(props.children, portalElement) : null; } export function OptimaPanelIn(props: { children: React.ReactNode }) { - const portalElement = _useOptimaPortalTargetElement('optima-portal-panel'); + const portalElement = useOptimaPortalTargetElement('optima-portal-panel'); return portalElement ? createPortal(props.children, portalElement) : null; } export function OptimaToolbarIn(props: { children: React.ReactNode }) { - const portalElement = _useOptimaPortalTargetElement('optima-portal-toolbar'); + const portalElement = useOptimaPortalTargetElement('optima-portal-toolbar'); return portalElement ? createPortal(props.children, portalElement) : null; } @@ -23,7 +23,7 @@ export function OptimaToolbarIn(props: { children: React.ReactNode }) { /** * Hook to get the target element for a portal. */ -function _useOptimaPortalTargetElement(targetPortalId: OptimaPortalId) { +function useOptimaPortalTargetElement(targetPortalId: OptimaPortalId) { // get the output element const targetPortalEl = useOptimaPortalsStore(state => state.portals[targetPortalId]?.element ?? null); diff --git a/src/common/util/textUtils.ts b/src/common/util/textUtils.ts index 7470cb381..840570749 100644 --- a/src/common/util/textUtils.ts +++ b/src/common/util/textUtils.ts @@ -50,3 +50,32 @@ export function ellipsizeMiddle(text: string, maxLength: number) { const half = Math.floor(maxLength / 2); return text.slice(0, half) + '…' + text.slice(-(maxLength - half - 1)); } + +export function ellipsizeEnd(text: string, maxLength: number, maxLines?: number) { + let wasTruncated = false; + + // Handle maxLines if specified + if (maxLines !== undefined && maxLines > 0) { + const lines = text.split('\n'); + if (lines.length > maxLines) { + text = lines.slice(0, maxLines).join('\n'); + wasTruncated = true; + } + } + + // Check if text exceeds maxLength and truncate if necessary + if (text.length > maxLength) { + text = text.slice(0, maxLength - 1) + '…'; + // wasTruncated = true; // not useful here + } else if (wasTruncated) { + // If text was truncated by lines but not by length, add ellipsis if possible + if (text.length + 1 <= maxLength) { + text += '…'; + } else if (maxLength > 0) { + // Truncate one character to add ellipsis without exceeding maxLength + text = text.slice(0, maxLength - 1) + '…'; + } + } + + return text; +} \ No newline at end of file diff --git a/src/modules/blocks/blocks.hooks.ts b/src/modules/blocks/blocks.hooks.ts index 050c27e8a..7eb4f2dae 100644 --- a/src/modules/blocks/blocks.hooks.ts +++ b/src/modules/blocks/blocks.hooks.ts @@ -99,5 +99,5 @@ export function useAutoBlocksMemoSemiStable(text: string, forceCodeWithTitle: st prevTextRef.current = text; return recycledBlocks; - }, [forceCodeWithTitle, forceMarkdown, forceSanityTextDiffs, text]); + }, [forceCodeWithTitle, forceMarkdown, forceSanityTextDiffs, selectSingleCodeBlock, text]); } \ No newline at end of file diff --git a/src/modules/blocks/markdown/CustomMarkdownRenderer.tsx b/src/modules/blocks/markdown/CustomMarkdownRenderer.tsx index 96cdad06d..0b0fc9f25 100644 --- a/src/modules/blocks/markdown/CustomMarkdownRenderer.tsx +++ b/src/modules/blocks/markdown/CustomMarkdownRenderer.tsx @@ -8,9 +8,8 @@ import { default as remarkGfm } from 'remark-gfm'; import { default as remarkMath } from 'remark-math'; import { remarkMark } from 'remark-mark-highlight'; -import { Box, Button, Tooltip } from '@mui/joy'; +import { Box, Button } from '@mui/joy'; import DownloadIcon from '@mui/icons-material/Download'; -import ContentCopyIcon from '@mui/icons-material/ContentCopy'; import { copyToClipboard } from '~/common/util/clipboardUtils'; diff --git a/src/modules/llms/vendors/openai/OpenAIServiceSetup.tsx b/src/modules/llms/vendors/openai/OpenAIServiceSetup.tsx index feb186cc5..26fb5f35b 100644 --- a/src/modules/llms/vendors/openai/OpenAIServiceSetup.tsx +++ b/src/modules/llms/vendors/openai/OpenAIServiceSetup.tsx @@ -74,7 +74,7 @@ export function OpenAIServiceSetup(props: { serviceId: DModelsServiceId }) { {advanced.on && What is this} + description={What is this} placeholder='Optional, for enterprise users' value={oaiOrg} onChange={text => updateSettings({ oaiOrg: text })}