1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { connect } from "react-redux";
6 import { RootState } from "../../../store/store";
7 import { getNodeValue } from "models/tree";
8 import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
9 import { CopyToClipboardAction } from "./copy-to-clipboard-action";
10 import { replaceCollectionId, getCollectionItemClipboardUrl, sanitizeToken } from "./helpers";
12 const mapStateToPropsUUID = (state: RootState) => {
13 const { resource } = state.contextMenu;
14 const currentCollectionUuid = state.collectionPanel.item ? state.collectionPanel.item.uuid : '';
16 ContextMenuKind.COLLECTION_FILE_ITEM,
17 ContextMenuKind.READONLY_COLLECTION_FILE_ITEM,
18 ContextMenuKind.COLLECTION_DIRECTORY_ITEM,
19 ContextMenuKind.READONLY_COLLECTION_DIRECTORY_ITEM ].indexOf(resource.menuKind as ContextMenuKind) > -1) {
20 const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
23 href: getCollectionItemClipboardUrl(replaceCollectionId(file.url, currentCollectionUuid),
24 state.auth.config.keepWebServiceUrl,
25 state.auth.config.keepWebInlineServiceUrl),
27 customText: "Copy link to latest version",
34 const mapStateToPropsPDH = (state: RootState) => {
35 const { resource } = state.contextMenu;
36 const currentCollectionPDH = state.collectionPanel.item ? state.collectionPanel.item.portableDataHash : '';
38 ContextMenuKind.COLLECTION_FILE_ITEM,
39 ContextMenuKind.READONLY_COLLECTION_FILE_ITEM,
40 ContextMenuKind.COLLECTION_DIRECTORY_ITEM,
41 ContextMenuKind.READONLY_COLLECTION_DIRECTORY_ITEM ].indexOf(resource.menuKind as ContextMenuKind) > -1) {
42 const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
45 href: getCollectionItemClipboardUrl(replaceCollectionId(file.url, currentCollectionPDH),
46 state.auth.config.keepWebServiceUrl,
47 state.auth.config.keepWebInlineServiceUrl),
49 customText: "Copy link to immutable version",
56 const mapStateToPropsCWL = (state: RootState) => {
57 const { resource } = state.contextMenu;
58 const currentCollectionPDH = state.collectionPanel.item ? state.collectionPanel.item.portableDataHash : '';
60 ContextMenuKind.COLLECTION_FILE_ITEM,
61 ContextMenuKind.READONLY_COLLECTION_FILE_ITEM,
62 ContextMenuKind.COLLECTION_DIRECTORY_ITEM,
63 ContextMenuKind.READONLY_COLLECTION_DIRECTORY_ITEM ].indexOf(resource.menuKind as ContextMenuKind) > -1) {
64 const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
67 url = replaceCollectionId(url, '');
68 url = sanitizeToken(url, false);
69 const path = new URL(url).pathname;
71 href: `keep:${currentCollectionPDH}${path}`,
73 customText: "Copy CWL file reference",
80 export const CollectionUUIDCopyToClipboardAction = connect(mapStateToPropsUUID)(CopyToClipboardAction);
82 export const CollectionPDHCopyToClipboardAction = connect(mapStateToPropsPDH)(CopyToClipboardAction);
84 export const CollectionCWLCopyToClipboardAction = connect(mapStateToPropsCWL)(CopyToClipboardAction);