From: Michal Klobukowski Date: Fri, 10 Aug 2018 10:35:15 +0000 (+0200) Subject: Implement single file download action X-Git-Tag: 1.3.0~153^2~13 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/27cb820f897c08448f7495c57a8f2fc9cadaa2b4 Implement single file download action Feature #13990 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- diff --git a/.env b/.env index de1444c0..df56fb28 100644 --- a/.env +++ b/.env @@ -4,5 +4,5 @@ REACT_APP_ARVADOS_CONFIG_URL=/config.json REACT_APP_ARVADOS_API_HOST=qr1hi.arvadosapi.com -REACT_APP_ARVADOS_KEEP_WEB_HOST=download.qr1hi.arvadosapi.com +REACT_APP_ARVADOS_KEEP_WEB_HOST=collections.qr1hi.arvadosapi.com HTTPS=true \ No newline at end of file diff --git a/src/components/context-menu/context-menu.tsx b/src/components/context-menu/context-menu.tsx index 95bbeafb..4068251b 100644 --- a/src/components/context-menu/context-menu.tsx +++ b/src/components/context-menu/context-menu.tsx @@ -36,21 +36,23 @@ export class ContextMenu extends React.PureComponent { {items.map((group, groupIndex) => {group.map((item, actionIndex) => - onItemClick(item)}> - {item.icon && - - - } - {item.name && - - {item.name} - } - {item.component && - } - )} + item.component + ? onItemClick(item)} /> + : onItemClick(item)}> + {item.icon && + + + } + {item.name && + + {item.name} + } + )} {groupIndex < items.length - 1 && } )} diff --git a/src/views-components/context-menu/action-sets/collection-files-item-action-set.ts b/src/views-components/context-menu/action-sets/collection-files-item-action-set.ts index e24108f4..7b03c49a 100644 --- a/src/views-components/context-menu/action-sets/collection-files-item-action-set.ts +++ b/src/views-components/context-menu/action-sets/collection-files-item-action-set.ts @@ -6,6 +6,7 @@ import { ContextMenuActionSet } from "../context-menu-action-set"; import { RenameIcon, DownloadIcon, RemoveIcon } from "../../../components/icon/icon"; import { openRenameFileDialog } from "../../rename-file-dialog/rename-file-dialog"; import { openFileRemoveDialog } from "../../file-remove-dialog/file-remove-dialog"; +import { DownloadCollectionFileAction } from "../actions/download-collection-file-action"; export const collectionFilesItemActionSet: ContextMenuActionSet = [[{ @@ -15,11 +16,8 @@ export const collectionFilesItemActionSet: ContextMenuActionSet = [[{ dispatch(openRenameFileDialog(resource.name)); } }, { - name: "Download", - icon: DownloadIcon, - execute: (dispatch, resource) => { - return; - } + component: DownloadCollectionFileAction, + execute: () => { return; } }, { name: "Remove", icon: RemoveIcon, diff --git a/src/views-components/context-menu/actions/download-action.tsx b/src/views-components/context-menu/actions/download-action.tsx new file mode 100644 index 00000000..1f6979d0 --- /dev/null +++ b/src/views-components/context-menu/actions/download-action.tsx @@ -0,0 +1,29 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import * as React from "react"; +import { ListItemIcon, ListItemText, Button, ListItem } from "@material-ui/core"; +import { DownloadIcon } from "../../../components/icon/icon"; + +export const DownloadAction = (props: { href?: string, download?: string, onClick?: () => void }) => { + const targetProps = props.download ? {} : { target: '_blank' }; + const downloadProps = props.download ? { download: props.download } : {}; + return props.href + ? + + + + + + Download + + + + : null; +}; \ No newline at end of file diff --git a/src/views-components/context-menu/actions/download-collection-file-action.tsx b/src/views-components/context-menu/actions/download-collection-file-action.tsx new file mode 100644 index 00000000..460e620a --- /dev/null +++ b/src/views-components/context-menu/actions/download-collection-file-action.tsx @@ -0,0 +1,25 @@ +// 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 { DownloadAction } from "./download-action"; +import { getNodeValue } from "../../../models/tree"; +import { CollectionFileType } from "../../../models/collection-file"; + +const mapStateToProps = (state: RootState) => { + const { resource } = state.contextMenu; + if (resource) { + const file = getNodeValue(resource.uuid)(state.collectionPanelFiles); + if (file) { + return { + href: file.url, + download: file.type === CollectionFileType.DIRECTORY ? undefined : file.name + }; + } + } + return {}; +}; + +export const DownloadCollectionFileAction = connect(mapStateToProps)(DownloadAction); diff --git a/src/views-components/context-menu/actions/favorite-action.tsx b/src/views-components/context-menu/actions/favorite-action.tsx index 55fe8cfd..06e3b5ef 100644 --- a/src/views-components/context-menu/actions/favorite-action.tsx +++ b/src/views-components/context-menu/actions/favorite-action.tsx @@ -3,25 +3,28 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from "react"; -import { ListItemIcon, ListItemText } from "@material-ui/core"; +import { ListItemIcon, ListItemText, ListItem } from "@material-ui/core"; import { AddFavoriteIcon, RemoveFavoriteIcon } from "../../../components/icon/icon"; import { connect } from "react-redux"; import { RootState } from "../../../store/store"; -const mapStateToProps = (state: RootState) => ({ - isFavorite: state.contextMenu.resource !== undefined && state.favorites[state.contextMenu.resource.uuid] === true +const mapStateToProps = (state: RootState, props: { onClick: () => {} }) => ({ + isFavorite: state.contextMenu.resource !== undefined && state.favorites[state.contextMenu.resource.uuid] === true, + onClick: props.onClick }); -export const ToggleFavoriteAction = connect(mapStateToProps)((props: { isFavorite: boolean }) => - <> +export const ToggleFavoriteAction = connect(mapStateToProps)((props: { isFavorite: boolean, onClick: () => void }) => + {props.isFavorite ? : } - + {props.isFavorite ? <>Remove from favorites : <>Add to favorites} - ); + );