1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import { RootState } from "store/store";
7 import { getUserUuid } from "common/getuser";
8 import { loadDetailsPanel } from "store/details-panel/details-panel-action";
9 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
10 import { favoritePanelActions, loadFavoritePanel } from "store/favorite-panel/favorite-panel-action";
11 import { getProjectPanelCurrentUuid, setIsProjectPanelTrashed } from "store/project-panel/project-panel-action";
12 import { projectPanelActions } from "store/project-panel/project-panel-action-bind";
14 activateSidePanelTreeItem,
16 loadSidePanelTreeProjects,
17 SidePanelTreeCategory,
19 } from "store/side-panel-tree/side-panel-tree-actions";
20 import { updateResources } from "store/resources/resources-actions";
21 import { projectPanelColumns } from "views/project-panel/project-panel";
22 import { favoritePanelColumns } from "views/favorite-panel/favorite-panel";
23 import { matchRootRoute } from "routes/routes";
25 setGroupDetailsBreadcrumbs,
27 setProcessBreadcrumbs,
28 setSharedWithMeBreadcrumbs,
29 setSidePanelBreadcrumbs,
32 setMyAccountBreadcrumbs,
33 setUserProfileBreadcrumbs,
34 setInstanceTypesBreadcrumbs,
35 setVirtualMachinesBreadcrumbs,
36 setVirtualMachinesAdminBreadcrumbs,
37 setRepositoriesBreadcrumbs,
38 } from "store/breadcrumbs/breadcrumbs-actions";
39 import { navigateTo, navigateToRootProject } from "store/navigation/navigation-action";
40 import { MoveToFormDialogData } from "store/move-to-dialog/move-to-dialog";
41 import { ServiceRepository } from "services/services";
42 import { getResource } from "store/resources/resources";
43 import * as projectCreateActions from "store/projects/project-create-actions";
44 import * as projectMoveActions from "store/projects/project-move-actions";
45 import * as projectUpdateActions from "store/projects/project-update-actions";
46 import * as collectionCreateActions from "store/collections/collection-create-actions";
47 import * as collectionCopyActions from "store/collections/collection-copy-actions";
48 import * as collectionMoveActions from "store/collections/collection-move-actions";
49 import * as processesActions from "store/processes/processes-actions";
50 import * as processMoveActions from "store/processes/process-move-actions";
51 import * as processUpdateActions from "store/processes/process-update-actions";
52 import * as processCopyActions from "store/processes/process-copy-actions";
53 import { trashPanelColumns } from "views/trash-panel/trash-panel";
54 import { loadTrashPanel, trashPanelActions } from "store/trash-panel/trash-panel-action";
55 import { loadProcessPanel } from "store/process-panel/process-panel-actions";
56 import { loadSharedWithMePanel, sharedWithMePanelActions } from "store/shared-with-me-panel/shared-with-me-panel-actions";
57 import { sharedWithMePanelColumns } from "views/shared-with-me-panel/shared-with-me-panel";
58 import { CopyFormDialogData } from "store/copy-dialog/copy-dialog";
59 import { workflowPanelActions } from "store/workflow-panel/workflow-panel-actions";
60 import { loadSshKeysPanel } from "store/auth/auth-action-ssh";
61 import { loadLinkAccountPanel, linkAccountPanelActions } from "store/link-account-panel/link-account-panel-actions";
62 import { loadSiteManagerPanel } from "store/auth/auth-action-session";
63 import { workflowPanelColumns } from "views/workflow-panel/workflow-panel-view";
64 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
65 import { getProgressIndicator } from "store/progress-indicator/progress-indicator-reducer";
66 import { extractUuidKind, Resource, ResourceKind } from "models/resource";
67 import { FilterBuilder } from "services/api/filter-builder";
68 import { GroupContentsResource } from "services/groups-service/groups-service";
69 import { MatchCases, ofType, unionize, UnionOf } from "common/unionize";
70 import { loadRunProcessPanel } from "store/run-process-panel/run-process-panel-actions";
71 import { collectionPanelActions, loadCollectionPanel } from "store/collection-panel/collection-panel-action";
72 import { CollectionResource } from "models/collection";
73 import { WorkflowResource } from "models/workflow";
74 import { loadSearchResultsPanel, searchResultsPanelActions } from "store/search-results-panel/search-results-panel-actions";
75 import { searchResultsPanelColumns } from "views/search-results-panel/search-results-panel-view";
76 import { loadVirtualMachinesPanel } from "store/virtual-machines/virtual-machines-actions";
77 import { loadRepositoriesPanel } from "store/repositories/repositories-actions";
78 import { loadKeepServicesPanel } from "store/keep-services/keep-services-actions";
79 import { loadUsersPanel, userBindedActions } from "store/users/users-actions";
80 import * as userProfilePanelActions from "store/user-profile/user-profile-actions";
81 import { linkPanelActions, loadLinkPanel } from "store/link-panel/link-panel-actions";
82 import { linkPanelColumns } from "views/link-panel/link-panel-root";
83 import { userPanelColumns } from "views/user-panel/user-panel";
84 import { loadApiClientAuthorizationsPanel, apiClientAuthorizationsActions } from "store/api-client-authorizations/api-client-authorizations-actions";
85 import { apiClientAuthorizationPanelColumns } from "views/api-client-authorization-panel/api-client-authorization-panel-root";
86 import * as groupPanelActions from "store/groups-panel/groups-panel-actions";
87 import { groupsPanelColumns } from "views/groups-panel/groups-panel";
88 import * as groupDetailsPanelActions from "store/group-details-panel/group-details-panel-actions";
89 import { groupDetailsMembersPanelColumns, groupDetailsPermissionsPanelColumns } from "views/group-details-panel/group-details-panel";
90 import { DataTableFetchMode } from "components/data-table/data-table";
91 import { loadPublicFavoritePanel, publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
92 import { publicFavoritePanelColumns } from "views/public-favorites-panel/public-favorites-panel";
94 loadCollectionsContentAddressPanel,
95 collectionsContentAddressActions,
96 } from "store/collections-content-address-panel/collections-content-address-panel-actions";
97 import { collectionContentAddressPanelColumns } from "views/collection-content-address-panel/collection-content-address-panel";
98 import { subprocessPanelActions } from "store/subprocess-panel/subprocess-panel-actions";
99 import { subprocessPanelColumns } from "views/subprocess-panel/subprocess-panel-root";
100 import { loadAllProcessesPanel, allProcessesPanelActions } from "../all-processes-panel/all-processes-panel-action";
101 import { allProcessesPanelColumns } from "views/all-processes-panel/all-processes-panel";
102 import { userProfileGroupsColumns } from "views/user-profile-panel/user-profile-panel-root";
103 import { selectedToArray, selectedToKindSet } from "components/multiselect-toolbar/MultiselectToolbar";
104 import { deselectOne } from "store/multiselect/multiselect-actions";
105 import { treePickerActions } from "store/tree-picker/tree-picker-actions";
106 import { workflowProcessesPanelColumns } from "views/workflow-panel/workflow-processes-panel-root";
107 import { workflowProcessesPanelActions } from "store/workflow-panel/workflow-panel-actions";
109 export const WORKBENCH_LOADING_SCREEN = "workbenchLoadingScreen";
111 export const isWorkbenchLoading = (state: RootState) => {
112 const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
113 return progress ? progress.working : false;
116 export const handleFirstTimeLoad = (action: any) => async (dispatch: Dispatch<any>, getState: () => RootState) => {
118 await dispatch(action);
120 snackbarActions.OPEN_SNACKBAR({
121 message: "Error " + e,
123 kind: SnackbarKind.WARNING,
126 if (isWorkbenchLoading(getState())) {
127 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
132 export const loadWorkbench = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
133 dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
134 const { auth, router } = getState();
135 const { user } = auth;
137 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
138 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
140 allProcessesPanelActions.SET_COLUMNS({
141 columns: allProcessesPanelColumns,
145 publicFavoritePanelActions.SET_COLUMNS({
146 columns: publicFavoritePanelColumns,
149 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
150 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: sharedWithMePanelColumns }));
151 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
153 searchResultsPanelActions.SET_FETCH_MODE({
154 fetchMode: DataTableFetchMode.INFINITE,
158 searchResultsPanelActions.SET_COLUMNS({
159 columns: searchResultsPanelColumns,
162 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
164 groupPanelActions.GroupsPanelActions.SET_COLUMNS({
165 columns: groupsPanelColumns,
169 groupDetailsPanelActions.GroupMembersPanelActions.SET_COLUMNS({
170 columns: groupDetailsMembersPanelColumns,
174 groupDetailsPanelActions.GroupPermissionsPanelActions.SET_COLUMNS({
175 columns: groupDetailsPermissionsPanelColumns,
179 userProfilePanelActions.UserProfileGroupsActions.SET_COLUMNS({
180 columns: userProfileGroupsColumns,
183 dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
185 apiClientAuthorizationsActions.SET_COLUMNS({
186 columns: apiClientAuthorizationPanelColumns,
190 collectionsContentAddressActions.SET_COLUMNS({
191 columns: collectionContentAddressPanelColumns,
194 dispatch(subprocessPanelActions.SET_COLUMNS({ columns: subprocessPanelColumns }));
195 dispatch(workflowProcessesPanelActions.SET_COLUMNS({ columns: workflowProcessesPanelColumns }));
197 if (services.linkAccountService.getAccountToLink()) {
198 dispatch(linkAccountPanelActions.HAS_SESSION_DATA());
201 dispatch<any>(initSidePanelTree());
202 if (router.location) {
203 const match = matchRootRoute(router.location.pathname);
205 dispatch<any>(navigateToRootProject);
209 dispatch(userIsNotAuthenticated);
213 export const loadFavorites = () =>
214 handleFirstTimeLoad((dispatch: Dispatch) => {
215 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
216 dispatch<any>(loadFavoritePanel());
217 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
220 export const loadCollectionContentAddress = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
221 await dispatch(loadCollectionsContentAddressPanel());
224 export const loadTrash = () =>
225 handleFirstTimeLoad((dispatch: Dispatch) => {
226 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
227 dispatch<any>(loadTrashPanel());
228 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
231 export const loadAllProcesses = () =>
232 handleFirstTimeLoad((dispatch: Dispatch) => {
233 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.ALL_PROCESSES));
234 dispatch<any>(loadAllProcessesPanel());
235 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.ALL_PROCESSES));
238 export const loadProject = (uuid: string) =>
239 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
240 const userUuid = getUserUuid(getState());
241 dispatch(setIsProjectPanelTrashed(false));
246 dispatch(progressIndicatorActions.START_WORKING(uuid));
247 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
248 // Load another users home projects
249 dispatch(finishLoadingProject(uuid));
250 dispatch<any>(setSidePanelBreadcrumbs(uuid));
251 } else if (userUuid !== uuid) {
252 await dispatch(finishLoadingProject(uuid));
253 const match = await loadGroupContentsResource({
260 await dispatch(activateSidePanelTreeItem(uuid));
261 dispatch<any>(setSidePanelBreadcrumbs(uuid));
263 SHARED: async () => {
264 await dispatch(activateSidePanelTreeItem(uuid));
265 dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
267 TRASHED: async () => {
268 await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
269 dispatch<any>(setTrashBreadcrumbs(uuid));
270 dispatch(setIsProjectPanelTrashed(true));
274 await dispatch(finishLoadingProject(userUuid));
275 await dispatch(activateSidePanelTreeItem(userUuid));
276 dispatch<any>(setSidePanelBreadcrumbs(userUuid));
279 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
283 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) => async (dispatch: Dispatch) => {
284 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
287 snackbarActions.OPEN_SNACKBAR({
288 message: "Project has been successfully created.",
290 kind: SnackbarKind.SUCCESS,
293 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
294 dispatch<any>(navigateTo(newProject.uuid));
298 export const moveProject =
299 (data: MoveToFormDialogData, isSecondaryMove = false) =>
300 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
301 const checkedList = getState().multiselect.checkedList;
302 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
304 //if no items in checkedlist default to normal context menu behavior
305 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
307 const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
308 const destinationUuid = data.ownerUuid;
310 const projectsToMove: MoveableResource[] = uuidsToMove
311 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
312 .filter(resource => resource.kind === ResourceKind.PROJECT);
314 for (const project of projectsToMove) {
315 await moveSingleProject(project);
318 //omly propagate if this call is the original
319 if (!isSecondaryMove) {
320 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
321 kindsToMove.delete(ResourceKind.PROJECT);
323 kindsToMove.forEach(kind => {
324 secondaryMove[kind](data, true)(dispatch, getState, services);
328 async function moveSingleProject(project: MoveableResource) {
330 const oldProject: MoveToFormDialogData = { name: project.name, uuid: project.uuid, ownerUuid: data.ownerUuid };
331 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
332 const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
335 snackbarActions.OPEN_SNACKBAR({
336 message: "Project has been moved",
338 kind: SnackbarKind.SUCCESS,
341 await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
345 snackbarActions.OPEN_SNACKBAR({
346 message: !!(project as any).frozenByUuid ? 'Could not move frozen project.' : e.message,
348 kind: SnackbarKind.ERROR,
353 if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
354 await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
357 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
358 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
359 if (updatedProject) {
361 snackbarActions.OPEN_SNACKBAR({
362 message: "Project has been successfully updated.",
364 kind: SnackbarKind.SUCCESS,
367 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
368 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
372 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
373 const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
376 snackbarActions.OPEN_SNACKBAR({
377 message: "Group has been successfully updated.",
379 kind: SnackbarKind.SUCCESS,
382 await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
383 dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
387 export const loadCollection = (uuid: string) =>
388 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
389 const userUuid = getUserUuid(getState());
391 dispatch(progressIndicatorActions.START_WORKING(uuid));
393 const match = await loadGroupContentsResource({
398 let collection: CollectionResource | undefined;
400 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
402 let sidepanel: string | undefined;
404 OWNED: thecollection => {
405 collection = thecollection as CollectionResource;
406 sidepanel = collection.ownerUuid;
407 breadcrumbfunc = setSidePanelBreadcrumbs;
409 SHARED: thecollection => {
410 collection = thecollection as CollectionResource;
411 sidepanel = collection.ownerUuid;
412 breadcrumbfunc = setSharedWithMeBreadcrumbs;
414 TRASHED: thecollection => {
415 collection = thecollection as CollectionResource;
416 sidepanel = SidePanelTreeCategory.TRASH;
417 breadcrumbfunc = () => setTrashBreadcrumbs("");
420 if (collection && breadcrumbfunc && sidepanel) {
421 dispatch(updateResources([collection]));
422 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
423 dispatch(collectionPanelActions.SET_COLLECTION(collection));
424 await dispatch(activateSidePanelTreeItem(sidepanel));
425 dispatch(breadcrumbfunc(collection.ownerUuid));
426 dispatch(loadCollectionPanel(collection.uuid));
430 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
434 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
435 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
438 snackbarActions.OPEN_SNACKBAR({
439 message: "Collection has been successfully created.",
441 kind: SnackbarKind.SUCCESS,
444 dispatch<any>(updateResources([collection]));
445 dispatch<any>(navigateTo(collection.uuid));
449 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
450 const checkedList = getState().multiselect.checkedList;
451 const uuidsToCopy: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
453 //if no items in checkedlist && no items passed in, default to normal context menu behavior
454 if (!uuidsToCopy.length) uuidsToCopy.push(data.uuid);
456 const collectionsToCopy: CollectionCopyResource[] = uuidsToCopy
457 .map(uuid => getResource(uuid)(getState().resources) as CollectionCopyResource)
458 .filter(resource => resource.kind === ResourceKind.COLLECTION);
460 for (const collection of collectionsToCopy) {
461 await copySingleCollection({ ...collection, ownerUuid: data.ownerUuid } as CollectionCopyResource);
464 async function copySingleCollection(copyToProject: CollectionCopyResource) {
465 const newName = data.fromContextMenu || collectionsToCopy.length === 1 ? data.name : `Copy of: ${copyToProject.name}`;
467 const collection = await dispatch<any>(
468 collectionCopyActions.copyCollection({
471 fromContextMenu: collectionsToCopy.length === 1 ? true : data.fromContextMenu,
474 if (copyToProject && collection) {
475 await dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
477 snackbarActions.OPEN_SNACKBAR({
478 message: "Collection has been copied.",
480 kind: SnackbarKind.SUCCESS,
481 link: collection.ownerUuid,
484 dispatch<any>(deselectOne(copyToProject.uuid));
488 snackbarActions.OPEN_SNACKBAR({
491 kind: SnackbarKind.ERROR,
496 dispatch(projectPanelActions.REQUEST_ITEMS());
499 export const moveCollection =
500 (data: MoveToFormDialogData, isSecondaryMove = false) =>
501 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
502 const checkedList = getState().multiselect.checkedList;
503 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
505 //if no items in checkedlist && no items passed in, default to normal context menu behavior
506 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
508 const collectionsToMove: MoveableResource[] = uuidsToMove
509 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
510 .filter(resource => resource.kind === ResourceKind.COLLECTION);
512 for (const collection of collectionsToMove) {
513 await moveSingleCollection(collection);
516 //omly propagate if this call is the original
517 if (!isSecondaryMove) {
518 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
519 kindsToMove.delete(ResourceKind.COLLECTION);
521 kindsToMove.forEach(kind => {
522 secondaryMove[kind](data, true)(dispatch, getState, services);
526 async function moveSingleCollection(collection: MoveableResource) {
528 const oldCollection: MoveToFormDialogData = { name: collection.name, uuid: collection.uuid, ownerUuid: data.ownerUuid };
529 const movedCollection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
530 dispatch<any>(updateResources([movedCollection]));
531 dispatch<any>(reloadProjectMatchingUuid([movedCollection.ownerUuid]));
533 snackbarActions.OPEN_SNACKBAR({
534 message: "Collection has been moved.",
536 kind: SnackbarKind.SUCCESS,
541 snackbarActions.OPEN_SNACKBAR({
544 kind: SnackbarKind.ERROR,
551 export const loadProcess = (uuid: string) =>
552 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
554 dispatch(progressIndicatorActions.START_WORKING(uuid));
555 dispatch<any>(loadProcessPanel(uuid));
556 const process = await dispatch<any>(processesActions.loadProcess(uuid));
558 await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
559 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
560 dispatch<any>(setProcessBreadcrumbs(uuid));
561 dispatch<any>(loadDetailsPanel(uuid));
564 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
568 export const loadRegisteredWorkflow = (uuid: string) =>
569 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
570 const userUuid = getUserUuid(getState());
572 const match = await loadGroupContentsResource({
577 let workflow: WorkflowResource | undefined;
579 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
582 OWNED: async theworkflow => {
583 workflow = theworkflow as WorkflowResource;
584 breadcrumbfunc = setSidePanelBreadcrumbs;
586 SHARED: async theworkflow => {
587 workflow = theworkflow as WorkflowResource;
588 breadcrumbfunc = setSharedWithMeBreadcrumbs;
592 if (workflow && breadcrumbfunc) {
593 dispatch(updateResources([workflow]));
594 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
595 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
596 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
597 dispatch(workflowProcessesPanelActions.REQUEST_ITEMS());
602 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
604 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
607 snackbarActions.OPEN_SNACKBAR({
608 message: "Process has been successfully updated.",
610 kind: SnackbarKind.SUCCESS,
613 dispatch<any>(updateResources([process]));
614 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
618 snackbarActions.OPEN_SNACKBAR({
621 kind: SnackbarKind.ERROR,
627 export const moveProcess =
628 (data: MoveToFormDialogData, isSecondaryMove = false) =>
629 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
630 const checkedList = getState().multiselect.checkedList;
631 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
633 //if no items in checkedlist && no items passed in, default to normal context menu behavior
634 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
636 const processesToMove: MoveableResource[] = uuidsToMove
637 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
638 .filter(resource => resource.kind === ResourceKind.PROCESS);
640 for (const process of processesToMove) {
641 await moveSingleProcess(process);
644 //omly propagate if this call is the original
645 if (!isSecondaryMove) {
646 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
647 kindsToMove.delete(ResourceKind.PROCESS);
649 kindsToMove.forEach(kind => {
650 secondaryMove[kind](data, true)(dispatch, getState, services);
654 async function moveSingleProcess(process: MoveableResource) {
656 const oldProcess: MoveToFormDialogData = { name: process.name, uuid: process.uuid, ownerUuid: data.ownerUuid };
657 const movedProcess = await dispatch<any>(processMoveActions.moveProcess(oldProcess));
658 dispatch<any>(updateResources([movedProcess]));
659 dispatch<any>(reloadProjectMatchingUuid([movedProcess.ownerUuid]));
661 snackbarActions.OPEN_SNACKBAR({
662 message: "Process has been moved.",
664 kind: SnackbarKind.SUCCESS,
669 snackbarActions.OPEN_SNACKBAR({
672 kind: SnackbarKind.ERROR,
679 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
681 const process = await dispatch<any>(processCopyActions.copyProcess(data));
682 dispatch<any>(updateResources([process]));
683 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
685 snackbarActions.OPEN_SNACKBAR({
686 message: "Process has been copied.",
688 kind: SnackbarKind.SUCCESS,
691 dispatch<any>(navigateTo(process.uuid));
694 snackbarActions.OPEN_SNACKBAR({
697 kind: SnackbarKind.ERROR,
703 export const resourceIsNotLoaded = (uuid: string) =>
704 snackbarActions.OPEN_SNACKBAR({
705 message: `Resource identified by ${uuid} is not loaded.`,
706 kind: SnackbarKind.ERROR,
709 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
710 message: "User is not authenticated",
711 kind: SnackbarKind.ERROR,
714 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
715 message: "Could not load user",
716 kind: SnackbarKind.ERROR,
719 export const reloadProjectMatchingUuid =
720 (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
721 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
722 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
723 dispatch<any>(loadProject(currentProjectPanelUuid));
727 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
728 dispatch<any>(loadSharedWithMePanel());
729 await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
730 await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
733 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
734 await dispatch<any>(loadRunProcessPanel());
737 export const loadPublicFavorites = () =>
738 handleFirstTimeLoad((dispatch: Dispatch) => {
739 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
740 dispatch<any>(loadPublicFavoritePanel());
741 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
744 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
745 await dispatch(loadSearchResultsPanel());
748 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
749 await dispatch(loadLinkPanel());
752 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
753 await dispatch(loadVirtualMachinesPanel());
754 dispatch(setVirtualMachinesBreadcrumbs());
755 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHELL_ACCESS));
758 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
759 await dispatch(loadVirtualMachinesPanel());
760 dispatch(setVirtualMachinesAdminBreadcrumbs());
761 dispatch(treePickerActions.DEACTIVATE_TREE_PICKER_NODE({ pickerId: SIDE_PANEL_TREE }))
764 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
765 await dispatch(loadRepositoriesPanel());
766 dispatch(setRepositoriesBreadcrumbs());
769 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
770 await dispatch(loadSshKeysPanel());
773 export const loadInstanceTypes = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
774 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.INSTANCE_TYPES));
775 dispatch(setInstanceTypesBreadcrumbs());
778 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
779 await dispatch(loadSiteManagerPanel());
782 export const loadUserProfile = (userUuid?: string) =>
783 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
785 dispatch(setUserProfileBreadcrumbs(userUuid));
786 dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
788 dispatch(setMyAccountBreadcrumbs());
789 dispatch(userProfilePanelActions.loadUserProfilePanel());
793 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
794 dispatch(loadLinkAccountPanel());
797 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
798 await dispatch(loadKeepServicesPanel());
801 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
802 await dispatch(loadUsersPanel());
803 dispatch(setUsersBreadcrumbs());
806 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
807 await dispatch(loadApiClientAuthorizationsPanel());
810 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
811 dispatch(setGroupsBreadcrumbs());
812 dispatch(groupPanelActions.loadGroupsPanel());
815 export const loadGroupDetailsPanel = (groupUuid: string) =>
816 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
817 dispatch(setGroupDetailsBreadcrumbs(groupUuid));
818 dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
821 const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
822 const uuid = typeof project === "string" ? project : project.uuid;
823 dispatch(loadDetailsPanel(uuid));
824 if (typeof project !== "string") {
825 dispatch(updateResources([project]));
829 const loadGroupContentsResource = async (params: { uuid: string; userUuid: string; services: ServiceRepository }) => {
830 const filters = new FilterBuilder().addEqual("uuid", params.uuid).getFilters();
831 const { items } = await params.services.groupsService.contents(params.userUuid, {
836 const resource = items.shift();
837 let handler: GroupContentsHandler;
840 (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
841 ? groupContentsHandlers.TRASHED(resource)
842 : groupContentsHandlers.OWNED(resource);
844 const kind = extractUuidKind(params.uuid);
845 let resource: GroupContentsResource;
846 if (kind === ResourceKind.COLLECTION) {
847 resource = await params.services.collectionService.get(params.uuid);
848 } else if (kind === ResourceKind.PROJECT) {
849 resource = await params.services.projectService.get(params.uuid);
850 } else if (kind === ResourceKind.WORKFLOW) {
851 resource = await params.services.workflowService.get(params.uuid);
852 } else if (kind === ResourceKind.CONTAINER_REQUEST) {
853 resource = await params.services.containerRequestService.get(params.uuid);
855 throw new Error("loadGroupContentsResource unsupported kind " + kind);
857 handler = groupContentsHandlers.SHARED(resource);
859 return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) => groupContentsHandlers.match(handler, cases);
862 const groupContentsHandlersRecord = {
863 TRASHED: ofType<GroupContentsResource>(),
864 SHARED: ofType<GroupContentsResource>(),
865 OWNED: ofType<GroupContentsResource>(),
868 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
870 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;
872 type CollectionCopyResource = Resource & { name: string; fromContextMenu: boolean };
874 type MoveableResource = Resource & { name: string };
877 data: MoveToFormDialogData,
878 isSecondaryMove?: boolean
879 ) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>;
881 const secondaryMove: Record<string, MoveFunc> = {
882 [ResourceKind.PROJECT]: moveProject,
883 [ResourceKind.PROCESS]: moveProcess,
884 [ResourceKind.COLLECTION]: moveCollection,