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 { multiselectActions } from "store/multiselect/multiselect-actions";
105 import { treePickerActions } from "store/tree-picker/tree-picker-actions";
107 export const WORKBENCH_LOADING_SCREEN = "workbenchLoadingScreen";
109 export const isWorkbenchLoading = (state: RootState) => {
110 const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
111 return progress ? progress.working : false;
114 export const handleFirstTimeLoad = (action: any) => async (dispatch: Dispatch<any>, getState: () => RootState) => {
116 await dispatch(action);
118 snackbarActions.OPEN_SNACKBAR({
119 message: "Error " + e,
121 kind: SnackbarKind.WARNING,
124 if (isWorkbenchLoading(getState())) {
125 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
130 export const loadWorkbench = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
131 dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
132 const { auth, router } = getState();
133 const { user } = auth;
135 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
136 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
138 allProcessesPanelActions.SET_COLUMNS({
139 columns: allProcessesPanelColumns,
143 publicFavoritePanelActions.SET_COLUMNS({
144 columns: publicFavoritePanelColumns,
147 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
148 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: sharedWithMePanelColumns }));
149 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
151 searchResultsPanelActions.SET_FETCH_MODE({
152 fetchMode: DataTableFetchMode.INFINITE,
156 searchResultsPanelActions.SET_COLUMNS({
157 columns: searchResultsPanelColumns,
160 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
162 groupPanelActions.GroupsPanelActions.SET_COLUMNS({
163 columns: groupsPanelColumns,
167 groupDetailsPanelActions.GroupMembersPanelActions.SET_COLUMNS({
168 columns: groupDetailsMembersPanelColumns,
172 groupDetailsPanelActions.GroupPermissionsPanelActions.SET_COLUMNS({
173 columns: groupDetailsPermissionsPanelColumns,
177 userProfilePanelActions.UserProfileGroupsActions.SET_COLUMNS({
178 columns: userProfileGroupsColumns,
181 dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
183 apiClientAuthorizationsActions.SET_COLUMNS({
184 columns: apiClientAuthorizationPanelColumns,
188 collectionsContentAddressActions.SET_COLUMNS({
189 columns: collectionContentAddressPanelColumns,
192 dispatch(subprocessPanelActions.SET_COLUMNS({ columns: subprocessPanelColumns }));
194 if (services.linkAccountService.getAccountToLink()) {
195 dispatch(linkAccountPanelActions.HAS_SESSION_DATA());
198 dispatch<any>(initSidePanelTree());
199 if (router.location) {
200 const match = matchRootRoute(router.location.pathname);
202 dispatch<any>(navigateToRootProject);
206 dispatch(userIsNotAuthenticated);
210 export const loadFavorites = () =>
211 handleFirstTimeLoad((dispatch: Dispatch) => {
212 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
213 dispatch<any>(loadFavoritePanel());
214 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
217 export const loadCollectionContentAddress = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
218 await dispatch(loadCollectionsContentAddressPanel());
221 export const loadTrash = () =>
222 handleFirstTimeLoad((dispatch: Dispatch) => {
223 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
224 dispatch<any>(loadTrashPanel());
225 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
228 export const loadAllProcesses = () =>
229 handleFirstTimeLoad((dispatch: Dispatch) => {
230 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.ALL_PROCESSES));
231 dispatch<any>(loadAllProcessesPanel());
232 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.ALL_PROCESSES));
235 export const loadProject = (uuid: string) =>
236 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
237 const userUuid = getUserUuid(getState());
238 dispatch(setIsProjectPanelTrashed(false));
243 dispatch(progressIndicatorActions.START_WORKING(uuid));
244 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
245 // Load another users home projects
246 dispatch(finishLoadingProject(uuid));
247 } else if (userUuid !== uuid) {
248 await dispatch(finishLoadingProject(uuid));
249 const match = await loadGroupContentsResource({
256 await dispatch(activateSidePanelTreeItem(uuid));
257 dispatch<any>(setSidePanelBreadcrumbs(uuid));
259 SHARED: async () => {
260 await dispatch(activateSidePanelTreeItem(uuid));
261 dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
263 TRASHED: async () => {
264 await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
265 dispatch<any>(setTrashBreadcrumbs(uuid));
266 dispatch(setIsProjectPanelTrashed(true));
270 await dispatch(finishLoadingProject(userUuid));
271 await dispatch(activateSidePanelTreeItem(userUuid));
272 dispatch<any>(setSidePanelBreadcrumbs(userUuid));
275 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
279 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) => async (dispatch: Dispatch) => {
280 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
283 snackbarActions.OPEN_SNACKBAR({
284 message: "Project has been successfully created.",
286 kind: SnackbarKind.SUCCESS,
289 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
290 dispatch<any>(navigateTo(newProject.uuid));
294 export const moveProject =
295 (data: MoveToFormDialogData, isSecondaryMove = false) =>
296 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
297 const checkedList = getState().multiselect.checkedList;
298 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
300 //if no items in checkedlist default to normal context menu behavior
301 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
303 const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
304 const destinationUuid = data.ownerUuid;
306 const projectsToMove: MoveableResource[] = uuidsToMove
307 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
308 .filter(resource => resource.kind === ResourceKind.PROJECT);
310 for (const project of projectsToMove) {
311 await moveSingleProject(project);
314 //omly propagate if this call is the original
315 if (!isSecondaryMove) {
316 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
317 kindsToMove.delete(ResourceKind.PROJECT);
319 kindsToMove.forEach(kind => {
320 secondaryMove[kind](data, true)(dispatch, getState, services);
324 async function moveSingleProject(project: MoveableResource) {
326 const oldProject: MoveToFormDialogData = { name: project.name, uuid: project.uuid, ownerUuid: data.ownerUuid };
327 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
328 const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
331 snackbarActions.OPEN_SNACKBAR({
332 message: "Project has been moved",
334 kind: SnackbarKind.SUCCESS,
337 await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
341 snackbarActions.OPEN_SNACKBAR({
342 message: !!(project as any).frozenByUuid ? 'Could not move frozen project.' : e.message,
344 kind: SnackbarKind.ERROR,
349 if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
350 await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
353 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
354 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
355 if (updatedProject) {
357 snackbarActions.OPEN_SNACKBAR({
358 message: "Project has been successfully updated.",
360 kind: SnackbarKind.SUCCESS,
363 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
364 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
368 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
369 const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
372 snackbarActions.OPEN_SNACKBAR({
373 message: "Group has been successfully updated.",
375 kind: SnackbarKind.SUCCESS,
378 await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
379 dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
383 export const loadCollection = (uuid: string) =>
384 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
385 const userUuid = getUserUuid(getState());
387 dispatch(progressIndicatorActions.START_WORKING(uuid));
389 const match = await loadGroupContentsResource({
394 let collection: CollectionResource | undefined;
396 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
398 let sidepanel: string | undefined;
400 OWNED: thecollection => {
401 collection = thecollection as CollectionResource;
402 sidepanel = collection.ownerUuid;
403 breadcrumbfunc = setSidePanelBreadcrumbs;
405 SHARED: thecollection => {
406 collection = thecollection as CollectionResource;
407 sidepanel = collection.ownerUuid;
408 breadcrumbfunc = setSharedWithMeBreadcrumbs;
410 TRASHED: thecollection => {
411 collection = thecollection as CollectionResource;
412 sidepanel = SidePanelTreeCategory.TRASH;
413 breadcrumbfunc = () => setTrashBreadcrumbs("");
416 if (collection && breadcrumbfunc && sidepanel) {
417 dispatch(updateResources([collection]));
418 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
419 dispatch(collectionPanelActions.SET_COLLECTION(collection));
420 await dispatch(activateSidePanelTreeItem(sidepanel));
421 dispatch(breadcrumbfunc(collection.ownerUuid));
422 dispatch(loadCollectionPanel(collection.uuid));
426 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
430 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
431 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
434 snackbarActions.OPEN_SNACKBAR({
435 message: "Collection has been successfully created.",
437 kind: SnackbarKind.SUCCESS,
440 dispatch<any>(updateResources([collection]));
441 dispatch<any>(navigateTo(collection.uuid));
445 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
446 const checkedList = getState().multiselect.checkedList;
447 const uuidsToCopy: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
449 //if no items in checkedlist && no items passed in, default to normal context menu behavior
450 if (!uuidsToCopy.length) uuidsToCopy.push(data.uuid);
452 const collectionsToCopy: CollectionCopyResource[] = uuidsToCopy
453 .map(uuid => getResource(uuid)(getState().resources) as CollectionCopyResource)
454 .filter(resource => resource.kind === ResourceKind.COLLECTION);
456 for (const collection of collectionsToCopy) {
457 await copySingleCollection({ ...collection, ownerUuid: data.ownerUuid } as CollectionCopyResource);
460 async function copySingleCollection(copyToProject: CollectionCopyResource) {
461 const newName = data.fromContextMenu || collectionsToCopy.length === 1 ? data.name : `Copy of: ${copyToProject.name}`;
463 const collection = await dispatch<any>(
464 collectionCopyActions.copyCollection({
467 fromContextMenu: collectionsToCopy.length === 1 ? true : data.fromContextMenu,
470 if (copyToProject && collection) {
471 await dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
473 snackbarActions.OPEN_SNACKBAR({
474 message: "Collection has been copied.",
476 kind: SnackbarKind.SUCCESS,
477 link: collection.ownerUuid,
480 dispatch<any>(multiselectActions.deselectOne(copyToProject.uuid));
484 snackbarActions.OPEN_SNACKBAR({
487 kind: SnackbarKind.ERROR,
492 dispatch(projectPanelActions.REQUEST_ITEMS());
495 export const moveCollection =
496 (data: MoveToFormDialogData, isSecondaryMove = false) =>
497 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
498 const checkedList = getState().multiselect.checkedList;
499 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
501 //if no items in checkedlist && no items passed in, default to normal context menu behavior
502 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
504 const collectionsToMove: MoveableResource[] = uuidsToMove
505 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
506 .filter(resource => resource.kind === ResourceKind.COLLECTION);
508 for (const collection of collectionsToMove) {
509 await moveSingleCollection(collection);
512 //omly propagate if this call is the original
513 if (!isSecondaryMove) {
514 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
515 kindsToMove.delete(ResourceKind.COLLECTION);
517 kindsToMove.forEach(kind => {
518 secondaryMove[kind](data, true)(dispatch, getState, services);
522 async function moveSingleCollection(collection: MoveableResource) {
524 const oldCollection: MoveToFormDialogData = { name: collection.name, uuid: collection.uuid, ownerUuid: data.ownerUuid };
525 const movedCollection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
526 dispatch<any>(updateResources([movedCollection]));
527 dispatch<any>(reloadProjectMatchingUuid([movedCollection.ownerUuid]));
529 snackbarActions.OPEN_SNACKBAR({
530 message: "Collection has been moved.",
532 kind: SnackbarKind.SUCCESS,
537 snackbarActions.OPEN_SNACKBAR({
540 kind: SnackbarKind.ERROR,
547 export const loadProcess = (uuid: string) =>
548 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
550 dispatch(progressIndicatorActions.START_WORKING(uuid));
551 dispatch<any>(loadProcessPanel(uuid));
552 const process = await dispatch<any>(processesActions.loadProcess(uuid));
554 await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
555 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
556 dispatch<any>(setProcessBreadcrumbs(uuid));
557 dispatch<any>(loadDetailsPanel(uuid));
560 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
564 export const loadRegisteredWorkflow = (uuid: string) =>
565 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
566 const userUuid = getUserUuid(getState());
568 const match = await loadGroupContentsResource({
573 let workflow: WorkflowResource | undefined;
575 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
578 OWNED: async theworkflow => {
579 workflow = theworkflow as WorkflowResource;
580 breadcrumbfunc = setSidePanelBreadcrumbs;
582 SHARED: async theworkflow => {
583 workflow = theworkflow as WorkflowResource;
584 breadcrumbfunc = setSharedWithMeBreadcrumbs;
588 if (workflow && breadcrumbfunc) {
589 dispatch(updateResources([workflow]));
590 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
591 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
592 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
597 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
599 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
602 snackbarActions.OPEN_SNACKBAR({
603 message: "Process has been successfully updated.",
605 kind: SnackbarKind.SUCCESS,
608 dispatch<any>(updateResources([process]));
609 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
613 snackbarActions.OPEN_SNACKBAR({
616 kind: SnackbarKind.ERROR,
622 export const moveProcess =
623 (data: MoveToFormDialogData, isSecondaryMove = false) =>
624 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
625 const checkedList = getState().multiselect.checkedList;
626 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
628 //if no items in checkedlist && no items passed in, default to normal context menu behavior
629 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
631 const processesToMove: MoveableResource[] = uuidsToMove
632 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
633 .filter(resource => resource.kind === ResourceKind.PROCESS);
635 for (const process of processesToMove) {
636 await moveSingleProcess(process);
639 //omly propagate if this call is the original
640 if (!isSecondaryMove) {
641 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
642 kindsToMove.delete(ResourceKind.PROCESS);
644 kindsToMove.forEach(kind => {
645 secondaryMove[kind](data, true)(dispatch, getState, services);
649 async function moveSingleProcess(process: MoveableResource) {
651 const oldProcess: MoveToFormDialogData = { name: process.name, uuid: process.uuid, ownerUuid: data.ownerUuid };
652 const movedProcess = await dispatch<any>(processMoveActions.moveProcess(oldProcess));
653 dispatch<any>(updateResources([movedProcess]));
654 dispatch<any>(reloadProjectMatchingUuid([movedProcess.ownerUuid]));
656 snackbarActions.OPEN_SNACKBAR({
657 message: "Process has been moved.",
659 kind: SnackbarKind.SUCCESS,
664 snackbarActions.OPEN_SNACKBAR({
667 kind: SnackbarKind.ERROR,
674 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
676 const process = await dispatch<any>(processCopyActions.copyProcess(data));
677 dispatch<any>(updateResources([process]));
678 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
680 snackbarActions.OPEN_SNACKBAR({
681 message: "Process has been copied.",
683 kind: SnackbarKind.SUCCESS,
686 dispatch<any>(navigateTo(process.uuid));
689 snackbarActions.OPEN_SNACKBAR({
692 kind: SnackbarKind.ERROR,
698 export const resourceIsNotLoaded = (uuid: string) =>
699 snackbarActions.OPEN_SNACKBAR({
700 message: `Resource identified by ${uuid} is not loaded.`,
701 kind: SnackbarKind.ERROR,
704 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
705 message: "User is not authenticated",
706 kind: SnackbarKind.ERROR,
709 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
710 message: "Could not load user",
711 kind: SnackbarKind.ERROR,
714 export const reloadProjectMatchingUuid =
715 (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
716 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
717 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
718 dispatch<any>(loadProject(currentProjectPanelUuid));
722 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
723 dispatch<any>(loadSharedWithMePanel());
724 await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
725 await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
728 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
729 await dispatch<any>(loadRunProcessPanel());
732 export const loadPublicFavorites = () =>
733 handleFirstTimeLoad((dispatch: Dispatch) => {
734 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
735 dispatch<any>(loadPublicFavoritePanel());
736 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
739 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
740 await dispatch(loadSearchResultsPanel());
743 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
744 await dispatch(loadLinkPanel());
747 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
748 await dispatch(loadVirtualMachinesPanel());
749 dispatch(setVirtualMachinesBreadcrumbs());
750 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHELL_ACCESS));
753 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
754 await dispatch(loadVirtualMachinesPanel());
755 dispatch(setVirtualMachinesAdminBreadcrumbs());
756 dispatch(treePickerActions.DEACTIVATE_TREE_PICKER_NODE({pickerId: SIDE_PANEL_TREE} ))
759 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
760 await dispatch(loadRepositoriesPanel());
761 dispatch(setRepositoriesBreadcrumbs());
764 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
765 await dispatch(loadSshKeysPanel());
768 export const loadInstanceTypes = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
769 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.INSTANCE_TYPES));
770 dispatch(setInstanceTypesBreadcrumbs());
773 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
774 await dispatch(loadSiteManagerPanel());
777 export const loadUserProfile = (userUuid?: string) =>
778 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
780 dispatch(setUserProfileBreadcrumbs(userUuid));
781 dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
783 dispatch(setMyAccountBreadcrumbs());
784 dispatch(userProfilePanelActions.loadUserProfilePanel());
788 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
789 dispatch(loadLinkAccountPanel());
792 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
793 await dispatch(loadKeepServicesPanel());
796 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
797 await dispatch(loadUsersPanel());
798 dispatch(setUsersBreadcrumbs());
801 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
802 await dispatch(loadApiClientAuthorizationsPanel());
805 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
806 dispatch(setGroupsBreadcrumbs());
807 dispatch(groupPanelActions.loadGroupsPanel());
810 export const loadGroupDetailsPanel = (groupUuid: string) =>
811 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
812 dispatch(setGroupDetailsBreadcrumbs(groupUuid));
813 dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
816 const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
817 const uuid = typeof project === "string" ? project : project.uuid;
818 dispatch(loadDetailsPanel(uuid));
819 if (typeof project !== "string") {
820 dispatch(updateResources([project]));
824 const loadGroupContentsResource = async (params: { uuid: string; userUuid: string; services: ServiceRepository }) => {
825 const filters = new FilterBuilder().addEqual("uuid", params.uuid).getFilters();
826 const { items } = await params.services.groupsService.contents(params.userUuid, {
831 const resource = items.shift();
832 let handler: GroupContentsHandler;
835 (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
836 ? groupContentsHandlers.TRASHED(resource)
837 : groupContentsHandlers.OWNED(resource);
839 const kind = extractUuidKind(params.uuid);
840 let resource: GroupContentsResource;
841 if (kind === ResourceKind.COLLECTION) {
842 resource = await params.services.collectionService.get(params.uuid);
843 } else if (kind === ResourceKind.PROJECT) {
844 resource = await params.services.projectService.get(params.uuid);
845 } else if (kind === ResourceKind.WORKFLOW) {
846 resource = await params.services.workflowService.get(params.uuid);
847 } else if (kind === ResourceKind.CONTAINER_REQUEST) {
848 resource = await params.services.containerRequestService.get(params.uuid);
850 throw new Error("loadGroupContentsResource unsupported kind " + kind);
852 handler = groupContentsHandlers.SHARED(resource);
854 return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) => groupContentsHandlers.match(handler, cases);
857 const groupContentsHandlersRecord = {
858 TRASHED: ofType<GroupContentsResource>(),
859 SHARED: ofType<GroupContentsResource>(),
860 OWNED: ofType<GroupContentsResource>(),
863 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
865 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;
867 type CollectionCopyResource = Resource & { name: string; fromContextMenu: boolean };
869 type MoveableResource = Resource & { name: string };
872 data: MoveToFormDialogData,
873 isSecondaryMove?: boolean
874 ) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>;
876 const secondaryMove: Record<string, MoveFunc> = {
877 [ResourceKind.PROJECT]: moveProject,
878 [ResourceKind.PROCESS]: moveProcess,
879 [ResourceKind.COLLECTION]: moveCollection,