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 { getUserUuid } from "common/getuser";
8 import { loadDetailsPanel } from "store/details-panel/details-panel-action";
9 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
10 import { favoritePanelActions, loadFavoritePanel } from "store/favorite-panel/favorite-panel-action";
11 import { getProjectPanelCurrentUuid, setIsProjectPanelTrashed } from "store/project-panel/project-panel-action";
12 import { projectPanelActions } from "store/project-panel/project-panel-action-bind";
14 activateSidePanelTreeItem,
16 loadSidePanelTreeProjects,
17 SidePanelTreeCategory,
18 } from "store/side-panel-tree/side-panel-tree-actions";
19 import { updateResources } from "store/resources/resources-actions";
20 import { projectPanelColumns } from "views/project-panel/project-panel";
21 import { favoritePanelColumns } from "views/favorite-panel/favorite-panel";
22 import { matchRootRoute } from "routes/routes";
25 setGroupDetailsBreadcrumbs,
27 setProcessBreadcrumbs,
28 setSharedWithMeBreadcrumbs,
29 setSidePanelBreadcrumbs,
32 setMyAccountBreadcrumbs,
33 setUserProfileBreadcrumbs,
34 } from "store/breadcrumbs/breadcrumbs-actions";
35 import { navigateTo, navigateToRootProject } from "store/navigation/navigation-action";
36 import { MoveToFormDialogData } from "store/move-to-dialog/move-to-dialog";
37 import { ServiceRepository } from "services/services";
38 import { getResource } from "store/resources/resources";
39 import * as projectCreateActions from "store/projects/project-create-actions";
40 import * as projectMoveActions from "store/projects/project-move-actions";
41 import * as projectUpdateActions from "store/projects/project-update-actions";
42 import * as collectionCreateActions from "store/collections/collection-create-actions";
43 import * as collectionCopyActions from "store/collections/collection-copy-actions";
44 import * as collectionMoveActions from "store/collections/collection-move-actions";
45 import * as processesActions from "store/processes/processes-actions";
46 import * as processMoveActions from "store/processes/process-move-actions";
47 import * as processUpdateActions from "store/processes/process-update-actions";
48 import * as processCopyActions from "store/processes/process-copy-actions";
49 import { trashPanelColumns } from "views/trash-panel/trash-panel";
50 import { loadTrashPanel, trashPanelActions } from "store/trash-panel/trash-panel-action";
51 import { loadProcessPanel } from "store/process-panel/process-panel-actions";
52 import { loadSharedWithMePanel, sharedWithMePanelActions } from "store/shared-with-me-panel/shared-with-me-panel-actions";
53 import { sharedWithMePanelColumns } from "views/shared-with-me-panel/shared-with-me-panel";
54 import { CopyFormDialogData } from "store/copy-dialog/copy-dialog";
55 import { workflowPanelActions } from "store/workflow-panel/workflow-panel-actions";
56 import { loadSshKeysPanel } from "store/auth/auth-action-ssh";
57 import { loadLinkAccountPanel, linkAccountPanelActions } from "store/link-account-panel/link-account-panel-actions";
58 import { loadSiteManagerPanel } from "store/auth/auth-action-session";
59 import { workflowPanelColumns } from "views/workflow-panel/workflow-panel-view";
60 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
61 import { getProgressIndicator } from "store/progress-indicator/progress-indicator-reducer";
62 import { extractUuidKind, Resource, ResourceKind } from "models/resource";
63 import { FilterBuilder } from "services/api/filter-builder";
64 import { GroupContentsResource } from "services/groups-service/groups-service";
65 import { MatchCases, ofType, unionize, UnionOf } from "common/unionize";
66 import { loadRunProcessPanel } from "store/run-process-panel/run-process-panel-actions";
67 import { collectionPanelActions, loadCollectionPanel } from "store/collection-panel/collection-panel-action";
68 import { CollectionResource } from "models/collection";
69 import { WorkflowResource } from "models/workflow";
70 import { loadSearchResultsPanel, searchResultsPanelActions } from "store/search-results-panel/search-results-panel-actions";
71 import { searchResultsPanelColumns } from "views/search-results-panel/search-results-panel-view";
72 import { loadVirtualMachinesPanel } from "store/virtual-machines/virtual-machines-actions";
73 import { loadRepositoriesPanel } from "store/repositories/repositories-actions";
74 import { loadKeepServicesPanel } from "store/keep-services/keep-services-actions";
75 import { loadUsersPanel, userBindedActions } from "store/users/users-actions";
76 import * as userProfilePanelActions from "store/user-profile/user-profile-actions";
77 import { linkPanelActions, loadLinkPanel } from "store/link-panel/link-panel-actions";
78 import { linkPanelColumns } from "views/link-panel/link-panel-root";
79 import { userPanelColumns } from "views/user-panel/user-panel";
80 import { loadApiClientAuthorizationsPanel, apiClientAuthorizationsActions } from "store/api-client-authorizations/api-client-authorizations-actions";
81 import { apiClientAuthorizationPanelColumns } from "views/api-client-authorization-panel/api-client-authorization-panel-root";
82 import * as groupPanelActions from "store/groups-panel/groups-panel-actions";
83 import { groupsPanelColumns } from "views/groups-panel/groups-panel";
84 import * as groupDetailsPanelActions from "store/group-details-panel/group-details-panel-actions";
85 import { groupDetailsMembersPanelColumns, groupDetailsPermissionsPanelColumns } from "views/group-details-panel/group-details-panel";
86 import { DataTableFetchMode } from "components/data-table/data-table";
87 import { loadPublicFavoritePanel, publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
88 import { publicFavoritePanelColumns } from "views/public-favorites-panel/public-favorites-panel";
90 loadCollectionsContentAddressPanel,
91 collectionsContentAddressActions,
92 } from "store/collections-content-address-panel/collections-content-address-panel-actions";
93 import { collectionContentAddressPanelColumns } from "views/collection-content-address-panel/collection-content-address-panel";
94 import { subprocessPanelActions } from "store/subprocess-panel/subprocess-panel-actions";
95 import { subprocessPanelColumns } from "views/subprocess-panel/subprocess-panel-root";
96 import { loadAllProcessesPanel, allProcessesPanelActions } from "../all-processes-panel/all-processes-panel-action";
97 import { allProcessesPanelColumns } from "views/all-processes-panel/all-processes-panel";
98 import { AdminMenuIcon } from "components/icon/icon";
99 import { userProfileGroupsColumns } from "views/user-profile-panel/user-profile-panel-root";
100 import { selectedToArray, selectedToKindSet } from "components/multiselect-toolbar/MultiselectToolbar";
101 import { multiselectActions } from "store/multiselect/multiselect-actions";
103 export const WORKBENCH_LOADING_SCREEN = "workbenchLoadingScreen";
105 export const isWorkbenchLoading = (state: RootState) => {
106 const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
107 return progress ? progress.working : false;
110 export const handleFirstTimeLoad = (action: any) => async (dispatch: Dispatch<any>, getState: () => RootState) => {
112 await dispatch(action);
114 snackbarActions.OPEN_SNACKBAR({
115 message: "Error " + e,
117 kind: SnackbarKind.WARNING,
120 if (isWorkbenchLoading(getState())) {
121 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
126 export const loadWorkbench = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
127 dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
128 const { auth, router } = getState();
129 const { user } = auth;
131 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
132 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
134 allProcessesPanelActions.SET_COLUMNS({
135 columns: allProcessesPanelColumns,
139 publicFavoritePanelActions.SET_COLUMNS({
140 columns: publicFavoritePanelColumns,
143 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
144 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: sharedWithMePanelColumns }));
145 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
147 searchResultsPanelActions.SET_FETCH_MODE({
148 fetchMode: DataTableFetchMode.INFINITE,
152 searchResultsPanelActions.SET_COLUMNS({
153 columns: searchResultsPanelColumns,
156 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
158 groupPanelActions.GroupsPanelActions.SET_COLUMNS({
159 columns: groupsPanelColumns,
163 groupDetailsPanelActions.GroupMembersPanelActions.SET_COLUMNS({
164 columns: groupDetailsMembersPanelColumns,
168 groupDetailsPanelActions.GroupPermissionsPanelActions.SET_COLUMNS({
169 columns: groupDetailsPermissionsPanelColumns,
173 userProfilePanelActions.UserProfileGroupsActions.SET_COLUMNS({
174 columns: userProfileGroupsColumns,
177 dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
179 apiClientAuthorizationsActions.SET_COLUMNS({
180 columns: apiClientAuthorizationPanelColumns,
184 collectionsContentAddressActions.SET_COLUMNS({
185 columns: collectionContentAddressPanelColumns,
188 dispatch(subprocessPanelActions.SET_COLUMNS({ columns: subprocessPanelColumns }));
190 if (services.linkAccountService.getAccountToLink()) {
191 dispatch(linkAccountPanelActions.HAS_SESSION_DATA());
194 dispatch<any>(initSidePanelTree());
195 if (router.location) {
196 const match = matchRootRoute(router.location.pathname);
198 dispatch<any>(navigateToRootProject);
202 dispatch(userIsNotAuthenticated);
206 export const loadFavorites = () =>
207 handleFirstTimeLoad((dispatch: Dispatch) => {
208 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
209 dispatch<any>(loadFavoritePanel());
210 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
213 export const loadCollectionContentAddress = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
214 await dispatch(loadCollectionsContentAddressPanel());
217 export const loadTrash = () =>
218 handleFirstTimeLoad((dispatch: Dispatch) => {
219 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
220 dispatch<any>(loadTrashPanel());
221 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
224 export const loadAllProcesses = () =>
225 handleFirstTimeLoad((dispatch: Dispatch) => {
226 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.ALL_PROCESSES));
227 dispatch<any>(loadAllProcessesPanel());
228 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.ALL_PROCESSES));
231 export const loadProject = (uuid: string) =>
232 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
233 const userUuid = getUserUuid(getState());
234 dispatch(setIsProjectPanelTrashed(false));
239 dispatch(progressIndicatorActions.START_WORKING(uuid));
240 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
241 // Load another users home projects
242 dispatch(finishLoadingProject(uuid));
243 } else if (userUuid !== uuid) {
244 await dispatch(finishLoadingProject(uuid));
245 const match = await loadGroupContentsResource({
252 await dispatch(activateSidePanelTreeItem(uuid));
253 dispatch<any>(setSidePanelBreadcrumbs(uuid));
255 SHARED: async () => {
256 await dispatch(activateSidePanelTreeItem(uuid));
257 dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
259 TRASHED: async () => {
260 await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
261 dispatch<any>(setTrashBreadcrumbs(uuid));
262 dispatch(setIsProjectPanelTrashed(true));
266 await dispatch(finishLoadingProject(userUuid));
267 await dispatch(activateSidePanelTreeItem(userUuid));
268 dispatch<any>(setSidePanelBreadcrumbs(userUuid));
271 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
275 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) => async (dispatch: Dispatch) => {
276 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
279 snackbarActions.OPEN_SNACKBAR({
280 message: "Project has been successfully created.",
282 kind: SnackbarKind.SUCCESS,
285 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
286 dispatch<any>(navigateTo(newProject.uuid));
290 export const moveProject =
291 (data: MoveToFormDialogData, isSecondaryMove = false) =>
292 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
293 const checkedList = getState().multiselect.checkedList;
294 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
296 //if no items in checkedlist default to normal context menu behavior
297 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
299 const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
300 const destinationUuid = data.ownerUuid;
302 const projectsToMove: MoveableResource[] = uuidsToMove
303 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
304 .filter(resource => resource.kind === ResourceKind.PROJECT);
306 for (const project of projectsToMove) {
307 await moveSingleProject(project);
310 //omly propagate if this call is the original
311 if (!isSecondaryMove) {
312 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
313 kindsToMove.delete(ResourceKind.PROJECT);
315 kindsToMove.forEach(kind => {
316 secondaryMove[kind](data, true)(dispatch, getState, services);
320 async function moveSingleProject(project: MoveableResource) {
322 const oldProject: MoveToFormDialogData = { name: project.name, uuid: project.uuid, ownerUuid: data.ownerUuid };
323 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
324 const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
327 snackbarActions.OPEN_SNACKBAR({
328 message: "Project has been moved",
330 kind: SnackbarKind.SUCCESS,
333 await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
337 snackbarActions.OPEN_SNACKBAR({
338 message: !!(project as any).frozenByUuid ? 'Could not move frozen project.' : e.message,
340 kind: SnackbarKind.ERROR,
345 if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
346 await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
349 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
350 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
351 if (updatedProject) {
353 snackbarActions.OPEN_SNACKBAR({
354 message: "Project has been successfully updated.",
356 kind: SnackbarKind.SUCCESS,
359 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
360 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
364 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
365 const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
368 snackbarActions.OPEN_SNACKBAR({
369 message: "Group has been successfully updated.",
371 kind: SnackbarKind.SUCCESS,
374 await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
375 dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
379 export const loadCollection = (uuid: string) =>
380 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
381 const userUuid = getUserUuid(getState());
383 dispatch(progressIndicatorActions.START_WORKING(uuid));
385 const match = await loadGroupContentsResource({
390 let collection: CollectionResource | undefined;
392 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
394 let sidepanel: string | undefined;
396 OWNED: thecollection => {
397 collection = thecollection as CollectionResource;
398 sidepanel = collection.ownerUuid;
399 breadcrumbfunc = setSidePanelBreadcrumbs;
401 SHARED: thecollection => {
402 collection = thecollection as CollectionResource;
403 sidepanel = collection.ownerUuid;
404 breadcrumbfunc = setSharedWithMeBreadcrumbs;
406 TRASHED: thecollection => {
407 collection = thecollection as CollectionResource;
408 sidepanel = SidePanelTreeCategory.TRASH;
409 breadcrumbfunc = () => setTrashBreadcrumbs("");
412 if (collection && breadcrumbfunc && sidepanel) {
413 dispatch(updateResources([collection]));
414 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
415 dispatch(collectionPanelActions.SET_COLLECTION(collection));
416 await dispatch(activateSidePanelTreeItem(sidepanel));
417 dispatch(breadcrumbfunc(collection.ownerUuid));
418 dispatch(loadCollectionPanel(collection.uuid));
422 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
426 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
427 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
430 snackbarActions.OPEN_SNACKBAR({
431 message: "Collection has been successfully created.",
433 kind: SnackbarKind.SUCCESS,
436 dispatch<any>(updateResources([collection]));
437 dispatch<any>(navigateTo(collection.uuid));
441 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
442 const checkedList = getState().multiselect.checkedList;
443 const uuidsToCopy: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
445 //if no items in checkedlist && no items passed in, default to normal context menu behavior
446 if (!uuidsToCopy.length) uuidsToCopy.push(data.uuid);
448 const collectionsToCopy: CollectionCopyResource[] = uuidsToCopy
449 .map(uuid => getResource(uuid)(getState().resources) as CollectionCopyResource)
450 .filter(resource => resource.kind === ResourceKind.COLLECTION);
452 for (const collection of collectionsToCopy) {
453 await copySingleCollection({ ...collection, ownerUuid: data.ownerUuid } as CollectionCopyResource);
456 async function copySingleCollection(copyToProject: CollectionCopyResource) {
457 const newName = data.fromContextMenu || collectionsToCopy.length === 1 ? data.name : `Copy of: ${copyToProject.name}`;
459 const collection = await dispatch<any>(
460 collectionCopyActions.copyCollection({
463 fromContextMenu: collectionsToCopy.length === 1 ? true : data.fromContextMenu,
466 if (copyToProject && collection) {
467 await dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
469 snackbarActions.OPEN_SNACKBAR({
470 message: "Collection has been copied.",
472 kind: SnackbarKind.SUCCESS,
473 link: collection.ownerUuid,
476 dispatch<any>(multiselectActions.deselectOne(copyToProject.uuid));
480 snackbarActions.OPEN_SNACKBAR({
483 kind: SnackbarKind.ERROR,
488 dispatch(projectPanelActions.REQUEST_ITEMS());
491 export const moveCollection =
492 (data: MoveToFormDialogData, isSecondaryMove = false) =>
493 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
494 const checkedList = getState().multiselect.checkedList;
495 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
497 //if no items in checkedlist && no items passed in, default to normal context menu behavior
498 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
500 const collectionsToMove: MoveableResource[] = uuidsToMove
501 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
502 .filter(resource => resource.kind === ResourceKind.COLLECTION);
504 for (const collection of collectionsToMove) {
505 await moveSingleCollection(collection);
508 //omly propagate if this call is the original
509 if (!isSecondaryMove) {
510 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
511 kindsToMove.delete(ResourceKind.COLLECTION);
513 kindsToMove.forEach(kind => {
514 secondaryMove[kind](data, true)(dispatch, getState, services);
518 async function moveSingleCollection(collection: MoveableResource) {
520 const oldCollection: MoveToFormDialogData = { name: collection.name, uuid: collection.uuid, ownerUuid: data.ownerUuid };
521 const movedCollection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
522 dispatch<any>(updateResources([movedCollection]));
523 dispatch<any>(reloadProjectMatchingUuid([movedCollection.ownerUuid]));
525 snackbarActions.OPEN_SNACKBAR({
526 message: "Collection has been moved.",
528 kind: SnackbarKind.SUCCESS,
533 snackbarActions.OPEN_SNACKBAR({
536 kind: SnackbarKind.ERROR,
543 export const loadProcess = (uuid: string) =>
544 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
546 dispatch(progressIndicatorActions.START_WORKING(uuid));
547 dispatch<any>(loadProcessPanel(uuid));
548 const process = await dispatch<any>(processesActions.loadProcess(uuid));
550 await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
551 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
552 dispatch<any>(setProcessBreadcrumbs(uuid));
553 dispatch<any>(loadDetailsPanel(uuid));
556 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
560 export const loadRegisteredWorkflow = (uuid: string) =>
561 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
562 const userUuid = getUserUuid(getState());
564 const match = await loadGroupContentsResource({
569 let workflow: WorkflowResource | undefined;
571 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
574 OWNED: async theworkflow => {
575 workflow = theworkflow as WorkflowResource;
576 breadcrumbfunc = setSidePanelBreadcrumbs;
578 SHARED: async theworkflow => {
579 workflow = theworkflow as WorkflowResource;
580 breadcrumbfunc = setSharedWithMeBreadcrumbs;
584 if (workflow && breadcrumbfunc) {
585 dispatch(updateResources([workflow]));
586 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
587 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
588 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
593 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
595 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
598 snackbarActions.OPEN_SNACKBAR({
599 message: "Process has been successfully updated.",
601 kind: SnackbarKind.SUCCESS,
604 dispatch<any>(updateResources([process]));
605 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
609 snackbarActions.OPEN_SNACKBAR({
612 kind: SnackbarKind.ERROR,
618 export const moveProcess =
619 (data: MoveToFormDialogData, isSecondaryMove = false) =>
620 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
621 const checkedList = getState().multiselect.checkedList;
622 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
624 //if no items in checkedlist && no items passed in, default to normal context menu behavior
625 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
627 const processesToMove: MoveableResource[] = uuidsToMove
628 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
629 .filter(resource => resource.kind === ResourceKind.PROCESS);
631 for (const process of processesToMove) {
632 await moveSingleProcess(process);
635 //omly propagate if this call is the original
636 if (!isSecondaryMove) {
637 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
638 kindsToMove.delete(ResourceKind.PROCESS);
640 kindsToMove.forEach(kind => {
641 secondaryMove[kind](data, true)(dispatch, getState, services);
645 async function moveSingleProcess(process: MoveableResource) {
647 const oldProcess: MoveToFormDialogData = { name: process.name, uuid: process.uuid, ownerUuid: data.ownerUuid };
648 const movedProcess = await dispatch<any>(processMoveActions.moveProcess(oldProcess));
649 dispatch<any>(updateResources([movedProcess]));
650 dispatch<any>(reloadProjectMatchingUuid([movedProcess.ownerUuid]));
652 snackbarActions.OPEN_SNACKBAR({
653 message: "Process has been moved.",
655 kind: SnackbarKind.SUCCESS,
660 snackbarActions.OPEN_SNACKBAR({
663 kind: SnackbarKind.ERROR,
670 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
672 const process = await dispatch<any>(processCopyActions.copyProcess(data));
673 dispatch<any>(updateResources([process]));
674 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
676 snackbarActions.OPEN_SNACKBAR({
677 message: "Process has been copied.",
679 kind: SnackbarKind.SUCCESS,
682 dispatch<any>(navigateTo(process.uuid));
685 snackbarActions.OPEN_SNACKBAR({
688 kind: SnackbarKind.ERROR,
694 export const resourceIsNotLoaded = (uuid: string) =>
695 snackbarActions.OPEN_SNACKBAR({
696 message: `Resource identified by ${uuid} is not loaded.`,
697 kind: SnackbarKind.ERROR,
700 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
701 message: "User is not authenticated",
702 kind: SnackbarKind.ERROR,
705 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
706 message: "Could not load user",
707 kind: SnackbarKind.ERROR,
710 export const reloadProjectMatchingUuid =
711 (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
712 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
713 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
714 dispatch<any>(loadProject(currentProjectPanelUuid));
718 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
719 dispatch<any>(loadSharedWithMePanel());
720 await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
721 await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
724 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
725 await dispatch<any>(loadRunProcessPanel());
728 export const loadPublicFavorites = () =>
729 handleFirstTimeLoad((dispatch: Dispatch) => {
730 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
731 dispatch<any>(loadPublicFavoritePanel());
732 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
735 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
736 await dispatch(loadSearchResultsPanel());
739 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
740 await dispatch(loadLinkPanel());
743 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
744 await dispatch(loadVirtualMachinesPanel());
745 dispatch(setBreadcrumbs([{ label: "Virtual Machines" }]));
748 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
749 await dispatch(loadVirtualMachinesPanel());
750 dispatch(setBreadcrumbs([{ label: "Virtual Machines Admin", icon: AdminMenuIcon }]));
753 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
754 await dispatch(loadRepositoriesPanel());
755 dispatch(setBreadcrumbs([{ label: "Repositories" }]));
758 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
759 await dispatch(loadSshKeysPanel());
762 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
763 await dispatch(loadSiteManagerPanel());
766 export const loadUserProfile = (userUuid?: string) =>
767 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
769 dispatch(setUserProfileBreadcrumbs(userUuid));
770 dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
772 dispatch(setMyAccountBreadcrumbs());
773 dispatch(userProfilePanelActions.loadUserProfilePanel());
777 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
778 dispatch(loadLinkAccountPanel());
781 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
782 await dispatch(loadKeepServicesPanel());
785 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
786 await dispatch(loadUsersPanel());
787 dispatch(setUsersBreadcrumbs());
790 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
791 await dispatch(loadApiClientAuthorizationsPanel());
794 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
795 dispatch(setGroupsBreadcrumbs());
796 dispatch(groupPanelActions.loadGroupsPanel());
799 export const loadGroupDetailsPanel = (groupUuid: string) =>
800 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
801 dispatch(setGroupDetailsBreadcrumbs(groupUuid));
802 dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
805 const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
806 const uuid = typeof project === "string" ? project : project.uuid;
807 dispatch(loadDetailsPanel(uuid));
808 if (typeof project !== "string") {
809 dispatch(updateResources([project]));
813 const loadGroupContentsResource = async (params: { uuid: string; userUuid: string; services: ServiceRepository }) => {
814 const filters = new FilterBuilder().addEqual("uuid", params.uuid).getFilters();
815 const { items } = await params.services.groupsService.contents(params.userUuid, {
820 const resource = items.shift();
821 let handler: GroupContentsHandler;
824 (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
825 ? groupContentsHandlers.TRASHED(resource)
826 : groupContentsHandlers.OWNED(resource);
828 const kind = extractUuidKind(params.uuid);
829 let resource: GroupContentsResource;
830 if (kind === ResourceKind.COLLECTION) {
831 resource = await params.services.collectionService.get(params.uuid);
832 } else if (kind === ResourceKind.PROJECT) {
833 resource = await params.services.projectService.get(params.uuid);
834 } else if (kind === ResourceKind.WORKFLOW) {
835 resource = await params.services.workflowService.get(params.uuid);
836 } else if (kind === ResourceKind.CONTAINER_REQUEST) {
837 resource = await params.services.containerRequestService.get(params.uuid);
839 throw new Error("loadGroupContentsResource unsupported kind " + kind);
841 handler = groupContentsHandlers.SHARED(resource);
843 return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) => groupContentsHandlers.match(handler, cases);
846 const groupContentsHandlersRecord = {
847 TRASHED: ofType<GroupContentsResource>(),
848 SHARED: ofType<GroupContentsResource>(),
849 OWNED: ofType<GroupContentsResource>(),
852 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
854 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;
856 type CollectionCopyResource = Resource & { name: string; fromContextMenu: boolean };
858 type MoveableResource = Resource & { name: string };
861 data: MoveToFormDialogData,
862 isSecondaryMove?: boolean
863 ) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>;
865 const secondaryMove: Record<string, MoveFunc> = {
866 [ResourceKind.PROJECT]: moveProject,
867 [ResourceKind.PROCESS]: moveProcess,
868 [ResourceKind.COLLECTION]: moveCollection,