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 { CopyFormDialogData } from "store/copy-dialog/copy-dialog";
54 import { workflowPanelActions } from "store/workflow-panel/workflow-panel-actions";
55 import { loadSshKeysPanel } from "store/auth/auth-action-ssh";
56 import { loadLinkAccountPanel, linkAccountPanelActions } from "store/link-account-panel/link-account-panel-actions";
57 import { loadSiteManagerPanel } from "store/auth/auth-action-session";
58 import { workflowPanelColumns } from "views/workflow-panel/workflow-panel-view";
59 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
60 import { getProgressIndicator } from "store/progress-indicator/progress-indicator-reducer";
61 import { extractUuidKind, Resource, ResourceKind } from "models/resource";
62 import { FilterBuilder } from "services/api/filter-builder";
63 import { GroupContentsResource } from "services/groups-service/groups-service";
64 import { MatchCases, ofType, unionize, UnionOf } from "common/unionize";
65 import { loadRunProcessPanel } from "store/run-process-panel/run-process-panel-actions";
66 import { collectionPanelActions, loadCollectionPanel } from "store/collection-panel/collection-panel-action";
67 import { CollectionResource } from "models/collection";
68 import { WorkflowResource } from "models/workflow";
69 import { loadSearchResultsPanel, searchResultsPanelActions } from "store/search-results-panel/search-results-panel-actions";
70 import { searchResultsPanelColumns } from "views/search-results-panel/search-results-panel-view";
71 import { loadVirtualMachinesPanel } from "store/virtual-machines/virtual-machines-actions";
72 import { loadRepositoriesPanel } from "store/repositories/repositories-actions";
73 import { loadKeepServicesPanel } from "store/keep-services/keep-services-actions";
74 import { loadUsersPanel, userBindedActions } from "store/users/users-actions";
75 import * as userProfilePanelActions from "store/user-profile/user-profile-actions";
76 import { linkPanelActions, loadLinkPanel } from "store/link-panel/link-panel-actions";
77 import { linkPanelColumns } from "views/link-panel/link-panel-root";
78 import { userPanelColumns } from "views/user-panel/user-panel";
79 import { loadApiClientAuthorizationsPanel, apiClientAuthorizationsActions } from "store/api-client-authorizations/api-client-authorizations-actions";
80 import { apiClientAuthorizationPanelColumns } from "views/api-client-authorization-panel/api-client-authorization-panel-root";
81 import * as groupPanelActions from "store/groups-panel/groups-panel-actions";
82 import { groupsPanelColumns } from "views/groups-panel/groups-panel";
83 import * as groupDetailsPanelActions from "store/group-details-panel/group-details-panel-actions";
84 import { groupDetailsMembersPanelColumns, groupDetailsPermissionsPanelColumns } from "views/group-details-panel/group-details-panel";
85 import { DataTableFetchMode } from "components/data-table/data-table";
86 import { loadPublicFavoritePanel, publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
87 import { publicFavoritePanelColumns } from "views/public-favorites-panel/public-favorites-panel";
89 loadCollectionsContentAddressPanel,
90 collectionsContentAddressActions,
91 } from "store/collections-content-address-panel/collections-content-address-panel-actions";
92 import { collectionContentAddressPanelColumns } from "views/collection-content-address-panel/collection-content-address-panel";
93 import { subprocessPanelActions } from "store/subprocess-panel/subprocess-panel-actions";
94 import { subprocessPanelColumns } from "views/subprocess-panel/subprocess-panel-root";
95 import { loadAllProcessesPanel, allProcessesPanelActions } from "../all-processes-panel/all-processes-panel-action";
96 import { allProcessesPanelColumns } from "views/all-processes-panel/all-processes-panel";
97 import { AdminMenuIcon } from "components/icon/icon";
98 import { userProfileGroupsColumns } from "views/user-profile-panel/user-profile-panel-root";
99 import { selectedToArray, selectedToKindSet } from "components/multiselect-toolbar/MultiselectToolbar";
100 import { multiselectActions } from "store/multiselect/multiselect-actions";
102 export const WORKBENCH_LOADING_SCREEN = "workbenchLoadingScreen";
104 export const isWorkbenchLoading = (state: RootState) => {
105 const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
106 return progress ? progress.working : false;
109 export const handleFirstTimeLoad = (action: any) => async (dispatch: Dispatch<any>, getState: () => RootState) => {
111 await dispatch(action);
113 if (isWorkbenchLoading(getState())) {
114 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
119 export const loadWorkbench = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
120 dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
121 const { auth, router } = getState();
122 const { user } = auth;
124 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
125 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
127 allProcessesPanelActions.SET_COLUMNS({
128 columns: allProcessesPanelColumns,
132 publicFavoritePanelActions.SET_COLUMNS({
133 columns: publicFavoritePanelColumns,
136 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
137 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
138 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
140 searchResultsPanelActions.SET_FETCH_MODE({
141 fetchMode: DataTableFetchMode.INFINITE,
145 searchResultsPanelActions.SET_COLUMNS({
146 columns: searchResultsPanelColumns,
149 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
151 groupPanelActions.GroupsPanelActions.SET_COLUMNS({
152 columns: groupsPanelColumns,
156 groupDetailsPanelActions.GroupMembersPanelActions.SET_COLUMNS({
157 columns: groupDetailsMembersPanelColumns,
161 groupDetailsPanelActions.GroupPermissionsPanelActions.SET_COLUMNS({
162 columns: groupDetailsPermissionsPanelColumns,
166 userProfilePanelActions.UserProfileGroupsActions.SET_COLUMNS({
167 columns: userProfileGroupsColumns,
170 dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
172 apiClientAuthorizationsActions.SET_COLUMNS({
173 columns: apiClientAuthorizationPanelColumns,
177 collectionsContentAddressActions.SET_COLUMNS({
178 columns: collectionContentAddressPanelColumns,
181 dispatch(subprocessPanelActions.SET_COLUMNS({ columns: subprocessPanelColumns }));
183 if (services.linkAccountService.getAccountToLink()) {
184 dispatch(linkAccountPanelActions.HAS_SESSION_DATA());
187 dispatch<any>(initSidePanelTree());
188 if (router.location) {
189 const match = matchRootRoute(router.location.pathname);
191 dispatch<any>(navigateToRootProject);
195 dispatch(userIsNotAuthenticated);
199 export const loadFavorites = () =>
200 handleFirstTimeLoad((dispatch: Dispatch) => {
201 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
202 dispatch<any>(loadFavoritePanel());
203 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
206 export const loadCollectionContentAddress = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
207 await dispatch(loadCollectionsContentAddressPanel());
210 export const loadTrash = () =>
211 handleFirstTimeLoad((dispatch: Dispatch) => {
212 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
213 dispatch<any>(loadTrashPanel());
214 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
217 export const loadAllProcesses = () =>
218 handleFirstTimeLoad((dispatch: Dispatch) => {
219 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.ALL_PROCESSES));
220 dispatch<any>(loadAllProcessesPanel());
221 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.ALL_PROCESSES));
224 export const loadProject = (uuid: string) =>
225 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
226 const userUuid = getUserUuid(getState());
227 dispatch(setIsProjectPanelTrashed(false));
232 dispatch(progressIndicatorActions.START_WORKING(uuid));
233 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
234 // Load another users home projects
235 dispatch(finishLoadingProject(uuid));
236 } else if (userUuid !== uuid) {
237 await dispatch(finishLoadingProject(uuid));
238 const match = await loadGroupContentsResource({
245 await dispatch(activateSidePanelTreeItem(uuid));
246 dispatch<any>(setSidePanelBreadcrumbs(uuid));
248 SHARED: async () => {
249 await dispatch(activateSidePanelTreeItem(uuid));
250 dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
252 TRASHED: async () => {
253 await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
254 dispatch<any>(setTrashBreadcrumbs(uuid));
255 dispatch(setIsProjectPanelTrashed(true));
259 await dispatch(finishLoadingProject(userUuid));
260 await dispatch(activateSidePanelTreeItem(userUuid));
261 dispatch<any>(setSidePanelBreadcrumbs(userUuid));
264 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
268 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) => async (dispatch: Dispatch) => {
269 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
272 snackbarActions.OPEN_SNACKBAR({
273 message: "Project has been successfully created.",
275 kind: SnackbarKind.SUCCESS,
278 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
279 dispatch<any>(navigateTo(newProject.uuid));
283 export const moveProject =
284 (data: MoveToFormDialogData, isSecondaryMove = false) =>
285 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
286 const checkedList = getState().multiselect.checkedList;
287 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
289 //if no items in checkedlist default to normal context menu behavior
290 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
292 const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
293 const destinationUuid = data.ownerUuid;
295 const projectsToMove: MoveableResource[] = uuidsToMove
296 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
297 .filter(resource => resource.kind === ResourceKind.PROJECT);
299 for (const project of projectsToMove) {
300 await moveSingleProject(project);
303 //omly propagate if this call is the original
304 if (!isSecondaryMove) {
305 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
306 kindsToMove.delete(ResourceKind.PROJECT);
308 kindsToMove.forEach(kind => {
309 secondaryMove[kind](data, true)(dispatch, getState, services);
313 async function moveSingleProject(project: MoveableResource) {
315 const oldProject: MoveToFormDialogData = { name: project.name, uuid: project.uuid, ownerUuid: data.ownerUuid };
316 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
317 const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
320 snackbarActions.OPEN_SNACKBAR({
321 message: "Project has been moved",
323 kind: SnackbarKind.SUCCESS,
326 await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
330 snackbarActions.OPEN_SNACKBAR({
333 kind: SnackbarKind.ERROR,
338 if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
339 await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
342 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
343 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
344 if (updatedProject) {
346 snackbarActions.OPEN_SNACKBAR({
347 message: "Project has been successfully updated.",
349 kind: SnackbarKind.SUCCESS,
352 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
353 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
357 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
358 const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
361 snackbarActions.OPEN_SNACKBAR({
362 message: "Group has been successfully updated.",
364 kind: SnackbarKind.SUCCESS,
367 await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
368 dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
372 export const loadCollection = (uuid: string) =>
373 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
374 const userUuid = getUserUuid(getState());
376 dispatch(progressIndicatorActions.START_WORKING(uuid));
378 const match = await loadGroupContentsResource({
383 let collection: CollectionResource | undefined;
385 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
387 let sidepanel: string | undefined;
389 OWNED: thecollection => {
390 collection = thecollection as CollectionResource;
391 sidepanel = collection.ownerUuid;
392 breadcrumbfunc = setSidePanelBreadcrumbs;
394 SHARED: thecollection => {
395 collection = thecollection as CollectionResource;
396 sidepanel = collection.ownerUuid;
397 breadcrumbfunc = setSharedWithMeBreadcrumbs;
399 TRASHED: thecollection => {
400 collection = thecollection as CollectionResource;
401 sidepanel = SidePanelTreeCategory.TRASH;
402 breadcrumbfunc = () => setTrashBreadcrumbs("");
405 if (collection && breadcrumbfunc && sidepanel) {
406 dispatch(updateResources([collection]));
407 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
408 dispatch(collectionPanelActions.SET_COLLECTION(collection));
409 await dispatch(activateSidePanelTreeItem(sidepanel));
410 dispatch(breadcrumbfunc(collection.ownerUuid));
411 dispatch(loadCollectionPanel(collection.uuid));
415 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
419 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
420 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
423 snackbarActions.OPEN_SNACKBAR({
424 message: "Collection has been successfully created.",
426 kind: SnackbarKind.SUCCESS,
429 dispatch<any>(updateResources([collection]));
430 dispatch<any>(navigateTo(collection.uuid));
434 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
435 const checkedList = getState().multiselect.checkedList;
436 const uuidsToCopy: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
438 //if no items in checkedlist && no items passed in, default to normal context menu behavior
439 if (!uuidsToCopy.length) uuidsToCopy.push(data.uuid);
441 const collectionsToCopy: CollectionCopyResource[] = uuidsToCopy
442 .map(uuid => getResource(uuid)(getState().resources) as CollectionCopyResource)
443 .filter(resource => resource.kind === ResourceKind.COLLECTION);
445 for (const collection of collectionsToCopy) {
446 await copySingleCollection({ ...collection, ownerUuid: data.ownerUuid } as CollectionCopyResource);
449 async function copySingleCollection(copyToProject: CollectionCopyResource) {
450 const newName = data.fromContextMenu || collectionsToCopy.length === 1 ? data.name : `Copy of: ${copyToProject.name}`;
452 const collection = await dispatch<any>(
453 collectionCopyActions.copyCollection({
456 fromContextMenu: collectionsToCopy.length === 1 ? true : data.fromContextMenu,
459 if (copyToProject && collection) {
460 await dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
462 snackbarActions.OPEN_SNACKBAR({
463 message: "Collection has been copied.",
465 kind: SnackbarKind.SUCCESS,
466 link: collection.ownerUuid,
469 dispatch<any>(multiselectActions.deselectOne(copyToProject.uuid));
473 snackbarActions.OPEN_SNACKBAR({
476 kind: SnackbarKind.ERROR,
481 dispatch(projectPanelActions.REQUEST_ITEMS());
484 export const moveCollection =
485 (data: MoveToFormDialogData, isSecondaryMove = false) =>
486 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
487 const checkedList = getState().multiselect.checkedList;
488 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
490 //if no items in checkedlist && no items passed in, default to normal context menu behavior
491 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
493 const collectionsToMove: MoveableResource[] = uuidsToMove
494 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
495 .filter(resource => resource.kind === ResourceKind.COLLECTION);
497 for (const collection of collectionsToMove) {
498 await moveSingleCollection(collection);
501 //omly propagate if this call is the original
502 if (!isSecondaryMove) {
503 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
504 kindsToMove.delete(ResourceKind.COLLECTION);
506 kindsToMove.forEach(kind => {
507 secondaryMove[kind](data, true)(dispatch, getState, services);
511 async function moveSingleCollection(collection: MoveableResource) {
513 const oldCollection: MoveToFormDialogData = { name: collection.name, uuid: collection.uuid, ownerUuid: data.ownerUuid };
514 const movedCollection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
515 dispatch<any>(updateResources([movedCollection]));
516 dispatch<any>(reloadProjectMatchingUuid([movedCollection.ownerUuid]));
518 snackbarActions.OPEN_SNACKBAR({
519 message: "Collection has been moved.",
521 kind: SnackbarKind.SUCCESS,
526 snackbarActions.OPEN_SNACKBAR({
529 kind: SnackbarKind.ERROR,
536 export const loadProcess = (uuid: string) =>
537 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
539 dispatch(progressIndicatorActions.START_WORKING(uuid));
540 dispatch<any>(loadProcessPanel(uuid));
541 const process = await dispatch<any>(processesActions.loadProcess(uuid));
543 await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
544 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
545 dispatch<any>(setProcessBreadcrumbs(uuid));
546 dispatch<any>(loadDetailsPanel(uuid));
549 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
553 export const loadRegisteredWorkflow = (uuid: string) =>
554 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
555 const userUuid = getUserUuid(getState());
557 const match = await loadGroupContentsResource({
562 let workflow: WorkflowResource | undefined;
564 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
567 OWNED: async theworkflow => {
568 workflow = theworkflow as WorkflowResource;
569 breadcrumbfunc = setSidePanelBreadcrumbs;
571 SHARED: async theworkflow => {
572 workflow = theworkflow as WorkflowResource;
573 breadcrumbfunc = setSharedWithMeBreadcrumbs;
577 if (workflow && breadcrumbfunc) {
578 dispatch(updateResources([workflow]));
579 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
580 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
581 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
586 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
588 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
591 snackbarActions.OPEN_SNACKBAR({
592 message: "Process has been successfully updated.",
594 kind: SnackbarKind.SUCCESS,
597 dispatch<any>(updateResources([process]));
598 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
602 snackbarActions.OPEN_SNACKBAR({
605 kind: SnackbarKind.ERROR,
611 export const moveProcess =
612 (data: MoveToFormDialogData, isSecondaryMove = false) =>
613 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
614 const checkedList = getState().multiselect.checkedList;
615 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
617 //if no items in checkedlist && no items passed in, default to normal context menu behavior
618 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
620 const processesToMove: MoveableResource[] = uuidsToMove
621 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
622 .filter(resource => resource.kind === ResourceKind.PROCESS);
624 for (const process of processesToMove) {
625 await moveSingleProcess(process);
628 //omly propagate if this call is the original
629 if (!isSecondaryMove) {
630 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
631 kindsToMove.delete(ResourceKind.PROCESS);
633 kindsToMove.forEach(kind => {
634 secondaryMove[kind](data, true)(dispatch, getState, services);
638 async function moveSingleProcess(process: MoveableResource) {
640 const oldProcess: MoveToFormDialogData = { name: process.name, uuid: process.uuid, ownerUuid: data.ownerUuid };
641 const movedProcess = await dispatch<any>(processMoveActions.moveProcess(oldProcess));
642 dispatch<any>(updateResources([movedProcess]));
643 dispatch<any>(reloadProjectMatchingUuid([movedProcess.ownerUuid]));
645 snackbarActions.OPEN_SNACKBAR({
646 message: "Process has been moved.",
648 kind: SnackbarKind.SUCCESS,
653 snackbarActions.OPEN_SNACKBAR({
656 kind: SnackbarKind.ERROR,
663 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
665 const process = await dispatch<any>(processCopyActions.copyProcess(data));
666 dispatch<any>(updateResources([process]));
667 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
669 snackbarActions.OPEN_SNACKBAR({
670 message: "Process has been copied.",
672 kind: SnackbarKind.SUCCESS,
675 dispatch<any>(navigateTo(process.uuid));
678 snackbarActions.OPEN_SNACKBAR({
681 kind: SnackbarKind.ERROR,
687 export const resourceIsNotLoaded = (uuid: string) =>
688 snackbarActions.OPEN_SNACKBAR({
689 message: `Resource identified by ${uuid} is not loaded.`,
690 kind: SnackbarKind.ERROR,
693 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
694 message: "User is not authenticated",
695 kind: SnackbarKind.ERROR,
698 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
699 message: "Could not load user",
700 kind: SnackbarKind.ERROR,
703 export const reloadProjectMatchingUuid =
704 (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
705 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
706 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
707 dispatch<any>(loadProject(currentProjectPanelUuid));
711 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
712 dispatch<any>(loadSharedWithMePanel());
713 await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
714 await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
717 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
718 await dispatch<any>(loadRunProcessPanel());
721 export const loadPublicFavorites = () =>
722 handleFirstTimeLoad((dispatch: Dispatch) => {
723 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
724 dispatch<any>(loadPublicFavoritePanel());
725 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
728 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
729 await dispatch(loadSearchResultsPanel());
732 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
733 await dispatch(loadLinkPanel());
736 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
737 await dispatch(loadVirtualMachinesPanel());
738 dispatch(setBreadcrumbs([{ label: "Virtual Machines" }]));
741 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
742 await dispatch(loadVirtualMachinesPanel());
743 dispatch(setBreadcrumbs([{ label: "Virtual Machines Admin", icon: AdminMenuIcon }]));
746 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
747 await dispatch(loadRepositoriesPanel());
748 dispatch(setBreadcrumbs([{ label: "Repositories" }]));
751 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
752 await dispatch(loadSshKeysPanel());
755 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
756 await dispatch(loadSiteManagerPanel());
759 export const loadUserProfile = (userUuid?: string) =>
760 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
762 dispatch(setUserProfileBreadcrumbs(userUuid));
763 dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
765 dispatch(setMyAccountBreadcrumbs());
766 dispatch(userProfilePanelActions.loadUserProfilePanel());
770 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
771 dispatch(loadLinkAccountPanel());
774 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
775 await dispatch(loadKeepServicesPanel());
778 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
779 await dispatch(loadUsersPanel());
780 dispatch(setUsersBreadcrumbs());
783 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
784 await dispatch(loadApiClientAuthorizationsPanel());
787 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
788 dispatch(setGroupsBreadcrumbs());
789 dispatch(groupPanelActions.loadGroupsPanel());
792 export const loadGroupDetailsPanel = (groupUuid: string) =>
793 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
794 dispatch(setGroupDetailsBreadcrumbs(groupUuid));
795 dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
798 const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
799 const uuid = typeof project === "string" ? project : project.uuid;
800 dispatch(loadDetailsPanel(uuid));
801 if (typeof project !== "string") {
802 dispatch(updateResources([project]));
806 const loadGroupContentsResource = async (params: { uuid: string; userUuid: string; services: ServiceRepository }) => {
807 const filters = new FilterBuilder().addEqual("uuid", params.uuid).getFilters();
808 const { items } = await params.services.groupsService.contents(params.userUuid, {
813 const resource = items.shift();
814 let handler: GroupContentsHandler;
817 (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
818 ? groupContentsHandlers.TRASHED(resource)
819 : groupContentsHandlers.OWNED(resource);
821 const kind = extractUuidKind(params.uuid);
822 let resource: GroupContentsResource;
823 if (kind === ResourceKind.COLLECTION) {
824 resource = await params.services.collectionService.get(params.uuid);
825 } else if (kind === ResourceKind.PROJECT) {
826 resource = await params.services.projectService.get(params.uuid);
827 } else if (kind === ResourceKind.WORKFLOW) {
828 resource = await params.services.workflowService.get(params.uuid);
829 } else if (kind === ResourceKind.CONTAINER_REQUEST) {
830 resource = await params.services.containerRequestService.get(params.uuid);
832 throw new Error("loadGroupContentsResource unsupported kind " + kind);
834 handler = groupContentsHandlers.SHARED(resource);
836 return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) => groupContentsHandlers.match(handler, cases);
839 const groupContentsHandlersRecord = {
840 TRASHED: ofType<GroupContentsResource>(),
841 SHARED: ofType<GroupContentsResource>(),
842 OWNED: ofType<GroupContentsResource>(),
845 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
847 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;
849 type CollectionCopyResource = Resource & { name: string; fromContextMenu: boolean };
851 type MoveableResource = Resource & { name: string };
854 data: MoveToFormDialogData,
855 isSecondaryMove?: boolean
856 ) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>;
858 const secondaryMove: Record<string, MoveFunc> = {
859 [ResourceKind.PROJECT]: moveProject,
860 [ResourceKind.PROCESS]: moveProcess,
861 [ResourceKind.COLLECTION]: moveCollection,