Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
import { RenameIcon, RemoveIcon } from "~/components/icon/icon";
import { DownloadCollectionFileAction } from "../actions/download-collection-file-action";
import { openFileRemoveDialog, openRenameFileDialog } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
-import { FileViewerActions } from '~/views-components/context-menu/actions/file-viewer-actions';
+import { CollectionFileViewerAction } from '~/views-components/context-menu/actions/collection-file-viewer-action';
export const collectionFilesItemActionSet: ContextMenuActionSet = [[{
dispatch<any>(openFileRemoveDialog(resource.uuid));
}
}], [{
- component: FileViewerActions,
+ component: CollectionFileViewerAction,
execute: () => { return; },
}]];
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { connect } from "react-redux";
+import { RootState } from "../../../store/store";
+import { FileViewerAction } from '~/views-components/context-menu/actions/file-viewer-action';
+import { getNodeValue } from "~/models/tree";
+import { CollectionFileType } from "~/models/collection-file";
+import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
+
+const mapStateToProps = (state: RootState) => {
+ const { resource } = state.contextMenu;
+ const currentCollectionUuid = state.collectionPanel.item ? state.collectionPanel.item.uuid : '';
+ if (resource && resource.menuKind === ContextMenuKind.COLLECTION_FILES_ITEM) {
+ const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
+ if (file) {
+ return {
+ href: file.url,
+ download: file.type === CollectionFileType.DIRECTORY ? undefined : file.name,
+ kind: 'file',
+ currentCollectionUuid
+ };
+ }
+ } else {
+ return ;
+ }
+ return ;
+};
+
+export const CollectionFileViewerAction = connect(mapStateToProps)(FileViewerAction);
const splittedByDot = href.split('.');
if (splittedByDot[splittedByDot.length - 1] !== 'json') {
if (fileUrls.length === id) {
- zip.file(download[id-1], data);
+ zip.file(download[id - 1], data);
zip.generateAsync({ type: 'blob' }).then((content) => {
FileSaver.saveAs(content, `download-${props.currentCollectionUuid}.zip`);
});
} else {
- zip.file(download[id-1], data);
+ zip.file(download[id - 1], data);
zip.generateAsync({ type: 'blob' });
}
} else {
- zip.file(download[id-1], JSON.stringify(data));
+ zip.file(download[id - 1], JSON.stringify(data));
zip.generateAsync({ type: 'blob' });
}
id++;
return props.href || props.kind === 'files'
? <a
style={{ textDecoration: 'none' }}
- href={props.kind === 'files' ? null : props.href}
+ href={props.kind === 'files' ? undefined : `${props.href}?disposition=attachment`}
onClick={props.onClick}
{...downloadProps}>
<ListItem button onClick={() => props.kind === 'files' ? createZip(props.href, props.download) : undefined}>
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from "react";
+import { ListItemIcon, ListItemText, ListItem } from "@material-ui/core";
+import { OpenIcon } from "~/components/icon/icon";
+
+export const FileViewerAction = (props: { href?: any, download?: any, onClick?: () => void, kind?: string, currentCollectionUuid?: string; }) => {
+ const fileProps = props.download ? { download: props.download } : {};
+
+ return props.href
+ ? <a
+ style={{ textDecoration: 'none' }}
+ href={props.href}
+ target="_blank"
+ onClick={props.onClick}
+ {...fileProps}>
+ <ListItem button>
+ <ListItemIcon>
+ <OpenIcon />
+ </ListItemIcon>
+ <ListItemText>
+ Open in new tab
+ </ListItemText>
+ </ListItem>
+ </a>
+ : null;
+};
\ No newline at end of file