Merge branch '15685-file-renaming-empty-name'
[arvados-workbench2.git] / src / store / open-in-new-tab / open-in-new-tab.actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as copy from 'copy-to-clipboard';
6 import { ResourceKind } from '~/models/resource';
7 import { getClipboardUrl } from '~/views-components/context-menu/actions/helpers';
8
9 const getUrl = (resource: any) => {
10     let url = null;
11     const { uuid, kind } = resource;
12
13     if (kind === ResourceKind.COLLECTION) {
14         url = `/collections/${uuid}`;
15     }
16     if (kind === ResourceKind.PROJECT) {
17         url = `/projects/${uuid}`;
18     }
19
20     return url;
21 };
22
23 export const openInNewTabAction = (resource: any) => () => {
24     const url = getUrl(resource);
25
26     if (url) {
27         window.open(`${window.location.origin}${url}`, '_blank');
28     }
29 };
30
31 export const copyToClipboardAction = (resource: any) => () => {
32     const url = getUrl(resource);
33
34     if (url) {
35         copy(getClipboardUrl(url, false));
36     }
37 };