1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from 'redux';
6 import { RootState } from '~/store/store';
7 import { ServiceRepository } from '~/services/services';
8 import { bindDataExplorerActions } from '~/store/data-explorer/data-explorer-action';
9 import { setBreadcrumbs } from '~/store/breadcrumbs/breadcrumbs-actions';
10 import { dialogActions } from '~/store/dialog/dialog-actions';
11 import { LinkResource } from '~/models/link';
12 import { getResource } from '~/store/resources/resources';
13 import {snackbarActions, SnackbarKind} from '~/store/snackbar/snackbar-actions';
15 export const LINK_PANEL_ID = "linkPanelId";
16 export const linkPanelActions = bindDataExplorerActions(LINK_PANEL_ID);
18 export const LINK_REMOVE_DIALOG = 'linkRemoveDialog';
19 export const LINK_ATTRIBUTES_DIALOG = 'linkAttributesDialog';
21 export const loadLinkPanel = () =>
22 (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
23 dispatch(setBreadcrumbs([{ label: 'Links' }]));
24 dispatch(linkPanelActions.REQUEST_ITEMS());
27 export const openLinkAttributesDialog = (uuid: string) =>
28 (dispatch: Dispatch, getState: () => RootState) => {
29 const { resources } = getState();
30 const link = getResource<LinkResource>(uuid)(resources);
31 dispatch(dialogActions.OPEN_DIALOG({ id: LINK_ATTRIBUTES_DIALOG, data: { link } }));
34 export const openLinkRemoveDialog = (uuid: string) =>
35 (dispatch: Dispatch, getState: () => RootState) => {
36 dispatch(dialogActions.OPEN_DIALOG({
37 id: LINK_REMOVE_DIALOG,
40 text: 'Are you sure you want to remove this link?',
41 confirmButtonLabel: 'Remove',
47 export const removeLink = (uuid: string) =>
48 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
49 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...', kind: SnackbarKind.INFO }));
51 await services.linkService.delete(uuid);
52 dispatch(linkPanelActions.REQUEST_ITEMS());
53 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Link has been successfully removed.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));