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 { projectPanelDataActions, projectPanelRunActions } 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 { projectPanelDataColumns } from "views/project-panel/project-panel-data";
22 import { projectPanelRunColumns } from "views/project-panel/project-panel-run";
23 import { favoritePanelColumns } from "views/favorite-panel/favorite-panel";
24 import { matchRootRoute } from "routes/routes";
26 setGroupDetailsBreadcrumbs,
28 setProcessBreadcrumbs,
29 setSharedWithMeBreadcrumbs,
30 setSidePanelBreadcrumbs,
33 setMyAccountBreadcrumbs,
34 setUserProfileBreadcrumbs,
35 setInstanceTypesBreadcrumbs,
36 setVirtualMachinesBreadcrumbs,
37 setVirtualMachinesAdminBreadcrumbs,
38 setRepositoriesBreadcrumbs,
39 } from "store/breadcrumbs/breadcrumbs-actions";
40 import { navigateTo, navigateToRootProject } from "store/navigation/navigation-action";
41 import { MoveToFormDialogData } from "store/move-to-dialog/move-to-dialog";
42 import { ServiceRepository } from "services/services";
43 import { getResource } from "store/resources/resources";
44 import * as projectCreateActions from "store/projects/project-create-actions";
45 import * as projectMoveActions from "store/projects/project-move-actions";
46 import * as projectUpdateActions from "store/projects/project-update-actions";
47 import * as collectionCreateActions from "store/collections/collection-create-actions";
48 import * as collectionCopyActions from "store/collections/collection-copy-actions";
49 import * as collectionMoveActions from "store/collections/collection-move-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 { loadProcess as loadProcessResources, 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(projectPanelDataActions.SET_COLUMNS({ columns: projectPanelDataColumns }));
138 dispatch(projectPanelRunActions.SET_COLUMNS({ columns: projectPanelRunColumns }));
139 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
141 allProcessesPanelActions.SET_COLUMNS({
142 columns: allProcessesPanelColumns,
146 publicFavoritePanelActions.SET_COLUMNS({
147 columns: publicFavoritePanelColumns,
150 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
151 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: sharedWithMePanelColumns }));
152 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
154 searchResultsPanelActions.SET_FETCH_MODE({
155 fetchMode: DataTableFetchMode.INFINITE,
159 searchResultsPanelActions.SET_COLUMNS({
160 columns: searchResultsPanelColumns,
163 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
165 groupPanelActions.GroupsPanelActions.SET_COLUMNS({
166 columns: groupsPanelColumns,
170 groupDetailsPanelActions.GroupMembersPanelActions.SET_COLUMNS({
171 columns: groupDetailsMembersPanelColumns,
175 groupDetailsPanelActions.GroupPermissionsPanelActions.SET_COLUMNS({
176 columns: groupDetailsPermissionsPanelColumns,
180 userProfilePanelActions.UserProfileGroupsActions.SET_COLUMNS({
181 columns: userProfileGroupsColumns,
184 dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
186 apiClientAuthorizationsActions.SET_COLUMNS({
187 columns: apiClientAuthorizationPanelColumns,
191 collectionsContentAddressActions.SET_COLUMNS({
192 columns: collectionContentAddressPanelColumns,
195 dispatch(subprocessPanelActions.SET_COLUMNS({ columns: subprocessPanelColumns }));
196 dispatch(workflowProcessesPanelActions.SET_COLUMNS({ columns: workflowProcessesPanelColumns }));
198 if (services.linkAccountService.getAccountToLink()) {
199 dispatch(linkAccountPanelActions.HAS_SESSION_DATA());
202 dispatch<any>(initSidePanelTree());
203 if (router.location) {
204 const match = matchRootRoute(router.location.pathname);
206 dispatch<any>(navigateToRootProject);
210 dispatch(userIsNotAuthenticated);
214 export const loadFavorites = () =>
215 handleFirstTimeLoad((dispatch: Dispatch) => {
216 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
217 dispatch<any>(loadFavoritePanel());
218 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
221 export const loadCollectionContentAddress = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
222 await dispatch(loadCollectionsContentAddressPanel());
225 export const loadTrash = () =>
226 handleFirstTimeLoad((dispatch: Dispatch) => {
227 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
228 dispatch<any>(loadTrashPanel());
229 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
232 export const loadAllProcesses = () =>
233 handleFirstTimeLoad((dispatch: Dispatch) => {
234 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.ALL_PROCESSES));
235 dispatch<any>(loadAllProcessesPanel());
236 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.ALL_PROCESSES));
239 export const loadProject = (uuid: string) =>
240 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
241 const userUuid = getUserUuid(getState());
242 dispatch(setIsProjectPanelTrashed(false));
247 dispatch(progressIndicatorActions.START_WORKING(uuid));
248 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
249 // Load another users home projects
250 dispatch(finishLoadingProject(uuid));
251 dispatch<any>(setSidePanelBreadcrumbs(uuid));
252 } else if (userUuid !== uuid) {
253 await dispatch(finishLoadingProject(uuid));
254 const match = await loadGroupContentsResource({
261 await dispatch(activateSidePanelTreeItem(uuid));
262 dispatch<any>(setSidePanelBreadcrumbs(uuid));
264 SHARED: async () => {
265 await dispatch(activateSidePanelTreeItem(uuid));
266 dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
268 TRASHED: async () => {
269 await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
270 dispatch<any>(setTrashBreadcrumbs(uuid));
271 dispatch(setIsProjectPanelTrashed(true));
275 await dispatch(finishLoadingProject(userUuid));
276 await dispatch(activateSidePanelTreeItem(userUuid));
277 dispatch<any>(setSidePanelBreadcrumbs(userUuid));
280 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
284 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) => async (dispatch: Dispatch) => {
285 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
288 snackbarActions.OPEN_SNACKBAR({
289 message: "Project has been successfully created.",
291 kind: SnackbarKind.SUCCESS,
294 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
295 dispatch<any>(navigateTo(newProject.uuid));
299 export const moveProject =
300 (data: MoveToFormDialogData, isSecondaryMove = false) =>
301 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
302 const checkedList = getState().multiselect.checkedList;
303 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
305 //if no items in checkedlist default to normal context menu behavior
306 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
308 const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
309 const destinationUuid = data.ownerUuid;
311 const projectsToMove: MoveableResource[] = uuidsToMove
312 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
313 .filter(resource => resource.kind === ResourceKind.PROJECT);
315 for (const project of projectsToMove) {
316 await moveSingleProject(project);
319 //omly propagate if this call is the original
320 if (!isSecondaryMove) {
321 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
322 kindsToMove.delete(ResourceKind.PROJECT);
324 kindsToMove.forEach(kind => {
325 secondaryMove[kind](data, true)(dispatch, getState, services);
329 async function moveSingleProject(project: MoveableResource) {
331 const oldProject: MoveToFormDialogData = { name: project.name, uuid: project.uuid, ownerUuid: data.ownerUuid };
332 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
333 const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
336 snackbarActions.OPEN_SNACKBAR({
337 message: "Project has been moved",
339 kind: SnackbarKind.SUCCESS,
342 await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
346 snackbarActions.OPEN_SNACKBAR({
347 message: !!(project as any).frozenByUuid ? 'Could not move frozen project.' : e.message,
349 kind: SnackbarKind.ERROR,
354 if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
355 await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
358 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
359 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
360 if (updatedProject) {
362 snackbarActions.OPEN_SNACKBAR({
363 message: "Project has been successfully updated.",
365 kind: SnackbarKind.SUCCESS,
368 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
369 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
373 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
374 const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
377 snackbarActions.OPEN_SNACKBAR({
378 message: "Group has been successfully updated.",
380 kind: SnackbarKind.SUCCESS,
383 await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
384 dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
388 export const loadCollection = (uuid: string) =>
389 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
390 const userUuid = getUserUuid(getState());
392 dispatch(progressIndicatorActions.START_WORKING(uuid));
394 const match = await loadGroupContentsResource({
399 let collection: CollectionResource | undefined;
401 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
403 let sidepanel: string | undefined;
405 OWNED: thecollection => {
406 collection = thecollection as CollectionResource;
407 sidepanel = collection.ownerUuid;
408 breadcrumbfunc = setSidePanelBreadcrumbs;
410 SHARED: thecollection => {
411 collection = thecollection as CollectionResource;
412 sidepanel = collection.ownerUuid;
413 breadcrumbfunc = setSharedWithMeBreadcrumbs;
415 TRASHED: thecollection => {
416 collection = thecollection as CollectionResource;
417 sidepanel = SidePanelTreeCategory.TRASH;
418 breadcrumbfunc = () => setTrashBreadcrumbs("");
421 if (collection && breadcrumbfunc && sidepanel) {
422 dispatch(updateResources([collection]));
423 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
424 dispatch(collectionPanelActions.SET_COLLECTION(collection));
425 await dispatch(activateSidePanelTreeItem(sidepanel));
426 dispatch(breadcrumbfunc(collection.ownerUuid));
427 dispatch(loadCollectionPanel(collection.uuid));
431 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
435 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
436 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
439 snackbarActions.OPEN_SNACKBAR({
440 message: "Collection has been successfully created.",
442 kind: SnackbarKind.SUCCESS,
445 dispatch<any>(updateResources([collection]));
446 dispatch<any>(navigateTo(collection.uuid));
450 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
451 const checkedList = getState().multiselect.checkedList;
452 const uuidsToCopy: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
454 //if no items in checkedlist && no items passed in, default to normal context menu behavior
455 if (!uuidsToCopy.length) uuidsToCopy.push(data.uuid);
457 const collectionsToCopy: CollectionCopyResource[] = uuidsToCopy
458 .map(uuid => getResource(uuid)(getState().resources) as CollectionCopyResource)
459 .filter(resource => resource.kind === ResourceKind.COLLECTION);
461 for (const collection of collectionsToCopy) {
462 await copySingleCollection({ ...collection, ownerUuid: data.ownerUuid } as CollectionCopyResource);
465 async function copySingleCollection(copyToProject: CollectionCopyResource) {
466 const newName = data.fromContextMenu || collectionsToCopy.length === 1 ? data.name : `Copy of: ${copyToProject.name}`;
468 const collection = await dispatch<any>(
469 collectionCopyActions.copyCollection({
472 fromContextMenu: collectionsToCopy.length === 1 ? true : data.fromContextMenu,
475 if (copyToProject && collection) {
476 await dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
478 snackbarActions.OPEN_SNACKBAR({
479 message: "Collection has been copied.",
481 kind: SnackbarKind.SUCCESS,
482 link: collection.ownerUuid,
485 dispatch<any>(deselectOne(copyToProject.uuid));
489 snackbarActions.OPEN_SNACKBAR({
492 kind: SnackbarKind.ERROR,
497 dispatch(projectPanelDataActions.REQUEST_ITEMS());
500 export const moveCollection =
501 (data: MoveToFormDialogData, isSecondaryMove = false) =>
502 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
503 const checkedList = getState().multiselect.checkedList;
504 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
506 //if no items in checkedlist && no items passed in, default to normal context menu behavior
507 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
509 const collectionsToMove: MoveableResource[] = uuidsToMove
510 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
511 .filter(resource => resource.kind === ResourceKind.COLLECTION);
513 for (const collection of collectionsToMove) {
514 await moveSingleCollection(collection);
517 //omly propagate if this call is the original
518 if (!isSecondaryMove) {
519 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
520 kindsToMove.delete(ResourceKind.COLLECTION);
522 kindsToMove.forEach(kind => {
523 secondaryMove[kind](data, true)(dispatch, getState, services);
527 async function moveSingleCollection(collection: MoveableResource) {
529 const oldCollection: MoveToFormDialogData = { name: collection.name, uuid: collection.uuid, ownerUuid: data.ownerUuid };
530 const movedCollection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
531 dispatch<any>(updateResources([movedCollection]));
532 dispatch<any>(reloadProjectMatchingUuid([movedCollection.ownerUuid]));
534 snackbarActions.OPEN_SNACKBAR({
535 message: "Collection has been moved.",
537 kind: SnackbarKind.SUCCESS,
542 snackbarActions.OPEN_SNACKBAR({
545 kind: SnackbarKind.ERROR,
552 export const loadProcess = (uuid: string) =>
553 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
555 dispatch(progressIndicatorActions.START_WORKING(uuid));
556 dispatch<any>(loadProcessPanel(uuid));
557 const process = await dispatch<any>(loadProcessResources(uuid));
559 await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
560 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
561 dispatch<any>(setProcessBreadcrumbs(uuid));
562 dispatch<any>(loadDetailsPanel(uuid));
565 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
569 export const loadRegisteredWorkflow = (uuid: string) =>
570 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
571 const userUuid = getUserUuid(getState());
573 const match = await loadGroupContentsResource({
578 let workflow: WorkflowResource | undefined;
580 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
583 OWNED: async theworkflow => {
584 workflow = theworkflow as WorkflowResource;
585 breadcrumbfunc = setSidePanelBreadcrumbs;
587 SHARED: async theworkflow => {
588 workflow = theworkflow as WorkflowResource;
589 breadcrumbfunc = setSharedWithMeBreadcrumbs;
593 if (workflow && breadcrumbfunc) {
594 dispatch(updateResources([workflow]));
595 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
596 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
597 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
598 dispatch(workflowProcessesPanelActions.REQUEST_ITEMS());
603 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
605 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
608 snackbarActions.OPEN_SNACKBAR({
609 message: "Process has been successfully updated.",
611 kind: SnackbarKind.SUCCESS,
614 dispatch<any>(updateResources([process]));
615 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
619 snackbarActions.OPEN_SNACKBAR({
622 kind: SnackbarKind.ERROR,
628 export const moveProcess =
629 (data: MoveToFormDialogData, isSecondaryMove = false) =>
630 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
631 const checkedList = getState().multiselect.checkedList;
632 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
634 //if no items in checkedlist && no items passed in, default to normal context menu behavior
635 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
637 const processesToMove: MoveableResource[] = uuidsToMove
638 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
639 .filter(resource => resource.kind === ResourceKind.PROCESS);
641 for (const process of processesToMove) {
642 await moveSingleProcess(process);
645 //omly propagate if this call is the original
646 if (!isSecondaryMove) {
647 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
648 kindsToMove.delete(ResourceKind.PROCESS);
650 kindsToMove.forEach(kind => {
651 secondaryMove[kind](data, true)(dispatch, getState, services);
655 async function moveSingleProcess(process: MoveableResource) {
657 const oldProcess: MoveToFormDialogData = { name: process.name, uuid: process.uuid, ownerUuid: data.ownerUuid };
658 const movedProcess = await dispatch<any>(processMoveActions.moveProcess(oldProcess));
659 dispatch<any>(updateResources([movedProcess]));
660 dispatch<any>(reloadProjectMatchingUuid([movedProcess.ownerUuid]));
662 snackbarActions.OPEN_SNACKBAR({
663 message: "Process has been moved.",
665 kind: SnackbarKind.SUCCESS,
670 snackbarActions.OPEN_SNACKBAR({
673 kind: SnackbarKind.ERROR,
680 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
682 const process = await dispatch<any>(processCopyActions.copyProcess(data));
683 dispatch<any>(updateResources([process]));
684 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
686 snackbarActions.OPEN_SNACKBAR({
687 message: "Process has been copied.",
689 kind: SnackbarKind.SUCCESS,
692 dispatch<any>(navigateTo(process.uuid));
695 snackbarActions.OPEN_SNACKBAR({
698 kind: SnackbarKind.ERROR,
704 export const resourceIsNotLoaded = (uuid: string) =>
705 snackbarActions.OPEN_SNACKBAR({
706 message: `Resource identified by ${uuid} is not loaded.`,
707 kind: SnackbarKind.ERROR,
710 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
711 message: "User is not authenticated",
712 kind: SnackbarKind.ERROR,
715 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
716 message: "Could not load user",
717 kind: SnackbarKind.ERROR,
720 export const reloadProjectMatchingUuid =
721 (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
722 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
723 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
724 dispatch<any>(loadProject(currentProjectPanelUuid));
728 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
729 dispatch<any>(loadSharedWithMePanel());
730 await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
731 await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
734 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
735 await dispatch<any>(loadRunProcessPanel());
738 export const loadPublicFavorites = () =>
739 handleFirstTimeLoad((dispatch: Dispatch) => {
740 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
741 dispatch<any>(loadPublicFavoritePanel());
742 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
745 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
746 await dispatch(loadSearchResultsPanel());
749 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
750 await dispatch(loadLinkPanel());
753 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
754 await dispatch(loadVirtualMachinesPanel());
755 dispatch(setVirtualMachinesBreadcrumbs());
756 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHELL_ACCESS));
759 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
760 await dispatch(loadVirtualMachinesPanel());
761 dispatch(setVirtualMachinesAdminBreadcrumbs());
762 dispatch(treePickerActions.DEACTIVATE_TREE_PICKER_NODE({ pickerId: SIDE_PANEL_TREE }))
765 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
766 await dispatch(loadRepositoriesPanel());
767 dispatch(setRepositoriesBreadcrumbs());
770 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
771 await dispatch(loadSshKeysPanel());
774 export const loadInstanceTypes = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
775 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.INSTANCE_TYPES));
776 dispatch(setInstanceTypesBreadcrumbs());
779 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
780 await dispatch(loadSiteManagerPanel());
783 export const loadUserProfile = (userUuid?: string) =>
784 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
786 dispatch(setUserProfileBreadcrumbs(userUuid));
787 dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
789 dispatch(setMyAccountBreadcrumbs());
790 dispatch(userProfilePanelActions.loadUserProfilePanel());
794 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
795 dispatch(loadLinkAccountPanel());
798 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
799 await dispatch(loadKeepServicesPanel());
802 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
803 await dispatch(loadUsersPanel());
804 dispatch(setUsersBreadcrumbs());
807 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
808 await dispatch(loadApiClientAuthorizationsPanel());
811 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
812 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.GROUPS));
813 dispatch(setGroupsBreadcrumbs());
814 dispatch(groupPanelActions.loadGroupsPanel());
817 export const loadGroupDetailsPanel = (groupUuid: string) =>
818 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
819 dispatch(setGroupDetailsBreadcrumbs(groupUuid));
820 dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
823 const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
824 const uuid = typeof project === "string" ? project : project.uuid;
825 dispatch(loadDetailsPanel(uuid));
826 if (typeof project !== "string") {
827 dispatch(updateResources([project]));
831 const loadGroupContentsResource = async (params: { uuid: string; userUuid: string; services: ServiceRepository }) => {
832 const filters = new FilterBuilder().addEqual("uuid", params.uuid).getFilters();
833 const { items } = await params.services.groupsService.contents(params.userUuid, {
838 const resource = items.shift();
839 let handler: GroupContentsHandler;
842 (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
843 ? groupContentsHandlers.TRASHED(resource)
844 : groupContentsHandlers.OWNED(resource);
846 const kind = extractUuidKind(params.uuid);
847 let resource: GroupContentsResource;
848 if (kind === ResourceKind.COLLECTION) {
849 resource = await params.services.collectionService.get(params.uuid);
850 } else if (kind === ResourceKind.PROJECT) {
851 resource = await params.services.projectService.get(params.uuid);
852 } else if (kind === ResourceKind.WORKFLOW) {
853 resource = await params.services.workflowService.get(params.uuid);
854 } else if (kind === ResourceKind.CONTAINER_REQUEST) {
855 resource = await params.services.containerRequestService.get(params.uuid);
857 throw new Error("loadGroupContentsResource unsupported kind " + kind);
859 handler = groupContentsHandlers.SHARED(resource);
861 return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) => groupContentsHandlers.match(handler, cases);
864 const groupContentsHandlersRecord = {
865 TRASHED: ofType<GroupContentsResource>(),
866 SHARED: ofType<GroupContentsResource>(),
867 OWNED: ofType<GroupContentsResource>(),
870 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
872 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;
874 type CollectionCopyResource = Resource & { name: string; fromContextMenu: boolean };
876 type MoveableResource = Resource & { name: string };
879 data: MoveToFormDialogData,
880 isSecondaryMove?: boolean
881 ) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>;
883 const secondaryMove: Record<string, MoveFunc> = {
884 [ResourceKind.PROJECT]: moveProject,
885 [ResourceKind.PROCESS]: moveProcess,
886 [ResourceKind.COLLECTION]: moveCollection,