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 { matchRootRoute } from "routes/routes";
23 setGroupDetailsBreadcrumbs,
25 setProcessBreadcrumbs,
26 setSharedWithMeBreadcrumbs,
27 setSidePanelBreadcrumbs,
30 setMyAccountBreadcrumbs,
31 setUserProfileBreadcrumbs,
32 setInstanceTypesBreadcrumbs,
33 setVirtualMachinesBreadcrumbs,
34 setVirtualMachinesAdminBreadcrumbs,
35 setRepositoriesBreadcrumbs,
36 } from "store/breadcrumbs/breadcrumbs-actions";
37 import { navigateTo, navigateToRootProject } from "store/navigation/navigation-action";
38 import { MoveToFormDialogData } from "store/move-to-dialog/move-to-dialog";
39 import { ServiceRepository } from "services/services";
40 import { getResource } from "store/resources/resources";
41 import * as projectCreateActions from "store/projects/project-create-actions";
42 import * as projectMoveActions from "store/projects/project-move-actions";
43 import * as projectUpdateActions from "store/projects/project-update-actions";
44 import * as collectionCreateActions from "store/collections/collection-create-actions";
45 import * as collectionCopyActions from "store/collections/collection-copy-actions";
46 import * as collectionMoveActions from "store/collections/collection-move-actions";
47 import * as processMoveActions from "store/processes/process-move-actions";
48 import * as processUpdateActions from "store/processes/process-update-actions";
49 import * as processCopyActions from "store/processes/process-copy-actions";
51 import { loadTrashPanel, trashPanelActions } from "store/trash-panel/trash-panel-action";
52 import { loadProcessPanel } from "store/process-panel/process-panel-actions";
53 import { loadSharedWithMePanel, sharedWithMePanelActions } from "store/shared-with-me-panel/shared-with-me-panel-actions";
54 import { CopyFormDialogData } from "store/copy-dialog/copy-dialog";
55 import { workflowPanelActions } from "store/workflow-panel/workflow-panel-actions";
56 import { loadSshKeysPanel } from "store/auth/auth-action-ssh";
57 import { loadLinkAccountPanel, linkAccountPanelActions } from "store/link-account-panel/link-account-panel-actions";
58 import { loadSiteManagerPanel } from "store/auth/auth-action-session";
59 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
60 import { getProgressIndicator } from "store/progress-indicator/progress-indicator-reducer";
61 import { extractUuidKind, Resource, ResourceKind } from "models/resource";
62 import { FilterBuilder } from "services/api/filter-builder";
63 import { GroupContentsResource } from "services/groups-service/groups-service";
64 import { MatchCases, ofType, unionize, UnionOf } from "common/unionize";
65 import { loadRunProcessPanel } from "store/run-process-panel/run-process-panel-actions";
66 import { collectionPanelActions, loadCollectionPanel } from "store/collection-panel/collection-panel-action";
67 import { CollectionResource } from "models/collection";
68 import { WorkflowResource } from "models/workflow";
69 import { loadSearchResultsPanel, searchResultsPanelActions } from "store/search-results-panel/search-results-panel-actions";
70 import { loadVirtualMachinesPanel } from "store/virtual-machines/virtual-machines-actions";
71 import { loadRepositoriesPanel } from "store/repositories/repositories-actions";
72 import { loadKeepServicesPanel } from "store/keep-services/keep-services-actions";
73 import { loadUsersPanel, userBindedActions } from "store/users/users-actions";
74 import * as userProfilePanelActions from "store/user-profile/user-profile-actions";
75 import { linkPanelActions, loadLinkPanel } from "store/link-panel/link-panel-actions";
76 import { loadApiClientAuthorizationsPanel, apiClientAuthorizationsActions } from "store/api-client-authorizations/api-client-authorizations-actions";
77 import * as groupPanelActions from "store/groups-panel/groups-panel-actions";
78 import * as groupDetailsPanelActions from "store/group-details-panel/group-details-panel-actions";
79 import { loadPublicFavoritePanel, publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
81 loadCollectionsContentAddressPanel,
82 collectionsContentAddressActions,
83 } from "store/collections-content-address-panel/collections-content-address-panel-actions";
84 import { subprocessPanelActions } from "store/subprocess-panel/subprocess-panel-actions";
85 import { deselectOne } from "store/multiselect/multiselect-actions";
86 import { treePickerActions } from "store/tree-picker/tree-picker-actions";
87 import { workflowProcessesPanelActions } from "store/workflow-panel/workflow-panel-actions";
88 import { loadAllProcessesPanel, allProcessesPanelActions } from "../all-processes-panel/all-processes-panel-action";
90 import { DataTableFetchMode } from "components/data-table/data-table";
91 import { selectedToArray, selectedToKindSet } from "components/multiselect-toolbar/MultiselectToolbar";
93 import { sharedWithMePanelColumns } from "views/shared-with-me-panel/shared-with-me-columns";
94 import { workflowPanelColumns } from "views/workflow-panel/workflow-panel-view";
95 import { searchResultsPanelColumns } from "views/search-results-panel/search-results-panel-view";
96 import { linkPanelColumns } from "views/link-panel/link-panel-root";
97 import { userPanelColumns } from "views/user-panel/user-panel";
98 import { apiClientAuthorizationPanelColumns } from "views/api-client-authorization-panel/api-client-authorization-panel-root";
99 import { groupsPanelColumns } from "views/groups-panel/groups-panel";
100 import { groupDetailsMembersPanelColumns, groupDetailsPermissionsPanelColumns } from "views/group-details-panel/group-details-panel";
101 import { publicFavoritePanelColumns } from "views/public-favorites-panel/public-favorites-panel";
102 import { collectionContentAddressPanelColumns } from "views/collection-content-address-panel/collection-content-address-panel";
103 import { subprocessPanelColumns } from "views/subprocess-panel/subprocess-panel-root";
104 import { allProcessesPanelColumns } from "views/all-processes-panel/all-processes-panel";
105 import { userProfileGroupsColumns } from "views/user-profile-panel/user-profile-panel-root";
106 import { workflowProcessesPanelColumns } from "views/workflow-panel/workflow-processes-panel-root";
107 import { trashPanelColumns } from "views/trash-panel/trash-panel";
108 import { projectPanelDataColumns } from "views/project-panel/project-panel-data";
109 import { projectPanelRunColumns } from "views/project-panel/project-panel-run";
110 import { favoritePanelColumns } from "views/favorite-panel/favorite-panel";
113 export const WORKBENCH_LOADING_SCREEN = "workbenchLoadingScreen";
115 export const isWorkbenchLoading = (state: RootState) => {
116 const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
117 return progress ? progress.working : false;
120 export const handleFirstTimeLoad = (action: any) => async (dispatch: Dispatch<any>, getState: () => RootState) => {
122 await dispatch(action);
124 snackbarActions.OPEN_SNACKBAR({
125 message: "Error " + e,
127 kind: SnackbarKind.WARNING,
130 if (isWorkbenchLoading(getState())) {
131 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
136 export const loadWorkbench = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
137 dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
138 const { auth, router } = getState();
139 const { user } = auth;
141 dispatch(projectPanelDataActions.SET_COLUMNS({ columns: projectPanelDataColumns }));
142 dispatch(projectPanelRunActions.SET_COLUMNS({ columns: projectPanelRunColumns }));
143 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
145 allProcessesPanelActions.SET_COLUMNS({
146 columns: allProcessesPanelColumns,
150 publicFavoritePanelActions.SET_COLUMNS({
151 columns: publicFavoritePanelColumns,
154 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
155 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: sharedWithMePanelColumns }));
156 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
158 searchResultsPanelActions.SET_FETCH_MODE({
159 fetchMode: DataTableFetchMode.INFINITE,
163 searchResultsPanelActions.SET_COLUMNS({
164 columns: searchResultsPanelColumns,
167 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
169 groupPanelActions.GroupsPanelActions.SET_COLUMNS({
170 columns: groupsPanelColumns,
174 groupDetailsPanelActions.GroupMembersPanelActions.SET_COLUMNS({
175 columns: groupDetailsMembersPanelColumns,
179 groupDetailsPanelActions.GroupPermissionsPanelActions.SET_COLUMNS({
180 columns: groupDetailsPermissionsPanelColumns,
184 userProfilePanelActions.UserProfileGroupsActions.SET_COLUMNS({
185 columns: userProfileGroupsColumns,
188 dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
190 apiClientAuthorizationsActions.SET_COLUMNS({
191 columns: apiClientAuthorizationPanelColumns,
195 collectionsContentAddressActions.SET_COLUMNS({
196 columns: collectionContentAddressPanelColumns,
199 dispatch(subprocessPanelActions.SET_COLUMNS({ columns: subprocessPanelColumns }));
200 dispatch(workflowProcessesPanelActions.SET_COLUMNS({ columns: workflowProcessesPanelColumns }));
202 if (services.linkAccountService.getAccountToLink()) {
203 dispatch(linkAccountPanelActions.HAS_SESSION_DATA());
206 dispatch<any>(initSidePanelTree());
207 if (router.location) {
208 const match = matchRootRoute(router.location.pathname);
210 dispatch<any>(navigateToRootProject);
214 dispatch(userIsNotAuthenticated);
218 export const loadFavorites = () =>
219 handleFirstTimeLoad((dispatch: Dispatch) => {
220 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
221 dispatch<any>(loadFavoritePanel());
222 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
225 export const loadCollectionContentAddress = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
226 await dispatch(loadCollectionsContentAddressPanel());
229 export const loadTrash = () =>
230 handleFirstTimeLoad((dispatch: Dispatch) => {
231 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
232 dispatch<any>(loadTrashPanel());
233 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
236 export const loadAllProcesses = () =>
237 handleFirstTimeLoad((dispatch: Dispatch) => {
238 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.ALL_PROCESSES));
239 dispatch<any>(loadAllProcessesPanel());
240 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.ALL_PROCESSES));
243 export const loadProject = (uuid: string) =>
244 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
245 const userUuid = getUserUuid(getState());
246 dispatch(setIsProjectPanelTrashed(false));
251 dispatch(progressIndicatorActions.START_WORKING(uuid));
252 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
253 // Load another users home projects
254 dispatch(finishLoadingProject(uuid));
255 dispatch<any>(setSidePanelBreadcrumbs(uuid));
256 } else if (userUuid !== uuid) {
257 await dispatch(finishLoadingProject(uuid));
258 const match = await loadGroupContentsResource({
265 await dispatch(activateSidePanelTreeItem(uuid));
266 dispatch<any>(setSidePanelBreadcrumbs(uuid));
268 SHARED: async () => {
269 await dispatch(activateSidePanelTreeItem(uuid));
270 dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
272 TRASHED: async () => {
273 await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
274 dispatch<any>(setTrashBreadcrumbs(uuid));
275 dispatch(setIsProjectPanelTrashed(true));
279 await dispatch(finishLoadingProject(userUuid));
280 await dispatch(activateSidePanelTreeItem(userUuid));
281 dispatch<any>(setSidePanelBreadcrumbs(userUuid));
284 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
288 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) => async (dispatch: Dispatch) => {
289 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
292 snackbarActions.OPEN_SNACKBAR({
293 message: "Project has been successfully created.",
295 kind: SnackbarKind.SUCCESS,
298 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
299 dispatch<any>(navigateTo(newProject.uuid));
303 export const moveProject =
304 (data: MoveToFormDialogData, isSecondaryMove = false) =>
305 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
306 const checkedList = getState().multiselect.checkedList;
307 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
309 //if no items in checkedlist default to normal context menu behavior
310 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
312 const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
313 const destinationUuid = data.ownerUuid;
315 const projectsToMove: MoveableResource[] = uuidsToMove
316 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
317 .filter(resource => resource.kind === ResourceKind.PROJECT);
319 for (const project of projectsToMove) {
320 await moveSingleProject(project);
323 //omly propagate if this call is the original
324 if (!isSecondaryMove) {
325 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
326 kindsToMove.delete(ResourceKind.PROJECT);
328 kindsToMove.forEach(kind => {
329 secondaryMove[kind](data, true)(dispatch, getState, services);
333 async function moveSingleProject(project: MoveableResource) {
335 const oldProject: MoveToFormDialogData = { name: project.name, uuid: project.uuid, ownerUuid: data.ownerUuid };
336 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
337 const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
340 snackbarActions.OPEN_SNACKBAR({
341 message: "Project has been moved",
343 kind: SnackbarKind.SUCCESS,
346 await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
350 snackbarActions.OPEN_SNACKBAR({
351 message: !!(project as any).frozenByUuid ? 'Could not move frozen project.' : e.message,
353 kind: SnackbarKind.ERROR,
358 if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
359 await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
362 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
363 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
364 if (updatedProject) {
366 snackbarActions.OPEN_SNACKBAR({
367 message: "Project has been successfully updated.",
369 kind: SnackbarKind.SUCCESS,
372 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
373 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
377 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
378 const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
381 snackbarActions.OPEN_SNACKBAR({
382 message: "Group has been successfully updated.",
384 kind: SnackbarKind.SUCCESS,
387 await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
388 dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
392 export const loadCollection = (uuid: string) =>
393 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
394 const userUuid = getUserUuid(getState());
396 dispatch(progressIndicatorActions.START_WORKING(uuid));
398 const match = await loadGroupContentsResource({
403 let collection: CollectionResource | undefined;
405 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
407 let sidepanel: string | undefined;
409 OWNED: thecollection => {
410 collection = thecollection as CollectionResource;
411 sidepanel = collection.ownerUuid;
412 breadcrumbfunc = setSidePanelBreadcrumbs;
414 SHARED: thecollection => {
415 collection = thecollection as CollectionResource;
416 sidepanel = collection.ownerUuid;
417 breadcrumbfunc = setSharedWithMeBreadcrumbs;
419 TRASHED: thecollection => {
420 collection = thecollection as CollectionResource;
421 sidepanel = SidePanelTreeCategory.TRASH;
422 breadcrumbfunc = () => setTrashBreadcrumbs("");
425 if (collection && breadcrumbfunc && sidepanel) {
426 dispatch(updateResources([collection]));
427 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
428 dispatch(collectionPanelActions.SET_COLLECTION(collection));
429 await dispatch(activateSidePanelTreeItem(sidepanel));
430 dispatch(breadcrumbfunc(collection.ownerUuid));
431 dispatch(loadCollectionPanel(collection.uuid));
435 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
439 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
440 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
443 snackbarActions.OPEN_SNACKBAR({
444 message: "Collection has been successfully created.",
446 kind: SnackbarKind.SUCCESS,
449 dispatch<any>(updateResources([collection]));
450 dispatch<any>(navigateTo(collection.uuid));
454 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
455 const checkedList = getState().multiselect.checkedList;
456 const uuidsToCopy: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
458 //if no items in checkedlist && no items passed in, default to normal context menu behavior
459 if (!uuidsToCopy.length) uuidsToCopy.push(data.uuid);
461 const collectionsToCopy: CollectionCopyResource[] = uuidsToCopy
462 .map(uuid => getResource(uuid)(getState().resources) as CollectionCopyResource)
463 .filter(resource => resource.kind === ResourceKind.COLLECTION);
465 for (const collection of collectionsToCopy) {
466 await copySingleCollection({ ...collection, ownerUuid: data.ownerUuid } as CollectionCopyResource);
469 async function copySingleCollection(copyToProject: CollectionCopyResource) {
470 const newName = data.fromContextMenu || collectionsToCopy.length === 1 ? data.name : `Copy of: ${copyToProject.name}`;
472 const collection = await dispatch<any>(
473 collectionCopyActions.copyCollection({
476 fromContextMenu: collectionsToCopy.length === 1 ? true : data.fromContextMenu,
479 if (copyToProject && collection) {
480 await dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
482 snackbarActions.OPEN_SNACKBAR({
483 message: "Collection has been copied.",
485 kind: SnackbarKind.SUCCESS,
486 link: collection.ownerUuid,
489 dispatch<any>(deselectOne(copyToProject.uuid));
493 snackbarActions.OPEN_SNACKBAR({
496 kind: SnackbarKind.ERROR,
501 dispatch(projectPanelDataActions.REQUEST_ITEMS());
504 export const moveCollection =
505 (data: MoveToFormDialogData, isSecondaryMove = false) =>
506 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
507 const checkedList = getState().multiselect.checkedList;
508 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
510 //if no items in checkedlist && no items passed in, default to normal context menu behavior
511 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
513 const collectionsToMove: MoveableResource[] = uuidsToMove
514 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
515 .filter(resource => resource.kind === ResourceKind.COLLECTION);
517 for (const collection of collectionsToMove) {
518 await moveSingleCollection(collection);
521 //omly propagate if this call is the original
522 if (!isSecondaryMove) {
523 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
524 kindsToMove.delete(ResourceKind.COLLECTION);
526 kindsToMove.forEach(kind => {
527 secondaryMove[kind](data, true)(dispatch, getState, services);
531 async function moveSingleCollection(collection: MoveableResource) {
533 const oldCollection: MoveToFormDialogData = { name: collection.name, uuid: collection.uuid, ownerUuid: data.ownerUuid };
534 const movedCollection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
535 dispatch<any>(updateResources([movedCollection]));
536 dispatch<any>(reloadProjectMatchingUuid([movedCollection.ownerUuid]));
538 snackbarActions.OPEN_SNACKBAR({
539 message: "Collection has been moved.",
541 kind: SnackbarKind.SUCCESS,
546 snackbarActions.OPEN_SNACKBAR({
549 kind: SnackbarKind.ERROR,
556 export const loadProcess = (uuid: string) =>
557 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
559 dispatch(progressIndicatorActions.START_WORKING(uuid));
560 const process = await dispatch<any>(loadProcessPanel(uuid));
562 await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
563 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
564 dispatch<any>(setProcessBreadcrumbs(uuid));
565 dispatch<any>(loadDetailsPanel(uuid));
568 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
572 export const loadRegisteredWorkflow = (uuid: string) =>
573 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
574 const userUuid = getUserUuid(getState());
576 const match = await loadGroupContentsResource({
581 let workflow: WorkflowResource | undefined;
583 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
586 OWNED: async theworkflow => {
587 workflow = theworkflow as WorkflowResource;
588 breadcrumbfunc = setSidePanelBreadcrumbs;
590 SHARED: async theworkflow => {
591 workflow = theworkflow as WorkflowResource;
592 breadcrumbfunc = setSharedWithMeBreadcrumbs;
596 if (workflow && breadcrumbfunc) {
597 dispatch(updateResources([workflow]));
598 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
599 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
600 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
601 dispatch(workflowProcessesPanelActions.REQUEST_ITEMS());
606 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
608 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
611 snackbarActions.OPEN_SNACKBAR({
612 message: "Process has been successfully updated.",
614 kind: SnackbarKind.SUCCESS,
617 dispatch<any>(updateResources([process]));
618 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
622 snackbarActions.OPEN_SNACKBAR({
625 kind: SnackbarKind.ERROR,
631 export const moveProcess =
632 (data: MoveToFormDialogData, isSecondaryMove = false) =>
633 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
634 const checkedList = getState().multiselect.checkedList;
635 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
637 //if no items in checkedlist && no items passed in, default to normal context menu behavior
638 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
640 const processesToMove: MoveableResource[] = uuidsToMove
641 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
642 .filter(resource => resource.kind === ResourceKind.PROCESS);
644 for (const process of processesToMove) {
645 await moveSingleProcess(process);
648 //omly propagate if this call is the original
649 if (!isSecondaryMove) {
650 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
651 kindsToMove.delete(ResourceKind.PROCESS);
653 kindsToMove.forEach(kind => {
654 secondaryMove[kind](data, true)(dispatch, getState, services);
658 async function moveSingleProcess(process: MoveableResource) {
660 const oldProcess: MoveToFormDialogData = { name: process.name, uuid: process.uuid, ownerUuid: data.ownerUuid };
661 const movedProcess = await dispatch<any>(processMoveActions.moveProcess(oldProcess));
662 dispatch<any>(updateResources([movedProcess]));
663 dispatch<any>(reloadProjectMatchingUuid([movedProcess.ownerUuid]));
665 snackbarActions.OPEN_SNACKBAR({
666 message: "Process has been moved.",
668 kind: SnackbarKind.SUCCESS,
673 snackbarActions.OPEN_SNACKBAR({
676 kind: SnackbarKind.ERROR,
683 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
685 const process = await dispatch<any>(processCopyActions.copyProcess(data));
686 dispatch<any>(updateResources([process]));
687 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
689 snackbarActions.OPEN_SNACKBAR({
690 message: "Process has been copied.",
692 kind: SnackbarKind.SUCCESS,
695 dispatch<any>(navigateTo(process.uuid));
698 snackbarActions.OPEN_SNACKBAR({
701 kind: SnackbarKind.ERROR,
707 export const resourceIsNotLoaded = (uuid: string) =>
708 snackbarActions.OPEN_SNACKBAR({
709 message: `Resource identified by ${uuid} is not loaded.`,
710 kind: SnackbarKind.ERROR,
713 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
714 message: "User is not authenticated",
715 kind: SnackbarKind.ERROR,
718 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
719 message: "Could not load user",
720 kind: SnackbarKind.ERROR,
723 export const reloadProjectMatchingUuid =
724 (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
725 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
726 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
727 dispatch<any>(loadProject(currentProjectPanelUuid));
731 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
732 dispatch<any>(loadSharedWithMePanel());
733 await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
734 await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
737 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
738 await dispatch<any>(loadRunProcessPanel());
741 export const loadPublicFavorites = () =>
742 handleFirstTimeLoad((dispatch: Dispatch) => {
743 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
744 dispatch<any>(loadPublicFavoritePanel());
745 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
748 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
749 await dispatch(loadSearchResultsPanel());
752 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
753 await dispatch(loadLinkPanel());
756 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
757 await dispatch(loadVirtualMachinesPanel());
758 dispatch(setVirtualMachinesBreadcrumbs());
759 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHELL_ACCESS));
762 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
763 await dispatch(loadVirtualMachinesPanel());
764 dispatch(setVirtualMachinesAdminBreadcrumbs());
765 dispatch(treePickerActions.DEACTIVATE_TREE_PICKER_NODE({ pickerId: SIDE_PANEL_TREE }))
768 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
769 await dispatch(loadRepositoriesPanel());
770 dispatch(setRepositoriesBreadcrumbs());
773 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
774 await dispatch(loadSshKeysPanel());
777 export const loadInstanceTypes = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
778 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.INSTANCE_TYPES));
779 dispatch(setInstanceTypesBreadcrumbs());
782 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
783 await dispatch(loadSiteManagerPanel());
786 export const loadUserProfile = (userUuid?: string) =>
787 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
789 dispatch(setUserProfileBreadcrumbs(userUuid));
790 dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
792 dispatch(setMyAccountBreadcrumbs());
793 dispatch(userProfilePanelActions.loadUserProfilePanel());
797 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
798 dispatch(loadLinkAccountPanel());
801 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
802 await dispatch(loadKeepServicesPanel());
805 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
806 await dispatch(loadUsersPanel());
807 dispatch(setUsersBreadcrumbs());
810 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
811 await dispatch(loadApiClientAuthorizationsPanel());
814 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
815 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.GROUPS));
816 dispatch(setGroupsBreadcrumbs());
817 dispatch(groupPanelActions.loadGroupsPanel());
820 export const loadGroupDetailsPanel = (groupUuid: string) =>
821 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
822 dispatch(setGroupDetailsBreadcrumbs(groupUuid));
823 dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
826 const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
827 const uuid = typeof project === "string" ? project : project.uuid;
828 dispatch(loadDetailsPanel(uuid));
829 if (typeof project !== "string") {
830 dispatch(updateResources([project]));
834 const loadGroupContentsResource = async (params: { uuid: string; userUuid: string; services: ServiceRepository }) => {
835 const filters = new FilterBuilder().addEqual("uuid", params.uuid).getFilters();
836 const { items } = await params.services.groupsService.contents(params.userUuid, {
841 const resource = items.shift();
842 let handler: GroupContentsHandler;
845 (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
846 ? groupContentsHandlers.TRASHED(resource)
847 : groupContentsHandlers.OWNED(resource);
849 const kind = extractUuidKind(params.uuid);
850 let resource: GroupContentsResource;
851 if (kind === ResourceKind.COLLECTION) {
852 resource = await params.services.collectionService.get(params.uuid);
853 } else if (kind === ResourceKind.PROJECT) {
854 resource = await params.services.projectService.get(params.uuid);
855 } else if (kind === ResourceKind.WORKFLOW) {
856 resource = await params.services.workflowService.get(params.uuid);
857 } else if (kind === ResourceKind.CONTAINER_REQUEST) {
858 resource = await params.services.containerRequestService.get(params.uuid);
860 throw new Error("loadGroupContentsResource unsupported kind " + kind);
862 handler = groupContentsHandlers.SHARED(resource);
864 return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) => groupContentsHandlers.match(handler, cases);
867 const groupContentsHandlersRecord = {
868 TRASHED: ofType<GroupContentsResource>(),
869 SHARED: ofType<GroupContentsResource>(),
870 OWNED: ofType<GroupContentsResource>(),
873 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
875 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;
877 type CollectionCopyResource = Resource & { name: string; fromContextMenu: boolean };
879 type MoveableResource = Resource & { name: string };
882 data: MoveToFormDialogData,
883 isSecondaryMove?: boolean
884 ) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>;
886 const secondaryMove: Record<string, MoveFunc> = {
887 [ResourceKind.PROJECT]: moveProject,
888 [ResourceKind.PROCESS]: moveProcess,
889 [ResourceKind.COLLECTION]: moveCollection,