Skip to content

Commit

Permalink
feat(ui-debug): add icon and a component for images
Browse files Browse the repository at this point in the history
  • Loading branch information
skamril committed Aug 1, 2024
1 parent 90bc6e2 commit d3aaeaf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
11 changes: 11 additions & 0 deletions webapp/src/components/App/Singlestudy/explore/Debug/Data/Image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ViewWrapper from "../../../../../common/page/ViewWrapper";

function Image() {
////////////////////////////////////////////////////////////////
// JSX
////////////////////////////////////////////////////////////////

return <ViewWrapper>Cannot diplay image</ViewWrapper>;
}

export default Image;
17 changes: 12 additions & 5 deletions webapp/src/components/App/Singlestudy/explore/Debug/Data/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import Text from "./Text";
import Image from "./Image";
import Json from "./Json";
import Matrix from "./Matrix";
import type { FileInfo } from "../utils";
import { Box } from "@mui/material";
import type { FileInfo, FileType } from "../utils";

interface Props extends FileInfo {
studyId: string;
}

const componentByFileType = {
interface DataComponentProps {
studyId: string;
path: string;
}
type DataComponent = React.ComponentType<DataComponentProps>;

const componentByFileType: Record<FileType, DataComponent> = {
matrix: Matrix,
json: Json,
file: Text,
folder: Box,
text: Text,
image: Image,
folder: ({ path }) => path,
} as const;

function Data({ studyId, fileType, filePath }: Props) {
Expand Down
11 changes: 8 additions & 3 deletions webapp/src/components/App/Singlestudy/explore/Debug/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import DataObjectIcon from "@mui/icons-material/DataObject";
import TextSnippetIcon from "@mui/icons-material/TextSnippet";
import ImageIcon from "@mui/icons-material/Image";
import FolderIcon from "@mui/icons-material/Folder";
import DatasetIcon from "@mui/icons-material/Dataset";
import { SvgIconComponent } from "@mui/icons-material";
Expand All @@ -9,7 +10,7 @@ import * as RA from "ramda-adjunct";
// Types
////////////////////////////////////////////////////////////////

export type FileType = "json" | "matrix" | "file" | "folder";
export type FileType = "json" | "matrix" | "text" | "image" | "folder";

export interface FileInfo {
fileType: FileType;
Expand All @@ -32,8 +33,9 @@ export type TreeData = TreeFolder | TreeFile;
const iconByFileType: Record<FileType, SvgIconComponent> = {
matrix: DatasetIcon,
json: DataObjectIcon,
text: TextSnippetIcon,
image: ImageIcon,
folder: FolderIcon,
file: TextSnippetIcon,
} as const;

/**
Expand Down Expand Up @@ -67,6 +69,9 @@ export function getFileType(treeData: TreeData): FileType {
if (treeData.startsWith("json://") || treeData.endsWith(".json")) {
return "json";
}
if (treeData.startsWith("file://") && treeData.endsWith(".ico")) {
return "image";
}
}
return isFolder(treeData) ? "folder" : "file";
return isFolder(treeData) ? "folder" : "text";
}

0 comments on commit d3aaeaf

Please sign in to comment.