1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import isImage from 'is-image';
7 import { withStyles, WithStyles } from '@material-ui/core';
8 import { FileTreeData } from 'components/file-tree/file-tree-data';
9 import { CollectionFileType } from 'models/collection-file';
10 import { getInlineFileUrl, sanitizeToken } from "views-components/context-menu/actions/helpers";
11 import { connect } from "react-redux";
12 import { RootState } from "store/store";
14 interface FileThumbnailProps {
18 export const FileThumbnail =
19 ({ file }: FileThumbnailProps) =>
20 file.type === CollectionFileType.FILE && isImage(file.name)
21 ? <ImageFileThumbnail file={file} />
24 type ImageFileThumbnailCssRules = 'thumbnail';
26 const imageFileThumbnailStyle = withStyles<ImageFileThumbnailCssRules>(theme => ({
29 margin: `${theme.spacing.unit}px 0`,
33 interface ImageFileThumbnailProps {
34 keepWebServiceUrl: string;
35 keepWebInlineServiceUrl: string;
38 const mapStateToProps = ({ auth }: RootState): ImageFileThumbnailProps => ({
39 keepWebServiceUrl: auth.config.keepWebServiceUrl,
40 keepWebInlineServiceUrl: auth.config.keepWebInlineServiceUrl,
43 const ImageFileThumbnail = connect(mapStateToProps)(imageFileThumbnailStyle(
44 ({ classes, file, keepWebServiceUrl, keepWebInlineServiceUrl }: WithStyles<ImageFileThumbnailCssRules> & FileThumbnailProps & ImageFileThumbnailProps) =>
46 className={classes.thumbnail}
48 src={sanitizeToken(getInlineFileUrl(file.url, keepWebServiceUrl, keepWebInlineServiceUrl))} />