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 processesActions from "store/processes/processes-actions";
51 import * as processMoveActions from "store/processes/process-move-actions";
52 import * as processUpdateActions from "store/processes/process-update-actions";
53 import * as processCopyActions from "store/processes/process-copy-actions";
54 import { trashPanelColumns } from "views/trash-panel/trash-panel";
55 import { loadTrashPanel, trashPanelActions } from "store/trash-panel/trash-panel-action";
56 import { loadProcessPanel } from "store/process-panel/process-panel-actions";
57 import { loadSharedWithMePanel, sharedWithMePanelActions } from "store/shared-with-me-panel/shared-with-me-panel-actions";
58 import { sharedWithMePanelColumns } from "views/shared-with-me-panel/shared-with-me-panel";
59 import { CopyFormDialogData } from "store/copy-dialog/copy-dialog";
60 import { workflowPanelActions } from "store/workflow-panel/workflow-panel-actions";
61 import { loadSshKeysPanel } from "store/auth/auth-action-ssh";
62 import { loadLinkAccountPanel, linkAccountPanelActions } from "store/link-account-panel/link-account-panel-actions";
63 import { loadSiteManagerPanel } from "store/auth/auth-action-session";
64 import { workflowPanelColumns } from "views/workflow-panel/workflow-panel-view";
65 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
66 import { getProgressIndicator } from "store/progress-indicator/progress-indicator-reducer";
67 import { extractUuidKind, Resource, ResourceKind } from "models/resource";
68 import { FilterBuilder } from "services/api/filter-builder";
69 import { GroupContentsResource } from "services/groups-service/groups-service";
70 import { MatchCases, ofType, unionize, UnionOf } from "common/unionize";
71 import { loadRunProcessPanel } from "store/run-process-panel/run-process-panel-actions";
72 import { collectionPanelActions, loadCollectionPanel } from "store/collection-panel/collection-panel-action";
73 import { CollectionResource } from "models/collection";
74 import { WorkflowResource } from "models/workflow";
75 import { loadSearchResultsPanel, searchResultsPanelActions } from "store/search-results-panel/search-results-panel-actions";
76 import { searchResultsPanelColumns } from "views/search-results-panel/search-results-panel-view";
77 import { loadVirtualMachinesPanel } from "store/virtual-machines/virtual-machines-actions";
78 import { loadRepositoriesPanel } from "store/repositories/repositories-actions";
79 import { loadKeepServicesPanel } from "store/keep-services/keep-services-actions";
80 import { loadUsersPanel, userBindedActions } from "store/users/users-actions";
81 import * as userProfilePanelActions from "store/user-profile/user-profile-actions";
82 import { linkPanelActions, loadLinkPanel } from "store/link-panel/link-panel-actions";
83 import { linkPanelColumns } from "views/link-panel/link-panel-root";
84 import { userPanelColumns } from "views/user-panel/user-panel";
85 import { loadApiClientAuthorizationsPanel, apiClientAuthorizationsActions } from "store/api-client-authorizations/api-client-authorizations-actions";
86 import { apiClientAuthorizationPanelColumns } from "views/api-client-authorization-panel/api-client-authorization-panel-root";
87 import * as groupPanelActions from "store/groups-panel/groups-panel-actions";
88 import { groupsPanelColumns } from "views/groups-panel/groups-panel";
89 import * as groupDetailsPanelActions from "store/group-details-panel/group-details-panel-actions";
90 import { groupDetailsMembersPanelColumns, groupDetailsPermissionsPanelColumns } from "views/group-details-panel/group-details-panel";
91 import { DataTableFetchMode } from "components/data-table/data-table";
92 import { loadPublicFavoritePanel, publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
93 import { publicFavoritePanelColumns } from "views/public-favorites-panel/public-favorites-panel";
95 loadCollectionsContentAddressPanel,
96 collectionsContentAddressActions,
97 } from "store/collections-content-address-panel/collections-content-address-panel-actions";
98 import { collectionContentAddressPanelColumns } from "views/collection-content-address-panel/collection-content-address-panel";
99 import { subprocessPanelActions } from "store/subprocess-panel/subprocess-panel-actions";
100 import { subprocessPanelColumns } from "views/subprocess-panel/subprocess-panel-root";
101 import { loadAllProcessesPanel, allProcessesPanelActions } from "../all-processes-panel/all-processes-panel-action";
102 import { allProcessesPanelColumns } from "views/all-processes-panel/all-processes-panel";
103 import { userProfileGroupsColumns } from "views/user-profile-panel/user-profile-panel-root";
104 import { selectedToArray, selectedToKindSet } from "components/multiselect-toolbar/MultiselectToolbar";
105 import { deselectOne } from "store/multiselect/multiselect-actions";
106 import { treePickerActions } from "store/tree-picker/tree-picker-actions";
107 import { workflowProcessesPanelColumns } from "views/workflow-panel/workflow-processes-panel-root";
108 import { workflowProcessesPanelActions } from "store/workflow-panel/workflow-panel-actions";
110 export const WORKBENCH_LOADING_SCREEN = "workbenchLoadingScreen";
112 export const isWorkbenchLoading = (state: RootState) => {
113 const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
114 return progress ? progress.working : false;
117 export const handleFirstTimeLoad = (action: any) => async (dispatch: Dispatch<any>, getState: () => RootState) => {
119 await dispatch(action);
121 snackbarActions.OPEN_SNACKBAR({
122 message: "Error " + e,
124 kind: SnackbarKind.WARNING,
127 if (isWorkbenchLoading(getState())) {
128 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
133 export const loadWorkbench = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
134 dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
135 const { auth, router } = getState();
136 const { user } = auth;
138 dispatch(projectPanelDataActions.SET_COLUMNS({ columns: projectPanelDataColumns }));
139 dispatch(projectPanelRunActions.SET_COLUMNS({ columns: projectPanelRunColumns }));
140 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
142 allProcessesPanelActions.SET_COLUMNS({
143 columns: allProcessesPanelColumns,
147 publicFavoritePanelActions.SET_COLUMNS({
148 columns: publicFavoritePanelColumns,
151 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
152 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: sharedWithMePanelColumns }));
153 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
155 searchResultsPanelActions.SET_FETCH_MODE({
156 fetchMode: DataTableFetchMode.INFINITE,
160 searchResultsPanelActions.SET_COLUMNS({
161 columns: searchResultsPanelColumns,
164 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
166 groupPanelActions.GroupsPanelActions.SET_COLUMNS({
167 columns: groupsPanelColumns,
171 groupDetailsPanelActions.GroupMembersPanelActions.SET_COLUMNS({
172 columns: groupDetailsMembersPanelColumns,
176 groupDetailsPanelActions.GroupPermissionsPanelActions.SET_COLUMNS({
177 columns: groupDetailsPermissionsPanelColumns,
181 userProfilePanelActions.UserProfileGroupsActions.SET_COLUMNS({
182 columns: userProfileGroupsColumns,
185 dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
187 apiClientAuthorizationsActions.SET_COLUMNS({
188 columns: apiClientAuthorizationPanelColumns,
192 collectionsContentAddressActions.SET_COLUMNS({
193 columns: collectionContentAddressPanelColumns,
196 dispatch(subprocessPanelActions.SET_COLUMNS({ columns: subprocessPanelColumns }));
197 dispatch(workflowProcessesPanelActions.SET_COLUMNS({ columns: workflowProcessesPanelColumns }));
199 if (services.linkAccountService.getAccountToLink()) {
200 dispatch(linkAccountPanelActions.HAS_SESSION_DATA());
203 dispatch<any>(initSidePanelTree());
204 if (router.location) {
205 const match = matchRootRoute(router.location.pathname);
207 dispatch<any>(navigateToRootProject);
211 dispatch(userIsNotAuthenticated);
215 export const loadFavorites = () =>
216 handleFirstTimeLoad((dispatch: Dispatch) => {
217 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
218 dispatch<any>(loadFavoritePanel());
219 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
222 export const loadCollectionContentAddress = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
223 await dispatch(loadCollectionsContentAddressPanel());
226 export const loadTrash = () =>
227 handleFirstTimeLoad((dispatch: Dispatch) => {
228 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
229 dispatch<any>(loadTrashPanel());
230 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
233 export const loadAllProcesses = () =>
234 handleFirstTimeLoad((dispatch: Dispatch) => {
235 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.ALL_PROCESSES));
236 dispatch<any>(loadAllProcessesPanel());
237 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.ALL_PROCESSES));
240 export const loadProject = (uuid: string) =>
241 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
242 const userUuid = getUserUuid(getState());
243 dispatch(setIsProjectPanelTrashed(false));
248 dispatch(progressIndicatorActions.START_WORKING(uuid));
249 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
250 // Load another users home projects
251 dispatch(finishLoadingProject(uuid));
252 dispatch<any>(setSidePanelBreadcrumbs(uuid));
253 } else if (userUuid !== uuid) {
254 await dispatch(finishLoadingProject(uuid));
255 const match = await loadGroupContentsResource({
262 await dispatch(activateSidePanelTreeItem(uuid));
263 dispatch<any>(setSidePanelBreadcrumbs(uuid));
265 SHARED: async () => {
266 await dispatch(activateSidePanelTreeItem(uuid));
267 dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
269 TRASHED: async () => {
270 await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
271 dispatch<any>(setTrashBreadcrumbs(uuid));
272 dispatch(setIsProjectPanelTrashed(true));
276 await dispatch(finishLoadingProject(userUuid));
277 await dispatch(activateSidePanelTreeItem(userUuid));
278 dispatch<any>(setSidePanelBreadcrumbs(userUuid));
281 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
285 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) => async (dispatch: Dispatch) => {
286 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
289 snackbarActions.OPEN_SNACKBAR({
290 message: "Project has been successfully created.",
292 kind: SnackbarKind.SUCCESS,
295 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
296 dispatch<any>(navigateTo(newProject.uuid));
300 export const moveProject =
301 (data: MoveToFormDialogData, isSecondaryMove = false) =>
302 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
303 const checkedList = getState().multiselect.checkedList;
304 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
306 //if no items in checkedlist default to normal context menu behavior
307 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
309 const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
310 const destinationUuid = data.ownerUuid;
312 const projectsToMove: MoveableResource[] = uuidsToMove
313 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
314 .filter(resource => resource.kind === ResourceKind.PROJECT);
316 for (const project of projectsToMove) {
317 await moveSingleProject(project);
320 //omly propagate if this call is the original
321 if (!isSecondaryMove) {
322 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
323 kindsToMove.delete(ResourceKind.PROJECT);
325 kindsToMove.forEach(kind => {
326 secondaryMove[kind](data, true)(dispatch, getState, services);
330 async function moveSingleProject(project: MoveableResource) {
332 const oldProject: MoveToFormDialogData = { name: project.name, uuid: project.uuid, ownerUuid: data.ownerUuid };
333 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
334 const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
337 snackbarActions.OPEN_SNACKBAR({
338 message: "Project has been moved",
340 kind: SnackbarKind.SUCCESS,
343 await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
347 snackbarActions.OPEN_SNACKBAR({
348 message: !!(project as any).frozenByUuid ? 'Could not move frozen project.' : e.message,
350 kind: SnackbarKind.ERROR,
355 if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
356 await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
359 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
360 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
361 if (updatedProject) {
363 snackbarActions.OPEN_SNACKBAR({
364 message: "Project has been successfully updated.",
366 kind: SnackbarKind.SUCCESS,
369 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
370 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
374 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
375 const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
378 snackbarActions.OPEN_SNACKBAR({
379 message: "Group has been successfully updated.",
381 kind: SnackbarKind.SUCCESS,
384 await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
385 dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
389 export const loadCollection = (uuid: string) =>
390 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
391 const userUuid = getUserUuid(getState());
393 dispatch(progressIndicatorActions.START_WORKING(uuid));
395 const match = await loadGroupContentsResource({
400 let collection: CollectionResource | undefined;
402 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
404 let sidepanel: string | undefined;
406 OWNED: thecollection => {
407 collection = thecollection as CollectionResource;
408 sidepanel = collection.ownerUuid;
409 breadcrumbfunc = setSidePanelBreadcrumbs;
411 SHARED: thecollection => {
412 collection = thecollection as CollectionResource;
413 sidepanel = collection.ownerUuid;
414 breadcrumbfunc = setSharedWithMeBreadcrumbs;
416 TRASHED: thecollection => {
417 collection = thecollection as CollectionResource;
418 sidepanel = SidePanelTreeCategory.TRASH;
419 breadcrumbfunc = () => setTrashBreadcrumbs("");
422 if (collection && breadcrumbfunc && sidepanel) {
423 dispatch(updateResources([collection]));
424 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
425 dispatch(collectionPanelActions.SET_COLLECTION(collection));
426 await dispatch(activateSidePanelTreeItem(sidepanel));
427 dispatch(breadcrumbfunc(collection.ownerUuid));
428 dispatch(loadCollectionPanel(collection.uuid));
432 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
436 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
437 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
440 snackbarActions.OPEN_SNACKBAR({
441 message: "Collection has been successfully created.",
443 kind: SnackbarKind.SUCCESS,
446 dispatch<any>(updateResources([collection]));
447 dispatch<any>(navigateTo(collection.uuid));
451 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
452 const checkedList = getState().multiselect.checkedList;
453 const uuidsToCopy: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
455 //if no items in checkedlist && no items passed in, default to normal context menu behavior
456 if (!uuidsToCopy.length) uuidsToCopy.push(data.uuid);
458 const collectionsToCopy: CollectionCopyResource[] = uuidsToCopy
459 .map(uuid => getResource(uuid)(getState().resources) as CollectionCopyResource)
460 .filter(resource => resource.kind === ResourceKind.COLLECTION);
462 for (const collection of collectionsToCopy) {
463 await copySingleCollection({ ...collection, ownerUuid: data.ownerUuid } as CollectionCopyResource);
466 async function copySingleCollection(copyToProject: CollectionCopyResource) {
467 const newName = data.fromContextMenu || collectionsToCopy.length === 1 ? data.name : `Copy of: ${copyToProject.name}`;
469 const collection = await dispatch<any>(
470 collectionCopyActions.copyCollection({
473 fromContextMenu: collectionsToCopy.length === 1 ? true : data.fromContextMenu,
476 if (copyToProject && collection) {
477 await dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
479 snackbarActions.OPEN_SNACKBAR({
480 message: "Collection has been copied.",
482 kind: SnackbarKind.SUCCESS,
483 link: collection.ownerUuid,
486 dispatch<any>(deselectOne(copyToProject.uuid));
490 snackbarActions.OPEN_SNACKBAR({
493 kind: SnackbarKind.ERROR,
498 dispatch(projectPanelDataActions.REQUEST_ITEMS());
501 export const moveCollection =
502 (data: MoveToFormDialogData, isSecondaryMove = false) =>
503 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
504 const checkedList = getState().multiselect.checkedList;
505 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
507 //if no items in checkedlist && no items passed in, default to normal context menu behavior
508 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
510 const collectionsToMove: MoveableResource[] = uuidsToMove
511 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
512 .filter(resource => resource.kind === ResourceKind.COLLECTION);
514 for (const collection of collectionsToMove) {
515 await moveSingleCollection(collection);
518 //omly propagate if this call is the original
519 if (!isSecondaryMove) {
520 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
521 kindsToMove.delete(ResourceKind.COLLECTION);
523 kindsToMove.forEach(kind => {
524 secondaryMove[kind](data, true)(dispatch, getState, services);
528 async function moveSingleCollection(collection: MoveableResource) {
530 const oldCollection: MoveToFormDialogData = { name: collection.name, uuid: collection.uuid, ownerUuid: data.ownerUuid };
531 const movedCollection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
532 dispatch<any>(updateResources([movedCollection]));
533 dispatch<any>(reloadProjectMatchingUuid([movedCollection.ownerUuid]));
535 snackbarActions.OPEN_SNACKBAR({
536 message: "Collection has been moved.",
538 kind: SnackbarKind.SUCCESS,
543 snackbarActions.OPEN_SNACKBAR({
546 kind: SnackbarKind.ERROR,
553 export const loadProcess = (uuid: string) =>
554 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
556 dispatch(progressIndicatorActions.START_WORKING(uuid));
557 dispatch<any>(loadProcessPanel(uuid));
558 const process = await dispatch<any>(processesActions.loadProcess(uuid));
560 await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
561 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
562 dispatch<any>(setProcessBreadcrumbs(uuid));
563 dispatch<any>(loadDetailsPanel(uuid));
566 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
570 export const loadRegisteredWorkflow = (uuid: string) =>
571 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
572 const userUuid = getUserUuid(getState());
574 const match = await loadGroupContentsResource({
579 let workflow: WorkflowResource | undefined;
581 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
584 OWNED: async theworkflow => {
585 workflow = theworkflow as WorkflowResource;
586 breadcrumbfunc = setSidePanelBreadcrumbs;
588 SHARED: async theworkflow => {
589 workflow = theworkflow as WorkflowResource;
590 breadcrumbfunc = setSharedWithMeBreadcrumbs;
594 if (workflow && breadcrumbfunc) {
595 dispatch(updateResources([workflow]));
596 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
597 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
598 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
599 dispatch(workflowProcessesPanelActions.REQUEST_ITEMS());
604 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
606 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
609 snackbarActions.OPEN_SNACKBAR({
610 message: "Process has been successfully updated.",
612 kind: SnackbarKind.SUCCESS,
615 dispatch<any>(updateResources([process]));
616 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
620 snackbarActions.OPEN_SNACKBAR({
623 kind: SnackbarKind.ERROR,
629 export const moveProcess =
630 (data: MoveToFormDialogData, isSecondaryMove = false) =>
631 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
632 const checkedList = getState().multiselect.checkedList;
633 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
635 //if no items in checkedlist && no items passed in, default to normal context menu behavior
636 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
638 const processesToMove: MoveableResource[] = uuidsToMove
639 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
640 .filter(resource => resource.kind === ResourceKind.PROCESS);
642 for (const process of processesToMove) {
643 await moveSingleProcess(process);
646 //omly propagate if this call is the original
647 if (!isSecondaryMove) {
648 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
649 kindsToMove.delete(ResourceKind.PROCESS);
651 kindsToMove.forEach(kind => {
652 secondaryMove[kind](data, true)(dispatch, getState, services);
656 async function moveSingleProcess(process: MoveableResource) {
658 const oldProcess: MoveToFormDialogData = { name: process.name, uuid: process.uuid, ownerUuid: data.ownerUuid };
659 const movedProcess = await dispatch<any>(processMoveActions.moveProcess(oldProcess));
660 dispatch<any>(updateResources([movedProcess]));
661 dispatch<any>(reloadProjectMatchingUuid([movedProcess.ownerUuid]));
663 snackbarActions.OPEN_SNACKBAR({
664 message: "Process has been moved.",
666 kind: SnackbarKind.SUCCESS,
671 snackbarActions.OPEN_SNACKBAR({
674 kind: SnackbarKind.ERROR,
681 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
683 const process = await dispatch<any>(processCopyActions.copyProcess(data));
684 dispatch<any>(updateResources([process]));
685 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
687 snackbarActions.OPEN_SNACKBAR({
688 message: "Process has been copied.",
690 kind: SnackbarKind.SUCCESS,
693 dispatch<any>(navigateTo(process.uuid));
696 snackbarActions.OPEN_SNACKBAR({
699 kind: SnackbarKind.ERROR,
705 export const resourceIsNotLoaded = (uuid: string) =>
706 snackbarActions.OPEN_SNACKBAR({
707 message: `Resource identified by ${uuid} is not loaded.`,
708 kind: SnackbarKind.ERROR,
711 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
712 message: "User is not authenticated",
713 kind: SnackbarKind.ERROR,
716 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
717 message: "Could not load user",
718 kind: SnackbarKind.ERROR,
721 export const reloadProjectMatchingUuid =
722 (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
723 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
724 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
725 dispatch<any>(loadProject(currentProjectPanelUuid));
729 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
730 dispatch<any>(loadSharedWithMePanel());
731 await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
732 await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
735 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
736 await dispatch<any>(loadRunProcessPanel());
739 export const loadPublicFavorites = () =>
740 handleFirstTimeLoad((dispatch: Dispatch) => {
741 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
742 dispatch<any>(loadPublicFavoritePanel());
743 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
746 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
747 await dispatch(loadSearchResultsPanel());
750 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
751 await dispatch(loadLinkPanel());
754 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
755 await dispatch(loadVirtualMachinesPanel());
756 dispatch(setVirtualMachinesBreadcrumbs());
757 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHELL_ACCESS));
760 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
761 await dispatch(loadVirtualMachinesPanel());
762 dispatch(setVirtualMachinesAdminBreadcrumbs());
763 dispatch(treePickerActions.DEACTIVATE_TREE_PICKER_NODE({ pickerId: SIDE_PANEL_TREE }))
766 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
767 await dispatch(loadRepositoriesPanel());
768 dispatch(setRepositoriesBreadcrumbs());
771 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
772 await dispatch(loadSshKeysPanel());
775 export const loadInstanceTypes = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
776 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.INSTANCE_TYPES));
777 dispatch(setInstanceTypesBreadcrumbs());
780 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
781 await dispatch(loadSiteManagerPanel());
784 export const loadUserProfile = (userUuid?: string) =>
785 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
787 dispatch(setUserProfileBreadcrumbs(userUuid));
788 dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
790 dispatch(setMyAccountBreadcrumbs());
791 dispatch(userProfilePanelActions.loadUserProfilePanel());
795 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
796 dispatch(loadLinkAccountPanel());
799 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
800 await dispatch(loadKeepServicesPanel());
803 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
804 await dispatch(loadUsersPanel());
805 dispatch(setUsersBreadcrumbs());
808 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
809 await dispatch(loadApiClientAuthorizationsPanel());
812 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
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,