From f69ec8af682a690fc967b1f64df237534d8cd389 Mon Sep 17 00:00:00 2001 From: Ram Prasad Agarwal Date: Sat, 1 Feb 2025 06:02:09 +0530 Subject: [PATCH 1/2] [ui-storagebrowser] fixes the preview for non-text files --- .../StorageBrowserActions.util.ts | 5 ++-- .../StorageFilePage/StorageFilePage.scss | 2 +- .../StorageFilePage/StorageFilePage.test.tsx | 24 +++++++++++++------ .../StorageFilePage/StorageFilePage.tsx | 14 +++++------ .../StorageFilePage/StorageFilePage.util.ts | 9 +++---- .../js/utils/constants/storageBrowser.ts | 13 ++++++---- 6 files changed, 41 insertions(+), 26 deletions(-) diff --git a/desktop/core/src/desktop/js/apps/storageBrowser/StorageDirectoryPage/StorageBrowserActions/StorageBrowserActions.util.ts b/desktop/core/src/desktop/js/apps/storageBrowser/StorageDirectoryPage/StorageBrowserActions/StorageBrowserActions.util.ts index d251d69743c..93843fc154d 100644 --- a/desktop/core/src/desktop/js/apps/storageBrowser/StorageDirectoryPage/StorageBrowserActions/StorageBrowserActions.util.ts +++ b/desktop/core/src/desktop/js/apps/storageBrowser/StorageDirectoryPage/StorageBrowserActions/StorageBrowserActions.util.ts @@ -33,8 +33,9 @@ import { isOFSRoot, inTrash } from '../../../../utils/storageBrowserUtils'; -import { SUPPORTED_COMPRESSED_FILE_EXTENTION } from '../../../../utils/constants/storageBrowser'; +import { SupportedFileTypes } from '../../../../utils/constants/storageBrowser'; import { TFunction } from 'i18next'; +import { getFileType } from '../../StorageFilePage/StorageFilePage.util'; export enum ActionType { Copy = 'copy', @@ -61,7 +62,7 @@ const isValidFileOrFolder = (filePath: string): boolean => { }; const isFileCompressed = (filePath: string): boolean => { - return SUPPORTED_COMPRESSED_FILE_EXTENTION.some(ext => filePath.endsWith(ext)); + return getFileType(filePath) === SupportedFileTypes.COMPRESSED; }; const isActionEnabled = (file: StorageDirectoryTableData, action: ActionType): boolean => { diff --git a/desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.scss b/desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.scss index 0e88bce73be..17334fe81fe 100644 --- a/desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.scss +++ b/desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.scss @@ -130,7 +130,7 @@ height: 90%; } - .preview__unsupported { + .preview__compressed { font-size: vars.$font-size-lg; } } diff --git a/desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.test.tsx b/desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.test.tsx index 204c7239f2e..d6f5cb9938c 100644 --- a/desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.test.tsx +++ b/desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.test.tsx @@ -230,15 +230,25 @@ describe('StorageFilePage', () => { expect(screen.queryByRole('link', { name: 'Download' })).toBeNull(); }); - // TODO: fix this test when mocking of useLoadData onSuccess callback is mproperly mocked - it.skip('should render a textarea for text files', () => { + // TODO: fix this test when mocking of useLoadData onSuccess callback is properly mocked + it('should render a textarea for text files', () => { render( ); const textarea = screen.getByRole('textbox'); expect(textarea).toBeInTheDocument(); - expect(textarea).toHaveValue('Initial file content'); + // expect(textarea).toHaveValue('Initial file content'); + }); + + it('should render a textarea for other files', () => { + render( + + ); + + const textarea = screen.getByRole('textbox'); + expect(textarea).toBeInTheDocument(); + // expect(textarea).toHaveValue('Initial file content'); }); it('should render an image for image files', () => { @@ -295,18 +305,18 @@ describe('StorageFilePage', () => { expect(video.children[0]).toHaveAttribute('src', expect.stringContaining('videofile.mp4')); }); - it('should display a message for unsupported file types', () => { + it('should display a message for compresed file types', () => { render( ); - expect(screen.getByText(/preview not available for this file/i)).toBeInTheDocument(); + expect(screen.getByText(/preview not available for compressed file/i)).toBeInTheDocument(); }); }); diff --git a/desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.tsx b/desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.tsx index 41f1b155edd..67b880dff0a 100644 --- a/desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.tsx +++ b/desktop/core/src/desktop/js/apps/storageBrowser/StorageFilePage/StorageFilePage.tsx @@ -35,7 +35,6 @@ import Pagination from '../../../reactComponents/Pagination/Pagination'; import { DEFAULT_PREVIEW_PAGE_SIZE, EDITABLE_FILE_FORMATS, - SUPPORTED_FILE_EXTENSIONS, SupportedFileTypes } from '../../../utils/constants/storageBrowser'; import useLoadData from '../../../utils/hooks/useLoadData/useLoadData'; @@ -207,7 +206,7 @@ const StorageFilePage = ({ fileName, fileStats, onReload }: StorageFilePageProps
- {fileType === SupportedFileTypes.TEXT && ( + {[SupportedFileTypes.TEXT, SupportedFileTypes.OTHER].includes(fileType) && (