various viewer pill fixes (#5714)

This commit is contained in:
Reece Browne
2026-02-13 12:16:30 +00:00
committed by GitHub
parent b1d44d5661
commit 7c3c7937b3
4 changed files with 70 additions and 18 deletions
@@ -3,11 +3,12 @@ import { Box } from '@mantine/core';
import { useRainbowThemeContext } from '@app/components/shared/RainbowThemeProvider'; import { useRainbowThemeContext } from '@app/components/shared/RainbowThemeProvider';
import { useToolWorkflow } from '@app/contexts/ToolWorkflowContext'; import { useToolWorkflow } from '@app/contexts/ToolWorkflowContext';
import { useFileHandler } from '@app/hooks/useFileHandler'; import { useFileHandler } from '@app/hooks/useFileHandler';
import { useFileState } from '@app/contexts/FileContext'; import { useFileState, useFileActions } from '@app/contexts/FileContext';
import { useNavigationState, useNavigationActions, useNavigationGuard } from '@app/contexts/NavigationContext'; import { useNavigationState, useNavigationActions, useNavigationGuard } from '@app/contexts/NavigationContext';
import { isBaseWorkbench } from '@app/types/workbench'; import { isBaseWorkbench } from '@app/types/workbench';
import { useViewer } from '@app/contexts/ViewerContext'; import { useViewer } from '@app/contexts/ViewerContext';
import { useAppConfig } from '@app/contexts/AppConfigContext'; import { useAppConfig } from '@app/contexts/AppConfigContext';
import { FileId } from '@app/types/file';
import styles from '@app/components/layout/Workbench.module.css'; import styles from '@app/components/layout/Workbench.module.css';
import TopControls from '@app/components/shared/TopControls'; import TopControls from '@app/components/shared/TopControls';
@@ -26,6 +27,7 @@ export default function Workbench() {
// Use context-based hooks to eliminate all prop drilling // Use context-based hooks to eliminate all prop drilling
const { selectors } = useFileState(); const { selectors } = useFileState();
const { actions: fileActions } = useFileActions();
const { workbench: currentView } = useNavigationState(); const { workbench: currentView } = useNavigationState();
const { actions: navActions } = useNavigationActions(); const { actions: navActions } = useNavigationActions();
const setCurrentView = navActions.setWorkbench; const setCurrentView = navActions.setWorkbench;
@@ -68,6 +70,10 @@ export default function Workbench() {
}); });
}, [activeFileIndex, requestNavigation, setActiveFileIndex]); }, [activeFileIndex, requestNavigation, setActiveFileIndex]);
const handleFileRemove = useCallback(async (fileId: FileId) => {
await fileActions.removeFiles([fileId], false); // false = don't delete from IndexedDB, just remove from context
}, [fileActions]);
const handlePreviewClose = () => { const handlePreviewClose = () => {
setPreviewFile(null); setPreviewFile(null);
const previousMode = sessionStorage.getItem('previousMode'); const previousMode = sessionStorage.getItem('previousMode');
@@ -201,6 +207,7 @@ export default function Workbench() {
})} })}
currentFileIndex={activeFileIndex} currentFileIndex={activeFileIndex}
onFileSelect={handleFileSelect} onFileSelect={handleFileSelect}
onFileRemove={handleFileRemove}
/> />
)} )}
@@ -1,15 +1,28 @@
import React from 'react'; import React from 'react';
import { Menu, Loader, Group, Text } from '@mantine/core'; import { Menu, Loader, Group, Text, ActionIcon, Tooltip } from '@mantine/core';
import VisibilityIcon from '@mui/icons-material/Visibility'; import InsertDriveFileIcon from '@mui/icons-material/InsertDriveFile';
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'; import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import CloseIcon from '@mui/icons-material/Close';
import FitText from '@app/components/shared/FitText'; import FitText from '@app/components/shared/FitText';
import { PrivateContent } from '@app/components/shared/PrivateContent'; import { PrivateContent } from '@app/components/shared/PrivateContent';
import { FileId } from '@app/types/file';
// Truncate text from the center: "very-long-filename.pdf" -> "very-lo...ame.pdf"
function truncateCenter(text: string, maxLength: number = 25): string {
if (text.length <= maxLength) return text;
const ellipsis = '...';
const charsToShow = maxLength - ellipsis.length;
const frontChars = Math.ceil(charsToShow / 2);
const backChars = Math.floor(charsToShow / 2);
return text.substring(0, frontChars) + ellipsis + text.substring(text.length - backChars);
}
interface FileDropdownMenuProps { interface FileDropdownMenuProps {
displayName: string; displayName: string;
activeFiles: Array<{ fileId: string; name: string; versionNumber?: number }>; activeFiles: Array<{ fileId: string; name: string; versionNumber?: number }>;
currentFileIndex: number; currentFileIndex: number;
onFileSelect?: (index: number) => void; onFileSelect?: (index: number) => void;
onFileRemove?: (fileId: FileId) => void;
switchingTo?: string | null; switchingTo?: string | null;
viewOptionStyle: React.CSSProperties; viewOptionStyle: React.CSSProperties;
pillRef?: React.RefObject<HTMLDivElement>; pillRef?: React.RefObject<HTMLDivElement>;
@@ -20,22 +33,27 @@ export const FileDropdownMenu: React.FC<FileDropdownMenuProps> = ({
activeFiles, activeFiles,
currentFileIndex, currentFileIndex,
onFileSelect, onFileSelect,
onFileRemove,
switchingTo, switchingTo,
viewOptionStyle, viewOptionStyle,
}) => { }) => {
return ( return (
<Menu trigger="click" position="bottom" width="30rem"> <Menu trigger="click" position="bottom" width="30rem">
<Menu.Target> <Menu.Target>
<div style={{...viewOptionStyle, cursor: 'pointer'}}> <div style={{...viewOptionStyle, cursor: 'pointer', maxWidth: '100%'}}>
{switchingTo === "viewer" ? ( {switchingTo === "viewer" ? (
<Loader size="xs" /> <Loader size="xs" />
) : ( ) : (
<VisibilityIcon fontSize="small" /> <InsertDriveFileIcon fontSize="small" style={{ flexShrink: 0 }} />
)} )}
<PrivateContent> <PrivateContent>
<FitText text={displayName} fontSize={14} minimumFontScale={0.6} /> <FitText
text={truncateCenter(displayName, 30)}
minimumFontScale={0.6}
style={{ maxWidth: '12rem', display: 'inline-block' }}
/>
</PrivateContent> </PrivateContent>
<KeyboardArrowDownIcon fontSize="small" /> <KeyboardArrowDownIcon fontSize="small" style={{ flexShrink: 0 }} />
</div> </div>
</Menu.Target> </Menu.Target>
<Menu.Dropdown style={{ <Menu.Dropdown style={{
@@ -65,14 +83,36 @@ export const FileDropdownMenu: React.FC<FileDropdownMenuProps> = ({
<Group gap="xs" style={{ width: '100%', justifyContent: 'space-between' }}> <Group gap="xs" style={{ width: '100%', justifyContent: 'space-between' }}>
<div style={{ flex: 1, textAlign: 'left', minWidth: 0 }}> <div style={{ flex: 1, textAlign: 'left', minWidth: 0 }}>
<PrivateContent> <PrivateContent>
<FitText text={itemName} fontSize={14} minimumFontScale={0.7} /> <FitText
text={truncateCenter(itemName, 50)}
minimumFontScale={0.7}
style={{ display: 'block', width: '100%' }}
/>
</PrivateContent> </PrivateContent>
</div> </div>
<Group gap="xs" style={{ flexShrink: 0 }}>
{file.versionNumber && file.versionNumber > 1 && ( {file.versionNumber && file.versionNumber > 1 && (
<Text size="xs" c="dimmed"> <Text size="xs" c="dimmed">
v{file.versionNumber} v{file.versionNumber}
</Text> </Text>
)} )}
{onFileRemove && (
<Tooltip label="Close file" withArrow>
<ActionIcon
size="xs"
variant="subtle"
color="red"
onClick={(e) => {
e.stopPropagation();
onFileRemove(file.fileId as FileId);
}}
style={{ flexShrink: 0 }}
>
<CloseIcon style={{ fontSize: 14 }} />
</ActionIcon>
</Tooltip>
)}
</Group>
</Group> </Group>
</Menu.Item> </Menu.Item>
); );
@@ -127,7 +127,7 @@ const FileMenuItem: React.FC<FileMenuItemProps> = ({
/> />
<div style={{ flex: 1, textAlign: 'left', minWidth: 0 }}> <div style={{ flex: 1, textAlign: 'left', minWidth: 0 }}>
<PrivateContent> <PrivateContent>
<FitText text={itemName} fontSize={14} minimumFontScale={0.7} /> <FitText text={itemName} minimumFontScale={0.7} />
</PrivateContent> </PrivateContent>
</div> </div>
{file.versionNumber && file.versionNumber > 1 && ( {file.versionNumber && file.versionNumber > 1 && (
@@ -11,6 +11,7 @@ import { PageEditorFileDropdown } from '@app/components/shared/PageEditorFileDro
import type { CustomWorkbenchViewInstance } from '@app/contexts/ToolWorkflowContext'; import type { CustomWorkbenchViewInstance } from '@app/contexts/ToolWorkflowContext';
import { FileDropdownMenu } from '@app/components/shared/FileDropdownMenu'; import { FileDropdownMenu } from '@app/components/shared/FileDropdownMenu';
import { usePageEditorDropdownState, PageEditorDropdownState } from '@app/components/pageEditor/hooks/usePageEditorDropdownState'; import { usePageEditorDropdownState, PageEditorDropdownState } from '@app/components/pageEditor/hooks/usePageEditorDropdownState';
import { FileId } from '@app/types/file';
const viewOptionStyle: React.CSSProperties = { const viewOptionStyle: React.CSSProperties = {
@@ -29,6 +30,7 @@ const createViewOptions = (
activeFiles: Array<{ fileId: string; name: string; versionNumber?: number }>, activeFiles: Array<{ fileId: string; name: string; versionNumber?: number }>,
currentFileIndex: number, currentFileIndex: number,
onFileSelect?: (index: number) => void, onFileSelect?: (index: number) => void,
onFileRemove?: (fileId: FileId) => void,
pageEditorState?: PageEditorDropdownState, pageEditorState?: PageEditorDropdownState,
customViews?: CustomWorkbenchViewInstance[] customViews?: CustomWorkbenchViewInstance[]
) => { ) => {
@@ -37,8 +39,7 @@ const createViewOptions = (
const isInViewer = currentView === 'viewer'; const isInViewer = currentView === 'viewer';
const fileName = currentFile?.name || ''; const fileName = currentFile?.name || '';
const viewerDisplayName = isInViewer && fileName ? fileName : 'Viewer'; const viewerDisplayName = isInViewer && fileName ? fileName : 'Viewer';
const hasMultipleFiles = activeFiles.length > 1; const showViewerDropdown = isInViewer;
const showViewerDropdown = isInViewer && hasMultipleFiles;
const viewerOption = { const viewerOption = {
label: showViewerDropdown ? ( label: showViewerDropdown ? (
@@ -47,6 +48,7 @@ const createViewOptions = (
activeFiles={activeFiles} activeFiles={activeFiles}
currentFileIndex={currentFileIndex} currentFileIndex={currentFileIndex}
onFileSelect={onFileSelect} onFileSelect={onFileSelect}
onFileRemove={onFileRemove}
switchingTo={switchingTo} switchingTo={switchingTo}
viewOptionStyle={viewOptionStyle} viewOptionStyle={viewOptionStyle}
/> />
@@ -132,6 +134,7 @@ interface TopControlsProps {
activeFiles?: Array<{ fileId: string; name: string; versionNumber?: number }>; activeFiles?: Array<{ fileId: string; name: string; versionNumber?: number }>;
currentFileIndex?: number; currentFileIndex?: number;
onFileSelect?: (index: number) => void; onFileSelect?: (index: number) => void;
onFileRemove?: (fileId: FileId) => void;
} }
const TopControls = ({ const TopControls = ({
@@ -141,6 +144,7 @@ const TopControls = ({
activeFiles = [], activeFiles = [],
currentFileIndex = 0, currentFileIndex = 0,
onFileSelect, onFileSelect,
onFileRemove,
}: TopControlsProps) => { }: TopControlsProps) => {
const { isRainbowMode } = useRainbowThemeContext(); const { isRainbowMode } = useRainbowThemeContext();
const [switchingTo, setSwitchingTo] = useState<WorkbenchType | null>(null); const [switchingTo, setSwitchingTo] = useState<WorkbenchType | null>(null);
@@ -176,9 +180,10 @@ const TopControls = ({
activeFiles, activeFiles,
currentFileIndex, currentFileIndex,
onFileSelect, onFileSelect,
onFileRemove,
pageEditorState, pageEditorState,
customViews customViews
), [currentView, switchingTo, activeFiles, currentFileIndex, onFileSelect, pageEditorState, customViews]); ), [currentView, switchingTo, activeFiles, currentFileIndex, onFileSelect, onFileRemove, pageEditorState, customViews]);
return ( return (
<div className="absolute left-0 w-full top-0 z-[100] pointer-events-none"> <div className="absolute left-0 w-full top-0 z-[100] pointer-events-none">