diff --git a/src/api/common.ts b/src/api/common.ts index 6f6daef8b..b21224533 100644 --- a/src/api/common.ts +++ b/src/api/common.ts @@ -454,3 +454,7 @@ export function needsQuoting(value: string) { const quotedValue = quote(value); return quotedValue !== value; } + +export const getFileName = (name: string) => { + return name.split("/").slice(-1).join(""); +}; diff --git a/src/api/model.ts b/src/api/model.ts index 1f9ece447..7ccb51dcf 100644 --- a/src/api/model.ts +++ b/src/api/model.ts @@ -1,5 +1,9 @@ import _ from "lodash"; -import type { FeedFile, PluginInstance } from "@fnndsc/chrisapi"; +import type { + FileBrowserFolderFile, + PACSFile, + PluginInstance, +} from "@fnndsc/chrisapi"; export interface IActionTypeParam { type: string; @@ -162,7 +166,7 @@ export class TreeModel { export interface IFileBlob { blob?: Blob; - file?: FeedFile; + file?: FileBrowserFolderFile | PACSFile; url?: string; fileType: string; } @@ -175,6 +179,7 @@ export const fileViewerMap: any = { html: "IframeDisplay", pdf: "PdfDisplay", csv: "TextDisplay", + md: "TextDisplay", ctab: "TextDisplay", json: "JsonDisplay", png: "ImageDisplay", @@ -209,7 +214,7 @@ export function getFileExtension(filename: string) { } export class FileViewerModel { - public getFileName(item: FeedFile) { + public getFileName(item: FileBrowserFolderFile) { const splitString = item.data.fname.split("/"); const filename = splitString[splitString.length - 1]; return filename; diff --git a/src/components/Common/index.tsx b/src/components/Common/index.tsx index 99d79496c..acef8957d 100644 --- a/src/components/Common/index.tsx +++ b/src/components/Common/index.tsx @@ -1,5 +1,5 @@ -import { InfoIcon as InfoIconComponent } from "../Icons"; import { + ClipboardCopy, ClipboardCopyButton, Dropdown, DropdownItem, @@ -14,12 +14,22 @@ import { Hint, MenuToggle, TextInput, - ClipboardCopy, } from "@patternfly/react-core"; -import { CubesIcon, SearchIcon } from "../Icons"; import { Alert, Popover, Spin, Typography } from "antd"; -import React, { ReactNode, useState } from "react"; +import React, { type ReactNode, useState } from "react"; import Dots from "react-activity/dist/Dots"; +import { + ArchiveIcon, + CubesIcon, + ExternalLinkSquareAltIcon, + FileIcon, + FileImageIcon, + FilePdfIcon, + FileTxtIcon, + FolderIcon, + InfoIcon as InfoIconComponent, + SearchIcon, +} from "../Icons"; import "react-activity/dist/library.css"; import { Cookies } from "react-cookie"; import ReactJson from "react-json-view"; @@ -350,3 +360,26 @@ export const ClipboardCopyFixed = ({ ); }; + +export const getIcon = (type: string) => { + switch (type.toLowerCase()) { + case "dir": + return ; + case "dcm": + case "jpg": + case "png": + return ; + case "txt": + return ; + case "pdf": + return ; + case "zip": + return ; + case "link": + return ; + case "folder": + return ; + default: + return ; + } +}; diff --git a/src/components/FeedOutputBrowser/FileBrowser.tsx b/src/components/FeedOutputBrowser/FileBrowser.tsx index a151d730a..a818a6ba6 100644 --- a/src/components/FeedOutputBrowser/FileBrowser.tsx +++ b/src/components/FeedOutputBrowser/FileBrowser.tsx @@ -20,28 +20,16 @@ import { setSelectedFile, } from "../../store/explorer/actions"; import useDownload, { useTypedSelector } from "../../store/hooks"; -import { ClipboardCopyContainer, SpinContainer } from "../Common"; +import { ClipboardCopyContainer, SpinContainer, getIcon } from "../Common"; import { ThemeContext } from "../DarkTheme/useTheme"; import { DrawerActionButton } from "../Feeds/DrawerUtils"; import { handleMaximize, handleMinimize } from "../Feeds/utilties"; -import { - DownloadIcon, - ExternalLinkSquareAltIcon, - FileIcon, - FileImageIcon, - FilePdfIcon, - FileTxtIcon, - FolderIcon, - HomeIcon, -} from "../Icons"; +import { DownloadIcon, HomeIcon } from "../Icons"; import FileDetailView from "../Preview/FileDetailView"; import XtkViewer from "../XtkViewer/XtkViewer"; import type { FileBrowserProps } from "./types"; import { bytesToSize } from "./utilities"; - -export const getFileName = (name: string) => { - return name.split("/").slice(-1).join(""); -}; +import { getFileExtension } from "../../api/model"; const previewAnimation = [{ opacity: "0.0" }, { opacity: "1.0" }]; @@ -193,7 +181,7 @@ const FileBrowser = (props: FileBrowserProps) => { fileName = pathList[pathList.length - 1]; if (type === "file" && fileName.indexOf(".") > -1) { - iconType = getFileName(fileName)[0].toUpperCase(); + iconType = getFileExtension(fileName); fsize = bytesToSize(item.data.fsize); } else { iconType = type; @@ -316,29 +304,3 @@ const FileBrowser = (props: FileBrowserProps) => { }; export default FileBrowser; - -const getIcon = (type: string) => { - switch (type.toLowerCase()) { - case "dir": - return ; - case "dcm": - case "jpg": - case "png": - return ; - case "html": - case "json": - return ; - case "txt": - return ; - case "pdf": - return ; - - case "link": - return ; - case "folder": - return ; - - default: - return ; - } -}; diff --git a/src/components/Icons/index.tsx b/src/components/Icons/index.tsx index 98f59710d..3dc920fa1 100644 --- a/src/components/Icons/index.tsx +++ b/src/components/Icons/index.tsx @@ -40,7 +40,6 @@ const CartIcon = ({ return ( { diff --git a/src/components/NewLibrary/components/FileCard.tsx b/src/components/NewLibrary/components/FileCard.tsx index 313e63b7f..9f8144112 100644 --- a/src/components/NewLibrary/components/FileCard.tsx +++ b/src/components/NewLibrary/components/FileCard.tsx @@ -24,6 +24,8 @@ import useLongPress, { elipses, getBackgroundRowColor, } from "../utils/longpress"; +import { getFileExtension } from "../../../api/model"; +import { getIcon } from "../../Common"; type Pagination = { totalCount: number; @@ -43,7 +45,7 @@ export const LinkCard = ({ const linkName = pathList[pathList.length - 1]; const creation_date = val.data.creation_date; return ( - + { const { isSuccess, isError, error: downloadError } = handleDownloadMutation; const isSelected = selectedPaths.some((payload) => { - payload.path === file.data.fname; + return payload.path === file.data.fname; }); + const selectedBgRow = getBackgroundRowColor(isSelected, isDarkTheme); + const ext = getFileExtension(file.data.fname); + const icon = getIcon(ext); useEffect(() => { if (isSuccess) { @@ -164,9 +169,7 @@ export const SubFileCard = ({ file }: { file: FileBrowserFolderFile }) => { {contextHolder} - - - + {icon} File Type: {ext} - - - ); + return ( - {alertText} - + type="info" + description={`No preview available for the filetype ${ext}`} + /> ); }; return noPreviewMessage(); }; -const MemoedCatchAllDisplay = React.memo(CatchallDisplay); +const MemoedCatchAllDisplay = memo(CatchallDisplay); export default MemoedCatchAllDisplay; diff --git a/src/components/Preview/displays/ViewerDisplay.tsx b/src/components/Preview/displays/ViewerDisplay.tsx index ea1f7ff14..c169584e8 100644 --- a/src/components/Preview/displays/ViewerDisplay.tsx +++ b/src/components/Preview/displays/ViewerDisplay.tsx @@ -1,18 +1,18 @@ -import * as React from "react"; -import { IFileBlob } from "../../../api/model"; +import type * as React from "react"; +import type { IFileBlob } from "../../../api/model"; +import type { ActionState } from "../FileDetailView"; import { CatchallDisplay, - JsonDisplay, + DcmDisplay, IframeDisplay, ImageDisplay, - DcmDisplay, + JsonDisplay, + NiiVueDisplay, PdfDisplay, - XtkDisplay, TextDisplay, - NiiVueDisplay, VideoDisplay, + XtkDisplay, } from "./index"; -import { ActionState } from "../FileDetailView"; const components = { JsonDisplay, diff --git a/src/store/cart/saga.ts b/src/store/cart/saga.ts index b494e7184..941d0e33e 100644 --- a/src/store/cart/saga.ts +++ b/src/store/cart/saga.ts @@ -178,7 +178,6 @@ function* handleIndividualDownload( } yield setStatus(type, id, "finished"); } catch (e) { - console.error(e); yield setStatus(type, id, "cancelled"); } } diff --git a/src/store/hooks.ts b/src/store/hooks.ts index 467dfacec..bf8419f81 100644 --- a/src/store/hooks.ts +++ b/src/store/hooks.ts @@ -4,12 +4,12 @@ export const useTypedSelector: TypedUseSelectorHook = useSelector; import type { Feed, FileBrowserFolderFile } from "@fnndsc/chrisapi"; import { useMutation } from "@tanstack/react-query"; import ChrisAPIClient from "../api/chrisapiclient"; -import { getFileName } from "../components/FeedOutputBrowser/FileBrowser"; +import { getFileName } from "../api/common"; export const createLinkAndDownload = (url: string, fileName: string) => { const link = document.createElement("a"); link.href = url; - //link.target = 'blank'; + link.target = "blank"; link.download = fileName; document.body.appendChild(link); link.click(); @@ -27,7 +27,6 @@ export const downloadPublicFile = async (file: FileBrowserFolderFile) => { }; export const downloadFile = async (file: FileBrowserFolderFile) => { - console.log("File", file); const fileName = getFileName(file.data.fname); const client = ChrisAPIClient.getClient(); const response = await client.createDownloadToken();