🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(resource): let the file detail panel be resized (#21285)
Arvin Xu8499f7510f80
diff --git a/src/features/ResourceManager/components/Explorer/FileDetailPanel/index.tsx b/src/features/ResourceManager/components/Explorer/FileDetailPanel/index.tsxindex 89038a2bcc9..5043773db6d 100644--- a/src/features/ResourceManager/components/Explorer/FileDetailPanel/index.tsx+++ b/src/features/ResourceManager/components/Explorer/FileDetailPanel/index.tsx@@ -12,6 +12,7 @@ import { downloadFile } from '@/utils/client/downloadFile';import FilePreview from './FilePreview';import PagePreview from './PagePreview';import { useDetailPanelFile } from './useDetailPanelFile';+import { DETAIL_PANEL_MIN_WIDTH, useDetailPanelWidth } from './useDetailPanelWidth';/*** In-context right dock for the explorer list: single click on a file row@@ -26,21 +27,24 @@ const FileDetailPanel = memo(() => {const detailPanelIsPage = useResourceManagerStore((s) => s.detailPanelIsPage);const closeDetailPanel = useResourceManagerStore((s) => s.closeDetailPanel);const [showProperties, setShowProperties] = useState(false);+ const { handleSizeChange, width } = useDetailPanelWidth();const fileDetail = useDetailPanelFile(detailPanelId);return (<DraggablePanel+ showHandleWideAreabackgroundColor={cssVar.colorBgContainer}expand={!!detailPanelId}expandable={false}- minWidth={320}+ minWidth={DETAIL_PANEL_MIN_WIDTH}placement={'right'}- size={{ height: '100%', width: 480 }}+ size={{ height: '100%', width }}style={{borderInlineStart: `1px solid ${cssVar.colorBorderSecondary}`,boxShadow: theme.boxShadowTertiary,}}+ onSizeChange={handleSizeChange}>{fileDetail && (<Flexbox height={'100%'} style={{ minHeight: 0, overflow: 'hidden' }}>diff --git a/src/features/ResourceManager/components/Explorer/FileDetailPanel/useDetailPanelWidth.test.ts b/src/features/ResourceManager/components/Explorer/FileDetailPanel/useDetailPanelWidth.test.tsnew file mode 100644index 00000000000..d90265ef586--- /dev/null+++ b/src/features/ResourceManager/components/Explorer/FileDetailPanel/useDetailPanelWidth.test.ts@@ -0,0 +1,28 @@+import { act, renderHook } from '@testing-library/react';+import { describe, expect, it } from 'vitest';++import { DETAIL_PANEL_DEFAULT_WIDTH, useDetailPanelWidth } from './useDetailPanelWidth';++describe('useDetailPanelWidth', () => {+ it('keeps the width the user resized the panel to', () => {+ const { result } = renderHook(() => useDetailPanelWidth());++ expect(result.current.width).toBe(DETAIL_PANEL_DEFAULT_WIDTH);++ act(() => {+ result.current.handleSizeChange({ width: 200 }, { height: '100%', width: 680 });+ });++ expect(result.current.width).toBe(680);+ });++ it('ignores size changes without a width', () => {+ const { result } = renderHook(() => useDetailPanelWidth());++ act(() => {+ result.current.handleSizeChange({}, { height: '100%' });+ });++ expect(result.current.width).toBe(DETAIL_PANEL_DEFAULT_WIDTH);+ });+});diff --git a/src/features/ResourceManager/components/Explorer/FileDetailPanel/useDetailPanelWidth.ts b/src/features/ResourceManager/components/Explorer/FileDetailPanel/useDetailPanelWidth.tsnew file mode 100644index 00000000000..879fc03d40f--- /dev/null+++ b/src/features/ResourceManager/components/Explorer/FileDetailPanel/useDetailPanelWidth.ts@@ -0,0 +1,19 @@+import { type DraggablePanelSize } from '@lobehub/ui';+import { useCallback, useState } from 'react';++export const DETAIL_PANEL_DEFAULT_WIDTH = 480;+export const DETAIL_PANEL_MIN_WIDTH = 320;++/**+ * The detail panel width is controlled, so a resize must be written back here or+ * the drag snaps the panel straight back to its previous width.+ */+export const useDetailPanelWidth = () => {+ const [width, setWidth] = useState<number | string>(DETAIL_PANEL_DEFAULT_WIDTH);++ const handleSizeChange = useCallback((_delta: DraggablePanelSize, size: DraggablePanelSize) => {+ if (size?.width) setWidth(size.width);+ }, []);++ return { handleSizeChange, width };+};