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,
19 } from "store/side-panel-tree/side-panel-tree-actions";
20 import { updateResources } from "store/resources/resources-actions";
21 import { projectPanelColumns } from "views/project-panel/project-panel";
22 import { favoritePanelColumns } from "views/favorite-panel/favorite-panel";
23 import { matchRootRoute } from "routes/routes";
25 setGroupDetailsBreadcrumbs,
27 setProcessBreadcrumbs,
28 setSharedWithMeBreadcrumbs,
29 setSidePanelBreadcrumbs,
32 setMyAccountBreadcrumbs,
33 setUserProfileBreadcrumbs,
34 setInstanceTypesBreadcrumbs,
35 setVirtualMachinesBreadcrumbs,
36 setVirtualMachinesAdminBreadcrumbs,
37 setRepositoriesBreadcrumbs,
38 } from "store/breadcrumbs/breadcrumbs-actions";
39 import { navigateTo, navigateToRootProject } from "store/navigation/navigation-action";
40 import { MoveToFormDialogData } from "store/move-to-dialog/move-to-dialog";
41 import { ServiceRepository } from "services/services";
42 import { getResource } from "store/resources/resources";
43 import * as projectCreateActions from "store/projects/project-create-actions";
44 import * as projectMoveActions from "store/projects/project-move-actions";
45 import * as projectUpdateActions from "store/projects/project-update-actions";
46 import * as collectionCreateActions from "store/collections/collection-create-actions";
47 import * as collectionCopyActions from "store/collections/collection-copy-actions";
48 import * as collectionMoveActions from "store/collections/collection-move-actions";
49 import * as processesActions from "store/processes/processes-actions";
50 import * as processMoveActions from "store/processes/process-move-actions";
51 import * as processUpdateActions from "store/processes/process-update-actions";
52 import * as processCopyActions from "store/processes/process-copy-actions";
53 import { trashPanelColumns } from "views/trash-panel/trash-panel";
54 import { loadTrashPanel, trashPanelActions } from "store/trash-panel/trash-panel-action";
55 import { loadProcessPanel } from "store/process-panel/process-panel-actions";
56 import { loadSharedWithMePanel, sharedWithMePanelActions } from "store/shared-with-me-panel/shared-with-me-panel-actions";
57 import { sharedWithMePanelColumns } from "views/shared-with-me-panel/shared-with-me-panel";
58 import { CopyFormDialogData } from "store/copy-dialog/copy-dialog";
59 import { workflowPanelActions } from "store/workflow-panel/workflow-panel-actions";
60 import { loadSshKeysPanel } from "store/auth/auth-action-ssh";
61 import { loadLinkAccountPanel, linkAccountPanelActions } from "store/link-account-panel/link-account-panel-actions";
62 import { loadSiteManagerPanel } from "store/auth/auth-action-session";
63 import { workflowPanelColumns } from "views/workflow-panel/workflow-panel-view";
64 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
65 import { getProgressIndicator } from "store/progress-indicator/progress-indicator-reducer";
66 import { extractUuidKind, Resource, ResourceKind } from "models/resource";
67 import { FilterBuilder } from "services/api/filter-builder";
68 import { GroupContentsResource } from "services/groups-service/groups-service";
69 import { MatchCases, ofType, unionize, UnionOf } from "common/unionize";
70 import { loadRunProcessPanel } from "store/run-process-panel/run-process-panel-actions";
71 import { collectionPanelActions, loadCollectionPanel } from "store/collection-panel/collection-panel-action";
72 import { CollectionResource } from "models/collection";
73 import { WorkflowResource } from "models/workflow";
74 import { loadSearchResultsPanel, searchResultsPanelActions } from "store/search-results-panel/search-results-panel-actions";
75 import { searchResultsPanelColumns } from "views/search-results-panel/search-results-panel-view";
76 import { loadVirtualMachinesPanel } from "store/virtual-machines/virtual-machines-actions";
77 import { loadRepositoriesPanel } from "store/repositories/repositories-actions";
78 import { loadKeepServicesPanel } from "store/keep-services/keep-services-actions";
79 import { loadUsersPanel, userBindedActions } from "store/users/users-actions";
80 import * as userProfilePanelActions from "store/user-profile/user-profile-actions";
81 import { linkPanelActions, loadLinkPanel } from "store/link-panel/link-panel-actions";
82 import { linkPanelColumns } from "views/link-panel/link-panel-root";
83 import { userPanelColumns } from "views/user-panel/user-panel";
84 import { loadApiClientAuthorizationsPanel, apiClientAuthorizationsActions } from "store/api-client-authorizations/api-client-authorizations-actions";
85 import { apiClientAuthorizationPanelColumns } from "views/api-client-authorization-panel/api-client-authorization-panel-root";
86 import * as groupPanelActions from "store/groups-panel/groups-panel-actions";
87 import { groupsPanelColumns } from "views/groups-panel/groups-panel";
88 import * as groupDetailsPanelActions from "store/group-details-panel/group-details-panel-actions";
89 import { groupDetailsMembersPanelColumns, groupDetailsPermissionsPanelColumns } from "views/group-details-panel/group-details-panel";
90 import { DataTableFetchMode } from "components/data-table/data-table";
91 import { loadPublicFavoritePanel, publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
92 import { publicFavoritePanelColumns } from "views/public-favorites-panel/public-favorites-panel";
94 loadCollectionsContentAddressPanel,
95 collectionsContentAddressActions,
96 } from "store/collections-content-address-panel/collections-content-address-panel-actions";
97 import { collectionContentAddressPanelColumns } from "views/collection-content-address-panel/collection-content-address-panel";
98 import { subprocessPanelActions } from "store/subprocess-panel/subprocess-panel-actions";
99 import { subprocessPanelColumns } from "views/subprocess-panel/subprocess-panel-root";
100 import { loadAllProcessesPanel, allProcessesPanelActions } from "../all-processes-panel/all-processes-panel-action";
101 import { allProcessesPanelColumns } from "views/all-processes-panel/all-processes-panel";
102 import { userProfileGroupsColumns } from "views/user-profile-panel/user-profile-panel-root";
103 import { selectedToArray, selectedToKindSet } from "components/multiselect-toolbar/MultiselectToolbar";
104 import { deselectOne } from "store/multiselect/multiselect-actions";
105 import { treePickerActions } from "store/tree-picker/tree-picker-actions";
106 import { workflowProcessesPanelColumns } from "views/workflow-panel/workflow-processes-panel-root";
107 import { workflowProcessesPanelActions } from "store/workflow-panel/workflow-panel-actions";
109 export const WORKBENCH_LOADING_SCREEN = "workbenchLoadingScreen";
111 export const isWorkbenchLoading = (state: RootState) => {
112 const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
113 return progress ? progress.working : false;
116 export const handleFirstTimeLoad = (action: any) => async (dispatch: Dispatch<any>, getState: () => RootState) => {
118 await dispatch(action);
120 snackbarActions.OPEN_SNACKBAR({
121 message: "Error " + e,
123 kind: SnackbarKind.WARNING,
126 if (isWorkbenchLoading(getState())) {
127 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
132 export const loadWorkbench = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
133 dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
134 const { auth, router } = getState();
135 const { user } = auth;
137 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
138 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
140 allProcessesPanelActions.SET_COLUMNS({
141 columns: allProcessesPanelColumns,
145 publicFavoritePanelActions.SET_COLUMNS({
146 columns: publicFavoritePanelColumns,
149 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
150 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: sharedWithMePanelColumns }));
151 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
153 searchResultsPanelActions.SET_FETCH_MODE({
154 fetchMode: DataTableFetchMode.INFINITE,
158 searchResultsPanelActions.SET_COLUMNS({
159 columns: searchResultsPanelColumns,
162 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
164 groupPanelActions.GroupsPanelActions.SET_COLUMNS({
165 columns: groupsPanelColumns,
169 groupDetailsPanelActions.GroupMembersPanelActions.SET_COLUMNS({
170 columns: groupDetailsMembersPanelColumns,
174 groupDetailsPanelActions.GroupPermissionsPanelActions.SET_COLUMNS({
175 columns: groupDetailsPermissionsPanelColumns,
179 userProfilePanelActions.UserProfileGroupsActions.SET_COLUMNS({
180 columns: userProfileGroupsColumns,
183 dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
185 apiClientAuthorizationsActions.SET_COLUMNS({
186 columns: apiClientAuthorizationPanelColumns,
190 collectionsContentAddressActions.SET_COLUMNS({
191 columns: collectionContentAddressPanelColumns,
194 dispatch(subprocessPanelActions.SET_COLUMNS({ columns: subprocessPanelColumns }));
195 dispatch(workflowProcessesPanelActions.SET_COLUMNS({ columns: workflowProcessesPanelColumns }));
197 if (services.linkAccountService.getAccountToLink()) {
198 dispatch(linkAccountPanelActions.HAS_SESSION_DATA());
201 dispatch<any>(initSidePanelTree());
202 if (router.location) {
203 const match = matchRootRoute(router.location.pathname);
205 dispatch<any>(navigateToRootProject);
209 dispatch(userIsNotAuthenticated);
213 export const loadFavorites = () =>
214 handleFirstTimeLoad((dispatch: Dispatch) => {
215 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
216 dispatch<any>(loadFavoritePanel());
217 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
220 export const loadCollectionContentAddress = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
221 await dispatch(loadCollectionsContentAddressPanel());
224 export const loadTrash = () =>
225 handleFirstTimeLoad((dispatch: Dispatch) => {
226 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
227 dispatch<any>(loadTrashPanel());
228 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
231 export const loadAllProcesses = () =>
232 handleFirstTimeLoad((dispatch: Dispatch) => {
233 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.ALL_PROCESSES));
234 dispatch<any>(loadAllProcessesPanel());
235 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.ALL_PROCESSES));
238 export const loadProject = (uuid: string) =>
239 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
240 const userUuid = getUserUuid(getState());
241 dispatch(setIsProjectPanelTrashed(false));
246 dispatch(progressIndicatorActions.START_WORKING(uuid));
247 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
248 // Load another users home projects
249 dispatch(finishLoadingProject(uuid));
250 } else if (userUuid !== uuid) {
251 await dispatch(finishLoadingProject(uuid));
252 const match = await loadGroupContentsResource({
259 await dispatch(activateSidePanelTreeItem(uuid));
260 dispatch<any>(setSidePanelBreadcrumbs(uuid));
262 SHARED: async () => {
263 await dispatch(activateSidePanelTreeItem(uuid));
264 dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
266 TRASHED: async () => {
267 await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
268 dispatch<any>(setTrashBreadcrumbs(uuid));
269 dispatch(setIsProjectPanelTrashed(true));
273 await dispatch(finishLoadingProject(userUuid));
274 await dispatch(activateSidePanelTreeItem(userUuid));
275 dispatch<any>(setSidePanelBreadcrumbs(userUuid));
278 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
282 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) => async (dispatch: Dispatch) => {
283 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
286 snackbarActions.OPEN_SNACKBAR({
287 message: "Project has been successfully created.",
289 kind: SnackbarKind.SUCCESS,
292 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
293 dispatch<any>(navigateTo(newProject.uuid));
297 export const moveProject =
298 (data: MoveToFormDialogData, isSecondaryMove = false) =>
299 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
300 const checkedList = getState().multiselect.checkedList;
301 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
303 //if no items in checkedlist default to normal context menu behavior
304 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
306 const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
307 const destinationUuid = data.ownerUuid;
309 const projectsToMove: MoveableResource[] = uuidsToMove
310 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
311 .filter(resource => resource.kind === ResourceKind.PROJECT);
313 for (const project of projectsToMove) {
314 await moveSingleProject(project);
317 //omly propagate if this call is the original
318 if (!isSecondaryMove) {
319 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
320 kindsToMove.delete(ResourceKind.PROJECT);
322 kindsToMove.forEach(kind => {
323 secondaryMove[kind](data, true)(dispatch, getState, services);
327 async function moveSingleProject(project: MoveableResource) {
329 const oldProject: MoveToFormDialogData = { name: project.name, uuid: project.uuid, ownerUuid: data.ownerUuid };
330 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
331 const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
334 snackbarActions.OPEN_SNACKBAR({
335 message: "Project has been moved",
337 kind: SnackbarKind.SUCCESS,
340 await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
344 snackbarActions.OPEN_SNACKBAR({
345 message: !!(project as any).frozenByUuid ? 'Could not move frozen project.' : e.message,
347 kind: SnackbarKind.ERROR,
352 if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
353 await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
356 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
357 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
358 if (updatedProject) {
360 snackbarActions.OPEN_SNACKBAR({
361 message: "Project has been successfully updated.",
363 kind: SnackbarKind.SUCCESS,
366 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
367 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
371 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
372 const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
375 snackbarActions.OPEN_SNACKBAR({
376 message: "Group has been successfully updated.",
378 kind: SnackbarKind.SUCCESS,
381 await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
382 dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
386 export const loadCollection = (uuid: string) =>
387 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
388 const userUuid = getUserUuid(getState());
390 dispatch(progressIndicatorActions.START_WORKING(uuid));
392 const match = await loadGroupContentsResource({
397 let collection: CollectionResource | undefined;
399 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
401 let sidepanel: string | undefined;
403 OWNED: thecollection => {
404 collection = thecollection as CollectionResource;
405 sidepanel = collection.ownerUuid;
406 breadcrumbfunc = setSidePanelBreadcrumbs;
408 SHARED: thecollection => {
409 collection = thecollection as CollectionResource;
410 sidepanel = collection.ownerUuid;
411 breadcrumbfunc = setSharedWithMeBreadcrumbs;
413 TRASHED: thecollection => {
414 collection = thecollection as CollectionResource;
415 sidepanel = SidePanelTreeCategory.TRASH;
416 breadcrumbfunc = () => setTrashBreadcrumbs("");
419 if (collection && breadcrumbfunc && sidepanel) {
420 dispatch(updateResources([collection]));
421 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
422 dispatch(collectionPanelActions.SET_COLLECTION(collection));
423 await dispatch(activateSidePanelTreeItem(sidepanel));
424 dispatch(breadcrumbfunc(collection.ownerUuid));
425 dispatch(loadCollectionPanel(collection.uuid));
429 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
433 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
434 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
437 snackbarActions.OPEN_SNACKBAR({
438 message: "Collection has been successfully created.",
440 kind: SnackbarKind.SUCCESS,
443 dispatch<any>(updateResources([collection]));
444 dispatch<any>(navigateTo(collection.uuid));
448 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
449 const checkedList = getState().multiselect.checkedList;
450 const uuidsToCopy: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
452 //if no items in checkedlist && no items passed in, default to normal context menu behavior
453 if (!uuidsToCopy.length) uuidsToCopy.push(data.uuid);
455 const collectionsToCopy: CollectionCopyResource[] = uuidsToCopy
456 .map(uuid => getResource(uuid)(getState().resources) as CollectionCopyResource)
457 .filter(resource => resource.kind === ResourceKind.COLLECTION);
459 for (const collection of collectionsToCopy) {
460 await copySingleCollection({ ...collection, ownerUuid: data.ownerUuid } as CollectionCopyResource);
463 async function copySingleCollection(copyToProject: CollectionCopyResource) {
464 const newName = data.fromContextMenu || collectionsToCopy.length === 1 ? data.name : `Copy of: ${copyToProject.name}`;
466 const collection = await dispatch<any>(
467 collectionCopyActions.copyCollection({
470 fromContextMenu: collectionsToCopy.length === 1 ? true : data.fromContextMenu,
473 if (copyToProject && collection) {
474 await dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
476 snackbarActions.OPEN_SNACKBAR({
477 message: "Collection has been copied.",
479 kind: SnackbarKind.SUCCESS,
480 link: collection.ownerUuid,
483 dispatch<any>(deselectOne(copyToProject.uuid));
487 snackbarActions.OPEN_SNACKBAR({
490 kind: SnackbarKind.ERROR,
495 dispatch(projectPanelActions.REQUEST_ITEMS());
498 export const moveCollection =
499 (data: MoveToFormDialogData, isSecondaryMove = false) =>
500 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
501 const checkedList = getState().multiselect.checkedList;
502 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
504 //if no items in checkedlist && no items passed in, default to normal context menu behavior
505 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
507 const collectionsToMove: MoveableResource[] = uuidsToMove
508 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
509 .filter(resource => resource.kind === ResourceKind.COLLECTION);
511 for (const collection of collectionsToMove) {
512 await moveSingleCollection(collection);
515 //omly propagate if this call is the original
516 if (!isSecondaryMove) {
517 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
518 kindsToMove.delete(ResourceKind.COLLECTION);
520 kindsToMove.forEach(kind => {
521 secondaryMove[kind](data, true)(dispatch, getState, services);
525 async function moveSingleCollection(collection: MoveableResource) {
527 const oldCollection: MoveToFormDialogData = { name: collection.name, uuid: collection.uuid, ownerUuid: data.ownerUuid };
528 const movedCollection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
529 dispatch<any>(updateResources([movedCollection]));
530 dispatch<any>(reloadProjectMatchingUuid([movedCollection.ownerUuid]));
532 snackbarActions.OPEN_SNACKBAR({
533 message: "Collection has been moved.",
535 kind: SnackbarKind.SUCCESS,
540 snackbarActions.OPEN_SNACKBAR({
543 kind: SnackbarKind.ERROR,
550 export const loadProcess = (uuid: string) =>
551 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
553 dispatch(progressIndicatorActions.START_WORKING(uuid));
554 dispatch<any>(loadProcessPanel(uuid));
555 const process = await dispatch<any>(processesActions.loadProcess(uuid));
557 await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
558 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
559 dispatch<any>(setProcessBreadcrumbs(uuid));
560 dispatch<any>(loadDetailsPanel(uuid));
563 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
567 export const loadRegisteredWorkflow = (uuid: string) =>
568 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
569 const userUuid = getUserUuid(getState());
571 const match = await loadGroupContentsResource({
576 let workflow: WorkflowResource | undefined;
578 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
581 OWNED: async theworkflow => {
582 workflow = theworkflow as WorkflowResource;
583 breadcrumbfunc = setSidePanelBreadcrumbs;
585 SHARED: async theworkflow => {
586 workflow = theworkflow as WorkflowResource;
587 breadcrumbfunc = setSharedWithMeBreadcrumbs;
591 if (workflow && breadcrumbfunc) {
592 dispatch(updateResources([workflow]));
593 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
594 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
595 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
596 dispatch(workflowProcessesPanelActions.REQUEST_ITEMS());
601 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
603 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
606 snackbarActions.OPEN_SNACKBAR({
607 message: "Process has been successfully updated.",
609 kind: SnackbarKind.SUCCESS,
612 dispatch<any>(updateResources([process]));
613 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
617 snackbarActions.OPEN_SNACKBAR({
620 kind: SnackbarKind.ERROR,
626 export const moveProcess =
627 (data: MoveToFormDialogData, isSecondaryMove = false) =>
628 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
629 const checkedList = getState().multiselect.checkedList;
630 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
632 //if no items in checkedlist && no items passed in, default to normal context menu behavior
633 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
635 const processesToMove: MoveableResource[] = uuidsToMove
636 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
637 .filter(resource => resource.kind === ResourceKind.PROCESS);
639 for (const process of processesToMove) {
640 await moveSingleProcess(process);
643 //omly propagate if this call is the original
644 if (!isSecondaryMove) {
645 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
646 kindsToMove.delete(ResourceKind.PROCESS);
648 kindsToMove.forEach(kind => {
649 secondaryMove[kind](data, true)(dispatch, getState, services);
653 async function moveSingleProcess(process: MoveableResource) {
655 const oldProcess: MoveToFormDialogData = { name: process.name, uuid: process.uuid, ownerUuid: data.ownerUuid };
656 const movedProcess = await dispatch<any>(processMoveActions.moveProcess(oldProcess));
657 dispatch<any>(updateResources([movedProcess]));
658 dispatch<any>(reloadProjectMatchingUuid([movedProcess.ownerUuid]));
660 snackbarActions.OPEN_SNACKBAR({
661 message: "Process has been moved.",
663 kind: SnackbarKind.SUCCESS,
668 snackbarActions.OPEN_SNACKBAR({
671 kind: SnackbarKind.ERROR,
678 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
680 const process = await dispatch<any>(processCopyActions.copyProcess(data));
681 dispatch<any>(updateResources([process]));
682 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
684 snackbarActions.OPEN_SNACKBAR({
685 message: "Process has been copied.",
687 kind: SnackbarKind.SUCCESS,
690 dispatch<any>(navigateTo(process.uuid));
693 snackbarActions.OPEN_SNACKBAR({
696 kind: SnackbarKind.ERROR,
702 export const resourceIsNotLoaded = (uuid: string) =>
703 snackbarActions.OPEN_SNACKBAR({
704 message: `Resource identified by ${uuid} is not loaded.`,
705 kind: SnackbarKind.ERROR,
708 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
709 message: "User is not authenticated",
710 kind: SnackbarKind.ERROR,
713 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
714 message: "Could not load user",
715 kind: SnackbarKind.ERROR,
718 export const reloadProjectMatchingUuid =
719 (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
720 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
721 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
722 dispatch<any>(loadProject(currentProjectPanelUuid));
726 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
727 dispatch<any>(loadSharedWithMePanel());
728 await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
729 await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
732 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
733 await dispatch<any>(loadRunProcessPanel());
736 export const loadPublicFavorites = () =>
737 handleFirstTimeLoad((dispatch: Dispatch) => {
738 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
739 dispatch<any>(loadPublicFavoritePanel());
740 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
743 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
744 await dispatch(loadSearchResultsPanel());
747 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
748 await dispatch(loadLinkPanel());
751 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
752 await dispatch(loadVirtualMachinesPanel());
753 dispatch(setVirtualMachinesBreadcrumbs());
754 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHELL_ACCESS));
757 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
758 await dispatch(loadVirtualMachinesPanel());
759 dispatch(setVirtualMachinesAdminBreadcrumbs());
760 dispatch(treePickerActions.DEACTIVATE_TREE_PICKER_NODE({ pickerId: SIDE_PANEL_TREE }))
763 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
764 await dispatch(loadRepositoriesPanel());
765 dispatch(setRepositoriesBreadcrumbs());
768 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
769 await dispatch(loadSshKeysPanel());
772 export const loadInstanceTypes = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
773 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.INSTANCE_TYPES));
774 dispatch(setInstanceTypesBreadcrumbs());
777 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
778 await dispatch(loadSiteManagerPanel());
781 export const loadUserProfile = (userUuid?: string) =>
782 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
784 dispatch(setUserProfileBreadcrumbs(userUuid));
785 dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
787 dispatch(setMyAccountBreadcrumbs());
788 dispatch(userProfilePanelActions.loadUserProfilePanel());
792 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
793 dispatch(loadLinkAccountPanel());
796 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
797 await dispatch(loadKeepServicesPanel());
800 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
801 await dispatch(loadUsersPanel());
802 dispatch(setUsersBreadcrumbs());
805 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
806 await dispatch(loadApiClientAuthorizationsPanel());
809 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
810 dispatch(setGroupsBreadcrumbs());
811 dispatch(groupPanelActions.loadGroupsPanel());
814 export const loadGroupDetailsPanel = (groupUuid: string) =>
815 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
816 dispatch(setGroupDetailsBreadcrumbs(groupUuid));
817 dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
820 const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
821 const uuid = typeof project === "string" ? project : project.uuid;
822 dispatch(loadDetailsPanel(uuid));
823 if (typeof project !== "string") {
824 dispatch(updateResources([project]));
828 const loadGroupContentsResource = async (params: { uuid: string; userUuid: string; services: ServiceRepository }) => {
829 const filters = new FilterBuilder().addEqual("uuid", params.uuid).getFilters();
830 const { items } = await params.services.groupsService.contents(params.userUuid, {
835 const resource = items.shift();
836 let handler: GroupContentsHandler;
839 (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
840 ? groupContentsHandlers.TRASHED(resource)
841 : groupContentsHandlers.OWNED(resource);
843 const kind = extractUuidKind(params.uuid);
844 let resource: GroupContentsResource;
845 if (kind === ResourceKind.COLLECTION) {
846 resource = await params.services.collectionService.get(params.uuid);
847 } else if (kind === ResourceKind.PROJECT) {
848 resource = await params.services.projectService.get(params.uuid);
849 } else if (kind === ResourceKind.WORKFLOW) {
850 resource = await params.services.workflowService.get(params.uuid);
851 } else if (kind === ResourceKind.CONTAINER_REQUEST) {
852 resource = await params.services.containerRequestService.get(params.uuid);
854 throw new Error("loadGroupContentsResource unsupported kind " + kind);
856 handler = groupContentsHandlers.SHARED(resource);
858 return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) => groupContentsHandlers.match(handler, cases);
861 const groupContentsHandlersRecord = {
862 TRASHED: ofType<GroupContentsResource>(),
863 SHARED: ofType<GroupContentsResource>(),
864 OWNED: ofType<GroupContentsResource>(),
867 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
869 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;
871 type CollectionCopyResource = Resource & { name: string; fromContextMenu: boolean };
873 type MoveableResource = Resource & { name: string };
876 data: MoveToFormDialogData,
877 isSecondaryMove?: boolean
878 ) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>;
880 const secondaryMove: Record<string, MoveFunc> = {
881 [ResourceKind.PROJECT]: moveProject,
882 [ResourceKind.PROCESS]: moveProcess,
883 [ResourceKind.COLLECTION]: moveCollection,