1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import { unionize, ofType, UnionOf } from "~/common/unionize";
7 import { RootState } from '~/store/store';
8 import { setBreadcrumbs } from '~/store/breadcrumbs/breadcrumbs-actions';
9 import { ServiceRepository } from "~/services/services";
10 import { KeepServiceResource } from '~/models/keep-services';
11 import { dialogActions } from '~/store/dialog/dialog-actions';
12 import { snackbarActions } from '~/store/snackbar/snackbar-actions';
13 import { navigateToRootProject } from '~/store/navigation/navigation-action';
15 export const keepServicesActions = unionize({
16 SET_KEEP_SERVICES: ofType<KeepServiceResource[]>(),
17 REMOVE_KEEP_SERVICE: ofType<string>()
20 export type KeepServicesActions = UnionOf<typeof keepServicesActions>;
22 export const KEEP_SERVICE_REMOVE_DIALOG = 'keepServiceRemoveDialog';
23 export const KEEP_SERVICE_ATTRIBUTES_DIALOG = 'keepServiceAttributesDialog';
25 export const loadKeepServicesPanel = () =>
26 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
27 const user = getState().auth.user;
28 if(user && user.isAdmin) {
30 dispatch(setBreadcrumbs([{ label: 'Keep Services' }]));
31 const response = await services.keepService.list();
32 dispatch(keepServicesActions.SET_KEEP_SERVICES(response.items));
37 dispatch(navigateToRootProject);
38 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "You don't have permissions to view this page", hideDuration: 2000 }));
42 export const openKeepServiceAttributesDialog = (uuid: string) =>
43 (dispatch: Dispatch, getState: () => RootState) => {
44 const keepService = getState().keepServices.find(it => it.uuid === uuid);
45 dispatch(dialogActions.OPEN_DIALOG({ id: KEEP_SERVICE_ATTRIBUTES_DIALOG, data: { keepService } }));
48 export const openKeepServiceRemoveDialog = (uuid: string) =>
49 (dispatch: Dispatch, getState: () => RootState) => {
50 dispatch(dialogActions.OPEN_DIALOG({
51 id: KEEP_SERVICE_REMOVE_DIALOG,
53 title: 'Remove keep service',
54 text: 'Are you sure you want to remove this keep service?',
55 confirmButtonLabel: 'Remove',
61 export const removeKeepService = (uuid: string) =>
62 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
63 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...' }));
65 await services.keepService.delete(uuid);
66 dispatch(keepServicesActions.REMOVE_KEEP_SERVICE(uuid));
67 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Keep service has been successfully removed.', hideDuration: 2000 }));