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 snackbarActions.OPEN_SNACKBAR({
114 message: "Error " + e,
116 kind: SnackbarKind.WARNING,
119 if (isWorkbenchLoading(getState())) {
120 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
125 export const loadWorkbench = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
126 dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
127 const { auth, router } = getState();
128 const { user } = auth;
130 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
131 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
133 allProcessesPanelActions.SET_COLUMNS({
134 columns: allProcessesPanelColumns,
138 publicFavoritePanelActions.SET_COLUMNS({
139 columns: publicFavoritePanelColumns,
142 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
143 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
144 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
146 searchResultsPanelActions.SET_FETCH_MODE({
147 fetchMode: DataTableFetchMode.INFINITE,
151 searchResultsPanelActions.SET_COLUMNS({
152 columns: searchResultsPanelColumns,
155 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
157 groupPanelActions.GroupsPanelActions.SET_COLUMNS({
158 columns: groupsPanelColumns,
162 groupDetailsPanelActions.GroupMembersPanelActions.SET_COLUMNS({
163 columns: groupDetailsMembersPanelColumns,
167 groupDetailsPanelActions.GroupPermissionsPanelActions.SET_COLUMNS({
168 columns: groupDetailsPermissionsPanelColumns,
172 userProfilePanelActions.UserProfileGroupsActions.SET_COLUMNS({
173 columns: userProfileGroupsColumns,
176 dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
178 apiClientAuthorizationsActions.SET_COLUMNS({
179 columns: apiClientAuthorizationPanelColumns,
183 collectionsContentAddressActions.SET_COLUMNS({
184 columns: collectionContentAddressPanelColumns,
187 dispatch(subprocessPanelActions.SET_COLUMNS({ columns: subprocessPanelColumns }));
189 if (services.linkAccountService.getAccountToLink()) {
190 dispatch(linkAccountPanelActions.HAS_SESSION_DATA());
193 dispatch<any>(initSidePanelTree());
194 if (router.location) {
195 const match = matchRootRoute(router.location.pathname);
197 dispatch<any>(navigateToRootProject);
201 dispatch(userIsNotAuthenticated);
205 export const loadFavorites = () =>
206 handleFirstTimeLoad((dispatch: Dispatch) => {
207 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
208 dispatch<any>(loadFavoritePanel());
209 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
212 export const loadCollectionContentAddress = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
213 await dispatch(loadCollectionsContentAddressPanel());
216 export const loadTrash = () =>
217 handleFirstTimeLoad((dispatch: Dispatch) => {
218 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
219 dispatch<any>(loadTrashPanel());
220 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
223 export const loadAllProcesses = () =>
224 handleFirstTimeLoad((dispatch: Dispatch) => {
225 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.ALL_PROCESSES));
226 dispatch<any>(loadAllProcessesPanel());
227 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.ALL_PROCESSES));
230 export const loadProject = (uuid: string) =>
231 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
232 const userUuid = getUserUuid(getState());
233 dispatch(setIsProjectPanelTrashed(false));
238 dispatch(progressIndicatorActions.START_WORKING(uuid));
239 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
240 // Load another users home projects
241 dispatch(finishLoadingProject(uuid));
242 } else if (userUuid !== uuid) {
243 await dispatch(finishLoadingProject(uuid));
244 const match = await loadGroupContentsResource({
251 await dispatch(activateSidePanelTreeItem(uuid));
252 dispatch<any>(setSidePanelBreadcrumbs(uuid));
254 SHARED: async () => {
255 await dispatch(activateSidePanelTreeItem(uuid));
256 dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
258 TRASHED: async () => {
259 await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
260 dispatch<any>(setTrashBreadcrumbs(uuid));
261 dispatch(setIsProjectPanelTrashed(true));
265 await dispatch(finishLoadingProject(userUuid));
266 await dispatch(activateSidePanelTreeItem(userUuid));
267 dispatch<any>(setSidePanelBreadcrumbs(userUuid));
270 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
274 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) => async (dispatch: Dispatch) => {
275 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
278 snackbarActions.OPEN_SNACKBAR({
279 message: "Project has been successfully created.",
281 kind: SnackbarKind.SUCCESS,
284 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
285 dispatch<any>(navigateTo(newProject.uuid));
289 export const moveProject =
290 (data: MoveToFormDialogData, isSecondaryMove = false) =>
291 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
292 const checkedList = getState().multiselect.checkedList;
293 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
295 //if no items in checkedlist default to normal context menu behavior
296 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
298 const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
299 const destinationUuid = data.ownerUuid;
301 const projectsToMove: MoveableResource[] = uuidsToMove
302 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
303 .filter(resource => resource.kind === ResourceKind.PROJECT);
305 for (const project of projectsToMove) {
306 await moveSingleProject(project);
309 //omly propagate if this call is the original
310 if (!isSecondaryMove) {
311 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
312 kindsToMove.delete(ResourceKind.PROJECT);
314 kindsToMove.forEach(kind => {
315 secondaryMove[kind](data, true)(dispatch, getState, services);
319 async function moveSingleProject(project: MoveableResource) {
321 const oldProject: MoveToFormDialogData = { name: project.name, uuid: project.uuid, ownerUuid: data.ownerUuid };
322 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
323 const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
326 snackbarActions.OPEN_SNACKBAR({
327 message: "Project has been moved",
329 kind: SnackbarKind.SUCCESS,
332 await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
336 snackbarActions.OPEN_SNACKBAR({
339 kind: SnackbarKind.ERROR,
344 if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
345 await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
348 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
349 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
350 if (updatedProject) {
352 snackbarActions.OPEN_SNACKBAR({
353 message: "Project has been successfully updated.",
355 kind: SnackbarKind.SUCCESS,
358 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
359 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
363 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
364 const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
367 snackbarActions.OPEN_SNACKBAR({
368 message: "Group has been successfully updated.",
370 kind: SnackbarKind.SUCCESS,
373 await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
374 dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
378 export const loadCollection = (uuid: string) =>
379 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
380 const userUuid = getUserUuid(getState());
382 dispatch(progressIndicatorActions.START_WORKING(uuid));
384 const match = await loadGroupContentsResource({
389 let collection: CollectionResource | undefined;
391 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
393 let sidepanel: string | undefined;
395 OWNED: thecollection => {
396 collection = thecollection as CollectionResource;
397 sidepanel = collection.ownerUuid;
398 breadcrumbfunc = setSidePanelBreadcrumbs;
400 SHARED: thecollection => {
401 collection = thecollection as CollectionResource;
402 sidepanel = collection.ownerUuid;
403 breadcrumbfunc = setSharedWithMeBreadcrumbs;
405 TRASHED: thecollection => {
406 collection = thecollection as CollectionResource;
407 sidepanel = SidePanelTreeCategory.TRASH;
408 breadcrumbfunc = () => setTrashBreadcrumbs("");
411 if (collection && breadcrumbfunc && sidepanel) {
412 dispatch(updateResources([collection]));
413 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
414 dispatch(collectionPanelActions.SET_COLLECTION(collection));
415 await dispatch(activateSidePanelTreeItem(sidepanel));
416 dispatch(breadcrumbfunc(collection.ownerUuid));
417 dispatch(loadCollectionPanel(collection.uuid));
421 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
425 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
426 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
429 snackbarActions.OPEN_SNACKBAR({
430 message: "Collection has been successfully created.",
432 kind: SnackbarKind.SUCCESS,
435 dispatch<any>(updateResources([collection]));
436 dispatch<any>(navigateTo(collection.uuid));
440 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
441 const checkedList = getState().multiselect.checkedList;
442 const uuidsToCopy: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
444 //if no items in checkedlist && no items passed in, default to normal context menu behavior
445 if (!uuidsToCopy.length) uuidsToCopy.push(data.uuid);
447 const collectionsToCopy: CollectionCopyResource[] = uuidsToCopy
448 .map(uuid => getResource(uuid)(getState().resources) as CollectionCopyResource)
449 .filter(resource => resource.kind === ResourceKind.COLLECTION);
451 for (const collection of collectionsToCopy) {
452 await copySingleCollection({ ...collection, ownerUuid: data.ownerUuid } as CollectionCopyResource);
455 async function copySingleCollection(copyToProject: CollectionCopyResource) {
456 const newName = data.fromContextMenu || collectionsToCopy.length === 1 ? data.name : `Copy of: ${copyToProject.name}`;
458 const collection = await dispatch<any>(
459 collectionCopyActions.copyCollection({
462 fromContextMenu: collectionsToCopy.length === 1 ? true : data.fromContextMenu,
465 if (copyToProject && collection) {
466 await dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
468 snackbarActions.OPEN_SNACKBAR({
469 message: "Collection has been copied.",
471 kind: SnackbarKind.SUCCESS,
472 link: collection.ownerUuid,
475 dispatch<any>(multiselectActions.deselectOne(copyToProject.uuid));
479 snackbarActions.OPEN_SNACKBAR({
482 kind: SnackbarKind.ERROR,
487 dispatch(projectPanelActions.REQUEST_ITEMS());
490 export const moveCollection =
491 (data: MoveToFormDialogData, isSecondaryMove = false) =>
492 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
493 const checkedList = getState().multiselect.checkedList;
494 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
496 //if no items in checkedlist && no items passed in, default to normal context menu behavior
497 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
499 const collectionsToMove: MoveableResource[] = uuidsToMove
500 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
501 .filter(resource => resource.kind === ResourceKind.COLLECTION);
503 for (const collection of collectionsToMove) {
504 await moveSingleCollection(collection);
507 //omly propagate if this call is the original
508 if (!isSecondaryMove) {
509 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
510 kindsToMove.delete(ResourceKind.COLLECTION);
512 kindsToMove.forEach(kind => {
513 secondaryMove[kind](data, true)(dispatch, getState, services);
517 async function moveSingleCollection(collection: MoveableResource) {
519 const oldCollection: MoveToFormDialogData = { name: collection.name, uuid: collection.uuid, ownerUuid: data.ownerUuid };
520 const movedCollection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
521 dispatch<any>(updateResources([movedCollection]));
522 dispatch<any>(reloadProjectMatchingUuid([movedCollection.ownerUuid]));
524 snackbarActions.OPEN_SNACKBAR({
525 message: "Collection has been moved.",
527 kind: SnackbarKind.SUCCESS,
532 snackbarActions.OPEN_SNACKBAR({
535 kind: SnackbarKind.ERROR,
542 export const loadProcess = (uuid: string) =>
543 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
545 dispatch(progressIndicatorActions.START_WORKING(uuid));
546 dispatch<any>(loadProcessPanel(uuid));
547 const process = await dispatch<any>(processesActions.loadProcess(uuid));
549 await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
550 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
551 dispatch<any>(setProcessBreadcrumbs(uuid));
552 dispatch<any>(loadDetailsPanel(uuid));
555 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
559 export const loadRegisteredWorkflow = (uuid: string) =>
560 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
561 const userUuid = getUserUuid(getState());
563 const match = await loadGroupContentsResource({
568 let workflow: WorkflowResource | undefined;
570 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
573 OWNED: async theworkflow => {
574 workflow = theworkflow as WorkflowResource;
575 breadcrumbfunc = setSidePanelBreadcrumbs;
577 SHARED: async theworkflow => {
578 workflow = theworkflow as WorkflowResource;
579 breadcrumbfunc = setSharedWithMeBreadcrumbs;
583 if (workflow && breadcrumbfunc) {
584 dispatch(updateResources([workflow]));
585 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
586 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
587 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
592 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
594 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
597 snackbarActions.OPEN_SNACKBAR({
598 message: "Process has been successfully updated.",
600 kind: SnackbarKind.SUCCESS,
603 dispatch<any>(updateResources([process]));
604 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
608 snackbarActions.OPEN_SNACKBAR({
611 kind: SnackbarKind.ERROR,
617 export const moveProcess =
618 (data: MoveToFormDialogData, isSecondaryMove = false) =>
619 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
620 const checkedList = getState().multiselect.checkedList;
621 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
623 //if no items in checkedlist && no items passed in, default to normal context menu behavior
624 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
626 const processesToMove: MoveableResource[] = uuidsToMove
627 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
628 .filter(resource => resource.kind === ResourceKind.PROCESS);
630 for (const process of processesToMove) {
631 await moveSingleProcess(process);
634 //omly propagate if this call is the original
635 if (!isSecondaryMove) {
636 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
637 kindsToMove.delete(ResourceKind.PROCESS);
639 kindsToMove.forEach(kind => {
640 secondaryMove[kind](data, true)(dispatch, getState, services);
644 async function moveSingleProcess(process: MoveableResource) {
646 const oldProcess: MoveToFormDialogData = { name: process.name, uuid: process.uuid, ownerUuid: data.ownerUuid };
647 const movedProcess = await dispatch<any>(processMoveActions.moveProcess(oldProcess));
648 dispatch<any>(updateResources([movedProcess]));
649 dispatch<any>(reloadProjectMatchingUuid([movedProcess.ownerUuid]));
651 snackbarActions.OPEN_SNACKBAR({
652 message: "Process has been moved.",
654 kind: SnackbarKind.SUCCESS,
659 snackbarActions.OPEN_SNACKBAR({
662 kind: SnackbarKind.ERROR,
669 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
671 const process = await dispatch<any>(processCopyActions.copyProcess(data));
672 dispatch<any>(updateResources([process]));
673 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
675 snackbarActions.OPEN_SNACKBAR({
676 message: "Process has been copied.",
678 kind: SnackbarKind.SUCCESS,
681 dispatch<any>(navigateTo(process.uuid));
684 snackbarActions.OPEN_SNACKBAR({
687 kind: SnackbarKind.ERROR,
693 export const resourceIsNotLoaded = (uuid: string) =>
694 snackbarActions.OPEN_SNACKBAR({
695 message: `Resource identified by ${uuid} is not loaded.`,
696 kind: SnackbarKind.ERROR,
699 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
700 message: "User is not authenticated",
701 kind: SnackbarKind.ERROR,
704 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
705 message: "Could not load user",
706 kind: SnackbarKind.ERROR,
709 export const reloadProjectMatchingUuid =
710 (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
711 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
712 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
713 dispatch<any>(loadProject(currentProjectPanelUuid));
717 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
718 dispatch<any>(loadSharedWithMePanel());
719 await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
720 await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
723 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
724 await dispatch<any>(loadRunProcessPanel());
727 export const loadPublicFavorites = () =>
728 handleFirstTimeLoad((dispatch: Dispatch) => {
729 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
730 dispatch<any>(loadPublicFavoritePanel());
731 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
734 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
735 await dispatch(loadSearchResultsPanel());
738 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
739 await dispatch(loadLinkPanel());
742 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
743 await dispatch(loadVirtualMachinesPanel());
744 dispatch(setBreadcrumbs([{ label: "Virtual Machines" }]));
747 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
748 await dispatch(loadVirtualMachinesPanel());
749 dispatch(setBreadcrumbs([{ label: "Virtual Machines Admin", icon: AdminMenuIcon }]));
752 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
753 await dispatch(loadRepositoriesPanel());
754 dispatch(setBreadcrumbs([{ label: "Repositories" }]));
757 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
758 await dispatch(loadSshKeysPanel());
761 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
762 await dispatch(loadSiteManagerPanel());
765 export const loadUserProfile = (userUuid?: string) =>
766 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
768 dispatch(setUserProfileBreadcrumbs(userUuid));
769 dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
771 dispatch(setMyAccountBreadcrumbs());
772 dispatch(userProfilePanelActions.loadUserProfilePanel());
776 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
777 dispatch(loadLinkAccountPanel());
780 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
781 await dispatch(loadKeepServicesPanel());
784 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
785 await dispatch(loadUsersPanel());
786 dispatch(setUsersBreadcrumbs());
789 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
790 await dispatch(loadApiClientAuthorizationsPanel());
793 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
794 dispatch(setGroupsBreadcrumbs());
795 dispatch(groupPanelActions.loadGroupsPanel());
798 export const loadGroupDetailsPanel = (groupUuid: string) =>
799 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
800 dispatch(setGroupDetailsBreadcrumbs(groupUuid));
801 dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
804 const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
805 const uuid = typeof project === "string" ? project : project.uuid;
806 dispatch(loadDetailsPanel(uuid));
807 if (typeof project !== "string") {
808 dispatch(updateResources([project]));
812 const loadGroupContentsResource = async (params: { uuid: string; userUuid: string; services: ServiceRepository }) => {
813 const filters = new FilterBuilder().addEqual("uuid", params.uuid).getFilters();
814 const { items } = await params.services.groupsService.contents(params.userUuid, {
819 const resource = items.shift();
820 let handler: GroupContentsHandler;
823 (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
824 ? groupContentsHandlers.TRASHED(resource)
825 : groupContentsHandlers.OWNED(resource);
827 const kind = extractUuidKind(params.uuid);
828 let resource: GroupContentsResource;
829 if (kind === ResourceKind.COLLECTION) {
830 resource = await params.services.collectionService.get(params.uuid);
831 } else if (kind === ResourceKind.PROJECT) {
832 resource = await params.services.projectService.get(params.uuid);
833 } else if (kind === ResourceKind.WORKFLOW) {
834 resource = await params.services.workflowService.get(params.uuid);
835 } else if (kind === ResourceKind.CONTAINER_REQUEST) {
836 resource = await params.services.containerRequestService.get(params.uuid);
838 throw new Error("loadGroupContentsResource unsupported kind " + kind);
840 handler = groupContentsHandlers.SHARED(resource);
842 return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) => groupContentsHandlers.match(handler, cases);
845 const groupContentsHandlersRecord = {
846 TRASHED: ofType<GroupContentsResource>(),
847 SHARED: ofType<GroupContentsResource>(),
848 OWNED: ofType<GroupContentsResource>(),
851 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
853 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;
855 type CollectionCopyResource = Resource & { name: string; fromContextMenu: boolean };
857 type MoveableResource = Resource & { name: string };
860 data: MoveToFormDialogData,
861 isSecondaryMove?: boolean
862 ) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>;
864 const secondaryMove: Record<string, MoveFunc> = {
865 [ResourceKind.PROJECT]: moveProject,
866 [ResourceKind.PROCESS]: moveProcess,
867 [ResourceKind.COLLECTION]: moveCollection,